1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.internal.maven; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
import java.util.regex.Pattern; |
24 |
|
|
25 |
|
import org.apache.commons.lang3.StringUtils; |
26 |
|
import org.apache.maven.model.Model; |
27 |
|
import org.apache.maven.model.Parent; |
28 |
|
import org.xwiki.extension.DefaultExtensionScmConnection; |
29 |
|
import org.xwiki.extension.ExtensionScmConnection; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@version |
35 |
|
@since |
36 |
|
|
|
|
| 91.7% |
Uncovered Elements: 9 (109) |
Complexity: 30 |
Complexity Density: 0.49 |
|
37 |
|
public class MavenUtils |
38 |
|
{ |
39 |
|
public static final String PKEY_MAVEN_MODEL = "maven.Model"; |
40 |
|
|
41 |
|
public static final String JAR_EXTENSION = "jar"; |
42 |
|
|
43 |
|
public static final String JAVA_LANGUAGE = "java"; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final String MAVENPACKAGE = "META-INF.maven"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public static final String SNAPSHOTSUFFIX = "-SNAPSHOT"; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public static final Pattern PARSER_ID = Pattern.compile("([^: ]+):([^: ]+)(:([^: ]+))?"); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
public static final String MF_EXTENSION_ID = "XWiki-Extension-Id"; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
public static final String UNKNOWN = "unknown"; |
69 |
|
|
70 |
|
|
71 |
|
@link |
72 |
|
|
73 |
|
@param |
74 |
|
@return@link |
75 |
|
|
|
|
| 95% |
Uncovered Elements: 1 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
76 |
31264 |
public static ExtensionScmConnection toExtensionScmConnection(String connectionURL)... |
77 |
|
{ |
78 |
31264 |
if (connectionURL == null) { |
79 |
2773 |
return null; |
80 |
|
} |
81 |
|
|
82 |
28491 |
String path = connectionURL; |
83 |
|
|
84 |
28491 |
if (path.startsWith("scm:")) { |
85 |
27916 |
path = path.substring("scm:".length()); |
86 |
|
} |
87 |
|
|
88 |
28491 |
String system = "git"; |
89 |
28491 |
int index = path.indexOf(':'); |
90 |
28491 |
if (index >= 0) { |
91 |
28458 |
if (index != 0) { |
92 |
28458 |
system = path.substring(0, index); |
93 |
|
} |
94 |
28458 |
path = path.substring(index + 1); |
95 |
|
} |
96 |
|
|
97 |
28491 |
return new DefaultExtensionScmConnection(system, path); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
@param |
105 |
|
@param |
106 |
|
@return |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
108 |
722474 |
public static String toExtensionId(String groupId, String artifactId, String classifier)... |
109 |
|
{ |
110 |
722474 |
StringBuilder builder = new StringBuilder(); |
111 |
|
|
112 |
722474 |
builder.append(groupId); |
113 |
722474 |
builder.append(':'); |
114 |
722474 |
builder.append(artifactId); |
115 |
722474 |
if (StringUtils.isNotEmpty(classifier)) { |
116 |
6801 |
builder.append(':'); |
117 |
6801 |
builder.append(classifier); |
118 |
|
} |
119 |
|
|
120 |
722474 |
return builder.toString(); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
@return |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
129 |
26406 |
public static String packagingToType(String packaging)... |
130 |
|
{ |
131 |
|
|
132 |
26406 |
if (packaging.equals("bundle")) { |
133 |
1855 |
return "jar"; |
134 |
|
} |
135 |
|
|
136 |
24551 |
return packaging; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@return |
142 |
|
@since |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
35305 |
public static String resolveVersion(Model mavenModel)... |
145 |
|
{ |
146 |
35305 |
return resolveVersion(mavenModel.getVersion(), mavenModel, false); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
@param |
151 |
|
@param |
152 |
|
@param |
153 |
|
@return |
154 |
|
@since |
155 |
|
|
|
|
| 96.7% |
Uncovered Elements: 1 (30) |
Complexity: 10 |
Complexity Density: 0.62 |
|
156 |
769671 |
public static String resolveVersion(String modelVersion, Model mavenModel, boolean dependency)... |
157 |
|
{ |
158 |
769671 |
String version = modelVersion; |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
769671 |
if (version == null) { |
163 |
17223 |
if (!dependency) { |
164 |
7870 |
Parent parent = mavenModel.getParent(); |
165 |
|
|
166 |
7870 |
if (parent != null) { |
167 |
7870 |
version = parent.getVersion(); |
168 |
|
} |
169 |
|
} |
170 |
752448 |
} else if (version.startsWith("$")) { |
171 |
18358 |
String propertyName = version.substring(2, version.length() - 1); |
172 |
|
|
173 |
18358 |
if (propertyName.equals("project.version") || propertyName.equals("pom.version") |
174 |
|
|| propertyName.equals("version")) { |
175 |
11947 |
version = resolveVersion(mavenModel.getVersion(), mavenModel, false); |
176 |
|
} else { |
177 |
6411 |
String value = mavenModel.getProperties().getProperty(propertyName); |
178 |
6411 |
if (value != null) { |
179 |
1072 |
version = value; |
180 |
|
} |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
769671 |
if (version == null) { |
185 |
9353 |
version = UNKNOWN; |
186 |
|
} |
187 |
|
|
188 |
769671 |
return version; |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
@param |
193 |
|
@return |
194 |
|
@since |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
35305 |
public static String resolveGroupId(Model mavenModel)... |
197 |
|
{ |
198 |
35305 |
return resolveGroupId(mavenModel.getGroupId(), mavenModel, false); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
@param |
203 |
|
@param |
204 |
|
@param |
205 |
|
@return |
206 |
|
@since |
207 |
|
|
|
|
| 76.9% |
Uncovered Elements: 6 (26) |
Complexity: 7 |
Complexity Density: 0.5 |
|
208 |
757724 |
public static String resolveGroupId(String modelGroupId, Model mavenModel, boolean dependency)... |
209 |
|
{ |
210 |
757724 |
String groupId = modelGroupId; |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
757724 |
if (groupId == null) { |
215 |
7860 |
if (!dependency) { |
216 |
7860 |
Parent parent = mavenModel.getParent(); |
217 |
|
|
218 |
7860 |
if (parent != null) { |
219 |
7860 |
groupId = parent.getGroupId(); |
220 |
|
} |
221 |
|
} |
222 |
749864 |
} else if (groupId.startsWith("$")) { |
223 |
210 |
String propertyName = groupId.substring(2, groupId.length() - 1); |
224 |
|
|
225 |
210 |
String value = mavenModel.getProperties().getProperty(propertyName); |
226 |
210 |
if (value != null) { |
227 |
0 |
groupId = value; |
228 |
|
} |
229 |
|
} |
230 |
|
|
231 |
757724 |
if (groupId == null) { |
232 |
0 |
groupId = UNKNOWN; |
233 |
|
} |
234 |
|
|
235 |
757724 |
return groupId; |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
@param |
240 |
|
|
241 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
242 |
10899 |
public static void resolveVariables(Model model)... |
243 |
|
{ |
244 |
|
|
245 |
10899 |
model.setVersion(resolveVersion(model)); |
246 |
|
|
247 |
|
|
248 |
10899 |
model.setGroupId(resolveGroupId(model)); |
249 |
|
|
250 |
|
|
251 |
10899 |
for (Map.Entry<Object, Object> entry : model.getProperties().entrySet()) { |
252 |
24005 |
if (entry.getValue() instanceof String) { |
253 |
24005 |
String value = (String) entry.getValue(); |
254 |
24005 |
entry.setValue(value.replace("${project.version}", model.getVersion())); |
255 |
|
} |
256 |
|
} |
257 |
|
} |
258 |
|
} |