forked from abayer/gradle-hpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor JpiExtension to use DependencyLookup
- Loading branch information
Showing
3 changed files
with
132 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/groovy/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookup.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.jenkinsci.gradle.plugins.jpi.internal | ||
|
||
import groovy.transform.CompileStatic | ||
import org.gradle.util.GradleVersion | ||
|
||
@CompileStatic | ||
class DependencyLookup { | ||
Set<String> find(String configuration, String jenkinsVersion) { | ||
String core = "org.jenkins-ci.main:jenkins-core:${jenkinsVersion}" | ||
String war = "org.jenkins-ci.main:jenkins-war:${jenkinsVersion}" | ||
String findbugs = 'com.google.code.findbugs:annotations:3.0.0' | ||
def version = GradleVersion.version(jenkinsVersion) | ||
if (version < GradleVersion.version('1.618')) { | ||
findbugs = 'findbugs:annotations:1.0.0' | ||
} | ||
String servlet = 'javax.servlet:javax.servlet-api:3.1.0' | ||
if (version < GradleVersion.version('2.0')) { | ||
servlet = 'javax.servlet:servlet-api:2.4' | ||
} | ||
String testHarness = 'org.jenkins-ci.main:jenkins-test-harness:2.60' | ||
if (version < GradleVersion.version('2.64')) { | ||
testHarness = 'org.jenkins-ci.main:jenkins-test-harness:2.0' | ||
} | ||
if (version <= GradleVersion.version('1.644')) { | ||
testHarness = "org.jenkins-ci.main:jenkins-test-harness:${jenkinsVersion}" | ||
} | ||
String uiSamples = 'org.jenkins-ci.main:ui-samples-plugin:2.0' | ||
if (version < GradleVersion.version('1.533')) { | ||
uiSamples = "org.jenkins-ci.main:ui-samples-plugin:${jenkinsVersion}" | ||
} | ||
switch (configuration) { | ||
case 'annotationProcessor': | ||
return [core] as Set | ||
case 'compileOnly': | ||
return [core, findbugs, servlet] as Set | ||
case 'testImplementation': | ||
Set<String> deps = [core, testHarness, uiSamples] as Set | ||
if (version < GradleVersion.version('1.505')) { | ||
deps.add('junit:junit-dep:4.10') | ||
} | ||
return deps | ||
case 'testRuntimeOnly': | ||
return [war] as Set | ||
default: | ||
[] as Set | ||
} | ||
} | ||
|
||
Set<String> configurations() { | ||
[ | ||
'annotationProcessor', | ||
'compileOnly', | ||
'testImplementation', | ||
'testRuntimeOnly', | ||
] as Set | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/test/groovy/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookupSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.jenkinsci.gradle.plugins.jpi.internal | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class DependencyLookupSpec extends Specification { | ||
def 'should get annotationProcessor dependencies by version'() { | ||
given: | ||
DependencyLookup lookup = new DependencyLookup() | ||
|
||
when: | ||
def actual = lookup.find('annotationProcessor', '2.0') | ||
|
||
then: | ||
actual == [ | ||
'org.jenkins-ci.main:jenkins-core:2.0', | ||
] as Set | ||
} | ||
|
||
@Unroll | ||
def 'should get compileOnly dependencies for #version'(String version, Set<String> expected) { | ||
given: | ||
DependencyLookup lookup = new DependencyLookup() | ||
|
||
when: | ||
def actual = lookup.find('compileOnly', version) | ||
|
||
then: | ||
actual == expected | ||
|
||
where: | ||
version | expected | ||
'1.617' | ['org.jenkins-ci.main:jenkins-core:1.617', 'findbugs:annotations:1.0.0', 'javax.servlet:servlet-api:2.4'] as Set | ||
'1.618' | ['org.jenkins-ci.main:jenkins-core:1.618', 'com.google.code.findbugs:annotations:3.0.0', 'javax.servlet:servlet-api:2.4'] as Set | ||
'2.0' | ['org.jenkins-ci.main:jenkins-core:2.0', 'com.google.code.findbugs:annotations:3.0.0', 'javax.servlet:javax.servlet-api:3.1.0'] as Set | ||
} | ||
|
||
@Unroll | ||
def 'should get testImplementation dependencies for #version'(String version, Set<String> expected) { | ||
given: | ||
DependencyLookup lookup = new DependencyLookup() | ||
|
||
when: | ||
def actual = lookup.find('testImplementation', version) | ||
|
||
then: | ||
actual == expected | ||
|
||
where: | ||
version | expected | ||
'1.504' | ['org.jenkins-ci.main:jenkins-core:1.504', 'org.jenkins-ci.main:jenkins-test-harness:1.504', 'org.jenkins-ci.main:ui-samples-plugin:1.504', 'junit:junit-dep:4.10'] as Set | ||
'1.532' | ['org.jenkins-ci.main:jenkins-core:1.532', 'org.jenkins-ci.main:jenkins-test-harness:1.532', 'org.jenkins-ci.main:ui-samples-plugin:1.532'] as Set | ||
'1.644' | ['org.jenkins-ci.main:jenkins-core:1.644', 'org.jenkins-ci.main:jenkins-test-harness:1.644', 'org.jenkins-ci.main:ui-samples-plugin:2.0'] as Set | ||
'1.645' | ['org.jenkins-ci.main:jenkins-core:1.645', 'org.jenkins-ci.main:jenkins-test-harness:2.0', 'org.jenkins-ci.main:ui-samples-plugin:2.0'] as Set | ||
'2.64' | ['org.jenkins-ci.main:jenkins-core:2.64', 'org.jenkins-ci.main:jenkins-test-harness:2.60', 'org.jenkins-ci.main:ui-samples-plugin:2.0'] as Set | ||
} | ||
|
||
def 'should get testRuntimeOnly dependencies for version'() { | ||
given: | ||
DependencyLookup lookup = new DependencyLookup() | ||
|
||
when: | ||
def actual = lookup.find('testRuntimeOnly', '2.222.3') | ||
|
||
then: | ||
actual == [ | ||
'org.jenkins-ci.main:jenkins-war:2.222.3', | ||
] as Set<String> | ||
} | ||
} |