1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.repository.script; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.context.Execution; |
28 |
|
import org.xwiki.extension.ExtensionException; |
29 |
|
import org.xwiki.extension.repository.ExtensionRepository; |
30 |
|
import org.xwiki.extension.repository.ExtensionRepositoryManager; |
31 |
|
import org.xwiki.extension.version.Version; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.repository.internal.RepositoryManager; |
34 |
|
import org.xwiki.script.service.ScriptService; |
35 |
|
|
36 |
|
@Component |
37 |
|
@Named("repository") |
38 |
|
@Singleton |
|
|
| 45% |
Uncovered Elements: 11 (20) |
Complexity: 7 |
Complexity Density: 0.5 |
|
39 |
|
public class RepositoryScriptService implements ScriptService |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
private static final String REPOSITORYERROR_KEY = "scriptservice.repository.error"; |
45 |
|
|
46 |
|
@Inject |
47 |
|
private RepositoryManager repositoryManager; |
48 |
|
|
49 |
|
@Inject |
50 |
|
private ExtensionRepositoryManager extensionRepositoryManager; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@Inject |
56 |
|
private Execution execution; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
61 |
|
@param |
62 |
|
@see |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
2 |
private void setError(Exception e)... |
65 |
|
{ |
66 |
2 |
this.execution.getContext().setProperty(REPOSITORYERROR_KEY, e); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
@return |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0 |
public Exception getLastError()... |
75 |
|
{ |
76 |
0 |
return (Exception) this.execution.getContext().getProperty(REPOSITORYERROR_KEY); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
79 |
0 |
public void validateExtensions()... |
80 |
|
{ |
81 |
0 |
setError(null); |
82 |
|
|
83 |
0 |
try { |
84 |
0 |
this.repositoryManager.validateExtensions(); |
85 |
|
} catch (Exception e) { |
86 |
0 |
setError(e); |
87 |
|
} |
88 |
|
} |
89 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
90 |
2 |
public DocumentReference importExtension(String extensionId, String repositoryId)... |
91 |
|
{ |
92 |
2 |
setError(null); |
93 |
|
|
94 |
2 |
try { |
95 |
2 |
ExtensionRepository repository = this.extensionRepositoryManager.getRepository(repositoryId); |
96 |
|
|
97 |
2 |
if (repository == null) { |
98 |
0 |
throw new ExtensionException("Can't find any registered repository with id [" + repositoryId + "]"); |
99 |
|
} |
100 |
|
|
101 |
2 |
return this.repositoryManager.importExtension(extensionId, repository, Version.Type.STABLE); |
102 |
|
} catch (Exception e) { |
103 |
0 |
setError(e); |
104 |
|
} |
105 |
|
|
106 |
0 |
return null; |
107 |
|
} |
108 |
|
} |