From: Tuukka Lehtonen Date: Sun, 23 Oct 2016 20:38:15 +0000 (+0300) Subject: Sync git svn branch with SVN repository r33358. X-Git-Tag: v1.25.0~65^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=2a46c55805427cfb40ed0db7e33208bb5ffb3d7a;p=simantics%2Fplatform.git Sync git svn branch with SVN repository r33358. refs #6502 --- 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..09931e604 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 @@ -3,9 +3,10 @@ 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 java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.mutable.Variant; @@ -13,29 +14,38 @@ import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; import org.simantics.graph.representation.TransferableGraph1; +/** + * @author Antti Villberg + * @since 1.24.0 + */ 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); + 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()); + 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); - 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.toFile(), new DataContainer( + container.format, container.version, + container.metadata, new Variant(TransferableGraph1.BINDING, graph))); + } + } - DataContainers.writeFile(output, new DataContainer( - container.format, container.version, - container.metadata, new Variant(TransferableGraph1.BINDING, graph))); - + public static void main(String[] args) throws Exception { + if (args.length < 1) { + System.out.println("Required arguments: []"); + } else if (args.length < 2) { + Path input = Paths.get(args[0]); + Path output = input.getParent().resolve(input.getName(input.getNameCount()-1) + ".fixed"); + convertExportedSharedOntologyIntoBundleOntology(input, output); + } else { + convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1])); + } } - }