Skip to content

Commit

Permalink
Merge pull request #130 from chali/RecognizeLocalM2AsSourceForProject…
Browse files Browse the repository at this point in the history
…UnderTestClasspath

support mavenLocal() for dependencies for plugins tested through IntegrationSpec
  • Loading branch information
chali committed Jan 28, 2021
2 parents 8cdfa7a + c532ab8 commit 6366c7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/main/groovy/nebula/test/functional/GradleRunner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ public interface GradleRunner {
@Override
boolean apply(URL url) {
String gradleSharedDependencyCache = System.getenv(SHARED_DEPENDENCY_CACHE_ENVIRONMENT_VARIABLE)
if(gradleSharedDependencyCache) {
return url.path.contains('/caches/modules-') || url.path.contains("${gradleSharedDependencyCache}/modules-")
if (gradleSharedDependencyCache) {
return url.path.contains('/caches/modules-') || url.path.contains("${gradleSharedDependencyCache}/modules-")
} else {
return url.path.contains('/caches/modules-')
}
}
}

static final Predicate<URL> MAVEN_LOCAL = new Predicate<URL>() {
@Override
boolean apply(URL url) {
String m2RepositoryPrefix = StandardSystemProperty.USER_HOME.value() + "/.m2/repository"
return url.path.contains(m2RepositoryPrefix)
}
}

static final Predicate<URL> CLASSPATH_PROJECT_DIR = new Predicate<URL>() {
@Override
boolean apply(URL url) {
Expand All @@ -57,7 +65,7 @@ public interface GradleRunner {
* Attempts to provide a classpath that approximates the 'normal' Gradle runtime classpath. Use {@link #CLASSPATH_ALL}
* to default to pre-2.2.2 behaviour.
*/
static final Predicate<URL> CLASSPATH_DEFAULT = Predicates.or(CLASSPATH_PROJECT_DIR, CLASSPATH_GRADLE_CACHE, CLASSPATH_PROJECT_DEPENDENCIES)
static final Predicate<URL> CLASSPATH_DEFAULT = Predicates.or(CLASSPATH_PROJECT_DIR, CLASSPATH_GRADLE_CACHE, CLASSPATH_PROJECT_DEPENDENCIES, MAVEN_LOCAL)

/**
* Accept all URLs. Provides pre-2.2.2 behaviour.
Expand Down
13 changes: 11 additions & 2 deletions src/test/groovy/nebula/test/functional/GradleRunnerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class GradleRunnerSpec extends Specification {
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(sharedDependencyCache, "/modules-2/files-2.1/junit/junit/4.13/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.13.jar").toURI() as String
new File(sharedDependencyCache, "/modules-2/files-2.1/junit/junit/4.13/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.13.jar").toURI() as String,

new File(System.getProperty('user.home'), '.m2/repository/com/netflix/genie/genie-common/4.0.0-SNAPSHOT/genie-common-4.0.0-SNAPSHOT.jar').toURI() as String
]
classpath = classpathUris.collect { new URI(it).toURL() }
}
Expand Down Expand Up @@ -135,9 +137,16 @@ class GradleRunnerSpec extends Specification {
filtered.size() == 14
}

def 'maven local dependencies matches expected files'() {
expect:
def filtered = FluentIterable.from(classpath).filter(GradleRunner.MAVEN_LOCAL).toList()
filtered.size() == 1
filtered.every {it.file.contains(".m2/repository") }
}

def 'default classpath matches only application class paths and dependencies'() {
expect:
def filtered = FluentIterable.from(classpath).filter(GradleRunner.CLASSPATH_DEFAULT).toList()
filtered.size() == 25
filtered.size() == 26
}
}

0 comments on commit 6366c7d

Please sign in to comment.