Skip to content

Commit

Permalink
modify message and remove throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jjiwooLim committed Sep 21, 2023
1 parent 86abda6 commit 25c2ad7
Showing 1 changed file with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public abstract class PrepareFeatureUtil extends ServerFeatureUtil {

private File installJarFile;
private File jsonFile;


public PrepareFeatureUtil(File installDirectory, String openLibertyVersion)
throws PluginScenarioException, PluginExecutionException {
Expand Down Expand Up @@ -82,15 +83,15 @@ public void prepareFeatures(List<String> featureBOMs) throws PluginExecutionExce
File additionalBOM = downloadArtifact(groupId, artifactId, "pom", version);
esaMap.putAll(populateESAMap(additionalBOM));
if(esaMap.isEmpty()) {
warn("There were no feature ESA files to generate feature.json. Please ignore this warning if this is not a user feature.");
warn("\"The features.json could not be generated because the required feature ESA files were not provided for features-bom at coordinates " + groupId + ":" +artifactId + ":" +version);
}else {
prepareFeature(groupId, artifactId, version, additionalBOM, esaMap);
}
}

}

private Map<File, String> populateESAMap(File additionalBOM) throws PluginExecutionException {
private Map<File, String> populateESAMap(File additionalBOM) {
Map<File, String> result = new HashMap<File, String>();
try {
result = downloadArtifactsFromBOM(additionalBOM);
Expand All @@ -109,7 +110,7 @@ private Map<File, String> populateESAMap(File additionalBOM) throws PluginExecut
* @param version
* @throws PluginExecutionException
*/
private void prepareFeature(String groupId, String artifactId, String version, File additionalBOM, Map<File, String> esaMap) throws PluginExecutionException {
private void prepareFeature(String groupId, String artifactId, String version, File additionalBOM, Map<File, String> esaMap) {
try {
String repoLocation = parseRepositoryLocation(additionalBOM, groupId, artifactId, "pom", version);
String targetJsonFile = createArtifactFilePath(repoLocation, groupId, FEATURES_JSON_ARTIFACT_ID, "json",
Expand All @@ -136,28 +137,37 @@ private void prepareFeature(String groupId, String artifactId, String version, F
* artifacts
*/
private Map<File, String> downloadArtifactsFromBOM(File additionalBOM) throws PluginExecutionException {
Map<File, String> result = new HashMap<File, String>();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(additionalBOM);
doc.getDocumentElement().normalize();
NodeList dependencyList = doc.getElementsByTagName("dependency");
for (int itr = 0; itr < dependencyList.getLength(); itr++) {
Node node = dependencyList.item(itr);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) node;
String groupId = eElement.getElementsByTagName("groupId").item(0).getTextContent();
String artifactId = eElement.getElementsByTagName("artifactId").item(0).getTextContent();
String version = eElement.getElementsByTagName("version").item(0).getTextContent();
String type = eElement.getElementsByTagName("type").item(0).getTextContent();

File artifactFile = downloadArtifact(groupId, artifactId, type, version);
result.put(artifactFile, groupId);
}
Map<File, String> result = new HashMap<File, String>();
String[] MavenCoord = {"groupId", "artifactId", "type", "version"};

try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(additionalBOM);
doc.getDocumentElement().normalize();
NodeList dependencyList = doc.getElementsByTagName("dependency");
for (int itr = 0; itr < dependencyList.getLength(); itr++) {
Node node = dependencyList.item(itr);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) node;
// error checking
for (String tag : MavenCoord) {
Node tmp_node = eElement.getElementsByTagName(tag).item(0);
if (tmp_node == null) {
throw new PluginExecutionException(
"Error: <" + tag + "> tag nof found in BOM file.");
}
}
} catch (ParserConfigurationException | SAXException | IOException | NullPointerException e) {
// TODO Auto-generated catch block
String groupId = eElement.getElementsByTagName(MavenCoord[0]).item(0).getTextContent();
String artifactId = eElement.getElementsByTagName(MavenCoord[1]).item(0).getTextContent();
String type = eElement.getElementsByTagName(MavenCoord[2]).item(0).getTextContent();
String version = eElement.getElementsByTagName(MavenCoord[3]).item(0).getTextContent();

File artifactFile = downloadArtifact(groupId, artifactId, type, version);
result.put(artifactFile, groupId);
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
debug(e);
throw new PluginExecutionException("Cannot read the BOM file " + additionalBOM.getAbsolutePath() + ". " + e.getMessage());

Expand Down

0 comments on commit 25c2ad7

Please sign in to comment.