summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java')
-rw-r--r--org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java95
1 files changed, 89 insertions, 6 deletions
diff --git a/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java b/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java
index 6fce4fe..1cd3818 100644
--- a/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java
+++ b/org.rtems.cdt.toolchain2/org/rtems/cdt/Storage.java
@@ -16,6 +16,8 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IProject;
@@ -26,6 +28,18 @@ import org.eclipse.core.runtime.QualifiedName;
import org.rtems.cdt.Activator;
public class Storage {
+ private static final String OPTION_SEPARATOR = "\0";
+
+ private static final String VALUE_START_TOKEN = "\t";
+
+ private static final int EXPECT_OPTION = 0;
+
+ private static final int EXPECT_COMMAND = 1;
+
+ private static final int EXPECT_KEY = 2;
+
+ private static final int TOOL_COMPLETE = 3;
+ ;
public static String getPristineProperty( IProject project, String key) {
String value = null;
@@ -43,7 +57,7 @@ public class Storage {
if (value == null) {
if (key.startsWith( Constants.TOOL_KEY_PREFIX)) {
- reloadBSPInformation( project);
+ updateTools( project);
} else {
value = Activator.getDefault().getPreferenceStore().getString( key);
setProperty( project, key, value);
@@ -61,7 +75,7 @@ public class Storage {
}
}
- public static void reloadBSPInformation( IProject project) {
+ public static void updateTools( IProject project) {
// Create make process builder
ProcessBuilder pb = new ProcessBuilder( "make");
@@ -77,19 +91,88 @@ public class Storage {
pb.directory( Activator.getDefault().getMakefileLocation().toFile());
// Start make process and parse its output
+ Process p = null;
try {
- Process p = pb.start();
+ p = pb.start();
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader( new InputStreamReader( is));
- String line;
- while ((line = br.readLine()) != null) {
- System.out.println(line);
+ String line = br.readLine();
+ String key = null;
+ String command = null;
+ List<String> options = new LinkedList<String>();
+ int state = EXPECT_KEY;
+ while (line != null) {
+ switch (state) {
+ case EXPECT_OPTION:
+ if (line.startsWith( VALUE_START_TOKEN)) {
+ options.add( line.substring( 1));
+ } else {
+ state = TOOL_COMPLETE;
+ continue;
+ }
+ break;
+ case EXPECT_COMMAND:
+ if (line.startsWith( VALUE_START_TOKEN)) {
+ command = line.substring( 1);
+ state = EXPECT_OPTION;
+ } else {
+ throw new IOException( "Unexpected line format");
+ }
+ break;
+ case EXPECT_KEY:
+ if (line.length() > Constants.TOOL_KEY_PREFIX.length()) {
+ key = line;
+ state = EXPECT_COMMAND;
+ } else {
+ throw new IOException( "Unexpected line format");
+ }
+ break;
+ case TOOL_COMPLETE:
+ updateTool( project, key, command, options);
+ options.clear();
+ state = EXPECT_KEY;
+ continue;
+ default:
+ throw new IOException( "Unexpected state");
+ }
+ line = br.readLine();
+ }
+ if (state == EXPECT_OPTION) {
+ updateTool( project, key, command, options);
}
} catch (IOException e) {
e.printStackTrace();
+ } finally {
+ while (true) {
+ try {
+ p.waitFor();
+ break;
+ } catch (InterruptedException e) {
+ continue;
+ }
+ }
}
}
+ private static void updateTool( IProject project, String toolKey, String command, List<String> options) {
+ String optionsValue = new String();
+ if (!options.isEmpty()) {
+ optionsValue = options.get( 0);
+ options.remove( 0);
+ }
+ for (String option : options) {
+ optionsValue += OPTION_SEPARATOR + option;
+ }
+ setProperty( project, toolKey, command);
+ setProperty( project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX, optionsValue);
+ }
+
+ public static String [] getToolOptions( IProject project, String toolKey) {
+ String optionsValue = getProperty( project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX);
+
+ return optionsValue.split( OPTION_SEPARATOR);
+ }
+
private Storage() {
// Do nothing
}