]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java
Fix graph.tg hardcoded in CompilePGraphs code
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / CompilePGraphs.java
index 7781fbeffdbe9d90cafd4b8e01346f27984c1f31..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;
@@ -51,6 +49,8 @@ import org.simantics.graph.compiler.ExternalFileLoader;
 import org.simantics.graph.compiler.GraphCompiler;
 import org.simantics.graph.compiler.GraphCompilerPreferences;
 import org.simantics.graph.compiler.ValidationMode;
+import org.simantics.graph.compiler.internal.ltk.ISource;
+import org.simantics.graph.compiler.internal.ltk.Problem;
 import org.simantics.graph.db.TransferableGraphException;
 import org.simantics.graph.db.TransferableGraphSource;
 import org.simantics.graph.db.TransferableGraphs;
@@ -59,11 +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.ltk.ISource;
-import org.simantics.ltk.Problem;
 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;
@@ -130,7 +133,7 @@ public class CompilePGraphs {
 
                 String uri = graph.getURI(r);
                 SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                ch.copyToClipboard(graph, clipboard);
+                ch.copyToClipboard(graph, clipboard, monitor);
                 for (Set<Representation> object : clipboard.getContents()) {
                     TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
                     if (tg != null)
@@ -141,30 +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;
-                       if (name.contains("ModelBroker"))
-                           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 {