]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix graph.tg hardcoded in CompilePGraphs code 02/3602/2
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Fri, 22 Nov 2019 11:03:07 +0000 (13:03 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 29 Nov 2019 19:46:35 +0000 (19:46 +0000)
Ontology cannot be compiled if it depends on a tg that has another name
than graph.tg. Fixed this by searching for all .tg files instead of
those called graph.tg.

gitlab #422

Change-Id: I52fb91f31b0ae052097fdedd36efa56e314adec5

bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java
bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java

index b0690532b85d584969526609181ba6fc712b5ba5..f2321dce9515b2819af7c51ddc146f324c5b4b1a 100644 (file)
@@ -78,7 +78,51 @@ public class TransferableGraphUtils {
         return identity;
         
     }
-    
+
+    /**
+     * Provided a tg and a resource uri, returns the identity of the tg if the uri_ matches the tg exactly
+     * @param tg
+     * @param uri_
+     * @return
+     */
+    public static Identity getIdentity2(TransferableGraph1 tg, String uri_) {
+        Collection<Identity> identities = TransferableGraphUtils.getRoots(tg);
+        for (Identity i : identities) {
+            Identity id = getIdentity2(tg, uri_, i);
+            if (id != null) {
+                return id;
+            }
+        }
+        return null;
+    }
+
+    /**
+     *
+     * @param tg
+     * @param uri_
+     * @param id
+     * @return
+     */
+    public static Identity getIdentity2(TransferableGraph1 tg, String uri_, Identity id) {
+        String uri = TransferableGraphUtils.getURI(tg, id.resource);
+
+        if (uri_.equals(uri)) {
+            return id;
+        }
+
+        if (uri_.startsWith(uri)) {
+            Collection<Identity> childIdentitiesOfRoot = TransferableGraphUtils.getChildren2(tg, id);
+            for (Identity i2 : childIdentitiesOfRoot) {
+                Identity id2 = getIdentity2(tg, uri_, i2);
+                if (id2 != null) {
+                    return id2;
+                }
+            }
+        }
+
+        return null;
+    }
+
     public static Identity getIdentity(TransferableGraph1 tg, int resource) {
         for(Identity id : tg.identities) {
             if(id.resource == resource) return id;
index be5f9abaee7c87b6f0b6ac5ee0cf401128f37a79..3a12a71320a56c367d67d4819146550acbc1ce70 100644 (file)
@@ -15,10 +15,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.osgi.framework.Bundle;
 import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
@@ -61,9 +59,14 @@ import org.simantics.graph.diff.TransferableGraphDelta1;
 import org.simantics.graph.representation.Identity;
 import org.simantics.graph.representation.Root;
 import org.simantics.graph.representation.TransferableGraph1;
+import org.simantics.graph.representation.TransferableGraphUtils;
 import org.simantics.graphfile.ontology.GraphFileResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.internal.Activator;
+import org.simantics.project.management.GraphBundle;
+import org.simantics.project.management.GraphBundleEx;
+import org.simantics.project.management.GraphBundleRef;
+import org.simantics.project.management.PlatformUtil;
 import org.simantics.utils.FileUtils;
 import org.simantics.utils.datastructures.Pair;
 import org.slf4j.LoggerFactory;
@@ -141,28 +144,21 @@ public class CompilePGraphs {
             }
         });
 
-        if (thisOntology == null)      
+        if (thisOntology == null)
             throw new DatabaseException("Failed to dump the containing ontology of " + r + " into TransferableGraph1");
 
         dependencies.add(thisOntology.second);
-        
-        for (Bundle b : Activator.getContext().getBundles()) {
-                       String id = b.getSymbolicName();
-                       String name = (String) b.getHeaders().get("Bundle-Name");
-                       if (name == null) name = id;
-                       if (name.equals(thisOntology.first))
-                               continue;
-            URL tg = b.getEntry("/graph.tg");
-            if (tg == null) continue;
-            File f = url2file(FileLocator.resolve(tg), b.getSymbolicName());
-            try {
-                dependencies.add(GraphCompiler.read(f));
-            } catch (Exception e) {
-                throw new IOException("Failed to read compiled transferable graph as dependency: " + f, e);
+
+        Collection<GraphBundle> tgs = PlatformUtil.getAllGraphs();
+
+        for (GraphBundle b : tgs) {
+            TransferableGraph1 tg = b.getGraph();
+            Identity id = TransferableGraphUtils.getIdentity2(tg, thisOntology.first);
+            if(id == null) {
+                dependencies.add(tg);
             }
         }
 
-
         Simantics.sync(new ReadRequest() {
             @Override
             public void run(ReadGraph graph) throws DatabaseException {