]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.maven/src/main/java/org/argeo/slc/maven/MavenCall.java
Improve log
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.maven / src / main / java / org / argeo / slc / maven / MavenCall.java
index d180d1e11ea26d4ad3432590d3be4e8b28df6271..0ac707325e74cdad49add5b1293a695e689ee5bc 100644 (file)
@@ -1,11 +1,29 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 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. */
@@ -13,21 +31,31 @@ public class MavenCall implements Runnable {
        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)
@@ -45,10 +73,17 @@ public class MavenCall implements Runnable {
                // System.setProperty("maven.home", m2Home);
                //
                // Launcher.main(goals);
+               log.info("Maven call: " + args);
 
                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())
@@ -56,6 +91,18 @@ public class MavenCall implements Runnable {
                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;
        }
@@ -76,4 +123,12 @@ public class MavenCall implements Runnable {
                this.properties = properties;
        }
 
+       public void setCl(String cl) {
+               this.cl = cl;
+       }
+
+       public Boolean getSuccess() {
+               return success == null ? false : success;
+       }
+
 }