Commit 87833730 authored by Paff's avatar Paff
Browse files

wrapper know with script for start

two workflows: first check parameter and then analysis
parent 6888a65f
......@@ -3,7 +3,7 @@ L02-List-Critical-Ports 1
L03-List-Incoming-Ports 1
L04-List-Outgoing-Ports 1
L05-List-Ports-String 1
L06-List-Third-Party-Components 1
L06-List-Third-Party-Components 2
L07-List-Not-Reviewed-Configuration 1
D01-Derive-Role-Component 1
D02-Derive-Role-Port 1
......
......@@ -3,26 +3,15 @@
* http://www.monticore.de/ - http://www.se-rwth.de/ */
package secarc;
import java.util.List;
import com.google.inject.Inject;
import interfaces2.language.ILanguage;
import interfaces2.language.ModelingLanguage;
import interfaces2.workflows.CreateExportedInterfaceWorkflow;
import interfaces2.workflows.PrepareCheckWorkflow;
import mc.DSLRootFactory;
import mc.IErrorDelegator;
import mc.IModelInfrastructureProvider;
import mc.umlp.arcd.ToolConstants;
import mc.umlp.arcd._tool.ArchitectureDiagramRoot;
import mc.umlp.arcd.prettyprint.ArchitectureDiagramPrettyPrintWorkflow;
import secarc._tool.MontiSecArcParsingWorkflow;
import secarc._tool.MontiSecArcRoot;
import secarc._tool.MontiSecArcRootFactory;
import secarc.ets.check.MontiSecArcAnalysisCreator;
import secarc.ets.check.MontiSecArcAnalysisWorkflow;
import secarc.ets.transform.PreCoCoCheckMontiSecArcTransformationWorkflow;
import secarc.ets.transform.criticalport.AnalysisCriticalPortTransformationWorkflow;
import secarc.ets.transform.trustlevel.AnalysisTrustlevelTransformationWorkflow;
import secarc.prettyprint.MontiSecArcPrettyPrintWorkflow;
......@@ -36,16 +25,11 @@ import secarc.prettyprint.MontiSecArcPrettyPrintWorkflow;
*
*/
public final class MontiSecArcAnalysis extends MontiSecArc {
/**
* The {@link mc.DSLRoot} class that encapsulates ASTs of this language.
*/
public static final Class<? extends MontiSecArcRoot> LANGUAGE_ROOT = MontiSecArcRoot.class;
/**
* Factory method for {@link MontiSecArcAnalysis}.l
* Factory method for {@link MontiSecArcAnalysis}.
*/
public static MontiSecArcAnalysis newLanguage(ILanguage component, List<String> analysisParameter, String analysisConfPath) {
public static MontiSecArcAnalysis newLanguage(ILanguage component, String analysisParameter, String analysisConfPath) {
return new MontiSecArcAnalysis(component, analysisParameter, analysisConfPath);
}
......@@ -53,32 +37,13 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
* Constructor for secarc.MontiSecArcAnalysis
*/
@Inject
public MontiSecArcAnalysis(final ILanguage component, List<String> analysisParameter, String analysisConfPath) {
public MontiSecArcAnalysis(final ILanguage component, String analysisParameter, String analysisConfPath) {
super(component);
// PARSING-SETUP
setRootClass(LANGUAGE_ROOT);
this.dslRootClassForUserNames.put(
MontiSecArcConstants.LANGUAGE_SHORTNAME,
LANGUAGE_ROOT);
// Set file-extension
setFileEnding(MontiSecArcConstants.FILE_ENDING);
/* Execution Units */
//WORKFLOWS
addExecutionUnit("parse",
new MontiSecArcParsingWorkflow());
addExecutionUnit("createExported", new CreateExportedInterfaceWorkflow<MontiSecArcRoot>(LANGUAGE_ROOT, this));
addExecutionUnit("prepareCheck", new PrepareCheckWorkflow<MontiSecArcRoot>(LANGUAGE_ROOT, this));
//Transformation-Workflow before coco checks (can be called by "preCheckTransformation" on the command line)
addExecutionUnit("preCheckTransformation", new PreCoCoCheckMontiSecArcTransformationWorkflow<MontiSecArcRoot>(LANGUAGE_ROOT));
//Workflow for analysis with trustlevel
this.addFilterTrustlevelWorkflow(analysisParameter, analysisConfPath);
......@@ -86,7 +51,7 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
this.addFilterCriticalPortWorkflow(analysisConfPath);
//Workflow for analysis
this.addAnalysisWorkflow(analysisConfPath, analysisParameter);
this.addAnalysisWorkflow(analysisConfPath);
// PrettyPrinter (can be called by "print" on the command line)
addExecutionUnit(ToolConstants.WF_PRETTY_PRINT, new MontiSecArcPrettyPrintWorkflow(LANGUAGE_ROOT));
......@@ -98,7 +63,7 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
* @param analysisConfPath Configuration file path
* @param analysisParameter Referenced components for what if analysis
*/
private void addAnalysisWorkflow(String analysisConfPath, List<String> analysisParameter) {
private void addAnalysisWorkflow(String analysisConfPath) {
//Workflow for Analysis
MontiSecArcAnalysisWorkflow<MontiSecArcRoot> analysisWorkflow = new MontiSecArcAnalysisWorkflow<MontiSecArcRoot>(LANGUAGE_ROOT);
//AnalysisCreator
......@@ -109,8 +74,6 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
} else {
analysisWorkflow.setAnalysisConfiguration(MontiSecArcAnalysisCreator.createConfig());
}
//AnalysisParaemter
analysisWorkflow.setAnalysisParameter(analysisParameter);
//Add Workflow for Analysis for advanced users
analysisWorkflow.setAdvanced(false);
//Add Workflow for Analysis for beginners
......@@ -138,28 +101,10 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
* @param analysisParameter Referenced components for what if analysis
* @param analysisConfPath Configuration file path
*/
private void addFilterTrustlevelWorkflow(List<String> analysisParameter, String analysisConfPath) {
private void addFilterTrustlevelWorkflow(String analysisParameter, String analysisConfPath) {
AnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot> trustlevelTransformationWorkflow = new AnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot>(MontiSecArcRoot.class);
trustlevelTransformationWorkflow.setAnalysisParameter(analysisParameter);
addExecutionUnit(MontiSecArcConstants.FILTER_TRUSTLEVEL, trustlevelTransformationWorkflow);
}
/**
* @see interfaces2.language.ModelingLanguage#getRootFactory(mc.IModelInfrastructureProvider,
* mc.IErrorDelegator, java.lang.String)
*/
@Override
public DSLRootFactory<MontiSecArcRoot> getRootFactory(IModelInfrastructureProvider mip,
IErrorDelegator errorDelegator, String encoding) {
return new MontiSecArcRootFactory(mip, errorDelegator, encoding);
}
/**
* @see interfaces2.language.ModelingLanguage#initILanguage()
*/
@Override
protected ILanguage initILanguage() {
return null;
}
}
......@@ -24,23 +24,6 @@ import secarc.ets.check.MontiSecArcContextConditionCreator;
*/
public class MontiSecArcAnalysisTool extends ETSTool {
/**
* The main method of this tool. Creates, initializes and starts
* {@link MontiSecArcAnalysisTool}. Takes a list of {@link DSLTool} arguments.
*
* @param a list of {@link DSLTool} arguments.
*/
public static void main(String[] arguments) {
MCG.initMonticoreGlobals();
List<String> analysisParameter = getAnalysisParameter(arguments);
String analysisConfPath = getAnalysisConfPath(arguments);
MontiSecArcAnalysisTool tool = new MontiSecArcAnalysisTool(cleanArgumentList(arguments), analysisParameter, analysisConfPath);
tool.init();
tool.run();
}
/**
* Path to config file
*
......@@ -101,23 +84,26 @@ public class MontiSecArcAnalysisTool extends ETSTool {
boolean isAnalysisParameter = false;
boolean isAnalysisConfPath = false;
for(String argument : arguments) {
//Filter parameter
if(argument.equals(MontiSecArcConstants.FILTER_TRUSTLEVEL)) {
isAnalysisParameter = true;
cleanedArguments.add(argument);
continue;
}
//Filter config path
if(argument.equals(MontiSecArcConstants.ARG_ANALYSISCONFPATH)) {
isAnalysisConfPath = true;
continue;
}
//Filter config path
if(isAnalysisConfPath) {
isAnalysisConfPath = false;
continue;
}
//Filter parameter
if(isAnalysisParameter) {
//New parameter
if(argument.contains("-") || argument.contains("/")) {
......@@ -138,7 +124,7 @@ public class MontiSecArcAnalysisTool extends ETSTool {
*
* @param arguments
*/
public MontiSecArcAnalysisTool(String[] arguments, List<String> analysisParameter, String analysisConfPath) {
public MontiSecArcAnalysisTool(String[] arguments, String analysisParameter, String analysisConfPath) {
super(arguments);
Injector injector = Guice.createInjector(new MontiSecArcDefaultModule());
......@@ -158,5 +144,26 @@ public class MontiSecArcAnalysisTool extends ETSTool {
setCocoConfiguration(cocoConfig);
}
/**
* Constructor for secarc.MontiSecArcAnalysisTool
*
* @param arguments
*/
public MontiSecArcAnalysisTool(String[] arguments, List<String> analysisParameter) {
super(arguments);
Injector injector = Guice.createInjector(new MontiSecArcDefaultModule());
InjectorProvider.setInjector(injector);
LanguageFamily languageFamily = new LanguageFamily();
languageFamily.addLanguage(MontiSecArcPreAnalysis.newLanguage(injector.getInstance(MontiSecArcComponent.class), analysisParameter));
setLanguages(languageFamily);
// set default CoCos
Map<String, Type> cocoConfig = MontiSecArcContextConditionCreator.createConfig();
cocoConfig.putAll(MontiSecArcAnalysisCreator.createConfig());
setCocoConfiguration(cocoConfig);
}
}
package secarc;
import java.lang.reflect.Constructor;
import java.util.LinkedList;
import java.util.List;
import secarc.ets.check.MontiSecArcAnalysisConstants;
import mc.MCG;
/**
* Tool for {@link MontiSecArcAnalysis}.
* For terminal controlled session
*
* @author (last commit) $Author$
* @version $Revision$, $Date$
*
*/
public class MontiSecArcAnalysisToolWrapper extends MontiSecArcAnalysisTool {
/**
* Class of the dsl tool that is used.
*/
protected static Class<MontiSecArcAnalysisToolWrapper> toolClass = MontiSecArcAnalysisToolWrapper.class;
/**
* Generate test output to this folder.
*/
public static final String OUTPUT_TEST_FOLDER = "target/testOut";
/**
* Test symbol table directory.
*/
public static final String SYMTAB_FOLDER = "target/symtab";
/**
* constructor for preparing parameter
*
* @param arguments
* @param analysisParameter
*/
public MontiSecArcAnalysisToolWrapper(String[] arguments, List<String> analysisParameter) {
super(arguments, analysisParameter);
}
/**
* constructor for analysis
*
* @param arguments
* @param analysisParameter
* @param analysisPath
*/
public MontiSecArcAnalysisToolWrapper(String[] arguments, String analysisParameter, String analysisPath) {
super(arguments, analysisParameter, analysisPath);
}
/**
* The main method of this tool. Creates, initializes and starts
* {@link MontiSecArcAnalysisTool}. Takes a list of {@link DSLTool} arguments.
*
* @param a list of {@link DSLTool} arguments.
*/
public static void main(String[] arguments) {
MontiSecArcAnalysisTool tool = null;
//Start Checking for parameters if parameters exist
if(getAnalysisParameter(arguments).size() > 0) {
System.out.println("\nStart: Checking parameter...\n");
MCG.initMonticoreGlobals();
tool = preCreateToolWithoutJava(arguments);
tool.init();
tool.run();
}
//Analysis
//Analysis for every parameter
if(MontiSecArcAnalysisConstants.EXISTING_PARAMETER.size() > 0) {
for(String analysisParameter : MontiSecArcAnalysisConstants.EXISTING_PARAMETER) {
System.out.println("\nStart: Analysis for " + analysisParameter);
MCG.initMonticoreGlobals();
tool = createToolWithoutJava(arguments, analysisParameter);
tool.init();
tool.run();
}
} else {
//Analysis without parameter
System.out.println("\nStart analysis\n");
MCG.initMonticoreGlobals();
tool = createToolWithoutJava(arguments, "");
tool.init();
tool.run();
}
System.out.println("\nDone");
}
/**
* Use start script for arguments
*
* @param arguments
* @return
*/
protected static MontiSecArcAnalysisToolWrapper preCreateToolWithoutJava(String[] arguments) {
MontiSecArcAnalysisToolWrapper tool = null;
List<String> argsAsList = new LinkedList<String>();
for (String mp : arguments) {
argsAsList.add(mp);
if(arguments.equals(MontiSecArcConstants.PREPARE_PARAMETER)) {
break;
}
}
try {
Constructor<MontiSecArcAnalysisToolWrapper> constructor = toolClass.getConstructor(String[].class, List.class);
String[] args = argsAsList.toArray(new String[argsAsList.size()]);
tool = constructor.newInstance((Object) cleanArgumentList(args), (Object) getAnalysisParameter(arguments));
}
catch (Exception e) {
e.printStackTrace();
}
return tool;
}
/**
* Use start script for arguments
*
* @param arguments
* @param analysisParameter
* @return
*/
protected static MontiSecArcAnalysisToolWrapper createToolWithoutJava(String[] arguments, String analysisParameter) {
MontiSecArcAnalysisToolWrapper tool = null;
List<String> argsAsList = new LinkedList<String>();
for (int i = 0; i < arguments.length; i++) {
if(arguments.equals(MontiSecArcConstants.PREPARE_PARAMETER)) {
argsAsList.remove(i-1);
argsAsList.remove(i-2);
continue;
}
argsAsList.add(arguments[i]);
}
try {
Constructor<MontiSecArcAnalysisToolWrapper> constructor = toolClass.getConstructor(String[].class, String.class, String.class);
String[] args = argsAsList.toArray(new String[argsAsList.size()]);
tool = constructor.newInstance((Object) cleanArgumentList(args), (Object) analysisParameter, (Object) getAnalysisConfPath(args));
}
catch (Exception e) {
e.printStackTrace();
}
return tool;
}
}
/* Copyright (c) 2012 RWTH Aachen. All rights reserved.
*
* http://www.monticore.de/ - http://www.se-rwth.de/ */
package secarc;
import java.util.List;
import com.google.inject.Inject;
import interfaces2.language.ILanguage;
import interfaces2.language.ModelingLanguage;
import secarc._tool.MontiSecArcRoot;
import secarc.ets.check.MontiSecArcAnalysisCreator;
import secarc.ets.transform.trustlevel.PreAnalysisTrustlevelTransformationWorkflow;
/**
* As subclass of {@link ModelingLanguage}, this class configures the technical
* aspects of MontiSecArcAnalysis.
*
* Checks if the parameter for what if trustlevel exist
*
* @author (last commit) $Author$
* @version $Revision$, $Date$
*
*/
public final class MontiSecArcPreAnalysis extends MontiSecArc {
/**
* Factory method for {@link MontiSecArcPreAnalysis}.
*/
public static MontiSecArcPreAnalysis newLanguage(ILanguage component, List<String> analysisParameter) {
return new MontiSecArcPreAnalysis(component, analysisParameter);
}
/**
* Constructor for secarc.MontiSecArcPreAnalysis
*/
@Inject
public MontiSecArcPreAnalysis(final ILanguage component, List<String> analysisParameter) {
super(component);
/* Execution Units */
//WORKFLOWS
// PrettyPrinter (can be called by "print" on the command line)
PreAnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot> pretransfomration = new PreAnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot>(MontiSecArcRoot.class);
//AnalysisCreator
pretransfomration.setAnalysis(MontiSecArcAnalysisCreator.createPreAnalysis());
pretransfomration.setAnalysisConfiguration(MontiSecArcAnalysisCreator.createPreAnalysisConfig());
pretransfomration.setAnalysisParameter(analysisParameter);
addExecutionUnit(MontiSecArcConstants.PREPARE_PARAMETER, pretransfomration);
}
}
package secarc;
import static mc.umlp.arcd.ToolConstants.ARG_ANALYSIS;
import static mc.umlp.arcd.ToolConstants.ARG_CONF;
import static mc.umlp.arcd.ToolConstants.ARG_MODELPATH;
import static mc.umlp.arcd.ToolConstants.ARG_OUT;
import static mc.umlp.arcd.ToolConstants.ARG_SYMTABDIR;
import static mc.umlp.arcd.ToolConstants.ARG_SYNTHESIS;
import static mc.umlp.arcd.ToolConstants.WF_CREATE_SYMTAB;
import static mc.umlp.arcd.ToolConstants.WF_INIT_CHECK;
import static mc.umlp.arcd.ToolConstants.WF_INIT_SYMTAB;
import static mc.umlp.arcd.ToolConstants.WF_PARSE;
import static mc.umlp.arcd.ToolConstants.WF_PRE_CHECK_TRAFO;
import static mc.umlp.arcd.ToolConstants.WF_RUN_CHECK;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import mc.MCG;
import mc.Parameters;
/**
* Tool for {@link MontiSecArcAnalysis}.
* For terminal controlled session
*
* @author (last commit) $Author$
* @version $Revision$, $Date$
*
*/
public class WrapperMontiSecArcAnalysisTool extends MontiSecArcAnalysisTool {
/**
* Class of the dsl tool that is used.
*/
protected static Class<WrapperMontiSecArcAnalysisTool> toolClass = WrapperMontiSecArcAnalysisTool.class;
/**
* Generate test output to this folder.
*/
public static final String OUTPUT_TEST_FOLDER = "target/testOut";
/**
* Test symbol table directory.
*/
public static final String SYMTAB_FOLDER = "target/symtab";
public WrapperMontiSecArcAnalysisTool(String[] arguments) {
super(cleanArgumentList(arguments), getAnalysisParameter(arguments), getAnalysisConfPath(arguments));
}
/**
* The main method of this tool. Creates, initializes and starts
* {@link MontiSecArcAnalysisTool}. Takes a list of {@link DSLTool} arguments.
*
* @param a list of {@link DSLTool} arguments.
*/
public static void main(String[] arguments) {
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Start analysis... \n\n");
String line = "";
try {
while((line = console.readLine()) != null) {
MCG.initMonticoreGlobals();
MontiSecArcAnalysisTool tool = createTestToolWithoutJava(line.split("\\s"));
tool.init();
tool.run();
System.out.println("\n\nStart analysis... \n\n");
}
} catch (IOException e) {
MCG.getLogger().info(e.getMessage());
}
}
/**
* Terminal comands
*
* -analsisconfpath path/../..
* -synthesis secarc secAnalysisBeginners | secAnalysisAdvanced
* -synthesis secarc secFilterCriticalPort
* -synthesis secarc secFilterTrustlevel
* files
*
*
* @param files
* @param analysisParameter
* @param analysisConfPath
* @return
*/
protected static WrapperMontiSecArcAnalysisTool createTestToolWithoutJava(String[] arguments) {
String[] args = new String[] {
ARG_MODELPATH, "/home/user/workspace/MA-Paff/03.Implementierung/montiSecArcAnalysis/src/main/java",
ARG_CONF, "mc-test.cfg",
ARG_OUT, OUTPUT_TEST_FOLDER,
ARG_SYMTABDIR, SYMTAB_FOLDER,
ARG_ANALYSIS, Parameters.ALL, WF_PARSE,
ARG_ANALYSIS, Parameters.ALL, WF_INIT_SYMTAB,
ARG_ANALYSIS, Parameters.ALL, WF_CREATE_SYMTAB,
ARG_SYNTHESIS, Parameters.ALL, WF_INIT_CHECK,
ARG_SYNTHESIS, "arcd", WF_PRE_CHECK_TRAFO,
ARG_SYNTHESIS, Parameters.ALL, WF_RUN_CHECK,
//Uses analysis workflow
};
WrapperMontiSecArcAnalysisTool tool = null;
List<String> argsAsList = new LinkedList<String>();
argsAsList.addAll(Arrays.asList(args));
for (String mp : arguments) {
argsAsList.add(mp);
}
try {
Constructor<WrapperMontiSecArcAnalysisTool> constructor = toolClass.getConstructor(String[].class);
args = argsAsList.toArray(new String[argsAsList.size()]);
tool = constructor.newInstance((Object) args);
}
catch (Exception e) {
e.printStackTrace();
}
return tool;