1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package org.xwiki.extension.handler.internal; |
22 |
|
|
23 |
|
import java.util.Collection; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.HashSet; |
26 |
|
import java.util.Map; |
27 |
|
import java.util.Set; |
28 |
|
|
29 |
|
import javax.inject.Inject; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.slf4j.Logger; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.extension.ExtensionDependency; |
35 |
|
import org.xwiki.extension.ExtensionException; |
36 |
|
import org.xwiki.extension.InstalledExtension; |
37 |
|
import org.xwiki.extension.handler.ExtensionHandlerManager; |
38 |
|
import org.xwiki.extension.handler.ExtensionInitializer; |
39 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
40 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Singleton |
|
|
| 90% |
Uncovered Elements: 7 (70) |
Complexity: 22 |
Complexity Density: 0.55 |
|
50 |
|
public class DefaultExtensionInitializer implements ExtensionInitializer |
51 |
|
{ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@Inject |
56 |
|
private InstalledExtensionRepository installedExtensionRepository; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@Inject |
62 |
|
private ExtensionHandlerManager extensionHandlerManager; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@Inject |
68 |
|
private CoreExtensionRepository coreExtensionRepository; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@Inject |
74 |
|
private Logger logger; |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
192 |
@Override... |
77 |
|
public void initialize() |
78 |
|
{ |
79 |
192 |
initialize(null, null); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public void initialize(String namespaceToLoad) |
84 |
|
{ |
85 |
0 |
initialize(namespaceToLoad, null); |
86 |
|
} |
87 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
88 |
252 |
@Override... |
89 |
|
public void initialize(String namespaceToInitialize, String type) |
90 |
|
{ |
91 |
252 |
Map<String, Set<InstalledExtension>> initializedExtensions = new HashMap<String, Set<InstalledExtension>>(); |
92 |
|
|
93 |
|
|
94 |
252 |
Collection<InstalledExtension> installedExtensions; |
95 |
252 |
if (namespaceToInitialize != null) { |
96 |
42 |
installedExtensions = this.installedExtensionRepository.getInstalledExtensions(namespaceToInitialize); |
97 |
|
} else { |
98 |
210 |
installedExtensions = this.installedExtensionRepository.getInstalledExtensions(); |
99 |
|
} |
100 |
252 |
for (InstalledExtension installedExtension : installedExtensions) { |
101 |
1527 |
if (type == null || type.equals(installedExtension.getType())) { |
102 |
1432 |
try { |
103 |
1432 |
initializeExtension(installedExtension, namespaceToInitialize, initializedExtensions); |
104 |
|
} catch (Throwable t) { |
105 |
0 |
this.logger.error("Failed to initialize local extension [{}]", installedExtension.getId(), t); |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@param |
115 |
|
@param |
116 |
|
@param |
117 |
|
@throws |
118 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
119 |
1432 |
private void initializeExtension(InstalledExtension installedExtension, String namespaceToLoad,... |
120 |
|
Map<String, Set<InstalledExtension>> initializedExtensions) throws ExtensionException |
121 |
|
{ |
122 |
1432 |
if (installedExtension.getNamespaces() != null) { |
123 |
569 |
if (namespaceToLoad == null) { |
124 |
554 |
for (String namespace : installedExtension.getNamespaces()) { |
125 |
714 |
initializeExtensionInNamespace(installedExtension, namespace, initializedExtensions); |
126 |
|
} |
127 |
15 |
} else if (installedExtension.getNamespaces().contains(namespaceToLoad)) { |
128 |
15 |
initializeExtensionInNamespace(installedExtension, namespaceToLoad, initializedExtensions); |
129 |
|
} |
130 |
863 |
} else if (namespaceToLoad == null) { |
131 |
818 |
initializeExtensionInNamespace(installedExtension, null, initializedExtensions); |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
@param |
139 |
|
@param |
140 |
|
@param |
141 |
|
@throws |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
143 |
2347 |
private void initializeExtensionInNamespace(InstalledExtension installedExtension, String namespace,... |
144 |
|
Map<String, Set<InstalledExtension>> initializedExtensions) throws ExtensionException |
145 |
|
{ |
146 |
|
|
147 |
2347 |
if (!installedExtension.isValid(namespace)) { |
148 |
223 |
return; |
149 |
|
} |
150 |
|
|
151 |
2124 |
Set<InstalledExtension> initializedExtensionsInNamespace = initializedExtensions.get(namespace); |
152 |
|
|
153 |
2124 |
if (initializedExtensionsInNamespace == null) { |
154 |
440 |
initializedExtensionsInNamespace = new HashSet<InstalledExtension>(); |
155 |
440 |
initializedExtensions.put(namespace, initializedExtensionsInNamespace); |
156 |
|
} |
157 |
|
|
158 |
2124 |
if (!initializedExtensionsInNamespace.contains(installedExtension)) { |
159 |
1484 |
initializeExtensionInNamespace(installedExtension, namespace, initializedExtensions, |
160 |
|
initializedExtensionsInNamespace); |
161 |
|
} |
162 |
|
} |
163 |
|
|
|
|
| 83.3% |
Uncovered Elements: 3 (18) |
Complexity: 6 |
Complexity Density: 0.5 |
|
164 |
1484 |
private void initializeExtensionInNamespace(InstalledExtension installedExtension, String namespace,... |
165 |
|
Map<String, Set<InstalledExtension>> initializedExtensions, |
166 |
|
Set<InstalledExtension> initializedExtensionsInNamespace) throws ExtensionException |
167 |
|
{ |
168 |
1484 |
if (namespace != null && installedExtension.getNamespaces() == null) { |
169 |
|
|
170 |
|
|
171 |
160 |
initializeExtensionInNamespace(installedExtension, null, initializedExtensions); |
172 |
|
} else { |
173 |
|
|
174 |
1324 |
for (ExtensionDependency dependency : installedExtension.getDependencies()) { |
175 |
720 |
if (!this.coreExtensionRepository.exists(dependency.getId())) { |
176 |
640 |
InstalledExtension dependencyExtension = |
177 |
|
this.installedExtensionRepository.getInstalledExtension(dependency.getId(), namespace); |
178 |
|
|
179 |
640 |
if (dependencyExtension == installedExtension) { |
180 |
0 |
throw new ExtensionException(String.format("Extension [] has itself as dependency ([])." |
181 |
|
+ " It usually mean an extension is installed along with one of it's features.", |
182 |
|
installedExtension, dependency)); |
183 |
|
} |
184 |
|
|
185 |
640 |
try { |
186 |
640 |
initializeExtensionInNamespace(dependencyExtension, namespace, initializedExtensions); |
187 |
|
} catch (Exception e) { |
188 |
0 |
throw new ExtensionException("Failed to initialize dependency [" + dependency + "]", e); |
189 |
|
} |
190 |
|
} |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
1324 |
this.extensionHandlerManager.initialize(installedExtension, namespace); |
195 |
|
|
196 |
|
|
197 |
1324 |
initializedExtensionsInNamespace.add(installedExtension); |
198 |
|
} |
199 |
|
} |
200 |
|
} |