Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Swanson2007-03-19 05:39:20 +0000
committerDarin Swanson2007-03-19 05:39:20 +0000
commite8ac2a0508ee72a6fe5db9fcce07bcc8fb363f84 (patch)
tree1ff344506c28d359c0ecf3a6c064e6420a20c422
parent0debb05fe37e4cd77c52643e3c28372b0965ae39 (diff)
downloadeclipse.platform.debug-e8ac2a0508ee72a6fe5db9fcce07bcc8fb363f84.tar.gz
eclipse.platform.debug-e8ac2a0508ee72a6fe5db9fcce07bcc8fb363f84.tar.xz
eclipse.platform.debug-e8ac2a0508ee72a6fe5db9fcce07bcc8fb363f84.zip
Bug 175186 - Add a build variable for showing changeset (patch included)
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java22
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildFilesResolver.java136
-rw-r--r--org.eclipse.ui.externaltools/plugin.properties1
-rw-r--r--org.eclipse.ui.externaltools/plugin.xml6
4 files changed, 161 insertions, 4 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 f151efdfb..f1aedbde1 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Matthew Conway - Bug 175186
*******************************************************************************/
package org.eclipse.ui.externaltools.internal.model;
@@ -58,6 +59,7 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
private static String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
private static IProject buildProject= null;
+ private static IResourceDelta buildDelta= null;
/* (non-Javadoc)
* @see org.eclipse.core.internal.events.InternalBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
@@ -197,7 +199,17 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
public static IProject getBuildProject() {
return buildProject;
}
-
+
+ /**
+ * Returns the <code>IResourceDelta</code> that is being built and has triggered the current external
+ * tool builder. <code>null</code> is returned if no build is currently occurring.
+ *
+ * @return resource delta for the build or <code>null</code>
+ */
+ public static IResourceDelta getBuildDelta() {
+ return buildDelta;
+ }
+
/**
* Stores the currently active build kind and build project when a build begins
* @param buildKind
@@ -221,14 +233,16 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
break;
}
buildProject= getProject();
+ buildDelta= getDelta(getProject());
}
/**
- * Clears the current build kind and build project when a build finishes.
+ * Clears the current build kind, build project and build delta when a build finishes.
*/
private void buildEnded() {
buildType= IExternalToolConstants.BUILD_TYPE_NONE;
buildProject= null;
+ buildDelta= null;
}
private boolean buildScopeIndicatesBuild(IResource[] resources) {
@@ -270,4 +284,4 @@ public final class ExternalToolBuilder extends IncrementalProjectBuilder {
launchBuild(IncrementalProjectBuilder.CLEAN_BUILD, config, monitor);
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildFilesResolver.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildFilesResolver.java
new file mode 100644
index 000000000..0670eda94
--- /dev/null
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildFilesResolver.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Matthew Conway and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Conway - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.externaltools.internal.variables;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.variables.IDynamicVariable;
+import org.eclipse.core.variables.IDynamicVariableResolver;
+import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
+
+public class BuildFilesResolver implements IDynamicVariableResolver
+{
+ private static final char ARG_REMOVED = 'r';
+ private static final char ARG_CHANGED = 'c';
+ private static final char ARG_ADDED = 'a';
+ private static final char ARG_DIRS = 'd';
+ private static final char ARG_FILES = 'f';
+
+ // Use a space as a separator as this is a more natural fit for sending a
+ // list of files to a unix command
+ private static final String FILE_LIST_SEPARATOR = " "; //$NON-NLS-1$
+
+ public String resolveValue(IDynamicVariable variable, String argument) throws CoreException
+ {
+ String result = null;
+
+ IResourceDelta buildDelta = ExternalToolBuilder.getBuildDelta();
+ if (buildDelta != null)
+ {
+ final StringBuffer fileList = new StringBuffer();
+ final Set changedResources = new LinkedHashSet();
+
+ // Use the argument to determine which deltas to visit - if none,
+ // then defaults to all
+ int deltas = 0;
+ boolean dirs = false, files = false;
+ if (argument != null)
+ {
+ // Check delta kinds
+ if (argument.indexOf(ARG_ADDED) > -1)
+ {
+ deltas |= IResourceDelta.ADDED;
+ }
+ if (argument.indexOf(ARG_CHANGED) > -1)
+ {
+ deltas |= IResourceDelta.CHANGED;
+ }
+ if (argument.indexOf(ARG_REMOVED) > -1)
+ {
+ deltas |= IResourceDelta.REMOVED;
+ }
+
+ // Check wether to include files and/or directories
+ if (argument.indexOf(ARG_DIRS) > -1)
+ {
+ dirs = true;
+ }
+ if (argument.indexOf(ARG_FILES) > -1)
+ {
+ files = true;
+ }
+
+ }
+ if (deltas == 0)
+ {
+ deltas = IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED;
+ }
+ if (!dirs && !files)
+ {
+ dirs = true;
+ files = true;
+ }
+ final int trackDeltas = deltas;
+ final boolean trackDirs = dirs;
+ final boolean trackFiles = files;
+
+
+ buildDelta.accept(new IResourceDeltaVisitor()
+ {
+ public boolean visit(IResourceDelta delta) throws CoreException
+ {
+ IResource resource = delta.getResource();
+
+ // Only track files with the right kind of delta
+ boolean isTracked = (delta.getKind() & trackDeltas) > 0;
+ if (isTracked)
+ {
+ // Only track dirs if desired
+ isTracked = trackDirs && resource.getType() != IResource.FILE;
+ // Only track files if desired
+ isTracked |= trackFiles && resource.getType() == IResource.FILE;
+ }
+
+ // If tracking a change, then add it to the change set for inclusion in the variable's output
+ if (isTracked)
+ {
+ String osPath = resource.getLocation().toOSString();
+ if (changedResources.add(osPath))
+ {
+ if (fileList.length() > 0)
+ {
+ fileList.append(FILE_LIST_SEPARATOR);
+ }
+
+ // Since space is our separator, we need to add quotes
+ // around each file to handle filenames with embedded
+ // spaces. We also need to escape out embedded quotes in
+ // the filename so they don't conflict with these
+ // special quotes.
+ //
+ osPath = osPath.replaceAll("\"", "\\\\\""); //$NON-NLS-1$ //$NON-NLS-2$
+ fileList.append("\"" + osPath + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return true;
+ }
+ }, deltas);
+ result = fileList.toString();
+ }
+
+ return result;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.externaltools/plugin.properties b/org.eclipse.ui.externaltools/plugin.properties
index 7611c0ced..3c617ae7c 100644
--- a/org.eclipse.ui.externaltools/plugin.properties
+++ b/org.eclipse.ui.externaltools/plugin.properties
@@ -14,6 +14,7 @@ Plugin.providerName = Eclipse.org
build_type.description= Returns the type of build being performed - "incremental", "full", "auto", or "none".
build_project.description= Returns the absolute file system path of the project currently being built, or the absolute file system path of the resource identified by an optional argument interpreted as a path relative to the project currently being built.
+build_files.description= Returns the set of absolute file system paths whose modification caused the current build. A list of the characters, 'a' (added), 'c' (changed), 'r' (removed), 'f' (files only), 'd' (directories only), can be supplied as an argument to limit the file list to just those types of deltas. Defaults to all deltas.
system_path.description= Returns the absolute file system path of the external tool. Resolved by finding the first occurrence of the named tool based on the system path specification. The tool name must be supplied as an argument.
ExtPoint.configurationDuplicationMaps = Launch Configuration Duplication Maps
diff --git a/org.eclipse.ui.externaltools/plugin.xml b/org.eclipse.ui.externaltools/plugin.xml
index bde515ba0..a0ca6df08 100644
--- a/org.eclipse.ui.externaltools/plugin.xml
+++ b/org.eclipse.ui.externaltools/plugin.xml
@@ -191,6 +191,12 @@
description="%build_project.description">
</variable>
<variable
+ name="build_files"
+ resolver="org.eclipse.ui.externaltools.internal.variables.BuildFilesResolver"
+ description="%build_files.description"
+ supportsArgument="true">
+ </variable>
+ <variable
name="system_path"
resolver="org.eclipse.ui.externaltools.internal.variables.SystemPathResolver"
description="%system_path.description"

Back to the top