]> 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
Use generator directly
[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 * @execute goal="env"
19 */
20 public class GenerateMojo extends AbstractMojo {
21 /**
22 * The Qooxdoo build target.
23 *
24 * @parameter expression="${job}"
25 * @required
26 */
27 private String job;
28
29 /**
30 * Location of the qooxdoo sdk.
31 *
32 * @parameter expression="${qooxdooSdk}"
33 */
34 private String qooxdooSdk = "src" + File.separator + "main"
35 + File.separator + "webapp" + File.separator + "qooxdoo-0.8-sdk";
36
37 /**
38 * The build directory.
39 *
40 * @parameter expression="${project.build.directory}"
41 * @required
42 */
43 private File buildDirectory;
44
45 /**
46 * The directory for the pom
47 *
48 * @parameter expression="${basedir}"
49 * @required
50 */
51 private File baseDir;
52
53 public void execute() throws MojoExecutionException, MojoFailureException {
54 try {
55 // File jythonBase = new File(buildDirectory, "jython");
56 // jythonBase.mkdirs();
57 // System.setProperty("python.home", jythonBase.getCanonicalPath());
58
59 File generateScript = new File(baseDir.getPath() + File.separator
60 + qooxdooSdk + File.separator + "tool" + File.separator
61 + "bin", "generator.py");
62 // String[] jobArray = jobs.split(" ");
63 // String[] args = new String[jobArray.length + 1];
64 // args[0] = generateScript.getCanonicalPath();
65 // System.arraycopy(jobArray, 0, args, 1, jobArray.length);
66 // String[] args = { "generate.py", job };
67 getLog().info("Running Qooxdoo job: " + job + " ...");
68 // jython.main(args);
69
70 Commandline cl = new Commandline();
71
72 if (File.separatorChar == '\\') {// win
73 File pythonBase = new File(buildDirectory, "python-win32")
74 .getCanonicalFile();
75 cl.setExecutable(pythonBase.getPath() + File.separator
76 + "python");
77 } else
78 cl.setExecutable("python");
79 cl.setWorkingDirectory(baseDir.getCanonicalPath());
80 cl.createArgument().setValue(generateScript.getCanonicalPath());
81 cl.createArgument().setValue(job);
82
83 StreamConsumer stdout = new StdoutConsumer(getLog());
84 StreamConsumer stderr = new StderrConsumer(getLog());
85 try {
86 int result = CommandLineUtils.executeCommandLine(cl, stdout,
87 stderr);
88 if (result != 0) {
89 throw new MojoExecutionException("Qooxdoo job returned: \'"
90 + result + "\'.");
91 }
92 } catch (CommandLineException e) {
93 throw new MojoExecutionException("Unable to run Qooxdoo job", e);
94 }
95 getLog().info("Finished Qooxdoo job: " + job);
96
97 } catch (Exception e) {
98 throw new MojoExecutionException(
99 "Unexpected exception when running Jython", e);
100 }
101
102 }
103
104 /**
105 * Consumer to receive lines sent to stdout. The lines are logged as info.
106 */
107 private class StdoutConsumer implements StreamConsumer {
108 /** Logger to receive the lines. */
109 private Log logger;
110
111 /**
112 * Constructor.
113 *
114 * @param log
115 * The logger to receive the lines
116 */
117 public StdoutConsumer(Log log) {
118 logger = log;
119 }
120
121 /**
122 * Consume a line.
123 *
124 * @param string
125 * The line to consume
126 */
127 public void consumeLine(String string) {
128 logger.info(string);
129 }
130 }
131
132 /**
133 * Consumer to receive lines sent to stderr. The lines are logged as
134 * warnings.
135 */
136 private class StderrConsumer implements StreamConsumer {
137 /** Logger to receive the lines. */
138 private Log logger;
139
140 /**
141 * Constructor.
142 *
143 * @param log
144 * The logger to receive the lines
145 */
146 public StderrConsumer(Log log) {
147 logger = log;
148 }
149
150 /**
151 * Consume a line.
152 *
153 * @param string
154 * The line to consume
155 */
156 public void consumeLine(String string) {
157 logger.warn(string);
158 }
159 }
160
161 }