Skip to content

Commit e19c8d6

Browse files
committed
first shot at #272
1 parent 860243c commit e19c8d6

File tree

13 files changed

+403
-197
lines changed

13 files changed

+403
-197
lines changed

it.baeyens.arduino.common/META-INF/MANIFEST.MF

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Import-Package: org.eclipse.cdt.core,
1818
org.eclipse.cdt.core.envvar,
1919
org.eclipse.cdt.core.model,
2020
org.eclipse.cdt.core.settings.model,
21+
org.eclipse.core.internal.resources,
2122
org.eclipse.core.resources,
2223
org.eclipse.ui.navigator
2324
Bundle-Vendor: Jan Baeyens

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ArduinoConst {
3131
public static final String KEY_ARDUINOPATH = "Arduino Path";//$NON-NLS-1$
3232
public static final String KEY_PRIVATE_LIBRARY_PATH = "Private Library Path";//$NON-NLS-1$
3333
public static final String KEY_PRIVATE_HARDWARE_PATH = "Private hardware Path";//$NON-NLS-1$
34+
public static final String KEY_PREFERENCE_MODIFICATION_STAMP = "Arduino IDE preference.txt time stamp";//$NON-NLS-1$
3435

3536
// properties keys
3637
public static final String KEY_LAST_USED_ARDUINOBOARD = "Arduino Board";//$NON-NLS-1$
@@ -126,6 +127,9 @@ public class ArduinoConst {
126127
public static final String ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.COMPILE";//$NON-NLS-1$
127128
public static final String ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.C.COMPILE";//$NON-NLS-1$
128129
public static final String ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.CPP.COMPILE";//$NON-NLS-1$
130+
public static final String ENV_KEY_JANTJE_PACKAGE_ID = ENV_KEY_JANTJE_START + "PACKAGE_ID";//$NON-NLS-1$
131+
public static final String ENV_KEY_JANTJE_ARCITECTURE_ID = ENV_KEY_JANTJE_START + "ARCHITECTURE_ID";//$NON-NLS-1$
132+
public static final String ENV_KEY_JANTJE_BOARD_ID = ENV_KEY_JANTJE_START + "BOARD_ID";//$NON-NLS-1$
129133
//
130134
// template Sketch information
131135

@@ -144,6 +148,7 @@ public class ArduinoConst {
144148
// least significant first 0xCDAB;
145149
public static final String ARDUINO_EXAMPLE_FOLDER_NAME = "examples";//$NON-NLS-1$
146150

147-
public static final String ARDUINO_IDE_ENVIRONMENT_VAR_FILE_NAME = "ArduinoIDE.txt";
151+
public static final String ARDUINO_IDE_DUMP__FILE_NAME_TRAILER = "ArduinoIDE.tmp";
152+
public static final String ARDUINO_IDE_DUMP__FILE_NAME_PREFIX = "DUMP_";
148153

149154
}

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

+48-32
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ArduinoInstancePreferences extends ArduinoConst {
2828
*/
2929
public static boolean getBuildBeforeUploadOption() {
3030

31-
switch (getGlobalValue(KEY_BUILD_BEFORE_UPLOAD_OPTION, "ASK")) {
31+
switch (getGlobalString(KEY_BUILD_BEFORE_UPLOAD_OPTION, "ASK")) {
3232
case "YES":
3333
return true;
3434
case "NO":
@@ -74,7 +74,7 @@ public void run() {
7474
* @author Jan Baeyens
7575
*/
7676
public static String getLastUsedArduinoBoardName() {
77-
return getGlobalValue(KEY_LAST_USED_ARDUINOBOARD);
77+
return getGlobalString(KEY_LAST_USED_ARDUINOBOARD, "");
7878
}
7979

8080
/**
@@ -84,7 +84,7 @@ public static String getLastUsedArduinoBoardName() {
8484
* @author Jan Baeyens
8585
*/
8686
public static String getLastUsedUploadPort() {
87-
return getGlobalValue(KEY_LAST_USED_COM_PORT);
87+
return getGlobalString(KEY_LAST_USED_COM_PORT, "");
8888
}
8989

9090
/**
@@ -94,7 +94,7 @@ public static String getLastUsedUploadPort() {
9494
* @author Jan Baeyens
9595
*/
9696
public static String getLastUsedUploadProgrammer() {
97-
return getGlobalValue(KEY_LAST_USED_PROGRAMMER, ArduinoConst.DEFAULT);
97+
return getGlobalString(KEY_LAST_USED_PROGRAMMER, ArduinoConst.DEFAULT);
9898
}
9999

100100
/**
@@ -135,19 +135,11 @@ public static void SetLastUsedArduinoBoard(String ArduinoBoardName) {
135135
setGlobalValue(KEY_LAST_USED_ARDUINOBOARD, ArduinoBoardName);
136136
}
137137

138-
public static String getGlobalValue(String key, String defaultValue) {
138+
public static String getGlobalString(String key, String defaultValue) {
139139
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
140140
return myScope.get(key, defaultValue);
141141
}
142142

143-
public static String getGlobalValue(String key) {
144-
return getGlobalValue(key, "");
145-
}
146-
147-
protected static boolean getGlobalBoolean(String key) {
148-
return getGlobalBoolean(key, false);
149-
}
150-
151143
protected static boolean getGlobalBoolean(String key, boolean def) {
152144
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
153145
return myScope.getBoolean(key, def);
@@ -158,6 +150,11 @@ protected static int getGlobalInt(String key) {
158150
return myScope.getInt(key, 0);
159151
}
160152

153+
protected static long getGlobalLong(String key) {
154+
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
155+
return myScope.getLong(key, 0);
156+
}
157+
161158
public static void setGlobalValue(String key, String Value) {
162159

163160
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
@@ -170,7 +167,7 @@ public static void setGlobalValue(String key, String Value) {
170167
}
171168
}
172169

173-
protected static void setGlobalInt(String key, int Value) {
170+
protected static void setGlobalValue(String key, int Value) {
174171
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
175172
myScope.putInt(key, Value);
176173
try {
@@ -181,7 +178,7 @@ protected static void setGlobalInt(String key, int Value) {
181178
}
182179
}
183180

184-
protected static void setGlobalBoolean(String key, boolean Value) {
181+
protected static void setGlobalValue(String key, boolean Value) {
185182
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
186183
myScope.putBoolean(key, Value);
187184
try {
@@ -192,14 +189,25 @@ protected static void setGlobalBoolean(String key, boolean Value) {
192189
}
193190
}
194191

192+
protected static void setGlobalValue(String key, long Value) {
193+
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
194+
myScope.putLong(key, Value);
195+
try {
196+
myScope.flush();
197+
} catch (BackingStoreException e) {
198+
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type long " + key));
199+
e.printStackTrace();
200+
}
201+
}
202+
195203
/**
196204
* getUseIDESettings get the UseIDESettings flag value from the preference store
197205
*
198206
* @return the value in the preference store representing the UseIDESettings flag
199207
* @author Jan Baeyens
200208
*/
201-
public static String getIDEVersion() {
202-
return (getGlobalValue(KEY_ARDUINO_IDE_VERSION));
209+
public static String getArduinoIDEVersion() {
210+
return getGlobalString(KEY_ARDUINO_IDE_VERSION, "").trim();
203211
}
204212

205213
/**
@@ -211,15 +219,15 @@ public static String getIDEVersion() {
211219
* @return true if it is arduino 1.0 or later; otherwise false
212220
*/
213221
public static boolean isArduinoIdeOne() {
214-
return !getIDEVersion().startsWith("00");
222+
return !getArduinoIDEVersion().startsWith("00");
215223
}
216224

217225
/*
218226
* This method returns the define value for the define ARDUINO
219227
*/
220-
public static String GetARDUINODefineValue() {
228+
public static String GetArduinoDefineValue() {
221229
String Ret;
222-
Ret = getIDEVersion().trim();
230+
Ret = getArduinoIDEVersion().trim();
223231
if (Ret.startsWith("1.5")) {
224232
if (Ret.contains(".")) {
225233
Ret = Ret.replace(".", "");
@@ -253,20 +261,20 @@ public static int GetLastUsedSerialLineEnd() {
253261
* @return the index of the last used setting
254262
*/
255263
public static void SetLastUsedSerialLineEnd(int LastUsedIndex) {
256-
setGlobalInt(KEY_RXTX_LAST_USED_LINE_INDES, LastUsedIndex);
264+
setGlobalValue(KEY_RXTX_LAST_USED_LINE_INDES, LastUsedIndex);
257265
}
258266

259267
public static boolean getLastUsedAutoScroll() {
260-
return getGlobalBoolean(KEY_RXTX_LAST_USED_AUTOSCROLL);
268+
return getGlobalBoolean(KEY_RXTX_LAST_USED_AUTOSCROLL, false);
261269
}
262270

263271
public static void setLastUsedAutoScroll(boolean autoScroll) {
264-
setGlobalBoolean(KEY_RXTX_LAST_USED_AUTOSCROLL, autoScroll);
272+
setGlobalValue(KEY_RXTX_LAST_USED_AUTOSCROLL, autoScroll);
265273

266274
}
267275

268276
public static String getLastUsedBoardsFile() {
269-
return getGlobalValue(KEY_LAST_USED_ARDUINO_BOARDS_FILE);
277+
return getGlobalString(KEY_LAST_USED_ARDUINO_BOARDS_FILE, "");
270278
}
271279

272280
public static void setLastUsedBoardsFile(String boardsFile) {
@@ -280,11 +288,11 @@ public static void setLastUsedMenuOption(String menuOptions) {
280288
}
281289

282290
public static String getLastUsedMenuOption() {
283-
return getGlobalValue(KEY_LAST_USED_ARDUINO_MENU_OPTIONS);
291+
return getGlobalString(KEY_LAST_USED_ARDUINO_MENU_OPTIONS, "");
284292
}
285293

286294
public static IPath getArduinoPath() {
287-
return Common.getArduinoIDEPathFromUserSelection(getGlobalValue(KEY_ARDUINOPATH));
295+
return Common.getArduinoIDEPathFromUserSelection(getGlobalString(KEY_ARDUINOPATH, ""));
288296
}
289297

290298
/**
@@ -306,12 +314,12 @@ public static boolean isConfigured(boolean showError) {
306314
}
307315

308316
public static boolean getLastUsedScopeFilter() {
309-
return getGlobalBoolean(KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION);
317+
return getGlobalBoolean(KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION, false);
310318

311319
}
312320

313321
public static void setLastUsedScopeFilter(boolean newFilter) {
314-
setGlobalBoolean(KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION, newFilter);
322+
setGlobalValue(KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION, newFilter);
315323

316324
}
317325

@@ -323,14 +331,14 @@ public static int getLastUsedDefaultSketchSelection() {
323331
}
324332

325333
public static void setLastUsedDefaultSketchSelection(int newFilter) {
326-
setGlobalInt(ENV_KEY_JANTJE_SKETCH_TEMPLATE_USE_DEFAULT, newFilter);
334+
setGlobalValue(ENV_KEY_JANTJE_SKETCH_TEMPLATE_USE_DEFAULT, newFilter);
327335
}
328336

329337
//
330338
// get/set last used sketch template folder parameters
331339
//
332340
public static String getLastTemplateFolderName() {
333-
return getGlobalValue(ENV_KEY_JANTJE_SKETCH_TEMPLATE_FOLDER);
341+
return getGlobalString(ENV_KEY_JANTJE_SKETCH_TEMPLATE_FOLDER, "");
334342
}
335343

336344
public static void setLastTemplateFolderName(String folderName) {
@@ -339,18 +347,26 @@ public static void setLastTemplateFolderName(String folderName) {
339347
}
340348

341349
public static String getPrivateLibraryPath() {
342-
return getGlobalValue(KEY_PRIVATE_LIBRARY_PATH);
350+
return getGlobalString(KEY_PRIVATE_LIBRARY_PATH, "");
343351
}
344352

345353
public static void setPrivateLibraryPath(String folderName) {
346354
setGlobalValue(KEY_PRIVATE_LIBRARY_PATH, folderName);
347355
}
348356

349357
public static String getPrivateHardwarePath() {
350-
return getGlobalValue(KEY_PRIVATE_HARDWARE_PATH);
358+
return getGlobalString(KEY_PRIVATE_HARDWARE_PATH, "");
351359
}
352360

353361
public static void setPrivateHardwarePath(String folderName) {
354362
setGlobalValue(KEY_PRIVATE_HARDWARE_PATH, folderName);
355363
}
364+
365+
public static long getStoredPreferenceModificatonStamp() {
366+
return getGlobalLong(KEY_PREFERENCE_MODIFICATION_STAMP);
367+
}
368+
369+
public static void getStoredPreferenceModificatonStamp(long stamp) {
370+
setGlobalValue(KEY_PREFERENCE_MODIFICATION_STAMP, stamp);
371+
}
356372
}

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

+46-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import java.util.Vector;
99

1010
import org.eclipse.cdt.core.CCorePlugin;
11+
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
12+
import org.eclipse.cdt.core.envvar.IContributedEnvironment;
13+
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
1114
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
1215
import org.eclipse.cdt.core.model.CoreModel;
1316
import org.eclipse.cdt.core.model.ICElement;
@@ -497,6 +500,24 @@ static public String getBuildEnvironmentVariable(IProject project, String config
497500
return getBuildEnvironmentVariable(prjDesc.getConfigurationByName(configName), EnvName, defaultvalue);
498501
}
499502

503+
/**
504+
*
505+
* Provides the build environment variable based on project and string This method does not add any knowledge.(like adding A.)
506+
*
507+
* @param project
508+
* the project that contains the environment variable
509+
*
510+
* @param EnvName
511+
* the key that describes the variable
512+
* @param defaultvalue
513+
* The return value if the variable is not found.
514+
* @return The expanded build environment variable
515+
*/
516+
static public String getBuildEnvironmentVariable(IProject project, String EnvName, String defaultvalue) {
517+
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
518+
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), EnvName, defaultvalue);
519+
}
520+
500521
/**
501522
*
502523
* Provides the build environment variable based on project and string This method does not add any knowledge.(like adding A.)
@@ -568,6 +589,16 @@ public static String getDefaultPrivateLibraryPath() {
568589
return homPath.append("Arduino").append("libraries").toString();
569590
}
570591

592+
/**
593+
* The file aduino IDE stores it's preferences in
594+
*
595+
* @return
596+
*/
597+
public static File getPreferenceFile() {
598+
IPath homPath = new Path(System.getProperty("user.home"));
599+
return homPath.append(".arduino").append("preferences.txt").toFile();
600+
}
601+
571602
/**
572603
* same as getDefaultLibPath but for the hardware folder
573604
*
@@ -578,15 +609,27 @@ public static String getDefaultPrivateHardwarePath() {
578609
return homPath.append("Arduino").append("hardware").toString();
579610
}
580611

581-
public static File getArduinoIDEEnvVarsName() {
582-
return getPluginWritePath(ARDUINO_IDE_ENVIRONMENT_VAR_FILE_NAME);
612+
public static File getArduinoIdeDumpName(String packageName, String architecture, String boardID) {
613+
return getPluginWritePath(ARDUINO_IDE_DUMP__FILE_NAME_PREFIX + packageName + "_" + architecture + "_" + boardID + "_"
614+
+ ARDUINO_IDE_DUMP__FILE_NAME_TRAILER);
583615
}
584616

585617
private static File getPluginWritePath(String name) {
586618
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
587619
File ret = myWorkspaceRoot.getLocation().append(name).toFile();
588620
return ret;
589-
// return PlatformUI.getWorkbench(). .getWorkbench().getActiveWorkbenchWindow();
621+
}
622+
623+
public static File getWorkspaceRoot() {
624+
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
625+
File ret = myWorkspaceRoot.getLocation().toFile();
626+
return ret;
627+
}
628+
629+
public static void setBuildEnvironmentVariable(IContributedEnvironment contribEnv, ICConfigurationDescription confdesc, String key, String value) {
630+
IEnvironmentVariable var = new EnvironmentVariable(key, value);
631+
contribEnv.addVariable(var, confdesc);
632+
590633
}
591634

592635
}

0 commit comments

Comments
 (0)