Codebase list exec-maven-plugin / fb61948
New upstream version 1.4.0 Emmanuel Bourg 6 years ago
17 changed file(s) with 86 addition(s) and 367 deletion(s). Raw diff Collapse all Expand all
33 <parent>
44 <groupId>org.codehaus.mojo</groupId>
55 <artifactId>mojo-parent</artifactId>
6 <version>33</version>
6 <version>34</version>
77 </parent>
88
99 <artifactId>exec-maven-plugin</artifactId>
10 <version>1.3.1</version>
10 <version>1.4.0</version>
1111 <packaging>maven-plugin</packaging>
1212
1313 <name>Exec Maven Plugin</name>
8989 </licenses>
9090
9191 <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>
9595 </scm>
9696
9797 <dependencies>
134134 <dependency>
135135 <groupId>org.codehaus.plexus</groupId>
136136 <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
145140 <dependency>
146141 <groupId>org.apache.maven.plugin-tools</groupId>
147142 <artifactId>maven-plugin-annotations</artifactId>
148 <version>3.2</version>
143 <version>3.3</version>
149144 <scope>provided</scope>
150145 </dependency>
151146
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 -->
156147 <dependency>
157148 <groupId>org.apache.commons</groupId>
158149 <artifactId>commons-exec</artifactId>
159 <version>1.2</version>
150 <version>1.3</version>
160151 </dependency>
161152
162153 <dependency>
168159 <dependency>
169160 <groupId>org.codehaus.plexus</groupId>
170161 <artifactId>plexus-interpolation</artifactId>
171 <version>1.19</version>
162 <version>1.21</version>
172163 <scope>test</scope>
173164 </dependency>
174165
175166 </dependencies>
176167
177168 <properties>
178 <mojo.java.target>1.5</mojo.java.target>
179 <mavenVersion>2.0.6</mavenVersion>
169 <mavenVersion>2.2.1</mavenVersion>
180170 </properties>
181171
182172 <build>
184174 <plugins>
185175 <plugin>
186176 <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>
187186 <artifactId>maven-plugin-plugin</artifactId>
188 <version>3.2</version>
187 <version>3.4</version>
189188 </plugin>
190189 </plugins>
191190 </pluginManagement>
217216 </configuration>
218217 <executions>
219218 <execution>
220 <id>default-descriptor</id>
219 <id>mojo-descriptor</id>
221220 <goals>
222221 <goal>descriptor</goal>
223222 </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>
232223 </execution>
233224 </executions>
234225 </plugin>
235
236226 </plugins>
237227 </build>
228
238229 <profiles>
239230 <profile>
240231 <id>run-its</id>
290281 <preBuildHookScript>setup</preBuildHookScript>
291282 <postBuildHookScript>verify</postBuildHookScript>
292283 <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 -->
295286 <parallelThreads>1</parallelThreads>
296287 </configuration>
297288 <executions>
00 invoker.goals = clean package
1 invoker.buildResult = failure
1 invoker.buildResult = success
2525
2626 t.checkExistenceAndContentOfAFile(buildLog, [
2727 "[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."
2928 ])
+0
-1
src/it/mexec-104-nonfailing/invoker.properties less more
0 invoker.goals = clean process-classes
+0
-45
src/it/mexec-104-nonfailing/pom.xml less more
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
-15
src/it/mexec-104-nonfailing/src/main/java/Main.java less more
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
-31
src/it/mexec-104-nonfailing/verify.groovy less more
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 ])
00 invoker.goals = clean package
1 invoker.buildResult = failure
1 invoker.buildResult = success
2525
2626 t.checkExistenceAndContentOfAFile(buildLog, [
2727 "[DEBUG] (f) environmentVariables = {key=null}",
28 "[DEBUG] (f) failWithEmptyArgument = true",
2928 "[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.",
3129 ])
+0
-2
src/it/mexec-108-failWithNullKeyOrValueInEnvironment-false/invoker.properties less more
0 invoker.goals = clean package
1 invoker.buildResult = success
+0
-43
src/it/mexec-108-failWithNullKeyOrValueInEnvironment-false/pom.xml less more
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
-15
src/it/mexec-108-failWithNullKeyOrValueInEnvironment-false/src/main/java/Main.java less more
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
-32
src/it/mexec-108-failWithNullKeyOrValueInEnvironment-false/verify.groovy less more
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 ])
7878
7979 if (mavenVersion.equals("2.0.11") || mavenVersion.equals("2.2.1")) {
8080 t.checkExistenceAndContentOfAFile(buildLog, [
81 "[DEBUG] (f) failWithEmptyArgument = true",
8281 "[DEBUG] (f) arguments = [-cp, target/classes, Main]",
8382 "[INFO] [exec:exec {execution: first-execution}]",
8483 "[INFO] [exec:exec {execution: second-execution}]",
8685 ])
8786 } else {
8887 t.checkExistenceAndContentOfAFile(buildLog, [
89 "[DEBUG] (f) failWithEmptyArgument = true",
9088 "[DEBUG] (f) arguments = [-cp, target/classes, Main]",
9189 "[INFO] --- exec-maven-plugin:" + pluginVersion + ":exec (first-execution) @ multiple-execution ---",
9290 "[INFO] --- exec-maven-plugin:" + pluginVersion + ":exec (second-execution) @ multiple-execution ---",
3131 /**
3232 * This class is used for unifying functionality between the 2 mojo exec plugins ('java' and 'exec'). It handles parsing
3333 * the arguments and adding source/test folders.
34 *
34 *
3535 * @author Philippe Jacot (PJA)
3636 * @author Jerome Lacoste
3737 */
5959 private File testSourceRoot;
6060
6161 /**
62 * Arguments for the executed program
62 * Arguments separated by space for the executed program. For example: "-j 20"
63 *
6364 */
6465 @Parameter( property = "exec.args" )
6566 private String commandlineArgs;
7374
7475 /**
7576 * 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>.
7779 * @since 1.0.1
7880 */
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" )
8083 private boolean skip;
8184
8285 /**
8386 * Collects the project artifacts in the specified List and the project specific classpath (build output and build
8487 * test output) Files in the specified List, depending on the plugin classpathScope value.
85 *
88 *
8689 * @param artifacts the list where to collect the scope specific artifacts
8790 * @param theClasspathFiles the list where to collect the scope specific output directories
8891 */
123126 * Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER.
124127 * PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using
125128 * ESCAPE_CHAR.
126 *
129 *
127130 * @return Array of String representing the arguments
128131 * @throws MojoExecutionException for wrong formatted arguments
129132 */
175178
176179 /**
177180 * Check if the execution should be skipped
178 *
181 *
179182 * @return true to skip
180183 */
181184 protected boolean isSkip()
215215 * @deprecated since 1.1-alpha-1
216216 * @since 1.0
217217 */
218 @Parameter( property = "exec.killAfter", defaultValue = "1" )
218 @Parameter( property = "exec.killAfter", defaultValue = "-1" )
219219 @Deprecated
220220 private long killAfter;
221221
5050 import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter;
5151 import org.apache.maven.execution.MavenSession;
5252 import org.apache.maven.plugin.MojoExecutionException;
53 import org.apache.maven.plugins.annotations.Component;
5453 import org.apache.maven.plugins.annotations.Mojo;
5554 import org.apache.maven.plugins.annotations.Parameter;
5655 import org.apache.maven.plugins.annotations.ResolutionScope;
128127 * @since 1.0
129128 */
130129 @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
158131
159132 /**
160133 * @since 1.0
183156 /**
184157 * The current build session instance. This is used for toolchain manager API calls.
185158 */
186 @Component
159 @Parameter( defaultValue = "${session}", readonly = true )
187160 private MavenSession session;
188161
189162 /**
319292 throws MojoExecutionException
320293 {
321294
322 validateEnvironmentVars();
323
324295 Map<String, String> enviro = new HashMap<String, String>();
325296 try
326297 {
361332 }
362333
363334 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 }
406335 }
407336
408337 /**
482411 {
483412 Object argument = arguments.get( i );
484413 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 ) )
500415 {
501416 // it is assumed that starting from -cp or -classpath the arguments
502417 // are: -classpath/-cp %classpath mainClass
517432 }
518433 else
519434 {
520 arg = argument.toString();
521 commandArguments.add( arg );
435 commandArguments.add( (String)argument );
522436 }
523437 }
524438 }
729643 return paths;
730644 }
731645
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
732689 //
733690 // methods used for tests purposes - allow mocking and simulate automatic setters
734691 //
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 }
778692
779693 void setExecutable( String executable )
780694 {