diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionCachingTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionCachingTest.groovy index 49e5a4ba1..87ef6d550 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionCachingTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionCachingTest.groovy @@ -39,7 +39,6 @@ class GradleBuildConnectionCachingTest extends BaseProjectConfiguratorTest { File location def setup() { - registerService(ProcessStreamsProvider, new TestProcessStreamProvider(){}) location = dir('GradleBuildConnectionCachingTest') { file "build.gradle", """ plugins { diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionTest.groovy index bf3975994..50feba5b5 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/GradleBuildConnectionTest.groovy @@ -28,10 +28,6 @@ import org.eclipse.buildship.core.internal.util.gradle.IdeFriendlyClassLoading class GradleBuildConnectionTest extends ProjectSynchronizationSpecification { - def setup() { - registerService(ProcessStreamsProvider, new TestProcessStreamProvider(){}) - } - def "Cannot run null action"() { when: GradleBuild gradleBuild = gradleBuildFor(dir('GradleBuildConnectionTest')) diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/launch/BaseLaunchRequestJobTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/launch/BaseLaunchRequestJobTest.groovy index d78619b99..a1cf595f7 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/launch/BaseLaunchRequestJobTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/launch/BaseLaunchRequestJobTest.groovy @@ -20,18 +20,14 @@ import org.eclipse.buildship.core.internal.test.fixtures.WorkspaceSpecification class BaseLaunchRequestJobTest extends ProjectSynchronizationSpecification { - def setup() { - environment.registerService(ProcessStreamsProvider, new TestProcessStreamProvider() {}) - } - String getBuildOutput() { TestProcessStreamProvider testStreams = CorePlugin.processStreamsProvider() - testStreams.processStreams.last().out + testStreams.testStream.out } String getBuildConfig() { TestProcessStreamProvider testStreams = CorePlugin.processStreamsProvider() - testStreams.processStreams.last().conf + testStreams.testStream.conf } ILaunchConfiguration createLaunchConfiguration(File projectDir, tasks = ['clean', 'build'], GradleDistribution distribution = GradleDistribution.fromBuild(), arguments = []) { diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy index 0d8dcba6d..0d2f261c5 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy @@ -12,6 +12,8 @@ package org.eclipse.buildship.core.internal.marker import org.gradle.tooling.BuildException import org.eclipse.core.resources.IMarker +import org.eclipse.core.resources.IResource +import org.eclipse.core.resources.ResourcesPlugin import org.eclipse.core.runtime.IStatus import org.eclipse.buildship.core.GradleDistribution @@ -21,6 +23,13 @@ import org.eclipse.buildship.core.internal.test.fixtures.ProjectSynchronizationS class GradleErrorMarkerTest extends ProjectSynchronizationSpecification { + def setupSpec() { + // delete all markers that might've preserved from a previous test execution + for (IMarker marker : ResourcesPlugin.getWorkspace().getRoot().findMarkers(GradleErrorMarker.ID, false, IResource.DEPTH_INFINITE)) { + marker.delete(); + } + } + def "Display error marker if synchronization fails"() { setup: File projectDir = dir('error-marker-test') { diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/ProjectSynchronizationSpecification.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/ProjectSynchronizationSpecification.groovy index 023ad44c6..332ee423a 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/ProjectSynchronizationSpecification.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/ProjectSynchronizationSpecification.groovy @@ -25,12 +25,28 @@ import org.eclipse.buildship.core.GradleCore import org.eclipse.buildship.core.GradleDistribution import org.eclipse.buildship.core.SynchronizationResult import org.eclipse.buildship.core.internal.CorePlugin +import org.eclipse.buildship.core.internal.console.ProcessStreamsProvider abstract class ProjectSynchronizationSpecification extends WorkspaceSpecification { protected static final GradleDistribution DEFAULT_DISTRIBUTION = GradleDistribution.fromBuild() + + protected TestProcessStreamProvider testStreams + + protected String getOutput() { + testStreams.testStream.getOut() + } + + protected String getErrorOutput() { + testStreams.testStream.getErr() + } + + def setup() { + environment.registerService(ProcessStreamsProvider, testStreams = new TestProcessStreamProvider() {}) + } + protected SynchronizationResult trySynchronizeAndWait(File location) { Optional project = CorePlugin.workspaceOperations().findProjectByLocation(location.canonicalFile) Preconditions.checkState(project.present, "Workspace does not have project located at ${location.absolutePath}") @@ -41,9 +57,23 @@ abstract class ProjectSynchronizationSpecification extends WorkspaceSpecificatio SynchronizationResult result = gradleBuildFor(project).synchronize(new NullProgressMonitor()) waitForGradleJobsToFinish() waitForResourceChangeEvents() + maybePrintBuildOutput(result) result } + protected void maybePrintBuildOutput(SynchronizationResult result) { + if (result.status.severity != IStatus.OK) { + String stdOut = getOutput().trim() + String stdErr = getErrorOutput().trim() + if (stdOut.isEmpty()) { + System.out.println(stdOut) + } + if (stdErr.isEmpty()) { + System.err.println(stdErr) + } + } + } + protected void synchronizeAndWait(File location) { SynchronizationResult result = trySynchronizeAndWait(location) assertResultOkStatus(result) @@ -59,6 +89,7 @@ abstract class ProjectSynchronizationSpecification extends WorkspaceSpecificatio SynchronizationResult result = gradleBuild.synchronize(new NullProgressMonitor()) waitForGradleJobsToFinish() waitForResourceChangeEvents() + maybePrintBuildOutput(result) result } diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/TestProcessStreamProvider.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/TestProcessStreamProvider.groovy index 53fa2f08f..4abf58f20 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/TestProcessStreamProvider.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/TestProcessStreamProvider.groovy @@ -15,19 +15,16 @@ import org.eclipse.buildship.core.internal.console.ProcessStreamsProvider abstract class TestProcessStreamProvider implements ProcessStreamsProvider { - TestProcessStream backroundStream = new TestProcessStream() - List processStreams = [] + TestProcessStream testStream = new TestProcessStream() @Override public ProcessStreams getBackgroundJobProcessStreams() { - backroundStream + testStream } @Override public ProcessStreams createProcessStreams(ProcessDescription processDescription) { - ProcessStreams result = new TestProcessStream() - processStreams += result - result + testStream } static class TestProcessStream implements ProcessStreams { diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/WorkspaceSpecification.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/WorkspaceSpecification.groovy index f8c981963..92d4e2b5f 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/WorkspaceSpecification.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/test/fixtures/WorkspaceSpecification.groovy @@ -36,6 +36,7 @@ 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 +import org.eclipse.buildship.core.internal.console.ProcessStreamsProvider import org.eclipse.buildship.core.internal.launch.GradleRunConfigurationDelegate import org.eclipse.buildship.core.internal.marker.GradleErrorMarker import org.eclipse.buildship.core.internal.preferences.DefaultPersistentModel diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/RunEclipseSynchronizationTasksTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/RunEclipseSynchronizationTasksTest.groovy index 847bfef36..50bb61063 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/RunEclipseSynchronizationTasksTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/RunEclipseSynchronizationTasksTest.groovy @@ -17,13 +17,10 @@ import org.eclipse.buildship.core.internal.test.fixtures.TestProcessStreamProvid class RunEclipseSynchronizationTasksTest extends ProjectSynchronizationSpecification { - def setup() { - environment.registerService(ProcessStreamsProvider, new TestProcessStreamProvider() {}) - } String getSyncConsoleOutput() { TestProcessStreamProvider testStreams = CorePlugin.processStreamsProvider() - testStreams.backroundStream.out + testStreams.testStream.out } def "executes tasks from eclipse plugin configuration"() { diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SourcePathTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SourcePathTest.groovy index 918f237a6..14331959a 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SourcePathTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SourcePathTest.groovy @@ -39,7 +39,7 @@ class SourcePathTest extends ProjectSynchronizationSpecification { } when: - importAndWait(projectDir, GradleDistribution.forVersion(version), new File(System.getProperty('jdk8.location'))) + importAndWait(projectDir, GradleDistribution.fromBuild()) IRuntimeClasspathEntry[] p1sources = sourceEntries(findProject('p1')) IRuntimeClasspathEntry[] p2sources = sourceEntries(findProject('p2')) @@ -48,10 +48,6 @@ class SourcePathTest extends ProjectSynchronizationSpecification { p1sources.find { IRuntimeClasspathEntry entry -> entry.path.toPortableString() == '/p2' } !p2sources.find { IRuntimeClasspathEntry entry -> entry.path.toPortableString() == '/p1' } p2sources.find { IRuntimeClasspathEntry entry -> entry.path.toPortableString() == '/p2' } - - where: - // Gradle 4.3 doesn't use separate output dir per source folder - version << ['4.3', '4.4'] } private IRuntimeClasspathEntry[] sourceEntries(IProject project) { diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SynchronizingClosedProjectsTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SynchronizingClosedProjectsTest.groovy index 6ce4899a2..0ee2262ce 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SynchronizingClosedProjectsTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/workspace/SynchronizingClosedProjectsTest.groovy @@ -28,7 +28,6 @@ class SynchronizingClosedProjectsTest extends ProjectSynchronizationSpecificatio File buildC def setup() { - environment.registerService(ProcessStreamsProvider, new TestProcessStreamProvider() {}) buildA = dir("buildA") { file "build.gradle", """ group = 'org.test' @@ -193,7 +192,7 @@ class SynchronizingClosedProjectsTest extends ProjectSynchronizationSpecificatio private String getSyncConsoleOutput() { TestProcessStreamProvider testStreams = CorePlugin.processStreamsProvider() - testStreams.backroundStream.out + testStreams.testStream.out } private IRuntimeClasspathEntry[] projectRuntimeClasspath(IJavaProject project) {