Skip to content

Commit

Permalink
Use new validatedJenkinsVersion provider
Browse files Browse the repository at this point in the history
Move coreVersion validation into Provider

Fixes #148
  • Loading branch information
sghill committed May 28, 2020
1 parent 5385dc7 commit 57a4442
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package org.jenkinsci.gradle.plugins.jpi

import hudson.util.VersionNumber
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.model.ReplacedBy
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.SourceSet
import org.gradle.util.ConfigureUtil
import org.gradle.util.GradleVersion

/**
* This gets exposed to the project as 'jpi' to offer additional convenience methods.
Expand All @@ -35,10 +35,18 @@ class JpiExtension {
@Deprecated
Map<String, String> jenkinsWarCoordinates
final Property<String> jenkinsVersion
final Provider<String> validatedJenkinsVersion

JpiExtension(Project project) {
this.project = project
this.jenkinsVersion = project.objects.property(String)
this.validatedJenkinsVersion = jenkinsVersion.map {
def resolved = it ?: coreVersion
if (GradleVersion.version(resolved) < GradleVersion.version('1.420')) {
throw new IllegalArgumentException('The gradle-jpi-plugin requires Jenkins 1.420 or later')
}
resolved
}
}

private String shortName
Expand Down Expand Up @@ -127,11 +135,6 @@ class JpiExtension {
void setCoreVersion(String v) {
jenkinsVersion.convention(v)
this.coreVersion = v

if (new VersionNumber(this.coreVersion) <= new VersionNumber('1.419.99')) {
throw new GradleException('The gradle-jpi-plugin requires Jenkins 1.420 or later')
}

if (this.coreVersion) {
jenkinsWarCoordinates = [group: 'org.jenkins-ci.main', name: 'jenkins-war', version: v]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import org.gradle.util.GradleVersion
import org.jenkinsci.gradle.plugins.jpi.internal.DependencyLookup
import org.jenkinsci.gradle.plugins.jpi.legacy.LegacyWorkaroundsPlugin
import org.jenkinsci.gradle.plugins.jpi.server.GenerateJenkinsServerHplTask

import org.jenkinsci.gradle.plugins.jpi.server.InstallJenkinsServerPluginsTask
import org.jenkinsci.gradle.plugins.jpi.server.JenkinsServerTask

Expand Down Expand Up @@ -169,7 +168,7 @@ class JpiPlugin implements Plugin<Project> {
for (String config : lookup.configurations()) {
gradleProject.configurations.getByName(config) { Configuration c ->
c.withDependencies { DependencySet deps ->
def toAdd = lookup.find(c.name, ext.coreVersion).collect {
def toAdd = lookup.find(c.name, ext.validatedJenkinsVersion.get()).collect {
gradleProject.dependencies.create(it) { Dependency d ->
d.because('Added by org.jenkins-ci.jpi plugin')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class LegacyWorkaroundsPlugin implements Plugin<Project> {
// workarounds for JENKINS-26331
project.tasks.named('test').configure { Task t ->
def ext = project.extensions.getByType(JpiExtension)
if (isBetween(ext.coreVersion, '1.545', '1.592')) {
def jenkinsVersion = ext.validatedJenkinsVersion
if (isBetween(jenkinsVersion.get(), '1.545', '1.592')) {
project.file('target').mkdirs()
}
}
project.tasks.named('clean', Delete).configure { Delete t ->
def ext = project.extensions.getByType(JpiExtension)
if (isOlderThan(ext.coreVersion, '1.598')) {
def jenkinsVersion = ext.validatedJenkinsVersion
if (isOlderThan(jenkinsVersion.get(), '1.598')) {
t.delete('target')
}
}
Expand Down

0 comments on commit 57a4442

Please sign in to comment.