1 12 package org.eclipse.ui.externaltools.internal.variables; 13 14 import java.io.File ; 15 import java.util.Map ; 16 import java.util.StringTokenizer ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.core.variables.IDynamicVariable; 22 import org.eclipse.core.variables.IDynamicVariableResolver; 23 import org.eclipse.debug.core.DebugPlugin; 24 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 25 26 public class SystemPathResolver implements IDynamicVariableResolver { 27 28 31 public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { 32 if (argument == null) { 33 throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, VariableMessages.SystemPathResolver_0, null)); 34 } 35 Map map= DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment(); 36 String path= (String ) map.get("PATH"); if (path == null) { 38 return argument; 39 } 40 String pathext = (String ) map.get("PATHEXT"); StringTokenizer tokenizer= new StringTokenizer (path, File.pathSeparator); 44 while (tokenizer.hasMoreTokens()) { 45 String pathElement= tokenizer.nextToken(); 46 File pathElementFile= new File (pathElement); 47 if (pathElementFile.isDirectory()) { 48 File toolFile= new File (pathElementFile, argument); 49 if (toolFile.exists()) { 50 return toolFile.getAbsolutePath(); 51 } 52 if ( pathext != null ) { 53 StringTokenizer pathextTokenizer = new StringTokenizer (pathext, File.pathSeparator); 54 while (pathextTokenizer.hasMoreTokens()) { 55 String pathextElement = pathextTokenizer.nextToken(); 56 toolFile = new File (pathElementFile, argument + pathextElement); 57 if (toolFile.exists()) { 58 return toolFile.getAbsolutePath(); 59 } 60 } 61 } 62 } 63 } 64 return argument; 65 } 66 } 67 | Popular Tags |