1 package org
.argeo
.slc
.maven
.plugins
.osgi
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Arrays
;
6 import java
.util
.HashMap
;
7 import java
.util
.Iterator
;
12 import org
.apache
.maven
.artifact
.Artifact
;
13 import org
.apache
.maven
.plugin
.MojoExecutionException
;
14 import org
.apache
.maven
.plugin
.MojoFailureException
;
15 import org
.argeo
.slc
.maven
.plugin
.MavenDependencyManager
;
16 import org
.argeo
.slc
.maven
.plugin
.SystemCall
;
21 public class EquinoxExecMojo
extends AbstractOsgiMojo
{
23 private MavenDependencyManager mavenDependencyManager
;
28 * @parameter expression="${equinoxArtifactId}"
29 * default-value="org.eclipse.osgi"
32 protected String equinoxArtifactId
;
35 * OSGIBoot artifact id
37 * @parameter expression="${osgiBootArtifactId}"
38 * default-value="org.argeo.slc.osgiboot"
41 protected String osgiBootArtifactId
;
46 * @parameter expression="${jvm}" default-value="${java.home}/bin/java"
54 * @parameter alias="${jvmArgs}"
56 protected String
[] jvmArgs
;
59 * JVM arguments to append
61 * @parameter alias="${jvmArgsToAppend}"
63 protected String
[] jvmArgsToAppend
;
65 protected String
[] defaultJvmArgs
= { "-Xmx128m" };
68 * Debug port (0 deactivate)
70 * @parameter expression="${debug}" default-value="0"
73 protected String debug
;
78 * @parameter alias="${args}"
80 protected String
[] args
;
83 * Equinox args to append
85 * @parameter alias="${argsToAppend}"
87 protected String
[] argsToAppend
;
89 protected String
[] defaultArgs
= { "-console", "-configuration", "conf",
93 * JVM system properties
95 * @parameter alias="${systemProperties}"
97 protected Map systemProperties
;
100 * Execution directory
102 * @parameter expression="${execDir}"
103 * default-value="${project.build.directory}/exec"
106 protected File execDir
;
108 public void execute() throws MojoExecutionException
, MojoFailureException
{
109 if ("bundles".equals(project
.getArtifact().getType())) {
110 System
.out
.println("Skip artifact of type bundles "
111 + artifactToString(project
.getArtifact()));
116 Artifact equinoxArtifact
= null;
117 Artifact osgiBootArtifact
= null;
119 Set dependencies
= mavenDependencyManager
120 .getTransitiveProjectDependencies(project
, remoteRepos
,
123 StringBuffer osgiLocations
= new StringBuffer();
124 List bundleArtifacts
= new ArrayList();
125 boolean first
= true;
126 for (Iterator it
= dependencies
.iterator(); it
.hasNext();) {
127 Artifact depArtifact
= (Artifact
) it
.next();
128 printArtifact(depArtifact
);
130 if (depArtifact
.getArtifactId().equals(equinoxArtifactId
)) {
131 equinoxArtifact
= depArtifact
;
132 } else if (depArtifact
.getArtifactId().equals(
133 osgiBootArtifactId
)) {
134 osgiBootArtifact
= depArtifact
;
136 bundleArtifacts
.add(depArtifact
);
138 if ("jar".equals(depArtifact
.getType())) {
139 // Add to OSGi locations
143 osgiLocations
.append(File
.pathSeparatorChar
);
145 osgiLocations
.append(depArtifact
.getFile()
146 .getCanonicalPath().replace(File
.separatorChar
,
154 jvmArgs
= defaultJvmArgs
;
157 if (systemProperties
== null)
158 systemProperties
= new HashMap();
160 if (!execDir
.exists())
164 List cmdList
= new ArrayList();
168 cmdList
.addAll(Arrays
.asList(jvmArgs
));
170 if (!"0".equals(debug
))
172 .add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
175 if (jvmArgsToAppend
!= null)
176 cmdList
.addAll(Arrays
.asList(jvmArgsToAppend
));
179 if (!systemProperties
.containsKey("osgi.bundles"))
180 cmdList
.add("-Dosgi.bundles="
181 + osgiBootArtifact
.getFile().getCanonicalPath()
183 if (!systemProperties
.containsKey("slc.osgi.locations"))
184 cmdList
.add("-Dslc.osgi.locations=" + osgiLocations
);
185 for (Iterator keys
= systemProperties
.keySet().iterator(); keys
187 Object key
= keys
.next();
188 Object value
= systemProperties
.get(key
);
189 String strValue
= null;
191 strValue
= value
.toString().trim();
192 strValue
= strValue
.replaceAll("\n", "");
193 strValue
= strValue
.replaceAll("\t", "");
195 cmdList
.add("-D" + key
+ "=" + strValue
);
200 cmdList
.add(equinoxArtifact
.getFile().getCanonicalPath());
203 cmdList
.addAll(Arrays
.asList(args
));
204 if (argsToAppend
!= null)
205 cmdList
.addAll(Arrays
.asList(argsToAppend
));
207 String
[] cmd
= (String
[]) cmdList
.toArray(new String
[0]);
209 System
.out
.println("\nExecute command:\n");
210 for (int i
= 0; i
< cmd
.length
; i
++) {
211 boolean containsSpace
= (cmd
[i
].indexOf(' ') >= 0)
212 || (cmd
[i
].indexOf('\t') >= 0);
214 System
.out
.print('\"');
215 System
.out
.print(cmd
[i
]);
217 System
.out
.print('\"');
218 System
.out
.print(' ');
220 System
.out
.println("\n");
222 SystemCall systemCall
= new SystemCall(execDir
.getCanonicalPath(),
226 } catch (Exception e
) {
227 throw new MojoExecutionException("Cannot execute Equinox", e
);
232 protected static void printArtifact(Artifact artifact
) {
233 System
.out
.println(artifactToString(artifact
));
236 protected static String
artifactToString(Artifact artifact
) {
237 return artifact
.getGroupId() + ":" + artifact
.getArtifactId() + ":"
238 + artifact
.getType() + ":" + artifact
.getClassifier() + ":"
239 + artifact
.getVersion() + " (" + artifact
.getFile() + ")";