Added Generation of Middleware Tag files

parent fa77b2a1
Pipeline #83143 failed with stage
in 56 seconds
......@@ -4,6 +4,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Expanded
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.*;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.MiddlewareTagGenImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.apache.commons.io.FileUtils;
......@@ -12,6 +13,16 @@ import java.io.IOException;
import java.util.*;
public class DistributedTargetGenerator extends CMakeGenerator {
private boolean generateMiddlewareTags = false;
public boolean isGenerateMiddlewareTags() {
return generateMiddlewareTags;
}
public void setGenerateMiddlewareTags(boolean generateMiddlewareTags) {
this.generateMiddlewareTags = generateMiddlewareTags;
}
private Set<String> subDirs = new HashSet<>();
......@@ -54,6 +65,12 @@ public class DistributedTargetGenerator extends CMakeGenerator {
files.add(generateRosMsgGen());
}
if(generateMiddlewareTags){
MiddlewareTagGenImpl middlewareTagGen = new MiddlewareTagGenImpl();
middlewareTagGen.setGenerationTargetPath(generationTargetPath + "emam/");
files.addAll(middlewareTagGen.generate(componentInstanceSymbol,taggingResolver));
}
files.add(generateCMake(componentInstanceSymbol));
return files;
}
......
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.MiddlewareSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import java.io.File;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class MiddlewareTagGenImpl implements GeneratorImpl {
private String generationTargetPath;
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> res = new ArrayList<>();
//Collect Ports with Middleware Symbols from Super Component and first level subcomponents
List<PortSymbol> middlewarePortsSuper = componentInstanceSymbol.getPortsList().stream()
.filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent())
.collect(Collectors.toList());
List<PortSymbol> middlewarePortsSub = componentInstanceSymbol.getSubComponents()
.stream()
.flatMap(ecis -> ecis.getPortsList().stream())
.filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent())
.collect(Collectors.toList());
List<PortSymbol> middlewarePorts = new ArrayList<>();
middlewarePorts.addAll(middlewarePortsSub);
middlewarePorts.addAll(middlewarePortsSuper);
res.add(generateRosTags(componentInstanceSymbol.getPackageName(),middlewarePorts));
return res;
}
private File generateRosTags(String packageName ,List<PortSymbol> middlewarePorts) throws IOException {
List<PortSymbol> rosPorts = middlewarePorts.stream()
.filter(PortSymbol::isRosPort)
.collect(Collectors.toList());
FileContent result = new FileContent();
result.setFileName("RosConnections.tag");
StringBuilder content = new StringBuilder();
content.append("package " + packageName +";\n");
content.append("conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;\n");
content.append("\n");
content.append("tags RosConnections{\n");
//Pro port: tag ${port.fullName} with RosConnection (; | topic=(${topicName},${topicType}) , (msgField=${msgField})?);
rosPorts.forEach(p -> {
content.append("tag " + p.getFullName() + " with RosConnection");
RosConnectionSymbol rosSymbol = (RosConnectionSymbol) p.getMiddlewareSymbol().get();
if(rosSymbol.getTopicName().isPresent() && rosSymbol.getTopicType().isPresent()){
content.append(" = {topic = ("+ rosSymbol.getTopicName().get() +", " +rosSymbol.getTopicType().get() + ")");
if(rosSymbol.getMsgField().isPresent()){
content.append(", msgField = " + rosSymbol.getMsgField().get());
}
content.append("}");
}
content.append(";\n");
});
content.append("}");
result.setFileContent(content.toString());
return FileHelper.generateFile(generationTargetPath ,result);
}
@Override
public void setGenerationTargetPath(String path) {
generationTargetPath = path;
}
@Override
public boolean willAccept(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
//TODO: fill?
return true;
}
}
......@@ -364,4 +364,25 @@ public class GenerationTest extends AbstractSymtabTest {
}
@Test
public void testMiddlewareTagFileGeneration() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver(TEST_PATH);
RosToEmamTagSchema.registerTagTypes(taggingResolver);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("lab.system", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
//make sure the middleware tags are loaded
Map<PortSymbol, RosConnectionSymbol> tags = TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
DistributedTargetGenerator middlewareGenerator = new DistributedTargetGenerator();
middlewareGenerator.setGenerationTargetPath("./target/generated-sources-cmake/labWithTags/src/");
//generator for component itself
middlewareGenerator.add(new CPPGenImpl(), "cpp");
//generator for the ros connection
middlewareGenerator.add(new RosCppGenImpl(), "roscpp");
middlewareGenerator.setGenerateMiddlewareTags(true);
middlewareGenerator.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