Skip to content

Commit ff3c5d0

Browse files
committed
Framework to allow boards.txt and platform.txt files to be inside the plugin.
1 parent fa0d062 commit ff3c5d0

10 files changed

+115
-173
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,9 @@ public class ArduinoConst {
154154

155155
public static final String ARDUINO_IDE_DUMP__FILE_NAME_TRAILER = "ArduinoIDE.tmp";
156156
public static final String ARDUINO_IDE_DUMP__FILE_NAME_PREFIX = "DUMP_";
157+
public static final String PRE_PROCESSING_BOARDS_TXT = "pre_processing_boards.txt";
158+
public static final String POST_PROCESSING_BOARDS_TXT = "post_processing_boards.txt";
159+
public static final String PRE_PROCESSING_PLATFORM_TXT = "pre_processing_platform.txt";
160+
public static final String POST_PROCESSING_PLATFORM_TXT = "post_processing_platform.txt";
157161

158162
}

it.baeyens.arduino.core/config/arduino_eclipse_plugin.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gemma.AA.post.processing.boards.6.1.5=true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gemma.AA.post.processing.boards.default=true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AA.post.processing.platform.default=true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gemma.AA.pre.processing.boards.default=true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AA.pre.processing.platform.default=true

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/ArduinoBoards.java

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,6 @@ public Map<String, String> getSection(String SectionKey) {
5454
return mArduinoSupportedBoards.get(SectionKey);
5555
}
5656

57-
// /**
58-
// * Generic method to read a value from the boards file
59-
// *
60-
// * @param boardName
61-
// * @param Key
62-
// * @return
63-
// */
64-
// private String getBoardSetting(String boardName, String Key, String
65-
// defaultValue) {
66-
// if (!mLastLoadedBoard.equals(boardName)) {
67-
// mLastLoadedBoard = boardName;
68-
// String mapName = getBoardIDFromName(boardName);
69-
// settings = mArduinoSupportedBoards.get(mapName);
70-
// }
71-
//
72-
// if (settings != null) {
73-
// String TagContent = settings.get(Key);
74-
// if (TagContent != null)
75-
// return TagContent;
76-
// } else {
77-
// IStatus status = new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
78-
// "Settings in ArduinoBoards is null. This should never happen.", null);
79-
// Common.log(status);
80-
// }
81-
// return defaultValue;
82-
// }
83-
8457
/**
8558
* Get all the options in the boards.txt file
8659
*
@@ -144,76 +117,6 @@ public String[] getMenuItemNames(String menuLabel, String boardName) {
144117
return ret.toArray(new String[ret.size()]);
145118
}
146119

147-
//
148-
// /**
149-
// * getMCUName returns the mcu name for a given board. <br/>
150-
// * This function assumes (and does not test so will fail) that the board
151-
// file has been loaded
152-
// *
153-
// * @param boardName
154-
// * the board name for which the mcu name will be returned
155-
// * @return the MCU name
156-
// * @author Jan Baeyens
157-
// */
158-
// public String getMCUName(String boardName) {
159-
// return getBoardSetting(boardName, ArduinoConst.ProcessorTypeKeyTAG, "");
160-
// }
161-
//
162-
// /**
163-
// * getMCUFrequency returns the mcu frequency for a given board. <br/>
164-
// * This function assumes (and does not test so will fail) that the board
165-
// file has been loaded
166-
// *
167-
// * @param boardName
168-
// * the board name for which the mcu frequency will be returned
169-
// * @return the MCU frequency
170-
// * @author Jan Baeyens
171-
// */
172-
// public String getMCUFrequency(String boardName) {
173-
// return getBoardSetting(boardName, ArduinoConst.FrequencyKeyTAG,
174-
// "").replaceFirst("L", " ").trim();
175-
// }
176-
//
177-
// /**
178-
// * returns the variant of the arduino board<br/>
179-
// * This function assumes (and does not test so will fail) that the board
180-
// file has been loaded
181-
// *
182-
// * @param boardName
183-
// * the board name for which the board variant will be returned
184-
// * @return the Arduino board variant
185-
// * @author Jan Baeyens
186-
// */
187-
// public String getBoardVariant(String boardName) {
188-
// return getBoardSetting(boardName, ArduinoConst.BoardVariantTAG, "");
189-
// }
190-
//
191-
// /**
192-
// * getDisableFlushing returns the disable flushing flag for a given board.
193-
// <br/>
194-
// * This function assumes (and does not test so will fail) that the board
195-
// file has been loaded. This function is currently unused
196-
// *
197-
// * @param boardName
198-
// * the board name for which the disable flushing flag will be returned
199-
// * @return disable flushing flag
200-
// * @author Jan Baeyens
201-
// */
202-
// public boolean getDisableFlushing(String boardName) {
203-
// return getBoardSetting(boardName, ArduinoConst.disableFlushingKeyTAG,
204-
// "").equalsIgnoreCase("TRUE");
205-
// }
206-
//
207-
// public String getUploadTool(String boardName) {
208-
// return getBoardSetting(boardName, ArduinoConst.UploadToolTAG,
209-
// ArduinoConst.UploadToolDefault);
210-
// }
211-
//
212-
// public String getBuildCoreFolder(String boardName) {
213-
// return getBoardSetting(boardName, ArduinoConst.BoardBuildCoreFolder,
214-
// ArduinoConst.BoardBuildCoreFolderdefault);
215-
//
216-
// }
217120
/**
218121
* GetArduinoBoards returns all the boards that are in the currently loaded board.txt file.
219122
*
@@ -261,6 +164,10 @@ public boolean LoadBoardsFile(String boardsFile) {
261164
return LoadBoardsFile();
262165
}
263166

167+
public boolean exists() {
168+
return mLastLoadedBoardsFile.exists();
169+
}
170+
264171
/**
265172
* Load loads the board.txt file based on the arduino path.
266173
*

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/ArduinoHelpers.java

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,8 @@ private static void setTheEnvironmentVariablesAddAFile(IContributedEnvironment c
621621
} else if (value.contains(BUILD_PATH_SYSCALLS_MTK)) {
622622
value = value.replace(BUILD_PATH_SYSCALLS_MTK, BUILD_PATH_ARDUINO_SYSCALLS_MTK);
623623
}
624-
IEnvironmentVariable envVar = new EnvironmentVariable(MakeKeyString(var[0]), MakeEnvironmentString(value));
624+
IEnvironmentVariable envVar = new EnvironmentVariable(MakeKeyString(var[0]), MakeEnvironmentString(value,
625+
ArduinoConst.ENV_KEY_ARDUINO_START));
625626
contribEnv.addVariable(envVar, confDesc);
626627
}
627628
}
@@ -660,7 +661,7 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
660661
// if it is not a menu item add it
661662
if (!currentPair.getKey().startsWith("menu.")) {
662663
String keyString = MakeKeyString(currentPair.getKey());
663-
String valueString = MakeEnvironmentString(currentPair.getValue());
664+
String valueString = MakeEnvironmentString(currentPair.getValue(), ArduinoConst.ENV_KEY_ARDUINO_START);
664665
contribEnv.addVariable(new EnvironmentVariable(keyString, valueString), confDesc);
665666
} else {
666667

@@ -672,7 +673,7 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
672673
String StartValue = "menu." + menuID + "." + menuItemID + ".";
673674
if (currentPair.getKey().startsWith(StartValue)) {
674675
String keyString = MakeKeyString(currentPair.getKey().substring(StartValue.length()));
675-
String valueString = MakeEnvironmentString(currentPair.getValue());
676+
String valueString = MakeEnvironmentString(currentPair.getValue(), ArduinoConst.ENV_KEY_ARDUINO_START);
676677
contribEnv.addVariable(new EnvironmentVariable(keyString, valueString), confDesc);
677678
}
678679
}
@@ -714,8 +715,9 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
714715
for (Entry<String, String> curOption : menuSectionMap.entrySet()) {
715716
if (curOption.getKey().startsWith(keyStartsWithValue)) {
716717
String key = curOption.getKey().substring(keyStartsWithValue.length());
717-
contribEnv
718-
.addVariable(new EnvironmentVariable(MakeKeyString(key), MakeEnvironmentString(curOption.getValue())), confDesc);
718+
contribEnv.addVariable(
719+
new EnvironmentVariable(MakeKeyString(key), MakeEnvironmentString(curOption.getValue(),
720+
ArduinoConst.ENV_KEY_ARDUINO_START)), confDesc);
719721
}
720722
}
721723

@@ -760,83 +762,44 @@ private static boolean isThisMenuItemSelected(ArduinoBoards boardsFile, ICConfig
760762

761763
public static void setTheEnvironmentVariables(IProject project, ICConfigurationDescription confDesc, boolean debugCompilerSettings) {
762764

765+
// first get all the data we need
763766
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
764767
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
765768

766769
IPath boardFileName = new Path(Common.getBuildEnvironmentVariable(confDesc, ArduinoConst.ENV_KEY_JANTJE_BOARDS_FILE,
767770
ArduinoInstancePreferences.getLastUsedBoardsFile()));
768771
IPath localPlatformFilename = new Path(Common.getBuildEnvironmentVariable(confDesc, ArduinoConst.ENV_KEY_JANTJE_PLATFORM_FILE, ""));
769772

770-
/*
771-
* Trying to find the file in the plugin as described here :http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/
772-
*/
773-
// Bundle bundle = Platform.getBundle(ArduinoConst.CORE_PLUGIN_ID);
774-
// URL fileURL = bundle.getEntry("config/arduino_eclipse_plugin.txt");
775-
// File file = null;
776-
// try {
777-
// file = new File(FileLocator.resolve(fileURL).toURI());
778-
// } catch (URISyntaxException e1) {
779-
// e1.printStackTrace();
780-
// } catch (IOException e1) {
781-
// e1.printStackTrace();
782-
// }
783-
// if (file == null) {
784-
// Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
785-
// "Your setup has gotten corrupt. Missing config/arduino_eclipse_plugin.txt file."));
786-
// return;
787-
// }
788-
// IPath arduinoEclipsePluginFile = new Path(file.getAbsolutePath());
789-
790-
/*
791-
* try the second method as the first method fails
792-
*/
793-
// URL url;
794-
// try {
795-
// url = new URL("platform:/plugin/it.baeyens.arduino.core/config/arduino_eclipse_plugin.txt");
796-
// } catch (MalformedURLException e) {
797-
// // TODO Auto-generated catch block
798-
// e.printStackTrace();
799-
// return;
800-
// }
801-
// File file = null;
802-
// try {
803-
// URL resolved_url = FileLocator.resolve(url);
804-
// URI resolverdURI = resolved_url.toURI();
805-
// file = new File(resolverdURI);
806-
// } catch (URISyntaxException e1) {
807-
// e1.printStackTrace();
808-
// } catch (IOException e1) {
809-
// e1.printStackTrace();
810-
// } catch (Exception e1) {
811-
// e1.printStackTrace();
812-
// }
813-
// if (file == null) {
814-
// Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
815-
// "Your setup has gotten corrupt. Missing config/arduino_eclipse_plugin.txt file."));
816-
// return;
817-
// }
818-
// IPath arduinoEclipsePluginFile = new Path(file.getAbsolutePath());
819-
820773
String boardID = Common.getBuildEnvironmentVariable(confDesc, ArduinoConst.ENV_KEY_JANTJE_BOARD_ID, "");
821774
String architecture = Common.getBuildEnvironmentVariable(confDesc, ArduinoConst.ENV_KEY_JANTJE_ARCITECTURE_ID, "");
822775
String packageName = Common.getBuildEnvironmentVariable(confDesc, ArduinoConst.ENV_KEY_JANTJE_PACKAGE_ID, "");
823776
File anduinoIDEEnvNamesFile = Common.getArduinoIdeDumpName(packageName, architecture, boardID);
824777
IPath anduinoIDEEnvNamesPath = new Path(anduinoIDEEnvNamesFile.toString());
825778
architecture = architecture.toUpperCase();
779+
IPath workspacePath = new Path(Common.getWorkspaceRoot().getAbsolutePath());
780+
ArduinoBoards pluginPreProcessingBoardsTxt = new ArduinoBoards(workspacePath.append(ArduinoConst.PRE_PROCESSING_BOARDS_TXT).toString());
781+
ArduinoBoards pluginPostProcessingBoardsTxt = new ArduinoBoards(workspacePath.append(ArduinoConst.POST_PROCESSING_BOARDS_TXT).toString());
782+
IPath pluginPreProcessingPlatformTxt = new Path(workspacePath.append(ArduinoConst.PRE_PROCESSING_PLATFORM_TXT).toString());
783+
IPath pluginPostProcessingPlatformTxt = new Path(workspacePath.append(ArduinoConst.POST_PROCESSING_PLATFORM_TXT).toString());
784+
ArduinoBoards boardsFile = new ArduinoBoards(boardFileName.toOSString());
785+
if (!(pluginPreProcessingBoardsTxt.exists() && pluginPostProcessingBoardsTxt.exists())) {
786+
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Plugin is not properly configured. Please reconfigure plugin."));
787+
return;
788+
}
789+
790+
// Now we have all info we can start processing
826791

827792
// first remove all Arduino Variables so there is no memory effect
828793
RemoveAllArduinoEnvironmentVariables(contribEnv, confDesc);
829794

830-
// process the default env variables first. This way the platform.txt
831-
// and boards.txt will
832-
// overwrite the default settings
833795
setTheEnvironmentVariablesSetTheDefaults(contribEnv, confDesc, localPlatformFilename);
834796

797+
setTheEnvironmentVariablesAddAFile(contribEnv, confDesc, pluginPreProcessingPlatformTxt);
798+
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, pluginPreProcessingBoardsTxt, boardID, true);
799+
835800
// Do some magic for the arduino:arduino stuff
836-
ArduinoBoards boardsFile = new ArduinoBoards(boardFileName.toOSString());
837801
setTheEnvironmentVariablesRedirectToOtherVendors(contribEnv, confDesc, boardsFile, boardID, architecture.toLowerCase());// TOFIX again some
838802
// dirty thing
839-
840803
// process the dump file from the arduino IDE
841804
if (anduinoIDEEnvNamesFile.exists()) {
842805
setTheEnvironmentVariablesAddAFile(contribEnv, confDesc, anduinoIDEEnvNamesPath);
@@ -856,19 +819,15 @@ public static void setTheEnvironmentVariables(IProject project, ICConfigurationD
856819
// now process the boards file
857820
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, boardsFile, boardID, true);
858821

859-
// also process the file as part of the plugin
860-
// if (arduinoEclipsePluginFile.toFile().exists()) {
861-
// ArduinoBoards myBoardsFile = new ArduinoBoards(arduinoEclipsePluginFile.toOSString());
862-
// setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, myBoardsFile, boardID, false);
863-
// }
822+
setTheEnvironmentVariablesAddAFile(contribEnv, confDesc, pluginPostProcessingPlatformTxt);
823+
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, pluginPostProcessingBoardsTxt, boardID, true);
864824

865-
// Do some post processing
825+
// Do some coded post processing
866826
setTheEnvironmentVariablesPostProcessing(contribEnv, confDesc);
867827

868828
// If this is a debug config we modify the environment variables for compilation
869829
if (debugCompilerSettings) {
870830
setTheEnvironmentVariablesModifyDebugCompilerSettings(confDesc, envManager, contribEnv);
871-
872831
}
873832

874833
}
@@ -1083,12 +1042,12 @@ private static void setTheEnvironmentVariablesModifyDebugCompilerSettings(ICConf
10831042
* the value string as read from the file
10841043
* @return the string to be stored as value for the environment variable
10851044
*/
1086-
public static String MakeEnvironmentString(String inputString) {
1045+
public static String MakeEnvironmentString(String inputString, String keyPrefix) {
10871046
// String ret = inputString.replaceAll("-o \"\\{object_file}\"",
10881047
// "").replaceAll("\"\\{object_file}\"",
10891048
// "").replaceAll("\"\\{source_file}\"", "")
10901049
// .replaceAll("\\{", "\\${" + ArduinoConst.ENV_KEY_START);
1091-
String ret = inputString.replaceAll("\\{(?!\\{)", "\\${" + ArduinoConst.ENV_KEY_ARDUINO_START);
1050+
String ret = inputString.replaceAll("\\{(?!\\{)", "\\${" + keyPrefix);
10921051
StringBuilder sb = new StringBuilder(ret);
10931052
String regex = "\\{[^}]*\\}";
10941053
Pattern p = Pattern.compile(regex); // Create the pattern.

0 commit comments

Comments
 (0)