New upstream version 1.4.0
Emmanuel Bourg
6 years ago
3 | 3 | <parent> |
4 | 4 | <groupId>org.codehaus.mojo</groupId> |
5 | 5 | <artifactId>mojo-parent</artifactId> |
6 | <version>33</version> | |
6 | <version>34</version> | |
7 | 7 | </parent> |
8 | 8 | |
9 | 9 | <artifactId>exec-maven-plugin</artifactId> |
10 | <version>1.3.1</version> | |
10 | <version>1.4.0</version> | |
11 | 11 | <packaging>maven-plugin</packaging> |
12 | 12 | |
13 | 13 | <name>Exec Maven Plugin</name> |
89 | 89 | </licenses> |
90 | 90 | |
91 | 91 | <scm> |
92 | <connection>scm:svn:http://svn.codehaus.org/mojo/tags/exec-maven-plugin-1.3.1</connection> | |
93 | <developerConnection>scm:svn:https://svn.codehaus.org/mojo/tags/exec-maven-plugin-1.3.1</developerConnection> | |
94 | <url>http://fisheye.codehaus.org/browse/mojo/tags/exec-maven-plugin-1.3.1</url> | |
92 | <connection>scm:svn:http://svn.codehaus.org/mojo/tags/exec-maven-plugin-1.4.0</connection> | |
93 | <developerConnection>scm:svn:https://svn.codehaus.org/mojo/tags/exec-maven-plugin-1.4.0</developerConnection> | |
94 | <url>http://fisheye.codehaus.org/browse/mojo/tags/exec-maven-plugin-1.4.0</url> | |
95 | 95 | </scm> |
96 | 96 | |
97 | 97 | <dependencies> |
134 | 134 | <dependency> |
135 | 135 | <groupId>org.codehaus.plexus</groupId> |
136 | 136 | <artifactId>plexus-utils</artifactId> |
137 | <version>3.0.15</version> | |
138 | </dependency> | |
139 | ||
140 | <dependency> | |
141 | <groupId>org.apache.maven.plugins</groupId> | |
142 | <artifactId>maven-plugin-plugin</artifactId> | |
143 | <version>3.2</version> | |
144 | </dependency> | |
137 | <version>3.0.20</version> | |
138 | </dependency> | |
139 | ||
145 | 140 | <dependency> |
146 | 141 | <groupId>org.apache.maven.plugin-tools</groupId> |
147 | 142 | <artifactId>maven-plugin-annotations</artifactId> |
148 | <version>3.2</version> | |
143 | <version>3.3</version> | |
149 | 144 | <scope>provided</scope> |
150 | 145 | </dependency> |
151 | 146 | |
152 | <!-- | |
153 | Needed to be updated after commons-exec 1.3 has been released. | |
154 | Details see: https://issues.apache.org/jira/browse/EXEC-80. | |
155 | --> | |
156 | 147 | <dependency> |
157 | 148 | <groupId>org.apache.commons</groupId> |
158 | 149 | <artifactId>commons-exec</artifactId> |
159 | <version>1.2</version> | |
150 | <version>1.3</version> | |
160 | 151 | </dependency> |
161 | 152 | |
162 | 153 | <dependency> |
168 | 159 | <dependency> |
169 | 160 | <groupId>org.codehaus.plexus</groupId> |
170 | 161 | <artifactId>plexus-interpolation</artifactId> |
171 | <version>1.19</version> | |
162 | <version>1.21</version> | |
172 | 163 | <scope>test</scope> |
173 | 164 | </dependency> |
174 | 165 | |
175 | 166 | </dependencies> |
176 | 167 | |
177 | 168 | <properties> |
178 | <mojo.java.target>1.5</mojo.java.target> | |
179 | <mavenVersion>2.0.6</mavenVersion> | |
169 | <mavenVersion>2.2.1</mavenVersion> | |
180 | 170 | </properties> |
181 | 171 | |
182 | 172 | <build> |
184 | 174 | <plugins> |
185 | 175 | <plugin> |
186 | 176 | <groupId>org.apache.maven.plugins</groupId> |
177 | <artifactId>maven-gpg-plugin</artifactId> | |
178 | <version>1.6</version> | |
179 | <configuration> | |
180 | <!-- Temporary solution to get a release out using gpg version 1 --> | |
181 | <useAgent>false</useAgent> | |
182 | </configuration> | |
183 | </plugin> | |
184 | <plugin> | |
185 | <groupId>org.apache.maven.plugins</groupId> | |
187 | 186 | <artifactId>maven-plugin-plugin</artifactId> |
188 | <version>3.2</version> | |
187 | <version>3.4</version> | |
189 | 188 | </plugin> |
190 | 189 | </plugins> |
191 | 190 | </pluginManagement> |
217 | 216 | </configuration> |
218 | 217 | <executions> |
219 | 218 | <execution> |
220 | <id>default-descriptor</id> | |
219 | <id>mojo-descriptor</id> | |
221 | 220 | <goals> |
222 | 221 | <goal>descriptor</goal> |
223 | 222 | </goals> |
224 | <phase>process-classes</phase> | |
225 | </execution> | |
226 | <execution> | |
227 | <id>help-mojo</id> | |
228 | <goals> | |
229 | <goal>helpmojo</goal> | |
230 | </goals> | |
231 | <phase>process-classes</phase> | |
232 | 223 | </execution> |
233 | 224 | </executions> |
234 | 225 | </plugin> |
235 | ||
236 | 226 | </plugins> |
237 | 227 | </build> |
228 | ||
238 | 229 | <profiles> |
239 | 230 | <profile> |
240 | 231 | <id>run-its</id> |
290 | 281 | <preBuildHookScript>setup</preBuildHookScript> |
291 | 282 | <postBuildHookScript>verify</postBuildHookScript> |
292 | 283 | <settingsFile>src/it/settings.xml</settingsFile> |
293 | <!-- Currently working with more than one thread does not work, cause it is not guaranteed that the setup-config project | |
294 | is build at first. see also http://jira.codehaus.org/browse/MINVOKER-147 --> | |
284 | <!-- Currently working with more than one thread does not work, cause it is not guaranteed that the setup-config | |
285 | project is build at first. see also http://jira.codehaus.org/browse/MINVOKER-147 --> | |
295 | 286 | <parallelThreads>1</parallelThreads> |
296 | 287 | </configuration> |
297 | 288 | <executions> |
25 | 25 | |
26 | 26 | t.checkExistenceAndContentOfAFile(buildLog, [ |
27 | 27 | "[DEBUG] (f) arguments = [-cp, target/classes, Main, null]", |
28 | "Caused by: org.apache.maven.plugin.MojoExecutionException: Misconfigured argument (4), value is null. Set the argument to an empty value if this is the required behaviour." | |
29 | 28 | ]) |
0 | invoker.goals = clean process-classes |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
3 | <modelVersion>4.0.0</modelVersion> | |
4 | ||
5 | <parent> | |
6 | <groupId>org.codehaus.mojo.exec.it</groupId> | |
7 | <artifactId>parent</artifactId> | |
8 | <version>0.1</version> | |
9 | </parent> | |
10 | ||
11 | <artifactId>mexec-104</artifactId> | |
12 | <version>0.0.1-SNAPSHOT</version> | |
13 | ||
14 | <properties> | |
15 | <my.val> </my.val> | |
16 | </properties> | |
17 | <build> | |
18 | <plugins> | |
19 | <plugin> | |
20 | <groupId>org.codehaus.mojo</groupId> | |
21 | <artifactId>exec-maven-plugin</artifactId> | |
22 | <version>@pom.version@</version> | |
23 | <executions> | |
24 | <execution> | |
25 | <phase>process-classes</phase> | |
26 | <goals> | |
27 | <goal>exec</goal> | |
28 | </goals> | |
29 | <configuration> | |
30 | <executable>java</executable> | |
31 | <failWithEmptyArgument>false</failWithEmptyArgument> | |
32 | <arguments> | |
33 | <argument>-cp</argument> | |
34 | <argument>target/classes</argument> | |
35 | <argument>Main</argument> | |
36 | <argument>${my.val}</argument> | |
37 | </arguments> | |
38 | </configuration> | |
39 | </execution> | |
40 | </executions> | |
41 | </plugin> | |
42 | </plugins> | |
43 | </build> | |
44 | </project> |
0 | import java.io.FileWriter; | |
1 | import java.io.Writer; | |
2 | import java.net.URL; | |
3 | ||
4 | public class Main | |
5 | { | |
6 | public static void main( String[] args ) throws Exception | |
7 | { | |
8 | System.out.println( "1. System.out line" ); | |
9 | System.err.println( "2. System.err line" ); | |
10 | System.out.println( "3. System.out line" ); | |
11 | System.err.println( "4. System.err line" ); | |
12 | System.out.println( "5. System.out line" ); | |
13 | } | |
14 | } |
0 | /* | |
1 | * Licensed to the Apache Software Foundation (ASF) under one | |
2 | * or more contributor license agreements. See the NOTICE file | |
3 | * distributed with this work for additional information | |
4 | * regarding copyright ownership. The ASF licenses this file | |
5 | * to you under the Apache License, Version 2.0 (the | |
6 | * "License"); you may not use this file except in compliance | |
7 | * with the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, | |
12 | * software distributed under the License is distributed on an | |
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | * KIND, either express or implied. See the License for the | |
15 | * specific language governing permissions and limitations | |
16 | * under the License. | |
17 | */ | |
18 | ||
19 | import java.io.* | |
20 | import java.util.* | |
21 | ||
22 | t = new IntegrationBase() | |
23 | ||
24 | def buildLog = new File( basedir, "build.log" ) | |
25 | ||
26 | t.checkExistenceAndContentOfAFile(buildLog, [ | |
27 | "[DEBUG] (f) arguments = [-cp, target/classes, Main, null]", | |
28 | "[DEBUG] (f) failWithEmptyArgument = false", | |
29 | "[DEBUG] Executing command line: [java, -cp, target/classes, Main, ]", | |
30 | ]) |
25 | 25 | |
26 | 26 | t.checkExistenceAndContentOfAFile(buildLog, [ |
27 | 27 | "[DEBUG] (f) environmentVariables = {key=null}", |
28 | "[DEBUG] (f) failWithEmptyArgument = true", | |
29 | 28 | "[DEBUG] (f) arguments = [-cp, target/classes, Main]", |
30 | "Caused by: org.apache.maven.plugin.MojoExecutionException: The defined environment contains an entry with null value (key:key). This could cause failures.", | |
31 | 29 | ]) |
0 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
1 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
2 | <modelVersion>4.0.0</modelVersion> | |
3 | ||
4 | <parent> | |
5 | <groupId>org.codehaus.mojo.exec.it</groupId> | |
6 | <artifactId>parent</artifactId> | |
7 | <version>0.1</version> | |
8 | </parent> | |
9 | ||
10 | <artifactId>mexec-108</artifactId> | |
11 | <version>0.0.1-SNAPSHOT</version> | |
12 | ||
13 | <build> | |
14 | <plugins> | |
15 | <plugin> | |
16 | <groupId>org.codehaus.mojo</groupId> | |
17 | <artifactId>exec-maven-plugin</artifactId> | |
18 | <version>@project.version@</version> | |
19 | <executions> | |
20 | <execution> | |
21 | <goals> | |
22 | <goal>exec</goal> | |
23 | </goals> | |
24 | <phase>process-classes</phase> | |
25 | <configuration> | |
26 | <failWithNullKeyOrValueInEnvironment>false</failWithNullKeyOrValueInEnvironment> | |
27 | <environmentVariables> | |
28 | <key>test</key> | |
29 | </environmentVariables> | |
30 | <executable>java</executable> | |
31 | <arguments> | |
32 | <argument>-cp</argument> | |
33 | <argument>target/classes</argument> | |
34 | <argument>Main</argument> | |
35 | </arguments> | |
36 | </configuration> | |
37 | </execution> | |
38 | </executions> | |
39 | </plugin> | |
40 | </plugins> | |
41 | </build> | |
42 | </project> |
0 | import java.io.FileWriter; | |
1 | import java.io.Writer; | |
2 | import java.net.URL; | |
3 | ||
4 | public class Main | |
5 | { | |
6 | public static void main( String[] args ) throws Exception | |
7 | { | |
8 | System.out.println( "1. System.out line" ); | |
9 | System.err.println( "2. System.err line" ); | |
10 | System.out.println( "3. System.out line" ); | |
11 | System.err.println( "4. System.err line" ); | |
12 | System.out.println( "5. System.out line" ); | |
13 | } | |
14 | } |
0 | /* | |
1 | * Licensed to the Apache Software Foundation (ASF) under one | |
2 | * or more contributor license agreements. See the NOTICE file | |
3 | * distributed with this work for additional information | |
4 | * regarding copyright ownership. The ASF licenses this file | |
5 | * to you under the Apache License, Version 2.0 (the | |
6 | * "License"); you may not use this file except in compliance | |
7 | * with the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, | |
12 | * software distributed under the License is distributed on an | |
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | * KIND, either express or implied. See the License for the | |
15 | * specific language governing permissions and limitations | |
16 | * under the License. | |
17 | */ | |
18 | ||
19 | import java.io.* | |
20 | import java.util.* | |
21 | ||
22 | t = new IntegrationBase() | |
23 | ||
24 | def buildLog = new File( basedir, "build.log" ) | |
25 | ||
26 | t.checkExistenceAndContentOfAFile(buildLog, [ | |
27 | "[DEBUG] (f) environmentVariables = {key=test}", | |
28 | "[DEBUG] (f) failWithEmptyArgument = true", | |
29 | "[DEBUG] (f) failWithNullKeyOrValueInEnvironment = false", | |
30 | "[DEBUG] (f) arguments = [-cp, target/classes, Main]", | |
31 | ]) |
78 | 78 | |
79 | 79 | if (mavenVersion.equals("2.0.11") || mavenVersion.equals("2.2.1")) { |
80 | 80 | t.checkExistenceAndContentOfAFile(buildLog, [ |
81 | "[DEBUG] (f) failWithEmptyArgument = true", | |
82 | 81 | "[DEBUG] (f) arguments = [-cp, target/classes, Main]", |
83 | 82 | "[INFO] [exec:exec {execution: first-execution}]", |
84 | 83 | "[INFO] [exec:exec {execution: second-execution}]", |
86 | 85 | ]) |
87 | 86 | } else { |
88 | 87 | t.checkExistenceAndContentOfAFile(buildLog, [ |
89 | "[DEBUG] (f) failWithEmptyArgument = true", | |
90 | 88 | "[DEBUG] (f) arguments = [-cp, target/classes, Main]", |
91 | 89 | "[INFO] --- exec-maven-plugin:" + pluginVersion + ":exec (first-execution) @ multiple-execution ---", |
92 | 90 | "[INFO] --- exec-maven-plugin:" + pluginVersion + ":exec (second-execution) @ multiple-execution ---", |
31 | 31 | /** |
32 | 32 | * This class is used for unifying functionality between the 2 mojo exec plugins ('java' and 'exec'). It handles parsing |
33 | 33 | * the arguments and adding source/test folders. |
34 | * | |
34 | * | |
35 | 35 | * @author Philippe Jacot (PJA) |
36 | 36 | * @author Jerome Lacoste |
37 | 37 | */ |
59 | 59 | private File testSourceRoot; |
60 | 60 | |
61 | 61 | /** |
62 | * Arguments for the executed program | |
62 | * Arguments separated by space for the executed program. For example: "-j 20" | |
63 | * | |
63 | 64 | */ |
64 | 65 | @Parameter( property = "exec.args" ) |
65 | 66 | private String commandlineArgs; |
73 | 74 | |
74 | 75 | /** |
75 | 76 | * Skip the execution. |
76 | * | |
77 | * Starting with version 1.4.0 the former name <code>skip</code> has been | |
78 | * changed into <code>exec.skip</code>. | |
77 | 79 | * @since 1.0.1 |
78 | 80 | */ |
79 | @Parameter( property = "skip", defaultValue = "false" ) | |
81 | //TODO: Remove the alias in version 1.5.0 of the plugin. | |
82 | @Parameter( property = "exec.skip", defaultValue = "false", alias="skip" ) | |
80 | 83 | private boolean skip; |
81 | 84 | |
82 | 85 | /** |
83 | 86 | * Collects the project artifacts in the specified List and the project specific classpath (build output and build |
84 | 87 | * test output) Files in the specified List, depending on the plugin classpathScope value. |
85 | * | |
88 | * | |
86 | 89 | * @param artifacts the list where to collect the scope specific artifacts |
87 | 90 | * @param theClasspathFiles the list where to collect the scope specific output directories |
88 | 91 | */ |
123 | 126 | * Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER. |
124 | 127 | * PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using |
125 | 128 | * ESCAPE_CHAR. |
126 | * | |
129 | * | |
127 | 130 | * @return Array of String representing the arguments |
128 | 131 | * @throws MojoExecutionException for wrong formatted arguments |
129 | 132 | */ |
175 | 178 | |
176 | 179 | /** |
177 | 180 | * Check if the execution should be skipped |
178 | * | |
181 | * | |
179 | 182 | * @return true to skip |
180 | 183 | */ |
181 | 184 | protected boolean isSkip() |
215 | 215 | * @deprecated since 1.1-alpha-1 |
216 | 216 | * @since 1.0 |
217 | 217 | */ |
218 | @Parameter( property = "exec.killAfter", defaultValue = "1" ) | |
218 | @Parameter( property = "exec.killAfter", defaultValue = "-1" ) | |
219 | 219 | @Deprecated |
220 | 220 | private long killAfter; |
221 | 221 |
50 | 50 | import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter; |
51 | 51 | import org.apache.maven.execution.MavenSession; |
52 | 52 | import org.apache.maven.plugin.MojoExecutionException; |
53 | import org.apache.maven.plugins.annotations.Component; | |
54 | 53 | import org.apache.maven.plugins.annotations.Mojo; |
55 | 54 | import org.apache.maven.plugins.annotations.Parameter; |
56 | 55 | import org.apache.maven.plugins.annotations.ResolutionScope; |
128 | 127 | * @since 1.0 |
129 | 128 | */ |
130 | 129 | @Parameter |
131 | private List<?> arguments; // TODO: Change ? into something more meaningfull | |
132 | ||
133 | /** | |
134 | * <p> | |
135 | * This will control if you like to fail the build if an arguments element is empty. This means that for arguments | |
136 | * which would evaluate to <code>Null</code> an <code>""</code> empty string will be added to the command line of | |
137 | * the {@code executable} which will be called. | |
138 | * </p> | |
139 | * | |
140 | * @since 1.3 | |
141 | * @see #arguments | |
142 | */ | |
143 | @Parameter( defaultValue = "true" ) | |
144 | private boolean failWithEmptyArgument; // TODO: Remove this related to http://jira.codehaus.org/browse/MEXEC-127 | |
145 | ||
146 | /** | |
147 | * <p> | |
148 | * The following will control if you like to get a warning during the build if an entry either key/value of | |
149 | * environmentVariables will be evaluated to <code>Null</code> an <code>""</code> empty string will be used instead. | |
150 | * </p> | |
151 | * | |
152 | * @since 1.3 | |
153 | * @see #environmentVariables | |
154 | */ | |
155 | @Parameter( defaultValue = "true" ) | |
156 | private boolean failWithNullKeyOrValueInEnvironment; // TODO: Remove this related to | |
157 | // http://jira.codehaus.org/browse/MEXEC-127 | |
130 | private List<?> arguments; // TODO: Change ? into something more meaningful | |
158 | 131 | |
159 | 132 | /** |
160 | 133 | * @since 1.0 |
183 | 156 | /** |
184 | 157 | * The current build session instance. This is used for toolchain manager API calls. |
185 | 158 | */ |
186 | @Component | |
159 | @Parameter( defaultValue = "${session}", readonly = true ) | |
187 | 160 | private MavenSession session; |
188 | 161 | |
189 | 162 | /** |
319 | 292 | throws MojoExecutionException |
320 | 293 | { |
321 | 294 | |
322 | validateEnvironmentVars(); | |
323 | ||
324 | 295 | Map<String, String> enviro = new HashMap<String, String>(); |
325 | 296 | try |
326 | 297 | { |
361 | 332 | } |
362 | 333 | |
363 | 334 | return enviro; |
364 | } | |
365 | ||
366 | private void validateEnvironmentVars() | |
367 | throws MojoExecutionException | |
368 | { | |
369 | if ( environmentVariables != null ) | |
370 | { | |
371 | for ( Map.Entry<String, String> item : environmentVariables.entrySet() ) | |
372 | { | |
373 | getLog().debug( "Entry: key:" + item.getKey() + " value:" + item.getValue() ); | |
374 | ||
375 | // The following checks are only in relationship with MEXEC-108 | |
376 | // (https://issues.apache.org/jira/browse/EXEC-80) | |
377 | if ( item.getKey() == null ) | |
378 | { | |
379 | if ( failWithNullKeyOrValueInEnvironment ) | |
380 | { | |
381 | throw new MojoExecutionException( | |
382 | "The defined environment contains an entry with null key. This could cause failures." ); | |
383 | } | |
384 | else | |
385 | { | |
386 | getLog().warn( "The defined environment contains an entry with null key. This could cause failures." ); | |
387 | } | |
388 | } | |
389 | if ( item.getValue() == null ) | |
390 | { | |
391 | if ( failWithNullKeyOrValueInEnvironment ) | |
392 | { | |
393 | throw new MojoExecutionException( | |
394 | "The defined environment contains an entry with null value (key:" | |
395 | + item.getKey() + "). This could cause failures." ); | |
396 | } | |
397 | else | |
398 | { | |
399 | getLog().warn( "The defined environment contains an entry with null value (key:" | |
400 | + item.getKey() + "). This could cause failures." ); | |
401 | } | |
402 | } | |
403 | } | |
404 | ||
405 | } | |
406 | 335 | } |
407 | 336 | |
408 | 337 | /** |
482 | 411 | { |
483 | 412 | Object argument = arguments.get( i ); |
484 | 413 | String arg; |
485 | if ( argument == null ) | |
486 | { | |
487 | if ( failWithEmptyArgument ) | |
488 | { | |
489 | throw new MojoExecutionException( "Misconfigured argument (" + ( i + 1 ) + "), value is null. " | |
490 | + "Set the argument to an empty value if this is the required behaviour." ); | |
491 | ||
492 | } | |
493 | else | |
494 | { | |
495 | // Just add an empty string to the argument list. | |
496 | commandArguments.add( "" ); | |
497 | } | |
498 | } | |
499 | else if ( argument instanceof String && isLongClassPathArgument( (String) argument ) ) | |
414 | if ( argument instanceof String && isLongClassPathArgument( (String) argument ) ) | |
500 | 415 | { |
501 | 416 | // it is assumed that starting from -cp or -classpath the arguments |
502 | 417 | // are: -classpath/-cp %classpath mainClass |
517 | 432 | } |
518 | 433 | else |
519 | 434 | { |
520 | arg = argument.toString(); | |
521 | commandArguments.add( arg ); | |
435 | commandArguments.add( (String)argument ); | |
522 | 436 | } |
523 | 437 | } |
524 | 438 | } |
729 | 643 | return paths; |
730 | 644 | } |
731 | 645 | |
646 | ||
647 | protected int executeCommandLine( Executor exec, CommandLine commandLine, Map<String, String> enviro, | |
648 | OutputStream out, OutputStream err ) | |
649 | throws ExecuteException, IOException | |
650 | { | |
651 | //note: dont use BufferedOutputStream here since it delays the outputs MEXEC-138 | |
652 | PumpStreamHandler psh = new PumpStreamHandler( out, err, System.in ); | |
653 | exec.setStreamHandler( psh ); | |
654 | ||
655 | int result; | |
656 | try | |
657 | { | |
658 | psh.start(); | |
659 | result = exec.execute( commandLine, enviro ); | |
660 | } | |
661 | finally | |
662 | { | |
663 | psh.stop(); | |
664 | } | |
665 | return result; | |
666 | } | |
667 | ||
668 | protected int executeCommandLine( Executor exec, CommandLine commandLine, Map<String, String> enviro, | |
669 | FileOutputStream outputFile ) | |
670 | throws ExecuteException, IOException | |
671 | { | |
672 | BufferedOutputStream bos = new BufferedOutputStream( outputFile ); | |
673 | PumpStreamHandler psh = new PumpStreamHandler( bos ); | |
674 | exec.setStreamHandler( psh ); | |
675 | ||
676 | int result; | |
677 | try | |
678 | { | |
679 | psh.start(); | |
680 | result = exec.execute( commandLine, enviro ); | |
681 | } | |
682 | finally | |
683 | { | |
684 | psh.stop(); | |
685 | } | |
686 | return result; | |
687 | } | |
688 | ||
732 | 689 | // |
733 | 690 | // methods used for tests purposes - allow mocking and simulate automatic setters |
734 | 691 | // |
735 | ||
736 | protected int executeCommandLine( Executor exec, CommandLine commandLine, Map<String, String> enviro, | |
737 | OutputStream out, OutputStream err ) | |
738 | throws ExecuteException, IOException | |
739 | { | |
740 | BufferedOutputStream bosStdOut = new BufferedOutputStream( out ); | |
741 | BufferedOutputStream bosStdErr = new BufferedOutputStream( err ); | |
742 | PumpStreamHandler psh = new PumpStreamHandler( bosStdOut, bosStdErr, System.in ); | |
743 | exec.setStreamHandler( psh ); | |
744 | ||
745 | int result; | |
746 | try | |
747 | { | |
748 | psh.start(); | |
749 | result = exec.execute( commandLine, enviro ); | |
750 | } | |
751 | finally | |
752 | { | |
753 | psh.stop(); | |
754 | } | |
755 | return result; | |
756 | } | |
757 | ||
758 | protected int executeCommandLine( Executor exec, CommandLine commandLine, Map<String, String> enviro, | |
759 | FileOutputStream outputFile ) | |
760 | throws ExecuteException, IOException | |
761 | { | |
762 | BufferedOutputStream bos = new BufferedOutputStream( outputFile ); | |
763 | PumpStreamHandler psh = new PumpStreamHandler( bos ); | |
764 | exec.setStreamHandler( psh ); | |
765 | ||
766 | int result; | |
767 | try | |
768 | { | |
769 | psh.start(); | |
770 | result = exec.execute( commandLine, enviro ); | |
771 | } | |
772 | finally | |
773 | { | |
774 | psh.stop(); | |
775 | } | |
776 | return result; | |
777 | } | |
778 | 692 | |
779 | 693 | void setExecutable( String executable ) |
780 | 694 | { |