Skip to content

Commit ac49f10

Browse files
authored
Use 1 instead of negative 1 for error return code (#286)
* negative numbers are not valid return codes, replaced all negative 1 occurrences with non-negative 1 * update expected responses in unit tests for new response code
1 parent ca6c200 commit ac49f10

File tree

12 files changed

+30
-30
lines changed

12 files changed

+30
-30
lines changed

imagetool/src/main/bin/imagetool.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ set -e
1414
#
1515
if [ -z "${JAVA_HOME}" ]; then
1616
echo "Please set the JAVA_HOME environment variable to match the location of your Java installation. Java 8 or newer is required." >&2
17-
exit -1
17+
exit 1
1818
elif [ ! -d "${JAVA_HOME}" ]; then
1919
echo "Your JAVA_HOME environment variable points to a non-existent directory: ${JAVA_HOME}" >&2
20-
exit -1
20+
exit 1
2121
fi
2222

2323
if [ -x "${JAVA_HOME}/bin/java" ]; then
2424
JAVA_EXE=${JAVA_HOME}/bin/java
2525
else
2626
echo "Java executable at ${JAVA_HOME}/bin/java either does not exist or is not executable" >&2
27-
exit -1
27+
exit 1
2828
fi
2929

3030
script_dir=$(dirname "${BASH_SOURCE[0]}")

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/ImageTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static void main(String[] args) {
6666
}
6767
System.exit(response.getStatus());
6868
}
69-
System.exit(-1);
69+
System.exit(1);
7070
}
7171

7272
/**

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/AddEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CommandResponse call() throws CacheStoreException {
3030
cache().addToCache(key, location);
3131
return new CommandResponse(0, msg);
3232
}
33-
return new CommandResponse(-1, "IMG-0044");
33+
return new CommandResponse(1, "IMG-0044");
3434
}
3535

3636
@Option(

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/AddPatchEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public CommandResponse call() throws Exception {
2929
List<String> patches = new ArrayList<>();
3030
patches.add(patchId);
3131
if (!Utils.validatePatchIds(patches, true)) {
32-
return new CommandResponse(-1, "Patch ID validation failed");
32+
return new CommandResponse(1, "Patch ID validation failed");
3333
}
3434
return addToCache(patchId);
3535
} else {
36-
return new CommandResponse(-1, "IMG-0076", "--patchId");
36+
return new CommandResponse(1, "IMG-0076", "--patchId");
3737
}
3838
}
3939

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/CacheAddOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class CacheAddOperation extends CacheOperation {
1717
CommandResponse addToCache(String key) throws CacheStoreException {
1818
// if file is invalid or does not exist, return an error
1919
if (filePath == null || !Files.isRegularFile(filePath)) {
20-
return new CommandResponse(-1, "IMG-0049", filePath);
20+
return new CommandResponse(1, "IMG-0049", filePath);
2121
}
2222

2323
// if the new value is the same as the existing cache value, do nothing
@@ -28,7 +28,7 @@ CommandResponse addToCache(String key) throws CacheStoreException {
2828

2929
// if there is already a cache entry and the user did not ask to force it, return an error
3030
if (!force && existingValue != null) {
31-
return new CommandResponse(-1, "IMG-0048", key, existingValue);
31+
return new CommandResponse(1, "IMG-0048", key, existingValue);
3232
}
3333

3434
// input appears valid, add the entry to the cache and exit

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/DeleteEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public CommandResponse call() throws Exception {
3434
}
3535
}
3636
}
37-
return new CommandResponse(-1, "IMG-0045");
37+
return new CommandResponse(1, "IMG-0045");
3838
}
3939

4040
@Option(

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public CommandResponse call() throws Exception {
5151
tmpDir = getTempDirectory();
5252

5353
if (!Utils.validatePatchIds(patches, false)) {
54-
return new CommandResponse(-1, "Patch ID validation failed");
54+
return new CommandResponse(1, "Patch ID validation failed");
5555
}
5656

5757
copyOptionsFromImage(fromImage, tmpDir);
@@ -106,7 +106,7 @@ public CommandResponse call() throws Exception {
106106
}
107107
} catch (Exception ex) {
108108
logger.fine("**ERROR**", ex);
109-
return new CommandResponse(-1, ex.getMessage());
109+
return new CommandResponse(1, ex.getMessage());
110110
} finally {
111111
if (!skipcleanup) {
112112
Utils.deleteFilesRecursively(tmpDir);

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/RebaseImage.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public CommandResponse call() throws Exception {
7575
modelHome = baseImageProperties.getProperty("wdtModelHome", null);
7676
modelOnly = Boolean.parseBoolean(baseImageProperties.getProperty("wdtModelOnly", null));
7777
} else {
78-
return new CommandResponse(-1, "Source Image not set");
78+
return new CommandResponse(1, "Source Image not set");
7979
}
8080

8181
if (!Utils.isEmptyString(targetImage)) {
@@ -94,15 +94,15 @@ public CommandResponse call() throws Exception {
9494
}
9595

9696
if (newJavaHome != null && !newJavaHome.equals(oldJavaHome)) {
97-
return new CommandResponse(-1, Utils.getMessage("IMG-0026"));
97+
return new CommandResponse(1, Utils.getMessage("IMG-0026"));
9898
}
9999

100100
if (newOracleHome != null && !newOracleHome.equals(oldOracleHome)) {
101-
return new CommandResponse(-1, Utils.getMessage("IMG-0021"));
101+
return new CommandResponse(1, Utils.getMessage("IMG-0021"));
102102
}
103103

104104
if (Utils.isEmptyString(domainHome)) {
105-
return new CommandResponse(-1, Utils.getMessage("IMG-0025"));
105+
return new CommandResponse(1, Utils.getMessage("IMG-0025"));
106106
}
107107

108108
if (modelOnly) {
@@ -161,7 +161,7 @@ public CommandResponse call() throws Exception {
161161
// add directory to pass the context
162162
runDockerCommand(dockerfile, cmdBuilder);
163163
} catch (Exception ex) {
164-
return new CommandResponse(-1, ex.getMessage());
164+
return new CommandResponse(1, ex.getMessage());
165165
} finally {
166166
if (!skipcleanup) {
167167
Utils.deleteFilesRecursively(tmpDir);

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public CommandResponse call() throws Exception {
5151
init(buildId);
5252

5353
if (fromImage == null || fromImage.isEmpty()) {
54-
return new CommandResponse(-1, "update requires a base image. use --fromImage to specify base image");
54+
return new CommandResponse(1, "update requires a base image. use --fromImage to specify base image");
5555
}
5656

5757
dockerfileOptions.setBaseImage(fromImage).setWdtBase(fromImage);
@@ -65,14 +65,14 @@ public CommandResponse call() throws Exception {
6565

6666
String oracleHome = baseImageProperties.getProperty("oracleHome", null);
6767
if (oracleHome == null) {
68-
return new CommandResponse(-1, "IMG-0072", fromImage);
68+
return new CommandResponse(1, "IMG-0072", fromImage);
6969
}
7070
dockerfileOptions.setOracleHome(oracleHome);
7171

7272
if (wdtOptions.isUsingWdt() && !wdtOptions.modelOnly()) {
7373
String domainHome = baseImageProperties.getProperty("domainHome", null);
7474
if (domainHome == null && wdtOperation == WdtOperation.UPDATE) {
75-
return new CommandResponse(-1, "IMG-0071", fromImage);
75+
return new CommandResponse(1, "IMG-0071", fromImage);
7676
}
7777
}
7878

@@ -83,7 +83,7 @@ public CommandResponse call() throws Exception {
8383
String baseImageUsr = baseImageProperties.getProperty("oracleHomeUser");
8484
String baseImageGrp = baseImageProperties.getProperty("oracleHomeGroup");
8585
if (!dockerfileOptions.userid().equals(baseImageUsr) || !dockerfileOptions.groupid().equals(baseImageGrp)) {
86-
return new CommandResponse(-1, "IMG-0087", fromImage, baseImageUsr, baseImageGrp);
86+
return new CommandResponse(1, "IMG-0087", fromImage, baseImageUsr, baseImageGrp);
8787
}
8888

8989
List<InstalledPatch> installedPatches = Collections.emptyList();
@@ -115,18 +115,18 @@ public CommandResponse call() throws Exception {
115115
logger.warning("IMG-0009");
116116
} else {
117117
if (!Utils.validatePatchIds(patches, false)) {
118-
return new CommandResponse(-1, "Patch ID validation failed");
118+
return new CommandResponse(1, "Patch ID validation failed");
119119
}
120120

121121
String oraclePatches = baseImageProperties.getProperty("oraclePatches", null);
122122
if (oraclePatches != null) {
123123
if (oraclePatches.contains("OPatch failed")) {
124124
logger.severe("patch inventory = " + oraclePatches);
125-
return new CommandResponse(-1, "opatch lsinventory failed");
125+
return new CommandResponse(1, "opatch lsinventory failed");
126126
}
127127
installedPatches = InstalledPatch.getPatchList(oraclePatches);
128128
} else {
129-
return new CommandResponse(-1, "lsinventory missing. required to check for conflicts");
129+
return new CommandResponse(1, "lsinventory missing. required to check for conflicts");
130130
}
131131
}
132132
}
@@ -138,7 +138,7 @@ public CommandResponse call() throws Exception {
138138
dockerfileOptions.setWdtCommand(wdtOperation);
139139
if (dockerfileOptions.runRcu()
140140
&& (wdtOperation == WdtOperation.UPDATE || wdtOperation == WdtOperation.DEPLOY)) {
141-
return new CommandResponse(-1, "IMG-0055");
141+
return new CommandResponse(1, "IMG-0055");
142142
}
143143

144144
FmwInstallerType installerType = FmwInstallerType.fromProductList(
@@ -156,7 +156,7 @@ public CommandResponse call() throws Exception {
156156
wdtOptions.handleResourceTemplates(imageTag);
157157
}
158158
} catch (Exception ex) {
159-
return new CommandResponse(-1, ex.getMessage());
159+
return new CommandResponse(1, ex.getMessage());
160160
} finally {
161161
if (!skipcleanup) {
162162
Utils.deleteFilesRecursively(tmpDir);

imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/cache/AddEntryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ void testMissingValue() {
5757
@Test
5858
void testInvalidParameters() {
5959
CommandResponse response = ImageTool.run(new AddEntry(), printStream, printStream, "--key", "", "--value", "");
60-
assertEquals(-1, response.getStatus());
60+
assertEquals(1, response.getStatus());
6161
}
6262
}

0 commit comments

Comments
 (0)