1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.devops.conga.plugins.aem.maven;
21
22 import static io.wcm.tooling.commons.packmgr.install.VendorInstallerFactory.COMPOSUM_URL;
23 import static io.wcm.tooling.commons.packmgr.install.VendorInstallerFactory.CRX_URL;
24
25 import java.util.List;
26
27 import javax.inject.Inject;
28
29 import org.apache.commons.lang3.StringUtils;
30 import org.apache.maven.execution.MavenSession;
31 import org.apache.maven.plugin.AbstractMojo;
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.plugins.annotations.Parameter;
34 import org.apache.maven.settings.crypto.SettingsDecrypter;
35
36 import io.wcm.tooling.commons.packmgr.PackageManagerProperties;
37 import io.wcm.tooling.commons.packmgr.install.VendorInstallerFactory;
38 import io.wcm.tooling.commons.packmgr.install.VendorInstallerFactory.Service;
39
40
41
42
43 abstract class AbstractContentPackageMojo extends AbstractMojo {
44
45 private static final String CONSOLE_URL = "/system/console";
46
47
48
49
50
51
52
53
54
55
56 @Parameter(property = "vault.serviceURL", required = true, defaultValue = "http://localhost:4502/crx/packmgr/service")
57 private String serviceURL;
58
59
60
61
62 @Parameter(property = "vault.userId", defaultValue = "admin")
63 private String userId;
64
65
66
67
68 @Parameter(property = "vault.password", defaultValue = "admin")
69 private String password;
70
71
72
73
74
75 @Parameter(property = "vault.oauth2AccessToken")
76 private String oauth2AccessToken;
77
78
79
80
81
82 @Parameter(property = "console.userId")
83 private String consoleUserId;
84
85
86
87
88
89 @Parameter(property = "console.password")
90
91 private String consolePassword;
92
93
94
95
96
97 @Parameter(property = "console.consoleOauth2AccessToken")
98 private String consoleOauth2AccessToken;
99
100
101
102
103 @Parameter(property = "vault.skip", defaultValue = "false")
104 private boolean skip;
105
106
107
108
109 @Parameter(property = "vault.retryCount", defaultValue = "24")
110 private int retryCount;
111
112
113
114
115 @Parameter(property = "vault.retryDelay", defaultValue = "5")
116 private int retryDelay;
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 @Parameter(property = "vault.bundleStatusURL", required = false)
136 private String bundleStatusURL;
137
138
139
140
141
142 @Parameter(property = "vault.bundleStatusWaitLimit", defaultValue = "360")
143 private int bundleStatusWaitLimit;
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 @Parameter(property = "vault.packageManagerInstallStatusURL", required = false)
163 private String packageManagerInstallStatusURL;
164
165
166
167
168
169
170 @Parameter(property = "vault.packageManagerInstallStatusWaitLimit", defaultValue = "360")
171 private int packageManagerInstallStatusWaitLimit;
172
173
174
175
176
177
178 @Parameter(property = "vault.bundleStatusBlacklistBundleNames", defaultValue = "^updater\\.aem.*$")
179 private String[] bundleStatusBlacklistBundleNames;
180
181
182
183
184
185 @Parameter(property = "vault.bundleStatusWhitelistBundleNames",
186 defaultValue = "^com\\.day\\.crx\\.crxde-support$,"
187 + "^com\\.adobe\\.granite\\.crx-explorer$,"
188 + "^com\\.adobe\\.granite\\.crxde-lite$,"
189 + "^org\\.apache\\.sling\\.jcr\\.webdav$,"
190 + "^org\\.apache\\.sling\\.jcr\\.davex$")
191 private String[] bundleStatusWhitelistBundleNames;
192
193
194
195
196 @Parameter(property = "vault.relaxedSSLCheck", defaultValue = "false")
197 private boolean relaxedSSLCheck;
198
199
200
201
202 @Parameter(property = "vault.httpConnectTimeoutSec", defaultValue = "10")
203 private int httpConnectTimeoutSec;
204
205
206
207
208 @Parameter(property = "vault.httpSocketTimeoutSec", defaultValue = "60")
209 private int httpSocketTimeout;
210
211
212
213
214
215 @Parameter(property = "vault.packageManagerOutputLogLevel", defaultValue = "INFO")
216 private String packageManagerOutputLogLevel;
217
218 @Parameter(property = "session", defaultValue = "${session}", readonly = true)
219 private MavenSession session;
220
221 @Inject
222 private SettingsDecrypter decrypter;
223
224 protected final boolean isSkip() {
225 return this.skip;
226 }
227
228 protected PackageManagerProperties getPackageManagerProperties() throws MojoExecutionException {
229 PackageManagerProperties props = new PackageManagerProperties();
230
231 props.setPackageManagerUrl(buildPackageManagerUrl());
232 props.setUserId(this.userId);
233 props.setPassword(this.password);
234 props.setOAuth2AccessToken(this.oauth2AccessToken);
235 props.setConsoleUserId(this.consoleUserId);
236 props.setConsolePassword(this.consolePassword);
237 props.setConsoleOAuth2AccessToken(this.consoleOauth2AccessToken);
238 props.setRetryCount(this.retryCount);
239 props.setRetryDelaySec(this.retryDelay);
240 props.setBundleStatusUrl(buildBundleStatusUrl());
241 props.setBundleStatusWaitLimitSec(this.bundleStatusWaitLimit);
242 props.setBundleStatusBlacklistBundleNames(List.of(this.bundleStatusBlacklistBundleNames));
243 props.setBundleStatusWhitelistBundleNames(List.of(this.bundleStatusWhitelistBundleNames));
244 props.setPackageManagerInstallStatusURL(buildPackageManagerInstallStatusUrl());
245 props.setPackageManagerInstallStatusWaitLimitSec(this.packageManagerInstallStatusWaitLimit);
246 props.setRelaxedSSLCheck(this.relaxedSSLCheck);
247 props.setHttpConnectTimeoutSec(this.httpConnectTimeoutSec);
248 props.setHttpSocketTimeoutSec(this.httpSocketTimeout);
249 props.setProxies(ProxySupport.getMavenProxies(session, decrypter));
250 props.setPackageManagerOutputLogLevel(this.packageManagerOutputLogLevel);
251
252 return props;
253 }
254
255 private String buildPackageManagerUrl() throws MojoExecutionException {
256 String serviceUrl = this.serviceURL;
257 switch (VendorInstallerFactory.identify(serviceUrl)) {
258 case CRX:
259 serviceUrl = VendorInstallerFactory.getBaseUrl(serviceUrl) + CRX_URL;
260 break;
261 case COMPOSUM:
262 serviceUrl = VendorInstallerFactory.getBaseUrl(serviceUrl) + COMPOSUM_URL;
263 break;
264 default:
265 throw new MojoExecutionException("Unsupported service URL: " + serviceUrl);
266 }
267 return serviceUrl;
268 }
269
270 private String buildBundleStatusUrl() throws MojoExecutionException {
271 if (StringUtils.equals(this.bundleStatusURL, "-")) {
272 return null;
273 }
274 if (this.bundleStatusURL != null) {
275 return this.bundleStatusURL;
276 }
277
278 String baseUrl = VendorInstallerFactory.getBaseUrl(buildPackageManagerUrl());
279 return baseUrl + "/system/console/bundles/.json";
280 }
281
282 private String buildPackageManagerInstallStatusUrl() throws MojoExecutionException {
283 if (StringUtils.equals(this.packageManagerInstallStatusURL, "-")
284 || VendorInstallerFactory.identify(this.serviceURL) != Service.CRX) {
285 return null;
286 }
287 if (this.packageManagerInstallStatusURL != null) {
288 return this.packageManagerInstallStatusURL;
289 }
290
291 String baseUrl = VendorInstallerFactory.getBaseUrl(buildPackageManagerUrl());
292 return baseUrl + "/crx/packmgr/installstatus.jsp";
293 }
294
295 protected String buildConsoleUrl() {
296 return VendorInstallerFactory.getBaseUrl(this.serviceURL) + CONSOLE_URL;
297 }
298
299 protected String getConsoleUser() {
300 return this.consoleUserId;
301 }
302
303 protected String getConsolePassword() {
304 return this.consolePassword;
305 }
306
307 }