X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=maven-argeo-osgi-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fmaven%2Fplugins%2Fosgi%2FEquinoxExecMojo.java;h=ea75a22838a001497edb694eb11666a981d19647;hb=ed281564bf156579dc163bc616db1881fe30b1a6;hp=7f54edd3de87b0fac91c60d8f431baf3f99e6bfb;hpb=a1bb36d5f443c6c13bf1e67dc03207496535227c;p=gpl%2Fargeo-slc.git diff --git a/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/EquinoxExecMojo.java b/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/EquinoxExecMojo.java index 7f54edd3d..ea75a2283 100644 --- a/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/EquinoxExecMojo.java +++ b/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/EquinoxExecMojo.java @@ -55,7 +55,22 @@ public class EquinoxExecMojo extends AbstractOsgiMojo { */ protected String[] jvmArgs; - protected String[] defaultJvmArgs = { "-Xmx256m" }; + /** + * JVM arguments to append + * + * @parameter alias="${jvmArgsToAppend}" + */ + protected String[] jvmArgsToAppend; + + protected String[] defaultJvmArgs = { "-Xmx128m" }; + + /** + * Debug port (0 deactivate) + * + * @parameter expression="${debug}" default-value="0" + * @required + */ + protected String debug; /** * Equinox args @@ -64,8 +79,15 @@ public class EquinoxExecMojo extends AbstractOsgiMojo { */ protected String[] args; - protected String[] defaultArgs = { "-clean", "-console", "-configuration", - "conf" }; + /** + * Equinox args to append + * + * @parameter alias="${argsToAppend}" + */ + protected String[] argsToAppend; + + protected String[] defaultArgs = { "-console", "-configuration", "conf", + "-data", "data" }; /** * JVM system properties @@ -78,11 +100,18 @@ public class EquinoxExecMojo extends AbstractOsgiMojo { * Execution directory * * @parameter expression="${execDir}" + * default-value="${project.build.directory}/exec" * @required */ protected File execDir; public void execute() throws MojoExecutionException, MojoFailureException { + if ("bundles".equals(project.getArtifact().getType())) { + System.out.println("Skip artifact of type bundles " + + artifactToString(project.getArtifact())); + return; + } + try { Artifact equinoxArtifact = null; Artifact osgiBootArtifact = null; @@ -128,10 +157,25 @@ public class EquinoxExecMojo extends AbstractOsgiMojo { 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() @@ -146,18 +190,34 @@ public class EquinoxExecMojo extends AbstractOsgiMojo { if (value != null) { strValue = value.toString().trim(); strValue = strValue.replaceAll("\n", ""); + strValue = strValue.replaceAll("\t", ""); } cmdList.add("-D" + key + "=" + strValue); } + + // 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]); - for (int i = 0; i < cmd.length; i++) + 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]); - System.out.print('\n'); + if (containsSpace) + System.out.print('\"'); + System.out.print(' '); + } + System.out.println("\n"); SystemCall systemCall = new SystemCall(execDir.getCanonicalPath(), cmd, true); @@ -170,10 +230,13 @@ public class EquinoxExecMojo extends AbstractOsgiMojo { } protected static void printArtifact(Artifact artifact) { - System.out.println(artifact.getGroupId() + ":" - + artifact.getArtifactId() + ":" + artifact.getType() + ":" - + artifact.getClassifier() + ":" + artifact.getVersion() + " (" - + artifact.getFile() + ")"); + System.out.println(artifactToString(artifact)); + } + + protected static String artifactToString(Artifact artifact) { + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + + artifact.getType() + ":" + artifact.getClassifier() + ":" + + artifact.getVersion() + " (" + artifact.getFile() + ")"; } }