forsyde.io.java.conversyde.ConverSyDeStandalone Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of forsyde-io-java-conversyde Show documentation
Show all versions of forsyde-io-java-conversyde Show documentation
ForSyDe IO Java Parent (+JVM) supporting library
The newest version!
package forsyde.io.java.conversyde;
import forsyde.io.java.core.ForSyDeSystemGraph;
import forsyde.io.java.amalthea.drivers.ForSyDeAmaltheaDriver;
//import forsyde.io.java.drivers.ForSyDeLFDriver;
import forsyde.io.java.drivers.ForSyDeModelHandler;
import forsyde.io.java.sdf3.drivers.ForSyDeSDF3Driver;
import forsyde.io.java.graphviz.drivers.ForSyDeGraphVizDriver;
import forsyde.io.java.kgt.drivers.ForSyDeKGTDriver;
import picocli.CommandLine;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
@CommandLine.Command(name = "conversyde", mixinStandardHelpOptions = true,
description = "Perform conversions in the standard ForSyDe IO library.")
public class ConverSyDeStandalone implements Callable {
public ForSyDeModelHandler forSyDeModelHandler = new ForSyDeModelHandler();
@CommandLine.Parameters(description = "Input model files to be converted.")
private List inputFiles = new ArrayList<>();
@CommandLine.Option(names = {"-o", "--output"}, description = "Output models of the conversion.")
private List outputFiles = new ArrayList<>();
public ConverSyDeStandalone() {
// register additional drivers that do not come with the default model handler.
forSyDeModelHandler.registerDriver(new ForSyDeAmaltheaDriver());
//forSyDeModelHandler.registerDriver(new ForSyDeLFDriver());
forSyDeModelHandler.registerDriver(new ForSyDeSDF3Driver());
// put it at high priority to override the core graphviz driver
forSyDeModelHandler.registerDriver(new ForSyDeGraphVizDriver(), 0);
forSyDeModelHandler.registerDriver(new ForSyDeKGTDriver());
}
@Override
public Integer call() throws Exception {
if (getInputFiles() != null && getOutputFiles().size() > 0) {
final List filteredInput = new ArrayList<>(inputFiles.size());
final List models = new ArrayList<>(inputFiles.size());
for (final File input : inputFiles) {
final Path inputPath = input.toPath();
if (forSyDeModelHandler.canLoadModel(inputPath)) {
filteredInput.add(inputPath);
} else {
System.out.println("Input model " + inputPath.getFileName() + " has no available converter.");
return 128;
}
}
// could do a streaming version because it complained on exceptions.
for (final Path inputModel : filteredInput) {
models.add(forSyDeModelHandler.loadModel(inputModel));
}
final ForSyDeSystemGraph merged = models.stream()
.reduce(new ForSyDeSystemGraph(), (a, b) -> {
a.mergeInPlace(b);
return a;
});
// finally do the writing
if (outputFiles.size() == 0) outputFiles.add(new File("converted-model.forsyde.xmi"));
for (File output : outputFiles) {
forSyDeModelHandler.writeModel(merged, output);
}
}
return 0;
}
public static void main(String[] args) {
int exitCode = new CommandLine(new ConverSyDeStandalone()).execute(args);
System.exit(exitCode);
}
public List getInputFiles() {
return inputFiles;
}
public void setInputFiles(List inputFiles) {
this.inputFiles = inputFiles;
}
public List getOutputFiles() {
return outputFiles;
}
public void setOutputFiles(List outputFiles) {
this.outputFiles = outputFiles;
}
}