package org.argeo.slc.maven;
+import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
import org.codehaus.plexus.PlexusContainer;
/** A Maven execution. */
private final static Log log = LogFactory.getLog(MavenCall.class);
private String basedir;
private String settings;
+ /** Raw command lines arguments */
+ private String cl;
private List<String> goals;
private List<String> profiles;
private Map<String, String> properties;
+ private Boolean success = null;
+
public void run() {
Thread.currentThread().setContextClassLoader(
getClass().getClassLoader());
List<String> args = new ArrayList<String>();
args.add("-e");
- if (settings != null) {
+ if (settings != null && !settings.trim().equals("")) {
args.add("--settings");
args.add(settings);
}
args.add("-f");
- args.add(basedir + "/pom.xml");
+ args.add(getBasedirFile().getPath() + "/pom.xml");
+ // FIXME manages \" \". Use Commons CLI?
+ if (cl != null) {
+ String[] clArgs = cl.split(" ");
+ args.addAll(Arrays.asList(clArgs));
+ }
+
if (goals != null)
args.addAll(goals);
if (profiles != null)
// Launcher.main(goals);
CustomCli mavenCli = new CustomCli();
- mavenCli.doMain(args.toArray(new String[args.size()]), basedir,
- System.out, System.err);
+ int exitCode = mavenCli.doMain(args.toArray(new String[args.size()]),
+ getBasedirFile().getPath(), System.out, System.err);
+ if (log.isDebugEnabled())
+ log.debug("Maven exit code: " + exitCode);
+ if (exitCode == 0)
+ success = true;
+ else
+ success = false;
PlexusContainer plexusContainer = mavenCli.getContainer();
if (log.isDebugEnabled())
plexusContainer.dispose();
}
+ /** Removes 'file:' prefix if present */
+ protected File getBasedirFile() {
+ if (basedir == null)
+ throw new SlcException("basedir not set");
+ File dir;
+ if (basedir.startsWith("file:"))
+ dir = new File(basedir.substring("file:".length()));
+ else
+ dir = new File(basedir);
+ return dir;
+ }
+
public void setBasedir(String basedir) {
this.basedir = basedir;
}
this.properties = properties;
}
+ public void setCl(String cl) {
+ this.cl = cl;
+ }
+
+ public Boolean getSuccess() {
+ return success == null ? false : success;
+ }
+
}