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
;
25 private Boolean success
= null;
28 Thread
.currentThread().setContextClassLoader(
29 getClass().getClassLoader());
30 List
<String
> args
= new ArrayList
<String
>();
32 if (settings
!= null && !settings
.trim().equals("")) {
33 args
.add("--settings");
37 args
.add(getBasedirFile().getPath() + "/pom.xml");
38 // FIXME manages \" \". Use Commons CLI?
40 String
[] clArgs
= cl
.split(" ");
41 args
.addAll(Arrays
.asList(clArgs
));
47 for (String profile
: profiles
)
48 args
.add("-P" + profile
);
49 if (properties
!= null)
50 for (String key
: properties
.keySet())
51 args
.add("-D" + key
+ "=\"" + properties
.get(key
) + "\"");
53 // String[] goals = { "-o", "-e", "-f", basedir + "/pom.xml", "clean",
56 // String m2Home = "/opt/apache-maven-3.0.1";
57 // System.setProperty("classworlds.conf", m2Home + "/bin/m2.conf");
58 // System.setProperty("maven.home", m2Home);
60 // Launcher.main(goals);
61 log
.info("Maven call: " + args
);
63 CustomCli mavenCli
= new CustomCli();
64 int exitCode
= mavenCli
.doMain(args
.toArray(new String
[args
.size()]),
65 getBasedirFile().getPath(), System
.out
, System
.err
);
66 if (log
.isDebugEnabled())
67 log
.debug("Maven exit code: " + exitCode
);
73 PlexusContainer plexusContainer
= mavenCli
.getContainer();
74 if (log
.isDebugEnabled())
75 log
.debug(plexusContainer
.getContext().getContextData());
76 plexusContainer
.dispose();
79 /** Removes 'file:' prefix if present */
80 protected File
getBasedirFile() {
82 throw new SlcException("basedir not set");
84 if (basedir
.startsWith("file:"))
85 dir
= new File(basedir
.substring("file:".length()));
87 dir
= new File(basedir
);
91 public void setBasedir(String basedir
) {
92 this.basedir
= basedir
;
95 public void setSettings(String settings
) {
96 this.settings
= settings
;
99 public void setGoals(List
<String
> goals
) {
103 public void setProfiles(List
<String
> profiles
) {
104 this.profiles
= profiles
;
107 public void setProperties(Map
<String
, String
> properties
) {
108 this.properties
= properties
;
111 public void setCl(String cl
) {
115 public Boolean
getSuccess() {
116 return success
== null ?
false : success
;