Adapt generators to new templates

parent 450898ad
......@@ -43,7 +43,6 @@ public class CMakeGenerator extends StarBridgeGenerator {
getGeneratorImpls().stream()
.filter(gen -> gen.willAccept(componentInstanceSymbol))
.map(this::getImplSubdir)
.sorted()
.forEach(subdir -> content.append("add_subdirectory(" + subdir + ")\n"));
......
......@@ -5,28 +5,28 @@ import de.monticore.lang.monticar.clustering.AutomaticClusteringHelper;
import de.monticore.lang.monticar.clustering.ClusteringResult;
import de.monticore.lang.monticar.clustering.ClusteringResultList;
import de.monticore.lang.monticar.clustering.FlattenArchitecture;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.cli.ClusteringParameters;
import de.monticore.lang.monticar.generator.middleware.cli.ResultChoosingStrategy;
import de.monticore.lang.monticar.generator.middleware.compile.CompilationGenerator;
import de.monticore.lang.monticar.generator.middleware.helpers.ClusterFromTagsHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.NameHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.RosHelper;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.MiddlewareTagGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RclCppGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RosCppGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.*;
import de.monticore.lang.monticar.generator.middleware.templates.compile.CompilationGenerator;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermission;
import java.util.*;
public class DistributedTargetGenerator extends CMakeGenerator {
public class DistributedTargetGenerator{
private boolean generateMiddlewareTags = false;
private ClusteringResultList clusteringResults = new ClusteringResultList();
private CMakeGenerator generatorBlueprint = new CMakeGenerator();
private String generationTargetPath;
public boolean isGenerateMiddlewareTags() {
return generateMiddlewareTags;
......@@ -36,8 +36,6 @@ public class DistributedTargetGenerator extends CMakeGenerator {
this.generateMiddlewareTags = generateMiddlewareTags;
}
private Set<String> subDirs = new HashSet<>();
private ClusteringParameters clusteringParameters;
public DistributedTargetGenerator() {
......@@ -51,7 +49,6 @@ public class DistributedTargetGenerator extends CMakeGenerator {
this.clusteringParameters = clusteringParameters;
}
@Override
public void setGenerationTargetPath(String path) {
String res = path;
if(res.endsWith("/") || res.endsWith("\\")){
......@@ -60,32 +57,48 @@ public class DistributedTargetGenerator extends CMakeGenerator {
if(res.endsWith("/src") || res.endsWith("\\src")){
res = res.substring(0, res.length() - 4);
}
super.setGenerationTargetPath(res);
generationTargetPath = res + "/";
}
@Override
public List<File> generate(EMAComponentInstanceSymbol genComp, TaggingResolver taggingResolver) throws IOException {
Map<EMAComponentInstanceSymbol, GeneratorImpl> generatorMap = new HashMap<>();
EMAComponentInstanceSymbol componentInstanceSymbol = preprocessing(genComp);
generatorBlueprint.setGenerationTargetPath(generationTargetPath);
StarBridgeGenerator completeGenerator = new CMakeGenerator();
completeGenerator.setGenerationTargetPath(generationTargetPath + "src/");
List<EMAComponentInstanceSymbol> clusterSubcomponents = ClusterFromTagsHelper.getClusterSubcomponents(componentInstanceSymbol);
if (clusterSubcomponents.size() > 0) {
clusterSubcomponents.forEach(clusterECIS -> {
String nameTargetLanguage = NameHelper.getNameTargetLanguage(clusterECIS.getFullName());
generatorMap.put(clusterECIS, createFullGenerator(nameTargetLanguage));
});
} else {
String nameTargetLanguage = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
generatorMap.put(componentInstanceSymbol, createFullGenerator(nameTargetLanguage));
if (clusterSubcomponents.isEmpty()) {
clusterSubcomponents = Arrays.asList(componentInstanceSymbol);
}
for (EMAComponentInstanceSymbol clusterECIS : clusterSubcomponents) {
String nameTargetLanguage = NameHelper.getNameTargetLanguage(clusterECIS.getFullName());
StateGenerator stateGenerator = new StateGenerator(createFullGenerator(nameTargetLanguage), clusterECIS, taggingResolver);
completeGenerator.add(stateGenerator, nameTargetLanguage);
}
List<File> files = new ArrayList<>();
for (EMAComponentInstanceSymbol comp : generatorMap.keySet()) {
files.addAll(generatorMap.get(comp).generate(comp, taggingResolver));
//add empty generator to subDirs so that CMakeLists.txt will be generated correctly
subDirs.add(NameHelper.getNameTargetLanguage(comp.getFullName()));
boolean useStructMsgs = false;
if (generatorBlueprint.getGeneratorImpls().stream().anyMatch(gi -> gi instanceof RosCppGenImpl)) {
RosMsgGenImpl msgGen = new RosMsgGenImpl(false);
if(msgGen.willAccept(componentInstanceSymbol)) {
completeGenerator.add(msgGen, "struct_msgs", 0);
useStructMsgs = true;
}
}
if (generatorBlueprint.getGeneratorImpls().stream().anyMatch(gi -> gi instanceof RclCppGenImpl)) {
RosMsgGenImpl msgGen = new RosMsgGenImpl(true);
if(msgGen.willAccept(componentInstanceSymbol)) {
StarBridgeGenerator newGen = new StarBridgeGenerator();
newGen.setGenerationTargetPath(generationTargetPath + "src/");
newGen.add(completeGenerator, "comps");
completeGenerator = newGen;
completeGenerator.add(msgGen, "struct_msgs");
useStructMsgs = true;
}
}
if(generateMiddlewareTags){
......@@ -95,8 +108,8 @@ public class DistributedTargetGenerator extends CMakeGenerator {
files.addAll(middlewareTagGen.generate(componentInstanceSymbol,taggingResolver));
}
files.add(generateCMake(componentInstanceSymbol));
files.addAll(generateCompileScripts());
files.addAll(completeGenerator.generate(componentInstanceSymbol, taggingResolver));
files.addAll(generateCompileScripts(useStructMsgs));
return files;
}
......@@ -147,46 +160,25 @@ public class DistributedTargetGenerator extends CMakeGenerator {
MiddlewareGenerator res = new MiddlewareGenerator();
res.setGenerationTargetPath(generationTargetPath + "src/" + (subdir.endsWith("/") ? subdir : subdir + "/"));
this.getGeneratorImpls().forEach(gen -> res.add(gen, this.getImplSubdir(gen)));
generatorBlueprint.getGeneratorImpls().forEach(gen -> res.add(gen, generatorBlueprint.getImplSubdir(gen)));
return res;
}
private void fixComponentInstance(EMAComponentInstanceSymbol componentInstanceSymbol) {
RosHelper.fixRosConnectionSymbols(componentInstanceSymbol, this.getGeneratorImpls().stream().anyMatch(g -> g instanceof RclCppGenImpl));
}
@Override
protected File generateCMake(EMAComponentInstanceSymbol componentInstanceSymbol) throws IOException {
FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt");
StringBuilder content = new StringBuilder();
content.append("cmake_minimum_required(VERSION 3.5)\n");
content.append("project (default)\n");
content.append("set (CMAKE_CXX_STANDARD 11)\n");
subDirs.stream().filter(dir -> dir.equals("rosMsg")).forEach(
dir -> content.append("add_subdirectory(" + dir + ")\n")
);
subDirs.stream().filter(dir -> !dir.equals("rosMsg")).forEach(
dir -> content.append("add_subdirectory(" + dir + ")\n")
);
fileContent.setFileContent(content.toString());
return FileHelper.generateFile(generationTargetPath + "src/", fileContent);
RosHelper.fixRosConnectionSymbols(componentInstanceSymbol, generatorBlueprint.getGeneratorImpls().stream().anyMatch(g -> g instanceof RclCppGenImpl));
}
protected List<File> generateCompileScripts(){
protected List<File> generateCompileScripts(boolean useStructMsgs){
List<File> res = new ArrayList<>();
boolean useRos = this.getGeneratorImpls().stream().anyMatch(impl -> impl instanceof RosCppGenImpl);
boolean useRos2 = this.getGeneratorImpls().stream().anyMatch(impl -> impl instanceof RclCppGenImpl);
boolean useRos = generatorBlueprint.getGeneratorImpls().stream().anyMatch(impl -> impl instanceof RosCppGenImpl);
boolean useRos2 = generatorBlueprint.getGeneratorImpls().stream().anyMatch(impl -> impl instanceof RclCppGenImpl);
List<CompilationGenerator> generators = CompilationGenerator.getInstanceOfAllGenerators();
generators.forEach(g -> g.setUseRos(useRos));
generators.forEach(g -> g.setUseRos2(useRos2));
generators.forEach(g -> g.setUseStructMsgs(useStructMsgs));
generators.stream()
.peek(g -> g.setUseRos(useRos))
......@@ -200,7 +192,29 @@ public class DistributedTargetGenerator extends CMakeGenerator {
}
});
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
for (File f : res) {
try {
Files.setPosixFilePermissions(f.toPath(), perms);
} catch (IOException e) {
Log.warn("Could not set permissions of " + f.getAbsolutePath());
}
}
return res;
}
public void add(GeneratorImpl generator, String subdir) {
generatorBlueprint.add(generator, subdir);
}
}
......@@ -7,18 +7,28 @@ import de.se_rwth.commons.logging.Log;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StarBridgeGenerator implements GeneratorImpl {
private Map<GeneratorImpl, String> generatorImpls = new HashMap<>();
private List<GeneratorImpl> generators = new ArrayList<>();
String generationTargetPath;
public void add(GeneratorImpl generator, String subdir) {
generators.add(generator);
generatorImpls.put(generator, subdir);
}
public Set<GeneratorImpl> getGeneratorImpls() {
return generatorImpls.keySet();
public void add(GeneratorImpl generator, String subdir, int i) {
generators.add(i, generator);
generatorImpls.put(generator, subdir);
}
public List<GeneratorImpl> getGeneratorImpls() {
return generators;
}
public String getImplSubdir(GeneratorImpl generator) {
......@@ -36,7 +46,8 @@ public class StarBridgeGenerator implements GeneratorImpl {
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> result = new ArrayList<>();
generatorImpls.forEach((key, value) -> {
generators.forEach(key -> {
String value = generatorImpls.get(key);
if (key.willAccept(componentInstanceSymbol)) {
String fullTargetPath = generationTargetPath;
if (value != null)
......
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