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