Skip to content

Commit 18202fa

Browse files
author
jantje
committed
#585 gone a bit haywire with refactoring
1 parent 8c68f48 commit 18202fa

40 files changed

+515
-366
lines changed

io.sloeber.core/src/io/sloeber/core/Activator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import io.sloeber.core.api.PackageManager;
4646
import io.sloeber.core.common.Common;
4747
import io.sloeber.core.common.ConfigurationPreferences;
48-
import io.sloeber.core.common.Const;
4948
import io.sloeber.core.common.InstancePreferences;
5049
import io.sloeber.core.listeners.ConfigurationChangeListener;
5150
import io.sloeber.core.listeners.IndexerListener;
@@ -60,8 +59,7 @@
6059
*/
6160
@SuppressWarnings({ "nls" })
6261
public class Activator extends Plugin {
63-
// preference nodes
64-
public static final String NODE_ARDUINO = "io.sloeber.arduino";
62+
6563
// TOFIX I think the fix below for unix users is no longer needed and we no
6664
// longer use the rxtx dll
6765
private static final String ENV_KEY_GNU_SERIAL_PORTS = "gnu.io.rxtx.SerialPorts";
@@ -124,15 +122,15 @@ private static void testKnownIssues() {
124122
if (!installFile.canWrite()) {
125123
errorString += addString + "The folder " + installPath.toString()
126124
+ " exists but Sloeber does not have write access to it.\n";
127-
errorString += "Alternatively use the environment var " + Const.SLOEBER_HOME + ".";
125+
errorString += "Alternatively use the environment var " + SLOEBER_HOME + ".";
128126
addString = "\nand\n";
129127
}
130128
} else {
131129
if (!installFile.getParentFile().canWrite()) {
132130
errorString += addString + "Sloeber does not have write access to "
133131
+ installFile.getParentFile().toString() + " and therefore can not create the folder "
134132
+ installPath.toString();
135-
errorString += "\nAlternatively use the environment var " + Const.SLOEBER_HOME + ".";
133+
errorString += "\nAlternatively use the environment var " + SLOEBER_HOME + ".";
136134
addString = "\nand\n";
137135
}
138136
}
@@ -143,7 +141,7 @@ private static void testKnownIssues() {
143141
errorString += "Your current path: " + installPath.toString();
144142
errorString += " is too long and the plugin will no longer function correctly for all boards.\n";
145143
errorString += "Please visit issue #705 for details. https://github.com/Sloeber/arduino-eclipse-plugin/issues/705\n";
146-
errorString += "Alternatively use the environment var " + Const.SLOEBER_HOME + ".";
144+
errorString += "Alternatively use the environment var " + SLOEBER_HOME + ".";
147145
addString = "\nand\n";
148146
}
149147
if (installPath.toString().contains(" ")) {

io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2323
import org.eclipse.core.runtime.preferences.InstanceScope;
2424

25-
import io.sloeber.core.Activator;
2625
import io.sloeber.core.common.Common;
2726
import io.sloeber.core.common.ConfigurationPreferences;
2827
import io.sloeber.core.managers.ArduinoPlatform;
@@ -61,7 +60,6 @@ public class BoardDescription {
6160
private static final String ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH = REFERENCED + DOT + UPLOAD + PATH;
6261

6362
// preference nodes
64-
private static final String NODE_ARDUINO = Activator.NODE_ARDUINO;
6563
private static final IEclipsePreferences myStorageNode = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
6664
private static final TxtFile pluginPreProcessingPlatformTxt = new TxtFile(
6765
ConfigurationPreferences.getPreProcessingPlatformFile());

io.sloeber.core/src/io/sloeber/core/api/LaunchConfiguration.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.eclipse.debug.core.ILaunch;
1010
import org.eclipse.debug.core.ILaunchConfiguration;
1111
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
12+
1213
@SuppressWarnings("unused")
1314
public class LaunchConfiguration implements ILaunchConfigurationDelegate {
1415

@@ -49,29 +50,29 @@ public class LaunchConfiguration implements ILaunchConfigurationDelegate {
4950

5051
@Override
5152
public void launch(ILaunchConfiguration launchConfig, String launchMode, ILaunch launchHandle,
52-
IProgressMonitor launchMonitor) throws CoreException {
53+
IProgressMonitor launchMonitor) throws CoreException {
5354

54-
this.config = launchConfig;
55-
this.mode = launchMode;
56-
this.launch = launchHandle;
57-
this.monitor = launchMonitor;
55+
this.config = launchConfig;
56+
this.mode = launchMode;
57+
this.launch = launchHandle;
58+
this.monitor = launchMonitor;
5859

59-
// Get data from config
60-
loadSettingsFromConfiguration();
60+
// Get data from config
61+
loadSettingsFromConfiguration();
6162

62-
if (this.project != null) {
63-
// Delegate launching the project
64-
Sketch.upload(this.project);
65-
}
63+
if (this.project != null) {
64+
// Delegate launching the project
65+
Sketch.syncUpload(this.project);
66+
}
6667
}
6768

6869
private void loadSettingsFromConfiguration() {
69-
try {
70-
String projectName = this.config.getAttribute(ATTR_PROJECT, ""); //$NON-NLS-1$
71-
this.project = findProject(projectName);
72-
} catch (CoreException e) {
73-
// Stupid exception...
74-
}
70+
try {
71+
String projectName = this.config.getAttribute(ATTR_PROJECT, ""); //$NON-NLS-1$
72+
this.project = findProject(projectName);
73+
} catch (CoreException e) {
74+
// Stupid exception...
75+
}
7576
}
7677

7778
/**
@@ -81,12 +82,12 @@ private void loadSettingsFromConfiguration() {
8182
* @return the project handle if a project was found
8283
*/
8384
public static IProject findProject(String name) {
84-
if (StringUtils.isNotBlank(name) && new Path(name).isValidPath(name)) {
85-
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
86-
if (p.getLocation() != null)
87-
return p;
88-
}
89-
return null;
85+
if (StringUtils.isNotBlank(name) && new Path(name).isValidPath(name)) {
86+
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
87+
if (p.getLocation() != null)
88+
return p;
89+
}
90+
return null;
9091
}
9192

9293
}

io.sloeber.core/src/io/sloeber/core/api/Sketch.java

Lines changed: 13 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,40 @@
11
package io.sloeber.core.api;
22

3-
import java.net.URL;
3+
import static io.sloeber.core.common.Const.*;
4+
45
import java.util.List;
56
import java.util.Map;
67
import java.util.Set;
7-
import java.util.TreeMap;
88

99
import org.eclipse.cdt.core.model.CoreModel;
10-
import org.eclipse.cdt.core.model.ICModelMarker;
1110
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
1211
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
13-
import org.eclipse.core.resources.IMarker;
1412
import org.eclipse.core.resources.IProject;
15-
import org.eclipse.core.resources.IResource;
16-
import org.eclipse.core.resources.IncrementalProjectBuilder;
1713
import org.eclipse.core.runtime.CoreException;
1814
import org.eclipse.core.runtime.IPath;
19-
import org.eclipse.core.runtime.IProgressMonitor;
2015
import org.eclipse.core.runtime.IStatus;
2116
import org.eclipse.core.runtime.Path;
2217
import org.eclipse.core.runtime.Status;
23-
import org.eclipse.core.runtime.jobs.Job;
24-
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
25-
import org.eclipse.core.runtime.preferences.InstanceScope;
26-
import org.eclipse.ui.console.MessageConsole;
27-
import org.osgi.service.prefs.BackingStoreException;
2818

29-
import io.sloeber.core.Activator;
3019
import io.sloeber.core.Messages;
31-
import io.sloeber.core.common.Common;
32-
import io.sloeber.core.common.Const;
3320
import io.sloeber.core.common.IndexHelper;
3421
import io.sloeber.core.tools.Helpers;
3522
import io.sloeber.core.tools.Libraries;
36-
import io.sloeber.core.tools.uploaders.UploadSketchWrapper;
3723

38-
@SuppressWarnings("unused")
3924
public class Sketch {
40-
// preference nodes
41-
public static final String NODE_ARDUINO = Activator.NODE_ARDUINO;
4225

4326
public static IStatus isUploadableProject(IProject project) {
4427
try {
45-
if (project == null || !project.hasNature(Const.ARDUINO_NATURE_ID)) {
46-
return new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_no_arduino_sketch, null);
28+
if (project == null || !project.hasNature(ARDUINO_NATURE_ID)) {
29+
return new Status(IStatus.ERROR, CORE_PLUGIN_ID, Messages.Upload_no_arduino_sketch, null);
4730
}
4831
} catch (CoreException e) {
49-
return new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_Project_nature_unaccesible, e);
32+
return new Status(IStatus.ERROR, CORE_PLUGIN_ID, Messages.Upload_Project_nature_unaccesible, e);
5033
}
5134
return Status.OK_STATUS;
5235
}
5336

54-
/**
55-
* Asynchronous upload of the sketch. The upload status has to be followed in
56-
* the GUI
57-
*
58-
* @param project
59-
*
60-
*/
61-
public static Job asyncUpload(IProject project) {
62-
IStatus ret = isUploadableProject(project);
63-
if (!ret.isOK()) {
64-
Common.log(ret);
65-
return null;
66-
}
67-
68-
return UploadSketchWrapper.upload(project,
69-
CoreModel.getDefault().getProjectDescription(project).getActiveConfiguration());
7037

71-
}
7238

7339
/**
7440
* Synchronous upload of the sketch returning the status.
@@ -77,104 +43,13 @@ public static Job asyncUpload(IProject project) {
7743
* @return the status of the upload. Status.OK means upload is OK
7844
*/
7945
public static IStatus syncUpload(IProject project) {
46+
8047
IStatus ret = isUploadableProject(project);
8148
if (!ret.isOK()) {
8249
return ret;
8350
}
84-
Job upLoadJob = UploadSketchWrapper.upload(project,
85-
CoreModel.getDefault().getProjectDescription(project).getActiveConfiguration());
86-
87-
if (upLoadJob == null)
88-
return new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_failed, null);
89-
try {
90-
upLoadJob.join();
91-
return upLoadJob.getResult();
92-
} catch (InterruptedException e) {
93-
// not sure if this is needed
94-
return new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_failed, e);
95-
}
96-
}
97-
98-
/**
99-
* Synchronous upload of the sketch with the errors shown in the gui.
100-
*
101-
* @param project
102-
* @return the status of the upload. true means upload is OK
103-
*/
104-
public static boolean upload(IProject project) {
105-
IStatus ret = syncUpload(project);
106-
if (!ret.isOK()) {
107-
Common.log(ret);
108-
}
109-
110-
return ret.isOK();
111-
}
112-
113-
/**
114-
* Verifies a project. Builds the active configuration If the build fails
115-
* returns false else tru
116-
*
117-
* @param project
118-
* @return
119-
*/
120-
public static boolean verify(IProject project, IProgressMonitor monitor) {
121-
MessageConsole theconsole = Helpers.findConsole("CDT Build Console (" + project.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
122-
if (theconsole != null) {
123-
theconsole.activate();
124-
}
125-
try {
126-
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
127-
128-
Job job = new Job("Start build Activator") { //$NON-NLS-1$
129-
@Override
130-
protected IStatus run(IProgressMonitor _monitor) {
131-
try {
132-
String buildflag = "FbStatus"; //$NON-NLS-1$
133-
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i',
134-
't', '/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a',
135-
'd', '/', 'b', 'u', 'i', 'l', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l',
136-
'?', 'b', '=' };
137-
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
138-
int curFsiStatus = myScope.getInt(buildflag, 0) + 1;
139-
myScope.putInt(buildflag, curFsiStatus);
140-
try {
141-
myScope.flush();
142-
} catch (BackingStoreException e) {
143-
// this should not happen
144-
}
145-
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
146-
pluginStartInitiator.getContent();
147-
} catch (Exception e) {
148-
e.printStackTrace();
149-
}
150-
return Status.OK_STATUS;
151-
}
152-
};
153-
job.setPriority(Job.DECORATE);
154-
job.schedule();
155-
return isBuildSuccessFull(project);
156-
} catch (CoreException e) {
157-
// don't care about the error; the only thing that matters is: the
158-
// build failed
159-
return true;
160-
}
161-
}
162-
163-
/**
164-
* Checks if build completed successfully.
165-
*
166-
* @return true iff project was built successfully last time.
167-
* @throws CoreException
168-
* if current project does not exist or is not open.
169-
*/
170-
private static boolean isBuildSuccessFull(IProject project) throws CoreException {
171-
IMarker[] markers = project.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
172-
for (IMarker marker : markers) {
173-
if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) {
174-
return false;
175-
}
176-
}
177-
return true;
51+
SloeberProject sProject = SloeberProject.getSloeberProject(project, true);
52+
return sProject.upload();
17853
}
17954

18055
/**
@@ -205,7 +80,7 @@ public static void reAttachLibrariesToProject(IProject iProject) {
20580

20681
public static boolean isSketch(IProject proj) {
20782
try {
208-
return proj.hasNature(Const.ARDUINO_NATURE_ID);
83+
return proj.hasNature(ARDUINO_NATURE_ID);
20984
} catch (CoreException e) {
21085
// ignore
21186
e.printStackTrace();
@@ -221,19 +96,12 @@ public static boolean removeLibrariesFromProject(IProject project, ICProjectDesc
22196

22297
public static boolean addLibrariesToProject(IProject project, ICConfigurationDescription confDesc,
22398
Set<String> libraries) {
224-
Map<String, List<IPath>> foldersToChange = Libraries.addLibrariesToProject(project, confDesc,
225-
libraries);
99+
Map<String, List<IPath>> foldersToChange = Libraries.addLibrariesToProject(project, confDesc, libraries);
226100
return Libraries.adjustProjectDescription(confDesc, foldersToChange);
227101
}
228102

229-
public static Map<String, IPath> getAllAvailableLibraries(IProject project) {
230-
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
231-
if (prjDesc != null) {
232-
return Libraries.getAllInstalledLibraries(prjDesc.getActiveConfiguration());
233-
}
234-
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
235-
"Is the selected project a C/Cpp project? " + project.getName(), null)); //$NON-NLS-1$
236-
return new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
103+
public static Map<String, IPath> getAllAvailableLibraries(ICConfigurationDescription confDesc) {
104+
return Libraries.getAllInstalledLibraries(confDesc);
237105
}
238106

239107
public static Set<String> getAllImportedLibraries(IProject project) {
@@ -263,8 +131,7 @@ public static void addCodeFolder(IProject project, Path path) throws CoreExcepti
263131
}
264132
}
265133
if (projDescNeedsSaving) {
266-
coreModel.getProjectDescriptionManager().setProjectDescription(project, projectDescription,
267-
true, null);
134+
coreModel.getProjectDescriptionManager().setProjectDescription(project, projectDescription, true, null);
268135
}
269136
}
270137

0 commit comments

Comments
 (0)