From a25f39118e07a4ce4a9faa6a3dbc2f1f205d0cf5 Mon Sep 17 00:00:00 2001 From: Florian Bossert Date: Mon, 22 Apr 2024 13:48:10 +0200 Subject: [PATCH] Let XmlDiscoverer discover all XMLs --- .../extraction/discoverers/XmlDiscoverer.java | 9 +---- .../extraction/rules/SpringGatewayRules.xtend | 3 +- .../extraction/rules/SpringRules.xtend | 3 +- .../extraction/rules/SpringZuulRules.xtend | 3 +- .../extraction/rules/util/ProjectHelper.xtend | 39 +++++++++++++++++++ .../extraction/rules/util/SpringHelper.xtend | 15 ------- 6 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/ProjectHelper.xtend diff --git a/bundles/org.palladiosimulator.retriever.extraction.discoverers/src/org/palladiosimulator/retriever/extraction/discoverers/XmlDiscoverer.java b/bundles/org.palladiosimulator.retriever.extraction.discoverers/src/org/palladiosimulator/retriever/extraction/discoverers/XmlDiscoverer.java index 26fec6f0..444b69f9 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.discoverers/src/org/palladiosimulator/retriever/extraction/discoverers/XmlDiscoverer.java +++ b/bundles/org.palladiosimulator.retriever.extraction.discoverers/src/org/palladiosimulator/retriever/extraction/discoverers/XmlDiscoverer.java @@ -54,15 +54,8 @@ public void execute(final IProgressMonitor monitor) throws JobFailedException, U } }); - final Map poms = new HashMap<>(); - xmls.keySet() - .stream() - .filter(p -> p.getFileName() - .toString() - .equalsIgnoreCase("pom.xml")) - .forEach(p -> poms.put(p, xmls.get(p))); this.getBlackboard() - .putDiscoveredFiles(DISCOVERER_ID, poms); + .putDiscoveredFiles(DISCOVERER_ID, xmls); } @Override diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringGatewayRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringGatewayRules.xtend index 6523aa3d..cf89b886 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringGatewayRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringGatewayRules.xtend @@ -15,6 +15,7 @@ import org.palladiosimulator.retriever.extraction.engine.Rule import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper import org.palladiosimulator.retriever.extraction.rules.data.GatewayRoute import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard +import org.palladiosimulator.retriever.extraction.rules.util.ProjectHelper class SpringGatewayRules implements Rule { static final Logger LOG = Logger.getLogger(SpringGatewayRules) @@ -34,7 +35,7 @@ class SpringGatewayRules implements Rule { val poms = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document)) val propertyFiles = blackboard.getDiscoveredFiles(PROPERTIES_DISCOVERER_ID, typeof(Properties)) - val projectRoot = SpringHelper.findProjectRoot(path, poms) + val projectRoot = ProjectHelper.findMavenProjectRoot(path, poms) var Map> routeMap = new HashMap>() if (blackboard.hasPartition(RULE_ID)) { diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend index e615bc0d..1ebb5391 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend @@ -22,6 +22,7 @@ import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper import org.palladiosimulator.retriever.extraction.rules.util.RESTHelper import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName +import org.palladiosimulator.retriever.extraction.rules.util.ProjectHelper class SpringRules implements Rule { static final Logger LOG = Logger.getLogger(SpringRules) @@ -44,7 +45,7 @@ class SpringRules implements Rule { val poms = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document)) val propertyFiles = blackboard.getDiscoveredFiles(PROPERTIES_DISCOVERER_ID, typeof(Properties)) - val projectRoot = SpringHelper.findProjectRoot(path, poms) + val projectRoot = ProjectHelper.findMavenProjectRoot(path, poms) val configRoot = SpringHelper.findConfigRoot(poms) val bootstrapYaml = projectRoot === null ? null diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringZuulRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringZuulRules.xtend index 7cc9cdde..78c0232a 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringZuulRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringZuulRules.xtend @@ -15,6 +15,7 @@ import org.palladiosimulator.retriever.extraction.engine.Rule import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper import org.palladiosimulator.retriever.extraction.rules.data.GatewayRoute import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard +import org.palladiosimulator.retriever.extraction.rules.util.ProjectHelper class SpringZuulRules implements Rule { static final Logger LOG = Logger.getLogger(SpringZuulRules) @@ -34,7 +35,7 @@ class SpringZuulRules implements Rule { val poms = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document)) val propertyFiles = blackboard.getDiscoveredFiles(PROPERTIES_DISCOVERER_ID, typeof(Properties)) - val projectRoot = SpringHelper.findProjectRoot(path, poms) + val projectRoot = ProjectHelper.findMavenProjectRoot(path, poms) val configRoot = SpringHelper.findConfigRoot(poms) if (configRoot === null) { diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/ProjectHelper.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/ProjectHelper.xtend new file mode 100644 index 00000000..1893a186 --- /dev/null +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/ProjectHelper.xtend @@ -0,0 +1,39 @@ +package org.palladiosimulator.retriever.extraction.rules.util + +import java.nio.file.Path +import java.util.Map +import org.jdom2.Document +import java.util.Set + +class ProjectHelper { + static def findMavenProjectRoot(Path currentPath, Map xmls) { + if (currentPath === null || xmls === null) { + return null + } + val closestPom = xmls.keySet.stream // Only keep poms above the current compilation unit. + .filter[path|path.fileName.toString == "pom.xml"] + .filter[path|currentPath.startsWith(path.parent)] // Take the longest path, which is the pom.xml closest to the compilation unit + .max([a, b|a.size.compareTo(b.size)]) + + if (closestPom.present) { + return closestPom.get.parent + } else { + return null + } + } + + static def findProjectRoot(Path currentPath, Set systemRoots) { + if (currentPath === null || systemRoots === null) { + return null + } + val closestSystemRoot = systemRoots.stream // Only keep build files above the current compilation unit. + .filter([path|currentPath.startsWith(path.parent)]) // Take the longest path, which is the build file closest to the compilation unit + .max([a, b|a.size.compareTo(b.size)]) + + if (closestSystemRoot.present) { + return closestSystemRoot.get.parent + } else { + return null + } + } +} diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/SpringHelper.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/SpringHelper.xtend index a6448b80..e8546ca7 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/SpringHelper.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/SpringHelper.xtend @@ -17,21 +17,6 @@ final class SpringHelper { throw new IllegalAccessException() } - static def findProjectRoot(Path currentPath, Map poms) { - if (currentPath === null || poms === null) { - return null - } - val closestPom = poms.entrySet.stream.map([entry|entry.key]) // Only keep poms above the current compilation unit. - .filter([path|currentPath.startsWith(path.parent)]) // Take the longest path, which is the pom.xml closest to the compilation unit - .max([a, b|a.size.compareTo(b.size)]) - - if (closestPom.present) { - return closestPom.get.parent - } else { - return null - } - } - static def findConfigRoot(Map poms) { if (poms === null) { return null