Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » IJavaProject - How do I determine build status (i.e., OK, warnings, errors)?
IJavaProject - How do I determine build status (i.e., OK, warnings, errors)? [message #43200] Thu, 29 May 2003 12:48 Go to next message
Eclipse UserFriend
Originally posted by: hallorant.yahoo.com

Within jtd.core, given a IJavaProject, how can I determine the Java
compilation status? I am within a builder (that occurs after the Java
builder) and I want to know if the IJavaProject is OK, has warnings, or
has errors.

Nothing is jumping out at me in the jdt.core API (now I'm starting to
look into the jdt.core source code), any pointers would help...thanks!

Tim Halloran
Carnegie Mellon University
Re: IJavaProject - How do I determine build status (i.e., OK, warnings, errors)? [message #43622 is a reply to message #43200] Thu, 29 May 2003 16:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hallorant.yahoo.com

Tim Halloran wrote:
> Within jtd.core, given a IJavaProject, how can I determine the Java
> compilation status? I am within a builder (that occurs after the Java
> builder) and I want to know if the IJavaProject is OK, has warnings, or
> has errors.
>
> Nothing is jumping out at me in the jdt.core API (now I'm starting to
> look into the jdt.core source code), any pointers would help...thanks!
>
> Tim Halloran
> Carnegie Mellon University

I appear to have solved my problem. The solution was to examine the markers
attached to the IProject related to the IJavaProject. My code is below:

/**
* Check if the compilation state of an {@link IJavaProject} has errors.
*
* @param javaProject the {@link IJavaProject} to check for errors
* @return <code>true</code> if the project has compilation errors (or has
* never been built), <code>false</code> otherwise
* @throws CoreException if we have trouble getting the project's
* {@link IMarker} list
*/
private boolean hasCompilationErrors(IJavaProject javaProject)
throws CoreException {
boolean result = true; // assume it has errors or has never been built
if (javaProject.hasBuildState()) {
result = false; // ok, we have a build state so assume no errors
IMarker[] problems =
javaProject.getProject().findMarkers(
IMarker.PROBLEM,
true,
IResource.DEPTH_INFINITE);
// check if any of these have a severity attribute that indicates an error
for (int problemsIndex = 0;
problemsIndex < problems.length;
problemsIndex++) {
result =
(IMarker.SEVERITY_ERROR
== problems[problemsIndex].getAttribute(
IMarker.SEVERITY,
IMarker.SEVERITY_INFO));
}
}
return result;
}
Re: IJavaProject - How do I determine build status (i.e., OK, warnings, errors)? [message #43833 is a reply to message #43622] Thu, 29 May 2003 17:59 Go to previous message
Eclipse UserFriend
Your code only indicates whether the last IMarker has a problem or not,
since you are re-writing over your result variable every time in the
loop. Instead, it should probably read:

for (int problemsIndex = 0;
problemsIndex < problems.length;
problemsIndex++) {
if (IMarker.SEVERITY_ERROR
== problems[problemsIndex].getAttribute(
IMarker.SEVERITY,
IMarker.SEVERITY_INFO))
return true;
}

Tim Halloran wrote:
> Tim Halloran wrote:
>
>> Within jtd.core, given a IJavaProject, how can I determine the Java
>> compilation status? I am within a builder (that occurs after the Java
>> builder) and I want to know if the IJavaProject is OK, has warnings,
>> or has errors.
>>
>> Nothing is jumping out at me in the jdt.core API (now I'm starting to
>> look into the jdt.core source code), any pointers would help...thanks!
>>
>> Tim Halloran
>> Carnegie Mellon University
>
>
> I appear to have solved my problem. The solution was to examine the
> markers attached to the IProject related to the IJavaProject. My code
> is below:
>
> /**
> * Check if the compilation state of an {@link IJavaProject} has errors.
> *
> * @param javaProject the {@link IJavaProject} to check for errors
> * @return <code>true</code> if the project has compilation errors (or
> has
> * never been built), <code>false</code> otherwise
> * @throws CoreException if we have trouble getting the project's
> * {@link IMarker} list
> */
> private boolean hasCompilationErrors(IJavaProject javaProject)
> throws CoreException {
> boolean result = true; // assume it has errors or has never been built
> if (javaProject.hasBuildState()) {
> result = false; // ok, we have a build state so assume no errors
> IMarker[] problems =
> javaProject.getProject().findMarkers(
> IMarker.PROBLEM,
> true,
> IResource.DEPTH_INFINITE);
> // check if any of these have a severity attribute that indicates
> an error
> for (int problemsIndex = 0;
> problemsIndex < problems.length;
> problemsIndex++) {
> result =
> (IMarker.SEVERITY_ERROR
> == problems[problemsIndex].getAttribute(
> IMarker.SEVERITY,
> IMarker.SEVERITY_INFO));
> }
> }
> return result;
> }
>
Previous Topic:Associate .java files with Eclipse (Windows)
Next Topic:Ant, Eclipse Config and JRE
Goto Forum:
  


Current Time: Wed Jul 16 04:52:10 EDT 2025

Powered by FUDForum. Page generated in 3.94003 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top