Java Code Examples for org.eclipse.core.resources.IProject#findMarkers()

The following examples show how to use org.eclipse.core.resources.IProject#findMarkers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns all build errors on the specified projects. Uses all projects in the
 * workspace if {@code projects} is empty.
 */
public static Set<String> getAllBuildErrors(IProject... projects) throws CoreException {
  if (projects.length == 0) {
    projects = getWorkspace().getRoot().getProjects();
  }

  Set<String> errors = new LinkedHashSet<>();
  for (IProject project : projects) {
    IMarker[] problems = project.findMarkers(IMarker.PROBLEM, true /* includeSubtypes */,
        IResource.DEPTH_INFINITE);
    for (IMarker problem : problems) {
      int severity = problem.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
      if (severity >= IMarker.SEVERITY_ERROR) {
        errors.add(formatProblem(problem));
      }
    }
  }
  return errors;
}
 
Example 2
Source File: AbstractSarlMavenTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create and compile a maven project from the given content of the POM file.
 *
 * @param pomFileContent the content of he POM file.
 * @return the markers on the project.
 * @throws Exception if any exception.
 */
protected IMarker[] createMavenProject(String pomFileContent) throws Exception {
	IFile pomFile = helper().createFileImpl(helper().getFullFileNameInProject("pom.xml"), pomFileContent);
	IProject project = helper().getProject();
	IProjectDescription description = project.getDescription();
	String[] natures = description.getNatureIds();
	String[] newNatures = new String[natures.length];
	System.arraycopy(natures, 0, newNatures, 0, natures.length);
	newNatures[newNatures.length - 1] = SARLEclipseConfig.MAVEN_NATURE_ID;
	description.setNatureIds(newNatures);
	project.setDescription(description, new NullProgressMonitor());

	helper().awaitAutoBuild();

	MavenPluginActivator.getDefault().getProjectConfigurationManager().updateProjectConfiguration(
			project, new NullProgressMonitor());

	helper().awaitAutoBuild();

	return project.findMarkers(null, true, IResource.DEPTH_INFINITE); 
}
 
Example 3
Source File: JavaUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public static File buildProject(IProject project) throws CoreException{
	project.build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
	project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
	IMarker[] markers;
	markers = project.findMarkers(IMarker.PROBLEM, true,IResource.DEPTH_INFINITE);
	boolean errorsExists=false;
	StringBuffer sb=new StringBuffer();
	for (IMarker marker : markers) {
		if(marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR) {
			sb.append(marker.getAttribute(IMarker.MESSAGE)).append("\n");
			errorsExists=true;
		}
	}
	if (errorsExists){
		throw new CoreException(new Status(IStatus.ERROR,Activator.PLUGIN_ID,"Compilation error exists in the project "+project.getName()+". Please resolve these error before continuing:\n"+sb.toString()));
	}
	return new File(project.getWorkspace().getRoot().getFolder(getJavaOutputDirectory(project)).getLocation().toOSString());
}
 
Example 4
Source File: ASTReader.java    From JDeodorant with MIT License 6 votes vote down vote up
private List<IMarker> buildProject(IJavaProject iJavaProject, IProgressMonitor pm) {
	ArrayList<IMarker> result = new ArrayList<IMarker>();
	try {
		IProject project = iJavaProject.getProject();
		project.refreshLocal(IResource.DEPTH_INFINITE, pm);	
		project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, pm);
		IMarker[] markers = null;
		markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
		for (IMarker marker: markers) {
			Integer severityType = (Integer) marker.getAttribute(IMarker.SEVERITY);
			if (severityType.intValue() == IMarker.SEVERITY_ERROR) {
				result.add(marker);
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return result;
}
 
Example 5
Source File: IncrementalDotnetBuilder.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
	IProject project = getProject();
	IMarker[] errorMarkers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
	if (errorMarkers.length == 0) {
		runDotnetSubCommand("build", project, monitor); //$NON-NLS-1$
	}
	return null;
}
 
Example 6
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private List<IMarker> getProblemMarkers(IProgressMonitor monitor) throws CoreException {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	List<IMarker> markers = new ArrayList<>();
	for (IProject project : projects) {
		if (monitor != null && monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(project)) {
			continue;
		}
		IMarker[] allMarkers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
		for (IMarker marker : allMarkers) {
			if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) {
				continue;
			}
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(marker.getType()) || IJavaModelMarker.TASK_MARKER.equals(marker.getType())) {
				markers.add(marker);
				continue;
			}
			IResource resource = marker.getResource();
			if (project.equals(resource) || projectsManager.isBuildFile(resource)) {
				markers.add(marker);
			}
		}
	}
	return markers;
}
 
Example 7
Source File: AbstractJavaGeneratorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public IMarker[] generateAndCompile(Statechart statechart) throws Exception {
	GeneratorEntry entry = createGeneratorEntry(statechart.getName(), SRC_GEN);
	entry.setElementRef(statechart);
	IProject targetProject = getProject(entry);
	targetProject.delete(true, new NullProgressMonitor());
	targetProject = getProject(entry);
	if (!targetProject.exists()) {
		targetProject.create(new NullProgressMonitor());
		targetProject.open(new NullProgressMonitor());
	}
	IGeneratorEntryExecutor executor = new EclipseContextGeneratorExecutorLookup() {
		protected Module getContextModule() {
			return Modules.override(super.getContextModule()).with(new Module() {
				@Override
				public void configure(Binder binder) {
					binder.bind(IConsoleLogger.class).to(TestLogger.class);
				}
			});
		};
	}.createExecutor(entry, "yakindu::java");
	executor.execute(entry);
	targetProject.refreshLocal(IResource.DEPTH_INFINITE, null);
	targetProject.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
	targetProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
	IMarker[] markers = targetProject.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
			IResource.DEPTH_INFINITE);
	return markers;
}
 
Example 8
Source File: JavaCompilationParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void testClean() throws CoreException {
  IProject project = getTestProject().getProject();
  IEclipsePreferences prefs = new InstanceScope().getNode("org.eclipse.core.resources");

  // Disable auto-building so we don't race with the build process.
  prefs.putBoolean("description.autobuilding", false);

  // Verify that we have existing problem markers
  IMarker[] markers = project.findMarkers(GWTJavaProblem.MARKER_ID, true,
      IResource.DEPTH_INFINITE);
  assertTrue(markers.length > 0);

  // Verify that we have existing JavaRefIndex entries
  assertEquals(3, JavaRefIndex.getInstance().size());

  // Clean the test project
  project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);

  // Wait for the validation job to complete.
  JobsUtilities.waitForIdle();

  // Verify that the problems went away
  markers = project.findMarkers(GWTJavaProblem.MARKER_ID, true,
      IResource.DEPTH_INFINITE);
  assertEquals(0, markers.length);

  // Verify that the JavaRefIndex entries went away
  assertEquals(0, JavaRefIndex.getInstance().size());

  // Re-enable auto-building
  prefs.putBoolean("description.autobuilding", true);
}
 
Example 9
Source File: ProjectUtils.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static void buildProject(final IProject project) throws Exception {
    try {
        project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
        project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
    } catch (Exception e) {
        throw new Exception("Could not build project", e); // $NLX-ProjectUtils.Couldnotbuildproject-1$
    }

    IMarker[] markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
    if (markers.length > 0) {
        throw new Exception("Plug-in project did not compile. Ensure that the Class and JAR files are correct."); // $NLX-ProjectUtils.PluginprojectdidnotcompileEnsuret-1$
    }
}
 
Example 10
Source File: JavaCompilationParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private IMarker[] getGWTProblemMarkers(IProject project) throws CoreException {
  return project.findMarkers(GWTJavaProblem.MARKER_ID, true,
      IResource.DEPTH_INFINITE);
}