Skip to content

Commit

Permalink
decode element name before mapping to class
Browse files Browse the repository at this point in the history
[FIXES JENKINS-37450]
  • Loading branch information
daspilker committed Aug 17, 2016
1 parent 9edd3c9 commit d329f45
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 2 additions & 0 deletions docs/Home.md
Expand Up @@ -27,6 +27,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins

## Release Notes
* 1.50 (unreleased)
* Fixed regression when updating views
([JENKINS-37450](https://issues.jenkins-ci.org/browse/JENKINS-37450))
* 1.49 (August 16 2016)
* Enhanced support for the [Sauce OnDemand Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Sauce+OnDemand+Plugin)
([JENKINS-36370](https://issues.jenkins-ci.org/browse/JENKINS-36370))
Expand Down
1 change: 1 addition & 0 deletions job-dsl-plugin/build.gradle
Expand Up @@ -66,5 +66,6 @@ dependencies {
optionalJenkinsPlugins 'org.jenkins-ci.plugins:config-file-provider:2.8.1@jar'
optionalJenkinsPlugins 'org.jenkinsci.plugins:managed-scripts:1.2.1@jar'
jenkinsTest 'org.jenkins-ci.plugins:cloudbees-folder:5.0@jar'
jenkinsTest 'org.jenkins-ci.plugins:nested-view:1.14@jar'
jenkinsTest 'org.jenkins-ci.main:jenkins-test-harness:2.7@jar'
}
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.thoughtworks.xstream.io.xml.XppDriver;
import groovy.util.Node;
import groovy.util.XmlParser;
import hudson.FilePath;
Expand Down Expand Up @@ -512,23 +513,9 @@ private void checkItemType(AbstractItem item, javaposse.jobdsl.dsl.Item dslItem)
}

private void checkItemType(View view, InputStream config) {
Node newConfig;

try {
newConfig = new XmlParser().parse(config);
} catch (Exception e) {
throw new DslException(format(
Messages.UpdateExistingView_CouldNotParseConfig(),
view.getViewName()
), e);
}

Class viewType = Jenkins.XSTREAM2.getMapper().realClass(newConfig.name().toString());
Class viewType = Jenkins.XSTREAM2.getMapper().realClass(new XppDriver().createReader(config).getNodeName());
if (!viewType.equals(view.getClass())) {
throw new DslException(format(
Messages.UpdateExistingView_ViewTypeDoesNotMatch(),
view.getViewName()
));
throw new DslException(format(Messages.UpdateExistingView_ViewTypeDoesNotMatch(), view.getViewName()));
}
}

Expand Down
Expand Up @@ -859,6 +859,21 @@ class JenkinsJobManagementSpec extends Specification {
!parameters.containsKey('SEED_JOB')
}
def 'create nested view JENKINS-37450'() {
setup:
jobManagement.createOrUpdateView(
'test', loadResource('javaposse/jobdsl/dsl/views/NestedView-template.xml'), false
)
when:
jobManagement.createOrUpdateView(
'test', loadResource('javaposse/jobdsl/dsl/views/NestedView-template.xml'), false
)
then:
noExceptionThrown()
}
private static boolean isXmlIdentical(String expected, Node actual) throws Exception {
XMLUnit.ignoreWhitespace = true
XMLUnit.compareXML(loadResource(expected), nodeToString(actual)).identical()
Expand Down

0 comments on commit d329f45

Please sign in to comment.