]> git.argeo.org Git - gpl/argeo-slc.git/blob - maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java
Don't use python win32 package
[gpl/argeo-slc.git] / 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}"
32 */
33 private String qooxdooSdk = "src" + File.separator + "main"
34 + File.separator + "webapp" + File.separator + "qooxdoo-0.8-sdk";
35
36 /**
37 * The build directory.
38 *
39 * @parameter expression="${project.build.directory}"
40 * @required
41 */
42 private File buildDirectory;
43
44 /**
45 * The directory for the pom
46 *
47 * @parameter expression="${basedir}"
48 * @required
49 */
50 private File baseDir;
51
52 public void execute() throws MojoExecutionException, MojoFailureException {
53 try {
54 File generateScript = new File(baseDir.getPath() + File.separator
55 + qooxdooSdk + File.separator + "tool" + File.separator
56 + "bin", "generator.py");
57 getLog().info("Running Qooxdoo job: " + job + " ...");
58
59 Commandline cl = new Commandline();
60
61 cl.setExecutable("python");// python needs to be installed
62 cl.setWorkingDirectory(baseDir.getCanonicalPath());
63 cl.createArgument().setValue(generateScript.getCanonicalPath());
64 cl.createArgument().setValue(job);
65
66 StreamConsumer stdout = new StdoutConsumer(getLog());
67 StreamConsumer stderr = new StderrConsumer(getLog());
68 try {
69 int result = CommandLineUtils.executeCommandLine(cl, stdout,
70 stderr);
71 if (result != 0) {
72 throw new MojoExecutionException("Qooxdoo job returned: \'"
73 + result + "\'.");
74 }
75 } catch (CommandLineException e) {
76 throw new MojoExecutionException("Unable to run Qooxdoo job", e);
77 }
78 getLog().info("Finished Qooxdoo job: " + job);
79
80 } catch (Exception e) {
81 throw new MojoExecutionException(
82 "Unexpected exception when running Jython", e);
83 }
84
85 }
86
87 /**
88 * Consumer to receive lines sent to stdout. The lines are logged as info.
89 */
90 private class StdoutConsumer implements StreamConsumer {
91 /** Logger to receive the lines. */
92 private Log logger;
93
94 /**
95 * Constructor.
96 *
97 * @param log
98 * The logger to receive the lines
99 */
100 public StdoutConsumer(Log log) {
101 logger = log;
102 }
103
104 /**
105 * Consume a line.
106 *
107 * @param string
108 * The line to consume
109 */
110 public void consumeLine(String string) {
111 logger.info(string);
112 }
113 }
114
115 /**
116 * Consumer to receive lines sent to stderr. The lines are logged as
117 * warnings.
118 */
119 private class StderrConsumer implements StreamConsumer {
120 /** Logger to receive the lines. */
121 private Log logger;
122
123 /**
124 * Constructor.
125 *
126 * @param log
127 * The logger to receive the lines
128 */
129 public StderrConsumer(Log log) {
130 logger = log;
131 }
132
133 /**
134 * Consume a line.
135 *
136 * @param string
137 * The line to consume
138 */
139 public void consumeLine(String string) {
140 logger.warn(string);
141 }
142 }
143
144 }