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 org.apache.commons.lang3.StringUtils;
28 import org.apache.maven.execution.MavenSession;
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.plugins.annotations.Component;
32 import org.apache.maven.plugins.annotations.Parameter;
33 import org.apache.maven.settings.crypto.SettingsDecrypter;
34
35 import io.wcm.tooling.commons.packmgr.PackageManagerProperties;
36 import io.wcm.tooling.commons.packmgr.install.VendorInstallerFactory;
37 import io.wcm.tooling.commons.packmgr.install.VendorInstallerFactory.Service;
38
39
40
41
42 abstract class AbstractContentPackageMojo extends AbstractMojo {
43
44 private static final String CONSOLE_URL = "/system/console";
45
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 @Parameter(property = "vault.bundleStatusURL", required = false)
135 private String bundleStatusURL;
136
137
138
139
140
141 @Parameter(property = "vault.bundleStatusWaitLimit", defaultValue = "360")
142 private int bundleStatusWaitLimit;
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 @Parameter(property = "vault.packageManagerInstallStatusURL", required = false)
161 private String packageManagerInstallStatusURL;
162
163
164
165
166
167
168 @Parameter(property = "vault.packageManagerInstallStatusWaitLimit", defaultValue = "360")
169 private int packageManagerInstallStatusWaitLimit;
170
171
172
173
174
175
176 @Parameter(property = "vault.bundleStatusBlacklistBundleNames", defaultValue = "^updater\\.aem.*$")
177 private String[] bundleStatusBlacklistBundleNames;
178
179
180
181
182
183 @Parameter(property = "vault.bundleStatusWhitelistBundleNames",
184 defaultValue = "^com\\.day\\.crx\\.crxde-support$,"
185 + "^com\\.adobe\\.granite\\.crx-explorer$,"
186 + "^com\\.adobe\\.granite\\.crxde-lite$,"
187 + "^org\\.apache\\.sling\\.jcr\\.webdav$,"
188 + "^org\\.apache\\.sling\\.jcr\\.davex$")
189 private String[] bundleStatusWhitelistBundleNames;
190
191
192
193
194 @Parameter(property = "vault.relaxedSSLCheck", defaultValue = "false")
195 private boolean relaxedSSLCheck;
196
197
198
199
200 @Parameter(property = "vault.httpConnectTimeoutSec", defaultValue = "10")
201 private int httpConnectTimeoutSec;
202
203
204
205
206 @Parameter(property = "vault.httpSocketTimeoutSec", defaultValue = "60")
207 private int httpSocketTimeout;
208
209
210
211
212
213 @Parameter(property = "vault.packageManagerOutputLogLevel", defaultValue = "INFO")
214 private String packageManagerOutputLogLevel;
215
216 @Parameter(property = "session", defaultValue = "${session}", readonly = true)
217 private MavenSession session;
218
219 @Component(role = SettingsDecrypter.class)
220 private SettingsDecrypter decrypter;
221
222 protected final boolean isSkip() {
223 return this.skip;
224 }
225
226 protected PackageManagerProperties getPackageManagerProperties() throws MojoExecutionException {
227 PackageManagerProperties props = new PackageManagerProperties();
228
229 props.setPackageManagerUrl(buildPackageManagerUrl());
230 props.setUserId(this.userId);
231 props.setPassword(this.password);
232 props.setOAuth2AccessToken(this.oauth2AccessToken);
233 props.setConsoleUserId(this.consoleUserId);
234 props.setConsolePassword(this.consolePassword);
235 props.setConsoleOAuth2AccessToken(this.consoleOauth2AccessToken);
236 props.setRetryCount(this.retryCount);
237 props.setRetryDelaySec(this.retryDelay);
238 props.setBundleStatusUrl(buildBundleStatusUrl());
239 props.setBundleStatusWaitLimitSec(this.bundleStatusWaitLimit);
240 props.setBundleStatusBlacklistBundleNames(List.of(this.bundleStatusBlacklistBundleNames));
241 props.setBundleStatusWhitelistBundleNames(List.of(this.bundleStatusWhitelistBundleNames));
242 props.setPackageManagerInstallStatusURL(buildPackageManagerInstallStatusUrl());
243 props.setPackageManagerInstallStatusWaitLimitSec(this.packageManagerInstallStatusWaitLimit);
244 props.setRelaxedSSLCheck(this.relaxedSSLCheck);
245 props.setHttpConnectTimeoutSec(this.httpConnectTimeoutSec);
246 props.setHttpSocketTimeoutSec(this.httpSocketTimeout);
247 props.setProxies(ProxySupport.getMavenProxies(session, decrypter));
248 props.setPackageManagerOutputLogLevel(this.packageManagerOutputLogLevel);
249
250 return props;
251 }
252
253 private String buildPackageManagerUrl() throws MojoExecutionException {
254 String serviceUrl = this.serviceURL;
255 switch (VendorInstallerFactory.identify(serviceUrl)) {
256 case CRX:
257 serviceUrl = VendorInstallerFactory.getBaseUrl(serviceUrl) + CRX_URL;
258 break;
259 case COMPOSUM:
260 serviceUrl = VendorInstallerFactory.getBaseUrl(serviceUrl) + COMPOSUM_URL;
261 break;
262 default:
263 throw new MojoExecutionException("Unsupported service URL: " + serviceUrl);
264 }
265 return serviceUrl;
266 }
267
268 private String buildBundleStatusUrl() throws MojoExecutionException {
269 if (StringUtils.equals(this.bundleStatusURL, "-")) {
270 return null;
271 }
272 if (this.bundleStatusURL != null) {
273 return this.bundleStatusURL;
274 }
275
276 String baseUrl = VendorInstallerFactory.getBaseUrl(buildPackageManagerUrl());
277 return baseUrl + "/system/console/bundles/.json";
278 }
279
280 private String buildPackageManagerInstallStatusUrl() throws MojoExecutionException {
281 if (StringUtils.equals(this.packageManagerInstallStatusURL, "-")
282 || VendorInstallerFactory.identify(this.serviceURL) != Service.CRX) {
283 return null;
284 }
285 if (this.packageManagerInstallStatusURL != null) {
286 return this.packageManagerInstallStatusURL;
287 }
288
289 String baseUrl = VendorInstallerFactory.getBaseUrl(buildPackageManagerUrl());
290 return baseUrl + "/crx/packmgr/installstatus.jsp";
291 }
292
293 protected String buildConsoleUrl() {
294 return VendorInstallerFactory.getBaseUrl(this.serviceURL) + CONSOLE_URL;
295 }
296
297 protected String getConsoleUser() {
298 return this.consoleUserId;
299 }
300
301 protected String getConsolePassword() {
302 return this.consolePassword;
303 }
304
305 }