From 4a602ca08c235735407b99b880fe9bebccacfee7 Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 5 Sep 2012 05:10:25 +0000 Subject: [PATCH] Refactoring tool for updating version numbers in old exported .tg:s for 1.7 release. (refs #3684) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25643 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/refactoring/TGRefactoring.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 org.simantics.sysdyn/src/org/simantics/sysdyn/refactoring/TGRefactoring.java diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/refactoring/TGRefactoring.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/refactoring/TGRefactoring.java new file mode 100644 index 00000000..9cbf68ae --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/refactoring/TGRefactoring.java @@ -0,0 +1,80 @@ +package org.simantics.sysdyn.refactoring; + +import java.io.File; +import java.net.URLDecoder; +import java.util.HashMap; + +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.databoard.container.DataContainer; +import org.simantics.databoard.container.DataContainers; +import org.simantics.graph.representation.External; +import org.simantics.graph.representation.Identity; +import org.simantics.graph.representation.TransferableGraph1; + +public class TGRefactoring { + + public static void main(String[] args) throws Exception { + // Select the directory where this file is + File dir = new File(URLDecoder.decode(TGRefactoring.class.getResource(".").getPath(), "UTF-8")).getAbsoluteFile(); + System.out.println(dir); + + // Choose input and output files for refactoring. Files are relative to the selected directory. + File input = new File(dir, "input.tg"); // use your own file names + File output = new File(dir, "output.tg"); + + // Get a map containing the changed names + HashMap map = getMap(); + + // Read input file + DataContainer dc = DataContainers.readFile(input); + + // Get transferable graph from the input file + TransferableGraph1 tg1 = (TransferableGraph1) dc.content.getValue(TransferableGraph1.BINDING); + + + // Loop through input file and change all names found from the map + for(Identity i : tg1.identities) { + if(i.definition instanceof External) { + External e = (External)i.definition; + String newName = map.get(e.name); + if(newName != null) { + System.out.println(e.name + " -> " + newName); + e.name = newName; + } + } + } + + // Rewrite DataContainer content + dc.content = new Variant(TransferableGraph1.BINDING, tg1); + + // Write the refactored graph to output file + DataContainers.writeFile(output, dc); + } + + private static HashMap getMap() { + HashMap map = new HashMap(); + + // 4.9.2012 ontology changes + map.put("Layer0-1.0", "Layer0-1.1"); + map.put("Layer0X-1.0", "Layer0X-1.1"); + map.put("G2D-1.0", "G2D-1.1"); + map.put("Structural-1.0", "Structural-1.2"); + map.put("Diagram-2.1", "Diagram-2.2"); + map.put("Simulation-1.0", "Simulation-1.1"); + map.put("Modeling-1.1", "Modeling-1.2"); + map.put("Project-1.1", "Project-1.2"); + map.put("Spreadsheet-1.1", "Spreadsheet-1.2"); + map.put("Viewpoint-1.1", "Viewpoint-1.2"); + map.put("Image2-1.1", "Image2-1.2"); + map.put("Color-1.0", "Color-1.1"); + map.put("Action-1.0", "Action-1.1"); + map.put("Silk-1.0", "Silk-1.1"); + map.put("Issue-1.1", "Issue-1.2"); + map.put("User-1.0", "User-1.1"); + map.put("Documentation-1.0", "Documentation-1.1"); + map.put("Document-1.1", "Document-1.2"); + map.put("SelectionView-1.1", "SelectionView-1.2"); + + return map; + } +} -- 2.47.1