X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FPlatformUtil.java;h=ebd987e3f2b5238e38ba4ace5ce1944a9eea6e55;hp=7655f9ca5af13e08637c1357f78ca88368d2212d;hb=3d96e3fa94898d90d6892c081ebed7cb9e773a4a;hpb=9c1b0bdc646d2e91526e49fd9233c2eb0c243019 diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java b/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java index 7655f9ca5..ebd987e3f 100644 --- a/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java +++ b/bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java @@ -25,11 +25,16 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; import java.util.Map.Entry; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.jar.Attributes; import java.util.jar.Manifest; +import java.util.stream.Collectors; import org.eclipse.core.internal.runtime.PlatformActivator; import org.eclipse.core.runtime.FileLocator; @@ -38,12 +43,10 @@ import org.eclipse.equinox.p2.metadata.IVersionedId; import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.equinox.p2.metadata.VersionedId; import org.osgi.framework.Bundle; -import org.simantics.databoard.adapter.AdaptException; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.mutable.Variant; import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; -import org.simantics.databoard.serialization.SerializationException; import org.simantics.graph.compiler.CompilationResult; import org.simantics.graph.compiler.GraphCompiler; import org.simantics.graph.compiler.GraphCompilerPreferences; @@ -310,12 +313,30 @@ public class PlatformUtil { * @param collection * @throws IOException */ - public static void getAllGraphs(Collection collection) throws IOException { - for (Bundle bundle : getBundles()) { - GraphBundle entry = getGraph(bundle); - if (entry!=null) collection.add(entry); - } - } + public static Collection getAllGraphs() throws IOException { + CompletableFuture f = new CompletableFuture<>(); + Bundle[] bundles = getBundles(); + Collection gbundles = Arrays.stream(bundles).map(t -> { // this could be done in parallel in the future? + if (f.isCompletedExceptionally()) + return null; + try { + return PlatformUtil.getGraph(t); + } catch (IOException e) { + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Could not get graph {}", t, e); + f.completeExceptionally(e); + return null; + } + }).filter(Objects::nonNull).collect(Collectors.toList()); + if (f.isCompletedExceptionally()) { + try { + f.get(); + } catch (ExecutionException | InterruptedException e) { + throw (IOException) e.getCause(); + } + } + return gbundles; + } /** * Get bundle