Example #1
0
 private static void deleteMarkersWithCompiledFile(final IProject project, final IFile file) {
   if (!project.isAccessible()) {
     return;
   }
   try {
     for (final IMarker m : project.findMarkers(PROBLEM_MARKER, true, IResource.DEPTH_INFINITE)) {
       final Object source_id = m.getAttribute(IMarker.SOURCE_ID);
       if (source_id != null
           && source_id instanceof String
           && source_id.equals(file.getFullPath().toString())) {
         try {
           m.delete();
         } catch (final CoreException e) {
           // not much to do
         }
       }
     }
     for (final IMarker m : project.findMarkers(TASK_MARKER, true, IResource.DEPTH_INFINITE)) {
       final Object source_id = m.getAttribute(IMarker.SOURCE_ID);
       if (source_id != null
           && source_id instanceof String
           && source_id.equals(file.getFullPath().toString())) {
         try {
           m.delete();
         } catch (final CoreException e) {
           // not much to do
         }
       }
     }
   } catch (final CoreException e) {
     // not much to do
   }
 }
  public void testMissingType() {
    try {

      IType type = fProject.findType("tests.apiusescan.coretestproject.IConstants");
      type.rename("IConstants1", true, null);
      IProject project = fProject.getProject();
      ExternalDependencyTestUtils.waitForBuild();

      IMarker[] markers =
          project.findMarkers(
              IApiMarkerConstants.API_USESCAN_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
      assertEquals(
          "No API Use Scan problem marker found for missing type IConstants", 1, markers.length);
      String typeName = markers[0].getAttribute(IApiMarkerConstants.API_USESCAN_TYPE, null);
      assertEquals(
          "Marker for missing type IConstants not found",
          "tests.apiusescan.coretestproject.IConstants",
          typeName);

      type = fProject.findType("tests.apiusescan.coretestproject.IConstants1");
      type.rename("IConstants", true, null);
      ExternalDependencyTestUtils.waitForBuild();
      markers =
          project.findMarkers(
              IApiMarkerConstants.API_USESCAN_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
      assertEquals(
          "API Use Scan problem marker for missing type IConstants did not clear",
          0,
          markers.length);
    } catch (JavaModelException e) {
      fail(e.getMessage());
    } catch (CoreException e) {
      fail(e.getMessage());
    }
  }
 public void testMarkersAreAdded() throws Exception {
   myProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
   SynchronizationUtils.joinBackgroudActivities();
   assertEquals(
       "Simple AJ Project should contain 2 advice markers after building",
       2,
       myProject.findMarkers(IAJModelMarker.ADVICE_MARKER, true, IResource.DEPTH_INFINITE)
           .length); //$NON-NLS-1$
   assertEquals(
       "Simple AJ Project should contain 2 source advice markers after building",
       2,
       myProject.findMarkers(IAJModelMarker.SOURCE_ADVICE_MARKER, true, IResource.DEPTH_INFINITE)
           .length); //$NON-NLS-1$
 }
Example #4
0
 public static void removeDialyzerWarningMarkers(final IProject project) {
   try {
     final IMarker[] markers =
         project.findMarkers(DIALYZE_WARNING_MARKER, true, IResource.DEPTH_INFINITE);
     for (final IMarker m : markers) {
       m.delete();
     }
   } catch (final CoreException e) {
     ErlLogger.error(e);
   }
 }
Example #5
0
 public static void updateAllSonarMarkerSeverity() throws CoreException {
   for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
     if (project.isAccessible()) {
       for (IMarker marker :
           project.findMarkers(SonarCorePlugin.MARKER_ID, true, IResource.DEPTH_INFINITE)) {
         boolean isNew = marker.getAttribute(SONAR_MARKER_IS_NEW_ATTR, false);
         marker.setAttribute(
             IMarker.SEVERITY, isNew ? markerSeverityForNewIssues : markerSeverity);
       }
     }
   }
 }
  public void setViolationSeverity(int severity) {
    validateSeverity(severity);
    int oldSeverity = getViolationSeverity();

    if (severity != oldSeverity) {
      getModelProperties().setViolationSeverity(severity);

      for (IProject project : projects) {
        try {
          if (oldSeverity == -1) {
            model.accept(new ModelProblemCollector(this, project));
          } else if (severity != -1) {
            for (IMarker marker :
                project.findMarkers(defaults.MARKER_TYPE, true, IResource.DEPTH_INFINITE))
              marker.setAttribute(IMarker.SEVERITY, severity);
          } else project.deleteMarkers(defaults.MARKER_TYPE, true, IResource.DEPTH_INFINITE);
        } catch (CoreException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
 /**
  * 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;
 }
  public void test001_missingParent() throws Exception {
    IProject p2 = createExisting("t001-p2");
    waitForJobsToComplete();

    assertNull(manager.create(p2, monitor));

    IMarker[] markers = p2.findMarkers(null, true, IResource.DEPTH_INFINITE);
    assertEquals(WorkspaceHelpers.toString(markers), 1, markers.length);
    WorkspaceHelpers.assertErrorMarker(
        IMavenConstants.MARKER_POM_LOADING_ID,
        "Project build error: Non-resolvable parent POM: Failure to find t001:t001-p3:pom:0.0.1-SNAPSHOT in file:remoterepo was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM",
        1 /*lineNumber*/,
        markers[0]);

    IProject p3 = createExisting("t001-p3");
    waitForJobsToComplete();

    assertNotNull(manager.create(p2, monitor));

    deleteProject(p3);
    waitForJobsToComplete();

    assertNull(manager.create(p2, monitor));
  }