Skip to content

Commit

Permalink
Add intial support for problem events
Browse files Browse the repository at this point in the history
  • Loading branch information
donat committed Jan 30, 2024
1 parent 455bf33 commit 6b38695
Show file tree
Hide file tree
Showing 24 changed files with 311 additions and 47 deletions.
5 changes: 3 additions & 2 deletions Launch Buildship.launch
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:MaxPermSize=128M -Dorg.eclipse.swt.internal.carbon.smallFonts -Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.swt.internal.carbon.smallFonts -Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
<booleanAttribute key="show_selected_only" value="false"/>
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.1.1
toolingApiVersion=8.6-rc-3

# 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.1.1,8.2.0)";visibility:=reexport
Require-Bundle: org.gradle.toolingapi;bundle-version="[8.6.0,8.7.0)";visibility:=reexport
Export-Package: org.eclipse.buildship.core.internal.workspace
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.1.1,8.2.0)";visibility:=reexport,
org.gradle.toolingapi;bundle-version="[8.6.0,8.7.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
4 changes: 3 additions & 1 deletion org.eclipse.buildship.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@
<!-- Define custom marker type for Gradle-related problems -->
<extension
id="org.eclipse.buildship.core.errormarker"
name="Gradle Error Marker"
name="Gradle Problem"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.problemmarker"/>
<persistent value="true" />
<attribute name="stacktrace" />
</extension>

<!-- Built-in Buildship project configurators -->
<extension
point="org.eclipse.buildship.core.projectconfigurators">
<configurator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.gradle.tooling.GradleConnectionException;
import org.gradle.tooling.ProgressListener;
import org.gradle.tooling.ResultHandler;
import org.gradle.tooling.StreamedValueListener;
import org.gradle.tooling.events.OperationType;

import com.google.common.cache.Cache;
Expand Down Expand Up @@ -222,4 +223,9 @@ public BuildActionExecuter<T> withSystemProperties(Map<String, String> systemPro
this.delegate.withSystemProperties(systemProperties);
return this;
}

@Override
public void setStreamedValueListener(StreamedValueListener listener) {
this.delegate.setStreamedValueListener(listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public GradleConnectionOperation(Function<ProjectConnection, ? extends T> action
@Override
public void runInToolingApi(CancellationTokenSource tokenSource, IProgressMonitor monitor) throws Exception {
// TODO (donat) use AutoCloseable once we update to Tooling API 5.0
ProjectConnection connection = IdeAttachedProjectConnection.newInstance(tokenSource, getGradleArguments(), monitor);
ProjectConnection connection = IdeAttachedProjectConnection.newInstance(tokenSource, getGradleArguments(), DefaultGradleBuild.this, monitor);
if (isSynchronizing()) {
connection = new CachingProjectConnection(connection, DefaultGradleBuild.this.projectConnectionCache);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.eclipse.buildship.core.internal.console.ProcessStreamsProvider;
import org.eclipse.buildship.core.internal.util.progress.CancellationForwardingListener;
import org.eclipse.buildship.core.internal.util.progress.DelegatingProgressListener;
import org.eclipse.buildship.core.internal.util.progress.ProblemsReportingProgressListener;
import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild;

/**
* Holds attributes that are commonly used to handle progress in each Gradle invocation.
Expand Down Expand Up @@ -98,8 +100,8 @@ public void close() {
this.streams.close();
}

public static final GradleProgressAttributesBuilder builder(CancellationTokenSource tokenSource, IProgressMonitor monitor) {
return new GradleProgressAttributesBuilder(tokenSource, monitor);
public static final GradleProgressAttributesBuilder builder(CancellationTokenSource tokenSource, InternalGradleBuild gradleBuild, IProgressMonitor monitor) {
return new GradleProgressAttributesBuilder(tokenSource, gradleBuild, monitor);
}

/**
Expand All @@ -114,9 +116,11 @@ public static class GradleProgressAttributesBuilder {
private ProcessDescription processDescription = null;
private boolean isInteractive = true;
private ProgressListener delegatingListener = null;
private final InternalGradleBuild gradleBuild;

public GradleProgressAttributesBuilder(CancellationTokenSource tokenSource, IProgressMonitor monitor) {
public GradleProgressAttributesBuilder(CancellationTokenSource tokenSource, InternalGradleBuild gradleBuild, IProgressMonitor monitor) {
this.tokenSource = tokenSource;
this.gradleBuild = gradleBuild;
this.monitor = monitor;
}

Expand Down Expand Up @@ -158,6 +162,7 @@ public GradleProgressAttributes build() {
CancellationForwardingListener cancellationListener = new CancellationForwardingListener(this.monitor, this.tokenSource);
progressListeners.add(cancellationListener);
progressEventListeners.add(cancellationListener);
progressEventListeners.add(new ProblemsReportingProgressListener(this.gradleBuild));

return new GradleProgressAttributes(streams, this.tokenSource.token(), progressListeners.build(), progressEventListeners.build(), this.isInteractive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.buildship.core.internal.console.ProcessDescription;
import org.eclipse.buildship.core.internal.event.Event;
import org.eclipse.buildship.core.internal.gradle.GradleProgressAttributes;
import org.eclipse.buildship.core.internal.marker.GradleMarkerManager;
import org.eclipse.buildship.core.internal.operation.ToolingApiJob;
import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild;

Expand Down Expand Up @@ -52,12 +53,13 @@ protected final void executeLaunch(CancellationTokenSource tokenSource, final IP
ProcessDescription processDescription = createProcessDescription();
BaseRunConfiguration runConfig = getRunConfig();
InternalGradleBuild gradleBuild = CorePlugin.internalGradleWorkspace().getGradleBuild(runConfig.getProjectConfiguration().getBuildConfiguration());
GradleProgressAttributes attributes = GradleProgressAttributes.builder(tokenSource, monitor)
GradleProgressAttributes attributes = GradleProgressAttributes.builder(tokenSource, gradleBuild, monitor)
.forDedicatedProcess(processDescription)
.withFullProgress()
.build();
T launcher = createLaunch(gradleBuild, attributes, processDescription);

GradleMarkerManager.clear(gradleBuild);
writeExtraConfigInfo(attributes);

Event event = new DefaultExecuteLaunchRequestEvent(processDescription, launcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
******************************************************************************/
package org.eclipse.buildship.core.internal.marker;

import java.util.List;
import java.util.stream.Collectors;

import com.google.common.base.Throwables;

import org.eclipse.core.resources.IMarker;
Expand All @@ -19,7 +22,7 @@
import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild;

/**
* Describes Gradle error marker.
* Describes a Gradle problem marker.
*
* @author Donat Csikos
*/
Expand All @@ -28,6 +31,10 @@ public class GradleErrorMarker {
public static String ID = CorePlugin.PLUGIN_ID + ".errormarker";
public static String ATTRIBUTE_STACKTRACE = "stacktrace";
public static String ATTRIBUTE_ROOT_DIR = "rootdir";
public static String ATTRIBUTE_PROBLEM_CATEGORY = "problem.category";
public static String ATTRIBUTE_PROBLEM_SOLUTIONS = "problem.solutions";
public static String ATTRIBUTE_DOCUMENTATION_LINK = "problem.documentationlink";


private GradleErrorMarker() {
}
Expand All @@ -38,14 +45,19 @@ public static boolean belongsToBuild(IMarker marker, InternalGradleBuild build)
}

public static void createError(IResource resource, InternalGradleBuild gradleBuild, String message, Throwable exception, int lineNumber) {
createMarker(IMarker.SEVERITY_ERROR, resource, gradleBuild, message, exception,lineNumber);
createMarker(IMarker.SEVERITY_ERROR, resource, gradleBuild, message, exception, lineNumber);
}

public static void createWarning(IResource resource, InternalGradleBuild gradleBuild, String message, Throwable exception, int lineNumber) {
createMarker(IMarker.SEVERITY_WARNING, resource, gradleBuild, message, exception,lineNumber);
}

private static void createMarker(int severity, IResource resource, InternalGradleBuild gradleBuild, String message, Throwable exception, int lineNumber) {
createMarker(severity, resource, gradleBuild, message, exception, lineNumber, null, null, null);
}

public static void createMarker(int severity, IResource resource, InternalGradleBuild gradleBuild, String message, Throwable exception, int lineNumber, String category,
List<String> solutions, String documentationLink) {
try {
IMarker marker = resource.createMarker(GradleErrorMarker.ID);

Expand All @@ -61,6 +73,16 @@ private static void createMarker(int severity, IResource resource, InternalGradl
String stackTrace = Throwables.getStackTraceAsString(exception);
marker.setAttribute(GradleErrorMarker.ATTRIBUTE_STACKTRACE, stackTrace);
}
if (category != null) {
marker.setAttribute(ATTRIBUTE_PROBLEM_CATEGORY, category);
}
if (solutions != null) {
String solutionsString = solutions.stream().collect(Collectors.joining(System.getProperty("line.separator")));
marker.setAttribute(ATTRIBUTE_PROBLEM_SOLUTIONS, solutionsString);
}
if (documentationLink != null) {
marker.setAttribute(ATTRIBUTE_DOCUMENTATION_LINK, documentationLink);
}
} catch (CoreException e) {
CorePlugin.logger().warn("Cannot create Gradle error marker", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.gradle.tooling.ProgressListener;
import org.gradle.tooling.ProjectConnection;
import org.gradle.tooling.ResultHandler;
import org.gradle.tooling.StreamedValueListener;
import org.gradle.tooling.TestLauncher;
import org.gradle.tooling.events.OperationType;
import org.gradle.tooling.model.eclipse.EclipseProject;
Expand Down Expand Up @@ -433,6 +434,11 @@ public BuildActionExecuter<T> withSystemProperties(Map<String, String> systemPro
this.delegate.withSystemProperties(systemProperties);
return this;
}

@Override
public void setStreamedValueListener(StreamedValueListener listener) {
this.delegate.setStreamedValueListener(listener);
}
}

private static class CompatIntermediateResultHander<T> implements IntermediateResultHandler<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ public boolean isPublic() {
}
}

@Override
public String getBuildTreePath() {
// returns true for Gradle versions < 2.1
try {
return this.delegate.getBuildTreePath();
} catch (Exception ignore) {
return getPath();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

import org.eclipse.core.runtime.IProgressMonitor;

import org.eclipse.buildship.core.internal.DefaultGradleBuild;
import org.eclipse.buildship.core.internal.configuration.GradleArguments;
import org.eclipse.buildship.core.internal.gradle.GradleProgressAttributes;
import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild;

public final class IdeAttachedProjectConnection implements ProjectConnection {

Expand Down Expand Up @@ -96,12 +98,12 @@ public void notifyDaemonsAboutChangedPaths(List<Path> changedPaths) {
this.delegate.notifyDaemonsAboutChangedPaths(changedPaths);
}

public static ProjectConnection newInstance(CancellationTokenSource tokenSource, GradleArguments gradleArguments, IProgressMonitor monitor) {
public static ProjectConnection newInstance(CancellationTokenSource tokenSource, GradleArguments gradleArguments, InternalGradleBuild gradleBuild, IProgressMonitor monitor) {
GradleConnector connector = GradleConnector.newConnector();
gradleArguments.applyTo(connector);
ProjectConnection connection = new CompatProjectConnection(connector.connect());

GradleProgressAttributes progressAttributes = GradleProgressAttributes.builder(tokenSource, monitor)
GradleProgressAttributes progressAttributes = GradleProgressAttributes.builder(tokenSource, gradleBuild, monitor)
.forBackgroundProcess()
.withFullProgress()
.build();
Expand Down
Loading

0 comments on commit 6b38695

Please sign in to comment.