X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frefactoring%2FFixExportedOntology.java;h=90738f70d1c8243366659ff2901ce315247eafc9;hb=refs%2Fchanges%2F19%2F1519%2F1;hp=65e7f956e48190c86201de421edbd4dff983de00;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git
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 65e7f956e..90738f70d 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
@@ -1,41 +1,75 @@
-package org.simantics.graph.refactoring;
-
-import java.io.BufferedInputStream;
-import java.io.DataInput;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
-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.TransferableGraph1;
-
-public class FixExportedOntology {
-
- public static void main(String[] args) throws Exception {
-
-// File input = new File("E:/work/workspace/apros-head/fi.semantum.simupedia.feature/rootfiles/sharedlibraries/SimupediaStandardLibrary-1.3-trunk.sharedLibrary");
- File input = new File("E:/work/workspace/apros-head/fi.semantum.simupedia.feature/rootfiles/sharedlibraries/AprosSimupedia-1.3-trunk.sharedLibrary");
- File output = new File(input.getParentFile(), input.getName() + ".fixed");
- InputStream is = new FileInputStream(input);
-
- is = new BufferedInputStream(is, 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);
- GraphRefactoringUtils.fixOntologyExport(graph);
-
- DataContainers.writeFile(output, new DataContainer(
- container.format, container.version,
- container.metadata, new Variant(TransferableGraph1.BINDING, graph)));
-
- }
-
-
-}
+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;
+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;
+
+/**
+ * @author Antti Villberg
+ * @since 1.24.0
+ */
+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);
+ GraphRefactoringUtils.fixOntologyExport(graph);
+
+ 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 createTGAndPGraph(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 == 0) {
+ System.out.println("Required arguments: [