Call python natively
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 7 Dec 2008 16:13:12 +0000 (16:13 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 7 Dec 2008 16:13:12 +0000 (16:13 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1925 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

maven/maven-argeo-qooxdoo-plugin/pom.xml
maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java
maven/maven-argeo-qooxdoo-plugin/src/main/resources/META-INF/maven/lifecycle.xml

index b740b00f6739eb93c59052606d34372c4b15f9bd..b456a2d805b8774373c51d0b3dabeb7cbb78e427 100644 (file)
                        <artifactId>maven-project</artifactId>\r
                        <version>2.0.7</version>\r
                </dependency>\r
-               <dependency>\r
-                       <groupId>org.argeo.dep.dist</groupId>\r
-                       <artifactId>jython</artifactId>\r
-                       <version>2.5.beta0</version>\r
-                       <classifier>exec</classifier>\r
-               </dependency>\r
        </dependencies>\r
        <distributionManagement>\r
                <repository>\r
index 5a3429523ffe436b03bacd3b1c48c0b374590235..ec695a56b21301ccf08b877f71f98882a0d33fe6 100644 (file)
@@ -5,7 +5,11 @@ import java.io.File;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.python.util.jython;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
 
 /**
  * Calls Qooxdoo python tool chain
@@ -40,19 +44,39 @@ public class GenerateMojo extends AbstractMojo {
 
        public void execute() throws MojoExecutionException, MojoFailureException {
                try {
-                       File jythonBase = new File(buildDirectory, "jython");
-                       jythonBase.mkdirs();
-                       System.setProperty("python.home", jythonBase.getCanonicalPath());
+                       // File jythonBase = new File(buildDirectory, "jython");
+                       // jythonBase.mkdirs();
+                       // System.setProperty("python.home", jythonBase.getCanonicalPath());
 
-                       //File generateScript = new File(baseDir, "generate.py");
+                       File generateScript = new File(baseDir, "generate.py");
                        // String[] jobArray = jobs.split(" ");
                        // String[] args = new String[jobArray.length + 1];
                        // args[0] = generateScript.getCanonicalPath();
                        // System.arraycopy(jobArray, 0, args, 1, jobArray.length);
                        String[] args = { "generate.py", job };
                        getLog().info("Running Qooxdoo job: " + job + " ...");
-                       jython.main(args);
+                       // jython.main(args);
+
+                       Commandline cl = new Commandline();
+                       cl.setExecutable("python");
+                       cl.setWorkingDirectory(baseDir.getCanonicalPath());
+                       cl.createArgument().setValue(generateScript.getCanonicalPath());
+                       cl.createArgument().setValue(job);
+
+                       StreamConsumer stdout = new StdoutConsumer(getLog());
+                       StreamConsumer stderr = new StderrConsumer(getLog());
+                       try {
+                               int result = CommandLineUtils.executeCommandLine(cl, stdout,
+                                               stderr);
+                               if (result != 0) {
+                                       throw new MojoExecutionException("Qooxdoo job returned: \'"
+                                                       + result + "\'.");
+                               }
+                       } catch (CommandLineException e) {
+                               throw new MojoExecutionException("Unable to run Qooxdoo job", e);
+                       }
                        getLog().info("Finished Qooxdoo job: " + job);
+
                } catch (Exception e) {
                        throw new MojoExecutionException(
                                        "Unexpected exception when running Jython", e);
@@ -60,4 +84,61 @@ public class GenerateMojo extends AbstractMojo {
 
        }
 
+       /**
+        * Consumer to receive lines sent to stdout. The lines are logged as info.
+        */
+       private class StdoutConsumer implements StreamConsumer {
+               /** Logger to receive the lines. */
+               private Log logger;
+
+               /**
+                * Constructor.
+                * 
+                * @param log
+                *            The logger to receive the lines
+                */
+               public StdoutConsumer(Log log) {
+                       logger = log;
+               }
+
+               /**
+                * Consume a line.
+                * 
+                * @param string
+                *            The line to consume
+                */
+               public void consumeLine(String string) {
+                       logger.info(string);
+               }
+       }
+
+       /**
+        * Consumer to receive lines sent to stderr. The lines are logged as
+        * warnings.
+        */
+       private class StderrConsumer implements StreamConsumer {
+               /** Logger to receive the lines. */
+               private Log logger;
+
+               /**
+                * Constructor.
+                * 
+                * @param log
+                *            The logger to receive the lines
+                */
+               public StderrConsumer(Log log) {
+                       logger = log;
+               }
+
+               /**
+                * Consume a line.
+                * 
+                * @param string
+                *            The line to consume
+                */
+               public void consumeLine(String string) {
+                       logger.warn(string);
+               }
+       }
+
 }
index 9d2f90106f9d253fb97f7814545ca49d0137a599..3fb51df2ed6e7625fc47b952ad3d375c9ff0a72e 100644 (file)
                                                </goals>
                                                <configuration>
                                                        <artifactItems>
-                                                               <artifactItem>
-                                                                       <groupId>org.argeo.dep.dist</groupId>
-                                                                       <artifactId>jython</artifactId>
-                                                                       <version>2.5.beta0</version>
-                                                                       <classifier>lib</classifier>
-                                                                       <type>zip</type>
-                                                                       <outputDirectory>${project.build.directory}/jython
-                                                                       </outputDirectory>
-                                                                       <overWrite>false</overWrite>
-                                                               </artifactItem>
                                                                <artifactItem>
                                                                        <groupId>org.argeo.dep.dist</groupId>
                                                                        <artifactId>qooxdoo-sdk</artifactId>