1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.ci.config.load;
17
18 import org.jdom.Document;
19 import org.jdom.Element;
20 import org.jdom.JDOMException;
21
22 import de.smartics.ci.config.hudson.HudsonConfigEntry;
23 import de.smartics.ci.config.hudson.HudsonConfigScmElement;
24 import de.smartics.ci.config.hudson.ScmType;
25 import de.smartics.ci.config.maven.MavenConfig;
26 import de.smartics.ci.config.maven.MavenPom;
27
28
29
30
31 class MavenInfoApplier
32 {
33
34
35
36
37
38
39
40
41
42
43 private final HudsonJobConfigurationLoaderConfig loaderConfig;
44
45
46
47
48 private final LoaderPlan plan;
49
50
51
52
53
54 private final MavenConfig mavenConfig;
55
56
57
58
59
60 MavenInfoApplier(final HudsonJobConfigurationLoaderConfig loaderConfig,
61 final LoaderPlan plan)
62 {
63 this.plan = plan;
64 this.loaderConfig = loaderConfig;
65 this.mavenConfig = plan.getMavenConfig();
66 }
67
68
69
70
71
72
73
74
75
76
77
78 void addAllInfo(final Document hudsonConfigXml) throws JDOMException
79 {
80 addScmInfo(hudsonConfigXml);
81 addProjectInfo(hudsonConfigXml);
82 addProjectDescription(hudsonConfigXml);
83 }
84
85 void addScmInfo(final Document hudsonConfigXml) throws JDOMException
86 {
87 final HudsonConfigScmElement element =
88 new HudsonConfigScmElement(hudsonConfigXml);
89
90 final MavenPom pom = mavenConfig.getPom();
91
92 if (pom.isScmInfoProvided())
93 {
94 final ScmType scmType = pom.getScmType();
95 final String scmUrl = pom.getScmUrl();
96
97 final HudsonConfigEntry entry = new HudsonConfigEntry(hudsonConfigXml);
98 entry.addScmConfig(scmType, scmUrl);
99
100 if (loaderConfig.isAddScmElementWithFullContent())
101 {
102 element.addScmConfig(scmType, scmUrl);
103 }
104 }
105 }
106
107 void addProjectInfo(final Document hudsonConfigXml) throws JDOMException
108 {
109 final Element rootModule = new Element("rootModule");
110 final Element groupId = new Element("groupId");
111 final Element artifactId = new Element("artifactId");
112
113 final MavenPom pom = mavenConfig.getPom();
114 groupId.addContent(pom.getGroupId());
115 artifactId.addContent(pom.getArtifactId());
116
117 rootModule.addContent(groupId);
118 rootModule.addContent(artifactId);
119
120 final Element authToken = new Element("authToken");
121 final String authTokenString = createAuthToken();
122 authToken.addContent(authTokenString);
123
124 final Element root = hudsonConfigXml.getRootElement();
125 root.addContent(authToken);
126 root.addContent(rootModule);
127 }
128
129 private String createAuthToken()
130 {
131 final MavenPom pom = mavenConfig.getPom();
132 final String artifactId = pom.getArtifactId();
133 final String planId = plan.getId();
134 final String authToken = artifactId + '-' + planId;
135 return authToken;
136 }
137
138 void addProjectDescription(final Document hudsonConfigXml)
139 throws JDOMException
140 {
141 final Element description = new Element("description");
142
143 final MavenPom pom = mavenConfig.getPom();
144 description.addContent(pom.getDescription());
145
146 hudsonConfigXml.getRootElement().addContent(description);
147 }
148
149
150
151 }