Commit 26a161ba authored by Paff's avatar Paff
Browse files

fixes for transformation

transformation in three steps because the visitor uses an iterator and
it is not possible to delete an element during this process without
conflicts
find elements which are needed, find elements which are not needed,
delete this elements
parent 4addd9e3
......@@ -5,20 +5,20 @@ import interfaces2.namespaces.NameSpace;
import interfaces2.resolvers.AmbigousException;
import interfaces2.resolvers.Resolver;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.jgrapht.DirectedGraph;
import org.jgrapht.traverse.DepthFirstIterator;
import secarc.MontiSecArcConstants;
import secarc._ast.ASTSecArcCPE;
import secarc._ast.ASTSecArcConfiguration;
import secarc._ast.ASTSecArcIdentity;
import secarc._ast.ASTSecArcPEP;
import secarc._ast.ASTSecArcRole;
import secarc._ast.ASTSecArcTrustLevel;
import secarc._ast.ASTSecArcTrustlevelRelation;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.entries.CPEEntry;
import secarc.ets.entries.ConfigurationEntry;
import secarc.ets.entries.PEPEntry;
......@@ -43,11 +43,14 @@ import mc.umlp.arcd._ast.ASTMCCompilationUnit;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.ConnectorEntry;
import mc.umlp.arcd.ets.entries.PortEntry;
import mc.umlp.common._ast.UMLPNode;
public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
private List<STEntry> entries;
private List<UMLPNode> removeNodes = new ArrayList<UMLPNode>();
private Resolver resolver;
protected Map<ASTNode, NameSpace> nodesToNameSpaces;
......@@ -61,7 +64,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
*
* @param dslroot dsl root to use
*/
public AnalysisCriticalPortTransformationVisitor(final MontiSecArcRoot dslroot) {
public AnalysisCriticalPortTransformationVisitor() {
super();
}
......@@ -77,6 +80,10 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
this.entries = entries;
}
public List<UMLPNode> getRemoveNodes() {
return removeNodes;
}
/**
* Visits compilation unit and builds the architecture graph
*
......@@ -103,7 +110,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
for(String role : node.getRoles()) {
RoleEntry entry = (RoleEntry) resolver.resolve(role, RoleEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
}
} catch (AmbigousException e) {
......@@ -116,7 +123,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
ConfigurationEntry entry = (ConfigurationEntry) resolver.resolve(node.getName(), ConfigurationEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
} catch (AmbigousException e) {
// not checked here
......@@ -128,7 +135,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
PEPEntry entry = (PEPEntry) resolver.resolve(MontiSecArcConstants.PEP_NAME, PEPEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
} catch (AmbigousException e) {
// not checked here
......@@ -140,7 +147,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
TrustlevelEntry entry = (TrustlevelEntry) resolver.resolve(MontiSecArcConstants.TRUSTLEVEL_NAME, TrustlevelEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
} catch (AmbigousException e) {
// not checked here
......@@ -152,7 +159,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
CPEEntry entry = (CPEEntry) resolver.resolve(MontiSecArcConstants.CPE_NAME, CPEEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
} catch (AmbigousException e) {
// not checked here
......@@ -165,7 +172,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
for(ASTQualifiedName target : node.getTargets()) {
ConnectorEntry entry = (ConnectorEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(target.getParts()), ConnectorEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
}
} catch (AmbigousException e) {
......@@ -179,7 +186,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
for(ASTQualifiedName target : node.getTargets()) {
ConnectorEntry entry = (ConnectorEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(target.getParts()), ConnectorEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
}
} catch (AmbigousException e) {
......@@ -192,7 +199,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
PortEntry entry = (PortEntry) resolver.resolve(node.getName(), PortEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
} catch (AmbigousException e) {
// not checked here
......@@ -204,21 +211,28 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
ComponentEntry entry = (ComponentEntry) resolver.resolve(node.getName(), ComponentEntry.KIND, getNameSpaceFor(node));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
}
//Delete Identity link, if the component is a target or source
Vertex<ComponentEntry> componentVertex = Vertex.of(entry);
//Check for target
DepthFirstIterator<Vertex<? extends STEntry>, Edge> iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(graphIdentityEdges.getReversedRawGraph(), componentVertex);
if(iterator.hasNext()) {
iterator.next().getArchitectureElement().getNode().delete();
}
//Check for source
iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(graphIdentityEdges.getRawGraph(), componentVertex);
if(iterator.hasNext()) {
iterator.next().getArchitectureElement().getNode().delete();
removeNodes.add(node);
//Delete Identity link, if the component is a target or source
Vertex<ComponentEntry> componentVertex = Vertex.of(entry);
DirectedGraph<Vertex<? extends STEntry>, Edge> reversedRawGraph = graphIdentityEdges.getReversedRawGraph();
//Check for target
DepthFirstIterator<Vertex<? extends STEntry>, Edge> iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(reversedRawGraph, componentVertex);
iterator.next();
if(iterator.hasNext()) {
Vertex<? extends STEntry> identity = iterator.next();
removeNodes.add((UMLPNode) identity.getArchitectureElement().getNode());
reversedRawGraph.removeVertex(identity);
}
//Check for source
iterator = new DepthFirstIterator<Vertex<? extends STEntry>, Edge>(reversedRawGraph, componentVertex);
iterator.next();
if(iterator.hasNext()) {
Vertex<? extends STEntry> identity = iterator.next();
removeNodes.add((UMLPNode) identity.getArchitectureElement().getNode());
reversedRawGraph.removeVertex(identity);
}
}
} catch (AmbigousException e) {
// not checked here
......@@ -230,7 +244,7 @@ public class AnalysisCriticalPortTransformationVisitor extends ConcreteVisitor {
try {
TrustlevelRelationEntry entry = (TrustlevelRelationEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(node.getServer().getParts()), TrustlevelRelationEntry.KIND, getNameSpaceFor(node.getMainParent()));
if(entry != null && !this.entries.contains(entry)) {
node.delete();
removeNodes.add(node);
}
} catch (AmbigousException e) {
// not checked here
......
......@@ -5,6 +5,7 @@ import interfaces2.Interfaces2Constants;
import interfaces2.namespaces.NameSpace;
import interfaces2.resolvers.Resolver;
import java.util.List;
import java.util.Map;
import secarc._ast.ASTMCCompilationUnit;
......@@ -15,6 +16,7 @@ import secarc.ets.check.MontiSecArcAnalysisWorkflow;
import mc.DSLWorkflow;
import mc.ast.ASTNode;
import mc.ast.InheritanceVisitor;
import mc.umlp.common._ast.UMLPNode;
public class AnalysisCriticalPortTransformationWorkflow<T extends MontiSecArcRoot> extends DSLWorkflow<T> {
......@@ -67,12 +69,17 @@ public class AnalysisCriticalPortTransformationWorkflow<T extends MontiSecArcRoo
//Delete Elements which are not needed
if(preVisitor.getEntries() != null) {
AnalysisCriticalPortTransformationVisitor visitorTransform = new AnalysisCriticalPortTransformationVisitor(dslroot);
AnalysisCriticalPortTransformationVisitor visitorTransform = new AnalysisCriticalPortTransformationVisitor();
visitorTransform.setResolver(resolver);
visitorTransform.setNodesToNameSpaces(nodesToNameSpaces);
visitorTransform.setEntries(preVisitor.getEntries());
InheritanceVisitor.run(visitorTransform, dslroot.getAst());
//Delete all entries
for(UMLPNode node : visitorTransform.getRemoveNodes()) {
node.delete();
}
}
//Analysis for transformed Entries
......
......@@ -23,6 +23,7 @@ import secarc.ets.graph.Vertex;
import mc.MCG;
import mc.ast.ASTNode;
import mc.ast.ConcreteVisitor;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd._ast.ASTMCCompilationUnit;
import mc.umlp.arcd.ets.entries.ComponentEntry;
......
......@@ -35,7 +35,7 @@ public class AnalysisTrustlevelTransformationVisitor extends ConcreteVisitor {
*
* @param dslroot dsl root to use
*/
public AnalysisTrustlevelTransformationVisitor(final MontiSecArcRoot dslroot) {
public AnalysisTrustlevelTransformationVisitor() {
super();
}
......
......@@ -59,7 +59,7 @@ public class AnalysisTrustlevelTransformationWorkflow<T extends MontiSecArcRoot>
}
//Transform entries
AnalysisTrustlevelTransformationVisitor visitor = new AnalysisTrustlevelTransformationVisitor(dslroot);
AnalysisTrustlevelTransformationVisitor visitor = new AnalysisTrustlevelTransformationVisitor();
visitor.setAnalysisParameter(analysisParameter);
visitor.setResolver(resolver);
visitor.setNodesToNameSpaces(nodesToNameSpaces);
......
......@@ -78,7 +78,7 @@ public class MontiSecArcAnalysisTransformationTrustlevelTest extends TestWithSym
MontiSecArcRoot root = (MontiSecArcRoot) initSymtabForRoot(tool, "secarc.analysis.connector.EncryptedPathEndInLowTrustlevel");
//Transform entries
AnalysisTrustlevelTransformationVisitor visitor = new AnalysisTrustlevelTransformationVisitor(root);
AnalysisTrustlevelTransformationVisitor visitor = new AnalysisTrustlevelTransformationVisitor();
List<String> parameters = new ArrayList<String>();
parameters.add(parameter);
visitor.setAnalysisParameter(parameters);
......
......@@ -3,12 +3,20 @@ package secarc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.List;
import mc.ast.ASTNode;
import mc.ast.InheritanceVisitor;
import mc.umlp.arcd._ast.ASTArcSubComponent;
import mc.umlp.common._ast.UMLPNode;
import org.junit.Test;
import secarc._ast.ASTArcComponent;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.transform.criticalport.AnalysisCriticalPortTransformationVisitor;
import secarc.ets.transform.criticalport.PreAnalysisCriticalPortTransformationVisitor;
public class MontiSecArcAnalysisWhatIfCiritcalPortTest extends TestWithSymtabAnalysis<MontiSecArcAnalysisTestTool> {
......@@ -66,4 +74,44 @@ public class MontiSecArcAnalysisWhatIfCiritcalPortTest extends TestWithSymtabAna
assertEquals(4, preVisitor.getEntries().size());
}
/**
* Test Transformation with a critical port
*/
@Test
public void testTranformationCriticalPortWithCriticalPort() {
//First File
System.out.println("CriticalPort.secarc");
MontiSecArcAnalysisTestTool tool = createTestToolWithoutJava(new String[] { "src/test/resources/secarc/analysis/criticalport/CriticalPort.secarc" });
tool.init();
assertTrue(tool.run());
MontiSecArcRoot root = (MontiSecArcRoot) initSymtabForRoot(tool, "secarc.analysis.criticalport.CriticalPort");
//Elements which are needed for analysis
PreAnalysisCriticalPortTransformationVisitor preVisitor = new PreAnalysisCriticalPortTransformationVisitor(root);
preVisitor.setResolver(resolver);
preVisitor.setNodesToNameSpaces(nodesToNameSpaces);
InheritanceVisitor.run(preVisitor, root.getAst());
assertEquals(4, preVisitor.getEntries().size());
//Delete Elements which are not needed
if(preVisitor.getEntries() != null) {
AnalysisCriticalPortTransformationVisitor visitorTransform = new AnalysisCriticalPortTransformationVisitor();
visitorTransform.setResolver(resolver);
visitorTransform.setNodesToNameSpaces(nodesToNameSpaces);
visitorTransform.setEntries(preVisitor.getEntries());
InheritanceVisitor.run(visitorTransform, root.getAst());
//Delete all entries
for(UMLPNode node : visitorTransform.getRemoveNodes()) {
node.delete();
}
}
assertEquals(0, ((ASTArcComponent) root.getAst().getType()).getSubComponents().size());
}
}
......@@ -12,7 +12,7 @@ component CriticalPort {
identity weak help -> targetHelp;
component Help help {
port out int output;
trustlevel +1;
}
......@@ -20,4 +20,5 @@ component CriticalPort {
access user;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment