Skip to content

Commit

Permalink
add federate__ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Depetrol committed Jul 22, 2024
1 parent 2eeb467 commit 9d0635b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-annotations:$fasterxmlVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:$fasterxmlVersion"
implementation "org.apache.commons:commons-text:$commonsTextVersion"
implementation "org.yaml:snakeyaml:${snakeyamlVersion}"

implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:$klighdVersion") {
exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public FederateInstance(
// If the instantiation is in a bank, then we have to append
// the bank index to the name.
if (instantiation.getWidthSpec() != null) {
this.name = instantiation.getName() + "__" + bankIndex;
this.name = "federate__" + instantiation.getName() + "__" + bankIndex;
} else {
this.name = instantiation.getName();
this.name = "federate__" + instantiation.getName();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.text.StringEscapeUtils;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.target.property.DockerProperty;
import org.lflang.util.FileUtil;
import org.lflang.util.LFCommand;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

/**
* Code generator for docker-compose configurations.
Expand Down Expand Up @@ -128,12 +134,37 @@ public void writeDockerComposeFile(List<DockerData> services, String networkName
if (!dockerConfigFile.isEmpty()) {
var found = FileUtil.findInPackage(Path.of(dockerConfigFile), context.getFileConfig());
if (found != null) {
var destination = dockerComposeDir.resolve("docker-compose-override.yml");
FileUtil.copyFile(found, destination);
this.context
.getErrorReporter()
.nowhere()
.info("Docker compose override file copied to " + destination);
try {
Yaml yamlLoader = new Yaml(new SafeConstructor(new LoaderOptions()));
Map<String, Object> yamlData = yamlLoader.load(Files.newBufferedReader(found));
if (yamlData.containsKey("services")) {
@SuppressWarnings("unchecked") // This will be caught by the try-catch block
var servicesMap = (Map<String, Object>) yamlData.get("services");
var serviceNames = new ArrayList<>(servicesMap.keySet());
for (String serviceName : serviceNames) {
Object value = servicesMap.get(serviceName);
servicesMap.remove(serviceName);
servicesMap.put("federate__" + serviceName, value);
}
}
var destination = dockerComposeDir.resolve("docker-compose-override.yml");
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
dumperOptions.setIndent(4);
dumperOptions.setPrettyFlow(true);
dumperOptions.setIndicatorIndent(2);
Yaml yamlDumper = new Yaml(dumperOptions);
yamlDumper.dump(yamlData, Files.newBufferedWriter(destination));
this.context
.getErrorReporter()
.at(found.toAbsolutePath())
.info("Docker compose override file copied to " + destination);
} catch (Exception e) {
context
.getErrorReporter()
.at(found.toAbsolutePath())
.error("Error parsing docker config file: %s".formatted(e.getMessage()));
}
}
}
var envFile = context.getTargetConfig().get(DockerProperty.INSTANCE).envFile();
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ swtVersion=3.124.0
spotbugsToolVersion=4.7.3
jcipVersion=1.0
commonsTextVersion=1.11.0
snakeyamlVersion=2.0

[manifestPropertyNames]
org.eclipse.xtext=xtextVersion
Expand Down

0 comments on commit 9d0635b

Please sign in to comment.