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.module.resources.setup; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.Path; |
37 |
|
import info.magnolia.cms.util.ClasspathResourcesUtil; |
38 |
|
import info.magnolia.jcr.util.NodeTypes; |
39 |
|
import info.magnolia.jcr.util.NodeTypes.Renderable; |
40 |
|
import info.magnolia.jcr.util.NodeUtil; |
41 |
|
import info.magnolia.module.InstallContext; |
42 |
|
import info.magnolia.module.delta.AbstractTask; |
43 |
|
import info.magnolia.module.delta.TaskExecutionException; |
44 |
|
import info.magnolia.module.resources.ResourceTypes; |
45 |
|
import info.magnolia.module.resources.ResourcesModule; |
46 |
|
|
47 |
|
import javax.jcr.Node; |
48 |
|
import javax.jcr.RepositoryException; |
49 |
|
import javax.jcr.Session; |
50 |
|
|
51 |
|
import org.apache.commons.lang3.StringUtils; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 93.4% |
Uncovered Elements: 4 (61) |
Complexity: 14 |
Complexity Density: 0.34 |
|
56 |
|
public class AbstractInstallResourceTask extends AbstractTask { |
57 |
|
|
58 |
|
protected final String resource; |
59 |
|
protected String template; |
60 |
|
protected String version; |
61 |
|
protected String source; |
62 |
|
protected String rights; |
63 |
|
protected Node node; |
64 |
|
protected String name; |
65 |
|
protected String extension; |
66 |
|
|
67 |
|
protected boolean preserveResourceParameters = false; |
68 |
|
protected boolean processed = true; |
69 |
|
private boolean stripExtension = false; |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
public AbstractInstallResourceTask(String resource, String version, String source, String rights, boolean preserveResourceParameters, boolean processed) {... |
72 |
0 |
this(resource, null, processed, version, source, rights, preserveResourceParameters); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
3 |
public AbstractInstallResourceTask(String resource, String template, boolean processed, String version, String source, String rights, boolean preserveResourceParameters) {... |
76 |
3 |
this(resource, template, processed, version, source, rights, preserveResourceParameters, true); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
79 |
19 |
public AbstractInstallResourceTask(String resource, String template, boolean processed, String version, String source, String rights, boolean preserveResourceParameters, boolean stripExtension) {... |
80 |
19 |
super("Install resource", "Copies the " + resource + " file to the resources workspace."); |
81 |
19 |
this.resource = resource; |
82 |
19 |
this.template = template; |
83 |
19 |
this.processed = processed; |
84 |
19 |
this.version = StringUtils.defaultString(version); |
85 |
19 |
this.source = StringUtils.defaultString(source); |
86 |
19 |
this.rights = StringUtils.defaultString(rights); |
87 |
19 |
this.preserveResourceParameters = preserveResourceParameters; |
88 |
19 |
this.stripExtension = stripExtension; |
89 |
|
} |
90 |
|
|
|
|
| 94.1% |
Uncovered Elements: 2 (34) |
Complexity: 7 |
Complexity Density: 0.29 |
|
91 |
19 |
@Override... |
92 |
|
public void execute(InstallContext installContext) throws TaskExecutionException { |
93 |
|
|
94 |
19 |
if (ClasspathResourcesUtil.getResource(resource) == null) { |
95 |
2 |
throw new TaskExecutionException("Can't find resource [" + resource + "] to install."); |
96 |
|
} |
97 |
|
|
98 |
17 |
try { |
99 |
17 |
name = StringUtils.substringAfterLast(resource, "/"); |
100 |
17 |
if (stripExtension) { |
101 |
12 |
name = StringUtils.substringBeforeLast(name, "."); |
102 |
12 |
extension = StringUtils.substringAfterLast(resource, "."); |
103 |
|
} |
104 |
17 |
String path = StringUtils.substringBeforeLast(resource, "/"); |
105 |
|
|
106 |
17 |
Session session = installContext.getJCRSession(ResourcesModule.DEFAULT_WORKSPACE); |
107 |
17 |
Node parent = NodeUtil.createPath(session.getRootNode(), path, NodeTypes.Folder.NAME); |
108 |
17 |
node = NodeUtil.createPath(parent, Path.getValidatedLabel(name), NodeTypes.Content.NAME); |
109 |
|
|
110 |
17 |
if (this.preserveResourceParameters) { |
111 |
1 |
this.version = this.getProperty("version"); |
112 |
1 |
this.source = this.getProperty("source"); |
113 |
1 |
this.rights = this.getProperty("rights"); |
114 |
1 |
this.template = Renderable.getTemplate(node); |
115 |
|
} |
116 |
|
|
117 |
17 |
String template = StringUtils.isNotEmpty(this.template) ? this.template : ResourceTypes.determineType(this.resource, this.processed); |
118 |
17 |
Renderable.set(node, template); |
119 |
|
|
120 |
17 |
if (StringUtils.isNotBlank(extension)) { |
121 |
12 |
this.setProperty("extension", extension); |
122 |
|
} |
123 |
17 |
this.setProperty("version", version); |
124 |
17 |
this.setProperty("source", source); |
125 |
17 |
this.setProperty("rights", rights); |
126 |
|
|
127 |
|
} catch (Exception e) { |
128 |
0 |
throw new TaskExecutionException("Can't install resource [" + resource + "]", e); |
129 |
|
} |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
132 |
77 |
protected void setProperty(String name, String value) throws RepositoryException {... |
133 |
77 |
if (node.hasProperty(name)) { |
134 |
3 |
node.getProperty(name).setValue(value); |
135 |
|
} else { |
136 |
74 |
node.setProperty(name, value); |
137 |
|
} |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
140 |
4 |
protected String getProperty(String name) throws RepositoryException {... |
141 |
4 |
if (node.hasProperty(name)) { |
142 |
1 |
return node.getProperty(name).getString(); |
143 |
|
} |
144 |
3 |
return null; |
145 |
|
} |
146 |
|
|
147 |
|
} |