X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frefactoring%2FFixExportedOntology.java;h=91d85ecf9732f9c5395b1094c2731a0d468e7d4c;hp=bf0224103228a0838952cf553b9fea9b54d14ed6;hb=fa806341cc06b72051d5e8d709674eb9d5c2bf00;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java index bf0224103..91d85ecf9 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java @@ -7,11 +7,13 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.mutable.Variant; import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; +import org.simantics.graph.representation.PrettyPrintTG; import org.simantics.graph.representation.TransferableGraph1; /** @@ -20,7 +22,7 @@ import org.simantics.graph.representation.TransferableGraph1; */ public class FixExportedOntology { - static void convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception { + static TransferableGraph1 convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception { System.out.format("Converting exported shared ontology%n\t" + input.toString() + "%nto bundle-compatible ontology%n\t" + output.toString()); try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128*1024)) { DataInput dis = new DataInputStream(is); @@ -33,16 +35,38 @@ public class FixExportedOntology { DataContainers.writeFile(output.toFile(), new DataContainer( container.format, container.version, container.metadata, new Variant(TransferableGraph1.BINDING, graph))); + + return graph; + } } + + public static void createTg(Path input) throws Exception { + Path output = input.getParent().resolve("graph.tg"); + createTg(input, output); + } + + private static void createTg(Path input, Path output) throws Exception { + convertExportedSharedOntologyIntoBundleOntology(input, output); + } + + public static void createPGraph(Path input) throws Exception { + Path output1 = input.getParent().resolve("graph.tg"); + TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, output1); + String listing = PrettyPrintTG.print(tg, false); + String newName = input.getFileName().toString(); + if (newName.contains("\\.")) + newName = newName.split("\\.")[0]; + Path output2 = input.getParent().resolve(newName + ".pgraph"); + Files.write(output2, listing.getBytes(),StandardOpenOption.CREATE); + } public static void main(String[] args) throws Exception { - if (args.length < 1) { - System.out.println("Required arguments: []"); - } else if (args.length < 2) { + if (args.length == 0) { + System.out.println("Required arguments: []"); + } else if (args.length == 1) { Path input = Paths.get(args[0]); - Path output = input.getParent().resolve(input.getName(input.getNameCount()-1) + ".fixed"); - convertExportedSharedOntologyIntoBundleOntology(input, output); + createPGraph(input); } else { convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1])); }