Skip to content

Commit 66c686b

Browse files
committed
Add blacklisting and TeammatesRules
1 parent f042eb3 commit 66c686b

File tree

3 files changed

+95
-19
lines changed
  • bundles
    • org.palladiosimulator.retriever.extraction.rules
    • org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine

3 files changed

+95
-19
lines changed

bundles/org.palladiosimulator.retriever.extraction.rules/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,13 @@
8181
class="org.palladiosimulator.retriever.extraction.rules.JaxRSDeploymentRules">
8282
</rule>
8383
</extension>
84+
<extension
85+
id="org.palladiosimulator.retriever.extraction.rules.teammates"
86+
name="Teammates Rules"
87+
point="org.palladiosimulator.retriever.services.rule">
88+
<rule
89+
class="org.palladiosimulator.retriever.extraction.rules.TeammatesRules">
90+
</rule>
91+
</extension>
8492

8593
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.palladiosimulator.retriever.extraction.rules
2+
3+
import java.nio.file.Path;
4+
import java.util.Set
5+
import org.palladiosimulator.retriever.services.blackboard.RetrieverBlackboard
6+
import org.palladiosimulator.retriever.services.Rule
7+
import org.palladiosimulator.retriever.extraction.engine.PCMDetector
8+
9+
class TeammatesRules implements Rule {
10+
11+
static final String RULE_ID = "org.palladiosimulator.retriever.extraction.rules.teammates"
12+
static final String JAVA_DISCOVERER_ID = "org.palladiosimulator.retriever.extraction.discoverers.java"
13+
static final String JAX_RS_RULES_ID = "org.palladiosimulator.retriever.extraction.rules.jax_rs"
14+
15+
override processRules(RetrieverBlackboard blackboard, Path path) {
16+
val pcmDetector = blackboard.PCMDetector as PCMDetector;
17+
pcmDetector.addToBlacklist("teammates.common.util.Logger");
18+
}
19+
20+
override isBuildRule() {
21+
true
22+
}
23+
24+
override getConfigurationKeys() {
25+
return Set.of
26+
}
27+
28+
override getID() {
29+
RULE_ID
30+
}
31+
32+
override getName() {
33+
"Teammates Rules"
34+
}
35+
36+
override getRequiredServices() {
37+
return Set.of(JAVA_DISCOVERER_ID)
38+
}
39+
40+
override getDependentServices() {
41+
Set.of(JAX_RS_RULES_ID)
42+
}
43+
}

bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMDetector.java

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5+
import java.util.HashSet;
6+
import java.util.LinkedList;
57
import java.util.List;
68
import java.util.Map;
79
import java.util.Set;
@@ -47,6 +49,7 @@ public class PCMDetector {
4749
private final RequirementsBuilder compositeRequirements = new RequirementsBuilder();
4850
private final Map<CompUnitOrName, List<String>> weakComponents = new ConcurrentHashMap<>();
4951
private final Map<CompUnitOrName, String> separatingIdentifiers = new ConcurrentHashMap<>();
52+
private final Set<String> blacklist = new HashSet<>();
5053

5154
private static String getFullUnitName(final CompUnitOrName unit) {
5255
// TODO this is potentially problematic, maybe restructure
@@ -76,18 +79,13 @@ private static String getFullUnitName(final CompUnitOrName unit) {
7679

7780
public void detectComponent(final CompUnitOrName unit) {
7881
if (!unit.isUnit()) {
79-
if (this.components.get(unit) == null) {
80-
this.components.put(unit, new ComponentBuilder(unit));
81-
}
82+
tryAddComponent(unit);
8283
return;
8384
}
8485
for (final Object type : unit.compilationUnit()
8586
.get()
8687
.types()) {
87-
if (type instanceof TypeDeclaration) {
88-
if (this.components.get(unit) == null) {
89-
this.components.put(unit, new ComponentBuilder(unit));
90-
}
88+
if (type instanceof TypeDeclaration && tryAddComponent(unit)) {
9189
final ITypeBinding binding = ((TypeDeclaration) type).resolveBinding();
9290
this.detectProvidedInterfaceWeakly(unit, binding);
9391
}
@@ -100,8 +98,8 @@ public void detectRequiredInterface(final CompUnitOrName unit, final InterfaceNa
10098

10199
private void detectRequiredInterface(final CompUnitOrName unit, final InterfaceName interfaceName,
102100
final boolean compositeRequired) {
103-
if (this.components.get(unit) == null) {
104-
this.components.put(unit, new ComponentBuilder(unit));
101+
if (!tryAddComponent(unit)) {
102+
return;
105103
}
106104
final EntireInterface iface = new EntireInterface(interfaceName);
107105
this.detectRequiredInterface(unit, compositeRequired, false, iface);
@@ -117,8 +115,8 @@ public void detectRequiredInterfaceWeakly(final CompUnitOrName unit, final Field
117115

118116
private void detectRequiredInterface(final CompUnitOrName unit, final FieldDeclaration field,
119117
final boolean compositeRequired, final boolean detectWeakly) {
120-
if (this.components.get(unit) == null) {
121-
this.components.put(unit, new ComponentBuilder(unit));
118+
if (!tryAddComponent(unit)) {
119+
return;
122120
}
123121
@SuppressWarnings("unchecked")
124122
final List<OperationInterface> ifaces = ((List<VariableDeclaration>) field.fragments()).stream()
@@ -136,17 +134,17 @@ public void detectCompositeRequiredInterfaceWeakly(final CompUnitOrName unit, fi
136134
return;
137135
}
138136
final ITypeBinding type = method.getDeclaringClass();
139-
if (this.components.get(unit) == null) {
140-
this.components.put(unit, new ComponentBuilder(unit));
137+
if (!tryAddComponent(unit)) {
138+
return;
141139
}
142140
final EntireInterface iface = new EntireInterface(type,
143141
new JavaInterfaceName(NameConverter.toPCMIdentifier(type)));
144142
this.detectRequiredInterface(unit, true, true, iface);
145143
}
146144

147145
public void detectRequiredInterface(final CompUnitOrName unit, final SingleVariableDeclaration parameter) {
148-
if (this.components.get(unit) == null) {
149-
this.components.put(unit, new ComponentBuilder(unit));
146+
if (!tryAddComponent(unit)) {
147+
return;
150148
}
151149
final IVariableBinding parameterBinding = parameter.resolveBinding();
152150
if (parameterBinding == null) {
@@ -245,8 +243,8 @@ public void detectProvidedOperation(final CompUnitOrName unit, final IMethodBind
245243

246244
private void detectProvidedOperation(final CompUnitOrName unit, final IMethodBinding method,
247245
final OperationName name, final boolean compositeProvided, final boolean detectWeakly) {
248-
if (this.components.get(unit) == null) {
249-
this.components.put(unit, new ComponentBuilder(unit));
246+
if (!tryAddComponent(unit)) {
247+
return;
250248
}
251249
final OperationInterface provision = new Operation(method, name);
252250
this.detectProvidedInterface(unit, provision, compositeProvided, detectWeakly);
@@ -290,8 +288,8 @@ public void detectSeparatingIdentifier(final CompUnitOrName unit, final String s
290288
}
291289

292290
public void detectPartOfComposite(final CompUnitOrName unit, final String compositeName) {
293-
if (this.components.get(unit) == null) {
294-
this.components.put(unit, new ComponentBuilder(unit));
291+
if (!tryAddComponent(unit)) {
292+
return;
295293
}
296294
if (!this.composites.containsKey(compositeName)) {
297295
this.composites.put(compositeName, new CompositeBuilder(compositeName));
@@ -380,4 +378,31 @@ public boolean isPartOfComposite(CompUnitOrName name) {
380378
}
381379
return false;
382380
}
381+
382+
public void addToBlacklist(String string) {
383+
this.blacklist.add(string);
384+
385+
// Clean up already added but now blacklisted components
386+
List<CompUnitOrName> toDelete = new LinkedList<>();
387+
for (CompUnitOrName unit : this.components.keySet()) {
388+
if (unit.name()
389+
.equals(string)) {
390+
toDelete.add(unit);
391+
}
392+
}
393+
for (CompUnitOrName unit : toDelete) {
394+
this.components.remove(unit);
395+
}
396+
}
397+
398+
private boolean tryAddComponent(CompUnitOrName unit) {
399+
if (this.components.get(unit) != null) {
400+
return true;
401+
}
402+
if (this.blacklist.contains(unit.name())) {
403+
return false;
404+
}
405+
this.components.put(unit, new ComponentBuilder(unit));
406+
return true;
407+
}
383408
}

0 commit comments

Comments
 (0)