]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Start implementing OSGi integration tests
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 2 Jun 2009 18:11:27 +0000 (18:11 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 2 Jun 2009 18:11:27 +0000 (18:11 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2444 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

21 files changed:
integration-tests/org.argeo.slc.it.webapp/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
integration-tests/org.argeo.slc.it.webapp/pom.xml
integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/StartStopServerTest.java [new file with mode: 0644]
org.argeo.slc/pom.xml
runtime/org.argeo.slc.osgiboot/.classpath
runtime/org.argeo.slc.osgiboot/pom.xml
runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/Activator.java
runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/test/bundles/others/subdir/org.argeo.slc.osgiboot.test.bundle3/META-INF/MANIFEST.MF [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/test/bundles/some/excluded/org.argeo.slc.osgiboot.test.bundle0/META-INF/MANIFEST.MF [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/test/bundles/some/org.argeo.slc.osgiboot.test.bundle1/META-INF/MANIFEST.MF [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/test/bundles/some/org.argeo.slc.osgiboot.test.bundle2/META-INF/MANIFEST.MF [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootNoRuntimeTest.java [new file with mode: 0644]
runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/.classpath
runtime/org.argeo.slc.support.equinox/pom.xml
runtime/org.argeo.slc.support.equinox/src/test/bundles/org.argeo.slc.support.osgi.test.hello/META-INF/MANIFEST.MF [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/src/test/bundles/org.argeo.slc.support.osgi.test.hello/META-INF/spring/hello.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTest.java [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java [new file with mode: 0644]

diff --git a/integration-tests/org.argeo.slc.it.webapp/.settings/org.eclipse.jdt.core.prefs b/integration-tests/org.argeo.slc.it.webapp/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..a1fe815
--- /dev/null
@@ -0,0 +1,12 @@
+#Tue Jun 02 18:41:08 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
index 6b15ce4a7b46b02987d7ba5c70a464cdbd647a43..c1ba1a27a1edd4ec8260e46729ed81ef44a41fd0 100644 (file)
@@ -2,16 +2,33 @@
        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>
-               <artifactId>argeo-slc</artifactId>
+               <groupId>org.argeo.slc.it</groupId>
+               <artifactId>argeo-slc-it</artifactId>
                <version>0.11.3-SNAPSHOT</version>
-               <relativePath>../../org.argeo.slc</relativePath>
+               <relativePath>..</relativePath>
        </parent>
        <artifactId>org.argeo.slc.it.webapp</artifactId>
        <packaging>jar</packaging>
        <name>Argeo SLC Web Application Integration Tests</name>
        <build>
                <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-dependency-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>copy-dependencies</id>
+                                               <phase>pre-integration-test</phase>
+                                               <goals>
+                                                       <goal>copy-dependencies</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <overWriteReleases>true</overWriteReleases>
+                                                       <overWriteSnapshots>true</overWriteSnapshots>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                </plugins>
        </build>
        <dependencies>
+               <!--  Server -->
+               <dependency>
+                       <groupId>org.argeo.slc.server</groupId>
+                       <artifactId>bundles</artifactId>
+                       <version>${project.version}</version>
+                       <type>pom</type>
+               </dependency>
+
+               <!-- TEST -->
+               <dependency>
+                       <groupId>org.argeo.slc.runtime</groupId>
+                       <artifactId>org.argeo.slc.support.equinox</artifactId>
+                       <classifier>tests</classifier>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework.osgi</groupId>
+                       <artifactId>org.springframework.osgi.test</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.argeo.slc.runtime</groupId>
+                       <artifactId>org.argeo.slc.osgiboot</artifactId>
+                       <scope>test</scope>
+               </dependency>
+
        </dependencies>
 </project>
\ No newline at end of file
diff --git a/integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/StartStopServerTest.java b/integration-tests/org.argeo.slc.it.webapp/src/test/java/org/argeo/slc/it/webapp/StartStopServerTest.java
new file mode 100644 (file)
index 0000000..84ac248
--- /dev/null
@@ -0,0 +1,55 @@
+package org.argeo.slc.it.webapp;
+
+import java.util.Properties;
+
+import org.argeo.slc.osgi.test.AbstractOsgiRuntimeTest;
+import org.argeo.slc.osgiboot.OsgiBoot;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.test.platform.EquinoxPlatform;
+import org.springframework.osgi.test.platform.OsgiPlatform;
+import org.springframework.osgi.util.OsgiStringUtils;
+
+public class StartStopServerTest extends AbstractOsgiRuntimeTest {
+       public void testStartStop() throws Exception {
+               BundleContext bundleContext = osgiPlatform.getBundleContext();
+               Bundle[] bundles = bundleContext.getBundles();
+               for (int i = 0; i < bundles.length; i++) {
+                       System.out
+                                       .println(OsgiStringUtils.nullSafeSymbolicName(bundles[i]));
+               }
+
+               Thread.sleep(5 * 1000);
+
+       }
+
+       protected void postStart() throws Exception {
+               String classpath = System.getProperty("java.class.path");
+               System.out.println("Classpath=" + classpath);
+               osgiBoot.installUrls(osgiBoot.getLocationsUrls(
+                               OsgiBoot.DEFAULT_BASE_URL, classpath));
+               osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
+                               "../../demo/site;in=*;ex=target"));
+               osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
+                               "target/dependency;in=*.jar"));
+
+               String bundlesToStart = "org.argeo.dep.osgi.catalina.start,org.springframework.osgi.extender,org.springframework.osgi.web.extender,org.springframework.osgi.samples.simplewebapp,org.argeo.slc.server.activemq,org.argeo.slc.server.hsqldb,org.argeo.slc.server.hibernate,org.argeo.slc.server.services,org.argeo.slc.server.jms,org.argeo.slc.webapp,org.argeo.slc.ria";
+               osgiBoot.startBundles(bundlesToStart);
+       }
+
+       @Override
+       protected OsgiPlatform createOsgiPlatform() {
+
+               return new EquinoxPlatform() {
+
+                       @Override
+                       public Properties getConfigurationProperties() {
+                               Properties props = super.getConfigurationProperties();
+                               props.put("osgi.console", "");
+                               return props;
+                       }
+
+               };
+       }
+
+}
index 12eb55d7b472aed732f409075bc4884fc8d6378b..20c25782a99a6e3a5e86a2c3f97e5b7cf0ae191b 100644 (file)
@@ -263,6 +263,13 @@ limitations under the License.
                                <artifactId>org.argeo.slc.support.equinox</artifactId>
                                <version>${project.version}</version>
                        </dependency>
+                       <dependency>
+                               <groupId>org.argeo.slc.runtime</groupId>
+                               <artifactId>org.argeo.slc.support.equinox</artifactId>
+                               <classifier>tests</classifier>
+                               <scope>test</scope>
+                               <version>${project.version}</version>
+                       </dependency>
                        <dependency>
                                <groupId>org.argeo.slc.runtime</groupId>
                                <artifactId>org.argeo.slc.support.ws.client</artifactId>
@@ -441,13 +448,11 @@ limitations under the License.
                                <artifactId>org.springframework.jms</artifactId>
                                <version>${version.spring}</version>
                        </dependency>
-                       <!-- 
-                       <dependency>
-                               <groupId>org.springframework.ws</groupId>
+                       <!--
+                               <dependency> <groupId>org.springframework.ws</groupId>
                                <artifactId>org.springframework.ws</artifactId>
-                               <version>${version.spring-ws}</version>
-                       </dependency>
-                        -->
+                               <version>${version.spring-ws}</version> </dependency>
+                       -->
                        <dependency>
                                <groupId>org.springframework.ws</groupId>
                                <artifactId>org.springframework.oxm</artifactId>
@@ -474,6 +479,11 @@ limitations under the License.
                                <artifactId>org.springframework.osgi.web</artifactId>
                                <version>${version.spring-osgi}</version>
                        </dependency>
+                       <dependency>
+                               <groupId>org.springframework.osgi</groupId>
+                               <artifactId>org.springframework.osgi.test</artifactId>
+                               <version>${version.spring-osgi}</version>
+                       </dependency>
                        <dependency>
                                <groupId>org.argeo.slc.dep.osgi</groupId>
                                <artifactId>org.argeo.dep.osgi.catalina.start</artifactId>
index 16f01e2ee7b671c44c26c453773dab706e98da1e..bab5b6519cb35d626d1749afcb047740c3971f90 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
        <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+       <classpathentry kind="src" path="src/test/java"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
        <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
        <classpathentry kind="output" path="target/classes"/>
index df47dc71ae916b59ccef5e3ef362ec77ec646eaa..d7c2afbbd76a0fbfd9d406562b270607257a2ff4 100644 (file)
                        <artifactId>org.eclipse.osgi</artifactId>
                </dependency>
 
+               <!-- TEST -->
+               <dependency>
+                       <groupId>org.junit</groupId>
+                       <artifactId>com.springsource.junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
+
+
 </project>
index 4457a4c51a9d119650289a0c16bc57fbed50a1c6..5d70b769a49694a7a400335373303d7c3716252e 100644 (file)
@@ -1,48 +1,29 @@
 package org.argeo.slc.osgiboot;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
-import org.argeo.slc.osgiboot.internal.springutil.AntPathMatcher;
-import org.argeo.slc.osgiboot.internal.springutil.PathMatcher;
-import org.argeo.slc.osgiboot.internal.springutil.SystemPropertyUtils;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 
 public class Activator implements BundleActivator {
-       public final static String PROP_SLC_OSGI_START = "slc.osgi.start";
-       public final static String PROP_SLC_OSGI_BUNDLES = "slc.osgi.bundles";
-       public final static String PROP_SLC_OSGI_DEV_BASES = "slc.osgi.devBases";
-       public final static String PROP_SLC_OSGI_DEV_PATTERNS = "slc.osgi.devPatterns";
-       public final static String PROP_SLC_OSGI_LOCATIONS = "slc.osgi.locations";
-       public final static String PROP_SLC_OSGI_BASE_URL = "slc.osgi.baseUrl";
-       public final static String PROP_SLC_MAVEN_DEPENDENCY_FILE = "slc.maven.dependencyFile";
-       public final static String PROP_SLC_OSGIBOOT_DEBUG = "slc.osgiboot.debug";
-
-       private static Boolean debug = Boolean.parseBoolean(System.getProperty(
-                       PROP_SLC_OSGIBOOT_DEBUG, "false"));
-
+       
        public void start(BundleContext bundleContext) throws Exception {
                try {
                        info("SLC OSGi bootstrap starting...");
-                       // installUrls(bundleContext, getDevLocationsUrls());
-
-                       installUrls(bundleContext, getBundlesUrls());
+                       OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
+                       
+                       osgiBoot.installUrls( osgiBoot.getBundlesUrls());
 
-                       installUrls(bundleContext, getLocationsUrls());
+                       osgiBoot.installUrls( osgiBoot.getLocationsUrls());
 
-                       installUrls(bundleContext, getMavenUrls());
+//                     installUrls(bundleContext, getMavenUrls());
 
-                       startBundles(bundleContext);
+                       osgiBoot.startBundles();
 
                        info("SLC OSGi bootstrap completed");
                } catch (Exception e) {
@@ -54,232 +35,7 @@ public class Activator implements BundleActivator {
        public void stop(BundleContext context) throws Exception {
        }
 
-       protected static void installUrls(BundleContext bundleContext,
-                       List<String> urls) {
-               Map<String, Bundle> installedBundles = getInstalledBundles(bundleContext);
-               for (String url : urls) {
-                       try {
-                               if (installedBundles.containsKey(url)) {
-                                       Bundle bundle = installedBundles.get(url);
-                                       // bundle.update();
-                                       if (debug)
-                                               debug("Bundle " + bundle.getSymbolicName()
-                                                               + " already installed from " + url);
-                               } else {
-                                       Bundle bundle = bundleContext.installBundle(url);
-                                       if (debug)
-                                               debug("Installed bundle " + bundle.getSymbolicName()
-                                                               + " from " + url);
-                               }
-                       } catch (BundleException e) {
-                               warn("Could not install bundle from " + url + ": "
-                                               + e.getMessage());
-                       }
-               }
-
-       }
-
-       protected List<String> getLocationsUrls() {
-               List<String> urlsProvided = new ArrayList<String>();
-
-               String baseUrl = getProperty(PROP_SLC_OSGI_BASE_URL, "reference:file:");
-               String bundlesList = getProperty(PROP_SLC_OSGI_LOCATIONS);
-               if (bundlesList == null)
-                       return urlsProvided;
-               bundlesList = SystemPropertyUtils.resolvePlaceholders(bundlesList);
-
-               StringTokenizer st = new StringTokenizer(bundlesList,
-                               File.pathSeparator);
-               while (st.hasMoreTokens()) {
-                       urlsProvided.add(baseUrl + st.nextToken().trim());
-               }
-               return urlsProvided;
-       }
-
-       protected List<String> getDevLocationsUrls() {
-               List<String> urls = new ArrayList<String>();
-
-               String devBase = getProperty(PROP_SLC_OSGI_DEV_BASES);
-               String devPatterns = getProperty(PROP_SLC_OSGI_DEV_PATTERNS);
-               if (devBase == null)
-                       return urls;
-               devBase = SystemPropertyUtils.resolvePlaceholders(devBase);
-               devBase = devBase.replace(File.separatorChar, '/');
-               devPatterns = SystemPropertyUtils.resolvePlaceholders(devPatterns);
-
-               List<String> bases = new ArrayList<String>();
-               StringTokenizer st = new StringTokenizer(devBase, ",");
-               while (st.hasMoreTokens()) {
-                       String token = st.nextToken().trim();
-                       char lastChar = token.charAt(token.length() - 1);
-                       if (lastChar != '/')
-                               token = token + '/';
-                       bases.add(token);
-               }
-
-               List<String> patterns = new ArrayList<String>();
-               st = new StringTokenizer(devPatterns, ";");
-               while (st.hasMoreTokens()) {
-                       patterns.add(st.nextToken().trim());
-               }
-
-               List<String> matched = new ArrayList<String>();
-               PathMatcher matcher = new AntPathMatcher();
-               for (String base : bases)
-                       for (String pattern : patterns)
-                               match(matcher, matched, base, null, pattern);
-
-               for (String fullPath : matched)
-                       urls.add("reference:file:" + fullPath);
-
-               return urls;
-       }
-
-       protected List<String> getBundlesUrls() {
-               List<String> urls = new ArrayList<String>();
-
-               List<BundlesSet> bundlesSets = new ArrayList<BundlesSet>();
-               String bundles = getProperty(PROP_SLC_OSGI_BUNDLES);
-               if (bundles == null)
-                       return urls;
-               info(PROP_SLC_OSGI_BUNDLES + "=" + bundles);
-
-               StringTokenizer st = new StringTokenizer(bundles, ",");
-               while (st.hasMoreTokens()) {
-                       bundlesSets.add(new BundlesSet(st.nextToken()));
-               }
-
-               List<String> included = new ArrayList<String>();
-               PathMatcher matcher = new AntPathMatcher();
-               for (BundlesSet bundlesSet : bundlesSets)
-                       for (String pattern : bundlesSet.getIncludes())
-                               match(matcher, included, bundlesSet.getDir(), null, pattern);
-
-               List<String> excluded = new ArrayList<String>();
-               for (BundlesSet bundlesSet : bundlesSets)
-                       for (String pattern : bundlesSet.getExcludes())
-                               match(matcher, excluded, bundlesSet.getDir(), null, pattern);
-
-               for (String fullPath : included) {
-                       if (!excluded.contains(fullPath))
-                               urls.add("reference:file:" + fullPath);
-               }
-
-               return urls;
-       }
-
-       private class BundlesSet {
-               private String baseUrl = "reference:file";
-               private final String dir;
-               private List<String> includes = new ArrayList<String>();
-               private List<String> excludes = new ArrayList<String>();
-
-               public BundlesSet(String def) {
-                       StringTokenizer st = new StringTokenizer(def, ";");
-
-                       if (!st.hasMoreTokens())
-                               throw new RuntimeException("Base dir not defined.");
-                       try {
-                               String dirPath = st.nextToken();
-                               dir = new File(dirPath.replace('/', File.separatorChar))
-                                               .getCanonicalPath();
-                               if (debug)
-                                       debug("Base dir: " + dir);
-                       } catch (IOException e) {
-                               throw new RuntimeException("Cannot convert to absolute path", e);
-                       }
-
-                       while (st.hasMoreTokens()) {
-                               String tk = st.nextToken();
-                               StringTokenizer stEq = new StringTokenizer(tk, "=");
-                               String type = stEq.nextToken();
-                               String pattern = stEq.nextToken();
-                               if ("in".equals(type) || "include".equals(type)) {
-                                       includes.add(pattern);
-                               } else if ("ex".equals(type) || "exclude".equals(type)) {
-                                       excludes.add(pattern);
-                               } else if ("baseUrl".equals(type)) {
-                                       baseUrl = pattern;
-                               } else {
-                                       System.err.println("Unkown bundles pattern type " + type);
-                               }
-                       }
-               }
-
-               public String getDir() {
-                       return dir;
-               }
-
-               public List<String> getIncludes() {
-                       return includes;
-               }
-
-               public List<String> getExcludes() {
-                       return excludes;
-               }
-
-               public String getBaseUrl() {
-                       return baseUrl;
-               }
-
-       }
-
-       protected void match(PathMatcher matcher, List<String> matched,
-                       String base, String currentPath, String pattern) {
-               if (currentPath == null) {
-                       // Init
-                       File baseDir = new File(base.replace('/', File.separatorChar));
-                       File[] files = baseDir.listFiles();
-
-                       if (files == null) {
-                               warn("Base dir " + baseDir + " has no children, exists="
-                                               + baseDir.exists() + ", isDirectory="
-                                               + baseDir.isDirectory());
-                               return;
-                       }
-
-                       for (File file : files)
-                               match(matcher, matched, base, file.getName(), pattern);
-               } else {
-                       String fullPath = base + '/' + currentPath;
-                       if (matched.contains(fullPath))
-                               return;// don't try deeper if already matched
-
-                       boolean ok = matcher.match(pattern, currentPath);
-                       if (debug)
-                               debug(currentPath + " " + (ok ? "" : " not ")
-                                               + " matched with " + pattern);
-                       if (ok) {
-                               matched.add(fullPath);
-                               return;
-                       } else {
-                               String newFullPath = (base + '/' + currentPath).replace('/',
-                                               File.separatorChar);
-                               File[] files = new File(newFullPath).listFiles();
-                               if (files != null) {
-                                       for (File file : files)
-                                               if (file.isDirectory()) {
-                                                       String newCurrentPath = currentPath + '/'
-                                                                       + file.getName();
-                                                       if (matcher.matchStart(pattern, newCurrentPath)) {
-                                                               // recurse only if start matches
-                                                               match(matcher, matched, base, newCurrentPath,
-                                                                               pattern);
-                                                       } else {
-                                                               if (debug)
-                                                                       debug(newCurrentPath
-                                                                                       + " does not start match with "
-                                                                                       + pattern);
-
-                                                       }
-                                               }
-                               } else {
-                                       warn("Not a directory: " + newFullPath);
-                               }
-                       }
-               }
-       }
-
+/*
        protected List<String> getMavenUrls() throws Exception {
                String baseUrl = "reference:file:" + System.getProperty("user.home")
                                + "/.m2/repository/";
@@ -306,49 +62,8 @@ public class Activator implements BundleActivator {
 
                return asUrls(baseUrl, mavenFiles);
        }
-
-       protected void startBundles(BundleContext bundleContext) throws Exception {
-               String bundlesToStart = getProperty(PROP_SLC_OSGI_START);
-               if (bundlesToStart == null)
-                       return;
-
-               StringTokenizer st = new StringTokenizer(bundlesToStart, ",");
-               Map<String, Bundle> bundles = getBundles(bundleContext);
-               while (st.hasMoreTokens()) {
-                       String name = st.nextToken().trim();
-                       Bundle bundle = bundles.get(name);
-                       if (bundle != null)
-                               try {
-                                       bundle.start();
-                               } catch (Exception e) {
-                                       warn("Bundle " + name + " cannot be started: "
-                                                       + e.getMessage());
-                               }
-                       else
-                               warn("Bundle " + name + " not installed.");
-
-               }
-       }
-
-       /** Key is location */
-       protected static Map<String, Bundle> getInstalledBundles(
-                       BundleContext bundleContext) {
-               Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
-
-               for (Bundle bundle : bundleContext.getBundles()) {
-                       installedBundles.put(bundle.getLocation(), bundle);
-               }
-               return installedBundles;
-       }
-
-       /** Key is symbolic name */
-       protected static Map<String, Bundle> getBundles(BundleContext bundleContext) {
-               Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
-               for (Bundle bundle : bundleContext.getBundles())
-                       installedBundles.put(bundle.getSymbolicName(), bundle);
-               return installedBundles;
-       }
-
+*/
+/*
        protected static List<String> asUrls(String baseUrl,
                        List<MavenFile> mavenFiles) {
                List<String> urls = new ArrayList<String>();
@@ -374,7 +89,7 @@ public class Activator implements BundleActivator {
                component.setScope(st.nextToken());
                return component;
        }
-
+*//*
        protected static String getProperty(String name, String defaultValue) {
                final String value;
                if (defaultValue != null)
@@ -391,11 +106,11 @@ public class Activator implements BundleActivator {
        protected static String getProperty(String name) {
                return getProperty(name, null);
        }
-
+*/
        private static void info(Object obj) {
                System.out.println("# INFO " + obj);
        }
-
+/*
        private static void debug(Object obj) {
                if (debug)
                        System.out.println("# DBUG " + obj);
@@ -408,7 +123,7 @@ public class Activator implements BundleActivator {
                // else
                // System.err.println("# WARN " + obj);
        }
-
+*//*
        static class MavenFile {
                private String groupId;
                private String artifactId;
@@ -476,5 +191,5 @@ public class Activator implements BundleActivator {
                }
 
        }
-
+*/
 }
diff --git a/runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java b/runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java
new file mode 100644 (file)
index 0000000..fdcb77d
--- /dev/null
@@ -0,0 +1,325 @@
+package org.argeo.slc.osgiboot;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.argeo.slc.osgiboot.internal.springutil.AntPathMatcher;
+import org.argeo.slc.osgiboot.internal.springutil.PathMatcher;
+import org.argeo.slc.osgiboot.internal.springutil.SystemPropertyUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class OsgiBoot {
+       public final static String PROP_SLC_OSGI_START = "slc.osgi.start";
+       public final static String PROP_SLC_OSGI_BUNDLES = "slc.osgi.bundles";
+       public final static String PROP_SLC_OSGI_LOCATIONS = "slc.osgi.locations";
+       public final static String PROP_SLC_OSGI_BASE_URL = "slc.osgi.baseUrl";
+       public final static String PROP_SLC_OSGIBOOT_DEBUG = "slc.osgiboot.debug";
+
+       public final static String DEFAULT_BASE_URL = "reference:file:";
+
+       private Boolean debug = Boolean.parseBoolean(System.getProperty(
+                       PROP_SLC_OSGIBOOT_DEBUG, "false"));
+
+       private final BundleContext bundleContext;
+
+       public OsgiBoot(BundleContext bundleContext) {
+               this.bundleContext = bundleContext;
+       }
+
+       public void installUrls(List<String> urls) {
+               Map<String, Bundle> installedBundles = getInstalledBundles();
+               for (String url : urls) {
+                       try {
+                               if (installedBundles.containsKey(url)) {
+                                       Bundle bundle = installedBundles.get(url);
+                                       // bundle.update();
+                                       if (debug)
+                                               debug("Bundle " + bundle.getSymbolicName()
+                                                               + " already installed from " + url);
+                               } else {
+                                       Bundle bundle = bundleContext.installBundle(url);
+                                       if (debug)
+                                               debug("Installed bundle " + bundle.getSymbolicName()
+                                                               + " from " + url);
+                               }
+                       } catch (BundleException e) {
+                               warn("Could not install bundle from " + url + ": "
+                                               + e.getMessage());
+                       }
+               }
+
+       }
+
+       public void startBundles() throws Exception {
+               String bundlesToStart = getProperty(PROP_SLC_OSGI_START);
+               startBundles(bundlesToStart);
+       }
+
+       public void startBundles(String bundlesToStart) throws Exception {
+               if (bundlesToStart == null)
+                       return;
+
+               StringTokenizer st = new StringTokenizer(bundlesToStart, ",");
+               Map<String, Bundle> bundles = getBundles();
+               while (st.hasMoreTokens()) {
+                       String name = st.nextToken().trim();
+                       Bundle bundle = bundles.get(name);
+                       if (bundle != null)
+                               try {
+                                       bundle.start();
+                               } catch (Exception e) {
+                                       warn("Bundle " + name + " cannot be started: "
+                                                       + e.getMessage());
+                               }
+                       else
+                               warn("Bundle " + name + " not installed.");
+
+               }
+       }
+
+       /** Key is location */
+       public Map<String, Bundle> getInstalledBundles() {
+               Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
+
+               for (Bundle bundle : bundleContext.getBundles()) {
+                       installedBundles.put(bundle.getLocation(), bundle);
+               }
+               return installedBundles;
+       }
+
+       /** Key is symbolic name */
+       public Map<String, Bundle> getBundles() {
+               Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
+               for (Bundle bundle : bundleContext.getBundles())
+                       installedBundles.put(bundle.getSymbolicName(), bundle);
+               return installedBundles;
+       }
+
+       public List<String> getLocationsUrls() {
+               String baseUrl = getProperty(PROP_SLC_OSGI_BASE_URL, DEFAULT_BASE_URL);
+               String bundleLocations = getProperty(PROP_SLC_OSGI_LOCATIONS);
+               return getLocationsUrls(baseUrl, bundleLocations);
+       }
+
+       public List<String> getLocationsUrls(String baseUrl, String bundleLocations) {
+               List<String> urls = new ArrayList<String>();
+
+               if (bundleLocations == null)
+                       return urls;
+               bundleLocations = SystemPropertyUtils
+                               .resolvePlaceholders(bundleLocations);
+
+               StringTokenizer st = new StringTokenizer(bundleLocations,
+                               File.pathSeparator);
+               while (st.hasMoreTokens()) {
+                       urls.add(baseUrl + st.nextToken().trim());
+               }
+               return urls;
+       }
+
+       public List<String> getBundlesUrls() {
+               String baseUrl = getProperty(PROP_SLC_OSGI_BASE_URL, DEFAULT_BASE_URL);
+               String bundlePatterns = getProperty(PROP_SLC_OSGI_BUNDLES);
+               return getBundlesUrls(baseUrl, bundlePatterns);
+       }
+
+       public List<String> getBundlesUrls(String baseUrl, String bundlePatterns) {
+               List<String> urls = new ArrayList<String>();
+
+               List<BundlesSet> bundlesSets = new ArrayList<BundlesSet>();
+               if (bundlePatterns == null)
+                       return urls;
+               // TODO: resolve placeholders
+               info(PROP_SLC_OSGI_BUNDLES + "=" + bundlePatterns);
+
+               StringTokenizer st = new StringTokenizer(bundlePatterns, ",");
+               while (st.hasMoreTokens()) {
+                       bundlesSets.add(new BundlesSet(st.nextToken()));
+               }
+
+               List<String> included = new ArrayList<String>();
+               PathMatcher matcher = new AntPathMatcher();
+               for (BundlesSet bundlesSet : bundlesSets)
+                       for (String pattern : bundlesSet.getIncludes())
+                               match(matcher, included, bundlesSet.getDir(), null, pattern);
+
+               List<String> excluded = new ArrayList<String>();
+               for (BundlesSet bundlesSet : bundlesSets)
+                       for (String pattern : bundlesSet.getExcludes())
+                               match(matcher, excluded, bundlesSet.getDir(), null, pattern);
+
+               for (String fullPath : included) {
+                       if (!excluded.contains(fullPath))
+                               urls.add(baseUrl + fullPath);
+               }
+
+               return urls;
+       }
+
+       protected void match(PathMatcher matcher, List<String> matched,
+                       String base, String currentPath, String pattern) {
+               if (currentPath == null) {
+                       // Init
+                       File baseDir = new File(base.replace('/', File.separatorChar));
+                       File[] files = baseDir.listFiles();
+
+                       if (files == null) {
+                               warn("Base dir " + baseDir + " has no children, exists="
+                                               + baseDir.exists() + ", isDirectory="
+                                               + baseDir.isDirectory());
+                               return;
+                       }
+
+                       for (File file : files)
+                               match(matcher, matched, base, file.getName(), pattern);
+               } else {
+                       String fullPath = base + '/' + currentPath;
+                       if (matched.contains(fullPath))
+                               return;// don't try deeper if already matched
+
+                       boolean ok = matcher.match(pattern, currentPath);
+                       if (debug)
+                               debug(currentPath + " " + (ok ? "" : " not ")
+                                               + " matched with " + pattern);
+                       if (ok) {
+                               matched.add(fullPath);
+                               return;
+                       } else {
+                               String newFullPath = (base + '/' + currentPath).replace('/',
+                                               File.separatorChar);
+                               File[] files = new File(newFullPath).listFiles();
+                               if (files != null) {
+                                       for (File file : files)
+                                               if (file.isDirectory()) {
+                                                       String newCurrentPath = currentPath + '/'
+                                                                       + file.getName();
+                                                       if (matcher.matchStart(pattern, newCurrentPath)) {
+                                                               // recurse only if start matches
+                                                               match(matcher, matched, base, newCurrentPath,
+                                                                               pattern);
+                                                       } else {
+                                                               if (debug)
+                                                                       debug(newCurrentPath
+                                                                                       + " does not start match with "
+                                                                                       + pattern);
+
+                                                       }
+                                               }
+                               } else {
+                                       warn("Not a directory: " + newFullPath);
+                               }
+                       }
+               }
+       }
+
+       protected void info(Object obj) {
+               System.out.println("# INFO " + obj);
+       }
+
+       protected void debug(Object obj) {
+               if (debug)
+                       System.out.println("# DBUG " + obj);
+       }
+
+       protected void warn(Object obj) {
+               System.out.println("# WARN " + obj);
+               // Because of a weird bug under Windows when starting it in a forked VM
+               // if (System.getProperty("os.name").contains("Windows"))
+               // System.out.println("# WARN " + obj);
+               // else
+               // System.err.println("# WARN " + obj);
+       }
+
+       protected String getProperty(String name, String defaultValue) {
+               final String value;
+               if (defaultValue != null)
+                       value = System.getProperty(name, defaultValue);
+               else
+                       value = System.getProperty(name);
+
+               if (value == null || value.equals(""))
+                       return null;
+               else
+                       return value;
+       }
+
+       protected String getProperty(String name) {
+               return getProperty(name, null);
+       }
+
+       public Boolean getDebug() {
+               return debug;
+       }
+
+       public void setDebug(Boolean debug) {
+               this.debug = debug;
+       }
+
+       public BundleContext getBundleContext() {
+               return bundleContext;
+       }
+
+       private class BundlesSet {
+               private String baseUrl = "reference:file";// not used yet
+               private final String dir;
+               private List<String> includes = new ArrayList<String>();
+               private List<String> excludes = new ArrayList<String>();
+
+               public BundlesSet(String def) {
+                       StringTokenizer st = new StringTokenizer(def, ";");
+
+                       if (!st.hasMoreTokens())
+                               throw new RuntimeException("Base dir not defined.");
+                       try {
+                               String dirPath = st.nextToken();
+                               dir = new File(dirPath.replace('/', File.separatorChar))
+                                               .getCanonicalPath();
+                               if (debug)
+                                       debug("Base dir: " + dir);
+                       } catch (IOException e) {
+                               throw new RuntimeException("Cannot convert to absolute path", e);
+                       }
+
+                       while (st.hasMoreTokens()) {
+                               String tk = st.nextToken();
+                               StringTokenizer stEq = new StringTokenizer(tk, "=");
+                               String type = stEq.nextToken();
+                               String pattern = stEq.nextToken();
+                               if ("in".equals(type) || "include".equals(type)) {
+                                       includes.add(pattern);
+                               } else if ("ex".equals(type) || "exclude".equals(type)) {
+                                       excludes.add(pattern);
+                               } else if ("baseUrl".equals(type)) {
+                                       baseUrl = pattern;
+                               } else {
+                                       System.err.println("Unkown bundles pattern type " + type);
+                               }
+                       }
+               }
+
+               public String getDir() {
+                       return dir;
+               }
+
+               public List<String> getIncludes() {
+                       return includes;
+               }
+
+               public List<String> getExcludes() {
+                       return excludes;
+               }
+
+               public String getBaseUrl() {
+                       return baseUrl;
+               }
+
+       }
+
+}
diff --git a/runtime/org.argeo.slc.osgiboot/src/test/bundles/others/subdir/org.argeo.slc.osgiboot.test.bundle3/META-INF/MANIFEST.MF b/runtime/org.argeo.slc.osgiboot/src/test/bundles/others/subdir/org.argeo.slc.osgiboot.test.bundle3/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..3019742
--- /dev/null
@@ -0,0 +1,2 @@
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle3
+Bundle-Version: 0.1.0
diff --git a/runtime/org.argeo.slc.osgiboot/src/test/bundles/some/excluded/org.argeo.slc.osgiboot.test.bundle0/META-INF/MANIFEST.MF b/runtime/org.argeo.slc.osgiboot/src/test/bundles/some/excluded/org.argeo.slc.osgiboot.test.bundle0/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..5216c27
--- /dev/null
@@ -0,0 +1,2 @@
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle0
+Bundle-Version: 0.1.0
diff --git a/runtime/org.argeo.slc.osgiboot/src/test/bundles/some/org.argeo.slc.osgiboot.test.bundle1/META-INF/MANIFEST.MF b/runtime/org.argeo.slc.osgiboot/src/test/bundles/some/org.argeo.slc.osgiboot.test.bundle1/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..2c6c008
--- /dev/null
@@ -0,0 +1,2 @@
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle1
+Bundle-Version: 0.1.0
diff --git a/runtime/org.argeo.slc.osgiboot/src/test/bundles/some/org.argeo.slc.osgiboot.test.bundle2/META-INF/MANIFEST.MF b/runtime/org.argeo.slc.osgiboot/src/test/bundles/some/org.argeo.slc.osgiboot.test.bundle2/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..2ab6328
--- /dev/null
@@ -0,0 +1,2 @@
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle2
+Bundle-Version: 0.1.0
diff --git a/runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootNoRuntimeTest.java b/runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootNoRuntimeTest.java
new file mode 100644 (file)
index 0000000..aab5799
--- /dev/null
@@ -0,0 +1,35 @@
+package org.argeo.slc.osgiboot;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.argeo.slc.osgiboot.OsgiBoot;
+
+public class OsgiBootNoRuntimeTest extends TestCase {
+       public final static String BUNDLES = "src/test/bundles/some;in=*;ex=excluded,"
+                       + "src/test/bundles/others;in=**/org.argeo.*";
+
+       public void testLocations() {
+               String baseUrl = "file:";
+               String locations = "/mydir/myfile" + File.pathSeparator
+                               + "/myotherdir/myotherfile";
+
+               OsgiBoot osgiBoot = new OsgiBoot(null);
+               List urls = osgiBoot.getLocationsUrls(baseUrl, locations);
+               assertEquals(2, urls.size());
+               assertEquals("file:/mydir/myfile", urls.get(0));
+               assertEquals("file:/myotherdir/myotherfile", urls.get(1));
+       }
+
+       public void testBundles() {
+               String baseUrl = "file:";
+               String bundles = BUNDLES;
+               OsgiBoot osgiBoot = new OsgiBoot(null);
+               List urls = osgiBoot.getBundlesUrls(baseUrl, bundles);
+               for (int i = 0; i < urls.size(); i++)
+                       System.out.println(urls.get(i));
+               assertEquals(3, urls.size());
+       }
+}
diff --git a/runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java b/runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java
new file mode 100644 (file)
index 0000000..401441c
--- /dev/null
@@ -0,0 +1,66 @@
+package org.argeo.slc.osgiboot;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+public class OsgiBootRuntimeTest extends TestCase {
+       protected OsgiBoot osgiBoot = null;
+
+       public void testInstallAndStart() throws Exception {
+               osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
+                               OsgiBootNoRuntimeTest.BUNDLES));
+               Map map = new TreeMap(osgiBoot.getBundles());
+               for (Iterator keys = map.keySet().iterator(); keys.hasNext();) {
+                       Object key = keys.next();
+                       Bundle bundle = (Bundle) map.get(key);
+                       System.out.println(key + " : " + bundle.getLocation());
+               }
+               assertEquals(4, map.size());
+               Iterator keys = map.keySet().iterator();
+               assertEquals("org.argeo.slc.osgiboot.test.bundle1", keys.next());
+               assertEquals("org.argeo.slc.osgiboot.test.bundle2", keys.next());
+               assertEquals("org.argeo.slc.osgiboot.test.bundle3", keys.next());
+               assertEquals("org.eclipse.osgi", keys.next());
+
+               osgiBoot.startBundles("org.argeo.slc.osgiboot.test.bundle2");
+               long begin = System.currentTimeMillis();
+               while (System.currentTimeMillis() - begin < 10000) {
+                       Map mapBundles = osgiBoot.getBundles();
+                       Bundle bundle = (Bundle) mapBundles
+                                       .get("org.argeo.slc.osgiboot.test.bundle2");
+                       if (bundle.getState() == Bundle.ACTIVE) {
+                               System.out.println("Bundle " + bundle + " started.");
+                               return;
+                       }
+               }
+               fail("Bundle not started after timeout limit.");
+       }
+
+       protected BundleContext startRuntime() throws Exception {
+               String[] args = { "-console" };
+               BundleContext bundleContext = EclipseStarter.startup(args, null);
+               return bundleContext;
+       }
+
+       protected void stopRuntime() throws Exception {
+               EclipseStarter.shutdown();
+       }
+
+       public void setUp() throws Exception{
+               BundleContext bundleContext = startRuntime();
+               osgiBoot = new OsgiBoot(bundleContext);
+       }
+       
+       public void tearDown() throws Exception{
+               osgiBoot = null;
+               stopRuntime();
+       }
+
+}
index 30baf1326015b0e1e881c9009d643374adafa6e4..6e4caca3156f509f886f3a7898b472dc7b25f158 100644 (file)
@@ -2,6 +2,7 @@
 <classpath>
        <classpathentry kind="src" output="target/classes" path="src/main/java"/>
        <classpathentry kind="src" path="src/main/resources"/>
+       <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
        <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
        <classpathentry kind="output" path="target/classes"/>
index 3677085d69b4d6c746849bb200afac9a28c0cad3..bc01f07059bd5991fc9aac3695652b395ccea94b 100644 (file)
        <build>
                <plugins>
                        <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-jar-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>test-jar</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.felix</groupId>
@@ -46,7 +54,7 @@
                        <groupId>org.springframework.osgi</groupId>
                        <artifactId>org.springframework.osgi.core</artifactId>
                </dependency>
-
+               
                <dependency>
                        <groupId>org.eclipse.osgi</groupId>
                        <artifactId>org.eclipse.osgi</artifactId>
                        <groupId>org.objectweb.asm</groupId>
                        <artifactId>com.springsource.org.objectweb.asm.attrs</artifactId>
                </dependency>
+               
+               <!-- TEST -->
+               <dependency>
+                       <groupId>org.springframework.osgi</groupId>
+                       <artifactId>org.springframework.osgi.test</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.argeo.slc.runtime</groupId>
+                       <artifactId>org.argeo.slc.osgiboot</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               
        </dependencies>
 </project>
diff --git a/runtime/org.argeo.slc.support.equinox/src/test/bundles/org.argeo.slc.support.osgi.test.hello/META-INF/MANIFEST.MF b/runtime/org.argeo.slc.support.equinox/src/test/bundles/org.argeo.slc.support.osgi.test.hello/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..5945393
--- /dev/null
@@ -0,0 +1,2 @@
+Bundle-SymbolicName: org.argeo.slc.support.osgi.test.hello
+Bundle-Version: 0.1.0
diff --git a/runtime/org.argeo.slc.support.equinox/src/test/bundles/org.argeo.slc.support.osgi.test.hello/META-INF/spring/hello.xml b/runtime/org.argeo.slc.support.equinox/src/test/bundles/org.argeo.slc.support.osgi.test.hello/META-INF/spring/hello.xml
new file mode 100644 (file)
index 0000000..1f0f892
--- /dev/null
@@ -0,0 +1,21 @@
+<?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:p="http://www.springframework.org/schema/p"
+       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/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+       <import resource="classpath:org/argeo/slc/core/execution/spring.xml" />
+
+       <bean id="main" parent="slcTemplate.simpleFlow" init-method="run">
+               <property name="executables">
+                       <list>
+                               <bean parent="task.echo">
+                                       <property name="message" value="Hello world!" />
+                               </bean>
+                       </list>
+               </property>
+       </bean>
+</beans>
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTest.java b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTest.java
new file mode 100644 (file)
index 0000000..5dc773a
--- /dev/null
@@ -0,0 +1,60 @@
+package org.argeo.slc.osgi.test;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.osgiboot.OsgiBoot;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.test.platform.EquinoxPlatform;
+import org.springframework.osgi.test.platform.OsgiPlatform;
+import org.springframework.osgi.util.OsgiStringUtils;
+
+public abstract class AbstractOsgiRuntimeTest extends TestCase {
+       private final static Log log = LogFactory
+                       .getLog(AbstractOsgiRuntimeTest.class);
+
+       protected OsgiBoot osgiBoot = null;
+       protected OsgiPlatform osgiPlatform = null;
+
+       protected OsgiPlatform createOsgiPlatform() {
+               return new EquinoxPlatform();
+       }
+
+       protected void postStart() throws Exception {
+
+       }
+
+       public void setUp() throws Exception {
+               // To avoid xerces from the classpath being detected as the provider
+               System
+                               .setProperty("javax.xml.parsers.DocumentBuilderFactory",
+                                               "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
+               System.setProperty("javax.xml.parsers.SAXParserFactory",
+                               "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
+
+               osgiPlatform = createOsgiPlatform();
+               osgiPlatform.start();
+               osgiBoot = new OsgiBoot(osgiPlatform.getBundleContext());
+               log.info("OSGi platform " + osgiPlatform + " started.");
+               postStart();
+       }
+
+       public void tearDown() throws Exception {
+               osgiBoot = null;
+               osgiPlatform.stop();
+               osgiPlatform = null;
+               log.info("OSGi platform " + osgiPlatform + " stopped.");
+       }
+
+       protected void listInstalledBundles() {
+               BundleContext bundleContext = osgiPlatform.getBundleContext();
+               Bundle[] bundles = bundleContext.getBundles();
+               for (int i = 0; i < bundles.length; i++) {
+                       System.out
+                                       .println(OsgiStringUtils.nullSafeSymbolicName(bundles[i]));
+               }
+
+       }
+}
diff --git a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java
new file mode 100644 (file)
index 0000000..668cc1d
--- /dev/null
@@ -0,0 +1,23 @@
+package org.argeo.slc.osgi.test;
+
+import org.argeo.slc.osgiboot.OsgiBoot;
+
+public class HelloTest extends AbstractOsgiRuntimeTest {
+       public void testHello() throws Exception {
+               Thread.sleep(5000);
+       }
+
+       protected void postStart() throws Exception {
+               osgiBoot.installUrls(osgiBoot.getLocationsUrls(
+                               OsgiBoot.DEFAULT_BASE_URL, System
+                                               .getProperty("java.class.path")));
+               osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
+                               "src/test/bundles;in=*"));
+
+               listInstalledBundles();
+               String bundlesToStart = "org.springframework.osgi.extender,org.argeo.slc.support.osgi.test.hello";
+               osgiBoot.startBundles(bundlesToStart);
+
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java
new file mode 100644 (file)
index 0000000..2748e84
--- /dev/null
@@ -0,0 +1,18 @@
+package org.argeo.slc.osgi.test;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+public class PlatformStartStopTest extends AbstractOsgiRuntimeTest {
+
+       public void testStartStop() {
+               BundleContext bundleContext = osgiPlatform.getBundleContext();
+               System.out.println(bundleContext
+                               .getProperty(Constants.FRAMEWORK_VENDOR));
+               System.out.println(bundleContext
+                               .getProperty(Constants.FRAMEWORK_VERSION));
+               System.out.println(bundleContext
+                               .getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT));
+
+       }
+}