1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.internal.installed; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.Date; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.HashSet; |
28 |
|
import java.util.Map; |
29 |
|
import java.util.Set; |
30 |
|
import java.util.concurrent.ConcurrentHashMap; |
31 |
|
|
32 |
|
import javax.inject.Inject; |
33 |
|
import javax.inject.Singleton; |
34 |
|
|
35 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
36 |
|
import org.slf4j.Logger; |
37 |
|
import org.xwiki.component.annotation.Component; |
38 |
|
import org.xwiki.component.phase.Initializable; |
39 |
|
import org.xwiki.component.phase.InitializationException; |
40 |
|
import org.xwiki.extension.CoreExtension; |
41 |
|
import org.xwiki.extension.ExtensionDependency; |
42 |
|
import org.xwiki.extension.ExtensionId; |
43 |
|
import org.xwiki.extension.InstallException; |
44 |
|
import org.xwiki.extension.InstalledExtension; |
45 |
|
import org.xwiki.extension.InvalidExtensionException; |
46 |
|
import org.xwiki.extension.LocalExtension; |
47 |
|
import org.xwiki.extension.ResolveException; |
48 |
|
import org.xwiki.extension.UninstallException; |
49 |
|
import org.xwiki.extension.internal.ExtensionUtils; |
50 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
51 |
|
import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor; |
52 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
53 |
|
import org.xwiki.extension.repository.LocalExtensionRepository; |
54 |
|
import org.xwiki.extension.version.Version; |
55 |
|
import org.xwiki.extension.version.VersionConstraint; |
56 |
|
|
57 |
|
|
58 |
|
@link |
59 |
|
|
60 |
|
@version |
61 |
|
@since |
62 |
|
|
63 |
|
@Component |
64 |
|
@Singleton |
|
|
| 91.3% |
Uncovered Elements: 33 (381) |
Complexity: 107 |
Complexity Density: 0.46 |
|
65 |
|
public class DefaultInstalledExtensionRepository extends AbstractInstalledExtensionRepository<DefaultInstalledExtension> |
66 |
|
implements InstalledExtensionRepository, Initializable |
67 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
|
private static class InstalledRootFeature |
69 |
|
{ |
70 |
|
public DefaultInstalledExtension extension; |
71 |
|
|
72 |
|
public Set<DefaultInstalledExtension> invalidExtensions = new HashSet<DefaultInstalledExtension>(); |
73 |
|
|
74 |
|
public String namespace; |
75 |
|
|
76 |
|
public Set<DefaultInstalledExtension> backwardDependencies = new HashSet<DefaultInstalledExtension>(); |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
1873 |
public InstalledRootFeature(String namespace)... |
79 |
|
{ |
80 |
1873 |
this.namespace = namespace; |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
84 |
|
private static class InstalledFeature |
85 |
|
{ |
86 |
|
public InstalledRootFeature root; |
87 |
|
|
88 |
|
public ExtensionId feature; |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
90 |
2197 |
public InstalledFeature(InstalledRootFeature root, ExtensionId feature)... |
91 |
|
{ |
92 |
2197 |
this.root = root; |
93 |
2197 |
this.feature = feature; |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@Inject |
101 |
|
private transient LocalExtensionRepository localRepository; |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@Inject |
107 |
|
private transient CoreExtensionRepository coreExtensionRepository; |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@Inject |
113 |
|
private transient Logger logger; |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
private Map<String, Map<String, InstalledFeature>> extensionNamespaceByFeature = |
121 |
|
new ConcurrentHashMap<String, Map<String, InstalledFeature>>(); |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
private Map<String, Map<String, Set<LocalExtension>>> localInstalledExtensionsCache; |
129 |
|
|
130 |
|
private boolean updateBackwardDependencies; |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
132 |
231 |
@Override... |
133 |
|
public void initialize() throws InitializationException |
134 |
|
{ |
135 |
231 |
setDescriptor(new DefaultExtensionRepositoryDescriptor("installed", "installed", |
136 |
|
this.localRepository.getDescriptor().getURI())); |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
231 |
this.updateBackwardDependencies = false; |
141 |
|
|
142 |
|
|
143 |
231 |
this.localInstalledExtensionsCache = new HashMap<>(); |
144 |
231 |
for (LocalExtension localExtension : this.localRepository.getLocalExtensions()) { |
145 |
1338 |
if (DefaultInstalledExtension.isInstalled(localExtension)) { |
146 |
1337 |
getInstalledLocalExtension(localExtension); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
231 |
validate(); |
152 |
|
|
153 |
|
|
154 |
231 |
updateMissingBackwardDependencies(); |
155 |
|
|
156 |
|
|
157 |
231 |
this.updateBackwardDependencies = true; |
158 |
|
|
159 |
|
|
160 |
231 |
this.localInstalledExtensionsCache = null; |
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
163 |
231 |
private void validate()... |
164 |
|
{ |
165 |
|
|
166 |
231 |
for (LocalExtension localExtension : this.localRepository.getLocalExtensions()) { |
167 |
1338 |
if (DefaultInstalledExtension.isInstalled(localExtension)) { |
168 |
1337 |
validateExtension(localExtension, false); |
169 |
|
} |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
231 |
for (LocalExtension localExtension : this.localRepository.getLocalExtensions()) { |
174 |
1338 |
if (DefaultInstalledExtension.isInstalled(localExtension)) { |
175 |
1337 |
validateExtension(localExtension, true); |
176 |
|
} |
177 |
|
} |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
180 |
1337 |
private void getInstalledLocalExtension(LocalExtension localExtension)... |
181 |
|
{ |
182 |
1337 |
getInstalledLocalExtension(localExtension.getId().getId(), localExtension); |
183 |
|
|
184 |
1337 |
for (ExtensionId feature : localExtension.getExtensionFeatures()) { |
185 |
320 |
getInstalledLocalExtension(feature.getId(), localExtension); |
186 |
|
} |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
189 |
1657 |
private void getInstalledLocalExtension(String feature, LocalExtension localExtension)... |
190 |
|
{ |
191 |
1657 |
Collection<String> namespaces = DefaultInstalledExtension.getNamespaces(localExtension); |
192 |
|
|
193 |
1657 |
if (namespaces == null) { |
194 |
1041 |
getInstalledLocalExtension(feature, null, localExtension); |
195 |
|
} else { |
196 |
616 |
for (String namespace : namespaces) { |
197 |
776 |
getInstalledLocalExtension(feature, namespace, localExtension); |
198 |
|
} |
199 |
|
} |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
202 |
1817 |
private void getInstalledLocalExtension(String feature, String namespace, LocalExtension localExtension)... |
203 |
|
{ |
204 |
1817 |
Map<String, Set<LocalExtension>> localInstallExtensionFeature = this.localInstalledExtensionsCache.get(feature); |
205 |
1817 |
if (localInstallExtensionFeature == null) { |
206 |
1577 |
localInstallExtensionFeature = new HashMap<>(); |
207 |
1577 |
this.localInstalledExtensionsCache.put(feature, localInstallExtensionFeature); |
208 |
|
} |
209 |
|
|
210 |
1817 |
Set<LocalExtension> localInstallExtensionNamespace = localInstallExtensionFeature.get(namespace); |
211 |
1817 |
if (localInstallExtensionNamespace == null) { |
212 |
1737 |
localInstallExtensionNamespace = new HashSet<LocalExtension>(); |
213 |
1737 |
localInstallExtensionFeature.put(namespace, localInstallExtensionNamespace); |
214 |
|
} |
215 |
|
|
216 |
1817 |
localInstallExtensionNamespace.add(localExtension); |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@param |
225 |
|
@param |
226 |
|
@throws |
227 |
|
|
|
|
| 81.5% |
Uncovered Elements: 5 (27) |
Complexity: 10 |
Complexity Density: 0.59 |
|
228 |
2674 |
private void validateExtension(LocalExtension localExtension, boolean dependencies)... |
229 |
|
{ |
230 |
2674 |
Collection<String> namespaces = DefaultInstalledExtension.getNamespaces(localExtension); |
231 |
|
|
232 |
2674 |
if (namespaces == null) { |
233 |
1602 |
if (dependencies || !DefaultInstalledExtension.isDependency(localExtension, null)) { |
234 |
1362 |
try { |
235 |
1362 |
validateExtension(localExtension, null, Collections.emptyMap()); |
236 |
|
} catch (InvalidExtensionException e) { |
237 |
183 |
if (this.logger.isDebugEnabled()) { |
238 |
0 |
this.logger.warn("Invalid extension [{}]", localExtension.getId(), e); |
239 |
|
} else { |
240 |
183 |
this.logger.warn("Invalid extension [{}] ({})", localExtension.getId(), |
241 |
|
ExceptionUtils.getRootCauseMessage(e)); |
242 |
|
} |
243 |
|
|
244 |
183 |
addInstalledExtension(localExtension, null, false); |
245 |
|
} |
246 |
|
} |
247 |
|
} else { |
248 |
1072 |
for (String namespace : namespaces) { |
249 |
1392 |
if (dependencies || !DefaultInstalledExtension.isDependency(localExtension, namespace)) { |
250 |
1392 |
try { |
251 |
1392 |
validateExtension(localExtension, namespace, Collections.emptyMap()); |
252 |
|
} catch (InvalidExtensionException e) { |
253 |
23 |
if (this.logger.isDebugEnabled()) { |
254 |
0 |
this.logger.warn("Invalid extension [{}] on namespace [{}]", localExtension.getId(), |
255 |
|
namespace, e); |
256 |
|
} else { |
257 |
23 |
this.logger.warn("Invalid extension [{}] on namespace [{}] ({})", localExtension.getId(), |
258 |
|
namespace, ExceptionUtils.getRootCauseMessage(e)); |
259 |
|
} |
260 |
|
|
261 |
23 |
addInstalledExtension(localExtension, namespace, false); |
262 |
|
} |
263 |
|
} |
264 |
|
} |
265 |
|
} |
266 |
|
} |
267 |
|
|
|
|
| 94.4% |
Uncovered Elements: 1 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
268 |
1029 |
private LocalExtension getInstalledLocalExtension(ExtensionDependency dependency, String namespace)... |
269 |
|
{ |
270 |
1029 |
Map<String, Set<LocalExtension>> localInstallExtensionFeature = |
271 |
|
this.localInstalledExtensionsCache.get(dependency.getId()); |
272 |
|
|
273 |
1029 |
if (localInstallExtensionFeature != null) { |
274 |
800 |
Set<LocalExtension> localInstallExtensionNamespace = localInstallExtensionFeature.get(namespace); |
275 |
|
|
276 |
800 |
if (localInstallExtensionNamespace != null) { |
277 |
640 |
for (LocalExtension dependencyVersion : localInstallExtensionNamespace) { |
278 |
640 |
if (isCompatible(dependencyVersion.getId().getVersion(), dependency.getVersionConstraint())) { |
279 |
640 |
return dependencyVersion; |
280 |
|
} |
281 |
|
} |
282 |
|
} |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
389 |
if (namespace != null) { |
287 |
183 |
return getInstalledLocalExtension(dependency, null); |
288 |
|
} |
289 |
|
|
290 |
206 |
return null; |
291 |
|
} |
292 |
|
|
|
|
| 65.4% |
Uncovered Elements: 9 (26) |
Complexity: 8 |
Complexity Density: 0.57 |
|
293 |
1001 |
private void validateDependency(ExtensionDependency dependency, String namespace,... |
294 |
|
Map<String, ExtensionDependency> managedDependencies) throws InvalidExtensionException |
295 |
|
{ |
296 |
1001 |
CoreExtension coreExtension = this.coreExtensionRepository.getCoreExtension(dependency.getId()); |
297 |
|
|
298 |
1001 |
if (coreExtension != null) { |
299 |
97 |
if (!isCompatible(coreExtension.getId().getVersion(), dependency.getVersionConstraint())) { |
300 |
0 |
throw new InvalidExtensionException(String |
301 |
|
.format("Dependency [%s] is incompatible with the core extension [%s]", dependency, coreExtension)); |
302 |
|
} |
303 |
|
} else { |
304 |
904 |
LocalExtension dependencyExtension = |
305 |
904 |
this.localInstalledExtensionsCache != null ? getInstalledLocalExtension(dependency, namespace) |
306 |
|
: getInstalledExtension(dependency.getId(), namespace); |
307 |
|
|
308 |
904 |
if (dependencyExtension == null) { |
309 |
207 |
throw new InvalidExtensionException( |
310 |
|
String.format("No compatible extension is installed for dependency [%s]", dependency)); |
311 |
|
} else { |
312 |
697 |
try { |
313 |
697 |
DefaultInstalledExtension installedExtension = |
314 |
|
validateExtension(dependencyExtension, namespace, managedDependencies); |
315 |
|
|
316 |
697 |
if (!installedExtension.isValid(namespace)) { |
317 |
0 |
throw new InvalidExtensionException( |
318 |
|
String.format("Extension dependency [%s] is invalid", installedExtension.getId())); |
319 |
|
} |
320 |
|
} catch (InvalidExtensionException e) { |
321 |
0 |
if (this.localInstalledExtensionsCache != null) { |
322 |
0 |
addInstalledExtension(dependencyExtension, namespace, false); |
323 |
|
} |
324 |
|
|
325 |
0 |
throw e; |
326 |
|
} |
327 |
|
} |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
@param |
335 |
|
@param |
336 |
|
@param |
337 |
|
@return@link |
338 |
|
@throws |
339 |
|
|
|
|
| 84.8% |
Uncovered Elements: 5 (33) |
Complexity: 11 |
Complexity Density: 0.58 |
|
340 |
3824 |
private DefaultInstalledExtension validateExtension(LocalExtension localExtension, String namespace,... |
341 |
|
Map<String, ExtensionDependency> managedDependencies) throws InvalidExtensionException |
342 |
|
{ |
343 |
3824 |
DefaultInstalledExtension installedExtension = this.extensions.get(localExtension.getId()); |
344 |
3824 |
if (installedExtension != null && installedExtension.isValidated(namespace)) { |
345 |
|
|
346 |
1979 |
return installedExtension; |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
1845 |
if (namespace != null && DefaultInstalledExtension.getNamespaces(localExtension) == null) { |
352 |
|
|
353 |
|
|
354 |
168 |
return validateExtension(localExtension, null, managedDependencies); |
355 |
|
} |
356 |
|
|
357 |
1677 |
if (!DefaultInstalledExtension.isInstalled(localExtension, namespace)) { |
358 |
0 |
throw new InvalidExtensionException(String.format("Extension [%s] is not installed", localExtension)); |
359 |
|
} |
360 |
|
|
361 |
1677 |
if (this.coreExtensionRepository.exists(localExtension.getId().getId())) { |
362 |
0 |
throw new InvalidExtensionException( |
363 |
|
String.format("Extension [%s] already exists as a core extension", localExtension)); |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
1677 |
InvalidExtensionException dependencyException = null; |
368 |
1677 |
for (ExtensionDependency dependency : localExtension.getDependencies()) { |
369 |
1001 |
try { |
370 |
|
|
371 |
1001 |
dependency = ExtensionUtils.getDependency(dependency, managedDependencies, localExtension); |
372 |
|
|
373 |
1001 |
validateDependency(dependency, namespace, ExtensionUtils.append(managedDependencies, localExtension)); |
374 |
|
} catch (InvalidExtensionException e) { |
375 |
|
|
376 |
207 |
if (dependencyException == null) { |
377 |
207 |
dependencyException = e; |
378 |
|
} |
379 |
|
} |
380 |
|
} |
381 |
|
|
382 |
|
|
383 |
1677 |
if (dependencyException != null) { |
384 |
207 |
throw dependencyException; |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
1470 |
return localExtension instanceof DefaultInstalledExtension ? (DefaultInstalledExtension) localExtension |
389 |
|
: addInstalledExtension(localExtension, namespace, true); |
390 |
|
} |
391 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
392 |
205 |
private boolean isValid(DefaultInstalledExtension installedExtension, String namespace,... |
393 |
|
Map<String, ExtensionDependency> managedDependencies) |
394 |
|
{ |
395 |
205 |
try { |
396 |
205 |
validateExtension(installedExtension, namespace, managedDependencies); |
397 |
|
|
398 |
204 |
return true; |
399 |
|
} catch (InvalidExtensionException e) { |
400 |
1 |
this.logger.debug("Invalid extension [{}] on namespace [{}]", installedExtension.getId(), namespace, e); |
401 |
|
} |
402 |
|
|
403 |
1 |
return false; |
404 |
|
} |
405 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
406 |
737 |
private boolean isCompatible(Version existingVersion, VersionConstraint versionConstraint)... |
407 |
|
{ |
408 |
737 |
boolean compatible = true; |
409 |
|
|
410 |
737 |
if (versionConstraint.getVersion() == null) { |
411 |
2 |
compatible = versionConstraint.containsVersion(existingVersion); |
412 |
|
} else { |
413 |
735 |
compatible = existingVersion.compareTo(versionConstraint.getVersion()) >= 0; |
414 |
|
} |
415 |
|
|
416 |
737 |
return compatible; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
|
@param |
425 |
|
@param |
426 |
|
@see |
427 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
428 |
120 |
private void removeInstalledExtension(DefaultInstalledExtension installedExtension, String namespace)... |
429 |
|
{ |
430 |
120 |
removeInstalledFeature(installedExtension.getId().getId(), namespace); |
431 |
|
|
432 |
120 |
for (ExtensionId feature : installedExtension.getExtensionFeatures()) { |
433 |
61 |
removeInstalledFeature(feature.getId(), namespace); |
434 |
|
} |
435 |
|
|
436 |
120 |
removeFromBackwardDependencies(installedExtension, namespace); |
437 |
|
|
438 |
120 |
if (!installedExtension.isInstalled()) { |
439 |
104 |
removeCachedExtension(installedExtension); |
440 |
|
} |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
@param |
447 |
|
@param |
448 |
|
@see |
449 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
450 |
181 |
private void removeInstalledFeature(String feature, String namespace)... |
451 |
|
{ |
452 |
|
|
453 |
|
|
454 |
181 |
if (namespace == null) { |
455 |
66 |
this.extensionNamespaceByFeature.remove(feature); |
456 |
|
} else { |
457 |
115 |
Map<String, InstalledFeature> namespaceInstalledExtension = this.extensionNamespaceByFeature.get(feature); |
458 |
|
|
459 |
115 |
namespaceInstalledExtension.remove(namespace); |
460 |
|
} |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
@param |
467 |
|
@param |
468 |
|
@param |
469 |
|
@param |
470 |
|
@param |
471 |
|
@throws |
472 |
|
@see |
473 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
474 |
205 |
private void applyInstallExtension(DefaultInstalledExtension installedExtension, String namespace,... |
475 |
|
boolean dependency, Map<String, Object> properties, Map<String, ExtensionDependency> managedDependencies) |
476 |
|
throws InstallException |
477 |
|
{ |
478 |
|
|
479 |
205 |
installedExtension.setInstalled(true, namespace); |
480 |
205 |
installedExtension.setInstallDate(new Date(), namespace); |
481 |
|
|
482 |
|
|
483 |
205 |
installedExtension.setDependency(dependency, namespace); |
484 |
|
|
485 |
|
|
486 |
|
|
487 |
205 |
installedExtension.getNamespaceProperties(namespace).putAll(properties); |
488 |
|
|
489 |
|
|
490 |
205 |
try { |
491 |
205 |
this.localRepository.setProperties(installedExtension.getLocalExtension(), |
492 |
|
installedExtension.getProperties()); |
493 |
|
} catch (Exception e) { |
494 |
0 |
throw new InstallException("Failed to modify extension descriptor", e); |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
205 |
installedExtension.setValid(namespace, isValid(installedExtension, namespace, managedDependencies)); |
499 |
|
|
500 |
|
|
501 |
|
|
502 |
205 |
addInstalledExtension(installedExtension, namespace); |
503 |
|
} |
504 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
505 |
120 |
private void removeFromBackwardDependencies(DefaultInstalledExtension installedExtension, String namespace)... |
506 |
|
{ |
507 |
|
|
508 |
120 |
for (ExtensionDependency dependency : installedExtension.getDependencies()) { |
509 |
94 |
if (this.coreExtensionRepository.getCoreExtension(dependency.getId()) == null) { |
510 |
62 |
InstalledFeature installedFeature = getInstalledFeatureFromCache(dependency.getId(), namespace); |
511 |
|
|
512 |
62 |
if (installedFeature != null) { |
513 |
57 |
installedFeature.root.backwardDependencies.remove(installedExtension); |
514 |
|
} |
515 |
|
} |
516 |
|
} |
517 |
|
} |
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
@param |
523 |
|
@param |
524 |
|
@param |
525 |
|
@return@link |
526 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
527 |
1497 |
private DefaultInstalledExtension addInstalledExtension(LocalExtension localExtension, String namespace,... |
528 |
|
boolean valid) |
529 |
|
{ |
530 |
1497 |
DefaultInstalledExtension installedExtension = this.extensions.get(localExtension.getId()); |
531 |
1497 |
if (installedExtension == null) { |
532 |
1337 |
installedExtension = new DefaultInstalledExtension(localExtension, this); |
533 |
|
} |
534 |
|
|
535 |
1497 |
installedExtension.setInstalled(true, namespace); |
536 |
1497 |
installedExtension.setValid(namespace, valid); |
537 |
|
|
538 |
1497 |
addInstalledExtension(installedExtension, namespace); |
539 |
|
|
540 |
1497 |
return installedExtension; |
541 |
|
} |
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
|
546 |
|
@param |
547 |
|
@param |
548 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
549 |
1702 |
private void addInstalledExtension(DefaultInstalledExtension installedExtension, String namespace)... |
550 |
|
{ |
551 |
1702 |
addCachedExtension(installedExtension); |
552 |
|
|
553 |
1702 |
boolean isValid = installedExtension.isValid(namespace); |
554 |
|
|
555 |
|
|
556 |
1702 |
addInstalledFeatureToCache(installedExtension.getId(), namespace, installedExtension, isValid); |
557 |
|
|
558 |
|
|
559 |
1702 |
for (ExtensionId feature : installedExtension.getExtensionFeatures()) { |
560 |
404 |
addInstalledFeatureToCache(feature, namespace, installedExtension, isValid); |
561 |
|
} |
562 |
|
|
563 |
1702 |
if (this.updateBackwardDependencies) { |
564 |
|
|
565 |
205 |
updateMissingBackwardDependencies(); |
566 |
|
} |
567 |
|
} |
568 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
569 |
436 |
private void updateMissingBackwardDependencies()... |
570 |
|
{ |
571 |
436 |
for (DefaultInstalledExtension installedExtension : this.extensions.values()) { |
572 |
2925 |
updateMissingBackwardDependencies(installedExtension); |
573 |
|
} |
574 |
|
} |
575 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
576 |
2925 |
private void updateMissingBackwardDependencies(DefaultInstalledExtension installedExtension)... |
577 |
|
{ |
578 |
2925 |
Collection<String> namespaces = installedExtension.getNamespaces(); |
579 |
|
|
580 |
2925 |
if (namespaces == null) { |
581 |
1660 |
if (installedExtension.isValid(null)) { |
582 |
1280 |
updateMissingBackwardDependencies(installedExtension, null); |
583 |
|
} |
584 |
|
} else { |
585 |
1265 |
for (String namespace : namespaces) { |
586 |
1604 |
if (installedExtension.isValid(namespace)) { |
587 |
1527 |
updateMissingBackwardDependencies(installedExtension, namespace); |
588 |
|
} |
589 |
|
} |
590 |
|
} |
591 |
|
} |
592 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
593 |
2807 |
private void updateMissingBackwardDependencies(DefaultInstalledExtension installedExtension, String namespace)... |
594 |
|
{ |
595 |
|
|
596 |
2807 |
for (ExtensionDependency dependency : installedExtension.getDependencies()) { |
597 |
1475 |
if (!this.coreExtensionRepository.exists(dependency.getId())) { |
598 |
|
|
599 |
1274 |
DefaultInstalledExtension dependencyLocalExtension = |
600 |
|
(DefaultInstalledExtension) getInstalledExtension(dependency.getId(), namespace); |
601 |
|
|
602 |
1274 |
if (dependencyLocalExtension != null) { |
603 |
1264 |
ExtensionId feature = dependencyLocalExtension.getExtensionFeature(dependency.getId()); |
604 |
|
|
605 |
|
|
606 |
1264 |
InstalledFeature dependencyInstalledExtension = |
607 |
|
addInstalledFeatureToCache(feature, namespace, dependencyLocalExtension, false); |
608 |
|
|
609 |
1264 |
dependencyInstalledExtension.root.backwardDependencies.add(installedExtension); |
610 |
|
} |
611 |
|
} |
612 |
|
} |
613 |
|
} |
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
@param |
621 |
|
@param |
622 |
|
@param |
623 |
|
@return |
624 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
625 |
3370 |
private InstalledFeature addInstalledFeatureToCache(ExtensionId feature, String namespace,... |
626 |
|
DefaultInstalledExtension installedExtension, boolean forceCreate) |
627 |
|
{ |
628 |
3370 |
Map<String, InstalledFeature> installedExtensionsForFeature = |
629 |
|
this.extensionNamespaceByFeature.get(feature.getId()); |
630 |
|
|
631 |
3370 |
if (installedExtensionsForFeature == null) { |
632 |
1782 |
installedExtensionsForFeature = new HashMap<String, InstalledFeature>(); |
633 |
1782 |
this.extensionNamespaceByFeature.put(feature.getId(), installedExtensionsForFeature); |
634 |
|
} |
635 |
|
|
636 |
3370 |
InstalledFeature installedFeature = installedExtensionsForFeature.get(namespace); |
637 |
3370 |
if (forceCreate || installedFeature == null) { |
638 |
|
|
639 |
2197 |
InstalledRootFeature rootInstalledFeature; |
640 |
2197 |
if (installedExtension.getId().getId().equals(feature.getId())) { |
641 |
1873 |
rootInstalledFeature = new InstalledRootFeature(namespace); |
642 |
|
} else { |
643 |
324 |
rootInstalledFeature = getInstalledFeatureFromCache(installedExtension.getId().getId(), namespace).root; |
644 |
|
} |
645 |
|
|
646 |
|
|
647 |
2197 |
installedFeature = new InstalledFeature(rootInstalledFeature, feature); |
648 |
|
|
649 |
|
|
650 |
2197 |
installedExtensionsForFeature.put(namespace, installedFeature); |
651 |
|
} |
652 |
|
|
653 |
3370 |
if (installedExtension.isValid(namespace)) { |
654 |
3083 |
installedFeature.root.extension = installedExtension; |
655 |
|
} else { |
656 |
287 |
installedFeature.root.invalidExtensions.add(installedExtension); |
657 |
|
} |
658 |
|
|
659 |
3370 |
return installedFeature; |
660 |
|
} |
661 |
|
|
662 |
|
|
663 |
|
|
664 |
|
|
665 |
|
@param |
666 |
|
@param |
667 |
|
@return |
668 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
669 |
5356 |
private InstalledFeature getInstalledFeatureFromCache(String feature, String namespace)... |
670 |
|
{ |
671 |
5356 |
if (feature == null) { |
672 |
0 |
return null; |
673 |
|
} |
674 |
|
|
675 |
5356 |
Map<String, InstalledFeature> installedExtensionsForFeature = this.extensionNamespaceByFeature.get(feature); |
676 |
|
|
677 |
5356 |
if (installedExtensionsForFeature == null) { |
678 |
1338 |
return null; |
679 |
|
} |
680 |
|
|
681 |
4018 |
InstalledFeature installedExtension = installedExtensionsForFeature.get(namespace); |
682 |
|
|
683 |
|
|
684 |
4018 |
if (installedExtension == null && namespace != null) { |
685 |
471 |
installedExtension = getInstalledFeatureFromCache(feature, null); |
686 |
|
} |
687 |
|
|
688 |
4018 |
return installedExtension; |
689 |
|
} |
690 |
|
|
691 |
|
|
692 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
693 |
4499 |
@Override... |
694 |
|
public InstalledExtension getInstalledExtension(String feature, String namespace) |
695 |
|
{ |
696 |
4499 |
InstalledFeature installedFeature = getInstalledFeatureFromCache(feature, namespace); |
697 |
|
|
698 |
4499 |
if (installedFeature != null) { |
699 |
2604 |
if (installedFeature.root.extension != null) { |
700 |
2590 |
return installedFeature.root.extension; |
701 |
|
} |
702 |
|
|
703 |
14 |
return installedFeature.root.invalidExtensions.isEmpty() ? null |
704 |
|
: installedFeature.root.invalidExtensions.iterator().next(); |
705 |
|
} |
706 |
|
|
707 |
1895 |
return null; |
708 |
|
} |
709 |
|
|
|
|
| 87% |
Uncovered Elements: 3 (23) |
Complexity: 8 |
Complexity Density: 0.53 |
|
710 |
207 |
@Override... |
711 |
|
public InstalledExtension installExtension(LocalExtension extension, String namespace, boolean dependency, |
712 |
|
Map<String, Object> properties) throws InstallException |
713 |
|
{ |
714 |
207 |
DefaultInstalledExtension installedExtension = this.extensions.get(extension.getId()); |
715 |
|
|
716 |
207 |
if (installedExtension != null && installedExtension.isInstalled(namespace) |
717 |
|
&& installedExtension.isValid(namespace)) { |
718 |
2 |
if (installedExtension.isDependency(namespace) == dependency) { |
719 |
1 |
throw new InstallException(String.format("The extension [%s] is already installed on namespace [%s]", |
720 |
|
installedExtension, namespace)); |
721 |
|
} |
722 |
|
|
723 |
1 |
installedExtension.setDependency(dependency, namespace); |
724 |
|
|
725 |
1 |
try { |
726 |
1 |
this.localRepository.setProperties(installedExtension.getLocalExtension(), |
727 |
|
installedExtension.getProperties()); |
728 |
|
} catch (Exception e) { |
729 |
0 |
throw new InstallException("Failed to modify extension descriptor", e); |
730 |
|
} |
731 |
|
} else { |
732 |
205 |
LocalExtension localExtension = this.localRepository.getLocalExtension(extension.getId()); |
733 |
|
|
734 |
205 |
if (localExtension == null) { |
735 |
|
|
736 |
0 |
throw new InstallException(String.format("The extension [%s] need to be stored first", extension)); |
737 |
|
} |
738 |
|
|
739 |
205 |
if (installedExtension == null) { |
740 |
180 |
installedExtension = new DefaultInstalledExtension(localExtension, this); |
741 |
|
} |
742 |
|
|
743 |
205 |
applyInstallExtension(installedExtension, namespace, dependency, properties, Collections.emptyMap()); |
744 |
|
} |
745 |
|
|
746 |
206 |
return installedExtension; |
747 |
|
} |
748 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
749 |
121 |
@Override... |
750 |
|
public void uninstallExtension(InstalledExtension extension, String namespace) throws UninstallException |
751 |
|
{ |
752 |
121 |
DefaultInstalledExtension installedExtension = |
753 |
|
(DefaultInstalledExtension) getInstalledExtension(extension.getId().getId(), namespace); |
754 |
|
|
755 |
121 |
if (installedExtension != null) { |
756 |
120 |
applyUninstallExtension(installedExtension, namespace); |
757 |
|
} |
758 |
|
} |
759 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
760 |
120 |
private void applyUninstallExtension(DefaultInstalledExtension installedExtension, String namespace)... |
761 |
|
throws UninstallException |
762 |
|
{ |
763 |
120 |
installedExtension.setInstalled(false, namespace); |
764 |
|
|
765 |
120 |
try { |
766 |
120 |
this.localRepository.setProperties(installedExtension.getLocalExtension(), |
767 |
|
installedExtension.getProperties()); |
768 |
|
} catch (Exception e) { |
769 |
0 |
throw new UninstallException("Failed to modify extension descriptor", e); |
770 |
|
} |
771 |
|
|
772 |
|
|
773 |
|
|
774 |
120 |
removeInstalledExtension(installedExtension, namespace); |
775 |
|
} |
776 |
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
777 |
148 |
@Override... |
778 |
|
public Collection<InstalledExtension> getBackwardDependencies(String feature, String namespace) |
779 |
|
throws ResolveException |
780 |
|
{ |
781 |
148 |
if (getInstalledExtension(feature, namespace) == null) { |
782 |
0 |
throw new ResolveException( |
783 |
|
String.format("Extension [%s] is not installed on namespace [%s]", feature, namespace)); |
784 |
|
} |
785 |
|
|
786 |
148 |
Map<String, InstalledFeature> installedExtensionsByFeature = this.extensionNamespaceByFeature.get(feature); |
787 |
148 |
if (installedExtensionsByFeature != null) { |
788 |
148 |
InstalledFeature installedExtension = installedExtensionsByFeature.get(namespace); |
789 |
|
|
790 |
148 |
if (installedExtension != null) { |
791 |
147 |
Set<DefaultInstalledExtension> backwardDependencies = installedExtension.root.backwardDependencies; |
792 |
|
|
793 |
|
|
794 |
|
|
795 |
147 |
return backwardDependencies.isEmpty() ? Collections.<InstalledExtension>emptyList() |
796 |
|
: new ArrayList<InstalledExtension>(backwardDependencies); |
797 |
|
} |
798 |
|
} |
799 |
|
|
800 |
1 |
return Collections.emptyList(); |
801 |
|
} |
802 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 5 |
Complexity Density: 0.45 |
|
803 |
119 |
@Override... |
804 |
|
public Map<String, Collection<InstalledExtension>> getBackwardDependencies(ExtensionId extensionId) |
805 |
|
throws ResolveException |
806 |
|
{ |
807 |
119 |
Map<String, Collection<InstalledExtension>> result; |
808 |
|
|
809 |
119 |
DefaultInstalledExtension installedExtension = resolve(extensionId); |
810 |
|
|
811 |
119 |
Collection<String> namespaces = installedExtension.getNamespaces(); |
812 |
|
|
813 |
119 |
Map<String, InstalledFeature> featureExtensions = |
814 |
|
this.extensionNamespaceByFeature.get(installedExtension.getId().getId()); |
815 |
119 |
if (featureExtensions != null) { |
816 |
119 |
result = new HashMap<String, Collection<InstalledExtension>>(); |
817 |
119 |
for (InstalledFeature festureExtension : featureExtensions.values()) { |
818 |
138 |
if ((namespaces == null || namespaces.contains(festureExtension.root.namespace)) |
819 |
|
&& !festureExtension.root.backwardDependencies.isEmpty()) { |
820 |
|
|
821 |
|
|
822 |
55 |
result.put(festureExtension.root.namespace, |
823 |
|
new ArrayList<InstalledExtension>(festureExtension.root.backwardDependencies)); |
824 |
|
} |
825 |
|
} |
826 |
|
} else { |
827 |
0 |
result = Collections.emptyMap(); |
828 |
|
} |
829 |
|
|
830 |
119 |
return result; |
831 |
|
} |
832 |
|
} |