Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failOnMissingPlugin option to dslGenerateXml task #82

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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