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
;
58 protected String
[] defaultJvmArgs
= { "-Xmx128m" };
63 * @parameter alias="${args}"
65 protected String
[] args
;
67 protected String
[] defaultArgs
= { "-console", "-configuration", "conf",
71 * JVM system properties
73 * @parameter alias="${systemProperties}"
75 protected Map systemProperties
;
80 * @parameter expression="${execDir}"
81 * default-value="${project.build.directory}/exec"
84 protected File execDir
;
86 public void execute() throws MojoExecutionException
, MojoFailureException
{
87 if ("bundles".equals(project
.getArtifact().getType())) {
88 System
.out
.println("Skip artifact of type bundles "
89 + artifactToString(project
.getArtifact()));
94 Artifact equinoxArtifact
= null;
95 Artifact osgiBootArtifact
= null;
97 Set dependencies
= mavenDependencyManager
98 .getTransitiveProjectDependencies(project
, remoteRepos
,
101 StringBuffer osgiLocations
= new StringBuffer();
102 List bundleArtifacts
= new ArrayList();
103 boolean first
= true;
104 for (Iterator it
= dependencies
.iterator(); it
.hasNext();) {
105 Artifact depArtifact
= (Artifact
) it
.next();
106 printArtifact(depArtifact
);
108 if (depArtifact
.getArtifactId().equals(equinoxArtifactId
)) {
109 equinoxArtifact
= depArtifact
;
110 } else if (depArtifact
.getArtifactId().equals(
111 osgiBootArtifactId
)) {
112 osgiBootArtifact
= depArtifact
;
114 bundleArtifacts
.add(depArtifact
);
116 if ("jar".equals(depArtifact
.getType())) {
117 // Add to OSGi locations
121 osgiLocations
.append(File
.pathSeparatorChar
);
123 osgiLocations
.append(depArtifact
.getFile()
124 .getCanonicalPath().replace(File
.separatorChar
,
132 jvmArgs
= defaultJvmArgs
;
135 if (systemProperties
== null)
136 systemProperties
= new HashMap();
138 if (!execDir
.exists())
142 List cmdList
= new ArrayList();
144 cmdList
.addAll(Arrays
.asList(jvmArgs
));
145 if (!systemProperties
.containsKey("osgi.bundles"))
146 cmdList
.add("-Dosgi.bundles="
147 + osgiBootArtifact
.getFile().getCanonicalPath()
149 if (!systemProperties
.containsKey("slc.osgi.locations"))
150 cmdList
.add("-Dslc.osgi.locations=" + osgiLocations
);
151 for (Iterator keys
= systemProperties
.keySet().iterator(); keys
153 Object key
= keys
.next();
154 Object value
= systemProperties
.get(key
);
155 String strValue
= null;
157 strValue
= value
.toString().trim();
158 strValue
= strValue
.replaceAll("\n", "");
159 strValue
= strValue
.replaceAll("\t", "");
161 cmdList
.add("-D" + key
+ "=" + strValue
);
164 cmdList
.add(equinoxArtifact
.getFile().getCanonicalPath());
165 cmdList
.addAll(Arrays
.asList(args
));
167 String
[] cmd
= (String
[]) cmdList
.toArray(new String
[0]);
169 System
.out
.println("\nExecute command:\n");
170 for (int i
= 0; i
< cmd
.length
; i
++) {
171 boolean containsSpace
= (cmd
[i
].indexOf(' ') >= 0)
172 || (cmd
[i
].indexOf('\t') >= 0);
174 System
.out
.print('\"');
175 System
.out
.print(cmd
[i
]);
177 System
.out
.print('\"');
178 System
.out
.print(' ');
180 System
.out
.println("\n");
182 SystemCall systemCall
= new SystemCall(execDir
.getCanonicalPath(),
186 } catch (Exception e
) {
187 throw new MojoExecutionException("Cannot execute Equinox", e
);
192 protected static void printArtifact(Artifact artifact
) {
193 System
.out
.println(artifactToString(artifact
));
196 protected static String
artifactToString(Artifact artifact
) {
197 return artifact
.getGroupId() + ":" + artifact
.getArtifactId() + ":"
198 + artifact
.getType() + ":" + artifact
.getClassifier() + ":"
199 + artifact
.getVersion() + " (" + artifact
.getFile() + ")";