1 package org
.argeo
.slc
.maven
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Arrays
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.SlcException
;
12 import org
.codehaus
.plexus
.PlexusContainer
;
14 /** A Maven execution. */
15 public class MavenCall
implements Runnable
{
16 private final static Log log
= LogFactory
.getLog(MavenCall
.class);
17 private String basedir
;
18 private String settings
;
19 /** Raw command lines arguments */
21 private List
<String
> goals
;
22 private List
<String
> profiles
;
23 private Map
<String
, String
> properties
;
26 Thread
.currentThread().setContextClassLoader(
27 getClass().getClassLoader());
28 List
<String
> args
= new ArrayList
<String
>();
30 if (settings
!= null) {
31 args
.add("--settings");
35 args
.add(getBasedirFile().getPath() + "/pom.xml");
36 // FIXME manages \" \". Use Commons CLI?
38 String
[] clArgs
= cl
.split(" ");
39 args
.addAll(Arrays
.asList(clArgs
));
45 for (String profile
: profiles
)
46 args
.add("-P" + profile
);
47 if (properties
!= null)
48 for (String key
: properties
.keySet())
49 args
.add("-D" + key
+ "=\"" + properties
.get(key
) + "\"");
51 // String[] goals = { "-o", "-e", "-f", basedir + "/pom.xml", "clean",
54 // String m2Home = "/opt/apache-maven-3.0.1";
55 // System.setProperty("classworlds.conf", m2Home + "/bin/m2.conf");
56 // System.setProperty("maven.home", m2Home);
58 // Launcher.main(goals);
60 CustomCli mavenCli
= new CustomCli();
61 int exitCode
= mavenCli
.doMain(args
.toArray(new String
[args
.size()]),
62 getBasedirFile().getPath(), System
.out
, System
.err
);
63 if (log
.isDebugEnabled())
64 log
.debug("Maven exit code: " + exitCode
);
66 PlexusContainer plexusContainer
= mavenCli
.getContainer();
67 if (log
.isDebugEnabled())
68 log
.debug(plexusContainer
.getContext().getContextData());
69 plexusContainer
.dispose();
72 /** Removes 'file:' prefix if present */
73 protected File
getBasedirFile() {
75 throw new SlcException("basedir not set");
77 if (basedir
.startsWith("file:"))
78 dir
= new File(basedir
.substring("file:".length()));
80 dir
= new File(basedir
);
84 public void setBasedir(String basedir
) {
85 this.basedir
= basedir
;
88 public void setSettings(String settings
) {
89 this.settings
= settings
;
92 public void setGoals(List
<String
> goals
) {
96 public void setProfiles(List
<String
> profiles
) {
97 this.profiles
= profiles
;
100 public void setProperties(Map
<String
, String
> properties
) {
101 this.properties
= properties
;
104 public void setCl(String cl
) {