1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.job.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.extension.InstalledExtension; |
30 |
|
import org.xwiki.extension.ResolveException; |
31 |
|
import org.xwiki.extension.UninstallException; |
32 |
|
import org.xwiki.extension.handler.ExtensionHandler; |
33 |
|
import org.xwiki.extension.job.ExtensionRequest; |
34 |
|
import org.xwiki.extension.job.plan.ExtensionPlanAction.Action; |
35 |
|
import org.xwiki.extension.job.plan.ExtensionPlanNode; |
36 |
|
import org.xwiki.extension.job.plan.internal.DefaultExtensionPlan; |
37 |
|
import org.xwiki.extension.job.plan.internal.DefaultExtensionPlanAction; |
38 |
|
import org.xwiki.extension.job.plan.internal.DefaultExtensionPlanNode; |
39 |
|
import org.xwiki.extension.job.plan.internal.DefaultExtensionPlanTree; |
40 |
|
import org.xwiki.job.Job; |
41 |
|
import org.xwiki.job.event.status.JobStatus; |
42 |
|
import org.xwiki.logging.marker.TranslationMarker; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@param |
48 |
|
@version |
49 |
|
@since |
50 |
|
|
|
|
| 91.7% |
Uncovered Elements: 7 (84) |
Complexity: 21 |
Complexity Density: 0.36 |
|
51 |
|
public abstract class AbstractExtensionPlanJob<R extends ExtensionRequest> |
52 |
|
extends AbstractExtensionJob<R, DefaultExtensionPlan<R>> |
53 |
|
{ |
54 |
|
protected static final TranslationMarker LOG_RESOLVE = new TranslationMarker("extension.log.job.plan.resolve"); |
55 |
|
|
56 |
|
protected static final TranslationMarker LOG_RESOLVE_NAMESPACE = |
57 |
|
new TranslationMarker("extension.log.job.plan.resolve.namespace"); |
58 |
|
|
59 |
|
protected static final TranslationMarker LOG_RESOLVEDEPENDENCY = |
60 |
|
new TranslationMarker("extension.log.job.plan.resolvedependency"); |
61 |
|
|
62 |
|
protected static final TranslationMarker LOG_RESOLVEDEPENDENCY_NAMESPACE = |
63 |
|
new TranslationMarker("extension.log.job.plan.resolvedependency.namespace"); |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private static final String EXCEPTION_NOTINSTALLED = "Extension [%s] is not installed"; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
private static final String EXCEPTION_NOTINSTALLEDNAMESPACE = EXCEPTION_NOTINSTALLED + " on namespace [%s]"; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
protected DefaultExtensionPlanTree extensionTree = new DefaultExtensionPlanTree(); |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
80 |
236 |
@Override... |
81 |
|
protected DefaultExtensionPlan<R> createNewStatus(R request) |
82 |
|
{ |
83 |
236 |
Job currentJob = this.jobContext.getCurrentJob(); |
84 |
236 |
JobStatus currentJobStatus = currentJob != null ? currentJob.getStatus() : null; |
85 |
236 |
return new DefaultExtensionPlan<R>(request, this.observationManager, this.loggerManager, this.extensionTree, |
86 |
|
currentJobStatus); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
@param |
92 |
|
@param@link |
93 |
|
@param |
94 |
|
@throws |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
96 |
16 |
protected void uninstallExtension(String extensionId, Collection<String> namespaces,... |
97 |
|
Collection<ExtensionPlanNode> parentBranch, boolean withBackWard) throws UninstallException |
98 |
|
{ |
99 |
16 |
this.progressManager.pushLevelProgress(namespaces.size(), this); |
100 |
|
|
101 |
16 |
try { |
102 |
16 |
for (String namespace : namespaces) { |
103 |
16 |
this.progressManager.startStep(this); |
104 |
|
|
105 |
16 |
uninstallExtension(extensionId, namespace, parentBranch, withBackWard); |
106 |
|
} |
107 |
|
} finally { |
108 |
16 |
this.progressManager.popLevelProgress(this); |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
@param |
115 |
|
@param@link |
116 |
|
@param |
117 |
|
@throws |
118 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
119 |
18 |
protected void uninstallExtension(String extensionId, String namespace, Collection<ExtensionPlanNode> parentBranch,... |
120 |
|
boolean withBackWard) throws UninstallException |
121 |
|
{ |
122 |
18 |
InstalledExtension installedExtension = |
123 |
|
this.installedExtensionRepository.getInstalledExtension(extensionId, namespace); |
124 |
|
|
125 |
18 |
if (installedExtension == null) { |
126 |
0 |
throw new UninstallException(String.format(EXCEPTION_NOTINSTALLED, extensionId)); |
127 |
|
} |
128 |
|
|
129 |
18 |
try { |
130 |
18 |
uninstallExtension(installedExtension, namespace, parentBranch, withBackWard); |
131 |
|
} catch (Exception e) { |
132 |
2 |
throw new UninstallException("Failed to uninstall extension", e); |
133 |
|
} |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
@param |
138 |
|
@param |
139 |
|
@param@link |
140 |
|
@param |
141 |
|
@throws |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
143 |
21 |
protected void uninstallExtension(InstalledExtension installedExtension, Collection<String> namespaces,... |
144 |
|
Collection<ExtensionPlanNode> parentBranch, boolean withBackWard) throws UninstallException |
145 |
|
{ |
146 |
21 |
this.progressManager.pushLevelProgress(namespaces.size(), this); |
147 |
|
|
148 |
21 |
try { |
149 |
21 |
for (String namespace : namespaces) { |
150 |
24 |
this.progressManager.startStep(this); |
151 |
|
|
152 |
24 |
uninstallExtension(installedExtension, namespace, parentBranch, withBackWard); |
153 |
|
} |
154 |
|
} finally { |
155 |
21 |
this.progressManager.popLevelProgress(this); |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
@param |
161 |
|
@param |
162 |
|
@param@link |
163 |
|
@param |
164 |
|
@throws |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
166 |
28 |
protected void uninstallExtensions(Collection<InstalledExtension> extensions, String namespace,... |
167 |
|
Collection<ExtensionPlanNode> parentBranch, boolean withBackWard) throws UninstallException |
168 |
|
{ |
169 |
28 |
this.progressManager.pushLevelProgress(extensions.size(), this); |
170 |
|
|
171 |
28 |
try { |
172 |
28 |
for (InstalledExtension backardDependency : extensions) { |
173 |
28 |
this.progressManager.startStep(this); |
174 |
|
|
175 |
28 |
uninstallExtension(backardDependency, namespace, parentBranch, withBackWard); |
176 |
|
} |
177 |
|
} finally { |
178 |
28 |
this.progressManager.popLevelProgress(this); |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
@param |
184 |
|
@param |
185 |
|
@param@link |
186 |
|
@param |
187 |
|
@throws |
188 |
|
|
|
|
| 85.2% |
Uncovered Elements: 4 (27) |
Complexity: 8 |
Complexity Density: 0.47 |
|
189 |
104 |
protected void uninstallExtension(InstalledExtension installedExtension, String namespace,... |
190 |
|
Collection<ExtensionPlanNode> parentBranch, boolean withBackWard) throws UninstallException |
191 |
|
{ |
192 |
104 |
if (namespace != null) { |
193 |
69 |
if (installedExtension.getNamespaces() == null || !installedExtension.getNamespaces().contains(namespace)) { |
194 |
0 |
throw new UninstallException( |
195 |
|
String.format(EXCEPTION_NOTINSTALLEDNAMESPACE, installedExtension, namespace)); |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
104 |
ExtensionHandler extensionHandler; |
200 |
|
|
201 |
|
|
202 |
104 |
try { |
203 |
104 |
extensionHandler = this.componentManager.getInstance(ExtensionHandler.class, installedExtension.getType()); |
204 |
|
} catch (ComponentLookupException e) { |
205 |
0 |
throw new UninstallException(String.format("Unsupported type [%s]", installedExtension.getType()), e); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
104 |
extensionHandler.checkUninstall(installedExtension, namespace, getRequest()); |
210 |
|
|
211 |
|
|
212 |
100 |
if (getRequest().isVerbose()) { |
213 |
100 |
if (namespace != null) { |
214 |
67 |
this.logger.info(LOG_RESOLVE_NAMESPACE, "Resolving extension [{}] from namespace [{}]", |
215 |
|
installedExtension.getId(), namespace); |
216 |
|
} else { |
217 |
33 |
this.logger.info(LOG_RESOLVE, "Resolving extension [{}]", installedExtension.getId()); |
218 |
|
} |
219 |
|
} |
220 |
|
|
221 |
100 |
List<ExtensionPlanNode> children = new ArrayList<ExtensionPlanNode>(); |
222 |
|
|
223 |
|
|
224 |
100 |
if (withBackWard) { |
225 |
84 |
uninstallBackwardDependencies(installedExtension, namespace, children, withBackWard); |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
100 |
DefaultExtensionPlanAction action = new DefaultExtensionPlanAction(installedExtension, installedExtension, |
230 |
|
Collections.singleton(installedExtension), Action.UNINSTALL, namespace, false); |
231 |
100 |
parentBranch.add(new DefaultExtensionPlanNode(action, children, null)); |
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
|
@param |
236 |
|
@param |
237 |
|
@param@link |
238 |
|
@param |
239 |
|
@throws |
240 |
|
@throws |
241 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
242 |
84 |
protected void uninstallBackwardDependencies(InstalledExtension installedExtension, String namespace,... |
243 |
|
List<ExtensionPlanNode> parentBranch, boolean withBackWard) throws UninstallException |
244 |
|
{ |
245 |
84 |
try { |
246 |
84 |
if (namespace != null) { |
247 |
55 |
Collection<InstalledExtension> installedExtensions = this.installedExtensionRepository |
248 |
|
.getBackwardDependencies(installedExtension.getId().getId(), namespace); |
249 |
55 |
if (!installedExtensions.isEmpty()) { |
250 |
8 |
uninstallExtensions(installedExtensions, namespace, parentBranch, withBackWard); |
251 |
|
} |
252 |
|
} else { |
253 |
29 |
uninstallBackwardDependencies(installedExtension, parentBranch, withBackWard); |
254 |
|
} |
255 |
|
} catch (ResolveException e) { |
256 |
0 |
throw new UninstallException( |
257 |
|
"Failed to resolve backward dependencies of extension [" + installedExtension + "]", e); |
258 |
|
} |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
@param |
263 |
|
@param@link |
264 |
|
@param |
265 |
|
@throws |
266 |
|
@throws |
267 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
268 |
29 |
protected void uninstallBackwardDependencies(InstalledExtension installedExtension,... |
269 |
|
List<ExtensionPlanNode> parentBranch, boolean withBackWard) throws UninstallException, ResolveException |
270 |
|
{ |
271 |
29 |
Map<String, Collection<InstalledExtension>> backwardDependencies = |
272 |
|
this.installedExtensionRepository.getBackwardDependencies(installedExtension.getId()); |
273 |
|
|
274 |
29 |
this.progressManager.pushLevelProgress(backwardDependencies.size(), this); |
275 |
|
|
276 |
29 |
try { |
277 |
29 |
for (Map.Entry<String, Collection<InstalledExtension>> entry : backwardDependencies.entrySet()) { |
278 |
20 |
this.progressManager.startStep(this); |
279 |
|
|
280 |
20 |
uninstallExtensions(entry.getValue(), entry.getKey(), parentBranch, withBackWard); |
281 |
|
} |
282 |
|
} finally { |
283 |
29 |
this.progressManager.popLevelProgress(this); |
284 |
|
} |
285 |
|
} |
286 |
|
} |