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