LibsInstaller.java
5 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.io.IOUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.installer.api.tasks.InstallTask
* org.apache.sling.installer.api.tasks.InstallTaskFactory
* org.apache.sling.installer.api.tasks.RegisteredResource
* org.apache.sling.installer.api.tasks.ResourceTransformer
* org.apache.sling.installer.api.tasks.TaskResource
* org.apache.sling.installer.api.tasks.TaskResourceGroup
* org.apache.sling.installer.api.tasks.TransformationResult
* org.apache.sling.settings.SlingSettingsService
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.core.libinstaller.internal;
import com.adobe.fd.core.libinstaller.internal.InstallLibsTask;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.installer.api.tasks.InstallTask;
import org.apache.sling.installer.api.tasks.InstallTaskFactory;
import org.apache.sling.installer.api.tasks.RegisteredResource;
import org.apache.sling.installer.api.tasks.ResourceTransformer;
import org.apache.sling.installer.api.tasks.TaskResource;
import org.apache.sling.installer.api.tasks.TaskResourceGroup;
import org.apache.sling.installer.api.tasks.TransformationResult;
import org.apache.sling.settings.SlingSettingsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class LibsInstaller
implements ResourceTransformer,
InstallTaskFactory {
public static final String AEMFD_ARTIFACT_TYPE = "AEMFD-Artifact-Type";
public static final String AEMFD_ARTIFACT_NAME = "AEMFD-Artifact-Name";
private static final String ARTIFACT_TYPE_LIBS = "libs";
private final Logger logger;
@Reference
private SlingSettingsService settingsService;
public LibsInstaller() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
public TransformationResult[] transform(RegisteredResource resource) {
if (resource.getType().equals("file")) {
try {
Manifest m = this.getManifest(resource.getInputStream());
if (m != null) {
String artifactTypeCode = m.getMainAttributes().getValue("AEMFD-Artifact-Type");
TransformationResult tr = null;
if ("libs".equalsIgnoreCase(artifactTypeCode)) {
tr = this.transformAsLibs(resource, m);
}
if (tr != null) {
return new TransformationResult[]{tr};
}
}
}
catch (IOException ignore) {
this.logger.warn("Error transforming resource " + resource.getURL(), (Throwable)ignore);
}
}
return null;
}
private TransformationResult transformAsLibs(RegisteredResource resource, Manifest m) {
HashMap attr = new HashMap();
String name = m.getMainAttributes().getValue("AEMFD-Artifact-Name");
if (name == null) {
this.logger.warn("AEMFD artifact name (AEMFD-Artifact-Name) not specified for resource ", (Object)resource);
return null;
}
TransformationResult tr = new TransformationResult();
tr.setId(name);
tr.setResourceType("libs");
tr.setAttributes(attr);
return tr;
}
public InstallTask createTask(TaskResourceGroup toActivate) {
String typeCode = toActivate.getActiveResource().getType();
if ("libs".equalsIgnoreCase(typeCode)) {
return new InstallLibsTask(toActivate, this.settingsService);
}
return null;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private Manifest getManifest(InputStream ins) throws IOException {
Manifest result = null;
if (ins != null) {
JarInputStream jis = null;
try {
jis = new JarInputStream(ins);
result = jis.getManifest();
}
finally {
if (jis != null) {
IOUtils.closeQuietly((InputStream)jis);
} else {
IOUtils.closeQuietly((InputStream)ins);
}
}
}
return result;
}
protected void bindSettingsService(SlingSettingsService slingSettingsService) {
this.settingsService = slingSettingsService;
}
protected void unbindSettingsService(SlingSettingsService slingSettingsService) {
if (this.settingsService == slingSettingsService) {
this.settingsService = null;
}
}
}