1 11 package org.eclipse.debug.internal.core; 12 13 import java.net.URL ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.core.variables.IDynamicVariable; 20 import org.eclipse.core.variables.IDynamicVariableResolver; 21 22 34 public class SystemVariableResolver implements IDynamicVariableResolver { 35 38 public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { 39 if ("ARCH".equals(argument)) { return Platform.getOSArch(); 41 } else if ("ECLIPSE_HOME".equals(argument)) { URL installURL = Platform.getInstallLocation().getURL(); 43 IPath ppath = new Path(installURL.getFile()).removeTrailingSeparator(); 44 return getCorrectPath(ppath.toOSString()); 45 } else if ("NL".equals(argument)) { return Platform.getNL(); 47 } else if ("OS".equals(argument)) { return Platform.getOS(); 49 } else if ("WS".equals(argument)) { return Platform.getWS(); 51 } 52 return null; 53 } 54 55 private static String getCorrectPath(String path) { 56 StringBuffer buf = new StringBuffer (); 57 for (int i = 0; i < path.length(); i++) { 58 char c = path.charAt(i); 59 if (Platform.getOS().equals("win32")) { if (i == 0 && c == '/') 61 continue; 62 } 63 if (c == '%' && i + 2 < path.length()) { 65 char c1 = path.charAt(i + 1); 66 char c2 = path.charAt(i + 2); 67 if (c1 == '2' && c2 == '0') { 68 i += 2; 69 buf.append(" "); continue; 71 } 72 } 73 buf.append(c); 74 } 75 return buf.toString(); 76 } 77 } 78 | Popular Tags |