1 17 package org.apache.forrest.eclipse; 18 19 import java.io.BufferedReader ; 20 import java.io.IOException ; 21 import java.io.InputStreamReader ; 22 import java.util.HashMap ; 23 import java.util.MissingResourceException ; 24 import java.util.ResourceBundle ; 25 26 import org.apache.forrest.eclipse.preference.ForrestPreferences; 27 import org.eclipse.jface.preference.IPreferenceStore; 28 import org.eclipse.ui.plugin.AbstractUIPlugin; 29 30 33 public class ForrestPlugin extends AbstractUIPlugin { 34 public final static String ID = "org.apache.forrest.eclipse"; 35 private static ForrestPlugin plugin; 37 38 private ResourceBundle resourceBundle; 40 41 45 public ForrestPlugin() { 46 super(); 47 plugin = this; 48 try { 49 resourceBundle = ResourceBundle 50 .getBundle("org.apache.forrest.ForrestPluginResources"); } catch (MissingResourceException x) { 52 resourceBundle = null; 53 } 54 } 55 56 61 public static ForrestPlugin getDefault() { 62 return plugin; 63 } 64 65 72 public static String getResourceString(String key) { 73 ResourceBundle bundle = ForrestPlugin.getDefault().getResourceBundle(); 74 try { 75 return (bundle != null) ? bundle.getString(key) : key; 76 } catch (MissingResourceException e) { 77 return key; 78 } 79 } 80 81 86 public ResourceBundle getResourceBundle() { 87 return resourceBundle; 88 } 89 90 93 protected void initializeDefaultPreferences(IPreferenceStore store) { 94 super.initializeDefaultPreferences(store); 95 96 HashMap envVariables = new HashMap (); 97 BufferedReader reader = null; 98 99 String envCommand = "env"; 102 if (System.getProperty("os.name").toLowerCase().startsWith("win")) 103 envCommand = "cmd /c set"; 104 105 try { 106 Process p = Runtime.getRuntime().exec(envCommand); 108 reader = new BufferedReader (new InputStreamReader (p.getInputStream())); 109 110 String theLine = null; 112 while ( (theLine = reader.readLine()) != null) { 113 int equalsIndex = theLine.indexOf("="); 114 if (equalsIndex < 0) 115 continue; 116 117 String name = theLine.substring(0,equalsIndex); 118 String value = ""; 119 if ((equalsIndex + 1) < theLine.length()) 121 value = theLine.substring(equalsIndex+1, theLine.length()); 122 envVariables.put(name, value); 123 } 124 } 125 catch (IOException e) { 126 e.printStackTrace(); 128 } 129 130 store = getPreferenceStore(); 131 if (envVariables.containsKey(ForrestPreferences.FORREST_HOME)) { 132 store.setDefault(ForrestPreferences.FORREST_HOME, (String )envVariables.get(ForrestPreferences.FORREST_HOME)); 133 } 134 } 135 136 140 public void setForrestHome(String forrestHome) { 141 IPreferenceStore store = getPreferenceStore(); 142 store.setDefault(ForrestPreferences.FORREST_HOME, forrestHome); 143 } 144 } 145 | Popular Tags |