Skip to content

Commit

Permalink
Create separate markers for classpath problems
Browse files Browse the repository at this point in the history
Previously classpath updates would delete problem markers added
during project provisioning. This is now avoided because they use
a separate marker type.

Fixes #490
  • Loading branch information
Gunnar Wagenknecht authored and guw committed Mar 23, 2024
1 parent ff4659d commit e8fb75b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
9 changes: 9 additions & 0 deletions bundles/com.salesforce.bazel.eclipse.core/plugin.xml
Expand Up @@ -70,6 +70,15 @@
<super type="org.eclipse.core.resources.textmarker"/>
<persistent value="true"/>
</extension>
<extension
id="container_problem"
name="Bazel Classpath Container Build Path Problem"
point="org.eclipse.core.resources.markers">
<super type="com.salesforce.bazel.eclipse.core.buildpath_problem"/>
<super type="org.eclipse.core.resources.problemmarker"/>
<super type="org.eclipse.core.resources.textmarker"/>
<persistent value="true"/>
</extension>
<extension
id="transient_problem"
name="Transient Bazel Problem"
Expand Down
Expand Up @@ -17,6 +17,9 @@ public interface BazelCoreSharedContstants {
/** Build Path related Bazel problem */
String BUILDPATH_PROBLEM_MARKER = PLUGIN_ID + ".buildpath_problem";

/** Classpath Container related Bazel problem */
String CLASSPATH_CONTAINER_PROBLEM_MARKER = PLUGIN_ID + ".container_problem";

/** transient Bazel problems, i.e. not persisted across restarts */
String TRANSIENT_PROBLEM_MARKER = PLUGIN_ID + ".transient_problem";

Expand Down
Expand Up @@ -6,7 +6,7 @@
import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.BAZEL_NATURE_ID;
import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.BUILDPATH_PROBLEM_MARKER;
import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.CLASSPATH_CONTAINER_ID;
import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.PROBLEM_MARKER;
import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.CLASSPATH_CONTAINER_PROBLEM_MARKER;
import static com.salesforce.bazel.eclipse.core.model.discovery.EclipsePreferencesHelper.convertToPreferences;
import static com.salesforce.bazel.eclipse.core.model.discovery.JvmConfigurator.VM_TYPE_RUNTIME;
import static com.salesforce.bazel.eclipse.core.model.discovery.JvmConfigurator.VM_TYPE_TOOLCHAIN;
Expand Down Expand Up @@ -528,7 +528,7 @@ protected void analyzeProjectInfo(BazelProject project, JavaProjectInfo javaInfo
}

// delete existing markers
project.getProject().deleteMarkers(PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
deleteBuildPathProblems(project);

// abort if canceled
if (monitor.isCanceled()) {
Expand Down Expand Up @@ -762,6 +762,21 @@ protected IMarker createBuildPathProblem(BazelProject project, IStatus status) t
return createMarker(project.getProject(), BUILDPATH_PROBLEM_MARKER, status);
}

/**
* Creates a problem marker of type {@link BazelCoreSharedContstants#CLASSPATH_CONTAINER_PROBLEM_MARKER} for the
* given status.
*
* @param project
* the project to create the marker at (must not be <code>null</code>)
* @param status
* the status to create the marker for (must not be <code>null</code>)
* @return the created marker (never <code>null</code>)
* @throws CoreException
*/
protected IMarker createClasspathContainerProblem(BazelProject project, IStatus status) throws CoreException {
return createMarker(project.getProject(), CLASSPATH_CONTAINER_PROBLEM_MARKER, status);
}

/**
* Creates a folder hierarchy and marks them as derived (because they are generated and should not go into SCM)
*
Expand Down Expand Up @@ -971,6 +986,18 @@ protected void deleteBuildPathProblems(BazelProject project) throws CoreExceptio
project.getProject().deleteMarkers(BUILDPATH_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
}

/**
* Convenience method to delete all markers of type
* {@link BazelCoreSharedContstants#CLASSPATH_CONTAINER_PROBLEM_MARKER} from the Bazel project
*
* @param project
* the project to create the marker at (must not be <code>null</code>)
* @throws CoreException
*/
protected void deleteClasspathContainerProblems(BazelProject project) throws CoreException {
project.getProject().deleteMarkers(CLASSPATH_CONTAINER_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
}

/**
* Queries <code>@bazel_tools//tools/jdk:current_java_toolchain</code> for extracting information about the default
* Java toolchain used by the workspace.
Expand Down
Expand Up @@ -199,11 +199,11 @@ public Map<BazelProject, Collection<ClasspathEntry>> computeClasspaths(Collectio
var classpath = classpathInfo.compute();

// remove old marker
deleteBuildPathProblems(bazelProject);
deleteClasspathContainerProblems(bazelProject);

// create problem markers for detected issues
for (IStatus problem : buildPathProblems) {
createBuildPathProblem(bazelProject, problem);
createClasspathContainerProblem(bazelProject, problem);
}

// check for non existing jars
Expand All @@ -213,7 +213,7 @@ public Map<BazelProject, Collection<ClasspathEntry>> computeClasspaths(Collectio
}

if (!isRegularFile(entry.getPath().toPath())) {
createBuildPathProblem(
createClasspathContainerProblem(
bazelProject,
Status.error(
format(
Expand Down
Expand Up @@ -117,12 +117,12 @@ public Map<BazelProject, Collection<ClasspathEntry>> computeClasspaths(Collectio
var classpathInfo = new JavaAspectsClasspathInfo(aspectsInfo, workspace);

// remove old marker
deleteBuildPathProblems(bazelProject);
deleteClasspathContainerProblems(bazelProject);

// add the target
var problem = classpathInfo.addTarget(bazelProject.getBazelTarget());
if (!problem.isOK()) {
createBuildPathProblem(bazelProject, problem);
createClasspathContainerProblem(bazelProject, problem);
}

// compute the classpath
Expand All @@ -135,7 +135,7 @@ public Map<BazelProject, Collection<ClasspathEntry>> computeClasspaths(Collectio
}

if (!isRegularFile(entry.getPath().toPath())) {
createBuildPathProblem(
createClasspathContainerProblem(
bazelProject,
Status.error(
format(
Expand Down

0 comments on commit e8fb75b

Please sign in to comment.