X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FCompilePGraphs.java;h=3a12a71320a56c367d67d4819146550acbc1ce70;hb=b055bfb36cca301ceed0591028d245e152c8c32d;hp=9b620c2f7c55e39e0d789b6d926759b8939d475a;hpb=6060da2a6dafae679ef44bf44adfbb5ecfc091bd;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java index 9b620c2f7..3a12a7132 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java @@ -15,8 +15,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.eclipse.core.runtime.FileLocator; -import org.osgi.framework.Bundle; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; @@ -49,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; @@ -57,19 +59,25 @@ 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; /** * @author Antti Villberg */ public class CompilePGraphs { + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CompilePGraphs.class); + public static interface UserAgent { void reportProblems(CompilationResult result); } @@ -86,24 +94,17 @@ public class CompilePGraphs { } public static void compilePGraphs(Resource r, UserAgent userAgent) throws IOException, DatabaseException { + compilePGraphs(r, userAgent, new NullProgressMonitor()); + } + + public static void compilePGraphs(Resource r, UserAgent userAgent, IProgressMonitor monitor) throws IOException, DatabaseException { final Collection sources = new ArrayList<>(); Collection dependencies = new ArrayList<>(); - for (Bundle b : Activator.getContext().getBundles()) { - 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); - } - } - - final TransferableGraph1 thisOntology = Simantics.sync(new UniqueRead() { + final Pair thisOntology = Simantics.sync(new UniqueRead>() { @Override - public TransferableGraph1 perform(ReadGraph graph) throws DatabaseException { + public Pair perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); Resource parent = graph.getSingleObject(r, L0.PartOf); @@ -130,22 +131,33 @@ public class CompilePGraphs { } }; + String uri = graph.getURI(r); SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl(); - ch.copyToClipboard(graph, clipboard); + ch.copyToClipboard(graph, clipboard, monitor); for (Set object : clipboard.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); if (tg != null) - return tg; + return Pair.make(uri, tg); } return null; } }); - if (thisOntology == null) + if (thisOntology == null) throw new DatabaseException("Failed to dump the containing ontology of " + r + " into TransferableGraph1"); - dependencies.add(thisOntology); + dependencies.add(thisOntology.second); + + Collection 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 @@ -242,6 +254,9 @@ public class CompilePGraphs { } }); } + + // Delete index to get rid of floating old instances of the same ontology +// DatabaseIndexing.deleteAllIndexes(); } private static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException { @@ -271,7 +286,7 @@ public class CompilePGraphs { Logger.defaultLogError(e); } } else { - System.err.println("Unsupported URL protocol '" + url + "' for FastLZ native library file '" + fileName); + LOGGER.warn("Unsupported URL protocol"); } return null; }