Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class GradleBuildConnectionCachingTest extends BaseProjectConfiguratorTest {
File location

def setup() {
registerService(ProcessStreamsProvider, new TestProcessStreamProvider(){})
location = dir('GradleBuildConnectionCachingTest') { file "build.gradle",
"""
plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProject> project = CorePlugin.workspaceOperations().findProjectByLocation(location.canonicalFile)
Preconditions.checkState(project.present, "Workspace does not have project located at ${location.absolutePath}")
Expand All @@ -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)
Expand All @@ -59,6 +89,7 @@ abstract class ProjectSynchronizationSpecification extends WorkspaceSpecificatio
SynchronizationResult result = gradleBuild.synchronize(new NullProgressMonitor())
waitForGradleJobsToFinish()
waitForResourceChangeEvents()
maybePrintBuildOutput(result)
result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ import org.eclipse.buildship.core.internal.console.ProcessStreamsProvider

abstract class TestProcessStreamProvider implements ProcessStreamsProvider {

TestProcessStream backroundStream = new TestProcessStream()
List<TestProcessStream> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down