InstallLibsTask.java
4.19 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.io.FileUtils
* org.apache.commons.io.IOUtils
* org.apache.sling.installer.api.tasks.InstallTask
* org.apache.sling.installer.api.tasks.InstallationContext
* org.apache.sling.installer.api.tasks.ResourceState
* org.apache.sling.installer.api.tasks.TaskResource
* org.apache.sling.installer.api.tasks.TaskResourceGroup
* 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.JarSupport;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.sling.installer.api.tasks.InstallTask;
import org.apache.sling.installer.api.tasks.InstallationContext;
import org.apache.sling.installer.api.tasks.ResourceState;
import org.apache.sling.installer.api.tasks.TaskResource;
import org.apache.sling.installer.api.tasks.TaskResourceGroup;
import org.apache.sling.settings.SlingSettingsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InstallLibsTask
extends InstallTask {
private static final String LIBS_DIR = "launchpad/ext";
private static final String INSTALL_ORDER = "999-";
private static final Logger logger = LoggerFactory.getLogger(InstallLibsTask.class);
private SlingSettingsService slingSettingsService;
public InstallLibsTask(TaskResourceGroup erl, SlingSettingsService slingSettingsService) {
super(erl);
this.slingSettingsService = slingSettingsService;
try {
InstallLibsTask.class.getClassLoader().loadClass(JarSupport.class.getName());
}
catch (ClassNotFoundException e) {
logger.warn("Error while loading class ", (Throwable)e);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void execute(InstallationContext ctx) {
block7 : {
TaskResource tr = this.getResource();
if (tr.getState() == ResourceState.INSTALL) {
InputStream is = null;
try {
is = tr.getInputStream();
if (is == null) {
logger.error("Resource {} does not provide an input stream!", (Object)tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
break block7;
}
File libsDir = this.getLibsDir();
this.unpackResources(is, libsDir);
ctx.log("Installed libs at {}", new Object[]{libsDir});
logger.debug("Installed libs at {}", (Object)libsDir);
this.getResourceGroup().setFinishState(ResourceState.INSTALLED);
}
catch (Exception e) {
logger.error("Unable to install libs from resource " + (Object)tr, (Throwable)e);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
}
finally {
IOUtils.closeQuietly((InputStream)is);
}
}
this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void unpackResources(InputStream is, File libsDir) throws IOException {
JarSupport inputJar = null;
try {
inputJar = new JarSupport(is);
inputJar.extractAll(libsDir);
inputJar.close();
}
finally {
if (inputJar != null) {
inputJar.close();
}
}
}
private File getLibsDir() throws IOException {
String slingHome = this.slingSettingsService.getSlingHomePath();
File libsDir = new File(slingHome, "launchpad/ext");
if (!libsDir.exists()) {
FileUtils.forceMkdir((File)libsDir);
}
return libsDir;
}
public String getSortKey() {
return "999-" + this.getResource().getURL();
}
}