Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-32196] Added support for the Maven Info Plugin
[JENKINS-32196] Added support for the Maven Info Plugin [JENKINS-32196] Removed redundant context [JENKINS-32196] Minor bits and pieces [JENKINS-32196] Removed unused imports
- Loading branch information
Showing
6 changed files
with
209 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
.../examples/javaposse/jobdsl/dsl/helpers/properties/MavenPropertiesContext/mavenInfo.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,19 @@ | ||
mavenJob('example_1') { | ||
properties { | ||
mavenInfo { | ||
modulePattern(':my-artifact') | ||
interestingDependenciesPattern('org.springframework.*:*') | ||
assignName('name template') | ||
} | ||
} | ||
} | ||
|
||
mavenJob('example_2') { | ||
properties { | ||
mavenInfo { | ||
modulePattern(':my-artifact') | ||
interestingDependenciesPattern('org.springframework.*:*') | ||
assignDescription('some text') | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/properties/MavenInfoContext.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,42 @@ | ||
package javaposse.jobdsl.dsl.helpers.properties | ||
|
||
import javaposse.jobdsl.dsl.Context | ||
|
||
class MavenInfoContext implements Context { | ||
boolean assignName = false | ||
boolean assignDescription = false | ||
String name | ||
String description | ||
String modulePattern | ||
String interestingDependenciesPattern | ||
|
||
/** | ||
* Sets the name from main module pom.xml (from tag <name>). | ||
*/ | ||
void assignName(String name) { | ||
this.assignName = true | ||
this.name = name | ||
} | ||
|
||
/** | ||
* Sets the description from main module pom.xml (from tag <description>). | ||
*/ | ||
void assignDescription(String description) { | ||
this.assignDescription = true | ||
this.description = description | ||
} | ||
|
||
/** | ||
* Sets the regex pattern to find module to extract versions, name, description. | ||
*/ | ||
void modulePattern(String modulePattern) { | ||
this.modulePattern = modulePattern | ||
} | ||
|
||
/** | ||
* Sets the pattern to find interesting dependencies. | ||
*/ | ||
void interestingDependenciesPattern(String interestingDependenciesPattern) { | ||
this.interestingDependenciesPattern = interestingDependenciesPattern | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ore/src/main/groovy/javaposse/jobdsl/dsl/helpers/properties/MavenPropertiesContext.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,38 @@ | ||
package javaposse.jobdsl.dsl.helpers.properties | ||
|
||
import javaposse.jobdsl.dsl.ContextHelper | ||
import javaposse.jobdsl.dsl.DslContext | ||
import javaposse.jobdsl.dsl.Item | ||
import javaposse.jobdsl.dsl.JobManagement | ||
import javaposse.jobdsl.dsl.RequiresPlugin | ||
|
||
class MavenPropertiesContext extends PropertiesContext { | ||
|
||
MavenPropertiesContext(JobManagement jobManagement, Item item) { | ||
super(jobManagement, item) | ||
} | ||
|
||
/** | ||
* This plugin add features related to Maven jobs info. Extract information from Maven jobs (update name and | ||
* description from POM) | ||
* | ||
* @since 1.46 | ||
*/ | ||
@RequiresPlugin(id = 'maven-info', minimumVersion = '0.2.0') | ||
void mavenInfo(@DslContext(MavenInfoContext) Closure closure) { | ||
MavenInfoContext context = new MavenInfoContext() | ||
ContextHelper.executeInContext(closure, context) | ||
|
||
propertiesNodes << new NodeBuilder().'jenkins.plugins.maveninfo.config.MavenInfoJobConfig' { | ||
assignName(context.assignName) | ||
nameTemplate(context.name ?: '') | ||
assignDescription(context.assignDescription) | ||
if (context.assignDescription) { | ||
descriptionTemplate(context.description ?: '') | ||
} | ||
mainModulePattern(context.modulePattern ?: '') | ||
dependenciesPattern(context.interestingDependenciesPattern ?: '') | ||
} | ||
} | ||
|
||
} |
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
91 changes: 91 additions & 0 deletions
91
...src/test/groovy/javaposse/jobdsl/dsl/helpers/properties/MavenPropertiesContextSpec.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,91 @@ | ||
package javaposse.jobdsl.dsl.helpers.properties | ||
|
||
import javaposse.jobdsl.dsl.Item | ||
import javaposse.jobdsl.dsl.JobManagement | ||
import spock.lang.Specification | ||
|
||
class MavenPropertiesContextSpec extends Specification { | ||
JobManagement jobManagement = Mock(JobManagement) | ||
Item item = Mock(Item) | ||
MavenPropertiesContext context = new MavenPropertiesContext(jobManagement, item) | ||
|
||
def 'call mavenInfo with no options'() { | ||
when: | ||
context.mavenInfo { | ||
} | ||
|
||
then: | ||
with(context.propertiesNodes[0]) { | ||
name() == 'jenkins.plugins.maveninfo.config.MavenInfoJobConfig' | ||
children().size() == 5 | ||
assignDescription[0].value() == false | ||
mainModulePattern[0].value().empty | ||
dependenciesPattern[0].value().empty | ||
assignName[0].value() == false | ||
nameTemplate[0].value().empty | ||
} | ||
1 * jobManagement.requireMinimumPluginVersion('maven-info', '0.2.0') | ||
} | ||
|
||
def 'call mavenInfo with assignName option'() { | ||
when: | ||
context.mavenInfo { | ||
assignName('name template') | ||
} | ||
|
||
then: | ||
with(context.propertiesNodes[0]) { | ||
name() == 'jenkins.plugins.maveninfo.config.MavenInfoJobConfig' | ||
children().size() == 5 | ||
assignDescription[0].value() == false | ||
mainModulePattern[0].value().empty | ||
dependenciesPattern[0].value().empty | ||
assignName[0].value() == true | ||
nameTemplate[0].value() == 'name template' | ||
} | ||
1 * jobManagement.requireMinimumPluginVersion('maven-info', '0.2.0') | ||
} | ||
|
||
def 'call mavenInfo with assignDescription option'() { | ||
when: | ||
context.mavenInfo { | ||
assignDescription('some text') | ||
} | ||
|
||
then: | ||
with(context.propertiesNodes[0]) { | ||
name() == 'jenkins.plugins.maveninfo.config.MavenInfoJobConfig' | ||
children().size() == 6 | ||
assignDescription[0].value() == true | ||
descriptionTemplate[0].value() == 'some text' | ||
mainModulePattern[0].value().empty | ||
dependenciesPattern[0].value().empty | ||
assignName[0].value() == false | ||
nameTemplate[0].value().empty | ||
} | ||
1 * jobManagement.requireMinimumPluginVersion('maven-info', '0.2.0') | ||
} | ||
|
||
def 'call mavenInfo with all options'() { | ||
when: | ||
context.mavenInfo { | ||
modulePattern(':my-artifact') | ||
interestingDependenciesPattern('org.springframework.*:*') | ||
assignName('name template') | ||
assignDescription('some text') | ||
} | ||
|
||
then: | ||
with(context.propertiesNodes[0]) { | ||
name() == 'jenkins.plugins.maveninfo.config.MavenInfoJobConfig' | ||
children().size() == 6 | ||
assignDescription[0].value() == true | ||
descriptionTemplate[0].value() == 'some text' | ||
mainModulePattern[0].value() == ':my-artifact' | ||
dependenciesPattern[0].value() == 'org.springframework.*:*' | ||
assignName[0].value() == true | ||
nameTemplate[0].value() == 'name template' | ||
} | ||
1 * jobManagement.requireMinimumPluginVersion('maven-info', '0.2.0') | ||
} | ||
} |