1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.test; |
21 |
|
|
22 |
|
import java.io.InputStream; |
23 |
|
import java.io.UnsupportedEncodingException; |
24 |
|
import java.net.URL; |
25 |
|
import java.net.URLEncoder; |
26 |
|
import java.util.Collections; |
27 |
|
|
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.component.manager.ComponentManager; |
30 |
|
import org.xwiki.extension.Extension; |
31 |
|
import org.xwiki.extension.ExtensionDependency; |
32 |
|
import org.xwiki.extension.ExtensionId; |
33 |
|
import org.xwiki.extension.ExtensionNotFoundException; |
34 |
|
import org.xwiki.extension.ResolveException; |
35 |
|
import org.xwiki.extension.repository.AbstractExtensionRepository; |
36 |
|
import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor; |
37 |
|
import org.xwiki.extension.repository.ExtensionRepository; |
38 |
|
import org.xwiki.extension.repository.internal.ExtensionSerializer; |
39 |
|
import org.xwiki.extension.repository.internal.local.DefaultLocalExtension; |
40 |
|
import org.xwiki.extension.repository.result.CollectionIterableResult; |
41 |
|
import org.xwiki.extension.repository.result.IterableResult; |
42 |
|
import org.xwiki.extension.version.Version; |
43 |
|
import org.xwiki.extension.version.internal.DefaultVersion; |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 13 |
Complexity Density: 0.57 |
|
45 |
|
public class ResourceExtensionRepository extends AbstractExtensionRepository implements ExtensionRepository |
46 |
|
{ |
47 |
|
private ExtensionSerializer extensionSerializer; |
48 |
|
|
49 |
|
private ClassLoader classLoader; |
50 |
|
|
51 |
|
private String baseResource; |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
53 |
0 |
public ResourceExtensionRepository(ClassLoader classLoader, String baseResource, ComponentManager componentManager)... |
54 |
|
throws ComponentLookupException |
55 |
|
{ |
56 |
0 |
super(new DefaultExtensionRepositoryDescriptor("test-resources", "resources", null)); |
57 |
|
|
58 |
0 |
this.extensionSerializer = componentManager.getInstance(ExtensionSerializer.class); |
59 |
|
|
60 |
0 |
this.classLoader = classLoader; |
61 |
0 |
this.baseResource = baseResource; |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
InputStream getResourceAsStream(ExtensionId extensionId, String type) throws UnsupportedEncodingException... |
65 |
|
{ |
66 |
0 |
return this.classLoader.getResourceAsStream(getEncodedPath(extensionId, type)); |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0 |
URL getResource(ExtensionId extensionId, String type) throws UnsupportedEncodingException... |
70 |
|
{ |
71 |
0 |
return this.classLoader.getResource(getEncodedPath(extensionId, type)); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0 |
String getEncodedPath(ExtensionId extensionId, String type) throws UnsupportedEncodingException... |
75 |
|
{ |
76 |
0 |
return this.baseResource + URLEncoder.encode(getPathSuffix(extensionId, type), "UTF-8"); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
String getPathSuffix(ExtensionId extensionId, String type)... |
80 |
|
{ |
81 |
0 |
return extensionId.getId() + '-' + extensionId.getVersion().getValue() + '.' + type; |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.4 |
|
84 |
0 |
@Override... |
85 |
|
public Extension resolve(ExtensionId extensionId) throws ResolveException |
86 |
|
{ |
87 |
0 |
InputStream descriptor; |
88 |
0 |
try { |
89 |
0 |
descriptor = getResourceAsStream(extensionId, "xed"); |
90 |
|
} catch (UnsupportedEncodingException e) { |
91 |
0 |
throw new ResolveException("Invalid extension id [" + extensionId + "]", e); |
92 |
|
} |
93 |
|
|
94 |
0 |
if (descriptor == null) { |
95 |
0 |
throw new ExtensionNotFoundException("Extension [" + extensionId + "] not found"); |
96 |
|
} |
97 |
|
|
98 |
0 |
try { |
99 |
0 |
DefaultLocalExtension localExtension = |
100 |
|
this.extensionSerializer.loadLocalExtensionDescriptor(null, descriptor); |
101 |
|
|
102 |
0 |
return new ResourceExtension(this, localExtension); |
103 |
|
} catch (Exception e) { |
104 |
0 |
throw new ResolveException("Failed to parse descriptor for extension [" + extensionId + "]", e); |
105 |
|
} |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
@Override... |
109 |
|
public Extension resolve(ExtensionDependency extensionDependency) throws ResolveException |
110 |
|
{ |
111 |
0 |
return resolve(new ExtensionId(extensionDependency.getId(), |
112 |
|
new DefaultVersion(extensionDependency.getVersionConstraint().getValue()))); |
113 |
|
} |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
115 |
0 |
@Override... |
116 |
|
public boolean exists(ExtensionId extensionId) |
117 |
|
{ |
118 |
0 |
try { |
119 |
0 |
return getResource(extensionId, "xed") != null; |
120 |
|
} catch (UnsupportedEncodingException e) { |
121 |
0 |
return false; |
122 |
|
} |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0 |
@Override... |
126 |
|
public IterableResult<Version> resolveVersions(String id, int offset, int nb) throws ResolveException |
127 |
|
{ |
128 |
0 |
return new CollectionIterableResult<Version>(0, offset, Collections.<Version>emptyList()); |
129 |
|
} |
130 |
|
} |