X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FOsgiBoot.java;h=f5b260caba404735f9f296830bab0e6e29c369bf;hb=1a65fa72abac6a458139240efa281138aac9ef2b;hp=c26fad66817c3b654f1ea0e965d9025e556f0c2d;hpb=af52952e94d59bba22d0ac861e7777b60cf06c78;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java index c26fad668..f5b260cab 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java @@ -19,9 +19,6 @@ import java.util.Set; import java.util.SortedMap; import java.util.StringTokenizer; import java.util.TreeMap; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ForkJoinPool; import org.argeo.init.a2.A2Source; import org.argeo.init.a2.ProvisioningManager; @@ -101,19 +98,25 @@ public class OsgiBoot implements OsgiBootConstants { queryPart = source.substring(qmIndex); source = source.substring(0, qmIndex); } + // TODO centralise in A" package? if (source.trim().equals(A2Source.DEFAULT_A2_URI)) { if (Files.exists(homePath)) provisioningManager.registerSource( A2Source.SCHEME_A2 + "://" + homePath.toString() + "/.local/share/a2" + queryPart); provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/local/share/a2" + queryPart); + provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/local/lib/a2" + queryPart); provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/share/a2" + queryPart); + provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/lib/a2" + queryPart); } else if (source.trim().equals(A2Source.DEFAULT_A2_REFERENCE_URI)) { if (Files.exists(homePath)) provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + "://" + homePath.toString() + "/.local/share/a2" + queryPart); provisioningManager .registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/local/share/a2" + queryPart); + provisioningManager + .registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/local/lib/a2" + queryPart); provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/share/a2" + queryPart); + provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/lib/a2" + queryPart); } else { provisioningManager.registerSource(source + queryPart); } @@ -378,7 +381,23 @@ public class OsgiBoot implements OsgiBootConstants { for (String bsn : startLevels.get(level)) bundleStartLevels.put(bsn, level); } - for (Bundle bundle : bundleContext.getBundles()) { + + // keep only bundles with the highest version + Map startableBundles = new HashMap<>(); + bundles: for (Bundle bundle : bundleContext.getBundles()) { + if (bundle.getVersion() == null) + continue bundles; + String bsn = bundle.getSymbolicName(); + if (!startableBundles.containsKey(bsn)) { + startableBundles.put(bsn, bundle); + } else { + if (bundle.getVersion().compareTo(startableBundles.get(bsn).getVersion()) > 0) { + startableBundles.put(bsn, bundle); + } + } + } + + for (Bundle bundle : startableBundles.values()) { String bsn = bundle.getSymbolicName(); if (bundleStartLevels.containsKey(bsn)) { BundleStartLevel bundleStartLevel = bundle.adapt(BundleStartLevel.class); @@ -391,7 +410,7 @@ public class OsgiBoot implements OsgiBootConstants { OsgiBootUtils.error("Cannot mark " + bsn + " as started", e); } if (OsgiBootUtils.isDebug()) - OsgiBootUtils.debug(bsn + " starts at level " + level); + OsgiBootUtils.debug(bsn + " v" + bundle.getVersion() + " starts at level " + level); } } } @@ -399,27 +418,36 @@ public class OsgiBoot implements OsgiBootConstants { if (OsgiBootUtils.isDebug()) OsgiBootUtils.debug("About to set framework start level to " + activeStartLevel + " ..."); - // Start the framework level after level - stages: for (int stage = initialStartLevel; stage <= activeStartLevel; stage++) { - OsgiBootUtils.info("Starting stage " + stage + "..."); - final int nextStage = stage; - final CompletableFuture stageCompleted = new CompletableFuture<>(); - ForkJoinPool.commonPool().execute(() -> { - frameworkStartLevel.setStartLevel(nextStage, (FrameworkEvent event) -> { - stageCompleted.complete(event); - }); - }); - FrameworkEvent event; - try { - event = stageCompleted.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException("Cannot continue start", e); - } - if (event.getThrowable() != null) { - OsgiBootUtils.error("Stage " + nextStage + " failed, aborting start.", event.getThrowable()); - break stages; + frameworkStartLevel.setStartLevel(activeStartLevel, (FrameworkEvent event) -> { + if (event.getType() == FrameworkEvent.ERROR) { + OsgiBootUtils.error("Start sequence failed", event.getThrowable()); + } else { + if (OsgiBootUtils.isDebug()) + OsgiBootUtils.debug("Framework started at level " + frameworkStartLevel.getStartLevel()); } - } + }); + +// // Start the framework level after level +// int currentStartLevel = frameworkStartLevel.getStartLevel(); +// stages: for (int stage = currentStartLevel + 1; stage <= activeStartLevel; stage++) { +// if (OsgiBootUtils.isDebug()) +// OsgiBootUtils.debug("Starting stage " + stage + "..."); +// final int nextStage = stage; +// final CompletableFuture stageCompleted = new CompletableFuture<>(); +// frameworkStartLevel.setStartLevel(nextStage, (FrameworkEvent event) -> { +// stageCompleted.complete(event); +// }); +// FrameworkEvent event; +// try { +// event = stageCompleted.get(); +// } catch (InterruptedException | ExecutionException e) { +// throw new IllegalStateException("Cannot continue start", e); +// } +// if (event.getThrowable() != null) { +// OsgiBootUtils.error("Stage " + nextStage + " failed, aborting start.", event.getThrowable()); +// break stages; +// } +// } } private static void computeStartLevels(SortedMap> startLevels, Map properties,