1 11 package org.eclipse.ui.externaltools.internal.variables; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.core.variables.IDynamicVariable; 20 import org.eclipse.core.variables.IDynamicVariableResolver; 21 import org.eclipse.osgi.util.NLS; 22 import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder; 23 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 24 25 26 public class BuildProjectResolver implements IDynamicVariableResolver { 27 28 31 public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { 32 IResource resource= ExternalToolBuilder.getBuildProject(); 33 if (argument != null && resource != null) { 34 resource = ((IProject)resource).findMember(new Path(argument)); 35 } 36 if (resource != null && resource.exists()) { 37 return resource.getLocation().toOSString(); 38 } 39 abort(NLS.bind(VariableMessages.BuildProjectResolver_3, new String []{getReferenceExpression(variable, argument)}), null); 40 return null; 41 } 42 43 50 protected void abort(String message, Throwable exception) throws CoreException { 51 throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, message, exception)); 52 } 53 54 62 protected String getReferenceExpression(IDynamicVariable variable, String argument) { 63 StringBuffer reference = new StringBuffer (); 64 reference.append("${"); reference.append(variable.getName()); 66 if (argument != null) { 67 reference.append(":"); reference.append(argument); 69 } 70 reference.append("}"); return reference.toString(); 72 } 73 } 74 | Popular Tags |