Skip to content

Commit

Permalink
[FIXED JENKINS-34204] include node attributes when writing job dsl nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackbaud-MikeLueders committed Apr 13, 2016
1 parent 5ca0f6b commit 0b86ed8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
@@ -1,6 +1,7 @@
package hudson.plugins.promoted_builds.integrations.jobdsl;

import java.util.Collection;
import java.util.Map;

import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
Expand All @@ -15,6 +16,8 @@
import hudson.PluginManager;
import hudson.PluginWrapper;
import jenkins.model.Jenkins;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;

/**
* XStream Converter for the PromotionProcess for the Job DSL Plugin
Expand Down Expand Up @@ -89,6 +92,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC

private void convertNode(Node node, HierarchicalStreamWriter writer) {
writer.startNode(node.name().toString());
writeNodeAttributes(node, writer);
if (node.value() instanceof Collection) {
for (Object subNode : (Collection) node.value()) {
convertNode((Node) subNode, writer);
Expand All @@ -99,6 +103,17 @@ private void convertNode(Node node, HierarchicalStreamWriter writer) {
writer.endNode();
}

private void writeNodeAttributes(Node node, HierarchicalStreamWriter writer) {
Map<?,?> attributes = node.attributes();
if (attributes != null) {
for (Map.Entry<?,?> entry : attributes.entrySet()) {
String key = ObjectUtils.toString(entry.getKey());
String value = ObjectUtils.toString(entry.getValue());
writer.addAttribute(key, value);
}
}
}

private String obtainClassOwnership() {
if (this.classOwnership != null) {
return this.classOwnership;
Expand Down
Expand Up @@ -61,7 +61,6 @@ public void testShouldGenerateTheCopyArtifactsJob() throws Exception {
TopLevelItem item = jenkins.getItem("copy-artifacts-test");
File config = new File(item.getRootDir(), "promotions/Development/config.xml");
String content = Files.toString(config, Charset.forName("UTF-8"));
System.out.println("CONTENT: " + content);
assert content.contains("<selector class=\"hudson.plugins.copyartifact.SpecificBuildSelector\">");
}

Expand Down

0 comments on commit 0b86ed8

Please sign in to comment.