/** Execute this Ant task. Builds the given project according to the given parameters */
  @Override
  public void execute() throws BuildException {
    validateAttributes();
    project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project == null) {
      displayError(TASKNAME + projectName + " project==null");
      return;
    }
    if (!project.exists()) {
      displayError(TASKNAME + projectName + " not found in Workspace.");
      return;
    }
    if (!project.isOpen()) {
      displayError(TASKNAME + projectName + " is not open");
      return;
    }

    try {
      AntConsoleProgressMonitor monitor = new AntConsoleProgressMonitor(this);
      monitor.beginTask(projectName, 1);
      setDebugOptions(debugcompilation);
      ProjectBuildWorkspaceModifyOperation op =
          new ProjectBuildWorkspaceModifyOperation(project, buildTypeInt);
      op.execute(monitor);
      // get/export errors and fail if needed
      int errors = getJavacErrorCount(project, monitor);
      if (errors > 0) {
        displayError(FAIL_MSG);
      }
      monitor.done();
    } catch (BuildException x) {
      throw x;
    } catch (Exception e) {
      displayError(TASKNAME + projectName + " Exception=" + e.getMessage());
    }
  }
 /**
  * return the number of compilation errors and as a side effect, write the errors to the specified
  * output file or to the build log if none specified.
  *
  * @param project
  * @param monitor
  * @return
  */
 private int getJavacErrorCount(IProject project, AntConsoleProgressMonitor monitor) {
   try {
     IMarker[] markerList =
         project.findMarkers(
             IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
     if (markerList == null || markerList.length == 0) {
       return 0;
     }
     IMarker marker = null;
     int numErrors = 0;
     XMLPrintStream out = getErrorOutputStream(project.getName());
     for (IMarker element : markerList) {
       marker = element;
       int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
       // default severity = ERROR
       if (severity == IMarker.SEVERITY_ERROR) {
         numErrors++;
         Integer lineNum = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
         String resourceName = marker.getResource().getName();
         String message = (String) marker.getAttribute(IMarker.MESSAGE);
         if (out != null) {
           appendError(out, marker.getResource(), message, lineNum);
         } else {
           monitor.displayMsg(resourceName + ":" + lineNum + ": " + message);
         }
       }
     }
     if (out != null) {
       close(out);
     }
     return numErrors;
   } catch (CoreException e) {
     displayError("CoreException: " + e.getMessage());
   }
   return UNKNOWN_ERRORS;
 }