X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frefactoring%2FFixExportedOntology.java;h=33291cdf108e75cef32b35e64e69b19d8583c589;hp=27c4b9195522d82291c6374586c0db985d1bfe4b;hb=fac3394a0015e8f1b642bb59f97c814ea5d7ff1f;hpb=cdfd997cc5118a9fb08a73f35c6f7306308abd86 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 27c4b9195..33291cdf1 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 @@ -13,15 +13,19 @@ 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 { - + + private static final Logger LOGGER = LoggerFactory.getLogger(FixExportedOntology.class); + 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()); + 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)) { Binding tgBinding = TransferableGraph1.BINDING; DataContainer container = DataContainers.readFile(new DataInputStream(is), tgBinding); @@ -34,26 +38,33 @@ public class FixExportedOntology { return graph; } } - - public static void createTg(Path input) throws Exception { - Path output = input.getParent().resolve("graph.tg"); - createTg(input, output); + + private static Path replaceExtension(Path p, String newExtension) { + String newName = p.getFileName().toString(); + int lastDot = newName.lastIndexOf('.'); + if (lastDot > -1) + newName = newName.substring(0, lastDot); + return p.resolveSibling(newName + newExtension); } - + private static void createTg(Path input, Path output) throws Exception { - convertExportedSharedOntologyIntoBundleOntology(input, output); + convertExportedSharedOntologyIntoBundleOntology(input, output); + } + + public static void createTg(Path input) throws Exception { + createTg(input, replaceExtension(input, ".tg")); } - + public static void createTGAndPGraph(Path input) throws Exception { - String newName = input.getFileName().toString(); - if (newName.contains(".")) - newName = newName.split("\\.")[0]; - 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); + createTGAndPGraph(input, true); + } + + 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 {