X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frefactoring%2FFixExportedOntology.java;h=17aa3ed26af30ab5143a2cacf7fb16b01d2a27d3;hb=d4a7620f4d36d1ab9f285497586e55725e48d219;hp=bf0224103228a0838952cf553b9fea9b54d14ed6;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;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 bf0224103..17aa3ed26 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,48 +1,77 @@
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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Antti Villberg
* @since 1.24.0
*/
public class FixExportedOntology {
-
- static void 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());
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(FixExportedOntology.class);
+
+ static TransferableGraph1 convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception {
+ LOGGER.info("Converting exported shared ontology\n\t{}\nto bundle-compatible ontology\n\t{}", input.toString(), 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(), container);
+ return graph;
+ }
+ }
+
+ private static Path replaceExtension(Path p, String newExtension) {
+ String newName = p.getFileName().toString();
+ if (newName.contains("."))
+ newName = newName.split("\\.")[0];
+ return p.resolveSibling(newName + newExtension);
+ }
+
+ private static void createTg(Path input, Path output) throws Exception {
+ convertExportedSharedOntologyIntoBundleOntology(input, output);
+ }
+
+ public static void createTg(Path input) throws Exception {
+ createTg(input, replaceExtension(input, ".tg"));
+ }
+
+ public static void createTGAndPGraph(Path input) throws Exception {
+ createTGAndPGraph(input, true);
+ }
- DataContainers.writeFile(output.toFile(), new DataContainer(
- container.format, container.version,
- container.metadata, new Variant(TransferableGraph1.BINDING, graph)));
+ public static void createTGAndPGraph(Path input, boolean writePGraph) throws Exception {
+ TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, replaceExtension(input, ".tg"));
+ if (writePGraph) {
+ String listing = PrettyPrintTG.print(tg, false);
+ Files.write(replaceExtension(input, ".pgraph"), listing.getBytes(),StandardOpenOption.CREATE);
}
}
public static void main(String[] args) throws Exception {
- if (args.length < 1) {
- System.out.println("Required arguments: [