Cq53StartupCodeUpgrade.java
7.24 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Session
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.sling.commons.osgi.PropertiesUtil
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.cq53;
import com.day.cq.compat.codeupgrade.CodeUpgradeTask;
import com.day.cq.compat.codeupgrade.impl.StatusNode;
import com.day.cq.compat.codeupgrade.impl.UpgradeNodetypes;
import com.day.cq.compat.codeupgrade.impl.cq53.UpgradeDamAssetContent;
import com.day.cq.compat.codeupgrade.internal.api.CodeUpgrader;
import com.day.cq.compat.codeupgrade.internal.api.CodeUpgraderFactory;
import com.day.cq.compat.codeupgrade.internal.api.NodeBackup;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import java.io.Writer;
import java.util.Dictionary;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class Cq53StartupCodeUpgrade
implements CodeUpgradeTask {
@Property(value={"/apps", "/etc/designs", "/etc/replication", "/etc/security", "/var/linkchecker", "/etc/workflow"})
public static final String PROP_PATHS_TO_UPGRADE = "paths.to.upgrade";
public static final String DEFAULT_CONFIG_PATH = "/libs/cq/compat/components/codeupgrade/5.3";
@Property(value={"/libs/cq/compat/components/codeupgrade/5.3"})
public static final String PROP_CONFIG_PATH = "upgrade.configuration.path";
public static final int DEFAULT_MAX_FILE_SIZE = 100000;
@Property(intValue={100000})
public static final String PROP_MAX_FILE_SIZE = "max.file.size";
public static final String DEFAULT_FILE_ACCEPT_REGEXP = "^[a-zA-Z0-9_].*\\.(jsp|jspf|jspx|esp|jst|ecma|js)$";
@Property(value={"^[a-zA-Z0-9_].*\\.(jsp|jspf|jspx|esp|jst|ecma|js)$"})
public static final String PROP_FILE_ACCEPT_REGEXP = "file.accept.regexp";
@Property(value={"/var/upgrade/status"})
public static final String PROP_STATUS_NODE_PATH = "status.node.path";
@Property(value={"Cq53StartupCodeUpgrade"})
public static final String PROP_STATUS_PROPERTY_NAME = "status.property.name";
private final Logger log;
private String[] pathsToUpgrade;
private String configPath;
private int maxFilesSize;
private String fileAcceptRegexp;
private ProgressInfoProvider infoProvider;
private String progressInfo;
@Reference
private SlingRepository repository;
@Reference
private CodeUpgraderFactory codeUpgraderFactory;
private CodeUpgrader upgrader;
private ComponentContext componentContext;
private StatusNode statusNode;
Cq53StartupCodeUpgrade() {
this.log = LoggerFactory.getLogger(this.getClass());
this.progressInfo = "No info yet";
}
public String toString() {
return this.getClass().getSimpleName();
}
public void activate(ComponentContext ctx) throws Exception {
this.componentContext = ctx;
}
public void deactivate(ComponentContext ctx) throws InterruptedException {
this.componentContext = null;
if (this.upgrader != null) {
this.upgrader.stop();
}
this.upgrader = null;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void run() {
long start = System.currentTimeMillis();
Session s = null;
try {
s = this.repository.loginService("compat-codeupgrade", null);
this.doUpgrade(s);
this.statusNode.recordUpgrade(this.repository);
}
catch (Exception e) {
this.log.error("Code upgrade error", (Throwable)e);
}
finally {
if (s != null) {
s.logout();
}
}
this.log.info("Code upgrade done, took {} msec", (Object)(System.currentTimeMillis() - start));
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void doUpgrade(Session s) throws Exception {
this.progressInfo = "Starting upgrade";
if (this.pathsToUpgrade == null) {
throw new IllegalStateException("pathsToUpgrade is null");
}
NodeBackup b = this.codeUpgraderFactory.createNodeBackup();
for (String path : this.pathsToUpgrade) {
long start = System.currentTimeMillis();
this.upgrader = this.codeUpgraderFactory.createUpgrader(s, this.configPath);
Cq53StartupCodeUpgrade cq53StartupCodeUpgrade = this;
synchronized (cq53StartupCodeUpgrade) {
this.infoProvider = this.upgrader;
}
this.upgrader.setMaxFileSize(this.maxFilesSize);
this.upgrader.setFileAcceptRegexp(this.fileAcceptRegexp);
this.log.info("Upgrader configured, max file size={}, file accept regexp={}", (Object)this.upgrader.getMaxFileSize(), (Object)this.upgrader.getFileAcceptRegexp());
this.upgrader.upgrade(s, path, b, null);
this.log.info("Done upgrading path {} (took {} msec)", (Object)path, (Object)(System.currentTimeMillis() - start));
}
Object udac = new UpgradeDamAssetContent();
Cq53StartupCodeUpgrade len$ = this;
synchronized (len$) {
this.infoProvider = udac;
}
udac.doUpgrade(s);
udac = this;
synchronized (udac) {
this.infoProvider = null;
}
this.progressInfo = "Upgrading node types";
new UpgradeNodetypes().doUpgrade(s, this.configPath + "/nodetypes.cnd");
this.progressInfo = "All done";
}
@Override
public void cancelUpgrade() {
if (this.upgrader != null) {
this.log.info("Calling upgrader.stop() to cancel upgrade...");
this.upgrader.stop();
}
}
@Override
public synchronized String getProgressInfo() {
if (this.infoProvider == null) {
return this.progressInfo;
}
return this.infoProvider.getProgressInfo();
}
@Override
public boolean upgradeNeeded() {
boolean upgradeNeeded = false;
Dictionary properties = this.componentContext.getProperties();
this.statusNode = new StatusNode((String)properties.get("status.node.path"), (String)properties.get("status.property.name"));
upgradeNeeded = this.statusNode.upgradeNeeded(this.repository);
if (upgradeNeeded) {
this.pathsToUpgrade = PropertiesUtil.toStringArray(properties.get("paths.to.upgrade"));
this.configPath = PropertiesUtil.toString(properties.get("upgrade.configuration.path"), (String)"/libs/cq/compat/components/codeupgrade/5.3");
this.maxFilesSize = PropertiesUtil.toInteger(properties.get("max.file.size"), (int)100000);
this.fileAcceptRegexp = PropertiesUtil.toString(properties.get("file.accept.regexp"), (String)"^[a-zA-Z0-9_].*\\.(jsp|jspf|jspx|esp|jst|ecma|js)$");
}
return upgradeNeeded;
}
}