- Notifications
You must be signed in to change notification settings - Fork 89
Wdt 579 add psu to version #992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits Select commit Hold shift + click to select a range
b2cbc29
Add psu to alias version
CarolynRountree c328cd1
Look up PSU for alias definition wls version
CarolynRountree f209654
fixes for found issues
CarolynRountree bd18de1
Update XPathUtil.java
CarolynRountree 4d4bbfe
Update aliases.py
CarolynRountree c1813c0
Update model_context.py
CarolynRountree 4014222
resolve requests for changes
CarolynRountree 6e2a030
resolve requests for changes
CarolynRountree 6a801fc
resolve outstanding requests
CarolynRountree c219b2d
fix unit test
CarolynRountree 6fc06d5
add psu for 12.2.1.3
CarolynRountree e639774
add psu changes for attributes in security configuration
CarolynRountree 7466077
fix broken unit test
CarolynRountree cd0b234
Update XPathUtil.java
CarolynRountree 193613b
Update aliases.py
CarolynRountree 5b2ef64
Update model_context.py
CarolynRountree 3268aff
Update wlsdeploy_rb.properties
CarolynRountree 3da571d
Update aliases_test.py
CarolynRountree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions 138 core/src/main/java/oracle/weblogic/deploy/util/XPathUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright (c) 2021, 2022, Oracle Corporation and/or its affiliates. | ||
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
*/ | ||
package oracle.weblogic.deploy.util; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
import org.xml.sax.SAXException; | ||
| ||
import javax.xml.XMLConstants; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathConstants; | ||
import javax.xml.xpath.XPathExpressionException; | ||
import javax.xml.xpath.XPathFactory; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.*; | ||
| ||
import oracle.weblogic.deploy.logging.PlatformLogger; | ||
import oracle.weblogic.deploy.logging.WLSDeployLogFactory; | ||
| ||
/* | ||
* Parse the xml file at the designated location for the PSU value | ||
*/ | ||
public class XPathUtil { | ||
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.util"); | ||
String oracle_home; | ||
String patches_home; | ||
public XPathUtil(String oracle_home){ | ||
this.oracle_home = oracle_home; | ||
patches_home = Paths.get(oracle_home, "inventory", "patches").toString(); | ||
} | ||
private static XPathFactory factory = null; | ||
| ||
private static synchronized XPathFactory factory() { | ||
if (factory == null) { | ||
factory = XPathFactory.newInstance(); | ||
} | ||
return factory; | ||
} | ||
| ||
/* | ||
* Get the PSU if one exists at the inventory/patches files. Look at the description | ||
* for the PSU wording. | ||
*/ | ||
public String getPSU() { | ||
// find the names in the directory first | ||
if (!(new File(patches_home)).exists()) { | ||
LOGGER.info("No patches home at {0}", patches_home); | ||
return null; | ||
} | ||
List<String> patch_files = findPatchFiles(); | ||
List<String> list = new ArrayList<>(); | ||
for (String patch_file : patch_files){ | ||
Document doc = readXmlFile(patch_file); | ||
String descrip = description(doc, "//@description"); | ||
LOGGER.fine("Description {0}", descrip); | ||
if (descrip != null && descrip.startsWith("WLS PATCH SET UPDATE")) { | ||
int idx = descrip.lastIndexOf('.'); | ||
String psu = descrip.substring(idx+1); | ||
list.add(psu); | ||
Collections.sort(list); | ||
return list.get(list.size() -1); | ||
} | ||
} | ||
return null; | ||
} | ||
| ||
/** | ||
* Locate the patch files in the Oracle home | ||
* @return list of patch file names. | ||
*/ | ||
public List<String> findPatchFiles() { | ||
List<String> patch_files = new ArrayList<String>(); | ||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(new File(patches_home).toPath())){ | ||
for (Path path : stream) { | ||
patch_files.add(path.toString()); | ||
} | ||
} catch (IOException ieo) { | ||
LOGGER.info("Unable to locate the patch files at {0}", patches_home); | ||
} | ||
return patch_files; | ||
} | ||
| ||
/** | ||
* Read the xml file at the indicated path. | ||
* @param path to the xml file | ||
* @return Document from the parsed xml file | ||
*/ | ||
public Document readXmlFile(String path) { | ||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
try { | ||
dbf.setXIncludeAware(false); | ||
dbf.setExpandEntityReferences(false); | ||
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); | ||
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); | ||
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); | ||
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); | ||
} catch (ParserConfigurationException pce) { | ||
LOGGER.warning("Unable to set feature in DocumentBuilderFactory : {0}"); | ||
} | ||
| ||
Document doc = null; | ||
try { | ||
// parse XML file | ||
DocumentBuilder db = dbf.newDocumentBuilder(); | ||
| ||
doc = db.parse(new File(path)); | ||
| ||
} catch (ParserConfigurationException | SAXException | IOException ioe) { | ||
LOGGER.info("Unable to parse the xml file {0}", path); | ||
} | ||
return doc; | ||
} | ||
| ||
/** | ||
* Apply the expression against the Node and return a String. | ||
* @param node parsed xml file Node to search | ||
* @param expression to evaluate on the Node | ||
* @return the String value if located in the Node | ||
*/ | ||
private String description(Node node, String expression) { | ||
XPath xpath = factory().newXPath(); | ||
try { | ||
return (String) xpath.evaluate(expression, node, XPathConstants.STRING); | ||
} catch (XPathExpressionException xpe) { | ||
LOGGER.info("Unable to apply the expression {0}", expression); | ||
} | ||
return null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.