]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/utils/DumpOntologyStructure.java
Improved shared library structure dump to take more types into account
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / utils / DumpOntologyStructure.java
index 79622f15e5839bf1cae00c32dc228e75967eb427..5bb3d9ca21c95d30bb5d96200d41caade8bf59df 100644 (file)
@@ -30,7 +30,7 @@ public class DumpOntologyStructure {
     private static final Logger LOGGER = LoggerFactory.getLogger(DumpOntologyStructure.class);
 
     private Resource ontology;
-    
+
     private Map<Resource, String> names = new HashMap<>();
     private Map<Resource,Resource> parents = new HashMap<>();
     private Map<Resource, File> libraryFolders = new HashMap<>();
@@ -40,11 +40,11 @@ public class DumpOntologyStructure {
         parents.put(r, container);
         names.put(r, NameUtils.getSafeName(graph, r));
     }
-    
+
     private Collection<Resource> containers() {
         return parents.values();
     }
-    
+
     private void readHierarchy(ReadGraph graph, Resource container) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(graph);
         for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, L0.Entity)) {
@@ -94,30 +94,27 @@ public class DumpOntologyStructure {
         }
     }
 
-    public void read(ReadGraph graph, Resource ontology) throws DatabaseException {
+    public DumpOntologyStructure read(ReadGraph graph, Resource ontology) throws DatabaseException {
         this.ontology = ontology;
         readHierarchy(graph, ontology);
         readGeneric(graph);
+        return this;
     }
-    
-    private File escapeFile(File file) {
 
+    private File escapeFile(File file) {
         if(file.exists())
             return file;
-        
         return new File(escapeFile(file.getParentFile()), FileUtils.escapeFileName(file.getName()));
-        
     }
-    
+
     public void write(File unsafeFolder) throws IOException {
         File folder = escapeFile(unsafeFolder);
-        if(folder.exists())
-            FileUtils.deleteAll(folder);
+        FileUtils.delete(folder.toPath());
         folder.mkdirs();
         writeDirectories(folder);
         writeResources(folder);
     }
-    
+
     private File getFolder(File root, Resource library) {
         if(ontology.equals(library))
             return root;
@@ -147,11 +144,11 @@ public class DumpOntologyStructure {
             writeResource(rootFolder, r);
         }
     }
-    
+
     private boolean isParent(Resource r) {
         return parents.values().contains(r);
     }
-    
+
     private void writeResource(File rootFolder, Resource resource) throws IOException {
         byte[] dump = contentDumps.get(resource);
         if(dump == null)
@@ -168,4 +165,4 @@ public class DumpOntologyStructure {
         FileUtils.writeFile(getFile(rootFolder, resource), bytes);
     }
 
-}
+}
\ No newline at end of file