MasterGenerator now implements GeneratorImpl, composite now possible

parent 5c7f015e
......@@ -14,7 +14,7 @@ import java.util.Objects;
public class CMakeMasterGenerator extends MasterGenerator {
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver, String targetPath) throws IOException {
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
long notInSubfolders = getGeneratorImpls().stream()
.map(this::getImplSubfolder)
.filter(Objects::isNull)
......@@ -25,8 +25,8 @@ public class CMakeMasterGenerator extends MasterGenerator {
return new ArrayList<>();
}
List<File> res = super.generate(componentInstanceSymbol, taggingResolver, targetPath);
res.add(generateCMake(targetPath));
List<File> res = super.generate(componentInstanceSymbol, taggingResolver);
res.add(generateCMake(generationTargetPath));
return res;
}
......
......@@ -8,8 +8,9 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
public class MasterGenerator {
public class MasterGenerator implements GeneratorImpl {
private Map<GeneratorImpl, String> generatorImpls = new HashMap<>();
String generationTargetPath;
public void add(GeneratorImpl generator, String subfolder) {
generatorImpls.put(generator, subfolder);
......@@ -27,14 +28,16 @@ public class MasterGenerator {
return generatorImpls.remove(generator) != null;
}
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver, String targetPath) throws IOException {
@Override
public void setGenerationTargetPath(String path) {
this.generationTargetPath = path.endsWith("/") ? path : path + "/";
}
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> result = new ArrayList<>();
generatorImpls.entrySet()
.forEach(entrySet -> {
String fullTargetPath = targetPath;
if (!fullTargetPath.endsWith("/"))
fullTargetPath = fullTargetPath + "/";
String fullTargetPath = generationTargetPath;
if (entrySet.getValue() != null)
fullTargetPath = fullTargetPath + entrySet.getValue();
......
......@@ -13,17 +13,17 @@ import java.util.stream.Collectors;
public class MiddlewareMasterGenerator extends CMakeMasterGenerator {
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver, String targetPath) throws IOException {
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
//Add dummy GeneratorImpl for the subdir
// String subdir = "Coordinator_"+NameHelper.getComponentNameTargetLanguage(componentInstanceSymbol.getFullName()) +"/";
String subdir = "coordinator/";
this.add(new GeneratorImpl() {
}, subdir);
List<File> files = super.generate(componentInstanceSymbol, taggingResolver, targetPath);
List<File> files = super.generate(componentInstanceSymbol, taggingResolver);
files.add(FileHelper.generateFile(targetPath + subdir, generateIAdapter(componentInstanceSymbol)));
files.add(FileHelper.generateFile(targetPath + subdir, generateCoordinator(componentInstanceSymbol, files)));
files.add(FileHelper.generateFile(targetPath + subdir, generateCMakeList(componentInstanceSymbol, files)));
files.add(FileHelper.generateFile(generationTargetPath + subdir, generateIAdapter(componentInstanceSymbol)));
files.add(FileHelper.generateFile(generationTargetPath + subdir, generateCoordinator(componentInstanceSymbol, files)));
files.add(FileHelper.generateFile(generationTargetPath + subdir, generateCMakeList(componentInstanceSymbol, files)));
return files;
}
......
......@@ -20,10 +20,11 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentInstanceSymbol);
MasterGenerator masterGenerator = new MasterGenerator();
masterGenerator.setGenerationTargetPath("./target/generated-sources/basicGeneration/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
masterGenerator.generate(componentInstanceSymbol, taggingResolver, "./target/generated-sources/basicGeneration/");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
......@@ -35,10 +36,11 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentInstanceSymbol);
MasterGenerator masterGenerator = new CMakeMasterGenerator();
masterGenerator.setGenerationTargetPath("./target/generated-sources/CMakeGeneration/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
masterGenerator.generate(componentInstanceSymbol, taggingResolver, "./target/generated-sources/CMakeGeneration/");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
......@@ -50,11 +52,12 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentInstanceSymbol);
MasterGenerator masterGenerator = new MiddlewareMasterGenerator();
masterGenerator.setGenerationTargetPath("./target/generated-sources/middlewareMasterGenerator/src/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
masterGenerator.add(new DummyMiddlewareGenerator(), "dummy");
masterGenerator.generate(componentInstanceSymbol, taggingResolver, "./target/generated-sources/middlewareMasterGenerator/src/");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
}
......
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