1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.xar.internal.handler; |
21 |
|
|
22 |
|
import java.io.Closeable; |
23 |
|
import java.io.File; |
24 |
|
import java.io.IOException; |
25 |
|
import java.util.Collection; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import org.slf4j.Logger; |
30 |
|
import org.slf4j.LoggerFactory; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.extension.ExtensionException; |
33 |
|
import org.xwiki.extension.ExtensionId; |
34 |
|
import org.xwiki.extension.InstalledExtension; |
35 |
|
import org.xwiki.extension.LocalExtension; |
36 |
|
import org.xwiki.extension.job.plan.ExtensionPlan; |
37 |
|
import org.xwiki.extension.job.plan.ExtensionPlanAction; |
38 |
|
import org.xwiki.extension.job.plan.ExtensionPlanAction.Action; |
39 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
40 |
|
import org.xwiki.extension.repository.LocalExtensionRepository; |
41 |
|
import org.xwiki.extension.xar.internal.handler.packager.Packager; |
42 |
|
import org.xwiki.extension.xar.internal.repository.XarInstalledExtension; |
43 |
|
import org.xwiki.model.reference.DocumentReference; |
44 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
45 |
|
import org.xwiki.model.reference.WikiReference; |
46 |
|
import org.xwiki.filter.FilterException; |
47 |
|
import org.xwiki.xar.XarEntry; |
48 |
|
import org.xwiki.xar.XarException; |
49 |
|
import org.xwiki.xar.XarPackage; |
50 |
|
|
51 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
52 |
|
|
53 |
|
|
54 |
|
@version |
55 |
|
@since |
56 |
|
|
|
|
| 81.3% |
Uncovered Elements: 23 (123) |
Complexity: 31 |
Complexity Density: 0.38 |
|
57 |
|
public class XarExtensionPlan implements Closeable |
58 |
|
{ |
59 |
|
public static final String CONTEXTKEY_XARINSTALLPLAN = "extension.xar.installplan"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(XarExtensionPlan.class); |
65 |
|
|
66 |
|
public final Map<String, Map<XarEntry, XarExtensionPlanEntry>> previousXAREntries; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
public final Map<String, Map<XarEntry, LocalExtension>> nextXAREntries; |
72 |
|
|
|
|
| 90.4% |
Uncovered Elements: 5 (52) |
Complexity: 12 |
Complexity Density: 0.32 |
|
73 |
53 |
public XarExtensionPlan(ExtensionPlan plan, InstalledExtensionRepository xarRepository,... |
74 |
|
LocalExtensionRepository localReposirory) throws ExtensionException, XarException, IOException |
75 |
|
{ |
76 |
53 |
this.previousXAREntries = new HashMap<String, Map<XarEntry, XarExtensionPlanEntry>>(); |
77 |
53 |
this.nextXAREntries = new HashMap<String, Map<XarEntry, LocalExtension>>(); |
78 |
|
|
79 |
53 |
Map<ExtensionId, XarExtensionPlanEntry> planEntry = new HashMap<ExtensionId, XarExtensionPlanEntry>(); |
80 |
|
|
81 |
53 |
for (ExtensionPlanAction action : plan.getActions()) { |
82 |
81 |
if (action.getExtension().getType().equals(XarExtensionHandler.TYPE)) { |
83 |
|
|
84 |
75 |
Collection<InstalledExtension> previousExtensions = action.getPreviousExtensions(); |
85 |
75 |
for (InstalledExtension previousExtension : previousExtensions) { |
86 |
24 |
if (previousExtension != null) { |
87 |
24 |
XarInstalledExtension previousXARExtension = |
88 |
|
(XarInstalledExtension) xarRepository.getInstalledExtension(previousExtension.getId()); |
89 |
|
|
90 |
24 |
XarExtensionPlanEntry xarPlanEntry = planEntry.get(previousXARExtension.getId()); |
91 |
24 |
if (xarPlanEntry == null) { |
92 |
24 |
xarPlanEntry = |
93 |
|
new XarExtensionPlanEntry(previousXARExtension, previousXARExtension.getXarPackage()); |
94 |
24 |
planEntry.put(previousXARExtension.getId(), xarPlanEntry); |
95 |
|
} |
96 |
|
|
97 |
24 |
for (XarEntry entry : previousXARExtension.getXarPackage().getEntries()) { |
98 |
120 |
String wiki; |
99 |
120 |
try { |
100 |
120 |
wiki = XarHandlerUtils.getWikiFromNamespace(action.getNamespace()); |
101 |
|
} catch (UnsupportedNamespaceException e) { |
102 |
0 |
throw new ExtensionException("Failed to extract wiki id from namespace", e); |
103 |
|
} |
104 |
120 |
Map<XarEntry, XarExtensionPlanEntry> pages = previousXAREntries.get(wiki); |
105 |
120 |
if (pages == null) { |
106 |
22 |
pages = new HashMap<XarEntry, XarExtensionPlanEntry>(); |
107 |
22 |
this.previousXAREntries.put(wiki, pages); |
108 |
|
} |
109 |
120 |
pages.put(entry, xarPlanEntry); |
110 |
|
} |
111 |
|
} |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
75 |
LocalExtension nextExtension = |
116 |
75 |
action.getAction() != Action.UNINSTALL && action.getExtension() != null ? localReposirory |
117 |
|
.getLocalExtension(action.getExtension().getId()) : null; |
118 |
|
|
119 |
75 |
if (nextExtension != null) { |
120 |
57 |
try { |
121 |
57 |
Collection<XarEntry> entries = |
122 |
|
XarPackage.getEntries(new File(nextExtension.getFile().getAbsolutePath())); |
123 |
|
|
124 |
57 |
for (XarEntry entry : entries) { |
125 |
282 |
String wiki; |
126 |
282 |
try { |
127 |
282 |
wiki = XarHandlerUtils.getWikiFromNamespace(action.getNamespace()); |
128 |
|
} catch (UnsupportedNamespaceException e) { |
129 |
0 |
throw new ExtensionException("Failed to extract wiki id from namespace", e); |
130 |
|
} |
131 |
282 |
Map<XarEntry, LocalExtension> pages = this.nextXAREntries.get(wiki); |
132 |
282 |
if (pages == null) { |
133 |
39 |
pages = new HashMap<XarEntry, LocalExtension>(); |
134 |
39 |
this.nextXAREntries.put(wiki, pages); |
135 |
|
} |
136 |
282 |
pages.put(entry, nextExtension); |
137 |
|
} |
138 |
|
} catch (Exception e) { |
139 |
0 |
LOGGER.error("Failed to parse extension file [{}]", nextExtension.getFile().getAbsolutePath(), |
140 |
|
e); |
141 |
|
} |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
147 |
0 |
public XarExtensionPlanEntry getPreviousXarExtensionPlanEntry(DocumentReference documentReference)... |
148 |
|
{ |
149 |
0 |
String wiki = documentReference.getWikiReference().getName(); |
150 |
0 |
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference); |
151 |
|
|
152 |
0 |
return getPreviousXarExtensionPlanEntry(wiki, localDocumentReference); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
155 |
438 |
public XarExtensionPlanEntry getPreviousXarExtensionPlanEntry(String wiki,... |
156 |
|
LocalDocumentReference localDocumentReference) |
157 |
|
{ |
158 |
438 |
XarEntry xarEntry = new XarEntry(localDocumentReference); |
159 |
|
|
160 |
438 |
XarExtensionPlanEntry planEntry = null; |
161 |
|
|
162 |
438 |
Map<XarEntry, XarExtensionPlanEntry> wikiEntry = this.previousXAREntries.get(wiki); |
163 |
|
|
164 |
438 |
if (wikiEntry != null) { |
165 |
95 |
planEntry = wikiEntry.get(xarEntry); |
166 |
|
} |
167 |
|
|
168 |
438 |
if (planEntry == null) { |
169 |
354 |
wikiEntry = this.previousXAREntries.get(null); |
170 |
|
|
171 |
354 |
if (wikiEntry != null) { |
172 |
52 |
planEntry = wikiEntry.get(xarEntry); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
438 |
return planEntry; |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
179 |
0 |
public XarInstalledExtension getPreviousXarExtension(DocumentReference documentReference)... |
180 |
|
{ |
181 |
0 |
String wiki = documentReference.getWikiReference().getName(); |
182 |
0 |
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference); |
183 |
|
|
184 |
0 |
return getPreviousXarExtension(wiki, localDocumentReference); |
185 |
|
} |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
187 |
0 |
public XarInstalledExtension getPreviousXarExtension(String wiki, LocalDocumentReference localDocumentReference)... |
188 |
|
{ |
189 |
0 |
XarExtensionPlanEntry entry = getPreviousXarExtensionPlanEntry(wiki, localDocumentReference); |
190 |
|
|
191 |
0 |
return entry != null ? entry.extension : null; |
192 |
|
} |
193 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
194 |
0 |
public LocalExtension getNextXarExtension(DocumentReference documentReference)... |
195 |
|
{ |
196 |
0 |
WikiReference wikiReference = documentReference.getWikiReference(); |
197 |
0 |
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference); |
198 |
|
|
199 |
0 |
return getNextXarExtension(wikiReference.getName(), localDocumentReference); |
200 |
|
} |
201 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
202 |
92 |
public LocalExtension getNextXarExtension(String wiki, LocalDocumentReference localDocumentReference)... |
203 |
|
{ |
204 |
92 |
XarEntry xarEntry = new XarEntry(localDocumentReference); |
205 |
|
|
206 |
92 |
LocalExtension nextExtension = null; |
207 |
|
|
208 |
92 |
Map<XarEntry, LocalExtension> wikiEntry = this.nextXAREntries.get(wiki); |
209 |
|
|
210 |
92 |
if (wikiEntry != null) { |
211 |
9 |
nextExtension = wikiEntry.get(xarEntry); |
212 |
|
} |
213 |
|
|
214 |
92 |
if (nextExtension == null) { |
215 |
92 |
wikiEntry = this.nextXAREntries.get(null); |
216 |
|
|
217 |
92 |
if (wikiEntry != null) { |
218 |
24 |
nextExtension = wikiEntry.get(xarEntry); |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
92 |
return nextExtension; |
223 |
|
} |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
225 |
438 |
public XWikiDocument getPreviousXWikiDocument(DocumentReference documentReference, Packager packager)... |
226 |
|
throws FilterException, ComponentLookupException, IOException |
227 |
|
{ |
228 |
438 |
WikiReference wikiReference = documentReference.getWikiReference(); |
229 |
438 |
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference); |
230 |
|
|
231 |
438 |
return getPreviousXWikiDocument(wikiReference, localDocumentReference, packager); |
232 |
|
} |
233 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
234 |
438 |
public XWikiDocument getPreviousXWikiDocument(WikiReference wikiReference, LocalDocumentReference localReference,... |
235 |
|
Packager packager) throws FilterException, ComponentLookupException, IOException |
236 |
|
{ |
237 |
438 |
XarExtensionPlanEntry xarPlanEntry = getPreviousXarExtensionPlanEntry(wikiReference.getName(), localReference); |
238 |
|
|
239 |
438 |
return xarPlanEntry != null ? packager.getXWikiDocument(wikiReference, localReference, xarPlanEntry.xarFile) |
240 |
|
: null; |
241 |
|
} |
242 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
243 |
53 |
@Override... |
244 |
|
public void close() throws IOException |
245 |
|
{ |
246 |
53 |
for (Map<XarEntry, XarExtensionPlanEntry> wikiEntry : this.previousXAREntries.values()) { |
247 |
22 |
for (XarExtensionPlanEntry entry : wikiEntry.values()) { |
248 |
119 |
entry.close(); |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
253 |
92 |
public boolean containsNewPage(DocumentReference documentReference)... |
254 |
|
{ |
255 |
92 |
WikiReference wikiReference = documentReference.getWikiReference(); |
256 |
92 |
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference); |
257 |
|
|
258 |
92 |
return containsNewPage(wikiReference, localDocumentReference); |
259 |
|
} |
260 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
261 |
92 |
public boolean containsNewPage(WikiReference wikiReference, LocalDocumentReference localDocumentReference)... |
262 |
|
{ |
263 |
92 |
return getNextXarExtension(wikiReference.getName(), localDocumentReference) != null; |
264 |
|
} |
265 |
|
} |