./0000755000175000017500000000000011312304563010235 5ustar user03user03./src/0000755000175000017500000000000011303510553011022 5ustar user03user03./src/test/0000755000175000017500000000000011303510551011777 5ustar user03user03./src/test/repository/0000755000175000017500000000000011303510550014215 5ustar user03user03./src/test/repository/commons-io/0000755000175000017500000000000011303510550016275 5ustar user03user03./src/test/repository/commons-io/commons-io/0000755000175000017500000000000011303510551020356 5ustar user03user03./src/test/repository/commons-io/commons-io/commons-io/0000755000175000017500000000000011303510551022436 5ustar user03user03./src/test/repository/commons-io/commons-io/commons-io/1.1/0000755000175000017500000000000011303510551022735 5ustar user03user03./src/test/repository/commons-io/commons-io/commons-io/1.1/commons-io-1.1.pom0000644000175000017500000001345711303510551026041 0ustar user03user03 4.0.0 commons-io commons-io IO 1.1 Commons-IO contains utility classes, stream implementations, file filters, and endian classes. http://jakarta.apache.org/commons/io/ http://issues.apache.org/bugzilla/
commons-dev@jakarta.apache.org
2002 Commons Dev List commons-dev-subscribe@jakarta.apache.org commons-dev-unsubscribe@jakarta.apache.org http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-dev@jakarta.apache.org Commons User List commons-user-subscribe@jakarta.apache.org commons-user-unsubscribe@jakarta.apache.org http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-user@jakarta.apache.org sanders Scott Sanders sanders@apache.org Java Developer dion dIon Gillard dion@apache.org Java Developer nicolaken Nicola Ken Barozzi nicolaken@apache.org Java Developer bayard Henri Yandell bayard@apache.org Java Developer scolebourne Stephen Colebourne Java Developer 0 jeremias Jeremias Maerki jeremias@apache.org Java Developer +1 matth Matthew Hawthorne matth@apache.org Java Developer martinc Martin Cooper martinc@apache.org Java Developer roxspring Rob Oxspring roxspring@apache.org Java Developer Jason Anderson Nathan Beyer Chris Eldredge Andy Lehane Marcelo Liberato Alban Peignier alban.peignier at free.fr Ian Springer Masato Tezuka Frank W. Zammetti The Apache Software License, Version 2.0 /LICENSE.txt scm:svn:http://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk http://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk The Apache Software Foundation http://jakarta.apache.org src/java src/test META-INF . NOTICE.txt surefire **/*Test* **/*AbstractTestCase* **/AllIOTestSuite* **/PackageTestSuite* **/testtools/** default Default Repository file:///www/jakarta.apache.org/builds/jakarta-commons/io/ default Default Site scp://jakarta.apache.org//www/jakarta.apache.org/commons/io/
./src/test/repository/commons-io/commons-io/1.1/0000755000175000017500000000000011303510551020655 5ustar user03user03./src/test/repository/commons-io/commons-io/1.1/commons-io-1.1.pom0000644000175000017500000001345711303510551023761 0ustar user03user03 4.0.0 commons-io commons-io IO 1.1 Commons-IO contains utility classes, stream implementations, file filters, and endian classes. http://jakarta.apache.org/commons/io/ http://issues.apache.org/bugzilla/
commons-dev@jakarta.apache.org
2002 Commons Dev List commons-dev-subscribe@jakarta.apache.org commons-dev-unsubscribe@jakarta.apache.org http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-dev@jakarta.apache.org Commons User List commons-user-subscribe@jakarta.apache.org commons-user-unsubscribe@jakarta.apache.org http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-user@jakarta.apache.org sanders Scott Sanders sanders@apache.org Java Developer dion dIon Gillard dion@apache.org Java Developer nicolaken Nicola Ken Barozzi nicolaken@apache.org Java Developer bayard Henri Yandell bayard@apache.org Java Developer scolebourne Stephen Colebourne Java Developer 0 jeremias Jeremias Maerki jeremias@apache.org Java Developer +1 matth Matthew Hawthorne matth@apache.org Java Developer martinc Martin Cooper martinc@apache.org Java Developer roxspring Rob Oxspring roxspring@apache.org Java Developer Jason Anderson Nathan Beyer Chris Eldredge Andy Lehane Marcelo Liberato Alban Peignier alban.peignier at free.fr Ian Springer Masato Tezuka Frank W. Zammetti The Apache Software License, Version 2.0 /LICENSE.txt scm:svn:http://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk http://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk The Apache Software Foundation http://jakarta.apache.org src/java src/test META-INF . NOTICE.txt surefire **/*Test* **/*AbstractTestCase* **/AllIOTestSuite* **/PackageTestSuite* **/testtools/** default Default Repository file:///www/jakarta.apache.org/builds/jakarta-commons/io/ default Default Site scp://jakarta.apache.org//www/jakarta.apache.org/commons/io/
./src/test/java/0000755000175000017500000000000011303510551012720 5ustar user03user03./src/test/java/org/0000755000175000017500000000000011303510551013507 5ustar user03user03./src/test/java/org/codehaus/0000755000175000017500000000000011303510551015302 5ustar user03user03./src/test/java/org/codehaus/mojo/0000755000175000017500000000000011303510551016246 5ustar user03user03./src/test/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510551017172 5ustar user03user03./src/test/java/org/codehaus/mojo/exec/ExecMojoArgsTest.java0000644000175000017500000000000011303510551023211 0ustar user03user03./src/test/java/org/codehaus/mojo/exec/FindClassInClasspath.java0000644000175000017500000000174411303510551024043 0ustar user03user03package org.codehaus.mojo.exec; import java.util.Timer; import java.util.TimerTask; /** * @author Jerome Lacoste */ public class FindClassInClasspath { public static final String FOUND_ALL = "OK"; /** * @param args the names of classes to search in the classpath * prints 'OK' if all classes found **/ public static void main( String[] args ) { for (int i = 0; i < args.length; i++) { if ( ! isClassInClasspath( args[i] )) { System.out.println( "ERROR: class + " + args[i] + " not found in classpath" ); System.exit( 1 ); } } System.out.println( FOUND_ALL ); } private static boolean isClassInClasspath( String className ) { try { Class.forName( className ); return true; } catch ( Exception e ) { System.out.println( "ERROR: " + e.getMessage() ); return false; } } } ./src/test/java/org/codehaus/mojo/exec/NoMain.java0000644000175000017500000000160411303510551021217 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jerome Lacoste * @version $Id: NoMain.java 6588 2008-03-28 12:22:57Z bentmann $ */ public class NoMain { // MEXEC-29 wrong interface for main method causes NPE public static void main( ) throws Exception { } } ./src/test/java/org/codehaus/mojo/exec/MainWithThreads.java0000644000175000017500000000441411303510551023073 0ustar user03user03package org.codehaus.mojo.exec; import java.util.Timer; import java.util.TimerTask; /** * @author David Smiley */ public class MainWithThreads extends Thread { public static final String ALL_EXITED = "t1(interrupted td)(cancelled timer)"; public static final String TIMER_IGNORED = "t1(interrupted td)"; /** * both daemon threads will be interrupted as soon as the non daemon thread is done. * the responsive daemon thread will be interrupted right away. * - if the timer is cancelled (using 'cancelTimer' as argument), the timer will die on itself * after all the other threads * - if not, one must use a time out to stop joining on that unresponsive daemon thread **/ public static void main( String[] args ) { // long run so that we interrupt it before it ends itself Thread responsiveDaemonThread = new MainWithThreads( 60000, "td" ); responsiveDaemonThread.setDaemon( true ); responsiveDaemonThread.start(); new MainWithThreads( 200, "t1" ).start(); // Timer in Java <= 6 aren't interruptible final Timer t = new Timer( true ); if ( optionsContains( args, "cancelTimer" ) ) { t.schedule( new TimerTask() { public void run() { System.out.print( "(cancelled timer)" ); t.cancel(); } }, 400 ); } } private static boolean optionsContains( String[] args, String option ) { for (int i = 0; i < args.length; i++ ) { if ( args[i].equals( option ) ) return true; } return false; } private int millisecsToSleep; private String message; public MainWithThreads( int millisecsToSleep, String message ) { this.millisecsToSleep = millisecsToSleep; this.message = message; } public void run() { try { Thread.sleep( millisecsToSleep ); } catch ( InterruptedException e ) // IE's are a way to cancel a thread { System.out.print( "(interrupted " + message + ")" ); return; } System.out.print( message ); } } ./src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java0000644000175000017500000002336011303510551023214 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.monitor.logging.DefaultLog; import org.codehaus.plexus.util.StringOutputStream; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import java.io.File; import java.io.PrintStream; /** * @author Jerome Lacoste * @version $Id: ExecJavaMojoTest.java 6914 2008-05-07 21:44:49Z lacostej $ */ public class ExecJavaMojoTest extends AbstractMojoTestCase { /* This one won't work yet public void xxtestSimpleRunPropertiesAndArguments() throws MojoExecutionException, Exception { File pom = new File( getBasedir(), "src/test/projects/project2/pom.xml" ); String output = execute( pom, "java" ); System.out.println(output); assertEquals( -1, output.trim().indexOf( "ERROR" ) ); } */ /** * Check that a simple execution with no arguments and no system properties produces the expected result *

* we load the config from a pom file and fill up the MavenProject property ourselves */ public void testSimpleRun() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project4/pom.xml" ); String output = execute( pom, "java" ); assertEquals( "Hello" + System.getProperty( "line.separator" ), output ); } /** * MEXEC-10 Check that an execution with no arguments and an system property with no value * produces the expected result *

* we load the config from a pom file and fill up the MavenProject property ourselves */ public void testEmptySystemProperty() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project5/pom.xml" ); assertNull( "System property not yet created", System.getProperty( "project5.property.with.no.value" ) ); execute( pom, "java" ); assertEquals( "System property now empty", "", System.getProperty( "project5.property.with.no.value" ) ); } /** * MEXEC-29 exec:java throws NPE if the mainClass main method has not a correct signature *

*/ public void testIncorrectMainMethodSignature() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project12/pom.xml" ); try { String output = execute( pom, "java" ); } catch (MojoExecutionException e) { assertTrue( stringContains( e.getMessage(), "The specified mainClass doesn't contain a main method with appropriate signature." ) ); } } // this test doesn't work as the classpath passed to the project when executing the POM isn't the same as when maven is executed from within the project dir // Should be moved as an integration-test /* public void testSetClasspathScopeToTest() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project14/pom.xml" ); String output = execute( pom, "java" ); assertEquals( "Hello" + System.getProperty( "line.separator" ), output ); } */ // java 1.4 compatibility private boolean stringContains( String str, String sequence ) { return str.indexOf( sequence ) != -1; } /** * For cases where the Java code spawns Threads and main returns soon. * See MEXEC-6. */ public void testWaitNoDaemonThreads() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project7/pom.xml" ); String output = execute( pom, "java" ); assertEquals( MainWithThreads.ALL_EXITED, output.trim() ); } /** * For cases where the Java code spawns Threads and main returns soon, but code contains non interruptible threads. * User is required to timeout the execution, otherwise it will hang. * See MEXEC-15. */ public void testWaitNonInterruptibleDaemonThreads() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project9/pom.xml" ); String output = execute( pom, "java" ); assertEquals( MainWithThreads.TIMER_IGNORED, output.trim() ); } /** * See MEXEC-15. * FIXME: this sometimes fail with unit.framework.ComparisonFailure: expected:<...> but was:<...3(f)> */ public void testUncooperativeThread() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project10/pom.xml" ); String output = execute( pom, "java" ); // note: execute() will wait a little bit before returning the output, // thereby allowing the stop()'ed thread to output the final "(f)". assertEquals( MainUncooperative.SUCCESS, output.trim() ); } /** * See MEXEC-17. */ /** This test doesn't work because the sun.tools.javac.Main class referenced in the project pom is found even if the system scope dependencies are not added by the plugin. The class was probably loaded by another plugin ?! To fix the test we have to: - maybe use a different system scope dependency/class to load. - find a different way to test. When ran manually, the test works though (i.e. removing the code that manually adds the system scope dependencies make the test fail). public void testSystemDependencyFound() throws Exception { File pom = new File( getBasedir(), "src/test/projects/project11/pom.xml" ); String output = execute( pom, "java" ); assertEquals( FindClassInClasspath.FOUND_ALL, output.trim() ); } */ /** * Test the commandline parsing facilities of the {@link AbstractExecMojo} class */ public void testRunWithArgs() throws Exception { String resultString = execute( new File( getBasedir(), "src/test/projects/project8/pom.xml" ), "java" ); String LS = System.getProperty("line.separator"); String expectedResult = "Hello" + LS + "Arg1" + LS +"Arg2a Arg2b" + LS; assertEquals( expectedResult, resultString ); } /** * @return output from System.out during mojo execution */ private String execute( File pom, String goal ) throws Exception { ExecJavaMojo mojo; mojo = (ExecJavaMojo) lookupMojo( goal, pom ); setUpProject( pom, mojo ); MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); // why isn't this set up by the harness based on the default-value? TODO get to bottom of this! setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE ); setVariableValueToObject( mojo, "killAfter", new Long( -1 ) ); setVariableValueToObject( mojo, "cleanupDaemonThreads", Boolean.TRUE ); setVariableValueToObject( mojo, "classpathScope", "compile" ); assertNotNull( mojo ); assertNotNull( project ); // trap System.out PrintStream out = System.out; StringOutputStream stringOutputStream = new StringOutputStream(); System.setOut( new PrintStream( stringOutputStream ) ); // ensure we don't log unnecessary stuff which would interfere with assessing success of tests mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:java" ) ) ); try { mojo.execute(); } finally { // see testUncooperativeThread() for explaination Thread.sleep( 150 ); // time seems about right System.setOut( out ); } return stringOutputStream.toString(); } private void setUpProject( File pomFile, AbstractMojo mojo ) throws Exception { MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); String path = "src/test/repository"; ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + new File( path ).getAbsolutePath(), localRepositoryLayout ); MavenProject project = builder.buildWithDependencies( pomFile, localRepository, null ); // this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() ); setVariableValueToObject( mojo, "project", project ); } } ./src/test/java/org/codehaus/mojo/exec/MainUncooperative.java0000644000175000017500000000366311303510551023475 0ustar user03user03package org.codehaus.mojo.exec; /** * Created by IntelliJ IDEA. * User: dsmiley * Date: Jan 19, 2007 * Time: 4:43:19 PM * To change this template use File | Settings | File Templates. */ public class MainUncooperative extends Thread { public static final String SUCCESS = "1(interrupted)(f)2(f)"; public static void main( String[] args ) throws InterruptedException { Thread daemonThread = new MainUncooperative(); daemonThread.setDaemon( true ); daemonThread.start(); Thread.sleep( 1000 ); //returns to caller now } final long SIMWORKTIME = 15*1000;//15 seconds of work which is going to be more than exec:java wants to wait public void run() { boolean interruptedOnce = false; long startedTime = System.currentTimeMillis(); for(int lap = 1; true; lap++ ) { long remainingWork = SIMWORKTIME - (System.currentTimeMillis() - startedTime); if ( remainingWork <= 0 ) { break;//done } try { System.out.print( lap ); Thread.sleep(remainingWork);//simulates doing work System.out.print( "(done)" ); break; } catch ( InterruptedException e ) { //We want to ensure this only gets reported once. It's possible depending on a race condition for // ExecJavaMojo.terminateThreads() to interrupt this thread a second time. if ( ! interruptedOnce ) { System.out.print( "(interrupted)" ); } interruptedOnce = true; //be uncooperative; don't quit and don't set interrupted status } finally { System.out.print("(f)");//we should see this if Thread.stop() is called } } } } ./src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java0000644000175000017500000003464711303510551022424 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.SystemStreamLog; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; import org.codehaus.plexus.util.StringOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.apache.maven.monitor.logging.DefaultLog; import org.apache.maven.plugin.testing.AbstractMojoTestCase; /** * @author Jerome Lacoste * @version $Id: ExecMojoTest.java 8882 2009-01-22 20:47:34Z lacostej $ */ public class ExecMojoTest extends AbstractMojoTestCase { private MockExecMojo mojo; static class MockExecMojo extends ExecMojo { public int executeResult; public List commandLines = new ArrayList(); public String failureMsg; public Map systemProperties = new HashMap(); protected int executeCommandLine( Commandline commandLine, StreamConsumer stream1, StreamConsumer stream2 ) throws CommandLineException { commandLines.add( commandLine ); if ( failureMsg != null ) { throw new CommandLineException( failureMsg ); } return executeResult; } protected String getSystemProperty( String key ) { return (String) systemProperties.get( key ); } int getAmountExecutedCommandLines() { return commandLines.size(); } Commandline getExecutedCommandline( int index ) { return ((Commandline) commandLines.get( index )); } } public void setUp() throws Exception { super.setUp(); mojo = new MockExecMojo(); // note: most of the tests below assume that the specified // executable path is not fully specicied. See ExecMojo#getExecutablePath mojo.setExecutable( "mvn" ); mojo.setArguments( Arrays.asList( new String[]{"--version"} ) ); mojo.executeResult = 0; mojo.setBasedir( File.createTempFile( "mvn-temp", "txt" ).getParentFile() ); } /** */ public void testRunOK() throws MojoExecutionException { mojo.execute(); checkMojo( "mvn --version" ); } /* This one won't work yet public void xxtestSimpleRunPropertiesAndArguments() throws MojoExecutionException, Exception { File pom = new File( getBasedir(), "src/test/projects/project1/pom.xml" ); String output = execute( pom, "exec" ); System.out.println(" OUTPUT" + output + "\n\n\n"); String expectedOutput = "arg.arg1\narg.arg2\nproject.env1=value1"; // FIXME should work on Windows as well assertEquals( expectedOutput, output ); } */ /** * integration test... * - compile the Test class using mvn clean compile * - run the test file using java, use it to generate a file whose contains are compared to expected output */ /* public void testRunOKWithAutoComputedClasspath() throws MojoExecutionException, Exception { String projectName = "project1"; ExecMojo mojo = new ExecMojo(); setUpProject( projectName, mojo ); // compile project mojo.setExecutable( "mvn" ); mojo.setWorkingDirectory( new File( "src/test/projects/" + projectName + "/" ) ); mojo.setArguments( Arrays.asList( new String[]{"clean", "compile"} ) ); mojo.execute(); mojo.getLog().info( "executed mvn clean compile" ); // the command executes the test class mojo.setExecutable( "java" ); mojo.setWorkingDirectory( (File) null ); Classpath classpath = new Classpath(); mojo.setArguments( Arrays.asList( new Object[]{"-Dproject.env1=value1", "-classpath", classpath, "org.codehaus.mojo.exec.test.Test", new File( "src/test/projects/" + projectName + "/target/exec/output.txt" ).getAbsolutePath(), "arg1", "arg2"} ) ); mojo.execute(); // checking the command line would involve resolving the repository // checkMojo( "java -cp" ); assertFileEquals( null, getTestFile( "src/test/projects/" + projectName + "/output.txt" ), getTestFile( "src/test/projects/" + projectName + "/target/exec/output.txt" ) ); // the command executes the test class, this time specifying the dependencies mojo.setExecutable( "java" ); mojo.setWorkingDirectory( (File) null ); classpath = new Classpath(); List dependencies = new ArrayList(); dependencies.add( "commons-io:commons-io" ); classpath.setDependencies( dependencies ); mojo.setArguments( Arrays.asList( new Object[]{"-Dproject.env1=value1", "-classpath", classpath, "org.codehaus.mojo.exec.test.Test", new File( "src/test/projects/" + projectName + "/target/exec/output.txt" ).getAbsolutePath(), "arg1", "arg2"} ) ); mojo.execute(); // checking the command line would involve resolving the repository // checkMojo( "java -cp" ); assertFileEquals( null, getTestFile( "src/test/projects/" + projectName + "/output.txt" ), getTestFile( "src/test/projects/" + projectName + "/target/exec/output.txt" ) ); } */ /** * @return output from System.out during mojo execution */ private String execute( File pom, String goal ) throws Exception { ExecMojo mojo; mojo = (ExecMojo) lookupMojo( goal, pom ); setUpProject( pom, mojo ); MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); // why isn't this set up by the harness based on the default-value? TODO get to bottom of this! // setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE ); // setVariableValueToObject( mojo, "killAfter", new Long( -1 ) ); assertNotNull( mojo ); assertNotNull( project ); // trap System.out PrintStream out = System.out; StringOutputStream stringOutputStream = new StringOutputStream(); System.setOut( new PrintStream( stringOutputStream ) ); // ensure we don't log unnecessary stuff which would interfere with assessing success of tests mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:exec" ) ) ); try { mojo.execute(); } catch ( Throwable e ) { e.printStackTrace( System.err ); fail( e.getMessage() ); } finally { System.setOut( out ); } return stringOutputStream.toString(); } private void setUpProject( File pomFile, ExecMojo mojo ) throws Exception { MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); String path = "src/test/repository"; ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + new File( path ).getAbsolutePath(), localRepositoryLayout ); mojo.setBasedir( File.createTempFile( "mvn-temp", "txt" ).getParentFile() ); MavenProject project = builder.buildWithDependencies( pomFile, localRepository, null ); // this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() ); mojo.setProject( project ); mojo.setLog( new SystemStreamLog() { public boolean isDebugEnabled() { return true; } } ); } // MEXEC-12 public void testGetExecutablePath() throws IOException { ExecMojo realMojo = new ExecMojo(); String myJavaPath = "target" + File.separator + "java"; File f = new File( myJavaPath ); assertTrue( "file created...", f.createNewFile() ); assertTrue( "file exists...", f.exists() ); realMojo.setExecutable( myJavaPath ); assertTrue( "File exists so path is absolute", realMojo.getExecutablePath().startsWith( System.getProperty( "user.dir" ) ) ); f.delete(); assertFalse( "file deleted...", f.exists() ); assertEquals( "File doesn't exist. Let the system find it (in that PATH?)", myJavaPath, realMojo.getExecutablePath() ); } public void testRunFailure() { mojo.executeResult = 1; try { mojo.execute(); fail( "expected failure" ); } catch ( MojoExecutionException e ) { assertEquals( "Result of " + mojo.getExecutedCommandline( 0 ) + " execution is: '1'.", e.getMessage() ); } checkMojo( "mvn --version" ); } public void testRunError() { mojo.failureMsg = "simulated failure"; try { mojo.execute(); fail( "expected failure" ); } catch ( MojoExecutionException e ) { assertEquals( "Command execution failed.", e.getMessage() ); } checkMojo( "mvn --version" ); } public void testOverrides() throws MojoExecutionException { mojo.systemProperties.put( "exec.args", "-f pom.xml" ); mojo.execute(); checkMojo( "mvn -f pom.xml" ); } public void testOverrides3() throws MojoExecutionException { mojo.systemProperties.put( "exec.args", null ); mojo.execute(); checkMojo( "mvn --version" ); mojo.commandLines.clear(); mojo.systemProperties.put( "exec.args", "" ); mojo.execute(); checkMojo( "mvn --version" ); } public void testIsResultCodeAFailure() { ExecMojo execMojo = new ExecMojo(); assertTrue(execMojo.isResultCodeAFailure(1)); assertFalse(execMojo.isResultCodeAFailure(0)); execMojo.setSuccessCodes(new ArrayList()); assertTrue(execMojo.isResultCodeAFailure(1)); assertFalse(execMojo.isResultCodeAFailure(0)); execMojo.setSuccessCodes(Arrays.asList(new String[] { "2", "5" })); assertTrue(execMojo.isResultCodeAFailure(0)); assertTrue(execMojo.isResultCodeAFailure(10)); assertFalse(execMojo.isResultCodeAFailure(2)); assertFalse(execMojo.isResultCodeAFailure(5)); } private void checkMojo( String expectedCommandLine ) { assertEquals( 1, mojo.getAmountExecutedCommandLines() ); Commandline commandline = mojo.getExecutedCommandline( 0 ); // do NOT depend on Commandline toString() assertEquals(expectedCommandLine, getCommandLineAsString( commandline )); } private String getCommandLineAsString( Commandline commandline ) { String result = commandline.getExecutable(); String[] arguments = commandline.getArguments(); for (int i = 0; i < arguments.length; i++) { String arg = arguments[i]; result += " " + arg; } return result; } // TAKEN FROM NetbeansFreeformPluginTest - refactor ? /** * This method asserts that the two given files are equals in their * content. * * @param mavenRepo Not used. * @param expectedFile The file that is expected. * @param actualFile The file that is. * @throws java.io.IOException if something goes wrong. */ private void assertFileEquals( String mavenRepo, File expectedFile, File actualFile ) throws IOException { List expectedLines = getLines( mavenRepo, expectedFile ); List actualLines = getLines( mavenRepo, actualFile ); for ( int i = 0; i < expectedLines.size(); i++ ) { String expected = expectedLines.get( i ).toString(); if ( actualLines.size() < i ) { fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: " + expectedLines.size() ); } String actual = actualLines.get( i ).toString(); assertEquals( "Checking line #" + ( i + 1 ), expected, actual ); } assertTrue( "Unequal number of lines.", expectedLines.size() == actualLines.size() ); } /** * This method gives the list of String in a file. * * @param mavenRepo Not used. * @param file The file to be read. * @return The list of the lines of the file. * @throws java.io.IOException if something goes wrong. */ private List getLines( String mavenRepo, File file ) throws IOException { List lines = new ArrayList(); BufferedReader reader = new BufferedReader( new FileReader( file ) ); String line; while ( ( line = reader.readLine() ) != null ) { lines.add( line ); //StringUtils.replace( line, "#ArtifactRepositoryPath#", mavenRepo.replace( '\\', '/' ) ) ); } return lines; } } ./src/test/java/org/codehaus/mojo/exec/DummyMain.java0000644000175000017500000000131311303510551021733 0ustar user03user03package org.codehaus.mojo.exec; /** * Simple class with a main method to call from unit tests * * @author Jerome Lacoste * @version $Id: DummyMain.java 6588 2008-03-28 12:22:57Z bentmann $ */ public class DummyMain { /** * Prints Hello followed by each argument, then a new line. Use a space character as separator. * * @param args */ public static void main( String[] args ) { StringBuffer buffer = new StringBuffer( "Hello" ); for ( int i = 0; i < args.length; i++ ) { buffer.append( System.getProperty( "line.separator" ) ).append( args[i] ); } System.out.println( buffer.toString() ); } } ./src/test/projects/0000755000175000017500000000000011303510552013631 5ustar user03user03./src/test/projects/project12/0000755000175000017500000000000011303510552015442 5ustar user03user03./src/test/projects/project12/pom.xml0000644000175000017500000000376311303510552016770 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project1 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo Jerome Lacoste jerome jerome@coffeebreaks.org CoffeeBreaks http://www.coffeebreaks.org Java Developer +1 commons-io commons-io 1.1 commons-logging commons-logging 1.0.4 org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.NoMain ./src/test/projects/project13/0000755000175000017500000000000011303510552015443 5ustar user03user03./src/test/projects/project13/src/0000755000175000017500000000000011303510552016232 5ustar user03user03./src/test/projects/project13/src/test/0000755000175000017500000000000011303510552017211 5ustar user03user03./src/test/projects/project13/src/test/java/0000755000175000017500000000000011303510552020132 5ustar user03user03./src/test/projects/project13/src/test/java/org/0000755000175000017500000000000011303510552020721 5ustar user03user03./src/test/projects/project13/src/test/java/org/codehaus/0000755000175000017500000000000011303510552022514 5ustar user03user03./src/test/projects/project13/src/test/java/org/codehaus/mojo/0000755000175000017500000000000011303510552023460 5ustar user03user03./src/test/projects/project13/src/test/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510552024404 5ustar user03user03./src/test/projects/project13/src/test/java/org/codehaus/mojo/exec/test1/0000755000175000017500000000000011303510552025444 5ustar user03user03./src/test/projects/project13/src/test/java/org/codehaus/mojo/exec/test1/Test.java0000644000175000017500000000442511303510552027233 0ustar user03user03package org.codehaus.mojo.exec.test1; /* * Copyright 2005-2008 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Properties; import junit.framework.Assert; /** * @author Jerome Lacoste * @version $Id: Test.java 6588 2008-03-28 12:22:57Z bentmann $ */ public class Test { // test that we can use FileUtils, i.e. that classpath specification works // Write to the file specified as args[ 0 ], the following (sorted) // * the remaining arguments prefixed with "arg." // * the project properties (identified in the System properties by their "project." prefix), // in the form of "key=value" public static void main( String[] args ) throws Exception { // make sure junit classes are in the classpath Assert.assertTrue( "missing output file path" , args.length > 0 ) ; List myProperties = new ArrayList(); for ( int i = 0; i < args.length - 1; i++ ) { myProperties.add( "arg." + args[ i + 1 ] ); } Properties systemProperties = System.getProperties(); for ( Iterator it = systemProperties.keySet().iterator(); it.hasNext(); ) { String key = it.next().toString(); if ( key.startsWith( "project." ) ) { myProperties.add( key + "=" + systemProperties.get( key ) ); } } Collections.sort( myProperties ); File toFile = new File( args[0] ); toFile.getParentFile().mkdirs(); FileUtils.writeLines( new File( args[0] ), "UTF-8", myProperties ); } } ./src/test/projects/project13/output.txt0000644000175000017500000000004611303510552017544 0ustar user03user03arg.arg1 arg.arg2 project.env1=value1 ./src/test/projects/project13/pom.xml0000644000175000017500000000517711303510552016772 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project13 0.1 jar Maven Exec Plugin Test that one can force adding the test-classpath for the exec mojo 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo Jerome Lacoste jerome jerome@coffeebreaks.org CoffeeBreaks http://www.coffeebreaks.org Java Developer +1 commons-io commons-io 1.1 commons-logging commons-logging 1.0.4 junit junit 3.8.1 test org.codehaus.mojo exec-maven-plugin test exec java test -Dproject.env1=value1 -classpath org.codehaus.mojo.exec.test1.Test target/exec/output.txt arg1 arg2 ./src/test/projects/project2/0000755000175000017500000000000011303510552015361 5ustar user03user03./src/test/projects/project2/src/0000755000175000017500000000000011303510551016147 5ustar user03user03./src/test/projects/project2/src/main/0000755000175000017500000000000011303510551017073 5ustar user03user03./src/test/projects/project2/src/main/java/0000755000175000017500000000000011303510551020014 5ustar user03user03./src/test/projects/project2/src/main/java/org/0000755000175000017500000000000011303510551020603 5ustar user03user03./src/test/projects/project2/src/main/java/org/codehaus/0000755000175000017500000000000011303510551022376 5ustar user03user03./src/test/projects/project2/src/main/java/org/codehaus/mojo/0000755000175000017500000000000011303510551023342 5ustar user03user03./src/test/projects/project2/src/main/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510552024267 5ustar user03user03./src/test/projects/project2/src/main/java/org/codehaus/mojo/exec/project2/0000755000175000017500000000000011303510552026017 5ustar user03user03./src/test/projects/project2/src/main/java/org/codehaus/mojo/exec/project2/App.java0000644000175000017500000000542411303510552027407 0ustar user03user03package org.codehaus.mojo.exec.project2; import org.apache.log4j.Logger; import com.sun.java_cup.internal.runtime.Symbol; /** * Used for manual integrationtest of the java goal. * */ public class App { static Logger log = Logger.getLogger(App.class); public static void main( String[] args ) { System.out.println("I was started. So obviously I found the main class"); App app = new App(); try { Class log = app.getClass().getClassLoader().loadClass( "org.apache.log4j.Logger" ); if ( null != log ) { System.out.println( "Found the compile dependency" ); } } catch ( Exception e ) { System.out.println( "ERROR: Did not find the compile dependency" ); } try { Class testCase = app.getClass().getClassLoader().loadClass( "junit.framework.TestCase" ); if ( null != testCase ) { System.out.println( "ERROR: Found the test dependency (should only be test scope)" ); } } catch ( Exception e ) { System.out.println( "Did not find the test dependency" ); } try { Class fileUtils = app.getClass().getClassLoader().loadClass( "org.apache.commons.io.FileUtils" ); if ( null != fileUtils ) { System.out.println( "Found the runtime dependency" ); } } catch ( Exception e ) { System.out.println( "ERROR: Did not find the runtime dependency" ); } String value = System.getProperty("propkey"); if ( "propvalue".equals( value ) ) { System.out.println("Found the passed system propery"); } else { System.out.println( "ERROR: Did not find the specified system property" ); } value = System.getProperty("com.sun.management.jmxremote"); if ( value == null ) { System.out.println( "Did not find the specified system property. This property can only be passed to the java mojo by using MAVEN_OPTS" ); } else { System.out.println("ERROR: Unexpected: found the passed system propery. This property cannot be passed from the POM"); } if ( "argument1".equals( args[0] ) ) { System.out.println("Found the first argument"); } else { System.out.println( "ERROR: Did not find the first argument" ); } if ( "argument2".equals( args[1] ) ) { System.out.println("Found the second argument"); } else { System.out.println( "ERROR: Did not find the second argument" ); } } } ./src/test/projects/project2/pom.xml0000644000175000017500000000361611303510552016704 0ustar user03user03 4.0.0 org.codehaus.mojo.exec.project2 project2 jar 1.0-SNAPSHOT Maven Quick Start Archetype http://maven.apache.org log4j log4j 1.2.9 commons-io commons-io 1.1 runtime junit junit 3.8.1 test org.codehaus.mojo exec-maven-plugin test java propkey propvalue com.sun.management.jmxremote org.codehaus.mojo.exec.project2.App argument1 argument2 ./src/test/projects/project4/0000755000175000017500000000000011303510552015363 5ustar user03user03./src/test/projects/project4/pom.xml0000644000175000017500000000170011303510552016676 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project4 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.DummyMain ./src/test/projects/project9/0000755000175000017500000000000011303510551015367 5ustar user03user03./src/test/projects/project9/pom.xml0000644000175000017500000000237111303510551016707 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project9 0.1 jar Maven Exec Plugin Allow the user to time out when the code to be run is buggy or improperly written with regards to Thread termination 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.MainWithThreads 4000 ./src/test/projects/project1/0000755000175000017500000000000011303510551015357 5ustar user03user03./src/test/projects/project1/src/0000755000175000017500000000000011303510551016146 5ustar user03user03./src/test/projects/project1/src/main/0000755000175000017500000000000011303510551017072 5ustar user03user03./src/test/projects/project1/src/main/java/0000755000175000017500000000000011303510551020013 5ustar user03user03./src/test/projects/project1/src/main/java/org/0000755000175000017500000000000011303510551020602 5ustar user03user03./src/test/projects/project1/src/main/java/org/codehaus/0000755000175000017500000000000011303510551022375 5ustar user03user03./src/test/projects/project1/src/main/java/org/codehaus/mojo/0000755000175000017500000000000011303510551023341 5ustar user03user03./src/test/projects/project1/src/main/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510551024265 5ustar user03user03./src/test/projects/project1/src/main/java/org/codehaus/mojo/exec/test1/0000755000175000017500000000000011303510551025325 5ustar user03user03./src/test/projects/project1/src/main/java/org/codehaus/mojo/exec/test1/Test.java0000644000175000017500000000444111303510551027112 0ustar user03user03package org.codehaus.mojo.exec.test1; /* * Copyright 2005 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Properties; /** * @author Jerome Lacoste * @version $Id: Test.java 6588 2008-03-28 12:22:57Z bentmann $ * @todo we depend too much on Commandline.toString() */ public class Test { // test that we can use FileUtils, i.e. that classpath specification works // Write to the file specified as args[ 0 ], the following (sorted) // * the remaining arguments prefixed with "arg." // * the project properties (identified in the System properties by their "project." prefix), // in the form of "key=value" public static void main( String[] args ) throws Exception { if ( args.length == 0 ) { throw new IllegalArgumentException ( "missing output file path" ) ; } List myProperties = new ArrayList(); for ( int i = 0; i < args.length - 1; i++ ) { myProperties.add( "arg." + args[ i + 1 ] ); } Properties systemProperties = System.getProperties(); for ( Iterator it = systemProperties.keySet().iterator(); it.hasNext(); ) { String key = it.next().toString(); if ( key.startsWith( "project." ) ) { myProperties.add( key + "=" + systemProperties.get( key ) ); } } Collections.sort( myProperties ); File toFile = new File( args[0] ); toFile.getParentFile().mkdirs(); FileUtils.writeLines( new File( args[0] ), "UTF-8", myProperties ); } } ./src/test/projects/project1/output.txt0000644000175000017500000000004611303510551017460 0ustar user03user03arg.arg1 arg.arg2 project.env1=value1 ./src/test/projects/project1/pom.xml0000644000175000017500000000451411303510551016700 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project1 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo Jerome Lacoste jerome jerome@coffeebreaks.org CoffeeBreaks http://www.coffeebreaks.org Java Developer +1 commons-io commons-io 1.1 commons-logging commons-logging 1.0.4 org.codehaus.mojo exec-maven-plugin test exec java -Dproject.env1=value1 -classpath org.codehaus.mojo.exec.test1.Test target/exec/output.txt arg1 arg2 ./src/test/projects/project6/0000755000175000017500000000000011303510552015365 5ustar user03user03./src/test/projects/project6/project5lib/0000755000175000017500000000000011303510552017607 5ustar user03user03./src/test/projects/project6/project5lib/src/0000755000175000017500000000000011303510552020376 5ustar user03user03./src/test/projects/project6/project5lib/src/main/0000755000175000017500000000000011303510552021322 5ustar user03user03./src/test/projects/project6/project5lib/src/main/java/0000755000175000017500000000000011303510552022243 5ustar user03user03./src/test/projects/project6/project5lib/src/main/java/org/0000755000175000017500000000000011303510552023032 5ustar user03user03./src/test/projects/project6/project5lib/src/main/java/org/codehaus/0000755000175000017500000000000011303510552024625 5ustar user03user03./src/test/projects/project6/project5lib/src/main/java/org/codehaus/mojo/0000755000175000017500000000000011303510552025571 5ustar user03user03./src/test/projects/project6/project5lib/src/main/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510552026515 5ustar user03user03./src/test/projects/project6/project5lib/src/main/java/org/codehaus/mojo/exec/project5lib/0000755000175000017500000000000011303510552030737 5ustar user03user03././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootroot./src/test/projects/project6/project5lib/src/main/java/org/codehaus/mojo/exec/project5lib/ExampleLibrary.java./src/test/projects/project6/project5lib/src/main/java/org/codehaus/mojo/exec/project5lib/ExampleLib0000644000175000017500000000056111303510552032706 0ustar user03user03package org.codehaus.mojo.exec.project5lib; import org.apache.log4j.Logger; /** * Used for manual integrationtest of the java goal. * */ public class ExampleLibrary { static Logger log = Logger.getLogger(ExampleLibrary.class); public ExampleLibrary() { } public boolean isAGoodDay() { log.debug("It's a great day!"); return true; } } ./src/test/projects/project6/project5lib/pom.xml0000644000175000017500000000200011303510552021114 0ustar user03user03 org.codehaus.mojo.exec.project5 project5 1.0-SNAPSHOT 4.0.0 project5lib jar Exec Plugin Example Project 5 Lib http://maven.apache.org log4j log4j 1.2.9 commons-io commons-io 1.1 runtime junit junit 3.8.1 test ./src/test/projects/project6/project5libB/0000755000175000017500000000000011303510552017711 5ustar user03user03./src/test/projects/project6/project5libB/src/0000755000175000017500000000000011303510552020500 5ustar user03user03./src/test/projects/project6/project5libB/src/main/0000755000175000017500000000000011303510552021424 5ustar user03user03./src/test/projects/project6/project5libB/src/main/java/0000755000175000017500000000000011303510552022345 5ustar user03user03./src/test/projects/project6/project5libB/src/main/java/org/0000755000175000017500000000000011303510552023134 5ustar user03user03./src/test/projects/project6/project5libB/src/main/java/org/codehaus/0000755000175000017500000000000011303510552024727 5ustar user03user03./src/test/projects/project6/project5libB/src/main/java/org/codehaus/mojo/0000755000175000017500000000000011303510552025673 5ustar user03user03./src/test/projects/project6/project5libB/src/main/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510552026617 5ustar user03user03./src/test/projects/project6/project5libB/src/main/java/org/codehaus/mojo/exec/project5libB/0000755000175000017500000000000011303510552031143 5ustar user03user03././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootroot./src/test/projects/project6/project5libB/src/main/java/org/codehaus/mojo/exec/project5libB/App.java./src/test/projects/project6/project5libB/src/main/java/org/codehaus/mojo/exec/project5libB/App.java0000644000175000017500000000421611303510552032531 0ustar user03user03package org.codehaus.mojo.exec.project5libB; import org.apache.log4j.Logger; /** * Used for manual integrationtest of the java goal. * */ public class App { static Logger log = Logger.getLogger(App.class); public static void main( String[] args ) { System.out.println("I was started. So obviously I found the main class"); App app = new App(); try { Class fileUtils = app.getClass().getClassLoader().loadClass( "org.codehaus.mojo.exec.project5lib.ExampleLibrary" ); if ( null != fileUtils ) { System.out.println( "Found the ExampleLibrary" ); } } catch ( Exception e ) { System.out.println( "Did not find the ExampleLibrary" ); } try { Class log = app.getClass().getClassLoader().loadClass( "org.apache.log4j.Logger" ); if ( null != log ) { System.out.println( "Found the compile dependency" ); } } catch ( Exception e ) { System.out.println( "Did not find the compile dependency" ); } try { Class testCase = app.getClass().getClassLoader().loadClass( "junit.framework.TestCase" ); if ( null != testCase ) { System.out.println( "Found the test dependency" ); } } catch ( Exception e ) { System.out.println( "Did not found the test dependency" ); } try { Class fileUtils = app.getClass().getClassLoader().loadClass( "org.apache.commons.io.FileUtils" ); if ( null != fileUtils ) { System.out.println( "Found the runtime dependency" ); } } catch ( Exception e ) { System.out.println( "Did not find the runtime dependency" ); } String value = System.getProperty("propkey"); if (null != value) { System.out.println("Found the system propery passed"); } } } ./src/test/projects/project6/project5libB/pom.xml0000644000175000017500000000140511303510552021226 0ustar user03user03 org.codehaus.mojo.exec.project5 project5 1.0-SNAPSHOT 4.0.0 project5libB jar Exec Plugin Example Project 5 Lib B http://maven.apache.org org.codehaus.mojo.exec.project5 project5lib ${project.version} ./src/test/projects/project6/project5exec/0000755000175000017500000000000011303510552017765 5ustar user03user03./src/test/projects/project6/project5exec/pom.xml0000644000175000017500000000520611303510552021305 0ustar user03user03 org.codehaus.mojo.exec.project5 project5 1.0-SNAPSHOT 4.0.0 project5exec jar Exec Plugin Example Project 5 Exec http://maven.apache.org org.codehaus.mojo exec-maven-plugin propkey propvalue org.codehaus.mojo.exec.project5libB.App argument1 argument2 false true org.codehaus.mojo.exec.project5 project5libB org.codehaus.mojo.exec.project5 project5libB ${project.version} berkeleydb je 2.1.30 runtime commons-logging commons-logging 1.0.4 ./src/test/projects/project6/pom.xml0000644000175000017500000000127211303510552016704 0ustar user03user03 4.0.0 org.codehaus.mojo.exec.project5 project5 pom 1.0-SNAPSHOT Exec Plugin Example Project 5 Parent junit junit 3.8.1 project5exec project5lib project5libB ./src/test/projects/project3/0000755000175000017500000000000011303510552015362 5ustar user03user03./src/test/projects/project3/src/0000755000175000017500000000000011303510552016151 5ustar user03user03./src/test/projects/project3/src/main/0000755000175000017500000000000011303510552017075 5ustar user03user03./src/test/projects/project3/src/main/java/0000755000175000017500000000000011303510552020016 5ustar user03user03./src/test/projects/project3/src/main/java/org/0000755000175000017500000000000011303510552020605 5ustar user03user03./src/test/projects/project3/src/main/java/org/codehaus/0000755000175000017500000000000011303510552022400 5ustar user03user03./src/test/projects/project3/src/main/java/org/codehaus/mojo/0000755000175000017500000000000011303510552023344 5ustar user03user03./src/test/projects/project3/src/main/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510552024270 5ustar user03user03./src/test/projects/project3/src/main/java/org/codehaus/mojo/exec/test3/0000755000175000017500000000000011303510552025332 5ustar user03user03./src/test/projects/project3/src/main/java/org/codehaus/mojo/exec/test3/Test.java0000644000175000017500000000471211303510552027120 0ustar user03user03package org.codehaus.mojo.exec.test3; /* * Copyright 2005 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Properties; /** * @author Jerome Lacoste * @version $Id: Test.java 6588 2008-03-28 12:22:57Z bentmann $ * @todo we depend too much on Commandline.toString() */ public class Test { // test that we can use FileUtils, i.e. that classpath specification works // Write to the file specified as args[ 0 ], the following (sorted) // * the remaining arguments prefixed with "arg." // * the project properties (identified in the System properties by their "project." prefix), // in the form of "key=value" public static void main( String[] args ) throws Exception { if ( args.length == 0 ) { throw new IllegalArgumentException ( "missing output file path" ) ; } List myProperties = new ArrayList(); for ( int i = 0; i < args.length - 1; i++ ) { myProperties.add( "arg." + args[ i + 1 ] ); } Properties systemProperties = System.getProperties(); for ( Iterator it = systemProperties.keySet().iterator(); it.hasNext(); ) { String key = it.next().toString(); if ( key.startsWith( "project." ) ) { myProperties.add( key + "=" + systemProperties.get( key ) ); } } myProperties.add("user.dir=" + systemProperties.get( "user.dir" )); myProperties.add("java.class.path=" + systemProperties.get( "java.class.path" )); Collections.sort( myProperties ); File toFile = new File( args[0] ); toFile.getParentFile().mkdirs(); FileUtils.writeLines( new File( args[0] ), "UTF-8", myProperties ); } } ./src/test/projects/project3/output.txt0000644000175000017500000000004611303510552017463 0ustar user03user03arg.arg1 arg.arg2 project.env1=value1 ./src/test/projects/project3/README.txt0000644000175000017500000000037411303510552017064 0ustar user03user03the target/exec/output.txt should contain only 3 elements: - the classpath with 2 elements: the commons-io and commons-logging jars + the classes, but not the commons-lang - a passed argument (project.env1) - the project user.dir, matching $PWD/target ./src/test/projects/project3/pom.xml0000644000175000017500000000525311303510552016704 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project3 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo Jerome Lacoste jerome jerome@coffeebreaks.org CoffeeBreaks http://www.coffeebreaks.org Java Developer +1 commons-io commons-io 1.1 commons-logging commons-logging 1.0.4 commons-lang commons-lang 1.0.1 org.codehaus.mojo exec-maven-plugin 1.1-SNAPSHOT test exec target java -Dproject.env1=value1 -classpath commons-io:commons-io commons-logging:commons-logging org.codehaus.mojo.exec.test3.Test exec/output.txt ./src/test/projects/project14/0000755000175000017500000000000011303510552015444 5ustar user03user03./src/test/projects/project14/src/0000755000175000017500000000000011303510552016233 5ustar user03user03./src/test/projects/project14/src/test/0000755000175000017500000000000011303510552017212 5ustar user03user03./src/test/projects/project14/src/test/java/0000755000175000017500000000000011303510552020133 5ustar user03user03./src/test/projects/project14/src/test/java/org/0000755000175000017500000000000011303510552020722 5ustar user03user03./src/test/projects/project14/src/test/java/org/codehaus/0000755000175000017500000000000011303510552022515 5ustar user03user03./src/test/projects/project14/src/test/java/org/codehaus/mojo/0000755000175000017500000000000011303510552023461 5ustar user03user03./src/test/projects/project14/src/test/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510552024405 5ustar user03user03./src/test/projects/project14/src/test/java/org/codehaus/mojo/exec/test1/0000755000175000017500000000000011303510552025445 5ustar user03user03./src/test/projects/project14/src/test/java/org/codehaus/mojo/exec/test1/Test.java0000644000175000017500000000451611303510552027235 0ustar user03user03package org.codehaus.mojo.exec.test1; /* * Copyright 2005-2008 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Properties; import junit.framework.Assert; /** * @author Jerome Lacoste * @version $Id: Test.java 6588 2008-03-28 12:22:57Z bentmann $ */ public class Test { // test that we can use FileUtils, i.e. that classpath specification works // Write to the file specified as args[ 0 ], the following (sorted) // * the remaining arguments prefixed with "arg." // * the project properties (identified in the System properties by their "project." prefix), // in the form of "key=value" public static void main( String[] args ) throws Exception { // make sure junit classes are in the classpath Assert.assertTrue( "missing output file path" , args.length > 0 ) ; List myProperties = new ArrayList(); for ( int i = 0; i < args.length - 1; i++ ) { myProperties.add( "arg." + args[ i + 1 ] ); } Properties systemProperties = System.getProperties(); for ( Iterator it = systemProperties.keySet().iterator(); it.hasNext(); ) { String key = it.next().toString(); if ( key.startsWith( "project." ) ) { myProperties.add( key + "=" + systemProperties.get( key ) ); } } Collections.sort( myProperties ); File toFile = new File( args[0] ); System.out.println( toFile.getAbsolutePath() ); toFile.getParentFile().mkdirs(); FileUtils.writeLines( new File( args[0] ), "UTF-8", myProperties ); } } ./src/test/projects/project14/output.txt0000644000175000017500000000004611303510552017545 0ustar user03user03arg.arg1 arg.arg2 project.env1=value1 ./src/test/projects/project14/pom.xml0000644000175000017500000000472211303510552016766 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project14 0.1 jar Maven Exec Plugin Test that one can force adding the test-classpath for the java mojo 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo Jerome Lacoste jerome jerome@coffeebreaks.org CoffeeBreaks http://www.coffeebreaks.org Java Developer +1 commons-io commons-io 1.1 commons-logging commons-logging 1.0.4 junit junit 3.8.1 test org.codehaus.mojo exec-maven-plugin test java test org.codehaus.mojo.exec.test1.Test target/output.txt arg1 arg2 ./src/test/projects/project7/0000755000175000017500000000000011303510552015366 5ustar user03user03./src/test/projects/project7/pom.xml0000644000175000017500000000220211303510552016677 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project7 0.1 jar Maven Exec Plugin Make sure correctly written daemon threads are automatically handled 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.MainWithThreads cancelTimer ./src/test/projects/project8/0000755000175000017500000000000011303510552015367 5ustar user03user03./src/test/projects/project8/pom.xml0000644000175000017500000000200211303510552016676 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project8 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.DummyMain "Arg1" "Arg2a Arg2b" ./src/test/projects/project5/0000755000175000017500000000000011303510552015364 5ustar user03user03./src/test/projects/project5/pom.xml0000644000175000017500000000236011303510552016702 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project4 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.DummyMain project5.property.with.no.value boum boum ./src/test/projects/project11/0000755000175000017500000000000011303510551015440 5ustar user03user03./src/test/projects/project11/readme.txt0000644000175000017500000000246511303510551017445 0ustar user03user03This test cannot yet be automated. To test using mvn: mkdir -p target rm -rf target/classes cp -ar ../../../../target/test-classes target/classes mvn -X test [...] [INFO] [exec:java {execution: default}] [DEBUG] Invoking : org.codehaus.mojo.exec.FindClassInClasspath.main(sun.tools.javac.Main) [DEBUG] Plugin Dependencies will be excluded. [DEBUG] Project Dependencies will be included. [DEBUG] Collected project artifacts [com.sun:tools:jar:1.5:system, commons-lang:commons-lang:jar:1.0.1:compile] [DEBUG] Collected project classpath [/home/jerome/Code/OSS/m2/exec-maven-plugin/src/test/projects/project11/target/classes] [DEBUG] Adding to classpath : file:/home/jerome/Code/OSS/m2/exec-maven-plugin/src/test/projects/project11/target/classes/ [DEBUG] Adding project dependency artifact: tools to classpath [DEBUG] Adding project dependency artifact: commons-lang to classpath [DEBUG] joining on thread Thread[org.codehaus.mojo.exec.FindClassInClasspath.main(),5,org.codehaus.mojo.exec.FindClassInClasspath] [DEBUG] Setting accessibility to true in order to invoke main(). OK [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ Expectation: both commons-lang and tools are added to the classpath ./src/test/projects/project11/pom.xml0000644000175000017500000000302511303510551016755 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project11 0.1 jar Maven Exec Plugin Make sure system scope dependencies are added 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.FindClassInClasspath sun.tools.javac.Main com.sun tools 1.5 system ${java.home}/../lib/tools.jar commons-lang commons-lang 1.0.1 ./src/test/projects/project10/0000755000175000017500000000000011303510551015437 5ustar user03user03./src/test/projects/project10/pom.xml0000644000175000017500000000213111303510551016751 0ustar user03user03 4.0.0 org.cb.maven.plugins.exec project10 0.1 jar Maven Exec Plugin 2005 Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo org.codehaus.mojo exec-maven-plugin test java org.codehaus.mojo.exec.MainUncooperative 3000 true ./src/main/0000755000175000017500000000000011303510552011745 5ustar user03user03./src/main/java/0000755000175000017500000000000011303510552012666 5ustar user03user03./src/main/java/org/0000755000175000017500000000000011303510552013455 5ustar user03user03./src/main/java/org/codehaus/0000755000175000017500000000000011303510552015250 5ustar user03user03./src/main/java/org/codehaus/mojo/0000755000175000017500000000000011303510552016214 5ustar user03user03./src/main/java/org/codehaus/mojo/exec/0000755000175000017500000000000011303510553017141 5ustar user03user03./src/main/java/org/codehaus/mojo/exec/ExecutableDependency.java0000644000175000017500000000437111303510553024071 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.artifact.Artifact; /** * */ public class ExecutableDependency { private String groupId; private String artifactId; public ExecutableDependency() { } public String getGroupId() { return this.groupId; } public void setGroupId( String groupId ) { this.groupId = groupId; } public String getArtifactId() { return this.artifactId; } public void setArtifactId( String artifactId ) { this.artifactId = artifactId; } public boolean matches( Artifact artifact ) { return artifact.getGroupId().equals( this.getGroupId() ) && artifact.getArtifactId().equals( this.getArtifactId() ); } public String toString() { return this.groupId + ":" + this.artifactId; } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } final ExecutableDependency that = (ExecutableDependency) o; if ( artifactId != null ? !artifactId.equals( that.artifactId ) : that.artifactId != null ) { return false; } if ( groupId != null ? !groupId.equals( that.groupId ) : that.groupId != null ) { return false; } return true; } public int hashCode() { int result; result = ( groupId != null ? groupId.hashCode() : 0 ); result = 29 * result + ( artifactId != null ? artifactId.hashCode() : 0 ); return result; } } ./src/main/java/org/codehaus/mojo/exec/ExecMojo.java0000644000175000017500000003670611303510553021531 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.toolchain.Toolchain; import org.apache.maven.toolchain.ToolchainManager; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.HashMap; import java.util.StringTokenizer; /** * A Plugin for executing external programs. * * @author Jerome Lacoste * @version $Id: ExecMojo.java 8882 2009-01-22 20:47:34Z lacostej $ * @goal exec * @requiresDependencyResolution test * @since 1.0 */ public class ExecMojo extends AbstractExecMojo { /** * Skip the execution. * * @parameter expression="${skip}" default-value="false" * @since 1.0.1 */ private boolean skip; /** * The executable. Can be a full path or a the name executable. In the latter case, the executable must be * in the PATH for the execution to work. * * @parameter expression="${exec.executable}" * @required * @since 1.0 */ private String executable; /** * The current working directory. Optional. If not specified, basedir will be used. * * @parameter expression="${exec.workingdir} * @since 1.0 */ private File workingDirectory; /** * Program standard and error output will be redirected to the file specified by this optional field. * If not specified the standard maven logging is used. * * @parameter expression="${exec.outputFile}" * @since 1.1-beta-2 */ private File outputFile; /** * Can be of type <argument> or <classpath> * Can be overriden using "exec.args" env. variable * * @parameter * @since 1.0 */ private List arguments; /** * @parameter expression="${basedir}" * @required * @readonly * @since 1.0 */ private File basedir; /** * Environment variables to pass to the executed program. * @parameter * @since 1.1-beta-2 */ private Map environmentVariables = new HashMap(); /** * The current build session instance. This is used for * toolchain manager API calls. * * @parameter expression="${session}" * @required * @readonly */ private MavenSession session; /** * Exit codes to be resolved as successful execution for non-compliant * applications (applications not returning 0 for success). * * @parameter * @since 1.1.1 */ private List successCodes; /** * if exec.args expression is used when invokign the exec:exec goal, * any occurence of %classpath argument is replaced by the actual project dependency classpath. */ public static final String CLASSPATH_TOKEN = "%classpath"; /** * priority in the execute method will be to use System properties arguments over the pom specification. * @throws MojoExecutionException if a failure happens */ public void execute() throws MojoExecutionException { if ( skip ) { getLog().info( "skipping execute as per configuraion" ); return; } if ( basedir == null ) { throw new IllegalStateException( "basedir is null. Should not be possible." ); } String argsProp = getSystemProperty( "exec.args" ); List commandArguments = new ArrayList(); if ( hasCommandlineArgs() ) { String[] args = parseCommandlineArgs(); for ( int i = 0; i < args.length; i++ ) { if ( CLASSPATH_TOKEN.equals( args[i] ) ) { commandArguments.add( computeClasspath( null ) ); } else { commandArguments.add( args[i] ); } } } else if ( !isEmpty( argsProp ) ) { getLog().debug( "got arguments from system properties: " + argsProp ); StringTokenizer strtok = new StringTokenizer( argsProp, " " ); while ( strtok.hasMoreTokens() ) { commandArguments.add( strtok.nextToken() ); } } else { if ( arguments != null ) { for ( int i = 0; i < arguments.size(); i++ ) { Object argument = arguments.get( i ); String arg; if ( argument == null ) { throw new MojoExecutionException( "Misconfigured argument, value is null. Set the argument to an empty value" + " if this is the required behaviour." ); } else if ( argument instanceof Classpath ) { Classpath specifiedClasspath = (Classpath) argument; arg = computeClasspath( specifiedClasspath ); } else { arg = argument.toString(); } commandArguments.add( arg ); } } } Commandline commandLine = new Commandline(); commandLine.setExecutable( getExecutablePath() ); String [] args = new String[ commandArguments.size() ]; for ( int i = 0; i < commandArguments.size(); i++ ) { args[i] = (String) commandArguments.get( i ); } commandLine.addArguments( args ); if ( workingDirectory == null ) { workingDirectory = basedir; } if ( !workingDirectory.exists() ) { getLog().debug( "Making working directory '" + workingDirectory.getAbsolutePath() + "'." ); if ( !workingDirectory.mkdirs() ) { throw new MojoExecutionException( "Could not make working directory: '" + workingDirectory.getAbsolutePath() + "'" ); } } commandLine.setWorkingDirectory( workingDirectory.getAbsolutePath() ); if ( environmentVariables != null ) { Iterator iter = environmentVariables.keySet().iterator(); while ( iter.hasNext() ) { String key = (String) iter.next(); String value = (String) environmentVariables.get( key ); commandLine.addEnvironment( key, value ); } } final Log outputLog = getExecOutputLog(); StreamConsumer stdout = new StreamConsumer() { public void consumeLine( String line ) { outputLog.info( line ); } }; StreamConsumer stderr = new StreamConsumer() { public void consumeLine( String line ) { outputLog.info( line ); } }; try { int resultCode = executeCommandLine( commandLine, stdout, stderr ); if ( isResultCodeAFailure( resultCode ) ) { throw new MojoExecutionException( "Result of " + commandLine + " execution is: '" + resultCode + "'." ); } } catch ( CommandLineException e ) { throw new MojoExecutionException( "Command execution failed.", e ); } registerSourceRoots(); } boolean isResultCodeAFailure(int result) { if (successCodes == null || successCodes.size() == 0) return result != 0; for (Iterator it = successCodes.iterator(); it.hasNext(); ) { int code = Integer.parseInt((String) it.next()); if (code == result) return false; } return true; } private Log getExecOutputLog() { Log log = getLog(); if ( outputFile != null ) { try { if ( !outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs() ) { getLog().warn( "Could not create non existing parent directories for log file: " + outputFile ); } PrintStream stream = new PrintStream( new FileOutputStream( outputFile ) ); log = new StreamLog( stream ); } catch ( Exception e ) { getLog().warn( "Could not open " + outputFile + ". Using default log", e ); } } return log; } /** * Compute the classpath from the specified Classpath. The computed classpath is based on the classpathScope. * The plugin cannot know from maven the phase it is executed in. So we have to depend on the user to tell us * he wants the scope in which the plugin is expected to be executed. * @param specifiedClasspath Non null when the user restricted the dependenceis, null otherwise (the default classpath will be used) * @return a platform specific String representation of the classpath */ private String computeClasspath( Classpath specifiedClasspath ) { // TODO we should consider rewriting this bit into something like // List collectProjectClasspathAsListOfURLs( optionalFilter ); // reusable by both mojos List artifacts = new ArrayList(); List theClasspathFiles = new ArrayList(); collectProjectArtifactsAndClasspath( artifacts, theClasspathFiles ); if ( specifiedClasspath != null && specifiedClasspath.getDependencies() != null ) { artifacts = filterArtifacts( artifacts, specifiedClasspath.getDependencies() ); } StringBuffer theClasspath = new StringBuffer(); for ( Iterator it = theClasspathFiles.iterator(); it.hasNext(); ) { File f = (File) it.next(); addToClasspath( theClasspath, f.getAbsolutePath() ); } for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); getLog().debug( "dealing with " + artifact ); addToClasspath( theClasspath, artifact.getFile().getAbsolutePath() ); } return theClasspath.toString(); } private static void addToClasspath( StringBuffer theClasspath, String toAdd ) { if ( theClasspath.length() > 0 ) { theClasspath.append( File.pathSeparator ); } theClasspath.append( toAdd ); } private List filterArtifacts( List artifacts, Collection dependencies ) { AndArtifactFilter filter = new AndArtifactFilter(); filter.add( new IncludesArtifactFilter( new ArrayList( dependencies ) ) ); // gosh List filteredArtifacts = new ArrayList(); for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); if ( filter.include( artifact ) ) { getLog().debug( "filtering in " + artifact ); filteredArtifacts.add( artifact ); } } return filteredArtifacts; } String getExecutablePath() { File execFile = new File( executable ); if ( execFile.exists() ) { getLog().debug( "Toolchains are ignored, 'executable' parameter is set to " + executable ); return execFile.getAbsolutePath(); } else { Toolchain tc = getToolchain(); // if the file doesn't exist & toolchain is null, the exec is probably in the PATH... // we should probably also test for isFile and canExecute, but the second one is only // available in SDK 6. if ( tc != null ) { getLog().info( "Toolchain in exec-maven-plugin: " + tc ); executable = tc.findTool( executable ); } } return executable; } private static boolean isEmpty( String string ) { return string == null || string.length() == 0; } // // methods used for tests purposes - allow mocking and simulate automatic setters // protected int executeCommandLine( Commandline commandLine, StreamConsumer stream1, StreamConsumer stream2 ) throws CommandLineException { return CommandLineUtils.executeCommandLine( commandLine, stream1, stream2 ); } void setExecutable( String executable ) { this.executable = executable; } String getExecutable() { return executable; } void setWorkingDirectory( String workingDir ) { setWorkingDirectory( new File( workingDir ) ); } void setWorkingDirectory( File workingDir ) { this.workingDirectory = workingDir; } void setArguments( List arguments ) { this.arguments = arguments; } void setBasedir( File basedir ) { this.basedir = basedir; } void setProject( MavenProject project ) { this.project = project; } protected String getSystemProperty( String key ) { return System.getProperty( key ); } public void setSuccessCodes(List list) { this.successCodes = list; } public List getSuccessCodes() { return successCodes; } private Toolchain getToolchain() { Toolchain tc = null; try { if ( session != null ) // session is null in tests.. { ToolchainManager toolchainManager = (ToolchainManager) session.getContainer().lookup( ToolchainManager.ROLE ); if ( toolchainManager != null ) { tc = toolchainManager.getToolchainFromBuildContext( "jdk", session ); } } } catch ( ComponentLookupException componentLookupException ) { // just ignore, could happen in pre-2.0.9 builds.. } return tc; } } ./src/main/java/org/codehaus/mojo/exec/Property.java0000644000175000017500000000214211303510553021627 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Wrapper class for the systemPropery argument type. * * @author Kaare Nilsen */ public class Property { private String key; private String value; public String getKey() { return key; } public void setKey( String key ) { this.key = key; } public String getValue() { return value; } public void setValue( String value ) { this.value = value; } } ./src/main/java/org/codehaus/mojo/exec/Classpath.java0000644000175000017500000000324311303510553021730 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; import java.util.Iterator; /** * @author Jerome Lacoste */ public class Classpath { /** * @parameter dependency */ private Collection dependencies; public void setDependencies( Collection deps ) { this.dependencies = deps; } public void setDependency( String dependency ) { // Is the the correct thing to do? See MOJO-348 if ( dependencies == null ) { setDependencies( new java.util.ArrayList() ); } dependencies.add( dependency ); } public Collection getDependencies() { return dependencies; } public String toString() { StringBuffer buffer = new StringBuffer( "Classpath {" ); if ( dependencies != null ) { for ( Iterator it = dependencies.iterator(); it.hasNext(); ) { buffer.append( " " ).append( it.next() ); } } buffer.append( "}" ); return buffer.toString(); } } ./src/main/java/org/codehaus/mojo/exec/StreamLog.java0000644000175000017500000000524511303510553021707 0ustar user03user03package org.codehaus.mojo.exec; import java.io.PrintStream; import org.apache.maven.plugin.logging.Log; /** * a Simple Maven Log that outputs to a Stream */ class StreamLog implements Log { static final int DEBUG = 0; static final int INFO = 1; static final int WARN = 2; static final int ERROR = 3; private int level = INFO; public void setLevel( int level ) { if ( level < DEBUG || level > ERROR ) { throw new IllegalStateException( "invalid level: " + level ); } this.level = level; } private final PrintStream s; StreamLog( PrintStream s ) { this.s = s; } public void debug( CharSequence content ) { if ( isDebugEnabled() ) { s.println( content ); } } public void debug( CharSequence content, Throwable error ) { if ( isDebugEnabled() ) { s.println( content ); } } public void debug( Throwable error ) { if ( isDebugEnabled() ) { error.printStackTrace( s ); } } public void error( CharSequence content ) { if ( isErrorEnabled() ) { s.println( content ); } } public void error( CharSequence content, Throwable error ) { error( content ); error( error ); } public void error( Throwable error ) { if ( isErrorEnabled() ) { error.printStackTrace( s ); } } public void info( CharSequence content ) { if ( isInfoEnabled() ) { s.println( content ); } } public void info( CharSequence content, Throwable error ) { info( content ); info( error ); } public void info( Throwable error ) { if ( isInfoEnabled() ) { error.printStackTrace( s ); } } public boolean isDebugEnabled() { return level >= DEBUG; } public boolean isErrorEnabled() { return level >= ERROR; } public boolean isInfoEnabled() { return level >= INFO; } public boolean isWarnEnabled() { return level >= WARN; } public void warn( CharSequence content ) { if ( isWarnEnabled() ) { s.println( content ); } } public void warn( CharSequence content, Throwable error ) { warn( content ); warn( error ); } public void warn( Throwable error ) { if ( isWarnEnabled() ) { error.printStackTrace( s ); } } } ./src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java0000644000175000017500000002013011303510553023175 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; /** * This class is used for unifying functionality between the 2 mojo exec plugins ('java' and 'exec'). * It handles parsing the arguments and adding source/test folders. * * @author Philippe Jacot (PJA) * @author Jerome Lacoste */ public abstract class AbstractExecMojo extends AbstractMojo { /** * The enclosing project. * * @parameter expression="${project}" * @required * @readonly */ protected MavenProject project; /** * This folder is added to the list of those folders * containing source to be compiled. Use this if your * plugin generates source code. * * @parameter expression="${sourceRoot}" */ private File sourceRoot; /** * This folder is added to the list of those folders * containing source to be compiled for testing. Use this if your * plugin generates test source code. * * @parameter expression="${testSourceRoot}" */ private File testSourceRoot; /** * Arguments for the executed program * * @parameter expression="${exec.args}" */ private String commandlineArgs; /** * Defines the scope of the classpath passed to the plugin. Set to compile,test,runtime or system depending * on your needs. * @parameter expression="${exec.classpathScope}" default-value="compile" */ protected String classpathScope; /** @see #parseCommandlineArgs */ private static final char PARAMETER_DELIMITER = ' '; /** @see #parseCommandlineArgs */ private static final char STRING_WRAPPER = '"'; /** @see #parseCommandlineArgs */ private static final char ESCAPE_CHAR = '\\'; /** * Collects the project artifacts in the specified List and the project specific classpath * (build output and build test output) Files in the specified List, depending on the plugin classpathScope value. * @param artifacts the list where to collect the scope specific artifacts * @param theClasspathFiles the list where to collect the scope specific output directories * @throws NullPointerException if at least one of the parameter is null */ protected void collectProjectArtifactsAndClasspath( List artifacts, List theClasspathFiles ) { if ( "compile".equals( classpathScope ) ) { artifacts.addAll( project.getCompileArtifacts() ); theClasspathFiles.add( new File( project.getBuild().getOutputDirectory() ) ); } else if ( "test".equals( classpathScope ) ) { artifacts.addAll( project.getTestArtifacts() ); theClasspathFiles.add( new File( project.getBuild().getTestOutputDirectory() ) ); theClasspathFiles.add( new File( project.getBuild().getOutputDirectory() ) ); } else if ( "runtime".equals( classpathScope ) ) { artifacts.addAll( project.getRuntimeArtifacts() ); theClasspathFiles.add( new File( project.getBuild().getOutputDirectory() ) ); } else if ( "system".equals( classpathScope ) ) { artifacts.addAll( project.getSystemArtifacts() ); } else { throw new IllegalStateException( "Invalid classpath scope: " + classpathScope ); } getLog().debug( "Collected project artifacts " + artifacts ); getLog().debug( "Collected project classpath " + theClasspathFiles ); } /** * Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER. * PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using * ESCAPE_CHAR. * * @return Array of String representing the arguments * @throws MojoExecutionException * for wrong formatted arguments */ protected String[] parseCommandlineArgs() throws MojoExecutionException { if ( commandlineArgs == null ) { return null; } boolean inString = false; String arguments = commandlineArgs.trim(); List argumentList = new LinkedList(); int chr = 0; char curChar; StringBuffer arg = new StringBuffer(); while ( chr < arguments.length() ) { curChar = arguments.charAt( chr ); if ( curChar == ESCAPE_CHAR ) { // A char is escaped, replace and skip one char if ( arguments.length() == chr + 1 ) { // ESCAPE_CHAR is the last character... this should be an error (?) // char is just ignored by now getLog().warn( ESCAPE_CHAR + " was the last character in your command line arguments. Verify your parameters." ); } else { // In a string only STRING_WRAPPER is escaped if ( !inString || arguments.charAt( chr + 1 ) == STRING_WRAPPER ) { chr++; } arg.append( arguments.charAt( chr ) ); } } else if ( curChar == PARAMETER_DELIMITER && !inString ) { // Next parameter begins here argumentList.add( arg.toString() ); arg.delete( 0, arg.length() ); } else if ( curChar == STRING_WRAPPER ) { // Entering or leaving a string inString = !inString; } else { // Append this char to the current parameter arg.append( curChar ); } chr++; } if ( inString ) { // Error string not terminated throw new MojoExecutionException( "args contains not properly formatted string" ); } else { // Append last parameter argumentList.add( arg.toString() ); } Iterator it = argumentList.listIterator(); String[] result = new String[argumentList.size()]; int index = 0; while ( it.hasNext() ) { result[index] = (String) it.next(); index++; } getLog().debug( "Args:" ); it = argumentList.listIterator(); while ( it.hasNext() ) { getLog().debug( " <" + (String) it.next() + ">" ); } getLog().debug( " parsed from <" + commandlineArgs + ">" ); return result; } /** * @return true of the mojo has command line arguments */ protected boolean hasCommandlineArgs() { return ( commandlineArgs != null ); } /** * Register compile and compile tests source roots if necessary */ protected void registerSourceRoots() { if ( sourceRoot != null ) { getLog().info( "Registering compile source root " + sourceRoot ); project.addCompileSourceRoot( sourceRoot.toString() ); } if ( testSourceRoot != null ) { getLog().info( "Registering compile test source root " + testSourceRoot ); project.addTestCompileSourceRoot( testSourceRoot.toString() ); } } } ./src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java0000644000175000017500000007076411303510553022335 0ustar user03user03package org.codehaus.mojo.exec; /* * Copyright 2005-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.x */ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.artifact.MavenMetadataSource; import java.io.File; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Set; /** * Executes the supplied java class in the current VM with the enclosing project's * dependencies as classpath. * * @author Kaare Nilsen, David Smiley * @goal java * @requiresDependencyResolution test * @execute phase="validate" * @since 1.0 */ public class ExecJavaMojo extends AbstractExecMojo { /** * @component */ private ArtifactResolver artifactResolver; /** * @component */ private ArtifactFactory artifactFactory; /** * @component */ private ArtifactMetadataSource metadataSource; /** * @parameter expression="${localRepository}" * @required * @readonly * @since 1.0 */ private ArtifactRepository localRepository; /** * @parameter expression="${project.remoteArtifactRepositories}" * @required * @readonly * @since 1.1-beta-1 */ private List remoteRepositories; /** * @component * @since 1.0 */ private MavenProjectBuilder projectBuilder; /** * @parameter expression="${plugin.artifacts}" * @readonly * @since 1.1-beta-1 */ private List pluginDependencies; /** * The main class to execute. * * @parameter expression="${exec.mainClass}" * @required * @since 1.0 */ private String mainClass; /** * The class arguments. * * @parameter expression="${exec.arguments}" * @since 1.0 */ private String[] arguments; /** * A list of system properties to be passed. Note: as the execution is not forked, some system properties * required by the JVM cannot be passed here. Use MAVEN_OPTS or the exec:exec instead. See the user guide for * more information. * * @parameter * @since 1.0 */ private Property[] systemProperties; /** * Indicates if mojo should be kept running after the mainclass terminates. * Usefull for serverlike apps with deamonthreads. * * @parameter expression="${exec.keepAlive}" default-value="false" * @deprecated since 1.1-alpha-1 * @since 1.0 */ private boolean keepAlive; /** * Indicates if the project dependencies should be used when executing * the main class. * * @parameter expression="${exec.includeProjectDependencies}" default-value="true" * @since 1.1-beta-1 */ private boolean includeProjectDependencies; /** * Indicates if this plugin's dependencies should be used when executing * the main class. *

* This is useful when project dependencies are not appropriate. Using only * the plugin dependencies can be particularly useful when the project is * not a java project. For example a mvn project using the csharp plugins * only expects to see dotnet libraries as dependencies. * * @parameter expression="${exec.includePluginDependencies}" default-value="false" * @since 1.1-beta-1 */ private boolean includePluginDependencies; /** * If provided the ExecutableDependency identifies which of the plugin dependencies * contains the executable class. This will have the affect of only including * plugin dependencies required by the identified ExecutableDependency. *

* If includeProjectDependencies is set to true, all of the project dependencies * will be included on the executable's classpath. Whether a particular project * dependency is a dependency of the identified ExecutableDependency will be * irrelevant to its inclusion in the classpath. * * @parameter * @optional * @since 1.1-beta-1 */ private ExecutableDependency executableDependency; /** * Wether to interrupt/join and possibly stop the daemon threads upon quitting.
If this is false, * maven does nothing about the daemon threads. When maven has no more work to do, the VM will normally terminate * any remaining daemon threads. *

* In certain cases (in particular if maven is embedded), * you might need to keep this enabled to make sure threads are properly cleaned up to ensure they don't interfere * with subsequent activity. * In that case, see {@link #daemonThreadJoinTimeout} and * {@link #stopUnresponsiveDaemonThreads} for further tuning. *

* @parameter expression="${exec.cleanupDaemonThreads} default-value="true" * @since 1.1-beta-1 */ private boolean cleanupDaemonThreads; /** * This defines the number of milliseconds to wait for daemon threads to quit following their interruption.
* This is only taken into account if {@link #cleanupDaemonThreads} is true. * A value <=0 means to not timeout (i.e. wait indefinitely for threads to finish). Following a timeout, a * warning will be logged. *

Note: properly coded threads should terminate upon interruption but some threads may prove * problematic: as the VM does interrupt daemon threads, some code may not have been written to handle * interruption properly. For example java.util.Timer is known to not handle interruptions in JDK <= 1.6. * So it is not possible for us to infinitely wait by default otherwise maven could hang. A sensible default * value has been chosen, but this default value may change in the future based on user feedback.

* @parameter expression="${exec.daemonThreadJoinTimeout}" default-value="15000" * @since 1.1-beta-1 */ private long daemonThreadJoinTimeout; /** * Wether to call {@link Thread#stop()} following a timing out of waiting for an interrupted thread to finish. * This is only taken into account if {@link #cleanupDaemonThreads} is true * and the {@link #daemonThreadJoinTimeout} threshold has been reached for an uncooperative thread. * If this is false, or if {@link Thread#stop()} fails to get the thread to stop, then * a warning is logged and Maven will continue on while the affected threads (and related objects in memory) * linger on. Consider setting this to true if you are invoking problematic code that you can't fix. * An example is {@link java.util.Timer} which doesn't respond to interruption. To have Timer * fixed, vote for this bug. * @parameter expression="${exec.stopUnresponsiveDaemonThreads} default-value="false" * @since 1.1-beta-1 */ private boolean stopUnresponsiveDaemonThreads; /** * Deprecated this is not needed anymore. * * @parameter expression="${exec.killAfter}" default-value="-1" * @deprecated since 1.1-alpha-1 * @since 1.0 */ private long killAfter; private Properties originalSystemProperties; /** * Execute goal. * @throws MojoExecutionException execution of the main class or one of the threads it generated failed. * @throws MojoFailureException something bad happened... */ public void execute() throws MojoExecutionException, MojoFailureException { if ( killAfter != -1 ) { getLog().warn( "Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6." ); } if ( null == arguments ) { arguments = new String[0]; } if ( getLog().isDebugEnabled() ) { StringBuffer msg = new StringBuffer( "Invoking : " ); msg.append( mainClass ); msg.append( ".main(" ); for ( int i = 0; i < arguments.length; i++ ) { if ( i > 0 ) { msg.append( ", " ); } msg.append( arguments[i] ); } msg.append( ")" ); getLog().debug( msg ); } IsolatedThreadGroup threadGroup = new IsolatedThreadGroup( mainClass /*name*/ ); Thread bootstrapThread = new Thread( threadGroup, new Runnable() { public void run() { try { Method main = Thread.currentThread().getContextClassLoader().loadClass( mainClass ) .getMethod( "main", new Class[]{ String[].class } ); if ( ! main.isAccessible() ) { getLog().debug( "Setting accessibility to true in order to invoke main()." ); main.setAccessible( true ); } main.invoke( main, new Object[]{arguments} ); } catch ( NoSuchMethodException e ) { // just pass it on Thread.currentThread().getThreadGroup().uncaughtException( Thread.currentThread(), new Exception( "The specified mainClass doesn't contain a main method with appropriate signature.", e ) ); } catch ( Exception e ) { // just pass it on Thread.currentThread().getThreadGroup().uncaughtException( Thread.currentThread(), e ); } } }, mainClass + ".main()" ); bootstrapThread.setContextClassLoader( getClassLoader() ); setSystemProperties(); bootstrapThread.start(); joinNonDaemonThreads( threadGroup ); // It's plausible that spontaneously a non-daemon thread might be created as we try and shut down, // but it's too late since the termination condition (only daemon threads) has been triggered. if ( keepAlive ) { getLog().warn( "Warning: keepAlive is now deprecated and obsolete. Do you need it? Please comment on MEXEC-6." ); waitFor( 0 ); } if ( cleanupDaemonThreads ) { terminateThreads( threadGroup ); try { threadGroup.destroy(); } catch ( IllegalThreadStateException e ) { getLog().warn( "Couldn't destroy threadgroup " + threadGroup, e ); } } if ( originalSystemProperties != null ) { System.setProperties( originalSystemProperties ); } synchronized ( threadGroup ) { if ( threadGroup.uncaughtException != null ) { throw new MojoExecutionException( "An exception occured while executing the Java class. " + threadGroup.uncaughtException.getMessage(), threadGroup.uncaughtException ); } } registerSourceRoots(); } /** * a ThreadGroup to isolate execution and collect exceptions. */ class IsolatedThreadGroup extends ThreadGroup { Throwable uncaughtException; // synchronize access to this public IsolatedThreadGroup( String name ) { super( name ); } public void uncaughtException( Thread thread, Throwable throwable ) { if ( throwable instanceof ThreadDeath ) { return; //harmless } boolean doLog = false; synchronized ( this ) { if ( uncaughtException == null ) // only remember the first one { uncaughtException = throwable; // will be reported eventually } else { doLog = true; } } if ( doLog ) { getLog().warn( "an additional exception was thrown", throwable ); } } } private void joinNonDaemonThreads( ThreadGroup threadGroup ) { boolean foundNonDaemon; do { foundNonDaemon = false; Collection threads = getActiveThreads( threadGroup ); for ( Iterator iter = threads.iterator(); iter.hasNext(); ) { Thread thread = (Thread) iter.next(); if ( thread.isDaemon() ) { continue; } foundNonDaemon = true; //try again; maybe more threads were created while we were busy joinThread( thread, 0 ); } } while ( foundNonDaemon ); } private void joinThread( Thread thread, long timeoutMsecs ) { try { getLog().debug( "joining on thread " + thread ); thread.join( timeoutMsecs ); } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); // good practice if don't throw getLog().warn( "interrupted while joining against thread " + thread, e ); // not expected! } if ( thread.isAlive() ) //generally abnormal { getLog().warn( "thread " + thread + " was interrupted but is still alive after waiting at least " + timeoutMsecs + "msecs" ); } } private void terminateThreads( ThreadGroup threadGroup ) { long startTime = System.currentTimeMillis(); Set uncooperativeThreads = new HashSet(); // these were not responsive to interruption for ( Collection threads = getActiveThreads( threadGroup ); !threads.isEmpty(); threads = getActiveThreads( threadGroup ), threads.removeAll( uncooperativeThreads ) ) { // Interrupt all threads we know about as of this instant (harmless if spuriously went dead (! isAlive()) // or if something else interrupted it ( isInterrupted() ). for ( Iterator iter = threads.iterator(); iter.hasNext(); ) { Thread thread = (Thread) iter.next(); getLog().debug( "interrupting thread " + thread ); thread.interrupt(); } // Now join with a timeout and call stop() (assuming flags are set right) for ( Iterator iter = threads.iterator(); iter.hasNext(); ) { Thread thread = (Thread) iter.next(); if ( ! thread.isAlive() ) { continue; //and, presumably it won't show up in getActiveThreads() next iteration } if ( daemonThreadJoinTimeout <= 0 ) { joinThread( thread, 0 ); //waits until not alive; no timeout continue; } long timeout = daemonThreadJoinTimeout - ( System.currentTimeMillis() - startTime ); if ( timeout > 0 ) { joinThread( thread, timeout ); } if ( ! thread.isAlive() ) { continue; } uncooperativeThreads.add( thread ); // ensure we don't process again if ( stopUnresponsiveDaemonThreads ) { getLog().warn( "thread " + thread + " will be Thread.stop()'ed" ); thread.stop(); } else { getLog().warn( "thread " + thread + " will linger despite being asked to die via interruption" ); } } } if ( ! uncooperativeThreads.isEmpty() ) { getLog().warn( "NOTE: " + uncooperativeThreads.size() + " thread(s) did not finish despite being asked to " + " via interruption. This is not a problem with exec:java, it is a problem with the running code." + " Although not serious, it should be remedied." ); } else { int activeCount = threadGroup.activeCount(); if ( activeCount != 0 ) { // TODO this may be nothing; continue on anyway; perhaps don't even log in future Thread[] threadsArray = new Thread[1]; threadGroup.enumerate( threadsArray ); getLog().debug( "strange; " + activeCount + " thread(s) still active in the group " + threadGroup + " such as " + threadsArray[0] ); } } } private Collection getActiveThreads( ThreadGroup threadGroup ) { Thread[] threads = new Thread[ threadGroup.activeCount() ]; int numThreads = threadGroup.enumerate( threads ); Collection result = new ArrayList( numThreads ); for ( int i = 0; i < threads.length && threads[i] != null; i++ ) { result.add( threads[i] ); } return result; //note: result should be modifiable } /** * Pass any given system properties to the java system properties. */ private void setSystemProperties() { if ( systemProperties != null ) { originalSystemProperties = System.getProperties(); for ( int i = 0; i < systemProperties.length; i++ ) { Property systemProperty = systemProperties[i]; String value = systemProperty.getValue(); System.setProperty( systemProperty.getKey(), value == null ? "" : value ); } } } /** * Set up a classloader for the execution of the main class. * * @return the classloader * @throws MojoExecutionException if a problem happens */ private ClassLoader getClassLoader() throws MojoExecutionException { List classpathURLs = new ArrayList(); this.addRelevantPluginDependenciesToClasspath( classpathURLs ); this.addRelevantProjectDependenciesToClasspath( classpathURLs ); return new URLClassLoader( ( URL[] ) classpathURLs.toArray( new URL[ classpathURLs.size() ] ) ); } /** * Add any relevant project dependencies to the classpath. * Indirectly takes includePluginDependencies and ExecutableDependency into consideration. * * @param path classpath of {@link java.net.URL} objects * @throws MojoExecutionException if a problem happens */ private void addRelevantPluginDependenciesToClasspath( List path ) throws MojoExecutionException { if ( hasCommandlineArgs() ) { arguments = parseCommandlineArgs(); } try { Iterator iter = this.determineRelevantPluginDependencies().iterator(); while ( iter.hasNext() ) { Artifact classPathElement = (Artifact) iter.next(); getLog().debug( "Adding plugin dependency artifact: " + classPathElement.getArtifactId() + " to classpath" ); path.add( classPathElement.getFile().toURL() ); } } catch ( MalformedURLException e ) { throw new MojoExecutionException( "Error during setting up classpath", e ); } } /** * Add any relevant project dependencies to the classpath. * Takes includeProjectDependencies into consideration. * * @param path classpath of {@link java.net.URL} objects * @throws MojoExecutionException if a problem happens */ private void addRelevantProjectDependenciesToClasspath( List path ) throws MojoExecutionException { if ( this.includeProjectDependencies ) { try { getLog().debug( "Project Dependencies will be included." ); List artifacts = new ArrayList(); List theClasspathFiles = new ArrayList(); collectProjectArtifactsAndClasspath( artifacts, theClasspathFiles ); for ( Iterator it = theClasspathFiles.iterator(); it.hasNext(); ) { URL url = ( (File) it.next() ).toURL(); getLog().debug( "Adding to classpath : " + url ); path.add( url ); } Iterator iter = artifacts.iterator(); while ( iter.hasNext() ) { Artifact classPathElement = (Artifact) iter.next(); getLog().debug( "Adding project dependency artifact: " + classPathElement.getArtifactId() + " to classpath" ); path.add( classPathElement.getFile().toURL() ); } } catch ( MalformedURLException e ) { throw new MojoExecutionException( "Error during setting up classpath", e ); } } else { getLog().debug( "Project Dependencies will be excluded." ); } } /** * Determine all plugin dependencies relevant to the executable. * Takes includePlugins, and the executableDependency into consideration. * * @return a set of Artifact objects. * (Empty set is returned if there are no relevant plugin dependencies.) * @throws MojoExecutionException if a problem happens resolving the plufin dependencies */ private Set determineRelevantPluginDependencies() throws MojoExecutionException { Set relevantDependencies; if ( this.includePluginDependencies ) { if ( this.executableDependency == null ) { getLog().debug( "All Plugin Dependencies will be included." ); relevantDependencies = new HashSet( this.pluginDependencies ); } else { getLog().debug( "Selected plugin Dependencies will be included." ); Artifact executableArtifact = this.findExecutableArtifact(); Artifact executablePomArtifact = this.getExecutablePomArtifact( executableArtifact ); relevantDependencies = this.resolveExecutableDependencies( executablePomArtifact ); } } else { relevantDependencies = Collections.EMPTY_SET; getLog().debug( "Plugin Dependencies will be excluded." ); } return relevantDependencies; } /** * Get the artifact which refers to the POM of the executable artifact. * * @param executableArtifact this artifact refers to the actual assembly. * @return an artifact which refers to the POM of the executable artifact. */ private Artifact getExecutablePomArtifact( Artifact executableArtifact ) { return this.artifactFactory.createBuildArtifact( executableArtifact.getGroupId(), executableArtifact.getArtifactId(), executableArtifact.getVersion(), "pom" ); } /** * Examine the plugin dependencies to find the executable artifact. * * @return an artifact which refers to the actual executable tool (not a POM) * @throws MojoExecutionException if no executable artifact was found */ private Artifact findExecutableArtifact() throws MojoExecutionException { //ILimitedArtifactIdentifier execToolAssembly = this.getExecutableToolAssembly(); Artifact executableTool = null; for ( Iterator iter = this.pluginDependencies.iterator(); iter.hasNext(); ) { Artifact pluginDep = (Artifact) iter.next(); if ( this.executableDependency.matches( pluginDep ) ) { executableTool = pluginDep; break; } } if ( executableTool == null ) { throw new MojoExecutionException( "No dependency of the plugin matches the specified executableDependency." + " Specified executableToolAssembly is: " + executableDependency.toString() ); } return executableTool; } /** * Resolve the executable dependencies for the specified project * @param executablePomArtifact the project's POM * @return a set of Artifacts * @throws MojoExecutionException if a failure happens */ private Set resolveExecutableDependencies( Artifact executablePomArtifact ) throws MojoExecutionException { Set executableDependencies; try { MavenProject executableProject = this.projectBuilder.buildFromRepository( executablePomArtifact, this.remoteRepositories, this.localRepository ); //get all of the dependencies for the executable project List dependencies = executableProject.getDependencies(); //make Artifacts of all the dependencies Set dependencyArtifacts = MavenMetadataSource.createArtifacts( this.artifactFactory, dependencies, null, null, null ); //not forgetting the Artifact of the project itself dependencyArtifacts.add( executableProject.getArtifact() ); //resolve all dependencies transitively to obtain a comprehensive list of assemblies ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencyArtifacts, executablePomArtifact, Collections.EMPTY_MAP, this.localRepository, this.remoteRepositories, metadataSource, null, Collections.EMPTY_LIST ); executableDependencies = result.getArtifacts(); } catch ( Exception ex ) { throw new MojoExecutionException( "Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex ); } return executableDependencies; } /** * Stop program execution for nn millis. * * @param millis the number of millis-seconds to wait for, * 0 stops program forever. */ private void waitFor( long millis ) { Object lock = new Object(); synchronized ( lock ) { try { lock.wait( millis ); } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); // good practice if don't throw getLog().warn( "Spuriously interrupted while waiting for " + millis + "ms", e ); } } } } ./src/site/0000755000175000017500000000000011303510553011766 5ustar user03user03./src/site/apt/0000755000175000017500000000000011303510553012552 5ustar user03user03./src/site/apt/examples/0000755000175000017500000000000011303510553014370 5ustar user03user03./src/site/apt/examples/example-exec-using-plugin-dependencies.apt0000644000175000017500000001075011303510553024521 0ustar user03user03 ------ Using plugin dependencies with the exec:java goal ------ Jerome Lacoste ------ 2008-10-10 ------ ~~ Copyright 2008 The Codehaus ~~ ~~ Licensed under the Apache License, Version 2.0 (the "License"); ~~ you may not use this file except in compliance with the License. ~~ You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, software ~~ distributed under the License is distributed on an "AS IS" BASIS, ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~~ See the License for the specific language governing permissions and ~~ limitations under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Using Plugin Dependencies Instead of Project Dependencies Ocassionally it is desirable to execute a Java class without affecting your project's dependencies. For example, if you are using the Maven csharp plugins, adding Java dependencies to your project will upset the csharp compiler. Therefore the Exec Maven Plugin allows you specify dependencies of your executable class as plugin dependencies. Since Maven takes plugin dependencies into consideration when determining build order for a multi-module project your build order should automatically be appropriately adjusted (I think). If you specify your executable class dependencies as plugin dependencies, you may end up with extraneous undesirable dependences required by the Exec Maven Plugin but not by your executable class. If this causes a problem, or if you simply prefer to avoid the extraneous dependencies you can use the <<<\>>> configuration element. The <<<\>>> element allows you to identify the particular artifact in the list of the plugin's dependencies which contains your executable class. The Exec Maven Plugin will ensure that only the selected artifact identified by the <<<\>>> configuration element and the selected artifact's transitive dependencies are used when the <<>> is executed. Although the use of the <<<\>>> configuration element will prevent the Java class being executed from seeing extraneous classes, the Exec Maven Plugin itself will still see all of the plugin dependencies. For example if your executable Java class has a dependency upon a brand new version of <<>> and you specify this as a plugin dependency then the Exec Maven Plugin, which already has a transitive dependency upon <<>>, will end up using the brand new version you explictly supplied. It is unlikely you will encounter a situation where this will be a problem, but hopefully this knowledge will help you diagnose such a problem if it occurs. None of this is relevant unless your using the plugin dependencies for your executable (<<>>). * Example POM Configuration using Plugin Dependencies ------------------- ... org.codehaus.mojo exec-maven-plugin 1.1 ... java false true com.example.myproject mylib com.example.Main argument1 ... myproperty myvalue ... com.example.myproject mylib 1.3.5 jar ... ------------------- ./src/site/apt/examples/example-exec-or-java-change-classpath-scope.apt0000644000175000017500000000255211303510553025326 0ustar user03user03 ------ Changing the classpath scope ------ Jerome Lacoste ------ 2008-10-10 ------ ~~ Copyright 2008 The Codehaus ~~ ~~ Licensed under the Apache License, Version 2.0 (the "License"); ~~ you may not use this file except in compliance with the License. ~~ You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, software ~~ distributed under the License is distributed on an "AS IS" BASIS, ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~~ See the License for the specific language governing permissions and ~~ limitations under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Changing the classpath scope when running Java programs Whether you use the <<>> goal or the special support of Java for the <<>> goal, you might want to change the scope of the plugin execution. This can be achieved using the <<>> configuration element, e.g. for a <<>> scope: ------------------- ... test ... ------------------- or, on the command line, ----- mvn exec:exec [...] -Dexec.classpathScope="java" ----- ./src/site/apt/examples/example-exec-for-java-programs.apt0000644000175000017500000000566511303510553023022 0ustar user03user03 ------ Running Java programs with the exec goal ------ Jerome Lacoste ------ 2008-10-10 ------ ~~ Copyright 2008 The Codehaus ~~ ~~ Licensed under the Apache License, Version 2.0 (the "License"); ~~ you may not use this file except in compliance with the License. ~~ You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, software ~~ distributed under the License is distributed on an "AS IS" BASIS, ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~~ See the License for the specific language governing permissions and ~~ limitations under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Running Java programs with the exec goal Special treatment of some command line arguments and configuration parameters facilitate the running of Java programs in external processes. Note: with the java mojo, there are some confusion caused by the almost duplication of functionality between the arguments and commandArgs configuration parameters. * If commandLineArgs is specified, it will be used as is, except for replacing %classpath with proper classpath using dependencies * Otherwise if the property exec.args is specified, it will be used * Otherwise the list of and will be parsed and used See {{http://jira.codehaus.org/browse/MEXEC-59}} for discussion. * Command line If specified as part of the <<>> argument, the special string <<<%classpath>>> will be replaced by the project classpath as computed by Maven. ----- mvn exec:exec -Dexec.executable="java" [...] -Dexec.args="%classpath" ----- * POM configuration To execute Java programs, the Exec Plugin helps by allowing the <<<\>>> special argument: ------------------- java -Dmyproperty=myvalue -classpath com.example.Main ... ------------------- or if one wants to restrict the dependencies in the classpath: ------------------- java -Dmyproperty=myvalue -classpath commons-io:commons-io commons-lang:commons-lang com.example.Main ... ------------------- ./src/site/apt/usage.apt0000644000175000017500000001220611303510553014365 0ustar user03user03 ------ Usage ------ Jerome Lacoste ------ 2008-10-10 ------ ~~ Copyright 2006 The Codehaus ~~ ~~ Licensed under the Apache License, Version 2.0 (the "License"); ~~ you may not use this file except in compliance with the License. ~~ You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, software ~~ distributed under the License is distributed on an "AS IS" BASIS, ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~~ See the License for the specific language governing permissions and ~~ limitations under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Usage * Exec goal You can formally specify all the relevant execution information in the plugin configuration. Depending on your use case, you can also specify some or all information using system properties. ** Command line Using system properties you would just execute it like in the following example. ----- mvn exec:exec -Dexec.executable="maven" [-Dexec.workingdir="/tmp"] -Dexec.args="-X myproject:dist" ----- ** POM Configuration Add a configuration similar to the following to your POM: ------------------- ... org.codehaus.mojo exec-maven-plugin 1.1 ... exec maven /tmp -X myproject:dist ... ... ------------------- * Java goal This goal helps you run a Java program within the same VM as Maven. ** Differences compared to plain command line The goal goes to great length to try to mimic the way the VM works, but there are some small subttle differences. Today all differences come from the way the goal deals with <>. *--------------------------------------+------------------------------------------+ | command line | Java Mojo | *--------------------------------------+------------------------------------------+ | The VM exits as soon as the only | By default daemon threads are joined | | remaining threads are daemon threads | and interrupted once all known non | | | daemon threads have quitted. The join | | | timeout is customisable | | | The user might wish to further cleanup | | | cleanup by stopping the unresponsive | | | threads. | | | The user can disable the full extra | | | thread management (interrupt/join/[stop])| *--------------------------------------+------------------------------------------+ Read the documentation for the {{{java-mojo.html}java goal}} for more information on how to configure this behavior. If you find out that these differences are unacceptable for your case, you may need to use the {{{exec-mojo.html} exec goal}} to wrap your Java executable. ** Command line If you want to execute Java programs in the same VM, you can either use the command line version ----- mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ... ----- ** POM Configuration or you can configure the plugin in your POM: ------------------- ... org.codehaus.mojo exec-maven-plugin 1.1 ... java com.example.Main argument1 ... myproperty myvalue ... ... ------------------- <> The <<>> goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the Maven VM using the <<>> environment variable. E.g. ------------------- MAVEN_OPTS=-Xmx1024m ------------------- Otherwise consider using the <<>> goal. ./src/site/apt/index.apt0000644000175000017500000000321511303510553014370 0ustar user03user03 ------ Introduction ------ Jerome Lacoste ------ 2008-10-10 ------ ~~ Copyright 2006 The Codehaus ~~ ~~ Licensed under the Apache License, Version 2.0 (the "License"); ~~ you may not use this file except in compliance with the License. ~~ You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, software ~~ distributed under the License is distributed on an "AS IS" BASIS, ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~~ See the License for the specific language governing permissions and ~~ limitations under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Exec Maven Plugin The plugin provides 2 goals to help execute system and Java programs. * Goals Overview General information about the goals. * {{{exec-mojo.html}exec:exec}} execute programs and Java programs in a separate process. * {{{java-mojo.html}exec:java}} execute Java programs in the same VM. * Usage Instructions on how to use the Exec Plugin can be found on the {{{usage.html}usage page}}. * Examples To provide you with better understanding of some usages of the Exec Plugin, you can take a look into the following examples: * {{{examples/example-exec-for-java-programs.html} Running Java programs with exec:exec}} * {{{examples/example-exec-or-java-change-classpath-scope.html} Changing the classpath scope when running Java programs}} * {{{examples/example-exec-using-plugin-dependencies.html} Using plugin dependencies with exec:exec}} ./src/site/site.xml0000644000175000017500000000141011303510553013450 0ustar user03user03 ./src/site/fml/0000755000175000017500000000000011303510553012544 5ustar user03user03./src/site/fml/faq.fml0000644000175000017500000000233311303510553014014 0ustar user03user03 How to execute the plugin multiple times ?

Use several execution nodes each with a different id. Don't forget to bind each execution to a phase.

Read the full answer.

./pom.xml0000644000175000017500000001004411303510553011547 0ustar user03user03 4.0.0 org.codehaus.mojo mojo-parent 20 exec-maven-plugin 1.1.1 maven-plugin Exec Maven Plugin A plugin to allow execution of system and Java programs http://mojo.codehaus.org/exec-maven-plugin 2005 2.0.6 jira http://jira.codehaus.org/browse/MEXEC jerome Jerome Lacoste jerome@coffeebreaks.org CoffeeBreaks http://www.coffeebreaks.org Java Developer +1 kaare Kaare Nilsen kaare.nilsen@gmail.com Objectware http://www.objectware.no Java Developer +1 David Smiley protected Patch Contributor Milos Kleint protected Patch Contributor Apache License 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo scm:svn:http://svn.codehaus.org/mojo/tags/exec-maven-plugin-1.1.1 scm:svn:https://svn.codehaus.org/mojo/tags/exec-maven-plugin-1.1.1 http://fisheye.codehaus.org/browse/mojo/tags/exec-maven-plugin-1.1.1 org.apache.maven maven-toolchain 1.0 org.apache.maven maven-project 2.0.6 org.apache.maven maven-model 2.0.6 org.apache.maven maven-artifact 2.0.6 org.apache.maven maven-artifact-manager 2.0.6 org.apache.maven maven-core 2.0.6 org.apache.maven maven-plugin-api 2.0.6 org.codehaus.plexus plexus-utils 1.5.6 org.codehaus.plexus plexus-container-default 1.0-alpha-9 org.apache.maven.shared maven-plugin-testing-harness 1.0-beta-1 test ./LICENSE.txt0000644000175000017500000000206711303510553012063 0ustar user03user03The MIT License Copyright (c) 2005-2006, The Codehaus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.