X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fa2%2FAbstractProvisioningSource.java;h=7df851b2452c0d788c5618a9372238459d712021;hb=c66685995c1bf2c59bdf6d68753470c85828310a;hp=0c3cefd014a915f7a02d0c5b8caf69c858a0b6e1;hpb=0a0a90e832a2fe24dc55d1cf67d75e276ad61b2c;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java b/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java index 0c3cefd01..7df851b24 100644 --- a/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java +++ b/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java @@ -28,6 +28,12 @@ import org.osgi.framework.Version; public abstract class AbstractProvisioningSource implements ProvisioningSource { protected final Map contributions = Collections.synchronizedSortedMap(new TreeMap<>()); + private final boolean useReference; + + public AbstractProvisioningSource(boolean useReference) { + this.useReference = useReference; + } + public Iterable listContributions(Object filter) { return contributions.values(); } @@ -35,16 +41,25 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource { @Override public Bundle install(BundleContext bc, A2Module module) { try { - Path tempJar = null; - if (module.getLocator() instanceof Path && Files.isDirectory((Path) module.getLocator())) - tempJar = toTempJar((Path) module.getLocator()); - Bundle bundle; - try (InputStream in = newInputStream(tempJar != null ? tempJar : module.getLocator())) { - bundle = bc.installBundle(module.getBranch().getCoordinates(), in); + Object locator = module.getLocator(); + if (useReference && locator instanceof Path locatorPath) { + String referenceUrl = "reference:file:" + locatorPath.toString(); + Bundle bundle = bc.installBundle(referenceUrl); + return bundle; + } else { + + Path tempJar = null; + if (locator instanceof Path && Files.isDirectory((Path) locator)) + tempJar = toTempJar((Path) locator); + Bundle bundle; + try (InputStream in = newInputStream(tempJar != null ? tempJar : locator)) { + bundle = bc.installBundle(module.getBranch().getCoordinates(), in); + } + + if (tempJar != null) + Files.deleteIfExists(tempJar); + return bundle; } - if (tempJar != null) - Files.deleteIfExists(tempJar); - return bundle; } catch (BundleException | IOException e) { throw new A2Exception("Cannot install module " + module, e); } @@ -53,14 +68,21 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource { @Override public void update(Bundle bundle, A2Module module) { try { - Path tempJar = null; - if (module.getLocator() instanceof Path && Files.isDirectory((Path) module.getLocator())) - tempJar = toTempJar((Path) module.getLocator()); - try (InputStream in = newInputStream(tempJar != null ? tempJar : module.getLocator())) { - bundle.update(in); + Object locator = module.getLocator(); + if (useReference && locator instanceof Path) { + try (InputStream in = newInputStream(locator)) { + bundle.update(in); + } + } else { + Path tempJar = null; + if (locator instanceof Path && Files.isDirectory((Path) locator)) + tempJar = toTempJar((Path) locator); + try (InputStream in = newInputStream(tempJar != null ? tempJar : locator)) { + bundle.update(in); + } + if (tempJar != null) + Files.deleteIfExists(tempJar); } - if (tempJar != null) - Files.deleteIfExists(tempJar); } catch (BundleException | IOException e) { throw new A2Exception("Cannot update module " + module, e); }