--- /dev/null
+#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
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
--- /dev/null
+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;
+ }
+
+ };
+ }
+
+}
<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>
<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>
<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>
<?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"/>
<artifactId>org.eclipse.osgi</artifactId>
</dependency>
+ <!-- TEST -->
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>com.springsource.junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+
+
</project>
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) {
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/";
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>();
component.setScope(st.nextToken());
return component;
}
-
+*//*
protected static String getProperty(String name, String defaultValue) {
final String value;
if (defaultValue != null)
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);
// else
// System.err.println("# WARN " + obj);
}
-
+*//*
static class MavenFile {
private String groupId;
private String artifactId;
}
}
-
+*/
}
--- /dev/null
+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;
+ }
+
+ }
+
+}
--- /dev/null
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle3
+Bundle-Version: 0.1.0
--- /dev/null
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle0
+Bundle-Version: 0.1.0
--- /dev/null
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle1
+Bundle-Version: 0.1.0
--- /dev/null
+Bundle-SymbolicName: org.argeo.slc.osgiboot.test.bundle2
+Bundle-Version: 0.1.0
--- /dev/null
+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());
+ }
+}
--- /dev/null
+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();
+ }
+
+}
<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"/>
<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>
<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>
--- /dev/null
+Bundle-SymbolicName: org.argeo.slc.support.osgi.test.hello
+Bundle-Version: 0.1.0
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns: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
--- /dev/null
+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]));
+ }
+
+ }
+}
--- /dev/null
+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);
+
+ }
+
+}
--- /dev/null
+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));
+
+ }
+}