X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=maven%2Fmaven-argeo-qooxdoo-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fmaven%2Fplugins%2Fqooxdoo%2FGenerateMojo.java;h=3138fbc4eea11a40582d2efb631b09e472cf98d6;hb=2c20b8060f8682ca9267ce158c002d79b1367a29;hp=5a3429523ffe436b03bacd3b1c48c0b374590235;hpb=34ac04ce7b1f2a1a658adaa0873fd0c53b1f8bb7;p=gpl%2Fargeo-slc.git diff --git a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java index 5a3429523..3138fbc4e 100644 --- a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java +++ b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java @@ -5,13 +5,16 @@ 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 * * @goal generate - * @execute goal="env" */ public class GenerateMojo extends AbstractMojo { /** @@ -22,6 +25,14 @@ public class GenerateMojo extends AbstractMojo { */ private String job; + /** + * Location of the qooxdoo sdk. + * + * @parameter expression="${qooxdooSdk}" + */ + private String qooxdooSdk = "src" + File.separator + "main" + + File.separator + "webapp" + File.separator + "qooxdoo-sdk"; + /** * The build directory. * @@ -40,19 +51,32 @@ 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 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 }; + File generateScript = new File(baseDir.getPath() + File.separator + + qooxdooSdk + File.separator + "tool" + File.separator + + "bin", "generator.py"); getLog().info("Running Qooxdoo job: " + job + " ..."); - jython.main(args); + + Commandline cl = new Commandline(); + + cl.setExecutable("python");// python needs to be installed + 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); + } + } + }