]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java
Use given base name when exporting tg file along with shared library
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / refactoring / FixExportedOntology.java
index 91d85ecf9732f9c5395b1094c2731a0d468e7d4c..27c4b9195522d82291c6374586c0db985d1bfe4b 100644 (file)
@@ -1,7 +1,6 @@
 package org.simantics.graph.refactoring;
 
 import java.io.BufferedInputStream;
-import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.InputStream;
 import java.nio.file.Files;
@@ -10,7 +9,6 @@ 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;
@@ -25,19 +23,15 @@ public class FixExportedOntology {
        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);
-                       org.simantics.databoard.container.DataContainer container = 
-                                       DataContainers.readFile(dis); 
-                       Binding binding = TransferableGraph1.BINDING;
-                       TransferableGraph1 graph = (TransferableGraph1)container.content.getValue(binding);
+                       Binding tgBinding = TransferableGraph1.BINDING;
+                       DataContainer container = DataContainers.readFile(new DataInputStream(is), tgBinding); 
+                       TransferableGraph1 graph = (TransferableGraph1) container.content.getValue(tgBinding);
+
                        GraphRefactoringUtils.fixOntologyExport(graph);
+                       container = TransferableGraphHasher.addHashToTG(container, graph);
 
-                       DataContainers.writeFile(output.toFile(), new DataContainer(
-                                       container.format, container.version,
-                                       container.metadata, new Variant(TransferableGraph1.BINDING, graph)));
-                       
+                       DataContainers.writeFile(output.toFile(), container);
                        return graph;
-                       
                }
        }
        
@@ -50,14 +44,15 @@ public class FixExportedOntology {
            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);
+       public static void createTGAndPGraph(Path input) throws Exception {
         String newName = input.getFileName().toString();
-        if (newName.contains("\\."))
+        if (newName.contains("."))
             newName = newName.split("\\.")[0];
-        Path output2 = input.getParent().resolve(newName + ".pgraph");
+        Path parent = input.getParent();
+        Path output1 = parent.resolve(newName + ".tg");
+        TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, output1);
+        String listing = PrettyPrintTG.print(tg, false);
+        Path output2 = parent.resolve(newName + ".pgraph");
         Files.write(output2, listing.getBytes(),StandardOpenOption.CREATE);
        }
 
@@ -66,7 +61,7 @@ public class FixExportedOntology {
                        System.out.println("Required arguments: <input .sharedLibrary file> [<output .tg file>]");
                } else if (args.length == 1) {
                        Path input = Paths.get(args[0]);
-                       createPGraph(input);
+                       createTGAndPGraph(input);
                } else {
                        convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1]));
                }