Modular distributions
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 23 Jul 2009 12:09:29 +0000 (12:09 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 23 Jul 2009 12:09:29 +0000 (12:09 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2733 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

29 files changed:
demo/pom.xml
dep/org.argeo.slc.dep.server/pom.xml
dep/pom.xml
modules/server/org.argeo.slc.server.main/META-INF/MANIFEST.MF
modules/server/org.argeo.slc.server.main/META-INF/spring/eclipseUpdateSite.xml [new file with mode: 0644]
modules/server/org.argeo.slc.server.main/META-INF/spring/manager.xml
modules/server/org.argeo.slc.server.main/META-INF/spring/osgi.xml
modules/server/org.argeo.slc.webapp.war/META-INF/MANIFEST.MF
modules/server/org.argeo.slc.webapp.war/WEB-INF/provisioning-servlet.xml
modules/server/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/build/VersionedResourceDistribution.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/build/ModularDistributionDescriptor.java [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/AbstractAvailableModules.java
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/AvailableModulesHtml.java
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/AvailableModulesOsgiBoot.java
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/EclipseUpdateSiteHandler.java
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/ListModularDistributions.java [new file with mode: 0644]
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/build/ModularDistribution.java
runtime/org.argeo.slc.support.castor/pom.xml
runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/build.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/msg.xml
runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/spring.xml
runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/AbstractCastorTestCase.java
runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ModularDistributionCastorTest.java [new file with mode: 0644]
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/AbstractOsgiModularDistribution.java [new file with mode: 0644]
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/BundleModularDistribution.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java [new file with mode: 0644]

index 6a6b21dbc68327bfdc845a83a47cd4c3bf100fef..9f0a494c9beff6ea74129f0366d32bf0d8ce5e22 100644 (file)
                                                                <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>
index 69db135908f6ec3f399a80d3bfcacabd7cfe5a6d..5dc5571050d3690349e4d953628333e577f7fe0b 100644 (file)
        <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>
index 1913d086cfdca9894f029805cd06cc03b8cc5775..91c3977fb2d74b0feed8a69d7ae425e7466b6b59 100644 (file)
                        </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
index f5bfae3057bb79a6912a612e445d7657355b5d5f..28b30ae38583b3d8ad79c9bc54d96ec1a7b53e11 100644 (file)
@@ -4,3 +4,5 @@ Bundle-Version: 0.11.4.SNAPSHOT
 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
diff --git a/modules/server/org.argeo.slc.server.main/META-INF/spring/eclipseUpdateSite.xml b/modules/server/org.argeo.slc.server.main/META-INF/spring/eclipseUpdateSite.xml
new file mode 100644 (file)
index 0000000..6e8775c
--- /dev/null
@@ -0,0 +1,20 @@
+<?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
index eccb3544a5a99d414215c771a3ac9407db621a6c..bf342bb6c9f0f54e1d4841938866d46e87f6585c 100644 (file)
@@ -5,4 +5,7 @@
        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
index 43818e34319f4ced98b75d2e96fbd9ce77817c1f..50237f47d9c7281770222001d138611ae47d219a 100644 (file)
@@ -7,4 +7,5 @@
        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
index 83da4bfa0492b8df3afce5ec8f242b4e4473851f..834a4474ac40df029942734307edc653bb0284fc 100644 (file)
@@ -48,4 +48,5 @@ Import-Package: net.sf.cglib.core,
  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
index a0f4c64908304ffafe1554bc189e836945d9446f..bc2df745ca4d97184b6f1fe3dd3070e8cc224b20 100644 (file)
@@ -35,7 +35,7 @@
                        <value>
                                /*/*/modules.html=availableModulesHtml
                                /*/*/modules=availableModulesPlain
-                               /*/*/osgiBoot=availableModulesOsgiBoot
+                               /*/*/modularDistribution=availableModulesOsgiBoot
                                /*/*/site.xml=updateSiteHandler
                        </value>
                </property>
index 9365eaac349b98ac4d90533074d73b43621c065e..42f0ec533b4471364e6ed99698a8ea7ad8322e99 100644 (file)
                <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">
index a813438ba1f31b90fc7da2b4099f33dd70ee667c..11044a2aaa842e45199ff42a5b41661ca13dea15 100644 (file)
@@ -12,6 +12,11 @@ public class VersionedResourceDistribution extends ResourceDistribution
                super();
        }
 
+       public VersionedResourceDistribution(NameVersion nameVersion,
+                       Resource resource) {
+               this(nameVersion.getName(), nameVersion.getVersion(), resource);
+       }
+
        public VersionedResourceDistribution(String name, String version,
                        Resource resource) {
                super(resource);
diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/build/ModularDistributionDescriptor.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/build/ModularDistributionDescriptor.java
new file mode 100644 (file)
index 0000000..1115149
--- /dev/null
@@ -0,0 +1,24 @@
+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;
+       }
+
+}
index fcefc8345e974986d70255920605af9619a01d46..788c0babfdd04ff2c39fe7577ee1ab6ea862fe60 100644 (file)
@@ -37,7 +37,7 @@ public class OsgiBoot {
                        .booleanValue();
 
        private boolean excludeSvn = true;
-       private String modulesUrlSeparator = ";";
+       private String modulesUrlSeparator = ",";
 
        private final BundleContext bundleContext;
 
index e9acf08f2a911ad78ace333b05e979abb6dbafa8..f85f4d86c821b834bb24f8c233b56b11da75a4c0 100644 (file)
@@ -8,8 +8,11 @@ import javax.servlet.http.HttpServletRequest;
 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,
@@ -23,8 +26,9 @@ public abstract class AbstractAvailableModules implements HttpRequestHandler {
                                .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);
        }
@@ -33,4 +37,12 @@ public abstract class AbstractAvailableModules implements HttpRequestHandler {
                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";
+       }
+
 }
index 338de8353c6175e462d4b787a22d25d98a1ac9e2..7a860996db26c80b5972f569c3704828245b573e 100644 (file)
@@ -3,8 +3,10 @@ package org.argeo.slc.web.mvc.provisioning;
 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 {
@@ -14,12 +16,22 @@ 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/>");
                }
        }
 
index a31dae9ccfc7e6520412283a74f96ac6e2f60593..d0a76e97921c0fda07ab8163a474af16de9c743a 100644 (file)
@@ -8,7 +8,7 @@ import org.argeo.slc.build.NameVersion;
 
 /** 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)
index d4c7260a91e0135e699cedede475224965ab7b4f..073724d06bca68bdfd2703f8e965c4fe4a378ec6 100644 (file)
@@ -17,6 +17,6 @@ public class EclipseUpdateSiteHandler implements HttpRequestHandler {
                ModularDistribution modularDistribution = (ModularDistribution) request
                                .getAttribute("modularDistribution");
                response.getWriter().write(
-                               modularDistribution.getDescriptor("eclipse").toString());
+                               modularDistribution.getModulesDescriptor("eclipse").toString());
        }
 }
diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/ListModularDistributions.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/ListModularDistributions.java
new file mode 100644 (file)
index 0000000..13261dd
--- /dev/null
@@ -0,0 +1,54 @@
+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;
+       }
+
+}
index cc9aacdc038fc08e563fb41ddef9193ab6329174..5c9f4377877e1c68a616006772c7cbc7c7034e88 100644 (file)
@@ -8,5 +8,5 @@ public interface ModularDistribution extends Distribution, NameVersion {
 
        public Set<NameVersion> listModulesNameVersions();
 
-       public Object getDescriptor(String descriptorType);
+       public Object getModulesDescriptor(String descriptorType);
 }
index 41c1b6f5f2efef8c3a1524356dac60f18b442fbe..4035da589d6c31731c4395e44361458b2b661fdf 100644 (file)
@@ -1,4 +1,5 @@
-<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>
@@ -38,6 +39,7 @@
                                                        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,
@@ -47,6 +49,7 @@
                                                        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,
@@ -91,7 +94,7 @@
                        <groupId>javax.xml.stream</groupId>
                        <artifactId>com.springsource.javax.xml.stream</artifactId>
                </dependency>
-               
+
                <!-- Unit Tests -->
                <dependency>
                        <groupId>org.argeo.slc.runtime</groupId>
diff --git a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/build.xml b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/build.xml
new file mode 100644 (file)
index 0000000..60e66c0
--- /dev/null
@@ -0,0 +1,16 @@
+<?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
index 0712515c891a90494afac0d9fbb0a765358662fa..85f5d850d1bc019c72a1ebd107e1af151aa53687 100644 (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"
@@ -43,7 +70,7 @@
                <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" />
index bdcd63a64d1695850c330c2097156225e8d78e70..6b0fa2b4236f71b394f823c54dce6a9d026aaba1 100644 (file)
@@ -27,6 +27,9 @@
                                <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" />
index a2f48c1997a770e38da09938ccec51785269af35..1cdd7be8fb3feaefb47d986f097a956b267cf611 100644 (file)
@@ -35,7 +35,7 @@ public abstract class AbstractCastorTestCase extends AbstractSpringTestCase {
                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),
diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ModularDistributionCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ModularDistributionCastorTest.java
new file mode 100644 (file)
index 0000000..e2e2209
--- /dev/null
@@ -0,0 +1,43 @@
+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
index 745ba76a616218bb244074fb4fc17b4aadf97fde..6dd75716afa336052d565bb2e19576cb7c378400 100644 (file)
@@ -1,5 +1,6 @@
 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;
@@ -8,9 +9,7 @@ import org.argeo.slc.process.RealizedFlow;
 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;
@@ -20,23 +19,28 @@ public class OsgiBundle implements Module {
        }
 
        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() {
@@ -51,22 +55,6 @@ public class OsgiBundle implements Module {
                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;
        }
diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/AbstractOsgiModularDistribution.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/AbstractOsgiModularDistribution.java
new file mode 100644 (file)
index 0000000..d4df344
--- /dev/null
@@ -0,0 +1,157 @@
+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;
+       }
+
+}
index 79bc3e6a87929a68f9feef2ebc8672ab5a453463..ac6eaa75e89b41bcd8047382598d628de143d2fd 100644 (file)
@@ -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<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;
@@ -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<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;
+        * }
+        */
 
 }
diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java
new file mode 100644 (file)
index 0000000..1c68cf5
--- /dev/null
@@ -0,0 +1,49 @@
+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;
+       }
+}