1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging; |
35 |
|
|
36 |
|
import info.magnolia.module.ModuleLifecycle; |
37 |
|
import info.magnolia.module.ModuleLifecycleContext; |
38 |
|
|
39 |
|
import java.util.ArrayList; |
40 |
|
import java.util.Iterator; |
41 |
|
import java.util.LinkedHashMap; |
42 |
|
import java.util.List; |
43 |
|
import java.util.Map; |
44 |
|
|
45 |
|
import javax.imageio.ImageIO; |
46 |
|
import javax.imageio.spi.IIORegistry; |
47 |
|
import javax.imageio.spi.ServiceRegistry; |
48 |
|
|
49 |
|
import org.slf4j.Logger; |
50 |
|
import org.slf4j.LoggerFactory; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.36 |
|
55 |
|
public class ImagingModule implements ModuleLifecycle { |
56 |
|
|
57 |
|
private static final Logger log = LoggerFactory.getLogger(ImagingModule.class); |
58 |
|
|
59 |
|
private Map<String, ImageGenerator> generators = new LinkedHashMap<String, ImageGenerator>(); |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
3 |
public void addGenerator(String name, ImageGenerator generator) {... |
62 |
3 |
generators.put(name, generator); |
63 |
|
} |
64 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
65 |
|
public void setGenerators(Map<String, ImageGenerator> generators) {... |
66 |
|
this.generators = generators; |
67 |
|
} |
68 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
69 |
|
public Map<String, ImageGenerator> getGenerators() {... |
70 |
|
return generators; |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@see |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
2 |
@Override... |
79 |
|
public void start(ModuleLifecycleContext moduleLifecycleContext) { |
80 |
2 |
ImageIO.scanForPlugins(); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
@link |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
90 |
1 |
@Override... |
91 |
|
public void stop(ModuleLifecycleContext moduleLifecycleContext) { |
92 |
|
|
93 |
|
|
94 |
1 |
final IIORegistry registry = IIORegistry.getDefaultInstance(); |
95 |
1 |
final LocalFilter localFilter = new LocalFilter(Thread.currentThread().getContextClassLoader()); |
96 |
|
|
97 |
1 |
Iterator<Class<?>> categories = registry.getCategories(); |
98 |
|
|
99 |
6 |
while (categories.hasNext()) { |
100 |
5 |
Class<?> category = categories.next(); |
101 |
5 |
Iterator<?> providers = registry.getServiceProviders(category, localFilter, false); |
102 |
|
|
103 |
|
|
104 |
5 |
List<Object> providersCopy = new ArrayList<>(); |
105 |
9 |
while (providers.hasNext()) { |
106 |
4 |
providersCopy.add(providers.next()); |
107 |
|
} |
108 |
|
|
109 |
5 |
for (Object provider : providersCopy) { |
110 |
4 |
registry.deregisterServiceProvider(provider); |
111 |
4 |
log.debug("Unregistered locally installed provider class: {}", provider.getClass()); |
112 |
|
} |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
119 |
|
static class LocalFilter implements ServiceRegistry.Filter { |
120 |
|
private final ClassLoader loader; |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
1 |
public LocalFilter(ClassLoader loader) {... |
123 |
1 |
this.loader = loader; |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
20 |
@Override... |
127 |
|
public boolean filter(Object provider) { |
128 |
20 |
return provider.getClass().getClassLoader() == loader; |
129 |
|
} |
130 |
|
} |
131 |
|
} |