X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.osgi%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fosgi%2Fbuild%2FBundleModularDistribution.java;h=ac6eaa75e89b41bcd8047382598d628de143d2fd;hb=5a7871454f57064cf5fb2be810dc1f26f744629e;hp=79bc3e6a87929a68f9feef2ebc8672ab5a453463;hpb=b98bef7b2e743103c93e719ac5c18bf41858ec3a;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/BundleModularDistribution.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/BundleModularDistribution.java index 79bc3e6a8..ac6eaa75e 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/BundleModularDistribution.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/BundleModularDistribution.java @@ -1,92 +1,33 @@ package org.argeo.slc.osgi.build; import java.net.URL; -import java.util.ArrayList; import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import java.util.SortedMap; import java.util.StringTokenizer; -import java.util.TreeMap; import java.util.jar.JarInputStream; import java.util.jar.Manifest; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.SlcException; -import org.argeo.slc.UnsupportedException; import org.argeo.slc.build.BasicNameVersion; import org.argeo.slc.build.Distribution; -import org.argeo.slc.build.ModularDistribution; import org.argeo.slc.build.NameVersion; import org.argeo.slc.core.build.VersionedResourceDistribution; -import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; -import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; -import org.springframework.osgi.context.BundleContextAware; -public class BundleModularDistribution implements ModularDistribution, - BundleContextAware, InitializingBean, ResourceLoaderAware { - private final static Log log = LogFactory - .getLog(BundleModularDistribution.class); - - private BundleContext bundleContext; +public class BundleModularDistribution extends AbstractOsgiModularDistribution + implements ResourceLoaderAware { private ResourceLoader resourceLoader; private String libDirectory = "/lib"; - private EclipseUpdateSite eclipseUpdateSite; - - /** Initialized by the object itself. */ - private SortedMap distributions = new TreeMap(); - - public Distribution getModuleDistribution(String moduleName, - String moduleVersion) { - return distributions - .get(new BasicNameVersion(moduleName, moduleVersion)); - // URL url = findModule(moduleName, moduleVersion); - // return new ResourceDistribution(new UrlResource(url)); - } @SuppressWarnings(value = { "unchecked" }) - protected URL findModule(String moduleName, String version) { - Enumeration urls = (Enumeration) bundleContext.getBundle() - .findEntries(libDirectory, moduleName + "*", false); - - if (!urls.hasMoreElements()) - throw new SlcException("Cannot find module " + moduleName); - - URL url = urls.nextElement(); - - // TODO: check version as well - if (urls.hasMoreElements()) - throw new SlcException("More than one module with name " - + moduleName); - return url; - } - - public String getDistributionId() { - return bundleContext.getBundle().getSymbolicName() - + "-" - + bundleContext.getBundle().getHeaders().get( - Constants.BUNDLE_VERSION); - } - - public Set listModulesNameVersions() { - return distributions.keySet(); - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - @SuppressWarnings(value = { "unchecked" }) - public void afterPropertiesSet() throws Exception { - Enumeration urls = (Enumeration) bundleContext.getBundle() - .findEntries(libDirectory, "*.jar", false); + protected void fillDistributions( + SortedMap distributions) + throws Exception { + Enumeration urls = (Enumeration) getBundleContext() + .getBundle().findEntries(libDirectory, "*.jar", false); while (urls.hasMoreElements()) { URL url = urls.nextElement(); JarInputStream in = null; @@ -112,105 +53,30 @@ public class BundleModularDistribution implements ModularDistribution, IOUtils.closeQuietly(in); } } - if (log.isDebugEnabled()) - log.debug("Distribution " + getName() + ":" + getVersion() - + " loaded (" + distributions.size() + " modules)"); - - } - - protected String findVersion(String name) { - Set versions = new HashSet(); - for (NameVersion key : distributions.keySet()) { - if (key.getName().equals(name)) - versions.add(key.getVersion()); - } - - if (versions.size() == 0) - throw new SlcException("Cannot find version for name " + name); - else if (versions.size() > 1) - throw new SlcException("Found more than one version for name " - + name + ": " + versions); - else - return versions.iterator().next(); - } public void setLibDirectory(String libDirectory) { this.libDirectory = libDirectory; } - public Object getDescriptor(String descriptorType) { - if (descriptorType.equals("eclipse")) - return writeEclipseUpdateSite(); - else - throw new UnsupportedException("descriptorType", descriptorType); - } - - protected Set writePlainUrlList() { - return distributions.keySet(); - } - - protected String writeEclipseUpdateSite() { - if (eclipseUpdateSite == null) - throw new SlcException("No eclipse update site declared."); - - StringBuffer buf = new StringBuffer(""); - buf.append(""); - - List usedCategories = new ArrayList(); - for (EclipseUpdateSiteFeature feature : eclipseUpdateSite.getFeatures()) { - - String featureId = feature.getName(); - String featureVersion = findVersion(featureId); - buf.append("\n"); - - for (EclipseUpdateSiteCategory category : feature.getCategories()) { - usedCategories.add(category); - buf.append(" \n"); - } - buf.append("\n\n"); - } - - for (EclipseUpdateSiteCategory category : usedCategories) { - buf.append("\n"); - buf.append(" ").append(category.getDescription()) - .append("\n"); - buf.append("\n\n"); - } - - buf.append(""); - return buf.toString(); - } - public void setResourceLoader(ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } - public String getName() { - return bundleContext.getBundle().getSymbolicName(); - } - - public String getVersion() { - return bundleContext.getBundle().getHeaders().get( - Constants.BUNDLE_VERSION).toString(); - } - - @Override - public String toString() { - return new BasicNameVersion(this).toString(); - } - - public void setEclipseUpdateSite(EclipseUpdateSite eclipseUpdateSite) { - this.eclipseUpdateSite = eclipseUpdateSite; - } + /* + * @SuppressWarnings(value = { "unchecked" }) protected URL + * findModule(String moduleName, String version) { Enumeration urls = + * (Enumeration) bundleContext.getBundle() .findEntries(libDirectory, + * moduleName + "*", false); + * + * if (!urls.hasMoreElements()) throw new SlcException("Cannot find module " + * + moduleName); + * + * URL url = urls.nextElement(); + * + * // TODO: check version as well if (urls.hasMoreElements()) throw new + * SlcException("More than one module with name " + moduleName); return url; + * } + */ }