X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2Fa2%2FProvisioningSource.java;h=62d7042d69588588d7fb6ce0dd4b1cff33e119cc;hb=c155192cfcd5ca355eb933fa3f55dbad6d01b958;hp=cb122e434441dde4a82dde1e9fbadb5c9c1930b2;hpb=088c1b517a543e935d8ab65c3b2fd2d0269b551d;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/a2/ProvisioningSource.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/a2/ProvisioningSource.java index cb122e434..62d7042d6 100644 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/a2/ProvisioningSource.java +++ b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/a2/ProvisioningSource.java @@ -1,106 +1,21 @@ package org.argeo.osgi.boot.a2; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.jar.JarInputStream; -import java.util.jar.Manifest; - -import org.argeo.osgi.boot.OsgiBootException; -import org.osgi.framework.Constants; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; import org.osgi.framework.Version; -abstract class ProvisioningSource { - final Map contributions = Collections.synchronizedSortedMap(new TreeMap<>()); - - A2Contribution getOrAddContribution(String contributionId) { - if (contributions.containsKey(contributionId)) - return contributions.get(contributionId); - else - return new A2Contribution(this, contributionId); - } - - void asTree(String prefix, StringBuffer buf) { - if (prefix == null) - prefix = ""; - for (String contributionId : contributions.keySet()) { - buf.append(prefix); - buf.append(contributionId); - buf.append('\n'); - A2Contribution contribution = contributions.get(contributionId); - contribution.asTree(prefix + " ", buf); - } - } - - void asTree() { - StringBuffer buf = new StringBuffer(); - asTree("", buf); - System.out.println(buf); - } - - A2Component findComponent(String componentId) { - SortedMap res = new TreeMap<>(); - for (A2Contribution contribution : contributions.values()) { - components: for (String componentIdKey : contribution.components.keySet()) { - if (componentId.equals(componentIdKey)) { - res.put(contribution, contribution.components.get(componentIdKey)); - break components; - } - } - } - if (res.size() == 0) - return null; - // TODO explicit contribution priorities - return res.get(res.lastKey()); - - } +/** Where components are retrieved from. */ +public interface ProvisioningSource { + /** List all contributions of this source. */ + Iterable listContributions(Object filter); - A2Branch findBranch(String componentId, Version version) { - A2Component component = findComponent(componentId); - if (component == null) - return null; - String branchId = version.getMajor() + "." + version.getMinor(); - if (!component.branches.containsKey(branchId)) - return null; - return component.branches.get(branchId); - } + /** Install a module in the OSGi runtime. */ + Bundle install(BundleContext bc, A2Module module); - protected String readVersionFromModule(Path modulePath) { - try (JarInputStream in = new JarInputStream(newInputStream(modulePath))) { - Manifest manifest = in.getManifest(); - String versionStr = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION); - return versionStr; - } catch (IOException e) { - throw new OsgiBootException("Cannot read manifest from " + modulePath, e); - } - } + /** Update a module in the OSGi runtime. */ + void update(Bundle bundle, A2Module module); - protected String readSymbolicNameFromModule(Path modulePath) { - try (JarInputStream in = new JarInputStream(newInputStream(modulePath))) { - Manifest manifest = in.getManifest(); - String symbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); - int semiColIndex = symbolicName.indexOf(';'); - if (semiColIndex >= 0) - symbolicName = symbolicName.substring(0, semiColIndex); - return symbolicName; - } catch (IOException e) { - throw new OsgiBootException("Cannot read manifest from " + modulePath, e); - } - } + /** Finds the {@link A2Branch} related to this component and version. */ + A2Branch findBranch(String componentId, Version version); - InputStream newInputStream(Object locator) throws IOException { - if (locator instanceof Path) { - return Files.newInputStream((Path) locator); - } else if (locator instanceof URL) { - return ((URL) locator).openStream(); - } else { - throw new IllegalArgumentException("Unsupported module locator type " + locator.getClass()); - } - } }