]> git.argeo.org Git - gpl/argeo-slc.git/blob - maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java
New versions
[gpl/argeo-slc.git] / maven / maven-argeo-qooxdoo-plugin / src / main / java / org / argeo / slc / maven / plugins / qooxdoo / GenerateMojo.java
1 package org.argeo.slc.maven.plugins.qooxdoo;
2
3 import java.io.File;
4
5 import org.apache.maven.plugin.MojoExecutionException;
6 import org.apache.maven.plugin.MojoFailureException;
7 import org.apache.maven.plugin.logging.Log;
8 import org.codehaus.plexus.util.cli.CommandLineException;
9 import org.codehaus.plexus.util.cli.CommandLineUtils;
10 import org.codehaus.plexus.util.cli.Commandline;
11 import org.codehaus.plexus.util.cli.StreamConsumer;
12
13 /**
14 * Calls Qooxdoo python tool chain
15 *
16 * @goal generate
17 */
18 public class GenerateMojo extends AbstractQooxdooMojo {
19 /**
20 * The Qooxdoo build target.
21 *
22 * @parameter expression="${job}"
23 * @required
24 */
25 private String job;
26
27 public void execute() throws MojoExecutionException, MojoFailureException {
28 try {
29 File generateScript = new File(srcBase+ File.separator
30 + sdkDirName + File.separator + "tool" + File.separator
31 + "bin", "generator.py");
32 getLog().info("Running Qooxdoo job: " + job + " ...");
33
34 Commandline cl = new Commandline();
35
36 cl.setExecutable("python");// python needs to be installed
37 cl.setWorkingDirectory(baseDir.getCanonicalPath());
38 cl.createArgument().setValue(generateScript.getCanonicalPath());
39 cl.createArgument().setValue(job);
40
41 StreamConsumer stdout = new StdoutConsumer(getLog());
42 StreamConsumer stderr = new StderrConsumer(getLog());
43 try {
44 int result = CommandLineUtils.executeCommandLine(cl, stdout,
45 stderr);
46 if (result != 0) {
47 throw new MojoExecutionException("Qooxdoo job returned: \'"
48 + result + "\'.");
49 }
50 } catch (CommandLineException e) {
51 throw new MojoExecutionException("Unable to run Qooxdoo job", e);
52 }
53 getLog().info("Finished Qooxdoo job: " + job);
54
55 } catch (Exception e) {
56 throw new MojoExecutionException(
57 "Unexpected exception when running Python", e);
58 }
59
60 }
61
62 /**
63 * Consumer to receive lines sent to stdout. The lines are logged as info.
64 */
65 private class StdoutConsumer implements StreamConsumer {
66 /** Logger to receive the lines. */
67 private Log logger;
68
69 /**
70 * Constructor.
71 *
72 * @param log
73 * The logger to receive the lines
74 */
75 public StdoutConsumer(Log log) {
76 logger = log;
77 }
78
79 /**
80 * Consume a line.
81 *
82 * @param string
83 * The line to consume
84 */
85 public void consumeLine(String string) {
86 logger.info(string);
87 }
88 }
89
90 /**
91 * Consumer to receive lines sent to stderr. The lines are logged as
92 * warnings.
93 */
94 private class StderrConsumer implements StreamConsumer {
95 /** Logger to receive the lines. */
96 private Log logger;
97
98 /**
99 * Constructor.
100 *
101 * @param log
102 * The logger to receive the lines
103 */
104 public StderrConsumer(Log log) {
105 logger = log;
106 }
107
108 /**
109 * Consume a line.
110 *
111 * @param string
112 * The line to consume
113 */
114 public void consumeLine(String string) {
115 logger.warn(string);
116 }
117 }
118
119 }