diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/FileLocation.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/FileLocation.java deleted file mode 100644 index 1f55602e0..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/FileLocation.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.core.internal.gradle; - -public class FileLocation implements ProblemLocation { - - private final String path; - private final Integer line; - private final Integer column; - private final Integer length; - - public FileLocation(String path, Integer line, Integer column, Integer length) { - this.path = path; - this.line = line; - this.column = column; - this.length = length; - } - - public String getPath() { - return this.path; - } - - public Integer getLine() { - return this.line; - } - - public Integer getColumn() { - return this.column; - } - - public Integer getLength() { - return this.length; - } -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/Problem.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/Problem.java deleted file mode 100644 index 2595a4fd9..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/Problem.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.core.internal.gradle; - -import java.util.List; -import java.util.Optional; -import java.util.Set; - -/** - * Represents a problem reported via Gradle's Problems service. - */ -public class Problem { - - private final String label; - private final ProblemSeverity severity; - private final Set locations; - private final Optional documentationLink; - private final List solutions; - private final ProblemCategory category; - - public Problem( - String label, - ProblemSeverity severity, - Set locations, - String documentationLink, // TODO do we want only one link? - List solutions, - // TODO how to represent exceptions? List? - ) { - this.label = label; - this.severity = severity; - this.locations = locations; - this.documentationLink = Optional.ofNullable(documentationLink); - this.solutions = solutions; - this.category = category; - } - - public String getLabel() { - return this.label; - } - - public ProblemSeverity getSeverity() { - return this.severity; - } - - public Set getLocations() { - return this.locations; - } - - public Optional getDocumentationLink() { - return this.documentationLink; - } - - public List getSolutions() { - return this.solutions; - } - - public ProblemCategory getCategory() { - return this.category; - } -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemCategory.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemCategory.java deleted file mode 100644 index 7c938a1b4..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemCategory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ - -package org.eclipse.buildship.core.internal.gradle; - - -public class ProblemCategory { - - private final String category; - - // TODO adapt new categorization scheme - public ProblemCategory(String category) { - this.category = category; - } - - public String getCategory() { - return this.category; - } -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemLocation.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemLocation.java deleted file mode 100644 index d27f10325..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemLocation.java +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ - - package org.eclipse.buildship.core.internal.gradle; - - -public interface ProblemLocation { - -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemParser.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemParser.java deleted file mode 100644 index 9c49ad288..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemParser.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.core.internal.gradle; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -public class ProblemParser { - - public static Problem parse(String json) { - JsonObject problemJsonElement = JsonParser.parseString(json).getAsJsonObject(); - String label = new ProblemLabelParser().parse(problemJsonElement); - ProblemSeverity severity = new ProblemSeverityParser().parse(problemJsonElement); - Set locations = new ProblemLocationsParser().parse(problemJsonElement); - String documentationLink = new ProblemDocumentationParser().parse(problemJsonElement); - List solutions = new ProblemSolutionsParser().parse(problemJsonElement); - ProblemCategory category = new ProblemCategoryParser().parse(problemJsonElement); - return new Problem(label, severity, locations, documentationLink, solutions, category); - } - - static interface ProblemPropertyParser { - T parse(JsonObject problemJson); - } - - static class ProblemLabelParser implements ProblemPropertyParser { - - @Override - public String parse(JsonObject problemJson) { - return problemJson.get("label").getAsString(); - } - } - - static class ProblemSeverityParser implements ProblemPropertyParser { - - @Override - public ProblemSeverity parse(JsonObject problemJson) { - String severityString = problemJson.get("severity").getAsString(); - try { - return ProblemSeverity.valueOf(severityString); - } catch (Exception e) { - return ProblemSeverity.WARNING; - } - } - } - - static class ProblemLocationsParser implements ProblemPropertyParser> { - - @Override - public Set parse(JsonObject problemJson) { - JsonElement where = problemJson.get("where"); - if (where != null) { - Set result = new LinkedHashSet<>(); - if (where.isJsonObject()) { - maybeAddLocation(where.getAsJsonObject(), result); - } else if (where.isJsonArray()) { - JsonArray locations = where.getAsJsonArray(); - for (JsonElement l : locations) { - if (l.isJsonObject()) { - maybeAddLocation(l.getAsJsonObject(), result); - } - } - } - return result; - } else { - return Collections.emptySet(); - } - } - - private static void maybeAddLocation(JsonObject location, Set result) { - if (location.has("path")) { - String path = location.get("path").getAsString(); - Integer line = location.has("line") ? location.get("line").getAsInt() : null; - Integer column = location.has("column") ? location.get("column").getAsInt() : null; - Integer length = location.has("length") ? location.get("length").getAsInt() : null; - result.add(new FileLocation(path, line, column, length)); - } else if (location.has("identityPath")) { - JsonObject pathObject = location.get("identityPath").getAsJsonObject(); - String fullPath = pathObject.get("fullPath").getAsString(); - result.add(new TaskLocation(fullPath)); - } - } - } - - static class ProblemDocumentationParser implements ProblemPropertyParser { - - @Override - public String parse(JsonObject problemJson) { - // TODO this is incorrect as we don't have information about the current Gradle version. - // The url creation should happen within either the Gradle daemon or the TAPI internals. - if (problemJson.has("documentationLink")) { - JsonObject docLinkObject = problemJson.get("documentationLink").getAsJsonObject(); - if (docLinkObject.has("page")) { - String page = docLinkObject.get("page").getAsString(); - if (docLinkObject.has("section")) { - String section = docLinkObject.get("section").getAsString(); - return String.format("%s/userguide/%s.html#%s", "https://docs.gradle.org/current", page, section); - } else { - return String.format("%s/userguide/%s.html", "https://docs.gradle.org/current", page); - } - } else { - return null; - } - } - else { - return null; - } - } - } - - static class ProblemSolutionsParser implements ProblemPropertyParser> { - - @Override - public List parse(JsonObject problemJson) { - JsonArray solutions = problemJson.get("solutions").getAsJsonArray(); - List result = new ArrayList<>(solutions.size()); - for (JsonElement s : solutions) { - result.add(s.getAsString()); - } - return result; - } - } - - static class ProblemCategoryParser implements ProblemPropertyParser { - - @Override - public ProblemCategory parse(JsonObject problemJson) { - // TODO This will change once https://github.com/gradle/gradle/pull/26510 is merged - if (problemJson.has("problemType")) { - return new ProblemCategory(problemJson.get("problemType").getAsString()); - } else { - return new ProblemCategory(problemJson.get("problemCategory").getAsString()); - } - - } - } -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemSeverity.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemSeverity.java deleted file mode 100644 index f586cbe7a..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/ProblemSeverity.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.core.internal.gradle; - - -public enum ProblemSeverity { - ADVICE, - WARNING, - ERROR -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/TaskLocation.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/TaskLocation.java deleted file mode 100644 index bd5c79bb7..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/gradle/TaskLocation.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.core.internal.gradle; - - -public class TaskLocation implements ProblemLocation { - - private final String identityPath; - - public TaskLocation(String identityPath) { - this.identityPath = identityPath; - } - - - public String getIdentityPath() { - return this.identityPath; - } -} diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemAdapter.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemAdapter.java deleted file mode 100644 index f1a314972..000000000 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemAdapter.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Gradle Inc. and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.core.internal.util.progress; - -import java.util.Optional; - -import org.gradle.tooling.events.problems.ProblemDescriptor; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -import org.eclipse.buildship.core.internal.gradle.FileLocation; -import org.eclipse.buildship.core.internal.gradle.Problem; -import org.eclipse.buildship.core.internal.gradle.ProblemSeverity; -import org.eclipse.buildship.core.internal.util.gradle.Pair; - -public class ProblemAdapter { - - private Problem problem; - - private ProblemAdapter(Problem problem) { - this.problem = problem; - } - - public static ProblemAdapter from(Problem problem) { - return new ProblemAdapter(problem); - } - - public Problem getProblem() { - return this.problem; - } - - public int toMarkerSeverity() { - ProblemSeverity severity = this.problem.getSeverity(); - switch (severity) { - case WARNING: - return IMarker.SEVERITY_WARNING; - case ADVICE: - return IMarker.SEVERITY_INFO; - case ERROR: - return IMarker.SEVERITY_ERROR; - default: - return IMarker.SEVERITY_INFO; - } - } - - public Optional firstFileLocation() { - return this.problem.getLocations().stream().filter(FileLocation.class::isInstance).map(FileLocation.class::cast).findFirst(); - } - - public Optional> resourceAndFileNumberOfFirstFileLocation() { - return firstFileLocation().map(location -> new Pair<>(toResource(location), lineNumberOf(location))); - } - - private static IResource toResource(FileLocation location) { - IPath absolutePath = Path.fromOSString(location.getPath()); - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IFile workspacePath = workspaceRoot.getFileForLocation(absolutePath); - if (workspacePath.exists()) { - return workspacePath; - } - return ResourcesPlugin.getWorkspace().getRoot(); - } - - private static Integer lineNumberOf(FileLocation location) { - if (location.getLine() != null) { - return location.getLine(); - } - return -1; - } -} 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 70dcf687f..5e7a5e675 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 @@ -15,7 +15,10 @@ import org.gradle.tooling.events.ProgressEvent; import org.gradle.tooling.events.ProgressListener; import org.gradle.tooling.events.problems.BaseProblemDescriptor; +import org.gradle.tooling.events.problems.FileLocation; import org.gradle.tooling.events.problems.LineInFileLocation; +import org.gradle.tooling.events.problems.ProblemAggregation; +import org.gradle.tooling.events.problems.ProblemAggregationDescriptor; import org.gradle.tooling.events.problems.ProblemDescriptor; import org.gradle.tooling.events.problems.ProblemEvent; import org.gradle.tooling.events.problems.Solution; @@ -29,7 +32,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.buildship.core.internal.CorePlugin; -import org.eclipse.buildship.core.internal.gradle.FileLocation; import org.eclipse.buildship.core.internal.marker.GradleErrorMarker; import org.eclipse.buildship.core.internal.util.gradle.Pair; import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild; @@ -46,13 +48,19 @@ public ProblemsReportingProgressListener(InternalGradleBuild gradleBuild) { public void statusChanged(ProgressEvent event) { if (event instanceof ProblemEvent) { ProblemEvent problemEvent = (ProblemEvent) event; - BaseProblemDescriptor descriptor = problemEvent.getDescriptor(); - if (descriptor instanceof ProblemDescriptor) { - try { - reportProblem((ProblemDescriptor) descriptor); - } catch (Exception e) { - CorePlugin.logger().warn("Cannot report problem " + problemEvent, e); + BaseProblemDescriptor eventDescriptor = problemEvent.getDescriptor(); + try { + if (eventDescriptor instanceof ProblemDescriptor) { + reportProblem((ProblemDescriptor) eventDescriptor); + } else if (eventDescriptor instanceof ProblemAggregationDescriptor) { + for (ProblemAggregation aggregation : ((ProblemAggregationDescriptor) eventDescriptor).getAggregations()) { + for (ProblemDescriptor descriptor : aggregation.getProblemDescriptors()) { + reportProblem(descriptor); + } + } } + } catch (Exception e) { + CorePlugin.logger().warn("Cannot report problem " + problemEvent, e); } } }