27
27
import static org .junit .jupiter .api .Assertions .assertTrue ;
28
28
29
29
/**
30
- * Implementation of actions that createArchive an application archive file.
30
+ * Implementation of actions that createArchive an application archive file.
31
31
*/
32
-
33
32
public class WDTArchiveHelper {
34
-
33
+
35
34
private AppParams params ;
36
35
37
36
/**
38
37
* Create an AppParams instance with the default values.
39
- * @return an AppParams instance
38
+ *
39
+ * @return an AppParams instance
40
40
*/
41
41
public static AppParams defaultAppParams () {
42
42
return new AppParams ().defaults ();
43
43
}
44
44
45
45
/**
46
46
* Create an AppParams instance with the custom values.
47
+ *
47
48
* @return an AppParams instance
48
49
*/
49
50
public static AppParams customAppParams (List <String > srcDirList ) {
@@ -52,9 +53,9 @@ public static AppParams customAppParams(List<String> srcDirList) {
52
53
53
54
/**
54
55
* Set up the AppBuilder with given parameters.
55
- *
56
+ *
56
57
* @param params instance of {@link AppParams} that contains parameters to createArchive an application archive
57
- * @return the AppBuilder instance
58
+ * @return the AppBuilder instance
58
59
*/
59
60
public static WDTArchiveHelper withParams (AppParams params ) {
60
61
return new WDTArchiveHelper ().params (params );
@@ -82,10 +83,10 @@ public boolean createArchive(boolean structuredApplication) throws IOException {
82
83
checkDirectory (archiveSrcDir );
83
84
for (String item : params .srcDirList ()) {
84
85
copyFolder (
85
- APP_DIR + "/" + item ,
86
+ APP_DIR + "/" + item ,
86
87
archiveSrcDir );
87
88
}
88
- } catch (IOException ioe ) {
89
+ } catch (IOException ioe ) {
89
90
getLogger ().severe ("Failed to get the directory " + archiveSrcDir + " ready" , ioe );
90
91
return false ;
91
92
}
@@ -100,7 +101,7 @@ public boolean createArchive(boolean structuredApplication) throws IOException {
100
101
String jarPath = String .format ("%s.ear" , params .appName ());
101
102
jarBuilt = buildJarArchive (jarPath , archiveSrcDir );
102
103
}
103
-
104
+
104
105
// createArchive a zip file that can be passed to WIT
105
106
String zipPath = String .format ("%s/%s.zip" , params .appArchiveDir (), params .appName ());
106
107
boolean zipBuilt = buildZipArchive (zipPath , params .appArchiveDir ());
@@ -132,19 +133,57 @@ public boolean addToArchive() throws IOException {
132
133
return createArchive ();
133
134
}
134
135
}
135
-
136
+
136
137
/**
137
138
* Build an application archive using a pre-populated AppParams instance.
138
- * @return true if the command succeeds
139
+ *
140
+ * @return true if the command succeeds
139
141
* @throws java.io.IOException when WDT download fails
140
142
*/
141
- public boolean createArchiveWithStructuredApplication () throws IOException {
142
- return createArchive (true );
143
+ public boolean createArchiveWithStructuredApplication (String archiveName ) throws IOException {
144
+ // check and install WDT
145
+ checkAndInstallWDT ();
146
+ // make sure that we always have an app name
147
+ if (params .appName () == null ) {
148
+ getLogger ().info ("Appname is not set, setting it to app src dir name" );
149
+ params .appName (params .srcDirList ().get (0 ));
150
+ }
151
+ String archiveSrcDir = params .appArchiveDir ()
152
+ + "/wlsdeploy/applications/" + params .appName ();
153
+ // prepare the archive directory and copy over the app src
154
+ try {
155
+ cleanupDirectory (archiveSrcDir );
156
+ checkDirectory (archiveSrcDir );
157
+ for (String item : params .srcDirList ()) {
158
+ getLogger ().info ("Copying {0} to {1}" , item , archiveSrcDir );
159
+ copyFolder (
160
+ item ,
161
+ archiveSrcDir );
162
+ }
163
+ } catch (IOException ioe ) {
164
+ getLogger ().severe ("Failed to get the directory " + archiveSrcDir + " ready" , ioe );
165
+ return false ;
166
+ }
167
+
168
+ // createArchive a zip file that can be passed to WIT
169
+ String zipPath = String .format ("%s/%s.zip" , params .appArchiveDir (), archiveName );
170
+ String cmd = String .format (
171
+ archiveHelperScript + " add structuredApplication"
172
+ + " -archive_file %s"
173
+ + " -source %s " ,
174
+ zipPath ,
175
+ archiveSrcDir );
176
+ return Command .withParams (
177
+ defaultCommandParams ()
178
+ .command (cmd )
179
+ .verbose (true )
180
+ .redirect (false ))
181
+ .execute ();
143
182
}
144
-
145
183
146
184
/**
147
185
* Build an application archive using a pre-populated AppParams instance.
186
+ *
148
187
* @return true if the command succeeds
149
188
*/
150
189
public boolean buildCoherence () {
@@ -172,7 +211,7 @@ public boolean buildCoherence() {
172
211
String jarPath = String .format ("%s.gar" , params .appName ());
173
212
jarBuilt = buildJarArchive (jarPath , archiveSrcDir );
174
213
} else if (params .appName ().contains ("CoherenceApp" )) {
175
- String [] appTypes = {"ear" , "gar" };
214
+ String [] appTypes = {"ear" , "gar" };
176
215
try {
177
216
for (String appType : appTypes ) {
178
217
String appSrcDir = String .format ("%s/%s/u01/application/builddir/%s.%s" ,
@@ -205,14 +244,14 @@ public boolean buildCoherence() {
205
244
* @param srcDir source directory
206
245
*/
207
246
private boolean buildJarArchive (
208
- String jarPath ,
247
+ String jarPath ,
209
248
String srcDir
210
249
) {
211
250
212
251
String cmd = String .format ("cd %s; jar -cfM %s . " , srcDir , jarPath );
213
252
214
253
return Command .withParams (
215
- defaultCommandParams ()
254
+ defaultCommandParams ()
216
255
.command (cmd )
217
256
.redirect (false ))
218
257
.execute ();
@@ -225,7 +264,7 @@ private boolean buildJarArchive(
225
264
* @param srcDir source directory
226
265
*/
227
266
public boolean buildZipArchive (
228
- String zipPath ,
267
+ String zipPath ,
229
268
String srcDir
230
269
) {
231
270
@@ -251,6 +290,64 @@ public boolean buildZipArchive(
251
290
.execute ();
252
291
}
253
292
293
+ /**
294
+ * Build a zip archive that includes an ear file in the srcDir.
295
+ *
296
+ * @param zipPath zip file path for the resulting archive
297
+ * @param serverName server name
298
+ * @param source source directory
299
+ */
300
+ public boolean addServerKeystore (
301
+ String zipPath ,
302
+ String serverName ,
303
+ String source
304
+ ) {
305
+
306
+ String cmd = String .format (
307
+ archiveHelperScript + " add serverKeystore"
308
+ + " -archive_file %s"
309
+ + " -server_name %s"
310
+ + " -source %s " ,
311
+ zipPath ,
312
+ serverName ,
313
+ source );
314
+
315
+ return Command .withParams (
316
+ defaultCommandParams ()
317
+ .command (cmd )
318
+ .verbose (true )
319
+ .redirect (false ))
320
+ .execute ();
321
+ }
322
+
323
+ /**
324
+ * Build a zip archive that includes an ear file in the srcDir.
325
+ *
326
+ * @param zipPath zip file path for the resulting archive
327
+ * @param source source directory
328
+ */
329
+ public boolean addCustom (
330
+ String zipPath ,
331
+ String source
332
+ ) {
333
+
334
+ String cmd = String .format (
335
+ archiveHelperScript + " add custom"
336
+ + " -archive_file %s"
337
+ + "-path patch"
338
+ + "-use_non_replicable_location"
339
+ + " -source %s " ,
340
+ zipPath ,
341
+ source );
342
+
343
+ return Command .withParams (
344
+ defaultCommandParams ()
345
+ .command (cmd )
346
+ .verbose (true )
347
+ .redirect (false ))
348
+ .execute ();
349
+ }
350
+
254
351
/**
255
352
* Build a zip archive that includes coh-proxy-server.gar in the srcDir.
256
353
*
@@ -272,27 +369,27 @@ public boolean buildCoherenceZipArchive(String zipPath, String srcDir) {
272
369
273
370
if (params .appName ().contains ("CoherenceApp" )) {
274
371
cmd = String .format (
275
- "cd %s ; zip -r %s.zip wlsdeploy/applications " ,
276
- params .appArchiveDir (),
277
- params .appName ()
372
+ "cd %s ; zip -r %s.zip wlsdeploy/applications " ,
373
+ params .appArchiveDir (),
374
+ params .appName ()
278
375
);
279
376
}
280
377
281
378
return Command .withParams (
282
- defaultCommandParams ()
283
- .command (cmd )
284
- .redirect (false ))
285
- .execute ();
379
+ defaultCommandParams ()
380
+ .command (cmd )
381
+ .redirect (false ))
382
+ .execute ();
286
383
}
287
384
288
385
/**
289
- * Archive an application from provided ear or war file that can be used by WebLogic Image Tool
290
- * to create an image with the application for a model-in-image use case.
386
+ * Archive an application from provided ear or war file that can be used by WebLogic Image Tool to create an image
387
+ * with the application for a model-in-image use case.
291
388
*
292
389
* @return true if the operation succeeds
293
390
*/
294
391
public boolean archiveApp () {
295
- List <String > srcFiles = params .srcDirList ();
392
+ List <String > srcFiles = params .srcDirList ();
296
393
String srcFile = srcFiles .get (0 );
297
394
String appName = srcFile .substring (srcFile .lastIndexOf ("/" ) + 1 , srcFile .lastIndexOf ("." ));
298
395
params .appName (appName );
@@ -306,7 +403,7 @@ public boolean archiveApp() {
306
403
getLogger ().info ("copy {0} to {1} " , appSrcFile , archiveSrcDir );
307
404
String fileName = appSrcFile .substring (appSrcFile .lastIndexOf ("/" ) + 1 );
308
405
Files .copy (Paths .get (appSrcFile ), Paths .get (archiveSrcDir + "/" + fileName ),
309
- StandardCopyOption .REPLACE_EXISTING );
406
+ StandardCopyOption .REPLACE_EXISTING );
310
407
}
311
408
}
312
409
} catch (IOException ioe ) {
@@ -315,18 +412,18 @@ public boolean archiveApp() {
315
412
}
316
413
317
414
String cmd = String .format (
318
- "cd %s ; zip -r %s.zip wlsdeploy/applications " ,
319
- params .appArchiveDir (),
320
- appName
415
+ "cd %s ; zip -r %s.zip wlsdeploy/applications " ,
416
+ params .appArchiveDir (),
417
+ appName
321
418
);
322
419
323
420
return Command .withParams (
324
- defaultCommandParams ()
325
- .command (cmd )
326
- .redirect (false ))
327
- .execute ();
421
+ defaultCommandParams ()
422
+ .command (cmd )
423
+ .redirect (false ))
424
+ .execute ();
328
425
}
329
-
426
+
330
427
static Path archiveHelperScript = Path .of (DOWNLOAD_DIR , "wdt" , "weblogic-deploy" , "bin" , "archiveHelper.sh" );
331
428
332
429
private static void downloadAndInstallWDT () throws IOException {
0 commit comments