]> 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
Do dependency management and unpacking itself
[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.AbstractMojo;
6 import org.apache.maven.plugin.MojoExecutionException;
7 import org.apache.maven.plugin.MojoFailureException;
8 import org.apache.maven.plugin.logging.Log;
9 import org.codehaus.plexus.util.cli.CommandLineException;
10 import org.codehaus.plexus.util.cli.CommandLineUtils;
11 import org.codehaus.plexus.util.cli.Commandline;
12 import org.codehaus.plexus.util.cli.StreamConsumer;
13
14 /**
15 * Calls Qooxdoo python tool chain
16 *
17 * @goal generate
18 */
19 public class GenerateMojo extends AbstractMojo {
20 /**
21 * The Qooxdoo build target.
22 *
23 * @parameter expression="${job}"
24 * @required
25 */
26 private String job;
27
28 /**
29 * Location of the qooxdoo sdk.
30 *
31 * @parameter expression="${qooxdooSdk}" default-value="src/qooxdoo-sdk"
32 */
33 private String qooxdooSdk;
34
35 /**
36 * The build directory.
37 *
38 * @parameter expression="${project.build.directory}"
39 * @required
40 */
41 private File buildDirectory;
42
43 /**
44 * The directory for the pom
45 *
46 * @parameter expression="${basedir}"
47 * @required
48 */
49 private File baseDir;
50
51 public void execute() throws MojoExecutionException, MojoFailureException {
52 try {
53 File generateScript = new File(baseDir.getPath() + File.separator
54 + qooxdooSdk + File.separator + "tool" + File.separator
55 + "bin", "generator.py");
56 getLog().info("Running Qooxdoo job: " + job + " ...");
57
58 Commandline cl = new Commandline();
59
60 cl.setExecutable("python");// python needs to be installed
61 cl.setWorkingDirectory(baseDir.getCanonicalPath());
62 cl.createArgument().setValue(generateScript.getCanonicalPath());
63 cl.createArgument().setValue(job);
64
65 StreamConsumer stdout = new StdoutConsumer(getLog());
66 StreamConsumer stderr = new StderrConsumer(getLog());
67 try {
68 int result = CommandLineUtils.executeCommandLine(cl, stdout,
69 stderr);
70 if (result != 0) {
71 throw new MojoExecutionException("Qooxdoo job returned: \'"
72 + result + "\'.");
73 }
74 } catch (CommandLineException e) {
75 throw new MojoExecutionException("Unable to run Qooxdoo job", e);
76 }
77 getLog().info("Finished Qooxdoo job: " + job);
78
79 } catch (Exception e) {
80 throw new MojoExecutionException(
81 "Unexpected exception when running Python", e);
82 }
83
84 }
85
86 /**
87 * Consumer to receive lines sent to stdout. The lines are logged as info.
88 */
89 private class StdoutConsumer implements StreamConsumer {
90 /** Logger to receive the lines. */
91 private Log logger;
92
93 /**
94 * Constructor.
95 *
96 * @param log
97 * The logger to receive the lines
98 */
99 public StdoutConsumer(Log log) {
100 logger = log;
101 }
102
103 /**
104 * Consume a line.
105 *
106 * @param string
107 * The line to consume
108 */
109 public void consumeLine(String string) {
110 logger.info(string);
111 }
112 }
113
114 /**
115 * Consumer to receive lines sent to stderr. The lines are logged as
116 * warnings.
117 */
118 private class StderrConsumer implements StreamConsumer {
119 /** Logger to receive the lines. */
120 private Log logger;
121
122 /**
123 * Constructor.
124 *
125 * @param log
126 * The logger to receive the lines
127 */
128 public StderrConsumer(Log log) {
129 logger = log;
130 }
131
132 /**
133 * Consume a line.
134 *
135 * @param string
136 * The line to consume
137 */
138 public void consumeLine(String string) {
139 logger.warn(string);
140 }
141 }
142
143 }