1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.distribution.internal.job.step; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
|
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
30 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
31 |
|
import org.xwiki.extension.ExtensionId; |
32 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
33 |
|
import org.xwiki.platform.flavor.FlavorManager; |
34 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
35 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named(WikisFlavorDistributionStep.ID) |
45 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 8 |
Complexity Density: 0.38 |
|
46 |
|
public class WikisFlavorDistributionStep extends AbstractDistributionStep |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public static final String ID = "extension.flavor.wikis"; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private transient FlavorManager flavorManager; |
57 |
|
|
58 |
|
@Inject |
59 |
|
private transient InstalledExtensionRepository installedRepository; |
60 |
|
|
61 |
|
@Inject |
62 |
|
private transient Logger logger; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
public WikisFlavorDistributionStep()... |
68 |
|
{ |
69 |
0 |
super(ID); |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 7 |
Complexity Density: 0.35 |
|
72 |
0 |
@Override... |
73 |
|
public void prepare() |
74 |
|
{ |
75 |
0 |
if (getState() == null) { |
76 |
0 |
setState(State.COMPLETED); |
77 |
|
|
78 |
0 |
if (!isMainWiki()) { |
79 |
0 |
return; |
80 |
|
} |
81 |
|
|
82 |
0 |
WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get(); |
83 |
|
|
84 |
0 |
Collection<String> wikiIds; |
85 |
0 |
try { |
86 |
0 |
wikiIds = wikiDescriptorManager.getAllIds(); |
87 |
|
} catch (WikiManagerException e) { |
88 |
0 |
this.logger.error("Failed to get the list of wikis", e); |
89 |
0 |
setState(null); |
90 |
0 |
return; |
91 |
|
} |
92 |
|
|
93 |
0 |
String mainWiki = wikiDescriptorManager.getMainWikiId(); |
94 |
|
|
95 |
|
|
96 |
0 |
for (String wikiId : wikiIds) { |
97 |
0 |
if (mainWiki.equals(wikiId)) { |
98 |
0 |
continue; |
99 |
|
} |
100 |
0 |
String namespace = "wiki:" + wikiId; |
101 |
0 |
ExtensionId flavor = flavorManager.getFlavorOfWiki(getWiki()); |
102 |
0 |
if (flavor == null || !installedRepository.getInstalledExtension(flavor).isValid(namespace)) { |
103 |
0 |
setState(null); |
104 |
0 |
return; |
105 |
|
} |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
|
} |