Skip to content

Commit

Permalink
Let XmlDiscoverer discover all XMLs
Browse files Browse the repository at this point in the history
  • Loading branch information
FloBoJa committed Apr 22, 2024
1 parent 93fbb82 commit a25f391
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,8 @@ public void execute(final IProgressMonitor monitor) throws JobFailedException, U
}
});

final Map<Path, Document> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<Path, List<GatewayRoute>> routeMap = new HashMap<Path, List<GatewayRoute>>()
if (blackboard.hasPartition(RULE_ID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Path, Document> 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<Path> 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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ final class SpringHelper {
throw new IllegalAccessException()
}

static def findProjectRoot(Path currentPath, Map<Path, Document> 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<Path, Document> poms) {
if (poms === null) {
return null
Expand Down

0 comments on commit a25f391

Please sign in to comment.