Skip to content
Snippets Groups Projects
Commit 06b4cbe6 authored by Markus Wieczorek's avatar Markus Wieczorek
Browse files

removed variants-folder

parent f36e337a
Branches
No related merge requests found
Showing
with 0 additions and 394 deletions
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("Radar2");
Super().save();
}
}
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("Waffle");
Super().save();
}
}
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("WafflePi");
Super().save();
}
}
File deleted
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<featureModel>
<properties>
<graphics key="showhiddenfeatures" value="true"/>
<graphics key="legendautolayout" value="true"/>
<graphics key="showshortnames" value="false"/>
<graphics key="layout" value="horizontal"/>
<graphics key="showcollapsedconstraints" value="true"/>
<graphics key="legendhidden" value="false"/>
<graphics key="layoutalgorithm" value="1"/>
</properties>
<struct>
<and abstract="true" mandatory="true" name="CarConfigurator">
<alt mandatory="true" name="ConfiguratorMain">
<alt abstract="true" name="TurtleBot">
<feature name="Burger"/>
<feature name="Waffle"/>
<feature name="WafflePi"/>
</alt>
<and abstract="true" name="CustomBot">
<alt abstract="true" name="Camera">
<feature name="Cam1"/>
<feature name="Cam2"/>
</alt>
<and abstract="true" name="NonOpticalSensor">
<graphics key="collapsed" value="false"/>
<alt abstract="true" mandatory="true" name="Radar">
<graphics key="collapsed" value="false"/>
<feature name="Radar1"/>
<feature name="Radar2"/>
</alt>
</and>
</and>
</alt>
</and>
</struct>
</featureModel>
<?xml version="1.0"?>
<struct>
<module name="Burger" types="TurtleBot"></module>
</struct>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/FeatureModelConfigurator/lib/jsoup-1.12.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>FeatureModelImplGenerator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
* A simple program that automatically generates implementations
* for the feature model based on the templates and the model.xml file.
* Parses the model file using jsoup and creates a Main Configurator
* and a .jak for each module.
*
*/
public class ImplGenerator {
public static void main(String[] aArgs) {
ImplGenerator oGenerator = new ImplGenerator();
}
//input path for the model file
String m_sFeatureModelPath = "../FeatureModelConfigurator/model.xml";
//input path for the main configurator template
String m_sMainTemplatePath = "./template/Main.jak";
//input path for the module template
String m_sModuleTemplatePath = "./template/Module.jak";
private ImplGenerator() {
//create jsoup document from model file
Document oFeatureModelDoc;
try {
File oModel = new File(m_sFeatureModelPath);
oFeatureModelDoc = Jsoup.parse(oModel, "UTF-8");
//System.out.println(oFeatureModelDoc.toString());
}
catch (IOException oEx) {
System.out.print(oEx);
return;
}
//create main configurator file
String sDestPath = "../FeatureModelConfigurator/features/ConfiguratorMain/Configurator.jak";
CopyFile(m_sMainTemplatePath, sDestPath);
//get modules
Elements aModules = oFeatureModelDoc.getElementsByAttributeValue("name", "ConfiguratorMain").first().children();
FindNonAbstractModules(aModules);
}
//recusively iterate through modules, create files for all non-abstract modules
private void FindNonAbstractModules(Elements aModules) {
for(Element oModule : aModules) {
//if the Element is not a graphics node
if(oModule.tagName().equals("graphics")) {
continue;
}
//if the module is not abstract
List<Attribute> aAttributes = oModule.attributes().asList();
if(!aAttributes.contains(new Attribute("abstract", "true"))) {
String sModuleName = oModule.attr("name");
if(sModuleName==null) {
System.out.println("Couldn't get Module name");
return;
}
String sTargetPath = "../FeatureModelConfigurator/features/"
+ sModuleName + "/Configurator.jak";
//copy the file
CopyFile(m_sModuleTemplatePath, sTargetPath);
//edit the file and add the name
Path path = Paths.get(sTargetPath);
try {
//write to file
String sContent = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
sContent = sContent.replaceAll("ModuleName", sModuleName);
Files.write(path, sContent.getBytes(StandardCharsets.UTF_8));
}
catch (IOException oEx) {
System.out.print(oEx.toString());
}
}
//if the module has children, iterate through them
if(oModule.children()!=null) {
FindNonAbstractModules(oModule.children());
}
}
}
//copy a file from source to dest
private void CopyFile(String sSource, String sDest) {
File oSourceFile = new File(sSource);
File oDestFile = new File(sDest);
try (FileInputStream fis = new FileInputStream(oSourceFile);
FileOutputStream fos = new FileOutputStream(oDestFile)) {
byte[] aBuffer = new byte[1024];
int nLength;
while ((nLength = fis.read(aBuffer)) > 0) {
fos.write(aBuffer, 0, nLength);
}
System.out.println("copied " + sSource + " to " + sDest);
}
catch (IOException oEx) {
System.out.print(oEx);
}
}
}
import java.util.List;
import java.util.ArrayList;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.*;
import org.jsoup.nodes.Document.OutputSettings;
import org.jsoup.nodes.Document.OutputSettings.Syntax;
import org.jsoup.parser.Parser;
/**
* Main class for the car configurator.
* Is refined by modules, which add selected components to component list.
* This class has to save a file containing the configuration
* and launch the test seletion application afterwards.
*
*
* Naming conventions:
* m_: Member variable
* s: String
* n: Integer number (int, long,...)
* f: Floating point number (float, double,...)
* o: Object
* a: Collection (List, Array,...)
*
*/
public class Configurator {
//module list
private List m_aModuleList;
//output path
private String m_sOutputPath = "./test.xml";
//TODO: set this
//path for test case selector, which has to be launched from this application
private String m_sTestCaseSelectorPath;
//TODO: set this
//path for the Gazebo adapter, which has to be launched from this application
private String m_sGazeboAdapterPath;
//TODO: properly set this
//path to the feature model xml
private String m_sFeatureModelPath = "./model.xml";
//document representation of the feature model
private Document m_oFeatureModelDoc;
//representation of a single module with all of its types
class Module {
String sModuleName;
ArrayList aModuleTypes;
}
public static void main(String[] args) {
new Configurator().save();
}
public void save() {
//transform list to XML document using jsoup
Document oDoc = Jsoup.parse("<?xml version=\"1.0\"?>\n", "", Parser.xmlParser());
Element oStruct = new Element("specification");
oDoc.appendChild(oStruct);
//if the module list was initialized
if(m_aModuleList!=null) {
for(int i=0; i<m_aModuleList.size(); i++) {
//Add module and tag to Document
Element oModuleElement = new Element("module");
//Add name
Module oModule = (Module)m_aModuleList.get(i);
oModuleElement.attr("name", oModule.sModuleName);
//Create type String
ArrayList<String> aTypes = oModule.aModuleTypes;
String sTypesString = "";
//concat String
for(int j=0; j<aTypes.size(); j++) {
sTypesString += aTypes.get(j);
//add comma if it's not the last Type
if(j<aTypes.size()-1)
sTypesString += ", ";
}
oModuleElement.attr("types", sTypesString);
oStruct.appendChild(oModuleElement);
}
}
//generate xml String
OutputSettings oOutputSettings = new OutputSettings();
oOutputSettings.syntax(Syntax.xml);
oDoc.outputSettings(oOutputSettings);
String sDoc = oDoc.toString();
System.out.println(sDoc);
//save to file
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(m_sOutputPath));
writer.write(sDoc);
writer.close();
}
catch (IOException oEx) {
System.out.println(oEx);
}
}
//get all parents of a given module from the Feature Model file
private Module GetModuleParents(String sModuleName) throws IOException {
Module oModule = new Module();
//set name
oModule.sModuleName = sModuleName;
//init Doc if not done
if(m_oFeatureModelDoc==null) {
File oModel = new File(m_sFeatureModelPath);
m_oFeatureModelDoc = Jsoup.parse(oModel, "UTF-8");
}
//should have size 1
org.jsoup.select.Elements aModuleBuffer = m_oFeatureModelDoc.getElementsByAttributeValue("name", sModuleName);
if(aModuleBuffer.size()>1) {
//somethings wrong
//TODO: properly log this
System.out.println("Found more than one module with the name " + sModuleName);
}
Element oModuleElement = aModuleBuffer.first();
//get all anchestors
aModuleBuffer = oModuleElement.parents();
ArrayList<String> aTypes = new ArrayList();
//itterate through parents of module
for(int i=0; i<aModuleBuffer.size(); i++) {
Element oElement = aModuleBuffer.get(i);
String sElementName = oElement.attr("name");
//break if we reach the Main class, as there are no types further up
if(sElementName.equals("ConfiguratorMain")) {
break;
}
aTypes.add(sElementName);
}
oModule.aModuleTypes = aTypes;
return oModule;
}
//add a module name and module type to the feature list. Init list, if not already done
public void addToModuleList(String sModuleName) {
//init List, if not already done
if(m_aModuleList==null) {
m_aModuleList = new ArrayList();
}
//get the module types
Module oModule;
try {
oModule = GetModuleParents(sModuleName);
}
catch (IOException oEx) {
System.out.print(oEx);
return;
}
m_aModuleList.add(oModule);
}
}
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("ModuleName");
Super().save();
}
}
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