Skip to content

Commit 6849e71

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 45b6ae3 + cc877cf commit 6849e71

File tree

27 files changed

+1312
-886
lines changed

27 files changed

+1312
-886
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Common.java

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import java.io.File;
44
import java.util.HashSet;
5-
import java.util.Vector;
5+
import java.util.List;
6+
import java.util.Set;
67

78
import org.eclipse.cdt.core.CCorePlugin;
89
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
@@ -37,16 +38,18 @@ public class Common extends InstancePreferences {
3738
// request him to disconnect
3839
// when we need the serial port
3940

41+
static Set<IProject> fProjects = new HashSet<>();
42+
4043
/**
4144
* This method is used to register a serial user. A serial user is alerted
4245
* when the serial port will be disconnected (for instance for a upload) The
4346
* serial user is requested to act appropriately Only 1 serial user can be
4447
* registered at a given time. No check is done.
4548
*
46-
* @param SerialUser
49+
* @param serialUser
4750
*/
48-
public static void registerSerialUser(ISerialUser SerialUser) {
49-
OtherSerialUser = SerialUser;
51+
public static void registerSerialUser(ISerialUser serialUser) {
52+
OtherSerialUser = serialUser;
5053
}
5154

5255
/**
@@ -85,14 +88,14 @@ public static void UnRegisterSerialUser() {
8588
* redirect input, allowed in Unix filenames, see Note 1 > greater than used
8689
* to redirect output, allowed in Unix filenames, see Note 1 . period or dot
8790
*
88-
* @param Name
91+
* @param name
8992
* the string that needs to be checked
9093
* @return a name safe to create files or folders
9194
*/
92-
public static String MakeNameCompileSafe(String Name) {
93-
char badChars[] = { ' ', '/', '.', '/', ':', ' ', '\\', '(', ')', '*', '?', '%', '|', '<', '>', ',', '-' };
95+
public static String MakeNameCompileSafe(String name) {
96+
char[] badChars = { ' ', '/', '.', '/', ':', ' ', '\\', '(', ')', '*', '?', '%', '|', '<', '>', ',', '-' };
9497

95-
String ret = Name.trim();
98+
String ret = name.trim();
9699
for (char curchar : badChars) {
97100
ret = ret.replace(curchar, '_');
98101
}
@@ -105,39 +108,37 @@ public static String MakeNameCompileSafe(String Name) {
105108
* @param project
106109
* The project for which the property is needed
107110
*
108-
* @param Tag
111+
* @param tag
109112
* The tag identifying the property to read
110113
* @return returns the property when found. When not found returns an empty
111114
* string
112115
*/
113-
public static String getPersistentProperty(IProject project, String Tag) {
116+
public static String getPersistentProperty(IProject project, String tag) {
114117
try {
115-
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, Tag));
118+
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, tag));
116119
if (sret == null) {
117-
sret = project.getPersistentProperty(new QualifiedName(EMPTY_STRING, Tag)); // for
120+
sret = project.getPersistentProperty(new QualifiedName(EMPTY_STRING, tag)); // for
118121
// downwards
119122
// compatibility
120123
if (sret == null)
121124
sret = EMPTY_STRING;
122125
}
123126
return sret;
124127
} catch (CoreException e) {
125-
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
126-
// e.printStackTrace();
128+
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + tag, e)); //$NON-NLS-1$
127129
return EMPTY_STRING;
128130
}
129131
}
130132

131-
public static int getPersistentPropertyInt(IProject project, String Tag, int defaultValue) {
133+
public static int getPersistentPropertyInt(IProject project, String tag, int defaultValue) {
132134
try {
133-
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, Tag));
135+
String sret = project.getPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, tag));
134136
if (sret == null) {
135137
return defaultValue;
136138
}
137139
return Integer.parseInt(sret);
138140
} catch (CoreException e) {
139-
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
140-
// e.printStackTrace();
141+
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + tag, e)); //$NON-NLS-1$
141142
return defaultValue;
142143
}
143144
}
@@ -148,15 +149,15 @@ public static int getPersistentPropertyInt(IProject project, String Tag, int def
148149
* @param project
149150
* The project for which the property needs to be set
150151
*
151-
* @param Tag
152+
* @param tag
152153
* The tag identifying the property to read
153154
* @return returns the property when found. When not found returns an empty
154155
* string
155156
*/
156-
public static void setPersistentProperty(IProject project, String Tag, String Value) {
157+
public static void setPersistentProperty(IProject project, String tag, String value) {
157158
try {
158-
project.setPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, Tag), Value);
159-
project.setPersistentProperty(new QualifiedName(EMPTY_STRING, Tag), Value); // for
159+
project.setPersistentProperty(new QualifiedName(CORE_PLUGIN_ID, tag), value);
160+
project.setPersistentProperty(new QualifiedName(EMPTY_STRING, tag), value); // for
160161
// downwards
161162
// compatibility
162163
} catch (CoreException e) {
@@ -166,8 +167,8 @@ public static void setPersistentProperty(IProject project, String Tag, String Va
166167
}
167168
}
168169

169-
public static void setPersistentProperty(IProject project, String Tag, int Value) {
170-
setPersistentProperty(project, Tag, Integer.toString(Value));
170+
public static void setPersistentProperty(IProject project, String tag, int value) {
171+
setPersistentProperty(project, tag, Integer.toString(value));
171172
}
172173

173174
/**
@@ -177,7 +178,7 @@ public static void setPersistentProperty(IProject project, String Tag, int Value
177178
* the status information to log
178179
*/
179180
public static void log(IStatus status) {
180-
int style = StatusManager.LOG;
181+
int style;
181182

182183
if (status.getSeverity() == IStatus.ERROR) {
183184
style = StatusManager.LOG | StatusManager.SHOW | StatusManager.BLOCK;
@@ -209,20 +210,20 @@ public static String UploadPortPrefix() {
209210
/**
210211
* ToInt converts a string to a integer in a save way
211212
*
212-
* @param Number
213+
* @param number
213214
* is a String that will be converted to an integer. Number can
214215
* be null or empty and can contain leading and trailing white
215216
* space
216217
* @return The integer value represented in the string based on parseInt
217218
* @see parseInt. After error checking and modifications parseInt is used
218219
* for the conversion
219220
**/
220-
public static int ToInt(String Number) {
221-
if (Number == null)
221+
public static int ToInt(String number) {
222+
if (number == null)
222223
return 0;
223-
if (Number.isEmpty())
224+
if (number.isEmpty())
224225
return 0;
225-
return Integer.parseInt(Number.trim());
226+
return Integer.parseInt(number.trim());
226227
}
227228

228229
public static IWorkbenchWindow getActiveWorkbenchWindow() {
@@ -237,8 +238,6 @@ public static IWorkbenchPage getActivePage() {
237238
return null;
238239
}
239240

240-
static HashSet<IProject> fProjects = new HashSet<>();
241-
242241
public static boolean StopSerialMonitor(String mComPort) {
243242
if (OtherSerialUser != null) {
244243
return OtherSerialUser.PauzePort(mComPort);
@@ -254,9 +253,9 @@ public static void StartSerialMonitor(String mComPort) {
254253
}
255254

256255
public static String[] listComPorts() {
257-
Vector<String> SerialList = Serial.list();
258-
String outgoing[] = new String[SerialList.size()];
259-
SerialList.copyInto(outgoing);
256+
List<String> serialList = Serial.list();
257+
String[] outgoing = new String[serialList.size()];
258+
serialList.toArray(outgoing);
260259
return outgoing;
261260
}
262261

@@ -294,16 +293,16 @@ public static String getLineEnding(int selectionIndex) {
294293
* the project that contains the environment variable
295294
* @param configName
296295
* the project configuration to use
297-
* @param EnvName
296+
* @param envName
298297
* the key that describes the variable
299298
* @param defaultvalue
300299
* The return value if the variable is not found.
301300
* @return The expanded build environment variable
302301
*/
303-
static public String getBuildEnvironmentVariable(IProject project, String configName, String EnvName,
302+
static public String getBuildEnvironmentVariable(IProject project, String configName, String envName,
304303
String defaultvalue) {
305304
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
306-
return getBuildEnvironmentVariable(prjDesc.getConfigurationByName(configName), EnvName, defaultvalue);
305+
return getBuildEnvironmentVariable(prjDesc.getConfigurationByName(configName), envName, defaultvalue);
307306
}
308307

309308
/**
@@ -314,15 +313,15 @@ static public String getBuildEnvironmentVariable(IProject project, String config
314313
* @param project
315314
* the project that contains the environment variable
316315
*
317-
* @param EnvName
316+
* @param envName
318317
* the key that describes the variable
319318
* @param defaultvalue
320319
* The return value if the variable is not found.
321320
* @return The expanded build environment variable
322321
*/
323-
static public String getBuildEnvironmentVariable(IProject project, String EnvName, String defaultvalue) {
322+
static public String getBuildEnvironmentVariable(IProject project, String envName, String defaultvalue) {
324323
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
325-
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), EnvName, defaultvalue);
324+
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), envName, defaultvalue);
326325
}
327326

328327
/**
@@ -332,24 +331,24 @@ static public String getBuildEnvironmentVariable(IProject project, String EnvNam
332331
*
333332
* @param project
334333
* the project that contains the environment variable
335-
* @param EnvName
334+
* @param envName
336335
* the key that describes the variable
337336
* @param defaultvalue
338337
* The return value if the variable is not found.
339338
* @return The expanded build environment variable
340339
*/
341340
static public String getBuildEnvironmentVariable(ICConfigurationDescription configurationDescription,
342-
String EnvName, String defaultvalue) {
341+
String envName, String defaultvalue) {
343342

344-
return getBuildEnvironmentVariable(configurationDescription, EnvName, defaultvalue, true);
343+
return getBuildEnvironmentVariable(configurationDescription, envName, defaultvalue, true);
345344
}
346345

347346
static public String getBuildEnvironmentVariable(ICConfigurationDescription configurationDescription,
348-
String EnvName, String defaultvalue, boolean expanded) {
347+
String envName, String defaultvalue, boolean expanded) {
349348

350349
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
351350
try {
352-
return envManager.getVariable(EnvName, configurationDescription, expanded).getValue();
351+
return envManager.getVariable(envName, configurationDescription, expanded).getValue();
353352
} catch (Exception e) {// ignore all errors and return the default value
354353
}
355354
return defaultvalue;
@@ -374,8 +373,7 @@ public static String getDefaultPrivateHardwarePath() {
374373

375374
public static File getWorkspaceRoot() {
376375
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
377-
File ret = myWorkspaceRoot.getLocation().toFile();
378-
return ret;
376+
return myWorkspaceRoot.getLocation().toFile();
379377
}
380378

381379
public static void setBuildEnvironmentVariable(IContributedEnvironment contribEnv,

it.baeyens.arduino.common/src/it/baeyens/arduino/common/InstancePreferences.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import org.osgi.service.prefs.BackingStoreException;
1818

1919
/**
20-
* ArduinoPreferences is a class containing only static methods that help managing the preferences.
20+
* ArduinoPreferences is a class containing only static methods that help
21+
* managing the preferences.
2122
*
2223
* @author jan Baeyens
2324
*
@@ -46,10 +47,12 @@ public static void setAutomaticallyIncludeLibraries(boolean value) {
4647
}
4748

4849
/***
49-
* get the stored option whether a build before the upload is wanted or not. If nothing is stored the option is ask and this method will pop up a
50+
* get the stored option whether a build before the upload is wanted or not.
51+
* If nothing is stored the option is ask and this method will pop up a
5052
* dialogbox
5153
*
52-
* @return true if a build is wanted before upload false if no build is wanted before upload
54+
* @return true if a build is wanted before upload false if no build is
55+
* wanted before upload
5356
*/
5457
public static boolean getBuildBeforeUploadOption() {
5558

@@ -93,7 +96,8 @@ public void run() {
9396
}
9497

9598
/**
96-
* This method reads the name of the last used arduino board from the instance preferences
99+
* This method reads the name of the last used arduino board from the
100+
* instance preferences
97101
*
98102
* @return the Arduino Board name
99103
* @author Jan Baeyens
@@ -164,7 +168,8 @@ public static void setGlobalValue(String key, String Value) {
164168
try {
165169
myScope.flush();
166170
} catch (BackingStoreException e) {
167-
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type string " + key)); //$NON-NLS-1$
171+
Common.log(
172+
new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type string " + key)); //$NON-NLS-1$
168173
e.printStackTrace();
169174
}
170175
}
@@ -186,7 +191,8 @@ protected static void setGlobalValue(String key, boolean Value) {
186191
try {
187192
myScope.flush();
188193
} catch (BackingStoreException e) {
189-
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type boolean " + key)); //$NON-NLS-1$
194+
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID,
195+
"failed to set global variable of type boolean " + key)); //$NON-NLS-1$
190196
e.printStackTrace();
191197
}
192198
}
@@ -197,13 +203,15 @@ protected static void setGlobalValue(String key, long Value) {
197203
try {
198204
myScope.flush();
199205
} catch (BackingStoreException e) {
200-
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type long " + key)); //$NON-NLS-1$
206+
Common.log(
207+
new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type long " + key)); //$NON-NLS-1$
201208
e.printStackTrace();
202209
}
203210
}
204211

205212
/**
206-
* This method returns the index of the last used line ending options are CR LF CR+LF none
213+
* This method returns the index of the last used line ending options are CR
214+
* LF CR+LF none
207215
*
208216
* @return the index of the last used setting
209217
*/
@@ -212,7 +220,8 @@ public static int GetLastUsedSerialLineEnd() {
212220
}
213221

214222
/**
215-
* This method returns the index of the last used line ending options are CR LF CR+LF none
223+
* This method returns the index of the last used line ending options are CR
224+
* LF CR+LF none
216225
*
217226
* @return the index of the last used setting
218227
*/
@@ -269,7 +278,8 @@ public static void setConfigured() {
269278
}
270279

271280
/**
272-
* This method returns boolean whether the plugin is properly configured The plugin is configured properly if a board has been installed
281+
* This method returns boolean whether the plugin is properly configured The
282+
* plugin is configured properly if a board has been installed
273283
*
274284
* @return
275285
*/
@@ -326,15 +336,17 @@ public static void setLastUsedExamples(String[] exampleNames) {
326336
}
327337

328338
public static String[] getPrivateLibraryPaths() {
329-
return getGlobalString(KEY_PRIVATE_LIBRARY_PATHS, Common.getDefaultPrivateLibraryPath()).split(File.pathSeparator);
339+
return getGlobalString(KEY_PRIVATE_LIBRARY_PATHS, Common.getDefaultPrivateLibraryPath())
340+
.split(File.pathSeparator);
330341
}
331342

332343
public static void setPrivateLibraryPaths(String[] folderName) {
333-
setGlobalValue(KEY_PRIVATE_LIBRARY_PATHS, String.join(File.pathSeparator, folderName)); //$NON-NLS-1$
344+
setGlobalValue(KEY_PRIVATE_LIBRARY_PATHS, String.join(File.pathSeparator, folderName));
334345
}
335346

336347
public static String[] getPrivateHardwarePaths() {
337-
return getGlobalString(KEY_PRIVATE_HARDWARE_PATHS, Common.getDefaultPrivateHardwarePath()).split(File.pathSeparator);
348+
return getGlobalString(KEY_PRIVATE_HARDWARE_PATHS, Common.getDefaultPrivateHardwarePath())
349+
.split(File.pathSeparator);
338350
}
339351

340352
public static void setPrivateHardwarePaths(String[] folderName) {
@@ -347,8 +359,8 @@ public static void setPrivateHardwarePaths(String[] folderName) {
347359
* @return a list of all the folder locations that can contain hardware
348360
*/
349361
public static String[] getHardwarePaths() {
350-
return (getGlobalString(KEY_PRIVATE_HARDWARE_PATHS, EMPTY_STRING) + File.pathSeparator + ConfigurationPreferences.getInstallationPath())
351-
.split(File.pathSeparator);
362+
return (getGlobalString(KEY_PRIVATE_HARDWARE_PATHS, EMPTY_STRING) + File.pathSeparator
363+
+ ConfigurationPreferences.getInstallationPath()).split(File.pathSeparator);
352364
}
353365

354366
}

0 commit comments

Comments
 (0)