Skip to content

Commit

Permalink
Add failOnMissingPlugin option to dslGenerateXml task
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzo Crisóstomo authored and mnonnenmacher committed May 25, 2018
1 parent e23af46 commit 3de67a1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ class GenerateXmlTest extends AbstractTaskTest {
XMLUnit.compareXML(expectedText, actualText).identical()
}

def 'failOnMissingPlugin fails the task if a required plugin is missing'() {
given:
buildFile << readBuildGradle('generateXml/build-with-missing-plugins.gradle')
copyResourceToTestDir('generateXml/folder.groovy')

when:
def result = gradleRunner
.withArguments('dslGenerateXml', '--failOnMissingPlugin')
.buildAndFail()

then:
result.task(':dslGenerateXml').outcome == TaskOutcome.FAILED
result.output.contains("plugin 'cloudbees-folder' needs to be installed")
}

def 'job in folder is generated in the right subfolder'() {
given:
buildFile << readBuildGradle('generateXml/build.gradle')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
buildscript {
dependencies {
classpath files(CLASSPATH_STRING)
}
}

apply plugin: 'com.here.jobdsl'

dependencies {
compile localGroovy()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ class FilteringJenkinsJobManagement extends JenkinsJobManagement {

private final ItemFilter filter

FilteringJenkinsJobManagement(ItemFilter filter, PrintStream outputLogger, Map<String, ?> envVars, File workspace) {
FilteringJenkinsJobManagement(ItemFilter filter, PrintStream outputLogger, Map<String, ?> envVars,
File workspace, boolean failOnMissingPlugin) {
super(outputLogger, envVars, workspace)
this.filter = filter
this.failOnMissingPlugin = failOnMissingPlugin
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package com.here.gradle.plugins.jobdsl.tasks

import org.gradle.api.internal.tasks.options.Option
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional

/**
* Task that calls {@link com.here.gradle.plugins.jobdsl.tasks.runners.GenerateXmlRunner} to generate XML files for
* all items and views configured in the project.
*/
class GenerateXmlTask extends AbstractDslTask {

@Input
@Optional
boolean failOnMissingPlugin

GenerateXmlTask() {
super()
description = 'Generate XML for all jobs.'
failOnMissingPlugin = false
}

@Override
Expand All @@ -20,8 +29,14 @@ class GenerateXmlTask extends AbstractDslTask {
@Override
Map<String, ?> getProperties() {
[
outputDirectory: "${project.buildDir}/jobdsl/xml"
outputDirectory : "${project.buildDir}/jobdsl/xml",
failOnMissingPlugin: failOnMissingPlugin,
]
}

@Option(option = 'failOnMissingPlugin', description = 'Fail the task if a required plugin is missing.')
void setFailOnMissingPlugin(boolean failOnMissingPlugin) {
this.failOnMissingPlugin = failOnMissingPlugin
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class GenerateXmlRunner extends AbstractTaskRunner {

@Override
JobManagement createJobManagement(Jenkins jenkins, ItemFilter filter) {
boolean failOnMissingPlugin = runProperties['failOnMissingPlugin'].toBoolean()
def workspace = Files.createTempDirectory('jobdsl').toFile()
workspace.deleteOnExit()

new FilteringJenkinsJobManagement(filter, System.out, [:], workspace)
new FilteringJenkinsJobManagement(filter, System.out, [:], workspace, failOnMissingPlugin)
}

@Override
Expand Down

0 comments on commit 3de67a1

Please sign in to comment.