<slc.osgi.bundles>
${user.home}/dev/src/sparta/dist/runtime/target;in=*.jar,
${basedir}/site;in=*;ex=pom.xml;ex=target,
- ${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*
+ ${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*,
+ ${basedir}/../modules/agent;in=*;ex=pom.xml;ex=target
</slc.osgi.bundles>
</systemProperties>
</configuration>
<packaging>jar</packaging>
<name>Argeo SLC Dependencies Server</name>
<dependencies>
+ <!-- Other deps -->
+ <dependency>
+ <groupId>org.argeo.slc.dep</groupId>
+ <artifactId>org.argeo.slc.dep.agent</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.slc.dep</groupId>
+ <artifactId>org.argeo.slc.dep.detached</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<!-- SLC -->
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
</resource>
</resources>
<plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>buildnumber-maven-plugin</artifactId>
+ <configuration>
+ <useLastCommittedRevision>false</useLastCommittedRevision>
+ </configuration>
+ </plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
- <manifestFile>META-INF/MANIFEST.MF</manifestFile>
+ <manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${version.maven-bundle-plugin}</version>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${project.version}-r${buildNumber}</Bundle-Version>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.argeo.maven.plugins</groupId>
+ <artifactId>maven-argeo-osgi-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>descriptors</goal>
+ </goals>
+ <phase>generate-resources</phase>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Bundle-Name: SLC Server Main\r
Require-Bundle: org.argeo.slc.specs,\r
org.argeo.slc.support.equinox\r
+Import-Package: org.argeo.slc.build,\r
+ org.argeo.slc.osgi.build\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+ <bean id="eclipseUpdateSite" class="org.argeo.slc.osgi.build.EclipseUpdateSite">
+ <property name="features">
+ <list>
+ <bean class="org.argeo.slc.osgi.build.EclipseUpdateSiteFeature">
+ <property name="name" value="org.argeo.slc.dep.agent" />
+ </bean>
+ <bean class="org.argeo.slc.osgi.build.EclipseUpdateSiteFeature">
+ <property name="name" value="org.argeo.slc.dep.detached" />
+ </bean>
+ </list>
+ </property>
+ </bean>
+</beans>
\ No newline at end of file
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dynamicRuntime" class="org.argeo.slc.equinox.EquinoxRuntime" />
+ <bean id="modularDistribution" class="org.argeo.slc.osgi.build.OsgiRuntimeModularDistribution">
+ <property name="eclipseUpdateSite" ref="eclipseUpdateSite" />
+ </bean>
</beans>
\ No newline at end of file
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<service ref="dynamicRuntime" interface="org.argeo.slc.deploy.DynamicRuntime" />
+ <service ref="modularDistribution" interface="org.argeo.slc.build.ModularDistribution" />
</beans:beans>
\ No newline at end of file
org.springframework.web.servlet,\r
org.springframework.web.servlet.handler,\r
org.springframework.web.servlet.mvc,\r
- org.springframework.security.context\r
+ org.springframework.security.context,\r
+ org.springframework.security.providers\r
<value>
/*/*/modules.html=availableModulesHtml
/*/*/modules=availableModulesPlain
- /*/*/osgiBoot=availableModulesOsgiBoot
+ /*/*/modularDistribution=availableModulesOsgiBoot
/*/*/site.xml=updateSiteHandler
</value>
</property>
<property name="dynamicRuntime" ref="dynamicRuntime" />
</bean>
+ <!-- Provisioning -->
+ <bean name="/listModularDistributions.service"
+ class="org.argeo.slc.web.mvc.provisioning.ListModularDistributions">
+ <property name="modularDistributions" ref="modularDistributions" />
+ </bean>
+
+
<!-- MVC -->
<bean id="handlerMapping"
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
super();
}
+ public VersionedResourceDistribution(NameVersion nameVersion,
+ Resource resource) {
+ this(nameVersion.getName(), nameVersion.getVersion(), resource);
+ }
+
public VersionedResourceDistribution(String name, String version,
Resource resource) {
super(resource);
--- /dev/null
+package org.argeo.slc.msg.build;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.argeo.slc.build.BasicNameVersion;
+
+public class ModularDistributionDescriptor extends BasicNameVersion implements
+ Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /** key is type, value the URL */
+ private Map<String, String> modulesDescriptors = new HashMap<String, String>();
+
+ public Map<String, String> getModulesDescriptors() {
+ return modulesDescriptors;
+ }
+
+ public void setModulesDescriptors(Map<String, String> urls) {
+ this.modulesDescriptors = urls;
+ }
+
+}
.booleanValue();
private boolean excludeSvn = true;
- private String modulesUrlSeparator = ";";
+ private String modulesUrlSeparator = ",";
private final BundleContext bundleContext;
import javax.servlet.http.HttpServletResponse;
import org.argeo.slc.build.ModularDistribution;
+import org.argeo.slc.build.NameVersion;
import org.springframework.web.HttpRequestHandler;
+import common.BaseUnit;
+
/** List of modules for a distribution. */
public abstract class AbstractAvailableModules implements HttpRequestHandler {
protected abstract void print(Writer out, String baseUrl,
.getAttribute("modularDistribution");
String baseUrl = "http://" + request.getServerName() + ":"
- + request.getServerPort() + request.getContextPath() + "/"
- + md.getName() + "/" + md.getVersion() + "/";
+ + request.getServerPort() + request.getContextPath()
+ + request.getServletPath() + "/" + md.getName() + "/"
+ + md.getVersion() + "/";
print(response.getWriter(), baseUrl, md);
}
return "text/plain";
}
+ protected String jarUrl(String baseUrl, NameVersion nameVersion) {
+ return baseUrl + jarFileName(nameVersion);
+ }
+
+ protected String jarFileName(NameVersion nameVersion) {
+ return nameVersion.getName() + "-" + nameVersion.getVersion() + ".jar";
+ }
+
}
import java.io.IOException;
import java.io.Writer;
+import org.argeo.slc.build.Distribution;
import org.argeo.slc.build.ModularDistribution;
import org.argeo.slc.build.NameVersion;
+import org.argeo.slc.core.build.ResourceDistribution;
/** List of modules for a distribution. */
public class AvailableModulesHtml extends AbstractAvailableModules {
out.write("<h1>Distribution " + md + "</h1>");
for (NameVersion nameVersion : md.listModulesNameVersions()) {
- String fileName = nameVersion.getName() + "-"
- + nameVersion.getVersion() + ".jar";
- String moduleUrl = baseUrl + fileName;
- out
- .write("<a href=\"" + moduleUrl + "\">" + fileName
- + "</a><br/>");
+ Distribution distribution = md.getModuleDistribution(nameVersion
+ .getName(), nameVersion.getVersion());
+
+ String moduleUrl = null;
+ if (distribution instanceof ResourceDistribution) {
+ String url = ((ResourceDistribution) distribution)
+ .getLocation().getURL().toString();
+ if (url.startsWith("reference:"))
+ moduleUrl = url;
+ }
+
+ if (moduleUrl == null)
+ moduleUrl = jarUrl(baseUrl, nameVersion);
+
+ out.write("<a href=\"" + moduleUrl + "\">"
+ + jarFileName(nameVersion) + "</a><br/>");
}
}
/** List of modules for a distribution. */
public class AvailableModulesOsgiBoot extends AbstractAvailableModules {
- private String separator = ";";
+ private String separator = ",";
@Override
protected void print(Writer out, String baseUrl, ModularDistribution md)
ModularDistribution modularDistribution = (ModularDistribution) request
.getAttribute("modularDistribution");
response.getWriter().write(
- modularDistribution.getDescriptor("eclipse").toString());
+ modularDistribution.getModulesDescriptor("eclipse").toString());
}
}
--- /dev/null
+package org.argeo.slc.web.mvc.provisioning;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.argeo.slc.build.ModularDistribution;
+import org.argeo.slc.msg.ObjectList;
+import org.argeo.slc.msg.build.ModularDistributionDescriptor;
+import org.argeo.slc.web.mvc.AbstractServiceController;
+import org.springframework.web.servlet.ModelAndView;
+
+/** List of distributions. */
+public class ListModularDistributions extends AbstractServiceController {
+ private Set<ModularDistribution> modularDistributions;
+
+ @Override
+ protected void handleServiceRequest(HttpServletRequest request,
+ HttpServletResponse response, ModelAndView modelAndView)
+ throws Exception {
+
+ String baseUrl = "http://" + request.getServerName() + ":"
+ + request.getServerPort() + request.getContextPath() + "/dist"
+ + "/";
+
+ ObjectList ol = new ObjectList();
+
+ for (Iterator<ModularDistribution> it = modularDistributions.iterator(); it
+ .hasNext();) {
+ ModularDistribution md = it.next();
+ String moduleBase = baseUrl + md.getName() + "/" + md.getVersion()
+ + "/";
+ ModularDistributionDescriptor mdd = new ModularDistributionDescriptor();
+ mdd.setName(md.getName());
+ mdd.setVersion(md.getVersion());
+
+ mdd.getModulesDescriptors().put("modularDistribution",
+ moduleBase + "modularDistribution");
+ mdd.getModulesDescriptors().put("eclipse", moduleBase + "site.xml");
+
+ ol.getObjects().add(mdd);
+ }
+
+ modelAndView.addObject(ol);
+ }
+
+ public void setModularDistributions(
+ Set<ModularDistribution> modularDistributions) {
+ this.modularDistributions = modularDistributions;
+ }
+
+}
public Set<NameVersion> listModulesNameVersions();
- public Object getDescriptor(String descriptorType);
+ public Object getModulesDescriptor(String descriptorType);
}
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.slc</groupId>
org.argeo.slc.*
</Export-Package>
<Import-Package>org.argeo.slc.*;resolution:=optional,
+ org.argeo.slc.build;resolution:=optional,
org.argeo.slc.execution;resolution:=optional,
org.argeo.slc.core.attachment;resolution:=optional,
org.argeo.slc.core.structure;resolution:=optional,
org.argeo.slc.runtime;resolution:=optional,
org.argeo.slc.core.execution;resolution:=optional,
org.argeo.slc.msg;resolution:=optional,
+ org.argeo.slc.msg.build;resolution:=optional,
org.argeo.slc.msg.process;resolution:=optional,
org.argeo.slc.msg.event;resolution:=optional,
org.argeo.slc.msg.test.tree;resolution:=optional,
<groupId>javax.xml.stream</groupId>
<artifactId>com.springsource.javax.xml.stream</artifactId>
</dependency>
-
+
<!-- Unit Tests -->
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
--- /dev/null
+<?xml version="1.0"?>
+
+<mapping>
+ <description>Build objects XML mapping</description>
+
+ <class name="org.argeo.slc.build.BasicNameVersion">
+ <map-to ns-uri="http://argeo.org/projects/slc/schemas"
+ ns-prefix="slc" />
+ <field name="name">
+ <bind-xml name="name" node="attribute" />
+ </field>
+ <field name="version">
+ <bind-xml name="version" node="attribute" />
+ </field>
+ </class>
+</mapping>
\ No newline at end of file
</field>
</class>
+ <!-- BUILD -->
+ <class name="org.argeo.slc.msg.build.ModularDistributionDescriptor"
+ extends="org.argeo.slc.build.BasicNameVersion">
+ <map-to ns-uri="http://argeo.org/projects/slc/schemas"
+ ns-prefix="slc" />
+ <field name="name">
+ <bind-xml name="name" node="attribute" />
+ </field>
+ <field name="version">
+ <bind-xml name="version" node="attribute" />
+ </field>
+ <field name="modulesDescriptors" collection="map">
+ <bind-xml name="modulesDescriptor" location="modulesDescriptors">
+ <class name="org.exolab.castor.mapping.MapItem">
+ <map-to ns-uri="http://argeo.org/projects/slc/schemas"
+ ns-prefix="slc" />
+ <field name="key" type="string">
+ <bind-xml name="type" node="attribute" />
+ </field>
+ <field name="value" type="string">
+ <bind-xml name="url" node="attribute" />
+ </field>
+ </class>
+ </bind-xml>
+ </field>
+ </class>
+
<!-- TESTS -->
<class name="org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest">
<map-to ns-uri="http://argeo.org/projects/slc/schemas"
<field name="resultUuid" />
<field name="closeDate" />
</class>
-
+
<class name="org.argeo.slc.msg.test.tree.AddTreeTestResultAttachmentRequest">
<map-to ns-uri="http://argeo.org/projects/slc/schemas"
ns-prefix="slc" />
<value>
classpath:org/argeo/slc/castor/attachment.xml
</value>
+ <value>
+ classpath:org/argeo/slc/castor/build.xml
+ </value>
</list>
</property>
<property name="whitespacePreserve" value="true" />
StringResult xml = new StringResult();
marshaller.marshal(obj, xml);
- log.info("Marshalled ResultPart Request: " + xml);
+ log.info("Marshalled " + obj.getClass() + ": " + xml + "\n");
if (validate)
UnitXmlUtils.assertXmlValidation(getBean(XmlValidator.class),
--- /dev/null
+package org.argeo.slc.castor;\r
+\r
+import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.msg.build.ModularDistributionDescriptor;\r
+\r
+public class ModularDistributionCastorTest extends AbstractCastorTestCase {\r
+ public void testModularDistributionDescriptor() throws Exception {\r
+ ModularDistributionDescriptor mdd = new ModularDistributionDescriptor();\r
+ mdd.setName("name");\r
+ mdd.setVersion("0.1.0");\r
+ mdd.getModulesDescriptors().put("eclipse",\r
+ "http://localhost/updateSite");\r
+ mdd.getModulesDescriptors().put("modularDistribution",\r
+ "http://localhost/modularDistribution");\r
+\r
+ marshUnmarsh(mdd, false);\r
+ }\r
+\r
+ public void testModularDistributionDescriptorList() throws Exception {\r
+ ModularDistributionDescriptor mdd = new ModularDistributionDescriptor();\r
+ mdd.setName("name");\r
+ mdd.setVersion("0.1.0");\r
+ mdd.getModulesDescriptors().put("eclipse",\r
+ "http://localhost/updateSite");\r
+ mdd.getModulesDescriptors().put("modularDistribution",\r
+ "http://localhost/modularDistribution");\r
+\r
+ ModularDistributionDescriptor mdd2 = new ModularDistributionDescriptor();\r
+ mdd2.setName("name2");\r
+ mdd2.setVersion("0.1.1");\r
+ mdd2.getModulesDescriptors().put("eclipse",\r
+ "http://localhost/updateSite2");\r
+ mdd2.getModulesDescriptors().put("modularDistribution",\r
+ "http://localhost/modularDistribution2");\r
+\r
+ ObjectList ol = new ObjectList();\r
+ ol.getObjects().add(mdd);\r
+ ol.getObjects().add(mdd2);\r
+\r
+ marshUnmarsh(ol, false);\r
+ }\r
+\r
+}\r
package org.argeo.slc.osgi;
+import org.argeo.slc.build.BasicNameVersion;
import org.argeo.slc.build.Distribution;
import org.argeo.slc.deploy.DeploymentData;
import org.argeo.slc.deploy.Module;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
-public class OsgiBundle implements Module {
- private String name;
- private String version;
+public class OsgiBundle extends BasicNameVersion implements Module {
private Distribution distribution;
private Long internalBundleId;
}
public OsgiBundle(String name, String version) {
- this.name = name;
- this.version = version;
+ super(name, version);
}
public OsgiBundle(Bundle bundle) {
- name = bundle.getSymbolicName();
- version = bundle.getHeaders().get(Constants.BUNDLE_VERSION).toString();
+ super(bundle.getSymbolicName(), getVersionSafe(bundle));
internalBundleId = bundle.getBundleId();
}
+ private static String getVersionSafe(Bundle bundle) {
+ Object versionObj = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (versionObj != null)
+ return versionObj.toString();
+ else
+ return null;
+ }
+
public OsgiBundle(RealizedFlow realizedFlow) {
- name = realizedFlow.getModuleName();
- version = realizedFlow.getModuleVersion();
+ super(realizedFlow.getModuleName(), realizedFlow.getModuleVersion());
}
public String getDeployedSystemId() {
- return name + ":" + version;
+ return getName() + ":" + getVersion();
}
public DeploymentData getDeploymentData() {
throw new UnsupportedOperationException();
}
- public String getName() {
- return name;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
public void setDistribution(Distribution distribution) {
this.distribution = distribution;
}
--- /dev/null
+package org.argeo.slc.osgi.build;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+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.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.osgi.context.BundleContextAware;
+
+public abstract class AbstractOsgiModularDistribution implements
+ ModularDistribution, BundleContextAware, InitializingBean {
+ private final static Log log = LogFactory
+ .getLog(AbstractOsgiModularDistribution.class);
+
+ private BundleContext bundleContext;
+ private EclipseUpdateSite eclipseUpdateSite;
+
+ /** Initialized by the object itself. */
+ private SortedMap<NameVersion, Distribution> distributions = new TreeMap<NameVersion, Distribution>();
+
+ protected abstract void fillDistributions(
+ SortedMap<NameVersion, Distribution> distributions)
+ throws Exception;
+
+ public Distribution getModuleDistribution(String moduleName,
+ String moduleVersion) {
+ return distributions
+ .get(new BasicNameVersion(moduleName, moduleVersion));
+ }
+
+ public String getDistributionId() {
+ return bundleContext.getBundle().getSymbolicName()
+ + "-"
+ + bundleContext.getBundle().getHeaders().get(
+ Constants.BUNDLE_VERSION);
+ }
+
+ public Set<NameVersion> listModulesNameVersions() {
+ return distributions.keySet();
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ fillDistributions(distributions);
+ if (log.isDebugEnabled())
+ log.debug("Distribution " + getName() + ":" + getVersion()
+ + " loaded (" + distributions.size() + " modules)");
+ }
+
+ protected String findVersion(String name) {
+ Set<String> versions = new HashSet<String>();
+ 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 Object getModulesDescriptor(String descriptorType) {
+ if (descriptorType.equals("eclipse"))
+ return writeEclipseUpdateSite();
+ else
+ throw new UnsupportedException("descriptorType", descriptorType);
+ }
+
+ protected Set<NameVersion> writePlainUrlList() {
+ return distributions.keySet();
+ }
+
+ protected String writeEclipseUpdateSite() {
+ if (eclipseUpdateSite == null)
+ throw new SlcException("No eclipse update site declared.");
+
+ StringBuffer buf = new StringBuffer("");
+ buf.append("<site>");
+
+ List<EclipseUpdateSiteCategory> usedCategories = new ArrayList<EclipseUpdateSiteCategory>();
+ for (EclipseUpdateSiteFeature feature : eclipseUpdateSite.getFeatures()) {
+
+ String featureId = feature.getName();
+ String featureVersion = findVersion(featureId);
+ buf.append("<feature");
+ buf.append(" url=\"features/").append(featureId).append('_')
+ .append(featureVersion).append(".jar\"");
+ buf.append(" id=\"").append(featureId).append("\"");
+ buf.append(" version=\"").append(featureVersion).append("\"");
+ buf.append(">\n");
+
+ for (EclipseUpdateSiteCategory category : feature.getCategories()) {
+ usedCategories.add(category);
+ buf.append(" <category name=\"").append(category.getName())
+ .append("\"/>\n");
+ }
+ buf.append("</feature>\n\n");
+ }
+
+ for (EclipseUpdateSiteCategory category : usedCategories) {
+ buf.append("<category-def");
+ buf.append(" name=\"").append(category.getName()).append("\"");
+ buf.append(" label=\"").append(category.getLabel()).append("\"");
+ buf.append(">\n");
+ buf.append(" <description>").append(category.getDescription())
+ .append("</description>\n");
+ buf.append("</category-def>\n\n");
+ }
+
+ buf.append("</site>");
+ return buf.toString();
+ }
+
+ 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;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+}
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<NameVersion, VersionedResourceDistribution> distributions = new TreeMap<NameVersion, VersionedResourceDistribution>();
-
- 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<URL> urls = (Enumeration<URL>) 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<NameVersion> listModulesNameVersions() {
- return distributions.keySet();
- }
-
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- }
-
- @SuppressWarnings(value = { "unchecked" })
- public void afterPropertiesSet() throws Exception {
- Enumeration<URL> urls = (Enumeration<URL>) bundleContext.getBundle()
- .findEntries(libDirectory, "*.jar", false);
+ protected void fillDistributions(
+ SortedMap<NameVersion, Distribution> distributions)
+ throws Exception {
+ Enumeration<URL> urls = (Enumeration<URL>) getBundleContext()
+ .getBundle().findEntries(libDirectory, "*.jar", false);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
JarInputStream in = null;
IOUtils.closeQuietly(in);
}
}
- if (log.isDebugEnabled())
- log.debug("Distribution " + getName() + ":" + getVersion()
- + " loaded (" + distributions.size() + " modules)");
-
- }
-
- protected String findVersion(String name) {
- Set<String> versions = new HashSet<String>();
- 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<NameVersion> writePlainUrlList() {
- return distributions.keySet();
- }
-
- protected String writeEclipseUpdateSite() {
- if (eclipseUpdateSite == null)
- throw new SlcException("No eclipse update site declared.");
-
- StringBuffer buf = new StringBuffer("");
- buf.append("<site>");
-
- List<EclipseUpdateSiteCategory> usedCategories = new ArrayList<EclipseUpdateSiteCategory>();
- for (EclipseUpdateSiteFeature feature : eclipseUpdateSite.getFeatures()) {
-
- String featureId = feature.getName();
- String featureVersion = findVersion(featureId);
- buf.append("<feature");
- buf.append(" url=\"features/").append(featureId).append('_')
- .append(featureVersion).append(".jar\"");
- buf.append(" id=\"").append(featureId).append("\"");
- buf.append(" version=\"").append(featureVersion).append("\"");
- buf.append(">\n");
-
- for (EclipseUpdateSiteCategory category : feature.getCategories()) {
- usedCategories.add(category);
- buf.append(" <category name=\"").append(category.getName())
- .append("\"/>\n");
- }
- buf.append("</feature>\n\n");
- }
-
- for (EclipseUpdateSiteCategory category : usedCategories) {
- buf.append("<category-def");
- buf.append(" name=\"").append(category.getName()).append("\"");
- buf.append(" label=\"").append(category.getLabel()).append("\"");
- buf.append(">\n");
- buf.append(" <description>").append(category.getDescription())
- .append("</description>\n");
- buf.append("</category-def>\n\n");
- }
-
- buf.append("</site>");
- 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<URL> urls =
+ * (Enumeration<URL>) 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;
+ * }
+ */
}
--- /dev/null
+package org.argeo.slc.osgi.build;
+
+import java.net.URL;
+import java.util.SortedMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.NameVersion;
+import org.argeo.slc.core.build.VersionedResourceDistribution;
+import org.argeo.slc.osgi.OsgiBundle;
+import org.osgi.framework.Bundle;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+
+public class OsgiRuntimeModularDistribution extends
+ AbstractOsgiModularDistribution implements ResourceLoaderAware {
+ private final static Log log = LogFactory
+ .getLog(OsgiRuntimeModularDistribution.class);
+
+ private ResourceLoader resourceLoader;
+
+ protected void fillDistributions(
+ SortedMap<NameVersion, Distribution> distributions)
+ throws Exception {
+
+ for (Bundle bundle : getBundleContext().getBundles()) {
+ OsgiBundle osgiBundle = new OsgiBundle(bundle);
+
+ String location = bundle.getLocation();
+ if (location.startsWith("reference:file:"))
+ location = location.substring("reference:".length());
+ try {
+ URL url = new URL(location);
+ Resource res = resourceLoader.getResource(url.toString());
+ distributions.put(osgiBundle,
+ new VersionedResourceDistribution(osgiBundle, res));
+ } catch (Exception e) {
+ log.warn("Cannot interpret location " + location
+ + " of bundle " + bundle + ": " + e);
+ }
+ }
+ }
+
+ public void setResourceLoader(ResourceLoader resourceLoader) {
+ this.resourceLoader = resourceLoader;
+ }
+}