2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.maven
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Arrays
;
21 import java
.util
.List
;
24 import org
.apache
.commons
.logging
.Log
;
25 import org
.apache
.commons
.logging
.LogFactory
;
26 import org
.argeo
.slc
.SlcException
;
27 import org
.codehaus
.plexus
.PlexusContainer
;
29 /** A Maven execution. */
30 public class MavenCall
implements Runnable
{
31 private final static Log log
= LogFactory
.getLog(MavenCall
.class);
32 private String basedir
;
33 private String settings
;
34 /** Raw command lines arguments */
36 private List
<String
> goals
;
37 private List
<String
> profiles
;
38 private Map
<String
, String
> properties
;
40 private Boolean success
= null;
43 Thread
.currentThread().setContextClassLoader(
44 getClass().getClassLoader());
45 List
<String
> args
= new ArrayList
<String
>();
47 if (settings
!= null && !settings
.trim().equals("")) {
48 args
.add("--settings");
52 args
.add(getBasedirFile().getPath() + "/pom.xml");
53 // FIXME manages \" \". Use Commons CLI?
55 String
[] clArgs
= cl
.split(" ");
56 args
.addAll(Arrays
.asList(clArgs
));
62 for (String profile
: profiles
)
63 args
.add("-P" + profile
);
64 if (properties
!= null)
65 for (String key
: properties
.keySet())
66 args
.add("-D" + key
+ "=\"" + properties
.get(key
) + "\"");
68 // String[] goals = { "-o", "-e", "-f", basedir + "/pom.xml", "clean",
71 // String m2Home = "/opt/apache-maven-3.0.1";
72 // System.setProperty("classworlds.conf", m2Home + "/bin/m2.conf");
73 // System.setProperty("maven.home", m2Home);
75 // Launcher.main(goals);
76 log
.info("Maven call: " + args
);
78 CustomCli mavenCli
= new CustomCli();
79 int exitCode
= mavenCli
.doMain(args
.toArray(new String
[args
.size()]),
80 getBasedirFile().getPath(), System
.out
, System
.err
);
81 if (log
.isDebugEnabled())
82 log
.debug("Maven exit code: " + exitCode
);
88 PlexusContainer plexusContainer
= mavenCli
.getContainer();
89 if (log
.isDebugEnabled())
90 log
.debug(plexusContainer
.getContext().getContextData());
91 plexusContainer
.dispose();
94 /** Removes 'file:' prefix if present */
95 protected File
getBasedirFile() {
97 throw new SlcException("basedir not set");
99 if (basedir
.startsWith("file:"))
100 dir
= new File(basedir
.substring("file:".length()));
102 dir
= new File(basedir
);
106 public void setBasedir(String basedir
) {
107 this.basedir
= basedir
;
110 public void setSettings(String settings
) {
111 this.settings
= settings
;
114 public void setGoals(List
<String
> goals
) {
118 public void setProfiles(List
<String
> profiles
) {
119 this.profiles
= profiles
;
122 public void setProperties(Map
<String
, String
> properties
) {
123 this.properties
= properties
;
126 public void setCl(String cl
) {
130 public Boolean
getSuccess() {
131 return success
== null ?
false : success
;