1 11 package org.eclipse.core.runtime.internal.adaptor; 12 13 import java.util.*; 14 import org.eclipse.osgi.framework.internal.core.FrameworkProperties; 15 import org.eclipse.osgi.service.environment.Constants; 16 import org.eclipse.osgi.service.environment.EnvironmentInfo; 17 import org.eclipse.osgi.util.NLS; 18 19 22 public class EclipseEnvironmentInfo implements EnvironmentInfo { 23 private static EclipseEnvironmentInfo singleton; 24 private static String nl; 25 private static String os; 26 private static String ws; 27 private static String arch; 28 static String [] allArgs; 29 static String [] frameworkArgs; 30 static String [] appArgs; 31 32 private static final String INTERNAL_OS_SUNOS = "SunOS"; private static final String INTERNAL_OS_LINUX = "Linux"; private static final String INTERNAL_OS_MACOSX = "Mac OS"; private static final String INTERNAL_OS_AIX = "AIX"; private static final String INTERNAL_OS_HPUX = "HP-UX"; private static final String INTERNAL_OS_QNX = "QNX"; 41 private static final String INTERNAL_ARCH_I386 = "i386"; private static final String INTERNAL_AMD64 = "amd64"; 48 private EclipseEnvironmentInfo() { 49 super(); 50 setupSystemContext(); 51 } 52 53 public static EclipseEnvironmentInfo getDefault() { 54 if (singleton == null) 55 singleton = new EclipseEnvironmentInfo(); 56 return singleton; 57 } 58 59 public boolean inDevelopmentMode() { 60 return FrameworkProperties.getProperty("osgi.dev") != null; } 62 63 public boolean inDebugMode() { 64 return FrameworkProperties.getProperty("osgi.debug") != null; } 66 67 public String [] getCommandLineArgs() { 68 return allArgs; 69 } 70 71 public String [] getFrameworkArgs() { 72 return frameworkArgs; 73 } 74 75 public String [] getNonFrameworkArgs() { 76 return appArgs; 77 } 78 79 public String getOSArch() { 80 return arch; 81 } 82 83 public String getNL() { 84 return nl; 85 } 86 87 public String getOS() { 88 return os; 89 } 90 91 public String getWS() { 92 return ws; 93 } 94 95 103 private static void setupSystemContext() { 104 nl = FrameworkProperties.getProperty("osgi.nl"); if (nl != null) { 107 StringTokenizer tokenizer = new StringTokenizer(nl, "_"); int segments = tokenizer.countTokens(); 109 try { 110 Locale userLocale = null; 111 switch (segments) { 112 case 1 : 113 userLocale = new Locale(tokenizer.nextToken(), ""); break; 116 case 2 : 117 userLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken()); 118 break; 119 case 3 : 120 userLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken()); 121 break; 122 default : 123 System.err.println(NLS.bind(EclipseAdaptorMsg.error_badNL, nl)); 125 userLocale = Locale.getDefault(); 126 break; 127 } 128 Locale.setDefault(userLocale); 129 FrameworkProperties.setProperty("osgi.nl.user", nl); } catch (NoSuchElementException e) { 132 } 134 } 135 nl = Locale.getDefault().toString(); 136 FrameworkProperties.setProperty("osgi.nl", nl); 138 os = FrameworkProperties.getProperty("osgi.os"); if (os == null) { 142 os = guessOS(FrameworkProperties.getProperty("os.name")); FrameworkProperties.setProperty("osgi.os", os); } 145 146 ws = FrameworkProperties.getProperty("osgi.ws"); if (ws == null) { 150 ws = guessWS(os); 151 FrameworkProperties.setProperty("osgi.ws", ws); } 153 154 arch = FrameworkProperties.getProperty("osgi.arch"); if (arch == null) { 158 String name = FrameworkProperties.getProperty("os.arch"); if (name.equalsIgnoreCase(INTERNAL_ARCH_I386)) 161 arch = Constants.ARCH_X86; 162 else if (name.equalsIgnoreCase(INTERNAL_AMD64)) 164 arch = Constants.ARCH_X86_64; 165 else 166 arch = name; 167 FrameworkProperties.setProperty("osgi.arch", arch); } 169 } 170 171 public static void setAllArgs(String [] allArgs) { 172 if (EclipseEnvironmentInfo.allArgs == null) 173 EclipseEnvironmentInfo.allArgs = allArgs; 174 } 175 176 public static void setAppArgs(String [] appArgs) { 177 if (EclipseEnvironmentInfo.appArgs == null) 178 EclipseEnvironmentInfo.appArgs = appArgs; 179 } 180 181 public static void setFrameworkArgs(String [] frameworkArgs) { 182 if (EclipseEnvironmentInfo.frameworkArgs == null) 183 EclipseEnvironmentInfo.frameworkArgs = frameworkArgs; 184 } 185 186 public static String guessWS(String os) { 187 if (os.equals(Constants.OS_WIN32)) 189 return Constants.WS_WIN32; 190 if (os.equals(Constants.OS_LINUX)) 191 return Constants.WS_MOTIF; 192 if (os.equals(Constants.OS_MACOSX)) 193 return Constants.WS_CARBON; 194 if (os.equals(Constants.OS_HPUX)) 195 return Constants.WS_MOTIF; 196 if (os.equals(Constants.OS_AIX)) 197 return Constants.WS_MOTIF; 198 if (os.equals(Constants.OS_SOLARIS)) 199 return Constants.WS_MOTIF; 200 if (os.equals(Constants.OS_QNX)) 201 return Constants.WS_PHOTON; 202 return Constants.WS_UNKNOWN; 203 } 204 205 public static String guessOS(String osName) { 206 if (osName.regionMatches(true, 0, Constants.OS_WIN32, 0, 3)) 209 return Constants.OS_WIN32; 210 if (osName.equalsIgnoreCase(INTERNAL_OS_SUNOS)) 212 return Constants.OS_SOLARIS; 213 if (osName.equalsIgnoreCase(INTERNAL_OS_LINUX)) 214 return Constants.OS_LINUX; 215 if (osName.equalsIgnoreCase(INTERNAL_OS_QNX)) 216 return Constants.OS_QNX; 217 if (osName.equalsIgnoreCase(INTERNAL_OS_AIX)) 218 return Constants.OS_AIX; 219 if (osName.equalsIgnoreCase(INTERNAL_OS_HPUX)) 220 return Constants.OS_HPUX; 221 if (osName.regionMatches(true, 0, INTERNAL_OS_MACOSX, 0, INTERNAL_OS_MACOSX.length())) 223 return Constants.OS_MACOSX; 224 return Constants.OS_UNKNOWN; 225 } 226 } 227 | Popular Tags |