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.repository; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.slf4j.Logger; |
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.extension.InstalledExtension; |
31 |
|
import org.xwiki.extension.event.ExtensionEvent; |
32 |
|
import org.xwiki.extension.event.ExtensionInstalledEvent; |
33 |
|
import org.xwiki.extension.event.ExtensionUninstalledEvent; |
34 |
|
import org.xwiki.extension.event.ExtensionUpgradedEvent; |
35 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
36 |
|
import org.xwiki.extension.xar.internal.handler.UnsupportedNamespaceException; |
37 |
|
import org.xwiki.extension.xar.internal.handler.XarExtensionHandler; |
38 |
|
import org.xwiki.observation.AbstractEventListener; |
39 |
|
import org.xwiki.observation.event.Event; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Named("org.xwiki.extension.xar.internal.repository.InstalledExtensionSynchronizer") |
50 |
|
@Singleton |
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 6 |
Complexity Density: 0.43 |
|
51 |
|
public class InstalledExtensionSynchronizer extends AbstractEventListener |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
@Named(XarExtensionHandler.TYPE) |
55 |
|
private InstalledExtensionRepository xarRepository; |
56 |
|
|
57 |
|
@Inject |
58 |
|
private Logger logger; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
26 |
public InstalledExtensionSynchronizer()... |
64 |
|
{ |
65 |
26 |
super(InstalledExtensionSynchronizer.class.getName(), new ExtensionInstalledEvent(), |
66 |
|
new ExtensionUninstalledEvent(), new ExtensionUpgradedEvent()); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
176 |
private XarInstalledExtensionRepository getXarRepository()... |
70 |
|
{ |
71 |
176 |
return (XarInstalledExtensionRepository) this.xarRepository; |
72 |
|
} |
73 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
74 |
82 |
@Override... |
75 |
|
public void onEvent(Event event, Object source, Object data) |
76 |
|
{ |
77 |
82 |
ExtensionEvent extensionEvent = (ExtensionEvent) event; |
78 |
|
|
79 |
82 |
try { |
80 |
82 |
if (extensionEvent instanceof ExtensionUninstalledEvent) { |
81 |
|
|
82 |
19 |
getXarRepository().pagesRemoved(extensionEvent.getExtensionId(), extensionEvent.getNamespace()); |
83 |
|
|
84 |
|
|
85 |
19 |
getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId()); |
86 |
|
} else { |
87 |
|
|
88 |
|
|
89 |
63 |
if (data != null) { |
90 |
6 |
for (InstalledExtension installedExtension : (Collection<InstalledExtension>) data) { |
91 |
|
|
92 |
6 |
getXarRepository().pagesRemoved(installedExtension.getId(), extensionEvent.getNamespace()); |
93 |
|
|
94 |
|
|
95 |
6 |
getXarRepository().updateCachedXarExtension(installedExtension.getId()); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
63 |
getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId()); |
103 |
|
|
104 |
|
|
105 |
63 |
getXarRepository().pagesAdded(extensionEvent.getExtensionId(), extensionEvent.getNamespace()); |
106 |
|
} |
107 |
|
} catch (UnsupportedNamespaceException e) { |
108 |
0 |
logger.error("Failed to extract wiki from namespace [{}]", extensionEvent.getNamespace()); |
109 |
|
} |
110 |
|
} |
111 |
|
} |