Skip to content

Commit 3105d39

Browse files
authored
Select patch version for a bug based on PSU version (#176)
* choose the patch version when not supplied based on the PSU of the source image for update * obfuscate bug numbers from unit test data
1 parent c21e10e commit 3105d39

File tree

23 files changed

+1080
-252
lines changed

23 files changed

+1080
-252
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/api/model/CachedFile.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Path;
1111
import java.nio.file.Paths;
1212
import java.util.Objects;
13+
import javax.xml.xpath.XPathExpressionException;
1314

1415
import com.oracle.weblogic.imagetool.cachestore.CacheStore;
1516
import com.oracle.weblogic.imagetool.installer.InstallerType;
@@ -38,8 +39,10 @@ public class CachedFile {
3839
*/
3940
public CachedFile(String id, String version) {
4041
Objects.requireNonNull(id, "key for the cached file cannot be null");
42+
logger.entering(id, version);
4143
this.id = id;
4244
this.version = version;
45+
logger.exiting();
4346
}
4447

4548
/**
@@ -66,10 +69,14 @@ public String getKey() {
6669
if (id.contains(CacheStore.CACHE_KEY_SEPARATOR)) {
6770
return id;
6871
} else {
69-
return id + CacheStore.CACHE_KEY_SEPARATOR + getVersion();
72+
return buildKeyFromVersion(getVersion());
7073
}
7174
}
7275

76+
protected String buildKeyFromVersion(String version) {
77+
return id + CacheStore.CACHE_KEY_SEPARATOR + version;
78+
}
79+
7380
/**
7481
* Get the version number for this cache entry/file.
7582
* @return the string version of this cached file.
@@ -84,7 +91,7 @@ public String getVersion() {
8491
* @return the Path of the file, if found
8592
* @throws IOException throws FileNotFoundException, if this cached file (key) could not be located in the cache
8693
*/
87-
public String resolve(CacheStore cacheStore) throws IOException {
94+
public String resolve(CacheStore cacheStore) throws IOException, XPathExpressionException {
8895
// check entry exists in cache
8996
String key = getKey();
9097
logger.entering(key);
@@ -103,9 +110,9 @@ public String resolve(CacheStore cacheStore) throws IOException {
103110
* @param buildContextDir directory to copy file to
104111
* @return the path of the file copied to the Docker build context directory
105112
*/
106-
public Path copyFile(CacheStore cacheStore, String buildContextDir) throws IOException {
113+
public Path copyFile(CacheStore cacheStore, String buildContextDir) throws IOException, XPathExpressionException {
107114
logger.entering();
108-
Path result = null;
115+
Path result;
109116
String sourceFile = resolve(cacheStore);
110117
logger.info("IMG-0043", sourceFile);
111118
String targetFilename = new File(sourceFile).getName();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2020, Oracle Corporation and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package com.oracle.weblogic.imagetool.cachestore;
5+
6+
import java.io.IOException;
7+
import java.util.List;
8+
import java.util.stream.Collectors;
9+
10+
import com.oracle.weblogic.imagetool.util.Utils;
11+
12+
public class MultiplePatchVersionsException extends IOException {
13+
14+
/**
15+
* Signals that the bug number provided was not unique, and has multiple versions available.
16+
*
17+
* @param bugNumber the bug number that was searched
18+
* @param versionsAvailable the list of versions for patches of that bug
19+
*/
20+
public MultiplePatchVersionsException(String bugNumber, List<String> versionsAvailable) {
21+
super(Utils.getMessage("IMG-0034", bugNumber,
22+
versionsAvailable.stream()
23+
.map(s -> bugNumber + "_" + s)
24+
.collect(Collectors.joining(", ")))
25+
);
26+
}
27+
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/cachestore/OPatchFile.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class OPatchFile extends PatchFile {
2929
* @param password the password to use with the userId to retrieve the patch
3030
*/
3131
public OPatchFile(String patchId, String userId, String password, CacheStore cache) {
32-
super(getPatchId(patchId), latestVersion(cache, patchId, userId, password), userId, password);
32+
super(getPatchId(patchId), latestVersion(cache, patchId, userId, password), null, userId, password);
3333
}
3434

3535
private static String getPatchId(String patchId) {
@@ -74,7 +74,7 @@ private static String latestVersion(CacheStore cache, String patchId, String use
7474
}
7575

7676
@Override
77-
public String resolve(CacheStore cacheStore) throws IOException {
77+
public String resolve(CacheStore cacheStore) throws IOException, XPathExpressionException {
7878
if (needAruInfo()) {
7979
initPatchInfo();
8080
}
@@ -86,18 +86,16 @@ public String resolve(CacheStore cacheStore) throws IOException {
8686
}
8787

8888
@Override
89-
void confirmUniquePatchSelection() throws IOException {
90-
// if the user did not provide the patch version on the command line, use the latest version from ARU
89+
boolean verifyPatchVersion() throws XPathExpressionException {
90+
// if the user did not provide the patch version on the command line, use the latest version from Oracle Support
9191
if (!isPatchVersionProvided()) {
92-
// grab the latest version for OPatch from ARU
93-
try {
94-
String latestVersion = XPathUtil.applyXPathReturnString(getAruInfo(),
95-
"string(/results/patch[access = 'Open access']/release/@name)");
96-
setPatchVersion(latestVersion);
97-
logger.fine("From ARU, setting OPatch patch version to {0}", latestVersion);
98-
} catch (XPathExpressionException xe) {
99-
throw new IOException(xe.getMessage());
100-
}
92+
// grab the latest version for OPatch from Oracle Support
93+
String latestVersion = XPathUtil.applyXPathReturnString(getAruInfo(),
94+
"string(/results/patch[access = 'Open access']/release/@name)");
95+
setPatchVersion(latestVersion);
96+
logger.fine("From ARU, setting OPatch patch version to {0}", latestVersion);
97+
return true;
10198
}
99+
return false;
102100
}
103101
}

0 commit comments

Comments
 (0)