Skip to content
Permalink
Browse files

Merge branch 'JENKINS-38648'

  • Loading branch information
daspilker committed Oct 17, 2016
2 parents 4aaf8e9 + f4f1d93 commit 2c13f9aa4c0e5d5a7903e2c104113eec2e6d4a7b
Showing with 151 additions and 23 deletions.
  1. +2 −0 docs/Home.md
  2. +6 −1 job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/GeneratedConfigFile.groovy
  3. +6 −1 job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/GeneratedJob.groovy
  4. +6 −1 job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/GeneratedUserContent.groovy
  5. +6 −1 job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/GeneratedView.groovy
  6. +15 −2 job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/GeneratedConfigFileSpec.groovy
  7. +12 −0 job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/GeneratedJobSpec.groovy
  8. +25 −0 job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/GeneratedUserContentSpec.groovy
  9. +13 −0 job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/GeneratedViewSpec.groovy
  10. +27 −0 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/Comparators.groovy
  11. +1 −1 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/GeneratedJobsAction.groovy
  12. +1 −1 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/GeneratedJobsBuildAction.groovy
  13. +1 −1 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/GeneratedObjectsAction.groovy
  14. +3 −1 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/GeneratedObjectsBuildAction.java
  15. +1 −1 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/GeneratedViewsAction.groovy
  16. +1 −1 job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/actions/GeneratedViewsBuildAction.groovy
  17. +8 −5 job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/actions/GeneratedJobsBuildActionSpec.groovy
  18. +8 −1 job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/actions/GeneratedViewsActionSpec.groovy
  19. +9 −5 job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/actions/GeneratedViewsBuildActionSpec.groovy
@@ -46,6 +46,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* Fixed problem with embedded API viewer
([JENKINS-38456](https://issues.jenkins-ci.org/browse/JENKINS-38456),
[JENKINS-38964](https://issues.jenkins-ci.org/browse/JENKINS-38964))
* Sort generated items by name on the seed job's summary and build pages
([JENKINS-38648](https://issues.jenkins-ci.org/browse/JENKINS-38648))
* Support for the older versions of the [Git Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin) is
deprecated, see [Migration](Migration#migrating-to-152)
* Support for the older versions of the [Multijob Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin)
@@ -1,6 +1,6 @@
package javaposse.jobdsl.dsl

class GeneratedConfigFile {
class GeneratedConfigFile implements Comparable<GeneratedConfigFile> {
final String id
final String name

@@ -34,4 +34,9 @@ class GeneratedConfigFile {
String toString() {
"GeneratedConfigFile{name='${name}', id='${id}'}"
}

@Override
int compareTo(GeneratedConfigFile o) {
name <=> o.name
}
}
@@ -1,6 +1,6 @@
package javaposse.jobdsl.dsl

class GeneratedJob {
class GeneratedJob implements Comparable<GeneratedJob> {
final String templateName
final String jobName

@@ -34,4 +34,9 @@ class GeneratedJob {
String toString() {
"GeneratedJob{name='${jobName}'${templateName == null ? '' : ", template='${templateName}'"}}"
}

@Override
int compareTo(GeneratedJob o) {
jobName <=> o.jobName
}
}
@@ -1,6 +1,6 @@
package javaposse.jobdsl.dsl

class GeneratedUserContent {
class GeneratedUserContent implements Comparable<GeneratedUserContent> {
final String path

GeneratedUserContent(String path) {
@@ -32,4 +32,9 @@ class GeneratedUserContent {
String toString() {
"GeneratedUserContent{path='${path}'}"
}

@Override
int compareTo(GeneratedUserContent o) {
path <=> o.path
}
}
@@ -1,6 +1,6 @@
package javaposse.jobdsl.dsl

class GeneratedView {
class GeneratedView implements Comparable<GeneratedView> {
final String name

GeneratedView(String name) {
@@ -32,4 +32,9 @@ class GeneratedView {
String toString() {
"GeneratedView{name='${name}'}"
}

@Override
int compareTo(GeneratedView o) {
name <=> o.name
}
}
@@ -28,6 +28,7 @@ class GeneratedConfigFileSpec extends Specification {
configFile.name == 'foo'
}

@SuppressWarnings('ChangeToOperator')
def 'only id is relevant for hashCode and equals'() {
when:
GeneratedConfigFile configFile1 = new GeneratedConfigFile('235421345', 'foo')
@@ -37,8 +38,8 @@ class GeneratedConfigFileSpec extends Specification {
then:
configFile1.hashCode() == configFile2.hashCode()
configFile2.hashCode() != configFile3.hashCode()
configFile1 == configFile2
configFile2 != configFile3
configFile1.equals(configFile2)
!configFile2.equals(configFile3)
}

def 'test toString'() {
@@ -48,4 +49,16 @@ class GeneratedConfigFileSpec extends Specification {
then:
configFile.toString() == "GeneratedConfigFile{name='foo', id='235421345'}"
}

@SuppressWarnings('ChangeToOperator')
def 'test compare'() {
when:
GeneratedConfigFile configFile1 = new GeneratedConfigFile('235421345', 'foo')
GeneratedConfigFile configFile2 = new GeneratedConfigFile('235421345', 'new name')

then:
configFile1.compareTo(configFile1) == 0
configFile1.compareTo(configFile2) < 0
configFile2.compareTo(configFile1) > 0
}
}
@@ -18,4 +18,16 @@ class GeneratedJobSpec extends Specification {
then:
generatedJob.toString() == "GeneratedJob{name='test', template='foo'}"
}

@SuppressWarnings('ChangeToOperator')
def 'test compare'() {
when:
GeneratedJob job1 = new GeneratedJob('235421345', 'foo')
GeneratedJob job2 = new GeneratedJob('235421345', 'new name')

then:
job1.compareTo(job1) == 0
job1.compareTo(job2) < 0
job2.compareTo(job1) > 0
}
}
@@ -0,0 +1,25 @@
package javaposse.jobdsl.dsl

import spock.lang.Specification

class GeneratedUserContentSpec extends Specification {
def 'test toString'() {
when:
GeneratedUserContent generatedUserContent = new GeneratedUserContent('test')

then:
generatedUserContent.toString() == "GeneratedUserContent{path='test'}"
}

@SuppressWarnings('ChangeToOperator')
def 'test compare'() {
when:
GeneratedUserContent userContent1 = new GeneratedUserContent('foo')
GeneratedUserContent userContent2 = new GeneratedUserContent('other')

then:
userContent1.compareTo(userContent1) == 0
userContent1.compareTo(userContent2) < 0
userContent2.compareTo(userContent1) > 0
}
}
@@ -19,6 +19,7 @@ class GeneratedViewSpec extends Specification {
thrown(IllegalArgumentException)
}

@SuppressWarnings(['ChangeToOperator', 'GrEqualsBetweenInconvertibleTypes'])
def 'test equals'() {
when:
GeneratedView view = new GeneratedView('test')
@@ -46,4 +47,16 @@ class GeneratedViewSpec extends Specification {
then:
view.toString() == "GeneratedView{name='test'}"
}

@SuppressWarnings('ChangeToOperator')
def 'test compare'() {
when:
GeneratedView view1 = new GeneratedView('foo')
GeneratedView view2 = new GeneratedView('other')

then:
view1.compareTo(view1) == 0
view1.compareTo(view2) < 0
view2.compareTo(view1) > 0
}
}
@@ -0,0 +1,27 @@
package javaposse.jobdsl.plugin.actions

import groovy.transform.PackageScope
import hudson.model.Item
import hudson.model.View

@PackageScope
class Comparators {
static final Comparator<Item> ITEM_COMPARATOR = new Comparator<Item>() {
@Override
int compare(Item o1, Item o2) {
o1.fullDisplayName <=> o2.fullDisplayName
}
}

static final Comparator<View> VIEW_COMPARATOR = new Comparator<View>() {
@Override
int compare(View o1, View o2) {
getFullDisplayName(o1) <=> getFullDisplayName(o2)
}

private static String getFullDisplayName(View view) {
String ownerDisplayName = view.ownerItemGroup.fullDisplayName
ownerDisplayName.length() == 0 ? view.displayName : "${ownerDisplayName} » ${view.displayName}"
}
}
}
@@ -11,7 +11,7 @@ class GeneratedJobsAction extends GeneratedObjectsAction<GeneratedJob, Generated
}

Set<Item> getItems() {
Set<Item> result = []
Set<Item> result = new TreeSet<>(Comparators.ITEM_COMPARATOR)
for (Run run : job.builds) {
GeneratedJobsBuildAction action = run.getAction(GeneratedJobsBuildAction)
if (action != null) {
@@ -20,7 +20,7 @@ class GeneratedJobsBuildAction extends GeneratedObjectsRunAction<GeneratedJob> {
}

Set<Item> getItems() {
Set<Item> result = []
Set<Item> result = new TreeSet<>(Comparators.ITEM_COMPARATOR)
for (GeneratedJob job : modifiedObjects) {
Item item = lookupStrategy.getItem(owner.parent, job.jobName, Item)
if (item != null) {
@@ -29,7 +29,7 @@ abstract class GeneratedObjectsAction<T, B extends GeneratedObjectsRunAction<T>>

@SuppressWarnings('GroovyUnusedDeclaration') // used by some Jelly views
Set<T> findAllGeneratedObjects() {
Set<T> result = []
Set<T> result = [] as SortedSet<T>
for (Run run : job.builds) {
B action = run.getAction(buildActionClass)
if (action != null && action.modifiedObjects != null) {
@@ -5,6 +5,7 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;

/**
* @deprecated use {@code javaposse.jobdsl.plugin.actions.GeneratedObjectsRunAction} instead
@@ -32,7 +33,8 @@ public String getUrlName() {
return null;
}

@SuppressWarnings("ConstantConditions") // modifiedObjects can be null when this is deserialized by XStream
public Collection<T> getModifiedObjects() {
return modifiedObjects;
return modifiedObjects == null ? null : new TreeSet<T>(modifiedObjects);
}
}
@@ -11,7 +11,7 @@ class GeneratedViewsAction extends GeneratedObjectsAction<GeneratedView, Generat
}

Set<View> getViews() {
Set<View> result = []
Set<View> result = new TreeSet<>(Comparators.VIEW_COMPARATOR)
for (Run run : job.builds) {
GeneratedViewsBuildAction action = run.getAction(GeneratedViewsBuildAction)
if (action != null) {
@@ -23,7 +23,7 @@ class GeneratedViewsBuildAction extends GeneratedObjectsRunAction<GeneratedView>
}

Set<View> getViews() {
Set<View> allGeneratedViews = []
Set<View> allGeneratedViews = new TreeSet<>(Comparators.VIEW_COMPARATOR)
for (GeneratedView generatedView : modifiedObjects) {
ItemGroup itemGroup = lookupStrategy.getParent(owner.parent, generatedView.name)
if (itemGroup instanceof ViewGroup) {
@@ -56,21 +56,24 @@ class GeneratedJobsBuildActionSpec extends Specification {
setup:
Item jobOne = jenkinsRule.jenkins.createProject(FreeStyleProject, 'one')
Item jobTwo = jenkinsRule.jenkins.createProject(FreeStyleProject, 'two')
Item jobThree = jenkinsRule.jenkins.createProject(FreeStyleProject, 'aaa')
GeneratedJob one = new GeneratedJob(null, 'one')
GeneratedJob two = new GeneratedJob(null, 'two')
GeneratedJob three = new GeneratedJob(null, 'aaa')
Run run = Mock(Run)
run.parent >> Mock(Job)
GeneratedJobsBuildAction action = new GeneratedJobsBuildAction([one, two], LookupStrategy.JENKINS_ROOT)
GeneratedJobsBuildAction action = new GeneratedJobsBuildAction([one, two, three], LookupStrategy.JENKINS_ROOT)
action.onLoad(run)

when:
Set<Item> items = action.items
List<Item> items = action.items as List

then:
items != null
items.size() == 2
items.contains(jobOne)
items.contains(jobTwo)
items.size() == 3
items[0] == jobThree
items[1] == jobOne
items[2] == jobTwo
}

def 'project actions'() {
@@ -2,6 +2,7 @@ package javaposse.jobdsl.plugin.actions

import hudson.model.AbstractBuild
import hudson.model.AbstractProject
import hudson.model.ItemGroup
import hudson.model.View
import javaposse.jobdsl.dsl.GeneratedView
import spock.lang.Specification
@@ -14,7 +15,7 @@ class GeneratedViewsActionSpec extends Specification {
AbstractBuild build2 = Mock(AbstractBuild)
AbstractProject project = Mock(AbstractProject)
Collection<GeneratedView> modifiedViews = [Mock(GeneratedView), Mock(GeneratedView)]
Collection<View> views = [Mock(View), Mock(View)]
List<View> views = [Mock(View), Mock(View)]

def 'interface methods'() {
when:
@@ -103,6 +104,12 @@ class GeneratedViewsActionSpec extends Specification {

def 'getViews'() {
setup:
ItemGroup itemGroup = Mock(ItemGroup)
itemGroup.fullDisplayName >> 'foo'
views[0].displayName >> 'one'
views[0].ownerItemGroup >> itemGroup
views[1].displayName >> 'two'
views[1].ownerItemGroup >> itemGroup
buildAction.views >> views
build1.getAction(GeneratedViewsBuildAction) >> buildAction
build2.getAction(GeneratedViewsBuildAction) >> buildAction
@@ -56,23 +56,27 @@ class GeneratedViewsBuildActionSpec extends Specification {
setup:
View viewOne = new ListView('one')
View viewTwo = new ListView('two')
View viewThree = new ListView('aaa')
jenkinsRule.jenkins.addView(viewOne)
jenkinsRule.jenkins.addView(viewTwo)
jenkinsRule.jenkins.addView(viewThree)
GeneratedView one = new GeneratedView('one')
GeneratedView two = new GeneratedView('two')
GeneratedView three = new GeneratedView('aaa')
Run run = Mock(Run)
run.parent >> Mock(Job)
GeneratedViewsBuildAction action = new GeneratedViewsBuildAction([one, two], LookupStrategy.JENKINS_ROOT)
GeneratedViewsBuildAction action = new GeneratedViewsBuildAction([one, two, three], LookupStrategy.JENKINS_ROOT)
action.onLoad(run)

when:
Set<View> views = action.views
List<View> views = action.views as List

then:
views != null
views.size() == 2
views.contains(viewOne)
views.contains(viewTwo)
views.size() == 3
views[0] == viewThree
views[1] == viewOne
views[2] == viewTwo
}

def 'project actions'() {

0 comments on commit 2c13f9a

Please sign in to comment.
You can’t perform that action at this time.