1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.xwiki.internal; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.StringReader; |
24 |
|
import java.net.MalformedURLException; |
25 |
|
import java.net.URI; |
26 |
|
import java.net.URISyntaxException; |
27 |
|
import java.net.URL; |
28 |
|
import java.util.ArrayList; |
29 |
|
import java.util.Collection; |
30 |
|
import java.util.List; |
31 |
|
|
32 |
|
import org.apache.commons.io.IOUtils; |
33 |
|
import org.xwiki.extension.AbstractRatingExtension; |
34 |
|
import org.xwiki.extension.DefaultExtensionScm; |
35 |
|
import org.xwiki.extension.DefaultExtensionScmConnection; |
36 |
|
import org.xwiki.extension.Extension; |
37 |
|
import org.xwiki.extension.ExtensionId; |
38 |
|
import org.xwiki.extension.ExtensionLicense; |
39 |
|
import org.xwiki.extension.ExtensionLicenseManager; |
40 |
|
import org.xwiki.extension.internal.ExtensionFactory; |
41 |
|
import org.xwiki.extension.internal.ExtensionUtils; |
42 |
|
import org.xwiki.extension.rating.DefaultExtensionRating; |
43 |
|
import org.xwiki.extension.repository.ExtensionRepositoryDescriptor; |
44 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionAuthor; |
45 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency; |
46 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionIssueManagement; |
47 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating; |
48 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRepository; |
49 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm; |
50 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScmConnection; |
51 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion; |
52 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.License; |
53 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.Namespaces; |
54 |
|
import org.xwiki.extension.repository.xwiki.model.jaxb.Property; |
55 |
|
|
56 |
|
|
57 |
|
@link |
58 |
|
|
59 |
|
@version |
60 |
|
@since |
61 |
|
|
|
|
| 78.5% |
Uncovered Elements: 20 (93) |
Complexity: 20 |
Complexity Density: 0.31 |
|
62 |
|
public class XWikiExtension extends AbstractRatingExtension |
63 |
|
{ |
|
|
| 80% |
Uncovered Elements: 15 (75) |
Complexity: 14 |
Complexity Density: 0.25 |
|
64 |
67 |
public XWikiExtension(XWikiExtensionRepository repository, ExtensionVersion restExtension,... |
65 |
|
ExtensionLicenseManager licenseManager, ExtensionFactory factory) |
66 |
|
{ |
67 |
67 |
super(repository, new ExtensionId(restExtension.getId(), factory.getVersion(restExtension.getVersion())), |
68 |
|
restExtension.getType()); |
69 |
|
|
70 |
67 |
setName(restExtension.getName()); |
71 |
67 |
setSummary(restExtension.getSummary()); |
72 |
67 |
setWebsite(restExtension.getWebsite()); |
73 |
|
|
74 |
67 |
setDescription(restExtension.getDescription()); |
75 |
|
|
76 |
|
|
77 |
67 |
for (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId feature : restExtension |
78 |
|
.getExtensionFeatures()) { |
79 |
11 |
addExtensionFeature(new ExtensionId(feature.getId(), |
80 |
11 |
feature.getVersion() != null ? factory.getVersion(feature.getVersion()) : getId().getVersion())); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
67 |
ExtensionRating restRating = restExtension.getRating(); |
85 |
67 |
if (restRating != null) { |
86 |
67 |
setRating( |
87 |
|
new DefaultExtensionRating(restRating.getTotalVotes(), restRating.getAverageVote(), getRepository())); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
67 |
for (ExtensionAuthor restAuthor : restExtension.getAuthors()) { |
92 |
22 |
URL url; |
93 |
22 |
try { |
94 |
22 |
url = new URL(restAuthor.getUrl()); |
95 |
|
} catch (MalformedURLException e) { |
96 |
22 |
url = null; |
97 |
|
} |
98 |
|
|
99 |
22 |
addAuthor(factory.getExtensionAuthor(restAuthor.getName(), url)); |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
67 |
for (License restLicense : restExtension.getLicenses()) { |
105 |
56 |
if (restLicense.getName() != null) { |
106 |
11 |
ExtensionLicense extensionLicense = licenseManager.getLicense(restLicense.getName()); |
107 |
11 |
if (extensionLicense != null) { |
108 |
0 |
addLicense(extensionLicense); |
109 |
|
} else { |
110 |
11 |
List<String> content = null; |
111 |
11 |
if (restLicense.getContent() != null) { |
112 |
0 |
try { |
113 |
0 |
content = IOUtils.readLines(new StringReader(restLicense.getContent())); |
114 |
|
} catch (IOException e) { |
115 |
|
|
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
11 |
addLicense(new ExtensionLicense(restLicense.getName(), content)); |
120 |
|
} |
121 |
|
} |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
67 |
ExtensionScm restSCM = restExtension.getScm(); |
127 |
67 |
if (restSCM != null) { |
128 |
56 |
DefaultExtensionScmConnection connection = toDefaultExtensionScmConnection(restSCM.getConnection()); |
129 |
56 |
DefaultExtensionScmConnection developerConnection = |
130 |
|
toDefaultExtensionScmConnection(restSCM.getDeveloperConnection()); |
131 |
|
|
132 |
56 |
setScm(new DefaultExtensionScm(restSCM.getUrl(), connection, developerConnection)); |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
67 |
ExtensionIssueManagement restIssueManagement = restExtension.getIssueManagement(); |
138 |
67 |
if (restIssueManagement != null) { |
139 |
0 |
setIssueManagement( |
140 |
|
factory.getExtensionIssueManagement(restIssueManagement.getSystem(), restIssueManagement.getUrl())); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
67 |
setCategory(restExtension.getCategory()); |
145 |
|
|
146 |
|
|
147 |
67 |
Namespaces namespaces = restExtension.getAllowedNamespaces(); |
148 |
67 |
if (namespaces != null) { |
149 |
0 |
setAllowedNamespaces(namespaces.getNamespaces()); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
67 |
Boolean recommended = restExtension.isRecommended(); |
154 |
67 |
if (recommended != null) { |
155 |
58 |
setRecommended(restExtension.isRecommended()); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
67 |
for (Property restProperty : restExtension.getProperties()) { |
160 |
0 |
putProperty(restProperty.getKey(), restProperty.getStringValue()); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
67 |
if (repository != null) { |
165 |
67 |
addRepository(repository.getDescriptor()); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
67 |
for (ExtensionRepository restRepository : restExtension.getRepositories()) { |
170 |
0 |
try { |
171 |
0 |
addRepository(toExtensionRepositoryDescriptor(restRepository, factory)); |
172 |
|
} catch (URISyntaxException e) { |
173 |
|
|
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
67 |
setDependencies(toXWikiExtensionDependencies(restExtension.getDependencies(), factory)); |
179 |
|
|
180 |
|
|
181 |
67 |
setManagedDependencies(toXWikiExtensionDependencies(restExtension.getManagedDependencies(), factory)); |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
67 |
setFile(new XWikiExtensionFile(repository, getId())); |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
67 |
setName(ExtensionUtils.importProperty(this, Extension.FIELD_NAME, getName())); |
190 |
67 |
setSummary(ExtensionUtils.importProperty(this, Extension.FIELD_SUMMARY, getSummary())); |
191 |
66 |
setWebsite(ExtensionUtils.importProperty(this, Extension.FIELD_WEBSITE, getWebSite())); |
192 |
67 |
setAllowedNamespaces(ExtensionUtils.importProperty(this, Extension.FIELD_NAMESPACES, getAllowedNamespaces())); |
193 |
|
} |
194 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
195 |
134 |
private Collection<XWikiExtensionDependency> toXWikiExtensionDependencies(... |
196 |
|
List<ExtensionDependency> restDependencies, ExtensionFactory factory) |
197 |
|
{ |
198 |
134 |
List<XWikiExtensionDependency> newDependencies = new ArrayList<>(restDependencies.size()); |
199 |
|
|
200 |
134 |
for (ExtensionDependency dependency : restDependencies) { |
201 |
41 |
newDependencies.add(new XWikiExtensionDependency(dependency, |
202 |
41 |
this.repository != null ? this.repository.getDescriptor() : null, factory)); |
203 |
|
} |
204 |
|
|
205 |
134 |
return newDependencies; |
206 |
|
} |
207 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
208 |
112 |
protected static DefaultExtensionScmConnection toDefaultExtensionScmConnection(ExtensionScmConnection connection)... |
209 |
|
{ |
210 |
112 |
if (connection != null) { |
211 |
0 |
return new DefaultExtensionScmConnection(connection.getSystem(), connection.getPath()); |
212 |
|
} else { |
213 |
112 |
return null; |
214 |
|
} |
215 |
|
} |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
217 |
0 |
protected static ExtensionRepositoryDescriptor toExtensionRepositoryDescriptor(ExtensionRepository restRepository,... |
218 |
|
ExtensionFactory factory) throws URISyntaxException |
219 |
|
{ |
220 |
0 |
return factory.getExtensionRepositoryDescriptor(restRepository.getId(), restRepository.getType(), |
221 |
|
new URI(restRepository.getUri())); |
222 |
|
} |
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
181 |
@Override... |
225 |
|
public XWikiExtensionRepository getRepository() |
226 |
|
{ |
227 |
181 |
return (XWikiExtensionRepository) super.getRepository(); |
228 |
|
} |
229 |
|
} |