Skip to content

Commit f1944b5

Browse files
authored
code cleanup (#311)
1 parent 6e02da0 commit f1944b5

File tree

19 files changed

+35
-47
lines changed

19 files changed

+35
-47
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public String toString() {
302302
return patchId + " - " + description;
303303
}
304304

305+
@Override
305306
public int compareTo(AruPatch obj) {
306307
return version.compareTo(obj.version);
307308
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ private void handleAdditionalBuildCommands() throws IOException {
9191
Path targetFile = Paths.get(getTempDirectory(), FILESFOLDER, additionalFile.getFileName().toString());
9292
logger.info("IMG-0043", additionalFile);
9393
if (Files.isDirectory(additionalFile)) {
94-
Utils.copyLocalDirectory(additionalFile, targetFile, false);
94+
Utils.copyLocalDirectory(additionalFile, targetFile);
9595
} else {
96-
Utils.copyLocalFile(additionalFile, targetFile, false);
96+
Utils.copyLocalFile(additionalFile, targetFile);
9797
}
9898
}
9999
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public CommandResponse call() throws Exception {
9191
// Set the inventory location, so that it will be copied
9292
if (inventoryPointerFile != null) {
9393
Utils.setInventoryLocation(inventoryPointerFile, dockerfileOptions);
94-
Utils.copyLocalFile(Paths.get(inventoryPointerFile), Paths.get(tmpDir, "/oraInst.loc"), false);
94+
Utils.copyLocalFile(Paths.get(inventoryPointerFile), Paths.get(tmpDir, "/oraInst.loc"));
9595
} else {
9696
Utils.copyResourceAsFile("/response-files/oraInst.loc", tmpDir);
9797
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public CommandResponse call() throws Exception {
148148
// Set the inventory pointer
149149
if (inventoryPointerFile != null) {
150150
Utils.setInventoryLocation(inventoryPointerFile, dockerfileOptions);
151-
Utils.copyLocalFile(Paths.get(inventoryPointerFile), Paths.get(tmpDir,"/oraInst.loc"), false);
151+
Utils.copyLocalFile(Paths.get(inventoryPointerFile), Paths.get(tmpDir,"/oraInst.loc"));
152152
} else {
153153
Utils.copyResourceAsFile("/response-files/oraInst.loc", tmpDir);
154154
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/inspect/InspectOutput.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* This class should be replaced if/when a full JSON parser is added to the project.
1818
*/
1919
public class InspectOutput {
20-
private static final String patchesKey = "oraclePatches";
20+
private static final String PATCHES_KEY = "oraclePatches";
2121
Map<String,String> attributes;
2222
List<InventoryPatch> patches;
2323
OperatingSystemProperties os;
@@ -30,15 +30,15 @@ public InspectOutput(Properties imageProperties) {
3030
// convert Properties to TreeMap (to sort attributes alphabetically)
3131
Map<String,String> sorted = imageProperties.entrySet().stream()
3232
.map(InspectOutput::convertToStringEntry)
33-
.filter(e -> !e.getKey().equals(patchesKey)) // do not store patches entry as a normal attribute
33+
.filter(e -> !e.getKey().equals(PATCHES_KEY)) // do not store patches entry as a normal attribute
3434
.filter(e -> !e.getKey().startsWith("__OS__")) // do not store OS entries as a normal attribute
3535
.collect(Collectors.toMap(
3636
Map.Entry::getKey, Map.Entry::getValue,
3737
(v1, v2) -> v1, // discard duplicates, but there shouldn't be any dupes
3838
TreeMap::new)); // use a sorted map
3939

40-
if (imageProperties.containsKey(patchesKey)) {
41-
patches = InventoryPatch.parseInventoryPatches(imageProperties.get(patchesKey).toString());
40+
if (imageProperties.containsKey(PATCHES_KEY)) {
41+
patches = InventoryPatch.parseInventoryPatches(imageProperties.get(PATCHES_KEY).toString());
4242
}
4343

4444
attributes = sorted;
@@ -53,7 +53,7 @@ private static Map.Entry<String,String> convertToStringEntry(Map.Entry<Object,Ob
5353
public String toString() {
5454
StringBuilder result = new StringBuilder().append("{\n");
5555
if (patches != null) {
56-
result.append(pad(1)).append('\"').append(patchesKey).append('\"').append(" : [\n");
56+
result.append(pad(1)).append('\"').append(PATCHES_KEY).append('\"').append(" : [\n");
5757
Iterator<InventoryPatch> patchesIter = patches.iterator();
5858
while (patchesIter.hasNext()) {
5959
InventoryPatch patch = patchesIter.next();

imagetool/src/main/java/com/oracle/weblogic/imagetool/installer/MiddlewareInstall.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ private static String getJarNameFromInstaller(Path installerFile) throws IOExcep
6161
ZipEntry entry = entries.nextElement();
6262
String entryName = entry.getName();
6363
logger.finer("Entry in zip {0}: {1}", filename, entryName);
64-
if (entryName.endsWith(".jar")) {
65-
filename = entryName;
66-
break;
67-
} else if (entryName.endsWith(".bin")) {
64+
if (entryName.endsWith(".jar") || entryName.endsWith(".bin")) {
6865
filename = entryName;
6966
break;
7067
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/logging/ConsoleFormatter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,32 @@ private String replaceColorTokens(String text) {
7575
/**
7676
* Formats the log record.
7777
*
78-
* @param record the log record
78+
* @param logRecord the log record
7979
* @return the formatted log record
8080
*/
8181
@Override
82-
public synchronized String format(LogRecord record) {
82+
public synchronized String format(LogRecord logRecord) {
8383
StringBuilder sb = new StringBuilder();
8484

8585
// Level
8686
sb.append("[")
87-
.append(getMessageLevelColor(record.getLevel()))
88-
.append(String.format("%-7s", record.getLevel().getLocalizedName()))
87+
.append(getMessageLevelColor(logRecord.getLevel()))
88+
.append(String.format("%-7s", logRecord.getLevel().getLocalizedName()))
8989
.append(AnsiColor.RESET)
9090
.append("] ");
9191

9292
// message
93-
sb.append(replaceColorTokens(formatMessage(record)));
93+
sb.append(replaceColorTokens(formatMessage(logRecord)));
9494

9595
// throwable
96-
if (record.getThrown() != null) {
96+
if (logRecord.getThrown() != null) {
9797
try {
9898
StringWriter sw = new StringWriter();
9999
PrintWriter pw = new PrintWriter(sw);
100-
record.getThrown().printStackTrace(pw);
100+
logRecord.getThrown().printStackTrace(pw);
101101
pw.close();
102102
sb.append(LINE_SEPARATOR)
103-
.append(sw.toString())
103+
.append(sw)
104104
.append(LINE_SEPARATOR);
105105
} catch (Exception ex) {
106106
//ignore

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.nio.file.Path;
2020
import java.nio.file.Paths;
2121
import java.nio.file.StandardCopyOption;
22-
import java.nio.file.attribute.PosixFilePermissions;
2322
import java.text.MessageFormat;
2423
import java.util.Arrays;
2524
import java.util.Base64;
@@ -85,30 +84,23 @@ public static void copyResourceAsFile(String resourcePath, String destPath) thro
8584
*
8685
* @param sourcePath resource path in the local directory
8786
* @param destPath local file to copy to.
88-
* @param markExec sets the executable flag if true
8987
* @throws IOException in case of error
9088
*/
91-
public static void copyLocalFile(Path sourcePath, Path destPath, boolean markExec) throws IOException {
89+
public static void copyLocalFile(Path sourcePath, Path destPath) throws IOException {
9290
Objects.requireNonNull(sourcePath);
9391
Objects.requireNonNull(destPath);
9492
logger.fine("copyLocalFile: copying file {0}->{1}", sourcePath, destPath);
9593
Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
96-
if (markExec) {
97-
if (!System.getProperty("os.name").toLowerCase().startsWith("windows")) {
98-
Files.setPosixFilePermissions(destPath, PosixFilePermissions.fromString("r-xr-xr-x"));
99-
}
100-
}
10194
}
10295

10396
/**
10497
* Utility method to copy a local directory to another local file system location.
10598
*
10699
* @param sourcePath path to the local directory
107100
* @param destPath local directory to copy to.
108-
* @param markExec sets the executable flag if true
109101
* @throws IOException in case of error
110102
*/
111-
public static void copyLocalDirectory(Path sourcePath, Path destPath, boolean markExec) throws IOException {
103+
public static void copyLocalDirectory(Path sourcePath, Path destPath) throws IOException {
112104
Objects.requireNonNull(sourcePath);
113105
Objects.requireNonNull(destPath);
114106
if (!Files.isDirectory(sourcePath)) {
@@ -124,9 +116,9 @@ public static void copyLocalDirectory(Path sourcePath, Path destPath, boolean ma
124116
try (DirectoryStream<Path> stream = Files.newDirectoryStream(sourcePath)) {
125117
for (Path child : stream) {
126118
if (Files.isDirectory(child)) {
127-
copyLocalDirectory(child, destPath.resolve(child.getFileName()), markExec);
119+
copyLocalDirectory(child, destPath.resolve(child.getFileName()));
128120
} else if (Files.isRegularFile(child)) {
129-
copyLocalFile(child, destPath.resolve(child.getFileName()), markExec);
121+
copyLocalFile(child, destPath.resolve(child.getFileName()));
130122
} else {
131123
logger.info("IMG-0035", sourcePath.toString());
132124
}

imagetool/src/test/java/com/oracle/weblogic/imagetool/aru/InstalledPatchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import static org.junit.jupiter.api.Assertions.fail;
1414

1515
@Tag("unit")
16-
public class InstalledPatchTest {
16+
class InstalledPatchTest {
1717
@Test
1818
void getPatchesTest() {
1919
// Parse the output from the image probe to get a list of installed patches

imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/CachedFileTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static org.junit.jupiter.api.Assertions.assertThrows;
2929

3030
@Tag("unit")
31-
public class CachedFileTest {
31+
class CachedFileTest {
3232

3333
static Path cacheDir;
3434
static CacheStore cacheStore;

0 commit comments

Comments
 (0)