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; |
21 |
|
|
22 |
|
import java.io.StreamTokenizer; |
23 |
|
import java.io.StringReader; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Collections; |
28 |
|
import java.util.HashMap; |
29 |
|
import java.util.List; |
30 |
|
import java.util.Map; |
31 |
|
|
32 |
|
import org.apache.commons.lang3.StringUtils; |
33 |
|
import org.xwiki.extension.CoreExtension; |
34 |
|
import org.xwiki.extension.Extension; |
35 |
|
import org.xwiki.extension.ExtensionDependency; |
36 |
|
import org.xwiki.extension.InstalledExtension; |
37 |
|
import org.xwiki.extension.LocalExtension; |
38 |
|
import org.xwiki.extension.MutableExtension; |
39 |
|
import org.xwiki.extension.RemoteExtension; |
40 |
|
import org.xwiki.extension.rating.RatingExtension; |
41 |
|
import org.xwiki.extension.wrap.WrappingCoreExtension; |
42 |
|
import org.xwiki.extension.wrap.WrappingExtension; |
43 |
|
import org.xwiki.extension.wrap.WrappingInstalledExtension; |
44 |
|
import org.xwiki.extension.wrap.WrappingLocalExtension; |
45 |
|
import org.xwiki.extension.wrap.WrappingRatingExtension; |
46 |
|
import org.xwiki.extension.wrap.WrappingRemoteExtension; |
47 |
|
import org.xwiki.properties.converter.ConversionException; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@version |
53 |
|
@since |
54 |
|
|
|
|
| 71.4% |
Uncovered Elements: 28 (98) |
Complexity: 27 |
Complexity Density: 0.47 |
|
55 |
|
public final class ExtensionUtils |
56 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
57 |
0 |
private ExtensionUtils()... |
58 |
|
{ |
59 |
|
|
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
@param |
65 |
|
@param |
66 |
|
@return |
67 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 5 |
Complexity Density: 0.83 |
|
68 |
1107 |
public static ExtensionDependency getDependency(ExtensionDependency dependency,... |
69 |
|
Map<String, ExtensionDependency> managedDependencies, Extension extension) |
70 |
|
{ |
71 |
1107 |
ExtensionDependency managedDependency = managedDependencies.get(dependency.getId()); |
72 |
|
|
73 |
|
|
74 |
1107 |
if (managedDependency == null && dependency.getVersionConstraint() == null) { |
75 |
1 |
for (ExtensionDependency extensionManagedDependency : extension.getManagedDependencies()) { |
76 |
1 |
if (extensionManagedDependency.getId().equals(dependency.getId())) { |
77 |
1 |
managedDependency = extensionManagedDependency; |
78 |
|
} |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
1107 |
return managedDependency != null ? managedDependency : dependency; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
@param |
88 |
|
@return |
89 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
90 |
1107 |
public static Map<String, ExtensionDependency> append(Map<String, ExtensionDependency> managedDependencies,... |
91 |
|
Extension extension) |
92 |
|
{ |
93 |
1107 |
Map<String, ExtensionDependency> newManagedDependencies = |
94 |
1107 |
managedDependencies != null ? new HashMap<>(managedDependencies) : new HashMap<>(); |
95 |
|
|
96 |
1107 |
for (ExtensionDependency dependency : extension.getManagedDependencies()) { |
97 |
1567 |
newManagedDependencies.put(dependency.getId(), dependency); |
98 |
|
} |
99 |
|
|
100 |
1107 |
return newManagedDependencies; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
@param |
108 |
|
@param |
109 |
|
@return |
110 |
|
@since |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
267 |
public static <T> T importProperty(MutableExtension extension, String propertySuffix)... |
113 |
|
{ |
114 |
267 |
return extension.removeProperty(Extension.IKEYPREFIX + propertySuffix); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
@param |
122 |
|
@param |
123 |
|
@return |
124 |
|
@since |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
199 |
public static String importProperty(MutableExtension extension, String propertySuffix, String def)... |
127 |
|
{ |
128 |
199 |
return StringUtils.defaultString(importProperty(extension, propertySuffix), def); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
@param |
136 |
|
@param |
137 |
|
@return |
138 |
|
@since |
139 |
|
|
|
|
| 28.6% |
Uncovered Elements: 10 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
140 |
66 |
public static Collection<String> importProperty(MutableExtension extension, String propertySuffix,... |
141 |
|
Collection<String> def) |
142 |
|
{ |
143 |
66 |
Object obj = importProperty(extension, propertySuffix); |
144 |
|
|
145 |
66 |
if (obj == null) { |
146 |
67 |
return def; |
147 |
0 |
} else if (obj instanceof Collection) { |
148 |
0 |
return (Collection) obj; |
149 |
0 |
} else if (obj instanceof String[]) { |
150 |
0 |
return Arrays.asList((String[]) obj); |
151 |
|
} else { |
152 |
0 |
return importPropertyStringList(obj.toString(), true); |
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
@param |
158 |
|
@param |
159 |
|
@return |
160 |
|
@since |
161 |
|
|
|
|
| 84.8% |
Uncovered Elements: 5 (33) |
Complexity: 7 |
Complexity Density: 0.28 |
|
162 |
995 |
public static List<String> importPropertyStringList(String str, boolean trim)... |
163 |
|
{ |
164 |
995 |
try { |
165 |
995 |
String cleanedString = str; |
166 |
|
|
167 |
|
|
168 |
995 |
if (trim) { |
169 |
995 |
cleanedString = cleanedString.trim(); |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
995 |
StreamTokenizer st = new StreamTokenizer(new StringReader(cleanedString)); |
174 |
|
|
175 |
|
|
176 |
995 |
st.ordinaryChars(0, 255); |
177 |
995 |
st.wordChars(0, 255); |
178 |
|
|
179 |
|
|
180 |
995 |
st.quoteChar('"'); |
181 |
995 |
st.quoteChar('\''); |
182 |
|
|
183 |
|
|
184 |
995 |
st.whitespaceChars(',', ','); |
185 |
995 |
st.whitespaceChars(' ', ' '); |
186 |
995 |
st.whitespaceChars('\t', '\t'); |
187 |
995 |
st.whitespaceChars('\n', '\n'); |
188 |
995 |
st.whitespaceChars('\r', '\r'); |
189 |
|
|
190 |
|
|
191 |
995 |
List<String> collection = new ArrayList<>(); |
192 |
995 |
while (true) { |
193 |
2109 |
int ttype = st.nextToken(); |
194 |
2109 |
if (ttype == StreamTokenizer.TT_WORD || ttype > 0) { |
195 |
1114 |
if (st.sval != null) { |
196 |
1114 |
collection.add(st.sval); |
197 |
|
} |
198 |
995 |
} else if (ttype == StreamTokenizer.TT_EOF) { |
199 |
995 |
break; |
200 |
|
} else { |
201 |
0 |
throw new ConversionException("Encountered token of type " + ttype + " parsing elements."); |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
995 |
return collection; |
207 |
|
} catch (Exception e) { |
208 |
|
|
209 |
|
} |
210 |
|
|
211 |
0 |
return Collections.emptyList(); |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
@param |
216 |
|
@param |
217 |
|
@return |
218 |
|
@since |
219 |
|
@since |
220 |
|
|
|
|
| 56.5% |
Uncovered Elements: 10 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
221 |
1 |
public static <T extends Extension> WrappingExtension<T> wrap(Extension extension)... |
222 |
|
{ |
223 |
1 |
WrappingExtension<?> wrapper; |
224 |
|
|
225 |
1 |
if (extension instanceof CoreExtension) { |
226 |
0 |
wrapper = new WrappingCoreExtension<>((CoreExtension) extension); |
227 |
1 |
} else if (extension instanceof InstalledExtension) { |
228 |
0 |
wrapper = new WrappingInstalledExtension<>((InstalledExtension) extension); |
229 |
1 |
} else if (extension instanceof LocalExtension) { |
230 |
0 |
wrapper = new WrappingLocalExtension<>((LocalExtension) extension); |
231 |
1 |
} else if (extension instanceof RatingExtension) { |
232 |
0 |
wrapper = new WrappingRatingExtension<>((RatingExtension) extension); |
233 |
1 |
} else if (extension instanceof RemoteExtension) { |
234 |
0 |
wrapper = new WrappingRemoteExtension<>((RemoteExtension) extension); |
235 |
|
} else { |
236 |
1 |
wrapper = new WrappingExtension<>(extension); |
237 |
|
} |
238 |
|
|
239 |
1 |
return (WrappingExtension<T>) wrapper; |
240 |
|
} |
241 |
|
} |