<relativePath>..</relativePath>\r
</parent>\r
<artifactId>maven-argeo-osgi-plugin</artifactId>\r
- <version>0.1.8</version>\r
+ <version>0.1.9</version>\r
<packaging>maven-plugin</packaging>\r
<name>Argeo OSGi Plugin</name>\r
\r
<groupId>ant-contrib</groupId>\r
<artifactId>ant-contrib</artifactId>\r
</dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.eclipse.osgi</groupId>\r
+ <artifactId>org.eclipse.osgi</artifactId>\r
+ <version>3.4.2.R34x_v20080826-1230</version>\r
+ </dependency>\r
+\r
</dependencies>\r
+ <repositories>\r
+ <repository>\r
+ <id>central</id>\r
+ <url>http://repo1.maven.org/maven2</url>\r
+ <releases>\r
+ <enabled>true</enabled>\r
+ <updatePolicy>daily</updatePolicy>\r
+ <checksumPolicy>warn</checksumPolicy>\r
+ </releases>\r
+ <snapshots>\r
+ <enabled>false</enabled>\r
+ <updatePolicy>never</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </snapshots>\r
+ </repository>\r
+ <repository>\r
+ <id>com.springsource.repository.bundles.release\r
+ </id>\r
+ <name>\r
+ SpringSource Enterprise Bundle Repository - SpringSource\r
+ Bundle\r
+ Releases\r
+ </name>\r
+ <url>\r
+ http://repository.springsource.com/maven/bundles/release\r
+ </url>\r
+ <releases>\r
+ <enabled>true</enabled>\r
+ <updatePolicy>daily</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </releases>\r
+ <snapshots>\r
+ <enabled>false</enabled>\r
+ <updatePolicy>never</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </snapshots>\r
+ </repository>\r
+ <repository>\r
+ <id>com.springsource.repository.bundles.external\r
+ </id>\r
+ <name>\r
+ SpringSource Enterprise Bundle Repository - External\r
+ Bundle\r
+ Releases\r
+ </name>\r
+ <url>\r
+ http://repository.springsource.com/maven/bundles/external\r
+ </url>\r
+ <releases>\r
+ <enabled>true</enabled>\r
+ <updatePolicy>daily</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </releases>\r
+ <snapshots>\r
+ <enabled>false</enabled>\r
+ <updatePolicy>never</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </snapshots>\r
+ </repository>\r
+ <repository>\r
+ <id>argeo</id>\r
+ <url>http://www.argeo.org/maven/argeo\r
+ </url>\r
+ <releases>\r
+ <enabled>true</enabled>\r
+ <updatePolicy>daily</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </releases>\r
+ <snapshots>\r
+ <enabled>false</enabled>\r
+ <updatePolicy>never</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </snapshots>\r
+ </repository>\r
+ <repository>\r
+ <id>argeo-snapshots</id>\r
+ <url>http://www.argeo.org/maven/argeo-snapshots\r
+ </url>\r
+ <releases>\r
+ <enabled>false</enabled>\r
+ <updatePolicy>never</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </releases>\r
+ <snapshots>\r
+ <enabled>true</enabled>\r
+ <updatePolicy>always</updatePolicy>\r
+ <checksumPolicy>fail</checksumPolicy>\r
+ </snapshots>\r
+ </repository>\r
+ </repositories>\r
+\r
</project>
import org.apache.maven.plugin.MojoFailureException;
import org.argeo.slc.maven.plugin.MavenDependencyManager;
import org.argeo.slc.maven.plugin.SystemCall;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
/**
+ * Starts Equinox runtime
+ *
* @goal equinox
* */
public class EquinoxExecMojo extends AbstractOsgiMojo {
*/
protected String[] argsToAppend;
- protected String[] defaultArgs = { "-console", "-configuration", "conf",
- "-data", "data" };
+ protected String[] defaultArgs = { "-console", "-configuration",
+ "target/slc/conf", "-data", "target/slc/data" };
/**
* JVM system properties
*/
protected File execDir;
+ /**
+ * Whether to create a new JVM
+ *
+ * @parameter expression="${fork}" default-value="false"
+ * @required
+ */
+ protected boolean fork;
+
+ /**
+ * Whether to wait for the runtime to exit
+ *
+ * @parameter expression="${wait}" default-value="true"
+ * @required
+ */
+ protected boolean wait;
+
+ /**
+ * Number of milliseconds to pause after having started the server (when
+ * ${wait}=false)
+ *
+ * @parameter expression="${pause}" default-value="0"
+ * @required
+ */
+ protected long pause;
+
public void execute() throws MojoExecutionException, MojoFailureException {
if ("bundles".equals(project.getArtifact().getType())) {
System.out.println("Skip artifact of type bundles "
return;
}
+ String originalUserDir = System.getProperty("user.dir");
try {
- Artifact equinoxArtifact = null;
- Artifact osgiBootArtifact = null;
-
- Set dependencies = mavenDependencyManager
- .getTransitiveProjectDependencies(project, remoteRepos,
- local);
-
- StringBuffer osgiLocations = new StringBuffer();
- List bundleArtifacts = new ArrayList();
- boolean first = true;
- for (Iterator it = dependencies.iterator(); it.hasNext();) {
- Artifact depArtifact = (Artifact) it.next();
- printArtifact(depArtifact);
-
- if (depArtifact.getArtifactId().equals(equinoxArtifactId)) {
- equinoxArtifact = depArtifact;
- } else if (depArtifact.getArtifactId().equals(
- osgiBootArtifactId)) {
- osgiBootArtifact = depArtifact;
- } else {
- bundleArtifacts.add(depArtifact);
-
- if ("jar".equals(depArtifact.getType())) {
- // Add to OSGi locations
- if (first)
- first = false;
- else
- osgiLocations.append(File.pathSeparatorChar);
-
- osgiLocations.append(depArtifact.getFile()
- .getCanonicalPath().replace(File.separatorChar,
- '/'));
- }
+ LocationsStruct locationsStruct = listOsgiLocations();
+ if (fork)
+ execForked(locationsStruct);
+ else
+ execNonForked(locationsStruct);
+ } catch (Exception e) {
+ throw new MojoExecutionException("Cannot execute OSGi runtime", e);
+ } finally {
+ System.setProperty("user.dir", originalUserDir);
+ }
+ }
+
+ protected LocationsStruct listOsgiLocations() throws Exception {
+ LocationsStruct locationsStruct = new LocationsStruct();
+
+ Set dependencies = mavenDependencyManager
+ .getTransitiveProjectDependencies(project, remoteRepos, local);
+
+ StringBuffer osgiLocations = new StringBuffer();
+ List bundleArtifacts = new ArrayList();
+ boolean first = true;
+ for (Iterator it = dependencies.iterator(); it.hasNext();) {
+ Artifact depArtifact = (Artifact) it.next();
+ printArtifact(depArtifact);
+
+ if (depArtifact.getArtifactId().equals(equinoxArtifactId)) {
+ locationsStruct.equinoxArtifact = depArtifact;
+ } else if (depArtifact.getArtifactId().equals(osgiBootArtifactId)) {
+ locationsStruct.osgiBootArtifact = depArtifact;
+ } else {
+ bundleArtifacts.add(depArtifact);
+
+ if ("jar".equals(depArtifact.getType())) {
+ // Add to OSGi locations
+ if (first)
+ first = false;
+ else
+ osgiLocations.append(File.pathSeparatorChar);
+
+ osgiLocations.append(depArtifact.getFile()
+ .getCanonicalPath()
+ .replace(File.separatorChar, '/'));
}
}
+ }
+ locationsStruct.osgiLocations = osgiLocations.toString();
+ return locationsStruct;
+ }
- // Set defaults
- if (jvmArgs == null)
- jvmArgs = defaultJvmArgs;
- if (args == null)
- args = defaultArgs;
- if (systemProperties == null)
- systemProperties = new HashMap();
-
- if (!execDir.exists())
- execDir.mkdirs();
-
- // Build command
- List cmdList = new ArrayList();
- // JVM
- cmdList.add(jvm);
- // JVM arguments
- cmdList.addAll(Arrays.asList(jvmArgs));
-
- if (!"0".equals(debug))
- cmdList
- .add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
- + debug);
-
- if (jvmArgsToAppend != null)
- cmdList.addAll(Arrays.asList(jvmArgsToAppend));
-
- // System properties
- if (!systemProperties.containsKey("osgi.bundles"))
- cmdList.add("-Dosgi.bundles="
- + osgiBootArtifact.getFile().getCanonicalPath()
- + "@start");
- if (!systemProperties.containsKey("slc.osgi.locations"))
- cmdList.add("-Dslc.osgi.locations=" + osgiLocations);
- for (Iterator keys = systemProperties.keySet().iterator(); keys
- .hasNext();) {
- Object key = keys.next();
- Object value = systemProperties.get(key);
- String strValue = null;
- if (value != null) {
- strValue = value.toString().trim();
- strValue = strValue.replaceAll("\n", "");
- strValue = strValue.replaceAll("\t", "");
- }
- cmdList.add("-D" + key + "=" + strValue);
+ protected void execNonForked(LocationsStruct locationsStruct)
+ throws Exception {
+ // Set defaults
+ if (args == null)
+ args = defaultArgs;
+
+ // if (!execDir.exists())
+ // execDir.mkdirs();
+ // System.setProperty("user.dir", execDir.getCanonicalPath());
+
+ // Build command
+ List cmdList = new ArrayList();
+
+ // System properties
+ if (!systemProperties.containsKey("osgi.bundles"))
+ System.setProperty("osgi.bundles", locationsStruct.osgiBootArtifact
+ .getFile().getCanonicalPath()
+ + "@start");
+ if (!systemProperties.containsKey("slc.osgi.locations"))
+ System.setProperty("slc.osgi.locations",
+ locationsStruct.osgiLocations);
+ for (Iterator keys = systemProperties.keySet().iterator(); keys
+ .hasNext();) {
+ Object key = keys.next();
+ Object value = systemProperties.get(key);
+ String strValue = null;
+ if (value != null) {
+ strValue = value.toString().trim();
+ strValue = strValue.replaceAll("\n", "");
+ strValue = strValue.replaceAll("\t", "");
}
+ System.setProperty(key.toString(), strValue);
+ }
+
+ // Program arguments
+ cmdList.addAll(Arrays.asList(args));
+ if (argsToAppend != null)
+ cmdList.addAll(Arrays.asList(argsToAppend));
+
+ String[] cmd = (String[]) cmdList.toArray(new String[0]);
+ System.out.println("Equinox arguments (non forked):");
+ printCommand(cmd);
- // Equinox jar
- cmdList.add("-jar");
- cmdList.add(equinoxArtifact.getFile().getCanonicalPath());
-
- // Program arguments
- cmdList.addAll(Arrays.asList(args));
- if (argsToAppend != null)
- cmdList.addAll(Arrays.asList(argsToAppend));
-
- String[] cmd = (String[]) cmdList.toArray(new String[0]);
-
- System.out.println("\nExecute command:\n");
- for (int i = 0; i < cmd.length; i++) {
- boolean containsSpace = (cmd[i].indexOf(' ') >= 0)
- || (cmd[i].indexOf('\t') >= 0);
- if (containsSpace)
- System.out.print('\"');
- System.out.print(cmd[i]);
- if (containsSpace)
- System.out.print('\"');
- System.out.print(' ');
+ EclipseStarter.startup(cmd, null);
+
+ if (wait) {
+ while (EclipseStarter.isRunning()) {
+ Thread.sleep(500);
}
- System.out.println("\n");
+ } else {
+ Thread.sleep(pause);
+ }
+ }
- SystemCall systemCall = new SystemCall(execDir.getCanonicalPath(),
- cmd, true);
- systemCall.run();
+ protected void execForked(LocationsStruct locationsStruct) throws Exception {
+ // Set defaults
+ if (jvmArgs == null)
+ jvmArgs = defaultJvmArgs;
+ if (args == null)
+ args = defaultArgs;
+ if (systemProperties == null)
+ systemProperties = new HashMap();
+
+ if (!execDir.exists())
+ execDir.mkdirs();
+
+ // Build command
+ List cmdList = new ArrayList();
+ // JVM
+ cmdList.add(jvm);
+ // JVM arguments
+ cmdList.addAll(Arrays.asList(jvmArgs));
+
+ if (!"0".equals(debug))
+ cmdList
+ .add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
+ + debug);
+
+ if (jvmArgsToAppend != null)
+ cmdList.addAll(Arrays.asList(jvmArgsToAppend));
+
+ // System properties
+ if (!systemProperties.containsKey("osgi.bundles"))
+ cmdList.add("-Dosgi.bundles="
+ + locationsStruct.osgiBootArtifact.getFile()
+ .getCanonicalPath() + "@start");
+ if (!systemProperties.containsKey("slc.osgi.locations"))
+ cmdList
+ .add("-Dslc.osgi.locations="
+ + locationsStruct.osgiLocations);
+ for (Iterator keys = systemProperties.keySet().iterator(); keys
+ .hasNext();) {
+ Object key = keys.next();
+ Object value = systemProperties.get(key);
+ String strValue = null;
+ if (value != null) {
+ strValue = value.toString().trim();
+ strValue = strValue.replaceAll("\n", "");
+ strValue = strValue.replaceAll("\t", "");
+ }
+ cmdList.add("-D" + key + "=" + strValue);
+ }
- } catch (Exception e) {
- throw new MojoExecutionException("Cannot execute Equinox", e);
+ // Equinox jar
+ cmdList.add("-jar");
+ cmdList.add(locationsStruct.equinoxArtifact.getFile()
+ .getCanonicalPath());
+
+ // Program arguments
+ cmdList.addAll(Arrays.asList(args));
+ if (argsToAppend != null)
+ cmdList.addAll(Arrays.asList(argsToAppend));
+
+ String[] cmd = (String[]) cmdList.toArray(new String[0]);
+ System.out.println("Execute Equinox command (forked):");
+ printCommand(cmd);
+
+ SystemCall systemCall = new SystemCall(execDir.getCanonicalPath(), cmd,
+ true);
+ if (wait) {
+ systemCall.run();
+ } else {
+ new Thread(systemCall).start();
+ Thread.sleep(pause);
}
+ }
+ protected void printArtifact(Artifact artifact) {
+ if (getLog().isDebugEnabled())
+ getLog().debug(artifactToString(artifact));
}
- protected static void printArtifact(Artifact artifact) {
- System.out.println(artifactToString(artifact));
+ protected void printCommand(String[] cmd) {
+ for (int i = 0; i < cmd.length; i++) {
+ boolean containsSpace = (cmd[i].indexOf(' ') >= 0)
+ || (cmd[i].indexOf('\t') >= 0);
+ if (containsSpace)
+ System.out.print('\"');
+ System.out.print(cmd[i]);
+ if (containsSpace)
+ System.out.print('\"');
+ System.out.print(' ');
+ }
}
protected static String artifactToString(Artifact artifact) {
+ artifact.getVersion() + " (" + artifact.getFile() + ")";
}
+ protected class LocationsStruct {
+ protected Artifact equinoxArtifact = null;
+ protected Artifact osgiBootArtifact = null;
+ protected String osgiLocations = null;
+ }
}