Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MavenInfoApplier |
|
|
1.3333333333333333;1.333 |
1 | /* |
|
2 | * Copyright 2012 smartics, Kronseder & Reiner GmbH |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | * Applies Maven settings and POM information to a Hudson config XML document. |
|
30 | */ |
|
31 | class MavenInfoApplier |
|
32 | { |
|
33 | // ********************************* Fields ********************************* |
|
34 | ||
35 | // --- constants ------------------------------------------------------------ |
|
36 | ||
37 | // --- members -------------------------------------------------------------- |
|
38 | ||
39 | /** |
|
40 | * The loader configuration to control the loading and creation of Hudson job |
|
41 | * configuration files. |
|
42 | */ |
|
43 | private final HudsonJobConfigurationLoaderConfig loaderConfig; |
|
44 | ||
45 | /** |
|
46 | * The plan to access plan information. |
|
47 | */ |
|
48 | private final LoaderPlan plan; |
|
49 | ||
50 | /** |
|
51 | * The Maven configuration to provide information for the Hudson |
|
52 | * configuration. |
|
53 | */ |
|
54 | private final MavenConfig mavenConfig; |
|
55 | ||
56 | // ****************************** Initializer ******************************* |
|
57 | ||
58 | // ****************************** Constructors ****************************** |
|
59 | ||
60 | MavenInfoApplier(final HudsonJobConfigurationLoaderConfig loaderConfig, |
|
61 | final LoaderPlan plan) |
|
62 | 0 | { |
63 | 0 | this.plan = plan; |
64 | 0 | this.loaderConfig = loaderConfig; |
65 | 0 | this.mavenConfig = plan.getMavenConfig(); |
66 | 0 | } |
67 | ||
68 | // ****************************** Inner Classes ***************************** |
|
69 | ||
70 | // ********************************* Methods ******************************** |
|
71 | ||
72 | // --- init ----------------------------------------------------------------- |
|
73 | ||
74 | // --- get&set -------------------------------------------------------------- |
|
75 | ||
76 | // --- business ------------------------------------------------------------- |
|
77 | ||
78 | void addAllInfo(final Document hudsonConfigXml) throws JDOMException |
|
79 | { |
|
80 | 0 | addScmInfo(hudsonConfigXml); |
81 | 0 | addProjectInfo(hudsonConfigXml); |
82 | 0 | addProjectDescription(hudsonConfigXml); |
83 | 0 | } |
84 | ||
85 | void addScmInfo(final Document hudsonConfigXml) throws JDOMException |
|
86 | { |
|
87 | 0 | final HudsonConfigScmElement element = |
88 | new HudsonConfigScmElement(hudsonConfigXml); |
|
89 | ||
90 | 0 | final MavenPom pom = mavenConfig.getPom(); |
91 | ||
92 | 0 | if (pom.isScmInfoProvided()) |
93 | { |
|
94 | 0 | final ScmType scmType = pom.getScmType(); |
95 | 0 | final String scmUrl = pom.getScmUrl(); |
96 | ||
97 | 0 | final HudsonConfigEntry entry = new HudsonConfigEntry(hudsonConfigXml); |
98 | 0 | entry.addScmConfig(scmType, scmUrl); |
99 | ||
100 | 0 | if (loaderConfig.isAddScmElementWithFullContent()) |
101 | { |
|
102 | 0 | element.addScmConfig(scmType, scmUrl); |
103 | } |
|
104 | } |
|
105 | 0 | } |
106 | ||
107 | void addProjectInfo(final Document hudsonConfigXml) throws JDOMException |
|
108 | { |
|
109 | 0 | final Element rootModule = new Element("rootModule"); |
110 | 0 | final Element groupId = new Element("groupId"); |
111 | 0 | final Element artifactId = new Element("artifactId"); |
112 | ||
113 | 0 | final MavenPom pom = mavenConfig.getPom(); |
114 | 0 | groupId.addContent(pom.getGroupId()); |
115 | 0 | artifactId.addContent(pom.getArtifactId()); |
116 | ||
117 | 0 | rootModule.addContent(groupId); |
118 | 0 | rootModule.addContent(artifactId); |
119 | ||
120 | 0 | final Element authToken = new Element("authToken"); |
121 | 0 | final String authTokenString = createAuthToken(); |
122 | 0 | authToken.addContent(authTokenString); |
123 | ||
124 | 0 | final Element root = hudsonConfigXml.getRootElement(); |
125 | 0 | root.addContent(authToken); |
126 | 0 | root.addContent(rootModule); |
127 | 0 | } |
128 | ||
129 | private String createAuthToken() |
|
130 | { |
|
131 | 0 | final MavenPom pom = mavenConfig.getPom(); |
132 | 0 | final String artifactId = pom.getArtifactId(); |
133 | 0 | final String planId = plan.getId(); |
134 | 0 | final String authToken = artifactId + '-' + planId; |
135 | 0 | return authToken; |
136 | } |
|
137 | ||
138 | void addProjectDescription(final Document hudsonConfigXml) |
|
139 | throws JDOMException |
|
140 | { |
|
141 | 0 | final Element description = new Element("description"); |
142 | ||
143 | 0 | final MavenPom pom = mavenConfig.getPom(); |
144 | 0 | description.addContent(pom.getDescription()); |
145 | ||
146 | 0 | hudsonConfigXml.getRootElement().addContent(description); |
147 | 0 | } |
148 | ||
149 | // --- object basics -------------------------------------------------------- |
|
150 | ||
151 | } |