Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more trace to understand the project import success rate #2726

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.core.IJavaModelMarker;
import org.eclipse.jdt.core.compiler.IProblem;

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
Expand Down Expand Up @@ -383,4 +384,9 @@ public static IMarker createWarningMarker(String type, IResource resource, Strin
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
return marker;
}

public static boolean isUnresolvedImportError(IMarker marker) {
return marker.getAttribute(IMarker.SEVERITY, 0) == IMarker.SEVERITY_ERROR
&& marker.getAttribute(IJavaModelMarker.ID, 0) == IProblem.ImportNotFound;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IJavaProject;
Expand All @@ -31,6 +34,7 @@
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;

import com.google.gson.JsonArray;
Expand Down Expand Up @@ -89,6 +93,9 @@ public void onBuildFinished(long buildFinishedTime) {
int javaProjectCount = 0;
JsonArray buildToolNamesList = new JsonArray();

long projectErrors = 0;
long unresolvedImportErrors = 0;
boolean jdkMismatch = false;
for (IProject project : ProjectUtils.getAllProjects()) {
Optional<IBuildSupport> bs = this.projectsManager.getBuildSupport(project);
if (bs.isPresent() && !ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
Expand All @@ -106,9 +113,36 @@ public void onBuildFinished(long buildFinishedTime) {
sourceLevelMax = Float.parseFloat(sourceLevel);
}
}

try {
IMarker[] projectMarkers = project.findMarkers(null /* all markers */, true /* subtypes */, IResource.DEPTH_ZERO);
projectErrors += Stream.of(projectMarkers).filter(m -> m.getAttribute(IMarker.SEVERITY, 0) == IMarker.SEVERITY_ERROR).count();
IMarker[] allmarkers = project.findMarkers(null /* all markers */, true /* subtypes */, IResource.DEPTH_INFINITE);
unresolvedImportErrors += Stream.of(allmarkers).filter(m -> ResourceUtils.isUnresolvedImportError(m)).count();
} catch (CoreException e) {
// ignore
}

IJavaProject javaProject = ProjectUtils.getJavaProject(project);
if (javaProject != null) {
try {
IVMInstall vmInstall = JavaRuntime.getVMInstall(javaProject);
if (JavaRuntime.compareJavaVersions(vmInstall, sourceLevel) < 0) {
jdkMismatch = true;
}
} catch (CoreException e) {
// ignore
}

}
}
}

properties.addProperty("project.projectErrorCount", Long.toString(projectErrors));
properties.addProperty("project.unresolvedImportErrorCount", Long.toString(unresolvedImportErrors));
properties.addProperty("project.autobuild", Boolean.toString(prefs.getPreferences().isAutobuildEnabled()));
properties.addProperty("project.jdkMismatch", Boolean.toString(jdkMismatch));

long projectInitElapsedTime, serviceReadyElapsedTime, buildFinishedElapsedTime;
projectInitElapsedTime = this.projectsInitializedTime - this.languageServerStartTime;
serviceReadyElapsedTime = this.serviceReadyTime - this.languageServerStartTime;
Expand Down