+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="src" output="target/classes" path="src/main/resources"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.slc.detached.launcher</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-#Mon Nov 17 14:48:56 CET 2008
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
-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=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+++ /dev/null
-#Wed Sep 24 16:04:14 CEST 2008
-activeProfiles=
-eclipse.preferences.version=1
-filterResources=false
-includeModules=false
-resolveWorkspaceProjects=true
-resourceFilterGoals=process-resources resources\:testResources
-useMavenFolders=false
-version=1
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.argeo.slc</groupId>
- <artifactId>argeo-slc</artifactId>
- <version>0.11.3-SNAPSHOT</version>
- <relativePath>../org.argeo.slc</relativePath>
- </parent>
- <artifactId>org.argeo.slc.detached.launcher</artifactId>
- <name>Argeo SLC Detached Launcher</name>
- <packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.4</source>
- <target>1.4</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>
- org.argeo.slc.detached.launcher.Main
- </mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${version.maven-bundle-plugin}</version>
- <configuration>
- <instructions>
- <Export-Package>
- org.argeo.slc.*
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptors>
- <descriptor>src/assembly/dist.xml</descriptor>
- </descriptors>
- </configuration>
- <executions>
- <execution>
- <id>attach-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <!--
- <dependency> <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.main</artifactId> </dependency>
- -->
- <dependency>
- <groupId>org.eclipse.osgi</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- </dependency>
-<!--
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.extender</artifactId>
- </dependency>
- -->
-
- <!--
- Old <dependency> <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId> <version>2.0.8</version>
- </dependency> <dependency> <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId> </dependency> <dependency>
- <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency>
- <dependency> <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId> </dependency>
- -->
-
- <!--
- <dependency> <groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.detached.ext.log4j</artifactId>
- <version>0.11.2</version> </dependency>
- -->
- <!-- Spring
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.context</artifactId>
- </dependency>
- -->
- <!--
- <dependency> <groupId>org.apache.xerces</groupId>
- <artifactId>com.springsource.org.apache.xerces</artifactId>
- </dependency> <dependency> <groupId>org.apache.xalan</groupId>
- <artifactId>com.springsource.org.apache.xalan</artifactId>
- </dependency> <dependency>
- <groupId>edu.emory.mathcs.backport</groupId> <artifactId>
- com.springsource.edu.emory.mathcs.backport </artifactId>
- </dependency>
- -->
- <!--
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>
- com.springsource.org.apache.commons.io
- </artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit</groupId>
- <artifactId>com.springsource.junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.log4j</groupId>
- <artifactId>com.springsource.org.apache.log4j</artifactId>
- </dependency> -->
- <!--
- <dependency> <groupId>org.slf4j</groupId>
- <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
- </dependency> <dependency> <groupId>org.slf4j</groupId>
- <artifactId>com.springsource.slf4j.jcl</artifactId> </dependency>
- -->
- </dependencies>
-</project>
\ No newline at end of file
+++ /dev/null
-<assembly xmlns="http://maven.apache.org/POM/4.0.0"\r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">\r
- <id>dist</id>\r
- <includeBaseDirectory>false</includeBaseDirectory>\r
- <formats>\r
- <format>tar.gz</format>\r
- </formats>\r
- <fileSets>\r
- <fileSet>\r
- <directory>src/main/base</directory>\r
- <outputDirectory></outputDirectory>\r
- <fileMode>0755</fileMode>\r
- </fileSet>\r
- </fileSets>\r
-</assembly>
\ No newline at end of file
+++ /dev/null
-@echo off\r
-\r
-rem Target application\r
-set JAVA_HOME=[the target JRE]\r
-set SLC_USER_CLASSPATH=[classpath of the application to test]\r
-set SLC_DETACHED_APPCLASS=[main class of the application to test]\r
-set SLC_DETACHED_APPARGS=[arguments of the application to test]\r
-set SLC_DETACHED_JVM_ARGS=[additional JVM arguments]\r
-\r
-rem Runtime\r
-set PROJECT_BASE=[base of the project to being developed]\r
-set SLC_WORK_DIR=%PROJECT_BASE%/src/main/slc/work\r
-set SLC_USER_BUNDLES=reference:file:%PROJECT_BASE%/target/classes\r
-\r
+++ /dev/null
-@echo off
-echo SLC Detached
-set SLC_HOME=%~dp0..
-echo SLC_HOME=%SLC_HOME%
-set SLC_LIB_DETACHED=%SLC_HOME%\lib\detached
-
-call slc-detached-settings.bat
-
-rem FOR %%f IN (%SLC_HOME%\lib\detached\*.jar) DO set CLASSPATH=%CLASSPATH%;%%f
-FOR %%f IN (%SLC_HOME%\lib\detached\org.argeo.slc.detached.launcher-*.jar) DO set SLC_DETACHED_LAUNCHER_JAR=%%f
-FOR %%f IN (%SLC_HOME%\lib\org.argeo.slc.detached-*.jar) DO set SLC_DETACHED_JAR=%%f
-
-set CLASSPATH=%SLC_DETACHED_LAUNCHER_JAR%;%SLC_USER_CLASSPATH%;%SLC_LIB_DETACHED%\com.springsource.org.aopalliance-1.0.0.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.commons.io-1.4.0.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.commons.logging-1.1.1.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.log4j-1.2.15.jar;%SLC_LIB_DETACHED%\org.apache.felix.main-1.2.1.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.xerces-2.8.1.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.xalan-2.7.0.jar
-
-set CMD=%JAVA_HOME%\bin\java %SLC_DETACHED_JVM_ARGS% -Dslc.detached.jar=%SLC_DETACHED_JAR% -Dslc.home=%SLC_HOME% -Dslc.workDir=%SLC_WORK_DIR% "-Dslc.detached.userBundles=%SLC_USER_BUNDLES%" -Dslc.detached.appclass=%SLC_DETACHED_APPCLASS% "-Dslc.detached.appargs=%SLC_DETACHED_APPARGS%" -classpath %CLASSPATH% org.argeo.slc.detached.launcher.Main
-rem echo CMD=%CMD%
-
-start %CMD%
-
+++ /dev/null
-package org.argeo.slc.detached.launcher;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import org.eclipse.core.runtime.adaptor.EclipseStarter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-
-public class Main {
- public final static String PROP_SLC_HOME = "slc.home";
- public final static String PROP_SLC_OSGI_START = "slc.osgi.start";
- public final static String PROP_SLC_OSGI_SCAN_CLASSPATH = "slc.osgi.scanClasspath";
- public final static String PROP_SLC_OSGI_EQUINOX_ARGS = "slc.osgi.equinox.args";
-
- private final static String DEV_BUNDLE_PREFIX = "slc.osgi.devbundle.";
-
- public static void main(String[] args) {
- info("Argeo SLC Detached launcher starting...");
- try {
- // Load properties
- String propertyPath = "slc-detached.properties";
- Properties config = prepareConfig(propertyPath);
-
- // Start app (in main class loader)
- startApp(config);
-
- // Start OSGi framework
- try {
- startEquinox(config);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- info("Argeo SLC Detached launcher started.");
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(-1);
- }
- }
-
- protected static Properties prepareConfig(String propertyFilePath)
- throws Exception {
- // Format slc.home
- String slcHome = System.getProperty(PROP_SLC_HOME);
- if (slcHome != null) {
- slcHome = new File(slcHome).getCanonicalPath();
- System.setProperty(PROP_SLC_HOME, slcHome);
- }
-
- // Load config
- Properties config = new Properties();
- InputStream in = null;
- try {
- File file = new File(propertyFilePath);
- if (file.exists()) {
- in = new FileInputStream(propertyFilePath);
- config.load(in);
- }
- } finally {
- if (in != null)
- in.close();
- }
-
- // System properties have priority.
- config.putAll(System.getProperties());
- return config;
- }
-
- public static void startEquinox(Properties config) throws Exception {
- info("java.home=" + System.getProperty("java.home"));
- info("java.class.path=" + System.getProperty("java.class.path"));
-
- File baseDir = new File(System.getProperty("user.dir"))
- .getCanonicalFile();
- String equinoxConfigurationPath = baseDir.getPath() + File.separator
- + "slc-detached" + File.separator + "equinoxConfiguration";
-
- String equinoxArgsLineDefault = "-console -noExit -clean -debug -configuration "
- + equinoxConfigurationPath;
- String equinoxArgsLine = config.getProperty(PROP_SLC_OSGI_EQUINOX_ARGS,
- equinoxArgsLineDefault);
- // String[] equinoxArgs = { "-console", "-noExit", "-clean", "-debug",
- // "-configuration", equinoxConfigurationPath };
- String[] equinoxArgs = equinoxArgsLine.split(" ");
-
- BundleContext context = EclipseStarter.startup(equinoxArgs, null);
-
- List installBundleNames = new ArrayList();
-
- // Load from class path (dev environment, maven)
- if (config.getProperty(PROP_SLC_OSGI_SCAN_CLASSPATH, "false").equals(
- "true")) {
- StringTokenizer st = new StringTokenizer(System
- .getProperty("java.class.path"), File.pathSeparator);
- while (st.hasMoreTokens()) {
- try {
- String path = st.nextToken();
- String url = "reference:file:"
- + new File(path).getCanonicalPath();
- Bundle bundle = context.installBundle(url);
- if (bundle.getSymbolicName() != null)
- installBundleNames.add(bundle.getSymbolicName());
- info("Installed from classpath " + url);
- } catch (Exception e) {
- bundleInstallWarn(e.getMessage());
- }
- }
- }
-
- // Load from dev bundles
- Map devBundleUrls = getDevBundleUrls(config);
- Iterator devBundles = devBundleUrls.keySet().iterator();
- while (devBundles.hasNext()) {
- try {
- String bundleName = (String) devBundles.next();
- String url = (String) devBundleUrls.get(bundleName);
- Bundle bundle = context.installBundle(url);
- installBundleNames.add(bundle.getSymbolicName());
- info("Installed as dev bundle " + url);
- } catch (Exception e) {
- bundleInstallWarn(e.getMessage());
- }
- }
-
- // Load from distribution
- String slcHome = config.getProperty(PROP_SLC_HOME);
- if (slcHome != null) {
- File libDir = new File(slcHome + File.separator + "lib");
- File[] bundleFiles = libDir.listFiles();
- for (int i = 0; i < bundleFiles.length; i++) {
- try {
- String url = "reference:file:"
- + bundleFiles[i].getCanonicalPath();
- Bundle bundle = context.installBundle(url);
- installBundleNames.add(bundle.getSymbolicName());
- info("INFO: Installed from SLC home " + url);
- } catch (Exception e) {
- bundleInstallWarn(e.getMessage());
- }
-
- }
- }
-
- // Start bundles
- String bundleStart = config.getProperty(PROP_SLC_OSGI_START,
- "org.springframework.osgi.extender,org.argeo.slc.detached");
-
- if (bundleStart.trim().equals("*")) {
- for (int i = 0; i < installBundleNames.size(); i++) {
- Object obj = installBundleNames.get(i);
- if (obj != null) {
- String bundleSymbolicName = obj.toString();
- try {
- startBundle(context, bundleSymbolicName);
- } catch (Exception e) {
- bundleInstallWarn("Cannot start " + bundleSymbolicName
- + ": " + e.getMessage());
- }
- }
- }
- } else {
- StringTokenizer stBundleStart = new StringTokenizer(bundleStart,
- ",");
- while (stBundleStart.hasMoreTokens()) {
- String bundleSymbolicName = stBundleStart.nextToken();
- startBundle(context, bundleSymbolicName);
- }
- }
- }
-
- private static Map getDevBundleUrls(Properties config) {
- Map bundles = new Hashtable();
- Iterator keys = config.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- if (key.startsWith(DEV_BUNDLE_PREFIX)) {
- String bundle = key.substring(DEV_BUNDLE_PREFIX.length());
- String path = config.getProperty(key);
- bundles.put(bundle, path);
- }
- }
- return bundles;
- }
-
- private static void startBundle(BundleContext bundleContext,
- String symbolicName) throws BundleException {
- //info("Starting bundle " + symbolicName + "...");
- Bundle bundle = findBundleBySymbolicName(bundleContext, symbolicName);
- if (bundle != null)
- bundle.start();
- else
- throw new RuntimeException("Bundle " + symbolicName + " not found");
- info("Started " + symbolicName);
- }
-
- /** WARNING: return the first one found! */
- private static Bundle findBundleBySymbolicName(BundleContext bundleContext,
- String symbolicName) {
- Bundle[] bundles = bundleContext.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- Bundle bundle = bundles[i];
- String bundleSymbolicName = bundle.getSymbolicName();
- if (bundleSymbolicName != null) {
- // throw new RuntimeException("Bundle " + bundle.getBundleId()
- // + " (" + bundle.getLocation()
- // + ") has no symbolic name.");
-
- if (bundleSymbolicName.equals(symbolicName)) {
- return bundle;
- }
- }
- }
- return null;
- }
-
- public static void startApp(Properties config) throws Exception {
- String className = config.getProperty("slc.detached.appclass");
- String[] uiArgs = readArgumentsFromLine(config.getProperty(
- "slc.detached.appargs", ""));
-
- if (className == null) {
- info("No slc.detached.appclass property define: does not try to launch an app from the standard classpath.");
- } else {
- // Launch main method using reflection
- Class clss = Class.forName(className);
- Class[] mainArgsClasses = new Class[] { uiArgs.getClass() };
- Object[] mainArgs = { uiArgs };
- Method mainMethod = clss.getMethod("main", mainArgsClasses);
- mainMethod.invoke(null, mainArgs);
- }
- }
-
- /* UTILITIES */
-
- /**
- * Transform a line into an array of arguments, taking "" as single
- * arguments. (nested \" are not supported)
- */
- private static String[] readArgumentsFromLine(String lineOrig) {
-
- String line = lineOrig.trim();// remove trailing spaces
- // System.out.println("line=" + line);
- List args = new Vector();
- StringBuffer curr = new StringBuffer("");
- boolean inQuote = false;
- char[] arr = line.toCharArray();
- for (int i = 0; i < arr.length; i++) {
- char c = arr[i];
- switch (c) {
- case '\"':
- inQuote = !inQuote;
- break;
- case ' ':
- if (!inQuote) {// otherwise, no break: goes to default
- if (curr.length() > 0) {
- args.add(curr.toString());
- curr = new StringBuffer("");
- }
- break;
- }
- default:
- curr.append(c);
- break;
- }
- }
-
- // Add last arg
- if (curr.length() > 0) {
- args.add(curr.toString());
- curr = null;
- }
-
- String[] res = new String[args.size()];
- for (int i = 0; i < args.size(); i++) {
- res[i] = args.get(i).toString();
- // System.out.println("res[i]=" + res[i]);
- }
- return res;
- }
-
- private static void info(Object obj) {
- System.out.println("[INFO] " + obj);
- }
-
- private static void bundleInstallWarn(Object obj) {
- System.err.println("[WARN] " + obj);
- //Thread.dumpStack();
- }
-}
+++ /dev/null
-# Set root logger level to DEBUG and its only appender to A1.\r
-log4j.rootLogger=WARN, console\r
-\r
-## Levels\r
-# Slc\r
-log4j.logger.org.argeo.slc=DEBUG\r
-log4j.logger.org.springframework=WARN\r
-\r
-## Appenders\r
-# A1 is set to be a ConsoleAppender.\r
-log4j.appender.console=org.apache.log4j.ConsoleAppender\r
-\r
-# A1 uses PatternLayout.\r
-log4j.appender.console.layout=org.apache.log4j.PatternLayout\r
-log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - %c %n\r
-\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.slc.detached.launcher</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Mon Nov 17 14:48:56 CET 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+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=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
--- /dev/null
+#Wed Sep 24 16:04:14 CEST 2008
+activeProfiles=
+eclipse.preferences.version=1
+filterResources=false
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+useMavenFolders=false
+version=1
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.slc</groupId>
+ <artifactId>argeo-slc</artifactId>
+ <version>0.11.3-SNAPSHOT</version>
+ <relativePath>../org.argeo.slc</relativePath>
+ </parent>
+ <artifactId>org.argeo.slc.detached.launcher</artifactId>
+ <name>Argeo SLC Detached Launcher</name>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>
+ org.argeo.slc.detached.launcher.Main
+ </mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${version.maven-bundle-plugin}</version>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.argeo.slc.*
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/dist.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!--
+ <dependency> <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.main</artifactId> </dependency>
+ -->
+ <dependency>
+ <groupId>org.eclipse.osgi</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>org.springframework.osgi.extender</artifactId>
+ </dependency>
+ -->
+
+ <!--
+ Old <dependency> <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId> <version>2.0.8</version>
+ </dependency> <dependency> <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId> </dependency> <dependency>
+ <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency>
+ <dependency> <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId> </dependency>
+ -->
+
+ <!--
+ <dependency> <groupId>org.argeo.slc</groupId>
+ <artifactId>org.argeo.slc.detached.ext.log4j</artifactId>
+ <version>0.11.2</version> </dependency>
+ -->
+ <!-- Spring
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.context</artifactId>
+ </dependency>
+ -->
+ <!--
+ <dependency> <groupId>org.apache.xerces</groupId>
+ <artifactId>com.springsource.org.apache.xerces</artifactId>
+ </dependency> <dependency> <groupId>org.apache.xalan</groupId>
+ <artifactId>com.springsource.org.apache.xalan</artifactId>
+ </dependency> <dependency>
+ <groupId>edu.emory.mathcs.backport</groupId> <artifactId>
+ com.springsource.edu.emory.mathcs.backport </artifactId>
+ </dependency>
+ -->
+ <!--
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>
+ com.springsource.org.apache.commons.io
+ </artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>com.springsource.junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.log4j</groupId>
+ <artifactId>com.springsource.org.apache.log4j</artifactId>
+ </dependency> -->
+ <!--
+ <dependency> <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+ </dependency> <dependency> <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.jcl</artifactId> </dependency>
+ -->
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+<assembly xmlns="http://maven.apache.org/POM/4.0.0"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">\r
+ <id>dist</id>\r
+ <includeBaseDirectory>false</includeBaseDirectory>\r
+ <formats>\r
+ <format>tar.gz</format>\r
+ </formats>\r
+ <fileSets>\r
+ <fileSet>\r
+ <directory>src/main/base</directory>\r
+ <outputDirectory></outputDirectory>\r
+ <fileMode>0755</fileMode>\r
+ </fileSet>\r
+ </fileSets>\r
+</assembly>
\ No newline at end of file
--- /dev/null
+@echo off\r
+\r
+rem Target application\r
+set JAVA_HOME=[the target JRE]\r
+set SLC_USER_CLASSPATH=[classpath of the application to test]\r
+set SLC_DETACHED_APPCLASS=[main class of the application to test]\r
+set SLC_DETACHED_APPARGS=[arguments of the application to test]\r
+set SLC_DETACHED_JVM_ARGS=[additional JVM arguments]\r
+\r
+rem Runtime\r
+set PROJECT_BASE=[base of the project to being developed]\r
+set SLC_WORK_DIR=%PROJECT_BASE%/src/main/slc/work\r
+set SLC_USER_BUNDLES=reference:file:%PROJECT_BASE%/target/classes\r
+\r
--- /dev/null
+@echo off
+echo SLC Detached
+set SLC_HOME=%~dp0..
+echo SLC_HOME=%SLC_HOME%
+set SLC_LIB_DETACHED=%SLC_HOME%\lib\detached
+
+call slc-detached-settings.bat
+
+rem FOR %%f IN (%SLC_HOME%\lib\detached\*.jar) DO set CLASSPATH=%CLASSPATH%;%%f
+FOR %%f IN (%SLC_HOME%\lib\detached\org.argeo.slc.detached.launcher-*.jar) DO set SLC_DETACHED_LAUNCHER_JAR=%%f
+FOR %%f IN (%SLC_HOME%\lib\org.argeo.slc.detached-*.jar) DO set SLC_DETACHED_JAR=%%f
+
+set CLASSPATH=%SLC_DETACHED_LAUNCHER_JAR%;%SLC_USER_CLASSPATH%;%SLC_LIB_DETACHED%\com.springsource.org.aopalliance-1.0.0.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.commons.io-1.4.0.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.commons.logging-1.1.1.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.log4j-1.2.15.jar;%SLC_LIB_DETACHED%\org.apache.felix.main-1.2.1.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.xerces-2.8.1.jar;%SLC_LIB_DETACHED%\com.springsource.org.apache.xalan-2.7.0.jar
+
+set CMD=%JAVA_HOME%\bin\java %SLC_DETACHED_JVM_ARGS% -Dslc.detached.jar=%SLC_DETACHED_JAR% -Dslc.home=%SLC_HOME% -Dslc.workDir=%SLC_WORK_DIR% "-Dslc.detached.userBundles=%SLC_USER_BUNDLES%" -Dslc.detached.appclass=%SLC_DETACHED_APPCLASS% "-Dslc.detached.appargs=%SLC_DETACHED_APPARGS%" -classpath %CLASSPATH% org.argeo.slc.detached.launcher.Main
+rem echo CMD=%CMD%
+
+start %CMD%
+
--- /dev/null
+package org.argeo.slc.detached.launcher;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class Main {
+ public final static String PROP_SLC_HOME = "slc.home";
+ public final static String PROP_SLC_OSGI_START = "slc.osgi.start";
+ public final static String PROP_SLC_OSGI_SCAN_CLASSPATH = "slc.osgi.scanClasspath";
+ public final static String PROP_SLC_OSGI_EQUINOX_ARGS = "slc.osgi.equinox.args";
+
+ private final static String DEV_BUNDLE_PREFIX = "slc.osgi.devbundle.";
+
+ public static void main(String[] args) {
+ info("Argeo SLC Detached launcher starting...");
+ try {
+ // Load properties
+ String propertyPath = "slc-detached.properties";
+ Properties config = prepareConfig(propertyPath);
+
+ // Start app (in main class loader)
+ startApp(config);
+
+ // Start OSGi framework
+ try {
+ startEquinox(config);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ info("Argeo SLC Detached launcher started.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+
+ protected static Properties prepareConfig(String propertyFilePath)
+ throws Exception {
+ // Format slc.home
+ String slcHome = System.getProperty(PROP_SLC_HOME);
+ if (slcHome != null) {
+ slcHome = new File(slcHome).getCanonicalPath();
+ System.setProperty(PROP_SLC_HOME, slcHome);
+ }
+
+ // Load config
+ Properties config = new Properties();
+ InputStream in = null;
+ try {
+ File file = new File(propertyFilePath);
+ if (file.exists()) {
+ in = new FileInputStream(propertyFilePath);
+ config.load(in);
+ }
+ } finally {
+ if (in != null)
+ in.close();
+ }
+
+ // System properties have priority.
+ config.putAll(System.getProperties());
+ return config;
+ }
+
+ public static void startEquinox(Properties config) throws Exception {
+ info("java.home=" + System.getProperty("java.home"));
+ info("java.class.path=" + System.getProperty("java.class.path"));
+
+ File baseDir = new File(System.getProperty("user.dir"))
+ .getCanonicalFile();
+ String equinoxConfigurationPath = baseDir.getPath() + File.separator
+ + "slc-detached" + File.separator + "equinoxConfiguration";
+
+ String equinoxArgsLineDefault = "-console -noExit -clean -debug -configuration "
+ + equinoxConfigurationPath;
+ String equinoxArgsLine = config.getProperty(PROP_SLC_OSGI_EQUINOX_ARGS,
+ equinoxArgsLineDefault);
+ // String[] equinoxArgs = { "-console", "-noExit", "-clean", "-debug",
+ // "-configuration", equinoxConfigurationPath };
+ String[] equinoxArgs = equinoxArgsLine.split(" ");
+
+ BundleContext context = EclipseStarter.startup(equinoxArgs, null);
+
+ List installBundleNames = new ArrayList();
+
+ // Load from class path (dev environment, maven)
+ if (config.getProperty(PROP_SLC_OSGI_SCAN_CLASSPATH, "false").equals(
+ "true")) {
+ StringTokenizer st = new StringTokenizer(System
+ .getProperty("java.class.path"), File.pathSeparator);
+ while (st.hasMoreTokens()) {
+ try {
+ String path = st.nextToken();
+ String url = "reference:file:"
+ + new File(path).getCanonicalPath();
+ Bundle bundle = context.installBundle(url);
+ if (bundle.getSymbolicName() != null)
+ installBundleNames.add(bundle.getSymbolicName());
+ info("Installed from classpath " + url);
+ } catch (Exception e) {
+ bundleInstallWarn(e.getMessage());
+ }
+ }
+ }
+
+ // Load from dev bundles
+ Map devBundleUrls = getDevBundleUrls(config);
+ Iterator devBundles = devBundleUrls.keySet().iterator();
+ while (devBundles.hasNext()) {
+ try {
+ String bundleName = (String) devBundles.next();
+ String url = (String) devBundleUrls.get(bundleName);
+ Bundle bundle = context.installBundle(url);
+ installBundleNames.add(bundle.getSymbolicName());
+ info("Installed as dev bundle " + url);
+ } catch (Exception e) {
+ bundleInstallWarn(e.getMessage());
+ }
+ }
+
+ // Load from distribution
+ String slcHome = config.getProperty(PROP_SLC_HOME);
+ if (slcHome != null) {
+ File libDir = new File(slcHome + File.separator + "lib");
+ File[] bundleFiles = libDir.listFiles();
+ for (int i = 0; i < bundleFiles.length; i++) {
+ try {
+ String url = "reference:file:"
+ + bundleFiles[i].getCanonicalPath();
+ Bundle bundle = context.installBundle(url);
+ installBundleNames.add(bundle.getSymbolicName());
+ info("INFO: Installed from SLC home " + url);
+ } catch (Exception e) {
+ bundleInstallWarn(e.getMessage());
+ }
+
+ }
+ }
+
+ // Start bundles
+ String bundleStart = config.getProperty(PROP_SLC_OSGI_START,
+ "org.springframework.osgi.extender,org.argeo.slc.detached");
+
+ if (bundleStart.trim().equals("*")) {
+ for (int i = 0; i < installBundleNames.size(); i++) {
+ Object obj = installBundleNames.get(i);
+ if (obj != null) {
+ String bundleSymbolicName = obj.toString();
+ try {
+ startBundle(context, bundleSymbolicName);
+ } catch (Exception e) {
+ bundleInstallWarn("Cannot start " + bundleSymbolicName
+ + ": " + e.getMessage());
+ }
+ }
+ }
+ } else {
+ StringTokenizer stBundleStart = new StringTokenizer(bundleStart,
+ ",");
+ while (stBundleStart.hasMoreTokens()) {
+ String bundleSymbolicName = stBundleStart.nextToken();
+ startBundle(context, bundleSymbolicName);
+ }
+ }
+ }
+
+ private static Map getDevBundleUrls(Properties config) {
+ Map bundles = new Hashtable();
+ Iterator keys = config.keySet().iterator();
+ while (keys.hasNext()) {
+ String key = (String) keys.next();
+ if (key.startsWith(DEV_BUNDLE_PREFIX)) {
+ String bundle = key.substring(DEV_BUNDLE_PREFIX.length());
+ String path = config.getProperty(key);
+ bundles.put(bundle, path);
+ }
+ }
+ return bundles;
+ }
+
+ private static void startBundle(BundleContext bundleContext,
+ String symbolicName) throws BundleException {
+ //info("Starting bundle " + symbolicName + "...");
+ Bundle bundle = findBundleBySymbolicName(bundleContext, symbolicName);
+ if (bundle != null)
+ bundle.start();
+ else
+ throw new RuntimeException("Bundle " + symbolicName + " not found");
+ info("Started " + symbolicName);
+ }
+
+ /** WARNING: return the first one found! */
+ private static Bundle findBundleBySymbolicName(BundleContext bundleContext,
+ String symbolicName) {
+ Bundle[] bundles = bundleContext.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ Bundle bundle = bundles[i];
+ String bundleSymbolicName = bundle.getSymbolicName();
+ if (bundleSymbolicName != null) {
+ // throw new RuntimeException("Bundle " + bundle.getBundleId()
+ // + " (" + bundle.getLocation()
+ // + ") has no symbolic name.");
+
+ if (bundleSymbolicName.equals(symbolicName)) {
+ return bundle;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static void startApp(Properties config) throws Exception {
+ String className = config.getProperty("slc.detached.appclass");
+ String[] uiArgs = readArgumentsFromLine(config.getProperty(
+ "slc.detached.appargs", ""));
+
+ if (className == null) {
+ info("No slc.detached.appclass property define: does not try to launch an app from the standard classpath.");
+ } else {
+ // Launch main method using reflection
+ Class clss = Class.forName(className);
+ Class[] mainArgsClasses = new Class[] { uiArgs.getClass() };
+ Object[] mainArgs = { uiArgs };
+ Method mainMethod = clss.getMethod("main", mainArgsClasses);
+ mainMethod.invoke(null, mainArgs);
+ }
+ }
+
+ /* UTILITIES */
+
+ /**
+ * Transform a line into an array of arguments, taking "" as single
+ * arguments. (nested \" are not supported)
+ */
+ private static String[] readArgumentsFromLine(String lineOrig) {
+
+ String line = lineOrig.trim();// remove trailing spaces
+ // System.out.println("line=" + line);
+ List args = new Vector();
+ StringBuffer curr = new StringBuffer("");
+ boolean inQuote = false;
+ char[] arr = line.toCharArray();
+ for (int i = 0; i < arr.length; i++) {
+ char c = arr[i];
+ switch (c) {
+ case '\"':
+ inQuote = !inQuote;
+ break;
+ case ' ':
+ if (!inQuote) {// otherwise, no break: goes to default
+ if (curr.length() > 0) {
+ args.add(curr.toString());
+ curr = new StringBuffer("");
+ }
+ break;
+ }
+ default:
+ curr.append(c);
+ break;
+ }
+ }
+
+ // Add last arg
+ if (curr.length() > 0) {
+ args.add(curr.toString());
+ curr = null;
+ }
+
+ String[] res = new String[args.size()];
+ for (int i = 0; i < args.size(); i++) {
+ res[i] = args.get(i).toString();
+ // System.out.println("res[i]=" + res[i]);
+ }
+ return res;
+ }
+
+ private static void info(Object obj) {
+ System.out.println("[INFO] " + obj);
+ }
+
+ private static void bundleInstallWarn(Object obj) {
+ System.err.println("[WARN] " + obj);
+ //Thread.dumpStack();
+ }
+}
--- /dev/null
+# Set root logger level to DEBUG and its only appender to A1.\r
+log4j.rootLogger=WARN, console\r
+\r
+## Levels\r
+# Slc\r
+log4j.logger.org.argeo.slc=DEBUG\r
+log4j.logger.org.springframework=WARN\r
+\r
+## Appenders\r
+# A1 is set to be a ConsoleAppender.\r
+log4j.appender.console=org.apache.log4j.ConsoleAppender\r
+\r
+# A1 uses PatternLayout.\r
+log4j.appender.console.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - %c %n\r
+\r