diff options
Diffstat (limited to 'org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java')
-rw-r--r-- | org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java new file mode 100644 index 000000000..ac6fee703 --- /dev/null +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.externaltools.internal.variables; + +import java.text.MessageFormat; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder; +import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; + + +public class BuildProjectResolver implements IDynamicVariableResolver { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.stringsubstitution.IContextVariableResolver#resolveValue(org.eclipse.debug.internal.core.stringsubstitution.IContextVariable, java.lang.String) + */ + public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { + IResource resource= ExternalToolBuilder.getBuildProject(); + if (argument != null && resource != null) { + resource = ((IProject)resource).findMember(new Path(argument)); + } + if (resource != null && resource.exists()) { + return resource.getLocation().toOSString(); + } + abort(MessageFormat.format(VariableMessages.getString("BuildProjectResolver.3"), new String[]{getReferenceExpression(variable, argument)}), null); //$NON-NLS-1$ + return null; + } + + /** + * Throws an exception with the given message and underlying exception. + * + * @param message exception message + * @param exception underlying exception or <code>null</code> + * @throws CoreException + */ + protected void abort(String message, Throwable exception) throws CoreException { + throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, message, exception)); + } + + /** + * Returns an expression used to reference the given variable and optional argument. + * For example, <code>${var_name:arg}</code>. + * + * @param variable referenced variable + * @param argument referenced argument or <code>null</code> + * @return vraiable reference expression + */ + protected String getReferenceExpression(IDynamicVariable variable, String argument) { + StringBuffer reference = new StringBuffer(); + reference.append("${"); //$NON-NLS-1$ + reference.append(variable.getName()); + if (argument != null) { + reference.append(":"); //$NON-NLS-1$ + reference.append(argument); + } + reference.append("}"); //$NON-NLS-1$ + return reference.toString(); + } +} |