Skip to content

Commit

Permalink
Merge branch 'bug37031303-inspect-patches' into 'main'
Browse files Browse the repository at this point in the history
Bug 37031303 inspect patches dropping last patch when no trailing semicolon

See merge request weblogic-cloud/weblogic-image-tool!482
  • Loading branch information
ddsharpe committed Sep 6, 2024
2 parents 143fa84 + a61fffe commit 6d82a07
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String description() {
public static List<InventoryPatch> parseInventoryPatches(String patchesString) {
List<InventoryPatch> patches = new ArrayList<>();
// Pattern defines a tuple of three elements: patch ID, patch UID, and patch description.
Pattern tuplePattern = Pattern.compile("(\\d+);(\\d+);\\\"(.*?)\\\";");
Pattern tuplePattern = Pattern.compile("(\\d+);(\\d+);\\\"(.*?)\\\";?");
Matcher patchMatcher = tuplePattern.matcher(patchesString);
while (patchMatcher.find()) {
InventoryPatch patch = new InventoryPatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ private String replaceColorTokens(String text) {
/**
* Formats the log record.
*
* @param record the log record
* @param rec the log record
* @return the formatted log record
*/
@Override
public synchronized String format(LogRecord record) {
public synchronized String format(LogRecord rec) {
StringBuilder sb = new StringBuilder();

date.setTime(record.getMillis());
date.setTime(rec.getMillis());
args[0] = date;

StringBuffer text = new StringBuffer();
Expand All @@ -79,28 +79,28 @@ public synchronized String format(LogRecord record) {

// Level
sb.append(" <");
sb.append(record.getLevel().getLocalizedName());
sb.append(rec.getLevel().getLocalizedName());
sb.append(">");

// Class name
sb.append(" <");
String source = record.getSourceClassName();
String source = rec.getSourceClassName();
if (source != null) {
sb.append(source.substring(source.lastIndexOf('.') + 1));
} else {
sb.append(record.getLoggerName());
sb.append(rec.getLoggerName());
}
sb.append(">");

// Method name
sb.append(" <");
if (record.getSourceMethodName() != null) {
sb.append(record.getSourceMethodName());
if (rec.getSourceMethodName() != null) {
sb.append(rec.getSourceMethodName());
}
sb.append(">");

String messageKey = record.getMessage();
String message = replaceColorTokens(formatMessage(record));
String messageKey = rec.getMessage();
String message = replaceColorTokens(formatMessage(rec));

if (messageKey != null) {
sb.append(" <");
Expand All @@ -111,11 +111,11 @@ public synchronized String format(LogRecord record) {
}
sb.append(" <");
sb.append(message);
if (record.getThrown() != null) {
if (rec.getThrown() != null) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
rec.getThrown().printStackTrace(pw);
pw.close();
sb.append(LINE_SEPARATOR);
sb.append(sw.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
package com.oracle.weblogic.imagetool.inspect;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

import org.junit.jupiter.api.Tag;
Expand All @@ -25,8 +26,8 @@ void testPatchStringParser() {
assertEquals(1, InventoryPatch.parseInventoryPatches("30319071;23384603;\"One-off\";").size());
assertEquals(3, InventoryPatch.parseInventoryPatches(
"30319071;23384603;\"One-off\";26355633;21447583;\"One-off\";26287183;21447582;\"One-off\";").size());
// same as previous but with last semi-colon removed. last patch should be discarded but shouldn't fail.
assertEquals(2, InventoryPatch.parseInventoryPatches(
// same as previous but with last semicolon removed, parser should return same number of patches.
assertEquals(3, InventoryPatch.parseInventoryPatches(
"30319071;23384603;\"One-off\";26355633;21447583;\"One-off\";26287183;21447582;\"One-off\"").size());
}

Expand All @@ -50,7 +51,7 @@ void testMoreProperties() throws IOException {

void testPropertiesToJson(String propsFile, String jsonFile) throws IOException {
Properties loaded = new Properties();
try (InputStream input = new FileInputStream(propsFile)) {
try (InputStream input = Files.newInputStream(Paths.get(propsFile))) {
loaded.load(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ITImagetool {

// STAGING_DIR - directory where JDK and other installers are pre-staged before testing
private static final String STAGING_DIR = System.getProperty("STAGING_DIR");
private static final String wlsImgBldDir = System.getProperty("WLSIMG_BLDDIR");
private static final String wlsImgCacheDir = System.getProperty("WLSIMG_CACHEDIR");
private static final String BLDDIR_ENV = System.getProperty("WLSIMG_BLDDIR");
private static final String CACHEDIR_ENV = System.getProperty("WLSIMG_CACHEDIR");

// Docker images
private static String DB_IMAGE = System.getProperty("DB_IMAGE");
Expand All @@ -74,7 +74,7 @@ class ITImagetool {
private static final String WLS_VERSION = "12.2.1.3.0";
private static final String OPATCH_VERSION = "13.9.4.2.2";
private static final String JDK_VERSION = "8u202";
private static final String JDK_VERSION_8u212 = "8u212";
private static final String JDK_VERSION_212 = "8u212";
private static final String WDT_VERSION = "1.1.2";
private static final Path WDT_ARCHIVE = Paths.get("target", "wdt", "archive.zip");
private static final Path WDT_RESOURCES = Paths.get("src", "test", "resources", "wdt");
Expand All @@ -92,11 +92,11 @@ private static void validateEnvironmentSettings() {
logger.info("Initializing the tests ...");

List<String> missingSettings = new ArrayList<>();
if (Utils.isEmptyString(wlsImgBldDir)) {
if (Utils.isEmptyString(BLDDIR_ENV)) {
missingSettings.add("WLSIMG_BLDDIR");
}

if (Utils.isEmptyString(wlsImgCacheDir)) {
if (Utils.isEmptyString(CACHEDIR_ENV)) {
missingSettings.add("WLSIMG_CACHEDIR");
}

Expand Down Expand Up @@ -129,8 +129,8 @@ private static void validateEnvironmentSettings() {
}
dbContainerName = "InfraDB4" + build_tag;
logger.info("build_tag = " + build_tag);
logger.info("WLSIMG_BLDDIR = " + wlsImgBldDir);
logger.info("WLSIMG_CACHEDIR = " + wlsImgCacheDir);
logger.info("WLSIMG_BLDDIR = " + BLDDIR_ENV);
logger.info("WLSIMG_CACHEDIR = " + CACHEDIR_ENV);
logger.info("STAGING_DIR = " + STAGING_DIR);
logger.info("DB_IMAGE = " + DB_IMAGE);
logger.info("JRE_IMAGE = " + JRE_IMAGE);
Expand Down Expand Up @@ -208,10 +208,10 @@ static void staticPrepare() throws Exception {

logger.info("Setting up the test environment ...");

if (!(new File(wlsImgBldDir)).exists()) {
logger.info(wlsImgBldDir + " does not exist, creating it");
if (!(new File(wlsImgBldDir)).mkdir()) {
throw new IllegalStateException("Unable to create build directory " + wlsImgBldDir);
if (!(new File(BLDDIR_ENV)).exists()) {
logger.info(BLDDIR_ENV + " does not exist, creating it");
if (!(new File(BLDDIR_ENV)).mkdir()) {
throw new IllegalStateException("Unable to create build directory " + BLDDIR_ENV);
}
}

Expand Down Expand Up @@ -706,7 +706,7 @@ void createMiiOl8slim(TestInfo testInfo) throws Exception {

// test assumes that the default JDK version 8u202 is already in the cache

Path tmpWdtModel = Paths.get(wlsImgBldDir, WDT_MODEL1);
Path tmpWdtModel = Paths.get(BLDDIR_ENV, WDT_MODEL1);

// update wdt model file
Files.copy(WDT_RESOURCES.resolve(WDT_MODEL1), tmpWdtModel, StandardCopyOption.REPLACE_EXISTING);
Expand Down Expand Up @@ -788,7 +788,7 @@ void createFmwImgFullInternetAccess(TestInfo testInfo) throws Exception {
// add jdk 8u212 installer to the cache
String addNewJdkCmd = new CacheCommand().addInstaller(true)
.type("jdk")
.version(JDK_VERSION_8u212)
.version(JDK_VERSION_212)
.path(Paths.get(STAGING_DIR, JDK_INSTALLER_NEWER))
.build();

Expand All @@ -801,7 +801,7 @@ void createFmwImgFullInternetAccess(TestInfo testInfo) throws Exception {
// create an image with FMW and the latest PSU using ARU to download the patch
String command = new CreateCommand()
.tag(tagName)
.jdkVersion(JDK_VERSION_8u212)
.jdkVersion(JDK_VERSION_212)
.type("fmw")
.user(oracleSupportUsername)
.passwordEnv("ORACLE_SUPPORT_PASSWORD")
Expand Down Expand Up @@ -835,7 +835,7 @@ void createJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {

// test assumes that the default JDK version 8u202 is already in the cache

Path tmpWdtModel = Paths.get(wlsImgBldDir, WDT_MODEL1);
Path tmpWdtModel = Paths.get(BLDDIR_ENV, WDT_MODEL1);

// update wdt model file
Files.copy(WDT_RESOURCES.resolve(WDT_MODEL1), tmpWdtModel, StandardCopyOption.REPLACE_EXISTING);
Expand Down

0 comments on commit 6d82a07

Please sign in to comment.