Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Swanson2004-04-07 20:10:52 +0000
committerDarin Swanson2004-04-07 20:10:52 +0000
commit9461d27e520f69cc63073c7a143e52ac4a254a6b (patch)
treeac98bfb0b61416dda03fd16f553e87f05a6cc82c /org.eclipse.ui.externaltools
parentcd272a6c5af8da3b7501c25ce2b43854666886a9 (diff)
downloadeclipse.platform.debug-9461d27e520f69cc63073c7a143e52ac4a254a6b.tar.gz
eclipse.platform.debug-9461d27e520f69cc63073c7a143e52ac4a254a6b.tar.xz
eclipse.platform.debug-9461d27e520f69cc63073c7a143e52ac4a254a6b.zip
Bug 52688 - Project "build_project" variables
Diffstat (limited to 'org.eclipse.ui.externaltools')
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java18
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java73
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.java31
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.properties12
-rw-r--r--org.eclipse.ui.externaltools/plugin.properties3
-rw-r--r--org.eclipse.ui.externaltools/plugin.xml5
6 files changed, 139 insertions, 3 deletions
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java
index f75c649ad..026caacb0 100644
--- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java
@@ -48,6 +48,8 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
private static String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
+ private static IProject buildProject= null;
+
private List projectsWithinScope;
private boolean buildKindCompatible(int kind, ILaunchConfiguration config) throws CoreException {
@@ -149,7 +151,17 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
}
/**
- * Stores the currently active build kind when a build begins
+ * Returns the project that is being built and has triggered the current external
+ * tool builder. <code>null</code> is returned if no build is currently occurring.
+ *
+ * @return project being built or <code>null</code>.
+ */
+ public static IProject getBuildProject() {
+ return buildProject;
+ }
+
+ /**
+ * Stores the currently active build kind and build project when a build begins
* @param buildKind
*/
private void buildStarted(int buildKind) {
@@ -167,13 +179,15 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
buildType = IExternalToolConstants.BUILD_TYPE_NONE;
break;
}
+ buildProject= getProject();
}
/**
- * Clears the current build kind when a build finishes.
+ * Clears the current build kind and build project when a build finishes.
*/
private void buildEnded() {
buildType= IExternalToolConstants.BUILD_TYPE_NONE;
+ buildProject= null;
}
private boolean buildScopeIndicatesBuild(IResource[] resources) {
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();
+ }
+}
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.java
new file mode 100644
index 000000000..bdc20f643
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class VariableMessages {
+
+ private static final String BUNDLE_NAME = "org.eclipse.ui.externaltools.internal.variables.VariableMessages";//$NON-NLS-1$
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private VariableMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.properties b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.properties
new file mode 100644
index 000000000..e45acd34e
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/VariableMessages.properties
@@ -0,0 +1,12 @@
+###############################################################################
+# 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
+###############################################################################
+
+BuildProjectResolver.3=Variable references non-existant resource : {0}
diff --git a/org.eclipse.ui.externaltools/plugin.properties b/org.eclipse.ui.externaltools/plugin.properties
index b70abc964..011289a2c 100644
--- a/org.eclipse.ui.externaltools/plugin.properties
+++ b/org.eclipse.ui.externaltools/plugin.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2003 IBM Corporation and others.
+# 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
@@ -13,6 +13,7 @@ Plugin.name = External Tools
Plugin.providerName = Eclipse.org
build_type.description= The type of build being performed - "incremental", "full", "auto", or "none".
+build_project.description= The name of the project currently being built.
ExtPoint.configurationDuplicationMaps = Launch Configuration Duplication Maps
ExtPoint.toolTypes = External Tool Types
diff --git a/org.eclipse.ui.externaltools/plugin.xml b/org.eclipse.ui.externaltools/plugin.xml
index 47631771f..5249c87f7 100644
--- a/org.eclipse.ui.externaltools/plugin.xml
+++ b/org.eclipse.ui.externaltools/plugin.xml
@@ -197,6 +197,11 @@
name="build_type"
resolver="org.eclipse.ui.externaltools.internal.variables.BuildTypeResolver"
description="%build_type.description">
+ </variable>
+ <variable
+ name="build_project"
+ resolver="org.eclipse.ui.externaltools.internal.variables.BuildProjectResolver"
+ description="%build_project.description">
</variable>
</extension>

Back to the top