Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 148695 Details for
Bug 291255
Enhancement request: Improvements to the <eclipse.incrementalBuild/> Ant task
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
patch.txt (text/plain), 7.40 KB, created by
Mike Morearty
on 2009-10-02 16:55:06 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Mike Morearty
Created:
2009-10-02 16:55:06 EDT
Size:
7.40 KB
patch
obsolete
>### 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 <code>"incremental"</code>) >@@ -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<warningsAndErrors.length; ++i) { >+ IMarker problem = warningsAndErrors[i]; >+ int severity = ((Integer) problem.getAttribute(IMarker.SEVERITY)).intValue(); >+ int logLevel = (severity == IMarker.SEVERITY_ERROR) ? Project.MSG_WARN : Project.MSG_ERR; >+ getProject().log(formatProblemMessage(problem), logLevel); >+ } >+ } >+ >+ /** >+ * Returns a string suitable for display that represents a build problem. >+ * >+ * @param problem the problem >+ * @return a string suitable for display that represents the problem >+ */ >+ private String formatProblemMessage(IMarker problem) { >+ StringBuffer sb = new StringBuffer(); >+ >+ // start with "path:linenum: " >+ IResource resource = problem.getResource(); >+ if (resource != null) { >+ IPath resourceLocation = resource.getLocation(); >+ if (resourceLocation != null) { >+ sb.append(resourceLocation.toOSString()); >+ sb.append(':'); >+ >+ int lineNumber = problem.getAttribute(IMarker.LINE_NUMBER, -1); >+ if (lineNumber != -1) { >+ sb.append(lineNumber); >+ sb.append(':'); >+ } >+ >+ sb.append(' '); >+ } >+ } >+ >+ // if it is a warning, append "warning: " >+ int severity = problem.getAttribute(IMarker.SEVERITY, -1); >+ if (severity == IMarker.SEVERITY_WARNING) { >+ sb.append("warning: "); //$NON-NLS-1$ >+ } >+ >+ // append the problem's actual message >+ String message = problem.getAttribute(IMarker.MESSAGE, null); >+ if (message != null) { >+ sb.append(message); >+ } >+ >+ return sb.toString(); >+ } >+ > /** > * Sets the name of the receiver's builder. > * >@@ -95,7 +175,7 @@ > } > > /** >- * Sets the receiver's kind> attribute. This value must be one >+ * Sets the receiver's kind attribute. This value must be one > * of: <code>IncrementalBuild.KIND_FULL</code>, > * <code>IncrementalBuild.KIND_AUTO</code>, > * <code>IncrementalBuild.KIND_INCREMENTAL</code>, >@@ -122,4 +202,102 @@ > public void setProject(String value) { > project = value; > } >+ >+ /** >+ * Sets whether build errors will cause the build to fail; defaults to <code>true</code>. >+ * >+ * @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 <code>true</code>. >+ * >+ * @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 <code>IMarker.SEVERITY_ERROR</code>. >+ * @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 <code>IMarker.SEVERITY_ERROR</code> >+ * or <code>IMarker.SEVERITY_WARNING</code>. >+ * @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 <code>minimumSeverity</code> >+ * @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()]); >+ } >+ >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 291255
: 148695