]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Sync git svn branch with SVN repository r33358.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 23 Oct 2016 20:38:15 +0000 (23:38 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 23 Oct 2016 20:38:15 +0000 (23:38 +0300)
refs #6502

bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java

index 65e7f956e48190c86201de421edbd4dff983de00..09931e604bf6fdddf9ab751f20e0f910090210c6 100644 (file)
@@ -3,9 +3,10 @@ package org.simantics.graph.refactoring;
 import java.io.BufferedInputStream;\r
 import java.io.DataInput;\r
 import java.io.DataInputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
 import java.io.InputStream;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+import java.nio.file.Paths;\r
 \r
 import org.simantics.databoard.binding.Binding;\r
 import org.simantics.databoard.binding.mutable.Variant;\r
@@ -13,29 +14,38 @@ import org.simantics.databoard.container.DataContainer;
 import org.simantics.databoard.container.DataContainers;\r
 import org.simantics.graph.representation.TransferableGraph1;\r
 \r
+/**\r
+ * @author Antti Villberg\r
+ * @since 1.24.0\r
+ */\r
 public class FixExportedOntology {\r
        \r
-       public static void main(String[] args) throws Exception {\r
-               \r
-//             File input = new File("E:/work/workspace/apros-head/fi.semantum.simupedia.feature/rootfiles/sharedlibraries/SimupediaStandardLibrary-1.3-trunk.sharedLibrary");\r
-               File input = new File("E:/work/workspace/apros-head/fi.semantum.simupedia.feature/rootfiles/sharedlibraries/AprosSimupedia-1.3-trunk.sharedLibrary");\r
-               File output = new File(input.getParentFile(), input.getName() + ".fixed");\r
-               InputStream is = new FileInputStream(input);\r
+       static void convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception {\r
+               System.out.format("Converting exported shared ontology%n\t" + input.toString() + "%nto bundle-compatible ontology%n\t" + output.toString());\r
+               try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128*1024)) {\r
+                       DataInput dis = new DataInputStream(is);\r
+                       org.simantics.databoard.container.DataContainer container = \r
+                                       DataContainers.readFile(dis); \r
+                       Binding binding = TransferableGraph1.BINDING;\r
+                       TransferableGraph1 graph = (TransferableGraph1)container.content.getValue(binding);\r
+                       GraphRefactoringUtils.fixOntologyExport(graph);\r
 \r
-               is = new BufferedInputStream(is, 128*1024);\r
-               \r
-               DataInput dis = new DataInputStream(is);\r
-               org.simantics.databoard.container.DataContainer container = \r
-                               DataContainers.readFile(dis); \r
-               Binding binding = TransferableGraph1.BINDING;\r
-               TransferableGraph1 graph = (TransferableGraph1)container.content.getValue(binding);\r
-               GraphRefactoringUtils.fixOntologyExport(graph);\r
+                       DataContainers.writeFile(output.toFile(), new DataContainer(\r
+                                       container.format, container.version,\r
+                                       container.metadata, new Variant(TransferableGraph1.BINDING, graph)));\r
+               }\r
+       }\r
 \r
-               DataContainers.writeFile(output, new DataContainer(\r
-                               container.format, container.version,\r
-                               container.metadata, new Variant(TransferableGraph1.BINDING, graph)));\r
-               \r
+       public static void main(String[] args) throws Exception {\r
+               if (args.length < 1) {\r
+                       System.out.println("Required arguments: <input .sharedOntology file> [<output .tg file>]");\r
+               } else if (args.length < 2) {\r
+                       Path input = Paths.get(args[0]);\r
+                       Path output = input.getParent().resolve(input.getName(input.getNameCount()-1) + ".fixed");\r
+                       convertExportedSharedOntologyIntoBundleOntology(input, output);\r
+               } else {\r
+                       convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1]));\r
+               }\r
        }\r
-       \r
 \r
 }\r