Skip to content

Commit

Permalink
Upgrade Job-DSL dependency to 1.42
Browse files Browse the repository at this point in the history
Replace job with freeStyleJob and view with listView in most tests.

Remove tests that check for an exception to be thrown when no job name is
provided, since the new Job DSL syntax requires the job name as a
parameter. Also the name method does not exist in Job DSL anymore, so
replace usages with calls to the setter method for name.

javaposse.jobdsl.dsl.JobType was removed, so instead use the simlar class
com.terrafolio.gradle.plugins.jenkins.jobdsl.DSLJobType.

Also add a direct dependency to Guava because it was removed from Job DSL.
  • Loading branch information
mnonnenmacher committed Jan 6, 2016
1 parent 088ce2f commit 534b751
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 105 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ dependencies {
exclude(module: 'xercesImpl')
}

compile('org.jenkins-ci.plugins:job-dsl-core:1.34') {
compile('org.jenkins-ci.plugins:job-dsl-core:1.42') {
exclude(module: 'groovy-all')
}

compile 'com.google.guava:guava:19.0'

testCompile('com.netflix.nebula:nebula-test:1.12.5') {
exclude(module: 'groovy-all')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terrafolio.gradle.plugins.jenkins.dsl

import com.terrafolio.gradle.plugins.jenkins.jobdsl.DSLJobType
import groovy.xml.StreamingMarkupBuilder
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.JobType
import org.gradle.util.ConfigureUtil

class JenkinsJob extends AbstractJenkinsConfigurable implements DSLConfigurable, XMLConfigurable {
Expand Down Expand Up @@ -37,7 +37,7 @@ class JenkinsJob extends AbstractJenkinsConfigurable implements DSLConfigurable,
}

def void setType(String type) {
if (JobType.find(type) == null) {
if (DSLJobType.find(type) == null) {
throw new JenkinsConfigurationException("${type} is not a valid jenkins-job-dsl type!")
}
this.type = type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.terrafolio.gradle.plugins.jenkins.dsl

import com.terrafolio.gradle.plugins.jenkins.jobdsl.DSLJobType
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.JobType

/**
* Created by ghale on 4/8/14.
Expand All @@ -24,7 +24,7 @@ class JenkinsJobTemplate implements DSLConfigurable, XMLConfigurable {
}

def void setType(String type) {
if (JobType.find(type) == null) {
if (DSLJobType.find(type) == null) {
throw new JenkinsConfigurationException("${type} is not a valid jenkins-job-dsl type!")
}
this.type = type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ class MapJobManagement extends AbstractJobManagement {
return credentialsDescription
}

@Override
void logPluginDeprecationWarning(String pluginShortName, String minimumVersion) { }

@Override
void requireMinimumPluginVersion(String pluginShortName, String version){
}

@Override
void requireMinimumPluginVersion(String pluginShortName, String version, boolean failIfMissing) {
}

@Override
VersionNumber getPluginVersion(String pluginShortName){
return null
Expand Down Expand Up @@ -106,6 +113,9 @@ class MapJobManagement extends AbstractJobManagement {
@Override
void requirePlugin(String pluginShortName) { }

@Override
void requirePlugin(String pluginShortName, boolean failIfMissing) { }

@Override
void requireMinimumCoreVersion(String version) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.terrafolio.gradle.plugins.jenkins.test.dsl
import com.terrafolio.gradle.plugins.jenkins.dsl.JenkinsJob
import com.terrafolio.gradle.plugins.jenkins.dsl.JenkinsView
import javaposse.jobdsl.dsl.NameNotProvidedException
import javaposse.jobdsl.dsl.ViewType
import nebula.test.ProjectSpec
import org.custommonkey.xmlunit.Diff
import org.custommonkey.xmlunit.XMLUnit
Expand Down Expand Up @@ -77,8 +76,7 @@ class JenkinsConfigurationTest extends ProjectSpec {
def dslFile = project.file('test.dsl')
dslFile.write("""
for (i in 0..2) {
job {
name "Test Job \${i}"
freeStyleJob("Test Job \${i}") {
}
}
""")
Expand Down Expand Up @@ -106,17 +104,15 @@ class JenkinsConfigurationTest extends ProjectSpec {
def dslFile1 = new File(jenkinsDir, 'test1.dsl')
dslFile1.write("""
for (i in 0..2) {
job {
name "Test Job \${i}"
freeStyleJob("Test Job \${i}") {
}
}
""")

def dslFile2 = new File(jenkinsDir, 'test2.dsl')
dslFile2.write("""
for (i in 0..2) {
job {
name "Another Job \${i}"
freeStyleJob("Another Job \${i}") {
}
}
""")
Expand Down Expand Up @@ -145,8 +141,7 @@ class JenkinsConfigurationTest extends ProjectSpec {
def dslFile = project.file('test.dsl')
dslFile.write("""
for (i in 0..2) {
view(type: ListView) {
name("test view \${i}")
listView("test view \${i}") {
}
}
""")
Expand All @@ -173,17 +168,15 @@ class JenkinsConfigurationTest extends ProjectSpec {
def dslFile1 = new File(jenkinsDir, 'test1.dsl')
dslFile1.write("""
for (i in 0..2) {
view(type: ListView) {
name "test view \${i}"
listView("test view \${i}") {
}
}
""")

def dslFile2 = new File(jenkinsDir, 'test2.dsl')
dslFile2.write("""
for (i in 0..2) {
view(type: ListView) {
name "another view \${i}"
listView("another view \${i}") {
}
}
""")
Expand Down Expand Up @@ -212,8 +205,7 @@ class JenkinsConfigurationTest extends ProjectSpec {
project.jenkins {
dsl {
for (i in 0..2) {
job {
name "Test Job ${i}"
freeStyleJob("Test Job ${i}") {
}
}
}
Expand All @@ -236,8 +228,7 @@ class JenkinsConfigurationTest extends ProjectSpec {
project.jenkins {
dsl {
for (i in 0..2) {
view(type: ViewType.ListView) {
name "test view ${i}"
listView("test view ${i}") {
}
}
}
Expand All @@ -254,46 +245,6 @@ class JenkinsConfigurationTest extends ProjectSpec {
"test view 2" | EMPTY_DSL_VIEW_XML
}

def "configure throws exeception when no job name provided with dsl closure"() {
when:
project.jenkins {
dsl {
for (i in 0..2) {
job {
steps {
shell("echo test")
}
}
}
}
}

then:
thrown(NameNotProvidedException)
}

def "configure throws exeception when no job name provided with dsl file"() {
setup:
def dslFile = project.file('test.dsl')
dslFile.write("""
for (i in 0..9) {
job {
steps {
shell "echo test"
}
}
}
""")

when:
project.jenkins {
dsl project.files('test.dsl')
}

then:
thrown(NameNotProvidedException)
}

def "configure configures jobs using dsl closure with basis xml"(jobName, xml) {
setup:
project.jenkins {
Expand All @@ -306,9 +257,8 @@ class JenkinsConfigurationTest extends ProjectSpec {
}
dsl {
for (i in 0..2) {
job {
freeStyleJob("Another Job ${i}") {
using "Test Job"
name "Another Job ${i}"
}
}
}
Expand All @@ -329,9 +279,8 @@ class JenkinsConfigurationTest extends ProjectSpec {
def dslFile = project.file('test.dsl')
dslFile.write("""
for (i in 0..2) {
job {
freeStyleJob("Another Job \${i}") {
using "Test Job"
name "Another Job \${i}"
}
}
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class JenkinsJobTemplateTest extends ProjectSpec {
XMLUnit.setIgnoreWhitespace(true)
def dslFile = project.file('test.dsl')
dslFile.write("""
job {
name "\${GRADLE_JOB_NAME}"
freeStyleJob("\${GRADLE_JOB_NAME}") {
}
""")

Expand All @@ -117,7 +116,7 @@ class JenkinsJobTemplateTest extends ProjectSpec {
templates {
test {
dsl {
name "Test Job"
name = "Test Job"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class JenkinsJobTest extends ProjectSpec {
XMLUnit.setIgnoreWhitespace(true)
def dslFile = project.file('test.dsl')
dslFile.write("""
job {
name "\${GRADLE_JOB_NAME}"
freeStyleJob("\${GRADLE_JOB_NAME}") {
}
""")

Expand All @@ -95,7 +94,7 @@ class JenkinsJobTest extends ProjectSpec {
jobs {
test {
dsl {
name "Test Job"
name = "Test Job"
}
}
}
Expand All @@ -115,7 +114,7 @@ class JenkinsJobTest extends ProjectSpec {
test {
type 'Freeform'
dsl {
name "Test Job"
name = "Test Job"
}
}
}
Expand All @@ -135,7 +134,7 @@ class JenkinsJobTest extends ProjectSpec {
test {
type 'Maven'
dsl {
name "Test Job"
name = "Test Job"
}
}
}
Expand All @@ -155,7 +154,7 @@ class JenkinsJobTest extends ProjectSpec {
test {
type 'Multijob'
dsl {
name "Test Job"
name = "Test Job"
}
}
}
Expand All @@ -175,7 +174,7 @@ class JenkinsJobTest extends ProjectSpec {
test {
type 'BuildFlow'
dsl {
name "Test Job"
name = "Test Job"
}
}
}
Expand Down Expand Up @@ -224,8 +223,7 @@ class JenkinsJobTest extends ProjectSpec {
def newXml = JobFixtures.FREEFORM_DSL_JOB_XML.replaceFirst('true', 'false')
def dslFile = project.file('test.dsl')
dslFile.write("""
job {
name "\${GRADLE_JOB_NAME}"
freeStyleJob("\${GRADLE_JOB_NAME}") {
}
""")

Expand Down Expand Up @@ -384,8 +382,7 @@ class JenkinsJobTest extends ProjectSpec {
def newXml = JobFixtures.FREEFORM_DSL_JOB_XML.replaceFirst('false', 'true').replaceFirst('n><', 'n>test<')
def dslFile = project.file('test.dsl')
dslFile.write("""
job {
name "\${GRADLE_JOB_NAME}"
freeStyleJob("\${GRADLE_JOB_NAME}") {
using "\${GRADLE_JOB_NAME}"
keepDependencies true
}
Expand Down Expand Up @@ -418,8 +415,7 @@ class JenkinsJobTest extends ProjectSpec {
def newXml = JobFixtures.FREEFORM_DSL_JOB_XML.replaceFirst('false', 'true').replaceFirst('n><', 'n>test<')
def dslFile = project.file('test.dsl')
dslFile.write("""
job {
name "\${GRADLE_JOB_NAME}"
freeStyleJob("\${GRADLE_JOB_NAME}") {
using "\${GRADLE_JOB_NAME}"
keepDependencies true
}
Expand All @@ -446,8 +442,7 @@ class JenkinsJobTest extends ProjectSpec {
def dslFile = project.file('test.dsl')
dslFile.write("""
for (i in 0..1) {
job {
name "Test Job \${i}"
freeStyleJob("Test Job \${i}") {
}
}
""")
Expand All @@ -474,7 +469,7 @@ class JenkinsJobTest extends ProjectSpec {
jobs {
test {
dsl {
name "Test Job"
name = "Test Job"
wrappers {
configure { root ->
count++
Expand Down
Loading

0 comments on commit 534b751

Please sign in to comment.