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

Render Gradle problem reports as Eclipse error markers #1306

Merged
merged 17 commits into from
Jul 22, 2024
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
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,18 @@ subprojects {
languageVersion = JavaLanguageVersion.of(8)
}
}
} else {
} else if (config.targetPlatform.eclipseVersion in ['417', '418', '419', '420', '421', '422', '423', '424']) {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
} else {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
}

tasks.matching { it instanceof JavaCompile || it instanceof GroovyCompile }.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ class BuildDefinitionPlugin implements Plugin<Project> {

onlyIf {
HashFunction sha512HashFunction = Hashing.sha512()
String hash = sha512HashFunction.hashString(config.targetPlatform.targetDefinition.text, StandardCharsets.UTF_8)
String manifests = project.rootProject.allprojects
.findAll { p -> p.plugins.hasPlugin(ExistingJarBundlePlugin) }
.toSorted { p1, p2 -> p1.name <=> p2.name }
.collect { p -> p.file("META-INF/MANIFEST.MF").exists() ? p.file("META-INF/MANIFEST.MF").text : null }
.findAll { it != null }
.join("\n")
String targetDef = config.targetPlatform.targetDefinition.text
String hashInput = manifests + "\n" + targetDef
String hash = sha512HashFunction.hashString(hashInput, StandardCharsets.UTF_8)
File digestFile = new File(config.nonMavenizedTargetPlatformDir, 'digest')
boolean digestMatch = digestFile.exists() ? digestFile.text == hash : false
!digestMatch
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# production library version numbers
toolingApiVersion=8.6
toolingApiVersion=8.9

# testing library version numbers
guavaVersion=33.0.0
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.buildship.compat/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Bundle-Version: 3.1.10.qualifier
Bundle-Vendor: Eclipse Buildship
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Require-Bundle: org.gradle.toolingapi;bundle-version="[8.6.0,8.7.0)";visibility:=reexport
Require-Bundle: org.gradle.toolingapi;bundle-version="[8.9.0,8.10.0)";visibility:=reexport
Export-Package: org.eclipse.buildship.core.internal.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BuildConfigurationTest extends ProjectSynchronizationSpecification {
WorkspaceConfiguration orignalConfiguration = configurationManager.loadWorkspaceConfiguration()

when:
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, workspaceGradleUserHome, workspaceJavaHome, offlineMode, buildScansEnabled, autoSync, workspaceArguments, workspaceJvmArguments, showConsole, showExecutions, false))
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, workspaceGradleUserHome, workspaceJavaHome, offlineMode, buildScansEnabled, autoSync, workspaceArguments, workspaceJvmArguments, showConsole, showExecutions, false, false))
BuildConfiguration configuration = createInheritingBuildConfiguration(projectDir)

then:
Expand Down Expand Up @@ -203,7 +203,7 @@ connection.gradle.distribution=MODIFIED_DISTRO"""

when:
configurationManager.saveBuildConfiguration(buildConfig)
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, workspaceGradleUserHome, workspaceJavaHome, offlineMode, buildScansEnabled, autoSync, workspaceArguments, workspaceJvmArguments, showConsole, showExecutions, false))
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, workspaceGradleUserHome, workspaceJavaHome, offlineMode, buildScansEnabled, autoSync, workspaceArguments, workspaceJvmArguments, showConsole, showExecutions, false, false))
buildConfig = configurationManager.loadBuildConfiguration(projectDir)

then:
Expand Down Expand Up @@ -242,7 +242,7 @@ connection.gradle.distribution=MODIFIED_DISTRO"""

when:
configurationManager.saveBuildConfiguration(buildConfig)
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(GradleDistribution.fromBuild(), null, null, !buildScansEnabled, !offlineMode, !autoSync, [], [], false, false, false))
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(GradleDistribution.fromBuild(), null, null, !buildScansEnabled, !offlineMode, !autoSync, [], [], false, false, false, false))
buildConfig = configurationManager.loadBuildConfiguration(projectDir)

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class ProjectConfigurationTest extends ProjectSynchronizationSpecification {

when:
configurationManager.saveProjectConfiguration(projectConfig)
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, gradleUserHome, javaHome, offlineMode, buildScansEnabled, autoSync, arguments, jvmArguments, showConsole, showExecutions, false))
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, gradleUserHome, javaHome, offlineMode, buildScansEnabled, autoSync, arguments, jvmArguments, showConsole, showExecutions, false, false))
projectConfig = configurationManager.loadProjectConfiguration(project)

then:
Expand Down Expand Up @@ -224,7 +224,7 @@ class ProjectConfigurationTest extends ProjectSynchronizationSpecification {

when:
configurationManager.saveProjectConfiguration(projectConfig)
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(GradleDistribution.fromBuild(), null, null, !buildScansEnabled, !offlineMode, !autoSync, [], [], false, false, false))
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(GradleDistribution.fromBuild(), null, null, !buildScansEnabled, !offlineMode, !autoSync, [], [], false, false, false, false))
projectConfig = configurationManager.loadProjectConfiguration(project)

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class WorkspaceConfigurationTest extends WorkspaceSpecification {
}

@Rollup
def "Can save workpsace configuration"(GradleDistribution distribution, String gradleUserHome, String javaHome, boolean offlineMode, boolean buildScansEnabled, boolean autoSync, List args, List jvmArgs, boolean showConsole, boolean showExecutions, moduleSupportEnabled) {
def "Can save workspace configuration"(GradleDistribution distribution, String gradleUserHome, String javaHome, boolean offlineMode, boolean buildScansEnabled, boolean autoSync, List args, List jvmArgs, boolean showConsole, boolean showExecutions, moduleSupportEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I guess that should be there

Suggested change
def "Can save workspace configuration"(GradleDistribution distribution, String gradleUserHome, String javaHome, boolean offlineMode, boolean buildScansEnabled, boolean autoSync, List args, List jvmArgs, boolean showConsole, boolean showExecutions, moduleSupportEnabled) {
def "Can save workspace configuration"(GradleDistribution distribution, String gradleUserHome, String javaHome, boolean offlineMode, boolean buildScansEnabled, boolean autoSync, List args, List jvmArgs, boolean showConsole, boolean showExecutions, boolean moduleSupportEnabled) {

setup:
WorkspaceConfiguration orignalConfiguration = configurationManager.loadWorkspaceConfiguration()

when:
File gradleUserHomeDir = dir(gradleUserHome)
File javaHomeDir = dir(javaHome)
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, gradleUserHomeDir, javaHomeDir, offlineMode, buildScansEnabled, autoSync, args, jvmArgs, showConsole, showExecutions, moduleSupportEnabled))
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(distribution, gradleUserHomeDir, javaHomeDir, offlineMode, buildScansEnabled, autoSync, args, jvmArgs, showConsole, showExecutions, moduleSupportEnabled, false))
WorkspaceConfiguration updatedConfiguration = configurationManager.loadWorkspaceConfiguration()

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.eclipse.core.resources.IMarker
import org.eclipse.core.runtime.IStatus

import org.eclipse.buildship.core.GradleDistribution
import org.eclipse.buildship.core.internal.CorePlugin
import org.eclipse.buildship.core.internal.configuration.WorkspaceConfiguration
import org.eclipse.buildship.core.internal.test.fixtures.ProjectSynchronizationSpecification

class GradleErrorMarkerTest extends ProjectSynchronizationSpecification {
Expand Down Expand Up @@ -128,6 +130,8 @@ class GradleErrorMarkerTest extends ProjectSynchronizationSpecification {

def "Convers problem reports to error markers"() {
setup:
WorkspaceConfiguration w = CorePlugin.configurationManager().loadWorkspaceConfiguration()
configurationManager.saveWorkspaceConfiguration(new WorkspaceConfiguration(w.gradleDistribution, w.gradleUserHome, w.javaHome, w.offline, w.buildScansEnabled, w.autoSync, w.arguments, w.jvmArguments, w.showConsoleView, w.showExecutionsView, w.experimentalModuleSupportEnabled , true))
File projectDir = dir('error-marker-test') {
file 'build.gradle', '''
import org.gradle.api.internal.GradleInternal
Expand All @@ -138,21 +142,24 @@ class GradleErrorMarkerTest extends ProjectSynchronizationSpecification {
def problems = gradleInternal.services.get(Problems)

problems.forNamespace("buildscript").reporting {
it.label("Problem label")
.category('deprecation', 'plugin')
it.id("id", 'My problem')
.details("Problem details")
.severity(Severity.WARNING)
.solution("Please use 'standard-plugin-2' instead of this plugin")
}
}
'''
}

when:
tryImportAndWait(projectDir)
importAndWait(projectDir)

then:
numOfGradleErrorMarkers == 1
gradleErrorMarkers[0].getAttribute(IMarker.MESSAGE) == 'Problem label'
gradleErrorMarkers[0].getAttribute(GradleErrorMarker.ATTRIBUTE_PROBLEM_CATEGORY) == 'buildscript:deprecation:plugin'
problemsApiErrorMarkers.size() == 1
problemsApiErrorMarkers[0].getAttribute(IMarker.MESSAGE) == 'Problem details'
problemsApiErrorMarkers[0].getAttribute(GradleErrorMarker.ATTRIBUTE_FQID) == 'generic:id'

cleanup:
CorePlugin.configurationManager().saveWorkspaceConfiguration(w)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.eclipse.debug.core.ILaunchManager
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore

import org.eclipse.buildship.core.GradleDistribution
import org.eclipse.buildship.core.internal.CorePlugin
import org.eclipse.buildship.core.internal.configuration.BuildConfiguration
import org.eclipse.buildship.core.internal.configuration.ConfigurationManager
Expand All @@ -40,7 +41,6 @@ import org.eclipse.buildship.core.internal.marker.GradleErrorMarker
import org.eclipse.buildship.core.internal.preferences.DefaultPersistentModel
import org.eclipse.buildship.core.internal.preferences.PersistentModel
import org.eclipse.buildship.core.internal.util.gradle.GradleVersion
import org.eclipse.buildship.core.GradleDistribution
import org.eclipse.buildship.core.internal.workspace.EclipseVmUtil
import org.eclipse.buildship.core.internal.workspace.PersistentModelBuilder
import org.eclipse.buildship.core.internal.workspace.WorkspaceOperations
Expand Down Expand Up @@ -247,7 +247,11 @@ abstract class WorkspaceSpecification extends Specification {
}

protected List<IMarker> getGradleErrorMarkers(IResource rootResource = workspace.root) {
rootResource.findMarkers(GradleErrorMarker.ID, false, IResource.DEPTH_INFINITE) as List
(rootResource.findMarkers(GradleErrorMarker.ID, false, IResource.DEPTH_INFINITE) as List).findAll { IMarker m -> m.getAttribute(GradleErrorMarker.ATTRIBUTE_FQID, null) == null }
}

protected List<IMarker> getProblemsApiErrorMarkers(IResource rootResource = workspace.root) {
(rootResource.findMarkers(GradleErrorMarker.ID, false, IResource.DEPTH_INFINITE) as List).findAll { IMarker m -> m.getAttribute(GradleErrorMarker.ATTRIBUTE_FQID, null) != null }
}

protected List<IStatus> getPlatformLogErrors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class SynchronizingBuildScriptUpdateListenerTest extends ProjectSynchronizationS
workspaceConfig.jvmArguments,
workspaceConfig.showConsoleView,
workspaceConfig.showExecutionsView,
false,
false)
configurationManager.saveWorkspaceConfiguration(workspaceConfig)
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.buildship.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Require-Bundle: org.eclipse.core.expressions,
org.eclipse.jdt.junit.core,
org.eclipse.jdt.launching,
org.eclipse.debug.core,
org.gradle.toolingapi;bundle-version="[8.6.0,8.7.0)";visibility:=reexport,
org.gradle.toolingapi;bundle-version="[8.9.0,8.10.0)";visibility:=reexport,
com.google.guava;bundle-version="33.0.0",
com.google.gson;bundle-version="[2.7.0,3.0.0)",
org.eclipse.buildship.compat;visibility:=reexport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ SynchronizationResult run(CancellationTokenSource tokenSource, IProgressMonitor
CorePlugin.operationManager().run(this, tokenSource, monitor);
for (SynchronizationProblem f : this.failures) {
if (f.getSeverity() == IStatus.ERROR) {
GradleErrorMarker.createError(f.getResource(), this.gradleBuild, f.getMessage(), f.getException(), 0);
GradleErrorMarker.createError(f.getResource(), this.gradleBuild, f.getMessage(), f.getException());
} else if (f.getSeverity() == IStatus.WARNING) {
GradleErrorMarker.createWarning(f.getResource(), this.gradleBuild, f.getMessage(), f.getException(), 0);
GradleErrorMarker.createWarning(f.getResource(), this.gradleBuild, f.getMessage(), f.getException());
}
}
result = DefaultSynchronizationResult.from(getFailures());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading
Loading