From 4973ff616bd3b866f0cf0936576c24cb9e1a21a0 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Mon, 13 Mar 2017 11:30:06 +0200 Subject: [PATCH] Support L0.loadString in CompilePGraphs refs #7085 Change-Id: Ia386a6b0f654ca26708dec5b2b5b19f4a975cec3 --- .../META-INF/MANIFEST.MF | 3 +- .../modeling/ui/actions/CompilePGraphs.java | 31 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF index a84c13f5f..525c8da52 100644 --- a/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF @@ -62,7 +62,8 @@ Require-Bundle: org.simantics.project;bundle-version="1.0.0", org.simantics.silk.ontology;bundle-version="1.1.0", org.simantics.image.ui;bundle-version="1.0.0", org.simantics.export.core;bundle-version="1.0.0", - org.slf4j.api + org.slf4j.api, + org.simantics.graphfile.ontology Export-Package: org.simantics.modeling.ui, org.simantics.modeling.ui.actions, org.simantics.modeling.ui.chart.property, diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java index c13f3cb43..4272b9de7 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java @@ -35,6 +35,7 @@ import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.IndexRoot; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.UniqueRead; @@ -58,6 +59,7 @@ import org.simantics.db.layer0.util.SimanticsKeys; import org.simantics.db.layer0.util.TransferableGraphConfiguration2; import org.simantics.db.service.SerialisationSupport; import org.simantics.graph.compiler.CompilationResult; +import org.simantics.graph.compiler.ExternalFileLoader; import org.simantics.graph.compiler.GraphCompiler; import org.simantics.graph.compiler.GraphCompilerPreferences; import org.simantics.graph.compiler.ValidationMode; @@ -68,6 +70,7 @@ 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.graphfile.ontology.GraphFileResource; import org.simantics.layer0.Layer0; import org.simantics.ltk.ISource; import org.simantics.ltk.Problem; @@ -270,7 +273,33 @@ public class CompilePGraphs implements ActionFactory { prefs.validate = true; prefs.validateRelationRestrictions = ValidationMode.ERROR; prefs.validateResourceHasType = ValidationMode.IGNORE; - final CompilationResult result = GraphCompiler.compile("1.1", sources, dependencies, null, prefs); + + final CompilationResult result = Simantics.sync(new UniqueRead() { + + @Override + public CompilationResult perform(ReadGraph graph) throws DatabaseException { + + final Resource root = graph.syncRequest(new IndexRoot(r)); + final String baseURI = graph.getURI(root); + + ExternalFileLoader fileLoader = new ExternalFileLoader() { + @Override + public byte[] load(String fileName) throws IOException { + try { + GraphFileResource GF = GraphFileResource.getInstance(graph); + Resource file = graph.getResource(baseURI + "/" + fileName); + return graph.getRelatedValue(file, GF.HasFiledata, Bindings.BYTE_ARRAY); + } catch (DatabaseException e) { + throw new IOException(e); + } + } + }; + + return GraphCompiler.compile("1.1", sources, dependencies, fileLoader, prefs); + + } + + }); for(Problem problem : result.getErrors()) errorStringBuilder.append(problem.getLocation() + ": " + problem.getDescription() + "\n"); -- 2.43.2