]> git.argeo.org Git - gpl/argeo-slc.git/blob - maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java
v0.8.0.5
[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 jythonBase = new File(buildDirectory, "jython");
55 // jythonBase.mkdirs();
56 // System.setProperty("python.home", jythonBase.getCanonicalPath());
57
58 File generateScript = new File(baseDir.getPath() + File.separator
59 + qooxdooSdk + File.separator + "tool" + File.separator
60 + "bin", "generator.py");
61 // String[] jobArray = jobs.split(" ");
62 // String[] args = new String[jobArray.length + 1];
63 // args[0] = generateScript.getCanonicalPath();
64 // System.arraycopy(jobArray, 0, args, 1, jobArray.length);
65 // String[] args = { "generate.py", job };
66 getLog().info("Running Qooxdoo job: " + job + " ...");
67 // jython.main(args);
68
69 Commandline cl = new Commandline();
70
71 if (File.separatorChar == '\\') {// win
72 File pythonBase = new File(buildDirectory, "python-win32")
73 .getCanonicalFile();
74 cl.setExecutable(pythonBase.getPath() + File.separator
75 + "python");
76 } else
77 cl.setExecutable("python");
78 cl.setWorkingDirectory(baseDir.getCanonicalPath());
79 cl.createArgument().setValue(generateScript.getCanonicalPath());
80 cl.createArgument().setValue(job);
81
82 StreamConsumer stdout = new StdoutConsumer(getLog());
83 StreamConsumer stderr = new StderrConsumer(getLog());
84 try {
85 int result = CommandLineUtils.executeCommandLine(cl, stdout,
86 stderr);
87 if (result != 0) {
88 throw new MojoExecutionException("Qooxdoo job returned: \'"
89 + result + "\'.");
90 }
91 } catch (CommandLineException e) {
92 throw new MojoExecutionException("Unable to run Qooxdoo job", e);
93 }
94 getLog().info("Finished Qooxdoo job: " + job);
95
96 } catch (Exception e) {
97 throw new MojoExecutionException(
98 "Unexpected exception when running Jython", e);
99 }
100
101 }
102
103 /**
104 * Consumer to receive lines sent to stdout. The lines are logged as info.
105 */
106 private class StdoutConsumer implements StreamConsumer {
107 /** Logger to receive the lines. */
108 private Log logger;
109
110 /**
111 * Constructor.
112 *
113 * @param log
114 * The logger to receive the lines
115 */
116 public StdoutConsumer(Log log) {
117 logger = log;
118 }
119
120 /**
121 * Consume a line.
122 *
123 * @param string
124 * The line to consume
125 */
126 public void consumeLine(String string) {
127 logger.info(string);
128 }
129 }
130
131 /**
132 * Consumer to receive lines sent to stderr. The lines are logged as
133 * warnings.
134 */
135 private class StderrConsumer implements StreamConsumer {
136 /** Logger to receive the lines. */
137 private Log logger;
138
139 /**
140 * Constructor.
141 *
142 * @param log
143 * The logger to receive the lines
144 */
145 public StderrConsumer(Log log) {
146 logger = log;
147 }
148
149 /**
150 * Consume a line.
151 *
152 * @param string
153 * The line to consume
154 */
155 public void consumeLine(String string) {
156 logger.warn(string);
157 }
158 }
159
160 }