Skip to content

Commit 856202b

Browse files
Parse off parentheses from psu name (#1093)
1 parent 214e610 commit 856202b

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

core/src/main/java/oracle/weblogic/deploy/util/XPathUtil.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public XPathUtil(String oracle_home){
3737
this.oracle_home = oracle_home;
3838
patches_home = Paths.get(oracle_home, "inventory", "patches").toString();
3939
}
40+
public XPathUtil() {
41+
// for testing only
42+
}
4043
private static XPathFactory factory = null;
4144

4245
private static synchronized XPathFactory factory() {
@@ -64,15 +67,24 @@ public String getPSU() {
6467
LOGGER.fine("Description {0}", descrip);
6568
if (descrip != null && descrip.startsWith("WLS PATCH SET UPDATE")) {
6669
int idx = descrip.lastIndexOf('.');
67-
String psu = descrip.substring(idx+1);
68-
list.add(psu);
70+
String psu = descrip.substring(idx+1).split("[\\d]+")[0];
71+
list.add(psu);
6972
Collections.sort(list);
7073
return list.get(list.size() -1);
7174
}
7275
}
7376
return null;
7477
}
7578

79+
public String extractPsu(String descrip) {
80+
int idx = descrip.lastIndexOf('.') + 1;
81+
int endIdx = descrip.length() - 1;
82+
if (descrip.charAt(endIdx) == ')') {
83+
endIdx--;
84+
}
85+
return descrip.substring(idx, endIdx+1);
86+
}
87+
7688
/**
7789
* Locate the patch files in the Oracle home
7890
* @return list of patch file names.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import oracle.weblogic.deploy.util.XPathUtil;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
public class XPathUtilTest {
14+
15+
@Test
16+
void testPSUWithParen() {
17+
XPathUtil util = new XPathUtil();
18+
String tester = new String(".2145)");
19+
String expected = new String("2145");
20+
String actual = util.extractPsu(tester);
21+
assertEquals(expected, actual);
22+
}
23+
24+
@Test
25+
void testPSU() {
26+
XPathUtil util = new XPathUtil();
27+
String tester = new String(".2145");
28+
String expected = new String("2145");
29+
String actual = util.extractPsu(tester);
30+
assertEquals(expected, actual);
31+
}
32+
}

0 commit comments

Comments
 (0)