Skip to content

Commit f4378d4

Browse files
author
dr6817
authored
Merge pull request #71 from PalladioSimulator/xml_and_multiroute
XML improvement and Multi-URL Support
2 parents 81ed500 + 9eb51ef commit f4378d4

File tree

7 files changed

+59
-32
lines changed

7 files changed

+59
-32
lines changed

bundles/org.palladiosimulator.retriever.extraction.discoverers/src/org/palladiosimulator/retriever/extraction/discoverers/XmlDiscoverer.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,8 @@ public void execute(final IProgressMonitor monitor) throws JobFailedException, U
5454
}
5555
});
5656

57-
final Map<Path, Document> poms = new HashMap<>();
58-
xmls.keySet()
59-
.stream()
60-
.filter(p -> p.getFileName()
61-
.toString()
62-
.equalsIgnoreCase("pom.xml"))
63-
.forEach(p -> poms.put(p, xmls.get(p)));
6457
this.getBlackboard()
65-
.putDiscoveredFiles(DISCOVERER_ID, poms);
58+
.putDiscoveredFiles(DISCOVERER_ID, xmls);
6659
}
6760

6861
@Override

bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ class EcmaScriptRules implements Rule {
8585
if (!mappedURL.isPartOf("/" + hostname)) {
8686
pcmDetector.detectRequiredInterface(GATEWAY_NAME, mappedURL)
8787
}
88-
pcmDetector.detectProvidedOperation(GATEWAY_NAME, null,
89-
new RESTOperationName(hostname, "/" + url))
88+
pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, new RESTOperationName(hostname, "/" + url))
9089
}
9190
}
9291
}
@@ -121,7 +120,7 @@ class EcmaScriptRules implements Rule {
121120
return normalizedRequests
122121
}
123122

124-
def findDirectHttpRequest(Tree element) {
123+
def Map<String, Set<String>> findDirectHttpRequest(Tree element) {
125124
val calls = new HashMap()
126125
element.accept(new SimpleTreeVisitorES6<Void, Void>() {
127126
override visitFunctionCall(FunctionCallTree node, Void v) {
@@ -137,7 +136,11 @@ class EcmaScriptRules implements Rule {
137136
val caller = identifier.getName() + SEPARATOR + member.getIdentifier()
138137
val urls = findLiteralsInArguments(node.getArguments())
139138
if (!urls.isEmpty()) {
140-
calls.put(caller, urls)
139+
if (calls.containsKey(caller)) {
140+
calls.get(caller).addAll(urls)
141+
} else {
142+
calls.put(caller, urls)
143+
}
141144
}
142145
}
143146
return super.visitFunctionCall(node, null)
@@ -180,13 +183,17 @@ class EcmaScriptRules implements Rule {
180183
return calls;
181184
}
182185

183-
def findFunctionDeclarationsWithUrls(Tree element) {
186+
def Map<String, Set<String>> findFunctionDeclarationsWithUrls(Tree element) {
184187
val declarations = new HashMap();
185188
element.accept(new SimpleTreeVisitorES6<Void, Void>() {
186189
override visitFunctionDeclaration(FunctionDeclarationTree functionDeclaration, Void v) {
187190
val urls = findLiteralsForIdentifier(functionDeclaration, URL_KEYWORD)
188191
if (!urls.empty) {
189-
declarations.put(functionDeclaration.name.name, urls)
192+
if (declarations.containsKey(functionDeclaration)) {
193+
declarations.get(functionDeclaration.name.name).addAll(urls)
194+
} else {
195+
declarations.put(functionDeclaration.name.name, urls)
196+
}
190197
}
191198
return super.visitFunctionDeclaration(functionDeclaration, null)
192199
}

bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringGatewayRules.xtend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.palladiosimulator.retriever.extraction.engine.Rule
1515
import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper
1616
import org.palladiosimulator.retriever.extraction.rules.data.GatewayRoute
1717
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard
18+
import org.palladiosimulator.retriever.extraction.rules.util.ProjectHelper
1819

1920
class SpringGatewayRules implements Rule {
2021
static final Logger LOG = Logger.getLogger(SpringGatewayRules)
@@ -34,7 +35,7 @@ class SpringGatewayRules implements Rule {
3435
val poms = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document))
3536
val propertyFiles = blackboard.getDiscoveredFiles(PROPERTIES_DISCOVERER_ID, typeof(Properties))
3637

37-
val projectRoot = SpringHelper.findProjectRoot(path, poms)
38+
val projectRoot = ProjectHelper.findMavenProjectRoot(path, poms)
3839

3940
var Map<Path, List<GatewayRoute>> routeMap = new HashMap<Path, List<GatewayRoute>>()
4041
if (blackboard.hasPartition(RULE_ID)) {

bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper
2222
import org.palladiosimulator.retriever.extraction.rules.util.RESTHelper
2323
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard
2424
import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName
25+
import org.palladiosimulator.retriever.extraction.rules.util.ProjectHelper
2526

2627
class SpringRules implements Rule {
2728
static final Logger LOG = Logger.getLogger(SpringRules)
@@ -44,7 +45,7 @@ class SpringRules implements Rule {
4445
val poms = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document))
4546
val propertyFiles = blackboard.getDiscoveredFiles(PROPERTIES_DISCOVERER_ID, typeof(Properties))
4647

47-
val projectRoot = SpringHelper.findProjectRoot(path, poms)
48+
val projectRoot = ProjectHelper.findMavenProjectRoot(path, poms)
4849
val configRoot = SpringHelper.findConfigRoot(poms)
4950
val bootstrapYaml = projectRoot === null
5051
? null

bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringZuulRules.xtend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.palladiosimulator.retriever.extraction.engine.Rule
1515
import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper
1616
import org.palladiosimulator.retriever.extraction.rules.data.GatewayRoute
1717
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard
18+
import org.palladiosimulator.retriever.extraction.rules.util.ProjectHelper
1819

1920
class SpringZuulRules implements Rule {
2021
static final Logger LOG = Logger.getLogger(SpringZuulRules)
@@ -34,7 +35,7 @@ class SpringZuulRules implements Rule {
3435
val poms = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document))
3536
val propertyFiles = blackboard.getDiscoveredFiles(PROPERTIES_DISCOVERER_ID, typeof(Properties))
3637

37-
val projectRoot = SpringHelper.findProjectRoot(path, poms)
38+
val projectRoot = ProjectHelper.findMavenProjectRoot(path, poms)
3839
val configRoot = SpringHelper.findConfigRoot(poms)
3940

4041
if (configRoot === null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.palladiosimulator.retriever.extraction.rules.util
2+
3+
import java.nio.file.Path
4+
import java.util.Map
5+
import org.jdom2.Document
6+
import java.util.Set
7+
8+
class ProjectHelper {
9+
static def findMavenProjectRoot(Path currentPath, Map<Path, Document> xmls) {
10+
if (currentPath === null || xmls === null) {
11+
return null
12+
}
13+
val closestPom = xmls.keySet.stream // Only keep poms above the current compilation unit.
14+
.filter[path|path.fileName.toString == "pom.xml"]
15+
.filter[path|currentPath.startsWith(path.parent)] // Take the longest path, which is the pom.xml closest to the compilation unit
16+
.max([a, b|a.size.compareTo(b.size)])
17+
18+
if (closestPom.present) {
19+
return closestPom.get.parent
20+
} else {
21+
return null
22+
}
23+
}
24+
25+
static def findProjectRoot(Path currentPath, Set<Path> systemRoots) {
26+
if (currentPath === null || systemRoots === null) {
27+
return null
28+
}
29+
val closestSystemRoot = systemRoots.stream // Only keep build files above the current compilation unit.
30+
.filter([path|currentPath.startsWith(path.parent)]) // Take the longest path, which is the build file closest to the compilation unit
31+
.max([a, b|a.size.compareTo(b.size)])
32+
33+
if (closestSystemRoot.present) {
34+
return closestSystemRoot.get.parent
35+
} else {
36+
return null
37+
}
38+
}
39+
}

bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/util/SpringHelper.xtend

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ final class SpringHelper {
1717
throw new IllegalAccessException()
1818
}
1919

20-
static def findProjectRoot(Path currentPath, Map<Path, Document> poms) {
21-
if (currentPath === null || poms === null) {
22-
return null
23-
}
24-
val closestPom = poms.entrySet.stream.map([entry|entry.key]) // Only keep poms above the current compilation unit.
25-
.filter([path|currentPath.startsWith(path.parent)]) // Take the longest path, which is the pom.xml closest to the compilation unit
26-
.max([a, b|a.size.compareTo(b.size)])
27-
28-
if (closestPom.present) {
29-
return closestPom.get.parent
30-
} else {
31-
return null
32-
}
33-
}
34-
3520
static def findConfigRoot(Map<Path, Document> poms) {
3621
if (poms === null) {
3722
return null

0 commit comments

Comments
 (0)