diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/WorkspaceConfigurationPersistence.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/WorkspaceConfigurationPersistence.java index 1112ab00f..a5ccdb75f 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/WorkspaceConfigurationPersistence.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/WorkspaceConfigurationPersistence.java @@ -73,7 +73,7 @@ public WorkspaceConfiguration readWorkspaceConfig() { boolean showConsoleView = preferences.getBoolean(SHOW_CONSOLE_VIEW, true); boolean showExecutionsView = preferences.getBoolean(SHOW_EXECUTIONS_VIEW, true); boolean moduleSupport = preferences.getBoolean(EXPERIMENTAL_ENABLE_MODULE_SUPPORT, false); - boolean problemsApiSupport = preferences.getBoolean(PROBLEMS_API_SUPPORT, true); + boolean problemsApiSupport = preferences.getBoolean(PROBLEMS_API_SUPPORT, false); return new WorkspaceConfiguration(distribution, gradleUserHome, javaHome, offlineMode, buildScansEnabled, autoSyncEnabled, arguments, jvmArguments, showConsoleView, showExecutionsView, moduleSupport, problemsApiSupport); } diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java index 1bc3ec150..ada35cb2d 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java @@ -10,7 +10,7 @@ package org.eclipse.buildship.core.internal.util.progress; import java.util.List; -import java.util.Optional; +import java.util.function.Consumer; import org.gradle.tooling.Failure; import org.gradle.tooling.events.ProgressEvent; @@ -23,6 +23,8 @@ import org.gradle.tooling.events.problems.ProblemEvent; import org.gradle.tooling.events.problems.SingleProblemEvent; +import com.google.common.base.Strings; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -61,87 +63,60 @@ public void statusChanged(ProgressEvent event) { private void reportProblem(SingleProblemEvent event) { List locations = event.getLocations(); - - // 1/4 offset in file location - Optional offsetInFileLocation = locations.stream().filter(OffsetInFileLocation.class::isInstance).map(OffsetInFileLocation.class::cast).findFirst(); - if (offsetInFileLocation.isPresent()) { - IResource resource = toResource(offsetInFileLocation.get()); - - GradleErrorMarker.createProblemMarker( - toMarkerSeverity(event.getDefinition().getSeverity()), - resource, - this.gradleBuild, - markerMessage(event), - stacktraceStringFor(event.getFailure().getFailure()), - marker -> { - OffsetInFileLocation location = offsetInFileLocation.get(); - int startOffset = location.getOffset(); - int endOffset = location.getLength(); - try { - marker.setAttribute(IMarker.CHAR_START, startOffset); - marker.setAttribute(IMarker.CHAR_END, startOffset + endOffset); - } catch (CoreException e) { - throw new RuntimeException(e); - } - }, - new ProblemEventAdapter(event) - ); - return; - } - - // 2/4 line in file location - Optional lineInFileLocation = locations.stream().filter(LineInFileLocation.class::isInstance).map(LineInFileLocation.class::cast).findFirst(); - if (lineInFileLocation.isPresent()) { - IResource resource = toResource(lineInFileLocation.get()); - GradleErrorMarker.createProblemMarker( - toMarkerSeverity(event.getDefinition().getSeverity()), - resource, - this.gradleBuild, - markerMessage(event), - stacktraceStringFor(event.getFailure().getFailure()), - marker -> { - Integer lineNumber = lineNumberOf(lineInFileLocation.get()); - if (lineNumber >= 0) { - try { - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - } catch (CoreException e) { - throw new RuntimeException(e); - } - } - }, - new ProblemEventAdapter(event) - ); - return; - } - - // 3/4 file location - Optional fileLocation = locations.stream().filter(FileLocation.class::isInstance).map(FileLocation.class::cast).findFirst(); - if (fileLocation.isPresent()) { - IResource resource = toResource(fileLocation.get()); - GradleErrorMarker.createProblemMarker( - toMarkerSeverity(event.getDefinition().getSeverity()), - resource, - this.gradleBuild, - markerMessage(event), - stacktraceStringFor(event.getFailure().getFailure()), - m -> {}, - new ProblemEventAdapter(event) - ); - return; - } - - // 4/4 no location GradleErrorMarker.createProblemMarker( toMarkerSeverity(event.getDefinition().getSeverity()), - ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(this.gradleBuild.getBuildConfig().getRootProjectDirectory().getAbsolutePath())), + findMarkerResource(locations), this.gradleBuild, markerMessage(event), stacktraceStringFor(event.getFailure().getFailure()), - m -> {}, + markerPositionConfiguration(locations), new ProblemEventAdapter(event) ); } + private IResource findMarkerResource(List locations) { + return locations.stream() + .filter(FileLocation.class::isInstance) + .map(FileLocation.class::cast).findFirst() + .map(fl -> toResource(fl)) + .orElseGet(() -> ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(rootProjectPath()))); + } + + private String rootProjectPath() { + return ProblemsReportingProgressListener.this.gradleBuild.getBuildConfig().getRootProjectDirectory().getAbsolutePath(); + } + + private Consumer markerPositionConfiguration(List locations) { + for (Location location : locations) { + if (location instanceof OffsetInFileLocation) { + return marker -> { + OffsetInFileLocation offsetLocation = ((OffsetInFileLocation) location); + int startOffset = offsetLocation.getOffset(); + int endOffset = offsetLocation.getLength(); + try { + marker.setAttribute(IMarker.CHAR_START, startOffset); + marker.setAttribute(IMarker.CHAR_END, startOffset + endOffset); + } catch (CoreException e) { + throw new RuntimeException(e); + } + }; + } else if (location instanceof LineInFileLocation) { + return marker -> { + + Integer lineNumber = lineNumberOf((FileLocation) location); + if (lineNumber >= 0) { + try { + marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); + } catch (CoreException e) { + throw new RuntimeException(e); + } + } + }; + } + } + return notUsed -> {}; + } + private static String markerMessage(SingleProblemEvent problem ) { String result = problem.getDetails().getDetails(); if (result == null) { @@ -151,7 +126,7 @@ private static String markerMessage(SingleProblemEvent problem ) { result = problem.getDefinition().getId().getDisplayName(); } - return result == null ? "" : result; + return Strings.nullToEmpty(""); } private static String stacktraceStringFor(Failure failure) {