diff --git a/.github/workflows/sonar-branch.yml b/.github/workflows/sonar-branch.yml index b4cb18f2..d141b5fe 100644 --- a/.github/workflows/sonar-branch.yml +++ b/.github/workflows/sonar-branch.yml @@ -27,7 +27,7 @@ jobs: - name: Sonar Scan run: | mvn -B sonar:sonar \ - -Dsonar.branch.name=main \ + -Dsonar.branch.name=${GITHUB_REF##*/} \ -Dsonar.projectKey=oracle_weblogic-image-tool env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java index db8e5991..98e8f4aa 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java @@ -3,9 +3,9 @@ package com.oracle.weblogic.imagetool.aru; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.xml.xpath.XPathExpressionException; @@ -237,8 +237,14 @@ public static AruPatch selectPatch(List patches, String providedVersio logger.entering(patches, providedVersion, psuVersion, installerVersion); AruPatch selected = null; - Map patchMap = patches.stream().collect(Collectors - .toMap(AruPatch::version, aruPatch -> aruPatch)); + Map patchMap = new HashMap<>(); + for (AruPatch patch: patches) { + if (patchMap.containsKey(patch.version())) { + throw new IllegalStateException(Utils.getMessage("IMG-0122", patch.patchId(), patch.version())); + } + patchMap.put(patch.version(), patch); + } + // select the correct patch version (priority order: user provided version, PSU version, GA installer version) if (providedVersion != null) { // if the user provided a specific version, select the provided version, or fail @@ -270,6 +276,7 @@ public static AruPatch selectPatch(List patches, String providedVersio * @return true if this patch is applicable to the provided platform. */ public boolean isApplicableToTarget(int aruPlatform) { + logger.finer("AruPatch id {0} platform {1} checking against {2}", patchId, platform, aruPlatform); // if this patch is for platform 2000, always return true, else return true if platforms are equal. return platform == 2000 || platform == aruPlatform; } diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruUtil.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruUtil.java index a5a0660f..64c8f26a 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruUtil.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruUtil.java @@ -518,8 +518,11 @@ private List getPatchesOffline(String bugNumber) throws CacheStoreExce if (matcher.groupCount() == 3 && matcher.group(3) != null) { int aruPlatform = Architecture.fromString(matcher.group(3)).getAruPlatform(); patch.platform(Integer.toString(aruPlatform)); + } else { + // architecture was not specified in the cache key, assume generic platform + patch.platform("2000"); } - patch.description("UNAVAILABLE WHILE OFFLINE"); + patch.description("description unavailable while working offline"); patchesInCache.add(patch); } return patchesInCache; diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/PatchVersionException.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/PatchVersionException.java index ba3d8fb2..339fc5ea 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/PatchVersionException.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/PatchVersionException.java @@ -12,7 +12,7 @@ public class PatchVersionException extends IOException { /** - * Signals that the bug number provided was not unique, and has multiple versions available. + * Signals that the bug number provided was unavailable for the requested or derived version. * * @param bugNumber the bug number that was searched * @param versionsAvailable the list of versions for patches of that bug diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonPatchingOptions.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonPatchingOptions.java index c81909e2..92a368ee 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonPatchingOptions.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonPatchingOptions.java @@ -211,6 +211,7 @@ String findPsuVersion(AruPatch aruPatch) { List resolveUserRequestedPatches(String psuVersion) throws XPathExpressionException, IOException, AruException { + logger.entering(psuVersion); List result = new ArrayList<>(patches.size()); // if the user specified the PSU as a normal bug number in the list of --patches, use that String effectivePsuVersion = psuVersion; @@ -248,6 +249,7 @@ List resolveUserRequestedPatches(String psuVersion) result.add(selectedVersion); } } + logger.exiting(result); return result; } diff --git a/imagetool/src/main/resources/ImageTool.properties b/imagetool/src/main/resources/ImageTool.properties index 0c0b0314..4d9fefda 100644 --- a/imagetool/src/main/resources/ImageTool.properties +++ b/imagetool/src/main/resources/ImageTool.properties @@ -120,3 +120,4 @@ IMG-0118=Failed to clean up intermediate container images for build ID {0} IMG-0119=All parameters and options provided after the -- will be passed to the container image build command. IMG-0120=Retries exhausted, unable to download patch from Oracle. Try again later or manually add the patch to the cache to skip this download step. IMG-0121=Did not recognize architecture name {0}. Defaulted to AMD64. +IMG-0122=Invalid patch {0} for version {1}. A patch cannot be both generic and architecture specific. Remove the invalid entry from the cache, like {0}_{1}_xxx64. diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java index 58e3ea57..4d4e4294 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java @@ -68,8 +68,9 @@ static void setup(@TempDir Path tempDir) addToCache(tempDir, "11100003_12.2.1.3.0", "p11100003_122130_Generic.zip"); addToCache(tempDir, "11100007_12.2.1.4.0_arm64", "p11100007_122140_ARM64.zip"); addToCache(tempDir, "11100007_12.2.1.4.0_amd64", "p11100007_122140_AMD64.zip"); - addToCache(tempDir, "11100007_12.2.1.4.0", "p11100007_122140_GENERIC.zip"); - + addToCache(tempDir, "11100008_12.2.1.4.0_arm64", "p11100008_122140_ARM64.zip"); + addToCache(tempDir, "11100008_12.2.1.4.0_amd64", "p11100008_122140_AMD64.zip"); + addToCache(tempDir, "11100008_12.2.1.4.0", "p11100008_122140_GENERIC.zip"); // disable console logging LoggingFacade logger = LoggingFactory.getLogger(PatchFile.class); originalLogLevel = logger.getLevel(); @@ -454,7 +455,7 @@ void resolveArmFile() throws IOException { @Test void findArmPatch() throws Exception { - // 11100007 has multiple patches, 1 ARM, 1 AMD, and 1 GENERIC + // 11100007 has multiple patches, 1 ARM and 1 AMD String patchId = "11100007"; String version = "12.2.1.4.0"; List aruPatches = AruUtil.rest().getPatches(patchId, null, null) @@ -472,4 +473,16 @@ void findArmPatch() throws Exception { assertNotNull(filePathFromCache, "Could not find new patch in cache"); assertEquals(filePath, filePathFromCache, "Patch in cache does not match"); } + + @Test + void illegalCacheEntry() throws Exception { + // 11100008 has multiple patches, 1 ARM, 1 AMD, and 1 GENERIC, generic and architecture specific cannot coexist + String patchId = "11100008"; + String version = "12.2.1.4.0"; + List aruPatches = AruUtil.rest().getPatches(patchId, null, null) + .filter(p -> p.isApplicableToTarget(Architecture.ARM64.getAruPlatform())) + .collect(Collectors.toList()); + assertThrows(IllegalStateException.class, + () -> AruPatch.selectPatch(aruPatches, version, null, version)); + } }