You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by rg...@apache.org on 2004/10/02 00:56:17 UTC
svn commit: rev 51762 - forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse
Author: rgardler
Date: Fri Oct 1 15:56:16 2004
New Revision: 51762
Modified:
forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/ForrestPlugin.java
Log:
Initialise FORREST_HOME property from the environment
Modified: forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/ForrestPlugin.java
==============================================================================
--- forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/ForrestPlugin.java (original)
+++ forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/ForrestPlugin.java Fri Oct 1 15:56:16 2004
@@ -15,8 +15,16 @@
*/
package org.apache.forrest.eclipse;
-import org.eclipse.ui.plugin.*;
-import java.util.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.forrest.eclipse.preference.ForrestPreferences;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
* The main plugin class to be used in the desktop.
@@ -75,5 +83,50 @@
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
+ */
+ protected void initializeDefaultPreferences(IPreferenceStore store) {
+ super.initializeDefaultPreferences(store);
+
+ HashMap envVariables = new HashMap();
+ BufferedReader reader = null;
+
+ //"env" works on Linux & Unix Variants but if we're on Windows,
+ //use "cmd /c set".
+ String envCommand = "env";
+ if (System.getProperty("os.name").toLowerCase().startsWith("win"))
+ envCommand = "cmd /c set";
+
+ try {
+ //First we launch the command and attach a Reader to the Output
+ Process p = Runtime.getRuntime().exec(envCommand);
+ reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+
+ //Now we parse the output, filling up the Hashtable
+ String theLine = null;
+ while ( (theLine = reader.readLine()) != null) {
+ int equalsIndex = theLine.indexOf("=");
+ if (equalsIndex < 0)
+ continue;
+
+ String name = theLine.substring(0,equalsIndex);
+ String value = "";
+ //Test for an empty value such as "FOO="
+ if ((equalsIndex + 1) < theLine.length())
+ value = theLine.substring(equalsIndex+1, theLine.length());
+ envVariables.put(name, value);
+ }
+ }
+ catch (IOException e) {
+ // FIXME: Handle this error
+ e.printStackTrace();
+ }
+
+ store = getPreferenceStore();
+ if (envVariables.containsKey(ForrestPreferences.FORREST_HOME)) {
+ store.setDefault(ForrestPreferences.FORREST_HOME, (String)envVariables.get(ForrestPreferences.FORREST_HOME));
+ }
}
}