Skip to content

Commit

Permalink
Merge pull request #127 from nebula-plugins/fix-integrationTest-class…
Browse files Browse the repository at this point in the history
…path-for-shared-cache

GradleRunner: CLASSPATH_GRADLE_CACHE should account for GRADLE_RO_DEP_CACHE environment variable presence
  • Loading branch information
rpalcolea committed Oct 30, 2020
2 parents f1f0a02 + df75031 commit 6ae19c1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
}
api 'cglib:cglib-nodep:3.2.2'
api 'org.objenesis:objenesis:2.4'
testImplementation('com.github.stefanbirkner:system-rules:1.19.0')
}

gradleTest {
Expand Down
10 changes: 0 additions & 10 deletions gradle/dependency-locks/default.lockfile

This file was deleted.

2 changes: 2 additions & 0 deletions gradle/dependency-locks/integTestCompileClasspath.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
cglib:cglib-nodep:3.2.2
com.github.stefanbirkner:system-rules:1.19.0
com.google.guava:guava:19.0
commons-io:commons-io:2.5
junit:junit-dep:4.11
junit:junit:4.12
org.hamcrest:hamcrest-core:1.3
org.objenesis:objenesis:2.4
Expand Down
2 changes: 2 additions & 0 deletions gradle/dependency-locks/integTestRuntimeClasspath.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
cglib:cglib-nodep:3.2.2
com.github.stefanbirkner:system-rules:1.19.0
com.google.guava:guava:19.0
commons-io:commons-io:2.5
junit:junit-dep:4.11
junit:junit:4.12
org.hamcrest:hamcrest-core:1.3
org.objenesis:objenesis:2.4
Expand Down
2 changes: 2 additions & 0 deletions gradle/dependency-locks/testCompileClasspath.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
cglib:cglib-nodep:3.2.2
com.github.stefanbirkner:system-rules:1.19.0
com.google.guava:guava:19.0
commons-io:commons-io:2.5
junit:junit-dep:4.11
junit:junit:4.12
org.hamcrest:hamcrest-core:1.3
org.objenesis:objenesis:2.4
Expand Down
2 changes: 2 additions & 0 deletions gradle/dependency-locks/testRuntimeClasspath.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
cglib:cglib-nodep:3.2.2
com.github.stefanbirkner:system-rules:1.19.0
com.google.guava:guava:19.0
commons-io:commons-io:2.5
junit:junit-dep:4.11
junit:junit:4.12
org.hamcrest:hamcrest-core:1.3
org.objenesis:objenesis:2.4
Expand Down
9 changes: 8 additions & 1 deletion src/main/groovy/nebula/test/functional/GradleRunner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ import nebula.test.functional.internal.GradleHandle
public interface GradleRunner {
// These predicates are here, instead of on GradleRunnerFactory due to a Groovy static compiler bug (https://issues.apache.org/jira/browse/GROOVY-7159)

static final String SHARED_DEPENDENCY_CACHE_ENVIRONMENT_VARIABLE = 'GRADLE_RO_DEP_CACHE'

static final Predicate<URL> CLASSPATH_GRADLE_CACHE = new Predicate<URL>() {
@Override
boolean apply(URL url) {
return url.path.contains('/caches/modules-')
String gradleSharedDependencyCache = System.getenv(SHARED_DEPENDENCY_CACHE_ENVIRONMENT_VARIABLE)
if(gradleSharedDependencyCache) {
return url.path.contains('/caches/modules-') || url.path.contains("${gradleSharedDependencyCache}/modules-")
} else {
return url.path.contains('/caches/modules-')
}
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/test/groovy/nebula/test/functional/GradleRunnerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package nebula.test.functional

import com.google.common.base.StandardSystemProperty
import com.google.common.collect.FluentIterable
import org.junit.Rule
import org.junit.contrib.java.lang.system.EnvironmentVariables
import spock.lang.Issue
import spock.lang.Specification

Expand All @@ -28,6 +30,10 @@ class GradleRunnerSpec extends Specification {

def workDir = new File(StandardSystemProperty.USER_DIR.value())
def siblingDir = new File(workDir.parentFile, 'sibling')
def sharedDependencyCache = new File(workDir.parentFile, 'sharedDependencyCache')

@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables()

def setup() {
// Partial real-world classpath from a IntegrationSpec launch, only the workDir/siblingDir paths matter, otherwise these are just string comparisons
Expand Down Expand Up @@ -93,7 +99,9 @@ class GradleRunnerSpec extends Specification {
new File(workDir, ".gradle/wrapper/dists/gradle-2.2.1-bin/3rn023ng4778ktj66tonmgpbv/gradle-2.2.1/lib/asm-all-5.0.3.jar").toURI() as String,
new File(workDir, ".gradle/wrapper/dists/gradle-2.2.1-bin/3rn023ng4778ktj66tonmgpbv/gradle-2.2.1/lib/ant-1.9.3.jar").toURI() as String,
new File(workDir, ".gradle/wrapper/dists/gradle-2.2.1-bin/3rn023ng4778ktj66tonmgpbv/gradle-2.2.1/lib/commons-collections-3.2.1.jar").toURI() as String,
new File(workDir, ".gradle/wrapper/dists/gradle-2.2.1-bin/3rn023ng4778ktj66tonmgpbv/gradle-2.2.1/lib/commons-io-1.4.jar").toURI() as String
new File(workDir, ".gradle/wrapper/dists/gradle-2.2.1-bin/3rn023ng4778ktj66tonmgpbv/gradle-2.2.1/lib/commons-io-1.4.jar").toURI() as String,

new File(sharedDependencyCache, "/modules-2/files-2.1/junit/junit/4.13/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.13.jar").toURI() as String
]
classpath = classpathUris.collect { new URI(it).toURL() }
}
Expand All @@ -104,6 +112,17 @@ class GradleRunnerSpec extends Specification {
filtered.size() == 5
}


def 'gradle distribution predicate matches expected files with GRADLE_RO_DEP_CACHE support'() {
setup:
environmentVariables.set("GRADLE_RO_DEP_CACHE", sharedDependencyCache.absolutePath)

expect:
def filtered = FluentIterable.from(classpath).filter(GradleRunner.CLASSPATH_GRADLE_CACHE).toList()
filtered.size() == 6
filtered.any { it.file.contains('junit-4.13') }
}

def 'jvm predicate matches expected files'() {
expect:
def filtered = FluentIterable.from(classpath).filter(GradleRunner.CLASSPATH_PROJECT_DIR).toList()
Expand Down

0 comments on commit 6ae19c1

Please sign in to comment.