### Eclipse Workspace Patch 1.0
#P org.eclipse.core.resources
Index: src_ant/org/eclipse/core/resources/ant/IncrementalBuild.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src_ant/org/eclipse/core/resources/ant/IncrementalBuild.java,v
retrieving revision 1.12
diff -u -r1.12 IncrementalBuild.java
--- src_ant/org/eclipse/core/resources/ant/IncrementalBuild.java 4 Apr 2006 20:53:47 -0000 1.12
+++ src_ant/org/eclipse/core/resources/ant/IncrementalBuild.java 2 Oct 2009 20:57:44 -0000
@@ -10,7 +10,15 @@
*******************************************************************************/
package org.eclipse.core.resources.ant;
-import java.util.Hashtable;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.core.resources.IResource;
+
+import org.apache.tools.ant.Project;
+
+import org.eclipse.core.resources.IMarker;
+
+import java.util.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.ant.core.AntCorePlugin;
@@ -28,6 +36,9 @@
private String builder;
private String project;
private int kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
+ private boolean failOnError = true;
+ private boolean showProblems = true;
+ private String errorProperty;
/**
* Unique identifier constant (value "incremental"
)
@@ -71,20 +82,89 @@
Hashtable references = getProject().getReferences();
if (references != null)
monitor = (IProgressMonitor) references.get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
+ IResource rootResource;
if (project == null) {
+ rootResource = ResourcesPlugin.getWorkspace().getRoot();
ResourcesPlugin.getWorkspace().build(kind, monitor);
} else {
IProject targetProject = ResourcesPlugin.getWorkspace().getRoot().getProject(project);
+ rootResource = targetProject;
if (builder == null)
targetProject.build(kind, monitor);
else
targetProject.build(kind, builder, null, monitor);
}
+ Problems problems = new Problems(rootResource);
+ if (showProblems) {
+ showProblems(problems);
+ }
+ if (errorProperty != null) {
+ if (problems.getErrors().length > 0) {
+ getProject().setProperty(errorProperty, "true"); //$NON-NLS-1$
+ }
+ }
+ if (failOnError) {
+ if (problems.getErrors().length > 0) {
+ throw new BuildException();
+ }
+ }
} catch (CoreException e) {
throw new BuildException(e);
}
}
+ private void showProblems(Problems problems) throws CoreException {
+ IMarker[] warningsAndErrors = problems.getWarningAndErrors();
+ for (int i=0; i attribute. This value must be one
+ * Sets the receiver's kind attribute. This value must be one
* of: IncrementalBuild.KIND_FULL
,
* IncrementalBuild.KIND_AUTO
,
* IncrementalBuild.KIND_INCREMENTAL
,
@@ -122,4 +202,102 @@
public void setProject(String value) {
project = value;
}
+
+ /**
+ * Sets whether build errors will cause the build to fail; defaults to true
.
+ *
+ * @param value whether build errors should cause the build to fail
+ */
+ public void setFailOnError(boolean value) {
+ failOnError = value;
+ }
+
+ /**
+ * Sets whether build errors and warnings should be displayed; defaults to true
.
+ *
+ * @param value whether build errors and warnings should be displayed
+ */
+ public void setShowProblems(boolean value) {
+ showProblems = value;
+ }
+
+ /**
+ * The property to set (to the value "true") if the build fails.
+ *
+ * @param value the name of the Ant property
+ */
+ public void setErrorProperty(String value) {
+ errorProperty = value;
+ }
+
+ /**
+ * Helper class to keep track of build problems.
+ */
+ private static class Problems {
+ private final IResource resource;
+ private IMarker[] allProblems;
+ private IMarker[] errors;
+ private IMarker[] errorsAndWarnings;
+
+ public Problems(IResource resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Returns all problem markers on the resource.
+ * @throws CoreException
+ */
+ public IMarker[] getAllProblems() throws CoreException {
+ if (allProblems == null) {
+ allProblems = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ }
+ return allProblems;
+ }
+
+ /**
+ * Returns all problem markers on the resource whose severity is IMarker.SEVERITY_ERROR
.
+ * @throws CoreException
+ */
+ public IMarker[] getErrors() throws CoreException {
+ if (errors == null) {
+ errors = filterProblems(getAllProblems(), IMarker.SEVERITY_ERROR);
+ }
+ return errors;
+ }
+
+ /**
+ * Returns all problem markers on the resource whose severity is IMarker.SEVERITY_ERROR
+ * or IMarker.SEVERITY_WARNING
.
+ * @throws CoreException
+ */
+ public IMarker[] getWarningAndErrors() throws CoreException {
+ if (errorsAndWarnings == null) {
+ errorsAndWarnings = filterProblems(getAllProblems(), IMarker.SEVERITY_WARNING);
+ }
+ return errorsAndWarnings;
+ }
+
+ /**
+ * Returns only those markers whose severity is equal to or greater than
+ * the specified value.
+ *
+ * @param minimumSeverity the desired minimum severity
+ * @return an array that contains only those markers whose severity is
+ * greater than or equal to minimumSeverity
+ * @throws CoreException
+ */
+ private static IMarker[] filterProblems(IMarker[] problems, int minimumSeverity) throws CoreException {
+ List filteredProblems = new ArrayList(problems.length);
+ for (int i = 0; i < problems.length; ++i) {
+ Integer severity = (Integer) problems[i].getAttribute(IMarker.SEVERITY);
+ if (severity != null) {
+ if (severity.intValue() >= minimumSeverity) {
+ filteredProblems.add(problems[i]);
+ }
+ }
+ }
+ return (IMarker[]) filteredProblems.toArray(new IMarker[filteredProblems.size()]);
+ }
+
+ }
}