2
2
3
3
package com .oracle .weblogicx .imagebuilder .cli .menu ;
4
4
5
- import com .oracle .weblogicx .imagebuilder .api .model .CachePolicy ;
6
5
import com .oracle .weblogicx .imagebuilder .api .model .CommandResponse ;
7
6
import com .oracle .weblogicx .imagebuilder .api .model .InstallerType ;
8
7
import com .oracle .weblogicx .imagebuilder .api .model .WLSInstallerType ;
29
28
import java .util .stream .Collectors ;
30
29
31
30
import static com .oracle .weblogicx .imagebuilder .api .model .CachePolicy .ALWAYS ;
31
+ import static com .oracle .weblogicx .imagebuilder .util .Constants .BUILD_ARG ;
32
32
import static com .oracle .weblogicx .imagebuilder .util .Constants .DEFAULT_JDK_VERSION ;
33
33
import static com .oracle .weblogicx .imagebuilder .util .Constants .DEFAULT_WLS_VERSION ;
34
34
@@ -79,7 +79,7 @@ public CommandResponse call() throws Exception {
79
79
cmdBuilder .addAll (handleInstallerFiles (tmpDir ));
80
80
81
81
if (fromImage != null && !fromImage .isEmpty ()) {
82
- cmdBuilder .add (Constants . BUILD_ARG );
82
+ cmdBuilder .add (BUILD_ARG );
83
83
cmdBuilder .add ("BASE_IMAGE=" + fromImage );
84
84
85
85
tmpDir2 = Files .createTempDirectory (Paths .get (System .getProperty ("user.home" )), null );
@@ -124,8 +124,7 @@ public CommandResponse call() throws Exception {
124
124
cmdBuilder .add (tmpDirPath );
125
125
126
126
logger .info ("docker cmd = " + String .join (" " , cmdBuilder ));
127
- Utils .runDockerCommand (cmdBuilder , dockerLog );
128
-
127
+ Utils .runDockerCommand (isCLIMode , cmdBuilder , dockerLog );
129
128
} catch (Exception ex ) {
130
129
return new CommandResponse (-1 , ex .getMessage ());
131
130
} finally {
@@ -148,7 +147,7 @@ public CommandResponse call() throws Exception {
148
147
* @return list of strings
149
148
* @throws Exception in case of error
150
149
*/
151
- List <String > handleInstallerFiles (Path tmpDir ) throws Exception {
150
+ private List <String > handleInstallerFiles (Path tmpDir ) throws Exception {
152
151
List <String > retVal = new LinkedList <>();
153
152
String tmpDirPath = tmpDir .toAbsolutePath ().toString ();
154
153
List <InstallerFile > requiredInstallers = gatherRequiredInstallers ();
@@ -188,18 +187,18 @@ private List<String> handleWDTArgsIfRequired(Path tmpDir) throws IOException {
188
187
if (Files .isRegularFile (wdtModelPath )) {
189
188
filterStartTags .add ("WDT_" );
190
189
Path targetLink = Files .createLink (Paths .get (tmpDirPath , wdtModelPath .getFileName ().toString ()), wdtModelPath );
191
- retVal .add (Constants . BUILD_ARG );
190
+ retVal .add (BUILD_ARG );
192
191
retVal .add ("WDT_MODEL=" + tmpDir .relativize (targetLink ).toString ());
193
192
194
193
if (wdtArchivePath != null && Files .isRegularFile (wdtArchivePath )) {
195
194
targetLink = Files .createLink (Paths .get (tmpDirPath , wdtArchivePath .getFileName ().toString ()), wdtArchivePath );
196
- retVal .add (Constants . BUILD_ARG );
195
+ retVal .add (BUILD_ARG );
197
196
retVal .add ("WDT_ARCHIVE=" + tmpDir .relativize (targetLink ).toString ());
198
197
}
199
198
200
199
if (wdtVariablesPath != null && Files .isRegularFile (wdtVariablesPath )) {
201
200
targetLink = Files .createLink (Paths .get (tmpDirPath , wdtVariablesPath .getFileName ().toString ()), wdtVariablesPath );
202
- retVal .add (Constants . BUILD_ARG );
201
+ retVal .add (BUILD_ARG );
203
202
retVal .add ("WDT_VARIABLE=" + tmpDir .relativize (targetLink ).toString ());
204
203
retVal .addAll (getWDTRequiredBuildArgs (wdtVariablesPath ));
205
204
}
@@ -232,7 +231,7 @@ private List<String> getWDTRequiredBuildArgs(Path wdtVariablesPath) throws IOExc
232
231
Constants .REQD_WDT_BUILD_ARGS .contains (((String ) x ).toUpperCase ())
233
232
).collect (Collectors .toList ());
234
233
matchingKeys .forEach (x -> {
235
- retVal .add (Constants . BUILD_ARG );
234
+ retVal .add (BUILD_ARG );
236
235
retVal .add (((String ) x ).toUpperCase () + "=" + variableProps .getProperty ((String ) x ));
237
236
});
238
237
return retVal ;
@@ -247,15 +246,14 @@ private List<String> getWDTRequiredBuildArgs(Path wdtVariablesPath) throws IOExc
247
246
*/
248
247
private List <InstallerFile > gatherRequiredInstallers () throws Exception {
249
248
List <InstallerFile > retVal = new LinkedList <>();
250
- retVal .add (new InstallerFile (InstallerType .fromValue (installerType .toString ()), installerVersion ,
251
- (useCache != ALWAYS ), userId , password ));
252
- retVal .add (new InstallerFile (InstallerType .JDK , jdkVersion , (useCache != ALWAYS ), userId , password ));
253
249
if (wdtModelPath != null && Files .isRegularFile (wdtModelPath )) {
254
- InstallerFile wdtInstaller = new InstallerFile (InstallerType .WDT , wdtVersion , (useCache != ALWAYS ),
255
- null , null );
250
+ InstallerFile wdtInstaller = new InstallerFile (useCache , InstallerType .WDT , wdtVersion , null , null );
256
251
retVal .add (wdtInstaller );
257
252
addWDTURL (wdtInstaller .getKey () + "_url" );
258
253
}
254
+ retVal .add (new InstallerFile (useCache , InstallerType .fromValue (installerType .toString ()), installerVersion ,
255
+ userId , password ));
256
+ retVal .add (new InstallerFile (useCache , InstallerType .JDK , jdkVersion , userId , password ));
259
257
return retVal ;
260
258
}
261
259
@@ -266,7 +264,10 @@ private List<InstallerFile> gatherRequiredInstallers() throws Exception {
266
264
* @throws Exception in case of error
267
265
*/
268
266
private void addWDTURL (String wdtURLKey ) throws Exception {
269
- if ("latest" .equalsIgnoreCase (wdtVersion ) || cacheStore .getValueFromCache (wdtURLKey ) == null ) {
267
+ if (cacheStore .getValueFromCache (wdtURLKey ) == null ) {
268
+ if (useCache == ALWAYS ) {
269
+ throw new Exception ("CachePolicy prohibits download. Add the required wdt installer to cache" );
270
+ }
270
271
List <String > wdtTags = HttpUtil .getWDTTags ();
271
272
String tagToMatch = "latest" .equalsIgnoreCase (wdtVersion ) ? wdtTags .get (0 ) : "weblogic-deploy-tooling-" + wdtVersion ;
272
273
if (wdtTags .contains (tagToMatch )) {
@@ -314,18 +315,6 @@ private void copyResponseFilesToDir(String dirPath) throws IOException {
314
315
)
315
316
private String jdkVersion ;
316
317
317
- @ Option (
318
- names = {"--useCache" },
319
- paramLabel = "<Cache Policy>" ,
320
- defaultValue = "always" ,
321
- description = "Whether to use local cache or download installers.\n " +
322
- "first - try to use cache and download artifacts if required\n " +
323
- "always - default. use cache always and never download artifacts\n " +
324
- "never - never use cache and always download artifacts" ,
325
- hidden = true
326
- )
327
- private CachePolicy useCache ;
328
-
329
318
@ Option (
330
319
names = {"--fromImage" },
331
320
description = "Docker image to use as base image."
0 commit comments