Skip to content

Commit 7dd3a54

Browse files
committed
Merge branch 'master' into real-jrf-poc
2 parents 7ed7f2b + fc379be commit 7dd3a54

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

src/main/java/com/oracle/weblogicx/imagebuilder/cli/CLIDriver.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import picocli.CommandLine.HelpCommand;
1212

1313
import java.util.concurrent.Callable;
14+
import java.util.logging.Logger;
1415

1516
@Command(
1617
name = "imagebuilder",
@@ -38,23 +39,29 @@ public CommandResponse call() {
3839
}
3940

4041
public static void main(String[] args) {
42+
Logger logger = Logger.getLogger(CLIDriver.class.getName());
4143
CLIDriver cliDriver = new CLIDriver();
4244
if (args.length == 0) {
4345
CommandLine.usage(cliDriver, System.out);
46+
System.exit(-1);
4447
} else {
4548
//List<String> argsList = Stream.of(args).collect(Collectors.toList());
4649
//argsList.add("--cli");
4750
//CommandResponse response = WLSCommandLine.call(cliDriver, argsList.toArray(new String[0]));
4851
CommandResponse response = WLSCommandLine.call(cliDriver, true, args);
4952

5053
if (response != null) {
51-
System.out.println(String.format("Response code: %d, message: %s", response.getStatus(),
52-
response.getMessage()));
53-
//Map<String, String> results = response.getResult();
54-
//results.forEach((key, value) -> System.out.println(key + "=" + value));
55-
}/* else {
56-
System.out.println("response is null");
57-
}*/
54+
55+
String message = String.format("Response code: %d, message: %s", response.getStatus(),
56+
response.getMessage());
57+
if (response.getStatus() != 0) {
58+
logger.severe(message);
59+
} else {
60+
logger.info(message);
61+
}
62+
System.exit(response.getStatus());
63+
}
64+
System.exit(-1);
5865
}
5966
}
6067
}

src/main/java/com/oracle/weblogicx/imagebuilder/cli/menu/CreateImage.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ public CommandResponse call() throws Exception {
6868
}
6969

7070
List<String> cmdBuilder = getInitialBuildCmd();
71-
7271
// create a tmp directory for user.
73-
tmpDir = Files.createTempDirectory(null);
72+
// using user home as base to avoid running out of space in tmp
73+
tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("user.home")),
74+
"wlsimgbuilder_temp");
7475
String tmpDirPath = tmpDir.toAbsolutePath().toString();
7576
logger.info("tmp directory used for build context: " + tmpDirPath);
7677
Path tmpPatchesDir = Files.createDirectory(Paths.get(tmpDirPath, "patches"));
@@ -81,9 +82,9 @@ public CommandResponse call() throws Exception {
8182

8283
if (fromImage != null && !fromImage.isEmpty()) {
8384
cmdBuilder.add(BUILD_ARG);
84-
cmdBuilder.add("BASE_IMAGE=" + fromImage);
8585

86-
tmpDir2 = Files.createTempDirectory(Paths.get(System.getProperty("user.home")), null);
86+
tmpDir2 = Files.createTempDirectory(Paths.get(System.getProperty("user.home")),
87+
"wlsimgbuilder_temp");
8788
logger.info("tmp directory in user.home for docker run: " + tmpDir2);
8889

8990
Utils.copyResourceAsFile("/probe-env/test-create-env.sh",
@@ -108,7 +109,6 @@ public CommandResponse call() throws Exception {
108109
} else {
109110
filterStartTags.add("_YUM");
110111
}
111-
112112
// build wdt args if user passes --wdtModelPath
113113
cmdBuilder.addAll(handleWDTArgsIfRequired(tmpDir));
114114

@@ -123,7 +123,6 @@ public CommandResponse call() throws Exception {
123123

124124
// add directory to pass the context
125125
cmdBuilder.add(tmpDirPath);
126-
127126
logger.info("docker cmd = " + String.join(" ", cmdBuilder));
128127
Utils.runDockerCommand(isCLIMode, cmdBuilder, dockerLog);
129128
} catch (Exception ex) {
@@ -155,9 +154,12 @@ private List<String> handleInstallerFiles(Path tmpDir) throws Exception {
155154
for (InstallerFile eachInstaller : requiredInstallers) {
156155
String targetFilePath = eachInstaller.resolve(cacheStore);
157156
File targetFile = new File(targetFilePath);
158-
Path targetLink = Files.createLink(Paths.get(tmpDirPath, targetFile.getName()),
159-
Paths.get(targetFilePath));
160-
retVal.addAll(eachInstaller.getBuildArg(tmpDir.relativize(targetLink).toString()));
157+
try {
158+
Path targetLink = Files.copy(Paths.get(targetFilePath), Paths.get(tmpDirPath, targetFile.getName()));
159+
retVal.addAll(eachInstaller.getBuildArg(tmpDir.relativize(targetLink).toString()));
160+
} catch (Exception ee ) {
161+
ee.printStackTrace();
162+
}
161163
}
162164
return retVal;
163165
}
@@ -198,18 +200,23 @@ private List<String> handleWDTArgsIfRequired(Path tmpDir) throws IOException {
198200
}
199201
}
200202
filterStartTags.add("WDT_");
201-
Path targetLink = Files.createLink(Paths.get(tmpDirPath, wdtModelPath.getFileName().toString()), wdtModelPath);
203+
Path targetLink = Files.copy(wdtModelPath, Paths.get(tmpDirPath, wdtModelPath.getFileName().toString())
204+
);
202205
retVal.add(BUILD_ARG);
203206
retVal.add("WDT_MODEL=" + tmpDir.relativize(targetLink).toString());
204207

205208
if (wdtArchivePath != null && Files.isRegularFile(wdtArchivePath)) {
206-
targetLink = Files.createLink(Paths.get(tmpDirPath, wdtArchivePath.getFileName().toString()), wdtArchivePath);
209+
targetLink = Files.copy(wdtArchivePath, Paths.get(tmpDirPath,
210+
wdtArchivePath.getFileName().toString())
211+
);
207212
retVal.add(BUILD_ARG);
208213
retVal.add("WDT_ARCHIVE=" + tmpDir.relativize(targetLink).toString());
209214
}
210215

211216
if (wdtVariablesPath != null && Files.isRegularFile(wdtVariablesPath)) {
212-
targetLink = Files.createLink(Paths.get(tmpDirPath, wdtVariablesPath.getFileName().toString()), wdtVariablesPath);
217+
targetLink = Files.copy(wdtVariablesPath, Paths.get(tmpDirPath,
218+
wdtVariablesPath.getFileName().toString())
219+
);
213220
retVal.add(BUILD_ARG);
214221
retVal.add("WDT_VARIABLE=" + tmpDir.relativize(targetLink).toString());
215222
retVal.addAll(getWDTRequiredBuildArgs(wdtVariablesPath));

src/main/java/com/oracle/weblogicx/imagebuilder/cli/menu/ImageOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ List<String> handlePatchFiles(Path tmpDir, Path tmpPatchesDir) throws Exception
106106
for (String patchLocation : patchLocations) {
107107
if (patchLocation != null) {
108108
File patch_file = new File(patchLocation);
109-
Files.createLink(Paths.get(toPatchesPath, patch_file.getName()), Paths.get(patchLocation));
109+
Files.copy(Paths.get(patchLocation), Paths.get(toPatchesPath, patch_file.getName()) );
110110
} else {
111111
logger.severe("null entry in patchLocations");
112112
}
@@ -162,8 +162,8 @@ void handleProxyUrls() throws IOException {
162162

163163
void addOPatch1394ToImage(Path tmpDir) throws Exception {
164164
String filePath = new PatchFile(useCache, "opatch", "13.9.4.0.0", "28186730", userId, password).resolve(cacheStore);
165-
Files.createLink(Paths.get(tmpDir.toAbsolutePath().toString(), new File(filePath).getName()),
166-
Paths.get(filePath));
165+
Files.copy(Paths.get(filePath), Paths.get(tmpDir.toAbsolutePath().toString(), new File(filePath).getName())
166+
);
167167
filterStartTags.add("OPATCH_1394");
168168
}
169169

src/main/java/com/oracle/weblogicx/imagebuilder/util/ARUUtil.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,6 @@ public static ValidationResult validatePatches(String lsInventoryPath, List<Stri
254254
}
255255

256256
doc.appendChild(element);
257-
/*System.out.println("===================================================");
258-
System.out.println("There are conflicts between the patches requested:-");
259-
System.out.println("===================================================");
260-
System.out.println();
261-
XPathUtil.prettyPrint(doc);*/
262257

263258
validationResult.setResults(doc);
264259
validationResult.setErrorMessage(parsePatchValidationError(doc));

src/main/java/com/oracle/weblogicx/imagebuilder/util/Utils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private static Map<String, String> readPlaceHolderResource(String resourcePath,
175175
retMap.put(startTag, content);
176176
}
177177
} else {
178-
System.out.println("pattern mismatch in resource " + resourcePath);
178+
logger.fine("pattern mismatch in resource " + resourcePath);
179179
}
180180
}
181181
return retMap;
@@ -323,6 +323,10 @@ public static void deleteFilesRecursively(Path tmpDir) throws IOException {
323323
.map(Path::toFile)
324324
//.peek(System.out::println)
325325
.forEach(File::delete);
326+
327+
if (Files.exists(tmpDir)) {
328+
logger.warning("Directory not cleaned up, please remove it manually " + tmpDir.toString());
329+
}
326330
}
327331
}
328332

src/main/java/com/oracle/weblogicx/imagebuilder/util/XPathUtil.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
import javax.xml.xpath.XPathFactory;
1919
import java.io.StringWriter;
2020
import java.io.Writer;
21+
import java.util.logging.Logger;
2122

2223
public class XPathUtil {
2324

24-
// /**
25+
private static final Logger logger = Logger.getLogger(XPathUtil.class.getName());
26+
27+
28+
// /**
2529
// * Apply XPath and return the results as nodelist
2630
// *
2731
// * @param doc dom document
@@ -93,9 +97,9 @@ public static final void prettyPrint(Document xml) {
9397
tf.setOutputProperty(OutputKeys.INDENT, "yes");
9498
Writer out = new StringWriter();
9599
tf.transform(new DOMSource(xml), new StreamResult(out));
96-
System.out.println(out.toString());
100+
logger.fine(out.toString());
97101
} catch (TransformerException ex) {
98-
System.out.println("Failed to print out xml document, probably not a valid document " + ex.getMessage());
102+
logger.fine("Failed to print out xml document, probably not a valid document " + ex.getMessage());
99103
}
100104
}
101105

0 commit comments

Comments
 (0)