maven-invoker-2.1.1/0000775000175000017500000000000012232232274013625 5ustar ebourgebourgmaven-invoker-2.1.1/src/0000775000175000017500000000000012232232274014414 5ustar ebourgebourgmaven-invoker-2.1.1/src/site/0000775000175000017500000000000012232232274015360 5ustar ebourgebourgmaven-invoker-2.1.1/src/site/site.xml0000664000175000017500000000273412034304133017046 0ustar ebourgebourg org.apache.maven.skins maven-fluido-skin 1.3.0 maven-invoker-2.1.1/src/site/apt/0000775000175000017500000000000012232232274016144 5ustar ebourgebourgmaven-invoker-2.1.1/src/site/apt/index.apt0000664000175000017500000000650512034124065017765 0ustar ebourgebourg --- Introduction --- John Casey --- 2008-08-02 --- ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you 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 Maven Invoker In many cases, tools (including Maven itself) may want to fire off a Maven build in a clean environment. Why? Perhaps you want to avoid polluting the current system environment with side-effects produced by Maven plugins. Maybe you want to run the build from a different working directory than the current <<<$\{user.dir\}>>>. Maybe you want to retain the ability to surgically kill one of many Maven builds if it hangs for some reason. This API is concerned with firing a Maven build in a new JVM. It accomplishes its task by building up a conventional Maven command line from options given in the current request, along with those global options specified in the invoker itself. Once it has the command line, the invoker will execute it, and capture the resulting exit code or any exception thrown to signal a failure to execute. Input/output control can be specified using an <<>> and up to two <<>>s. * Features * Tracking of exit code and exception resulting from an invocation * Global Options: * Maven-Home Location (location of Maven application directory) * Global Checksum policy (fail/warn, global across defined repositories) * Local Repository Location * Working Directory * Input/Output Handlers * API Logger * Maven Executable [] * Request Options: * Global Checksum Policy (fail/warn, global across defined repositories) * Local Repository Location * Project Base Directory * POM File * POM File-Name (used in conjunction with Base Directory) * Interactive/Batch Mode (determines whether Maven prompts for input) * Offline Mode * Update-Snapshots Flag * Debug Flag (show debug-level output) * Show-Errors Flag (show exception stacktraces, but not full debug output) * Inherit-Shell-Environment Flag (inherit envars from the shell used to start the current JVM) * Reactor-Failure Behavior (fail-at-end, fail-never, etc.) * Input/Output Handlers * Build Properties (-D switches) * Build Goals * Settings Location (<<>> file path) * Threadcount ( since Maven3 with -T ) * Toolchains location ( since Maven3 with -t ) [] [] maven-invoker-2.1.1/src/site/apt/usage.apt0000664000175000017500000001252212042046341017755 0ustar ebourgebourg --- Usage --- John Casey --- 2008-08-02 --- ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you 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 This page documents the basic usage of the Maven invocation API. * Hello, World The simplest possible way to use the invocation API is to construct the invoker and request at the same time, and simply call <<>>. In this example, we don't care about the build result: +---+ InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile( new File( "/path/to/pom.xml" ) ); request.setGoals( Collections.singletonList( "install" ) ); Invoker invoker = new DefaultInvoker(); invoker.execute( request ); +---+ This code will execute a new Maven build to the <<>> lifecycle phase for the project defined at <<>>. If the build fails, we will remain blissfully ignorant... * Checking the Exit Code If we wanted to detect a build failure in the above example, we could simply add the following lines: +---+ InvocationResult result = invoker.execute( request ); if ( result.getExitCode() != 0 ) { throw new IllegalStateException( "Build failed." ); } +---+ This will retrieve the exit code from the invocation result, and throw an exception if it's not <<<0>>> (the traditional all-clear code). Note that we could capture the build output by adding an <<>> instance to either the <<>> or the <<>>. * Caching the Invoker Since you can specify global options for Maven invocations via the <<>> configuration, it will often make sense to configure a single <<>> instance, and reuse it over multiple method calls: +---+ // we will always call the same goals... private static final List PUBLISH_GOALS = Arrays.asList( "clean", "site-deploy" ); // define a field for the Invoker instance. private final Invoker invoker; // now, instantiate the invoker in the class constructor... public SomeClass( File localRepositoryDir ) { Invoker newInvoker = new DefaultInvoker(); newInvoker.setLocalRepositoryDirectory( localRepositoryDir ); this.invoker = newInvoker; } // this method will be called repeatedly, and fire off new builds... public void publishSite( File siteDirectory ) throws PublishException { InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( siteDirectory ); request.setInteractive( false ); request.setGoals( PUBLISH_GOALS ); InvocationResult result = invoker.execute( request ); if ( result.getExitCode() != 0 ) { if ( result.getExecutionException() != null ) { throw new PublishException( "Failed to publish site.", result.getExecutionException() ); } else { throw new PublishException( "Failed to publish site. Exit code: " + result.getExitCode() ); } } } +---+ As you can see, we're using the same local repository location (since the site-generation artifacts will most likely be common to most sites), the same invoker instance (it's configured, we may as well reuse it), and the same set of goals per build. We can actually accommodate a fairly complex configuration of the Invoker without adding complexity to the <<>> method in this manner. * Configuring the Maven Home Directory You can use the method <<>> to specify which Maven executable it should use. If you don't provide an explicit value for this setting, the <<>> will automatically try to detect a Maven installation by evaluating the system property <<>> and the environment variable <<>>. <> If you use the invocation API in tests run by the {{{../../plugins/maven-surefire-plugin}Maven Surefire Plugin}}, you need to tell Surefire to pass the system property <<>> to the tests in order for the automatic Maven detection to work: +---+ ... org.apache.maven.plugins maven-surefire-plugin 2.12.4 ${maven.home} ... ... +---+ maven-invoker-2.1.1/src/test/0000775000175000017500000000000012232232274015373 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/0000775000175000017500000000000012232232274016314 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/org/0000775000175000017500000000000012232232274017103 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/org/apache/0000775000175000017500000000000012232232274020324 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/org/apache/maven/0000775000175000017500000000000012232232274021432 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/org/apache/maven/shared/0000775000175000017500000000000012232232274022700 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/org/apache/maven/shared/invoker/0000775000175000017500000000000012232232274024355 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java0000664000175000017500000001564511020211326031174 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.net.MalformedURLException; import junit.framework.TestCase; public class SystemOutLoggerTest extends TestCase { private static final Throwable EXCEPTION = new MalformedURLException( "This is meant to happen. It's part of the test." ); private static final String MESSAGE = "This is a test message."; public void testDebugWithMessageOnly() { logTestStart(); new SystemOutLogger().debug( MESSAGE ); } public void testDebugWithMessageAndError() { logTestStart(); new SystemOutLogger().debug( MESSAGE, EXCEPTION ); } public void testDebugWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().debug( null ); } public void testDebugWithNullMessageError() { logTestStart(); new SystemOutLogger().debug( null, EXCEPTION ); } public void testDebugWithMessageNullError() { logTestStart(); new SystemOutLogger().debug( MESSAGE, null ); } public void testInfoWithMessageOnly() { logTestStart(); new SystemOutLogger().info( MESSAGE ); } public void testInfoWithMessageAndError() { logTestStart(); new SystemOutLogger().info( MESSAGE, EXCEPTION ); } public void testInfoWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().info( null ); } public void testInfoWithNullMessageError() { logTestStart(); new SystemOutLogger().info( null, EXCEPTION ); } public void testInfoWithMessageNullError() { logTestStart(); new SystemOutLogger().info( MESSAGE, null ); } public void testWarnWithMessageOnly() { logTestStart(); new SystemOutLogger().warn( MESSAGE ); } public void testWarnWithMessageAndError() { logTestStart(); new SystemOutLogger().warn( MESSAGE, EXCEPTION ); } public void testWarnWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().warn( null ); } public void testWarnWithNullMessageError() { logTestStart(); new SystemOutLogger().warn( null, EXCEPTION ); } public void testWarnWithMessageNullError() { logTestStart(); new SystemOutLogger().warn( MESSAGE, null ); } public void testErrorWithMessageOnly() { logTestStart(); new SystemOutLogger().error( MESSAGE ); } public void testErrorWithMessageAndError() { logTestStart(); new SystemOutLogger().error( MESSAGE, EXCEPTION ); } public void testErrorWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().error( null ); } public void testErrorWithNullMessageError() { logTestStart(); new SystemOutLogger().error( null, EXCEPTION ); } public void testErrorWithMessageNullError() { logTestStart(); new SystemOutLogger().error( MESSAGE, null ); } public void testFatalErrorWithMessageOnly() { logTestStart(); new SystemOutLogger().fatalError( MESSAGE ); } public void testFatalErrorWithMessageAndError() { logTestStart(); new SystemOutLogger().fatalError( MESSAGE, EXCEPTION ); } public void testFatalErrorWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().fatalError( null ); } public void testFatalErrorWithNullMessageError() { logTestStart(); new SystemOutLogger().fatalError( null, EXCEPTION ); } public void testFatalErrorWithMessageNullError() { logTestStart(); new SystemOutLogger().fatalError( MESSAGE, null ); } public void testDefaultThresholdInfo() { assertEquals( InvokerLogger.INFO, new SystemOutLogger().getThreshold() ); } public void testThresholdDebug() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold( InvokerLogger.DEBUG ); assertTrue( logger.isDebugEnabled() ); assertTrue( logger.isInfoEnabled() ); assertTrue( logger.isWarnEnabled() ); assertTrue( logger.isErrorEnabled() ); assertTrue( logger.isFatalErrorEnabled() ); } public void testThresholdInfo() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold( InvokerLogger.INFO ); assertFalse( logger.isDebugEnabled() ); assertTrue( logger.isInfoEnabled() ); assertTrue( logger.isWarnEnabled() ); assertTrue( logger.isErrorEnabled() ); assertTrue( logger.isFatalErrorEnabled() ); } public void testThresholdWarn() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold( InvokerLogger.WARN ); assertFalse( logger.isDebugEnabled() ); assertFalse( logger.isInfoEnabled() ); assertTrue( logger.isWarnEnabled() ); assertTrue( logger.isErrorEnabled() ); assertTrue( logger.isFatalErrorEnabled() ); } public void testThresholdError() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold( InvokerLogger.ERROR ); assertFalse( logger.isDebugEnabled() ); assertFalse( logger.isInfoEnabled() ); assertFalse( logger.isWarnEnabled() ); assertTrue( logger.isErrorEnabled() ); assertTrue( logger.isFatalErrorEnabled() ); } public void testThresholdFatal() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold( InvokerLogger.FATAL ); assertFalse( logger.isDebugEnabled() ); assertFalse( logger.isInfoEnabled() ); assertFalse( logger.isWarnEnabled() ); assertFalse( logger.isErrorEnabled() ); assertTrue( logger.isFatalErrorEnabled() ); } // this is just a debugging helper for separating unit test output... private void logTestStart() { NullPointerException npe = new NullPointerException(); StackTraceElement element = npe.getStackTrace()[1]; System.out.println( "Starting: " + element.getMethodName() ); } } maven-invoker-2.1.1/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java0000664000175000017500000011216412042043133032542 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Properties; import java.util.Set; import junit.framework.TestCase; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; public class MavenCommandLineBuilderTest extends TestCase { private List toDelete = new ArrayList(); private Properties sysProps; public void testWrapwithQuotes() { TestCommandLineBuilder tcb = new TestCommandLineBuilder(); String test = "noSpacesInHere"; assertSame( test, tcb.wrapStringWithQuotes( test ) ); assertEquals( "noSpacesInHere", tcb.wrapStringWithQuotes( test ) ); test = "bunch of spaces in here"; assertNotSame( test, tcb.wrapStringWithQuotes( test ) ); assertEquals( "\"bunch of spaces in here\"", tcb.wrapStringWithQuotes( test ) ); } public void testShouldFailToSetLocalRepoLocationGloballyWhenItIsAFile() throws IOException { logTestStart(); File lrd = File.createTempFile( "workdir-test", "file" ).getCanonicalFile(); toDelete.add( lrd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setLocalRepositoryDirectory( lrd ); Commandline cli = new Commandline(); try { tcb.setEnvironmentPaths( newRequest(), cli ); fail( "Should not set local repo location to point to a file." ); } catch ( IllegalArgumentException e ) { assertTrue( true ); } } public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() throws IOException { logTestStart(); File lrd = File.createTempFile( "workdir-test", "file" ).getCanonicalFile(); toDelete.add( lrd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); try { tcb.setEnvironmentPaths( newRequest().setLocalRepositoryDirectory( lrd ), cli ); fail( "Should not set local repo location to point to a file." ); } catch ( IllegalArgumentException e ) { assertTrue( true ); } } public void testShouldSetLocalRepoLocationGlobally() throws Exception { logTestStart(); File tmpDir = getTempDir(); File lrd = new File( tmpDir, "workdir" ).getCanonicalFile(); lrd.mkdirs(); toDelete.add( lrd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setLocalRepositoryDirectory( lrd ); Commandline cli = new Commandline(); tcb.setEnvironmentPaths( newRequest(), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); } public void testShouldSetLocalRepoLocationFromRequest() throws Exception { logTestStart(); File tmpDir = getTempDir(); File lrd = new File( tmpDir, "workdir" ).getCanonicalFile(); lrd.mkdirs(); toDelete.add( lrd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setEnvironmentPaths( newRequest().setLocalRepositoryDirectory( lrd ), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); } public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { logTestStart(); File tmpDir = getTempDir(); File lrd = new File( tmpDir, "workdir" ).getCanonicalFile(); File glrd = new File( tmpDir, "global-workdir" ).getCanonicalFile(); lrd.mkdirs(); glrd.mkdirs(); toDelete.add( lrd ); toDelete.add( glrd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setLocalRepositoryDirectory( glrd ); Commandline cli = new Commandline(); tcb.setEnvironmentPaths( newRequest().setLocalRepositoryDirectory( lrd ), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); } public void testShouldSetWorkingDirectoryGlobally() throws Exception { logTestStart(); File tmpDir = getTempDir(); File wd = new File( tmpDir, "workdir" ); wd.mkdirs(); toDelete.add( wd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setWorkingDirectory( wd ); Commandline cli = new Commandline(); tcb.setEnvironmentPaths( newRequest(), cli ); assertEquals( cli.getWorkingDirectory(), wd ); } public void testShouldSetWorkingDirectoryFromRequest() throws Exception { logTestStart(); File tmpDir = getTempDir(); File wd = new File( tmpDir, "workdir" ); wd.mkdirs(); toDelete.add( wd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); InvocationRequest req = newRequest(); req.setBaseDirectory( wd ); Commandline cli = new Commandline(); tcb.setEnvironmentPaths( req, cli ); assertEquals( cli.getWorkingDirectory(), wd ); } public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { logTestStart(); File tmpDir = getTempDir(); File wd = new File( tmpDir, "workdir" ); File gwd = new File( tmpDir, "global-workdir" ); wd.mkdirs(); gwd.mkdirs(); toDelete.add( wd ); toDelete.add( gwd ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setWorkingDirectory( gwd ); InvocationRequest req = newRequest(); req.setBaseDirectory( wd ); Commandline cli = new Commandline(); tcb.setEnvironmentPaths( req, cli ); assertEquals( cli.getWorkingDirectory(), wd ); } public void testShouldUseSystemOutLoggerWhenNoneSpecified() throws Exception { logTestStart(); setupTempMavenHomeIfMissing(); TestCommandLineBuilder tclb = new TestCommandLineBuilder(); tclb.checkRequiredState(); } private File setupTempMavenHomeIfMissing() throws Exception { String mavenHome = System.getProperty( "maven.home" ); File appDir = null; if ( ( mavenHome == null ) || !new File( mavenHome ).exists() ) { File tmpDir = getTempDir(); appDir = new File( tmpDir, "invoker-tests/maven-home" ); File binDir = new File( appDir, "bin" ); binDir.mkdirs(); toDelete.add( appDir ); if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) { createDummyFile( binDir, "mvn.bat" ); } else { createDummyFile( binDir, "mvn" ); } Properties props = System.getProperties(); props.setProperty( "maven.home", appDir.getCanonicalPath() ); System.setProperties( props ); } else { appDir = new File( mavenHome ); } return appDir; } public void testShouldFailIfLoggerSetToNull() { logTestStart(); TestCommandLineBuilder tclb = new TestCommandLineBuilder(); tclb.setLogger( null ); try { tclb.checkRequiredState(); fail( "Should not allow execution to proceed when logger is missing." ); } catch ( IllegalStateException e ) { assertTrue( true ); } catch ( IOException e ) { fail( e.getMessage() ); } } public void testShouldFindDummyMavenExecutable() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); File dummyMavenHomeBin = new File( base, "dummy-maven-home/bin" ); dummyMavenHomeBin.mkdirs(); toDelete.add( base ); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) { check = createDummyFile( dummyMavenHomeBin, "mvn.bat" ); } else { check = createDummyFile( dummyMavenHomeBin, "mvn" ); } TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setMavenHome( dummyMavenHomeBin.getParentFile() ); File mavenExe = tcb.findMavenExecutable(); assertEquals( check.getCanonicalPath(), mavenExe.getCanonicalPath() ); } public void testShouldSetBatchModeFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setInteractive( false ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-B" ) ); } public void testShouldSetOfflineFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setOffline( true ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-o" ) ); } public void testShouldSetUpdateSnapshotsFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setUpdateSnapshots( true ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-U" ) ); } public void testShouldSetDebugFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setDebug( true ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-X" ) ); } public void testShouldSetErrorFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setShowErrors( true ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-e" ) ); } public void testDebugOptionShouldMaskShowErrorsOption() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setDebug( true ).setShowErrors( true ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-X" ) ); assertArgumentsNotPresent( cli, Collections.singleton( "-e" ) ); } public void testActivateReactor() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().activateReactor( null, null ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-r" ) ); } public void testActivateReactorIncludesExcludes() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); String[] includes = new String[] {"foo", "bar"}; String[] excludes = new String[] {"baz", "quz"}; tcb.setReactorBehavior( newRequest().activateReactor( includes, excludes ), cli ); Set args = new HashSet(); args.add( "-r" ); args.add( "-D" ); args.add( "maven.reactor.includes=foo,bar" ); args.add( "maven.reactor.excludes=baz,quz" ); assertArgumentsPresent( cli, args ); } public void testAlsoMake() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setAlsoMake( true ), cli ); //-am is only useful with -pl assertArgumentsNotPresent( cli, Collections.singleton( "-am" ) ); } public void testProjectsAndAlsoMake() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setProjects( Collections.singletonList( "proj1" ) ).setAlsoMake( true ), cli ); assertArgumentsPresentInOrder( cli, "-pl", "proj1", "-am" ); } public void testAlsoMakeDependents() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setAlsoMakeDependents( true ), cli ); //-amd is only useful with -pl assertArgumentsNotPresent( cli, Collections.singleton( "-amd" ) ); } public void testProjectsAndAlsoMakeDependents() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setProjects( Collections.singletonList( "proj1" ) ).setAlsoMakeDependents( true ), cli ); assertArgumentsPresentInOrder( cli, "-pl", "proj1", "-amd" ); } public void testProjectsAndAlsoMakeAndAlsoMakeDependents() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setProjects( Collections.singletonList( "proj1" ) ).setAlsoMake( true ).setAlsoMakeDependents( true ), cli ); assertArgumentsPresentInOrder( cli, "-pl", "proj1", "-am", "-amd" ); } public void testShouldSetResumeFrom() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setResumeFrom( ":module3" ), cli ); assertArgumentsPresentInOrder( cli, "-rf", ":module3" ); } public void testShouldSetStrictChecksumPolityFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setGlobalChecksumPolicy( InvocationRequest.CHECKSUM_POLICY_FAIL ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-C" ) ); } public void testShouldSetLaxChecksumPolicyFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setFlags( newRequest().setGlobalChecksumPolicy( InvocationRequest.CHECKSUM_POLICY_WARN ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-c" ) ); } public void testShouldSetFailAtEndFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setFailureBehavior( InvocationRequest.REACTOR_FAIL_AT_END ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-fae" ) ); } public void testShouldSetFailNeverFlagFromRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setFailureBehavior( InvocationRequest.REACTOR_FAIL_NEVER ), cli ); assertArgumentsPresent( cli, Collections.singleton( "-fn" ) ); } public void testShouldUseDefaultOfFailFastWhenSpecifiedInRequest() { logTestStart(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); Commandline cli = new Commandline(); tcb.setReactorBehavior( newRequest().setFailureBehavior( InvocationRequest.REACTOR_FAIL_FAST ), cli ); Set banned = new HashSet(); banned.add( "-fae" ); banned.add( "-fn" ); assertArgumentsNotPresent( cli, banned ); } public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "file-option-nonstd-pom-file-location" ).getCanonicalFile(); projectDir.mkdirs(); File pomFile = createDummyFile( projectDir, "non-standard-pom.xml" ).getCanonicalFile(); Commandline cli = new Commandline(); InvocationRequest req = newRequest().setPomFile( pomFile ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setEnvironmentPaths( req, cli ); tcb.setPomLocation( req, cli ); assertEquals( projectDir, cli.getWorkingDirectory() ); Set args = new HashSet(); args.add( "-f" ); args.add( "non-standard-pom.xml" ); assertArgumentsPresent( cli, args ); } public void testShouldSpecifyFileOptionUsingNonStandardPomInBasedir() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "file-option-nonstd-basedir" ).getCanonicalFile(); projectDir.mkdirs(); File basedir = createDummyFile( projectDir, "non-standard-pom.xml" ).getCanonicalFile(); Commandline cli = new Commandline(); InvocationRequest req = newRequest().setBaseDirectory( basedir ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setEnvironmentPaths( req, cli ); tcb.setPomLocation( req, cli ); assertEquals( projectDir, cli.getWorkingDirectory() ); Set args = new HashSet(); args.add( "-f" ); args.add( "non-standard-pom.xml" ); assertArgumentsPresent( cli, args ); } public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "std-pom-file-location" ).getCanonicalFile(); projectDir.mkdirs(); File pomFile = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); Commandline cli = new Commandline(); InvocationRequest req = newRequest().setPomFile( pomFile ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setEnvironmentPaths( req, cli ); tcb.setPomLocation( req, cli ); assertEquals( projectDir, cli.getWorkingDirectory() ); Set args = new HashSet(); args.add( "-f" ); args.add( "pom.xml" ); assertArgumentsNotPresent( cli, args ); } public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "std-basedir-is-pom-file" ).getCanonicalFile(); projectDir.mkdirs(); File basedir = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); Commandline cli = new Commandline(); InvocationRequest req = newRequest().setBaseDirectory( basedir ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setEnvironmentPaths( req, cli ); tcb.setPomLocation( req, cli ); assertEquals( projectDir, cli.getWorkingDirectory() ); Set args = new HashSet(); args.add( "-f" ); args.add( "pom.xml" ); assertArgumentsNotPresent( cli, args ); } public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "std-basedir-no-pom-filename" ).getCanonicalFile(); projectDir.mkdirs(); Commandline cli = new Commandline(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setEnvironmentPaths( req, cli ); tcb.setPomLocation( req, cli ); assertEquals( projectDir, cli.getWorkingDirectory() ); Set args = new HashSet(); args.add( "-f" ); args.add( "pom.xml" ); assertArgumentsNotPresent( cli, args ); } public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "std-basedir-with-pom-filename" ).getCanonicalFile(); projectDir.mkdirs(); Commandline cli = new Commandline(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ).setPomFileName( "non-standard-pom.xml" ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setEnvironmentPaths( req, cli ); tcb.setPomLocation( req, cli ); assertEquals( projectDir, cli.getWorkingDirectory() ); Set args = new HashSet(); args.add( "-f" ); args.add( "non-standard-pom.xml" ); assertArgumentsPresent( cli, args ); } public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "custom-settings" ).getCanonicalFile(); projectDir.mkdirs(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); Commandline cli = new Commandline(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setSettingsLocation( newRequest().setUserSettingsFile( settingsFile ), cli ); Set args = new HashSet(); args.add( "-s" ); args.add( settingsFile.getCanonicalPath() ); assertArgumentsPresent( cli, args ); } public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "custom-settings" ).getCanonicalFile(); projectDir.mkdirs(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); Commandline cli = new Commandline(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setSettingsLocation( newRequest().setGlobalSettingsFile( settingsFile ), cli ); Set args = new HashSet(); args.add( "-gs" ); args.add( settingsFile.getCanonicalPath() ); assertArgumentsPresent( cli, args ); } public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { logTestStart(); File tmpDir = getTempDir(); File base = new File( tmpDir, "invoker-tests" ); toDelete.add( base ); File projectDir = new File( base, "custom-toolchains" ).getCanonicalFile(); projectDir.mkdirs(); File toolchainsFile = createDummyFile( projectDir, "toolchains.xml" ); Commandline cli = new Commandline(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setToolchainsLocation( newRequest().setToolchainsFile( toolchainsFile ), cli ); Set args = new HashSet(); args.add( "-t" ); args.add( toolchainsFile.getCanonicalPath() ); assertArgumentsPresent( cli, args ); } public void testShouldSpecifyCustomPropertyFromRequest() throws IOException { logTestStart(); Commandline cli = new Commandline(); Properties properties = new Properties(); properties.setProperty( "key", "value" ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setProperties( newRequest().setProperties( properties ), cli ); assertArgumentsPresentInOrder( cli, "-D", "key=value" ); } public void testShouldSpecifyCustomPropertyWithSpacesInValueFromRequest() throws IOException { logTestStart(); Commandline cli = new Commandline(); Properties properties = new Properties(); properties.setProperty( "key", "value with spaces" ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setProperties( newRequest().setProperties( properties ), cli ); assertArgumentsPresentInOrder( cli, "-D", "key=value with spaces" ); } public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() throws IOException { logTestStart(); Commandline cli = new Commandline(); Properties properties = new Properties(); properties.setProperty( "key with spaces", "value with spaces" ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setProperties( newRequest().setProperties( properties ), cli ); assertArgumentsPresentInOrder( cli, "-D", "key with spaces=value with spaces" ); } public void testShouldSpecifySingleGoalFromRequest() throws IOException { logTestStart(); Commandline cli = new Commandline(); List goals = new ArrayList(); goals.add( "test" ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setGoals( newRequest().setGoals( goals ), cli ); assertArgumentsPresent( cli, Collections.singleton( "test" ) ); } public void testShouldSpecifyTwoGoalsFromRequest() throws IOException { logTestStart(); Commandline cli = new Commandline(); List goals = new ArrayList(); goals.add( "test" ); goals.add( "clean" ); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setGoals( newRequest().setGoals( goals ), cli ); assertArgumentsPresent( cli, new HashSet( goals ) ); assertArgumentsPresentInOrder( cli, goals ); } public void testShouldSpecifyThreadsFromRequest() throws IOException { logTestStart(); Commandline cli = new Commandline(); TestCommandLineBuilder tcb = new TestCommandLineBuilder(); tcb.setThreads( newRequest().setThreads( "2.0C" ), cli ); assertArgumentsPresentInOrder( cli, "-T", "2.0C"); } public void testBuildTypicalMavenInvocationEndToEnd() throws Exception { logTestStart(); File mavenDir = setupTempMavenHomeIfMissing(); InvocationRequest request = newRequest(); File tmpDir = getTempDir(); File projectDir = new File( tmpDir, "invoker-tests/typical-end-to-end-cli-build" ); projectDir.mkdirs(); toDelete.add( projectDir.getParentFile() ); request.setBaseDirectory( projectDir ); Set expectedArgs = new HashSet(); Set bannedArgs = new HashSet(); createDummyFile( projectDir, "pom.xml" ); bannedArgs.add( "-f" ); bannedArgs.add( "pom.xml" ); Properties properties = new Properties(); // this is REALLY bad practice, but since it's just a test... properties.setProperty( "maven.tests.skip", "true" ); expectedArgs.add( "maven.tests.skip=true" ); request.setProperties( properties ); request.setOffline( true ); expectedArgs.add( "-o" ); List goals = new ArrayList(); goals.add( "post-clean" ); goals.add( "deploy" ); goals.add( "site-deploy" ); request.setGoals( goals ); MavenCommandLineBuilder commandLineBuilder = new MavenCommandLineBuilder(); Commandline commandline = commandLineBuilder.build( request ); assertArgumentsPresent( commandline, expectedArgs ); assertArgumentsNotPresent( commandline, bannedArgs ); assertArgumentsPresentInOrder( commandline, goals ); File mavenFile; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) { mavenFile = new File( mavenDir, "bin/mvn.bat" ); } else { mavenFile = new File( mavenDir, "bin/mvn" ); } String executable = commandline.getExecutable(); System.out.println( "Executable is: " + executable ); assertTrue( executable.indexOf( mavenFile.getCanonicalPath() ) > -1 ); assertEquals( projectDir.getCanonicalPath(), commandline.getWorkingDirectory().getCanonicalPath() ); } public void testShouldSetEnvVar_MAVEN_TERMINATE_CMD() throws Exception { logTestStart(); setupTempMavenHomeIfMissing(); InvocationRequest request = newRequest(); File tmpDir = getTempDir(); File projectDir = new File( tmpDir, "invoker-tests/maven-terminate-cmd-options-set" ); projectDir.mkdirs(); toDelete.add( projectDir.getParentFile() ); request.setBaseDirectory( projectDir ); createDummyFile( projectDir, "pom.xml" ); List goals = new ArrayList(); goals.add( "clean" ); request.setGoals( goals ); MavenCommandLineBuilder commandLineBuilder = new MavenCommandLineBuilder(); Commandline commandline = commandLineBuilder.build( request ); String[] environmentVariables = commandline.getEnvironmentVariables(); String envVarMavenTerminateCmd = null; for ( int i = 0; i < environmentVariables.length; i++ ) { String envVar = environmentVariables[i]; if ( envVar.startsWith( "MAVEN_TERMINATE_CMD=" ) ) { envVarMavenTerminateCmd = envVar; break; } } assertEquals( "MAVEN_TERMINATE_CMD=on", envVarMavenTerminateCmd ); } public void testShouldInsertActivatedProfiles() throws Exception { setupTempMavenHomeIfMissing(); String profile1 = "profile-1"; String profile2 = "profile-2"; InvocationRequest request = newRequest(); List profiles = new ArrayList(); profiles.add( profile1 ); profiles.add( profile2 ); request.setProfiles( profiles ); MavenCommandLineBuilder commandLineBuilder = new MavenCommandLineBuilder(); Commandline commandline = commandLineBuilder.build( request ); assertArgumentsPresentInOrder( commandline, "-P", profile1 + "," + profile2 ); } public void testMvnCommand() throws Exception { MavenCommandLineBuilder commandLineBuilder = new MavenCommandLineBuilder(); File mavenExecutable = new File ( "mvnDebug" ); commandLineBuilder.setMavenExecutable( mavenExecutable ); File executable = commandLineBuilder.findMavenExecutable(); assertTrue( "Expected executable to exist", executable.exists() ); assertTrue( "Expected executable to be absolute", executable.isAbsolute() ); } public void setUp() { sysProps = System.getProperties(); Properties p = new Properties( sysProps ); System.setProperties( p ); } public void tearDown() throws IOException { System.setProperties( sysProps ); for ( File file : toDelete ) { if ( file.exists() ) { if ( file.isDirectory() ) { FileUtils.deleteDirectory( file ); } else { file.delete(); } } } } // this is just a debugging helper for separating unit test output... private void logTestStart() { NullPointerException npe = new NullPointerException(); StackTraceElement element = npe.getStackTrace()[1]; System.out.println( "Starting: " + element.getMethodName() ); } private void assertArgumentsPresentInOrder( Commandline cli, String... expected ) { assertArgumentsPresentInOrder( cli, Arrays.asList( expected ) ); } private void assertArgumentsPresentInOrder( Commandline cli, List expected ) { String[] arguments = cli.getArguments(); int expectedCounter = 0; for ( int i = 0; i < arguments.length; i++ ) { if ( arguments[i].equals( expected.get( expectedCounter ) ) ) { expectedCounter++; } } assertEquals( "Arguments: " + expected + " were not found or are in the wrong order: " + Arrays.asList( arguments ), expected.size(), expectedCounter ); } private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) { String[] argv = cli.getArguments(); List args = Arrays.asList( argv ); for ( String arg : requiredArgs ) { assertTrue( "Command-line argument: \'" + arg + "\' is missing in " + args, args.contains( arg ) ); } } private void assertArgumentsNotPresent( Commandline cli, Set bannedArgs ) { String[] argv = cli.getArguments(); List args = Arrays.asList( argv ); for ( String arg : bannedArgs ) { assertFalse( "Command-line argument: \'" + arg + "\' should not be present.", args.contains( arg ) ); } } private File createDummyFile( File directory, String filename ) throws IOException { File dummyFile = new File( directory, filename ); FileWriter writer = null; try { writer = new FileWriter( dummyFile ); writer.write( "This is a dummy file." ); } finally { IOUtil.close( writer ); } toDelete.add( dummyFile ); return dummyFile; } private static final class TestCommandLineBuilder extends MavenCommandLineBuilder { public void checkRequiredState() throws IOException { super.checkRequiredState(); } public File findMavenExecutable() throws CommandLineConfigurationException, IOException { return super.findMavenExecutable(); } public void setEnvironmentPaths( InvocationRequest request, Commandline cli ) { super.setEnvironmentPaths( request, cli ); } public void setFlags( InvocationRequest request, Commandline cli ) { super.setFlags( request, cli ); } public void setGoals( InvocationRequest request, Commandline cli ) { super.setGoals( request, cli ); } public void setPomLocation( InvocationRequest request, Commandline cli ) { super.setPomLocation( request, cli ); } public void setProperties( InvocationRequest request, Commandline cli ) { super.setProperties( request, cli ); } public void setReactorBehavior( InvocationRequest request, Commandline cli ) { super.setReactorBehavior( request, cli ); } public void setSettingsLocation( InvocationRequest request, Commandline cli ) { super.setSettingsLocation( request, cli ); } public void setShellEnvironment( InvocationRequest request, Commandline cli ) throws CommandLineConfigurationException { super.setShellEnvironment( request, cli ); } } private File getTempDir() throws Exception { return new File( System.getProperty( "java.io.tmpdir" ) ).getCanonicalFile(); } private InvocationRequest newRequest() { return new DefaultInvocationRequest(); } } maven-invoker-2.1.1/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java0000664000175000017500000000323711020211326031324 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 junit.framework.TestCase; public class SystemOutHandlerTest extends TestCase { public void testConsumeWithoutAlwaysFlush() { logTestStart(); new SystemOutHandler( false ).consumeLine( "This is a test." ); } public void testConsumeWithAlwaysFlush() { logTestStart(); new SystemOutHandler( true ).consumeLine( "This is a test." ); } public void testConsumeNullLine() { logTestStart(); new SystemOutHandler().consumeLine( null ); } // this is just a debugging helper for separating unit test output... private void logTestStart() { NullPointerException npe = new NullPointerException(); StackTraceElement element = npe.getStackTrace()[1]; System.out.println( "Starting: " + element.getMethodName() ); } } maven-invoker-2.1.1/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java0000664000175000017500000001637712042043133031011 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Properties; import junit.framework.TestCase; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineUtils; public class DefaultInvokerTest extends TestCase { public void testBuildShouldSucceed() throws IOException, MavenInvocationException, URISyntaxException { File basedir = getBasedirForBuild(); Invoker invoker = newInvoker(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( basedir ); request.setDebug( true ); List goals = new ArrayList(); goals.add( "clean" ); goals.add( "package" ); request.setGoals( goals ); InvocationResult result = invoker.execute( request ); assertEquals( 0, result.getExitCode() ); } public void testBuildShouldFail() throws IOException, MavenInvocationException, URISyntaxException { File basedir = getBasedirForBuild(); Invoker invoker = newInvoker(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( basedir ); request.setDebug( true ); List goals = new ArrayList(); goals.add( "clean" ); goals.add( "package" ); request.setGoals( goals ); InvocationResult result = invoker.execute( request ); assertEquals( 1, result.getExitCode() ); } public void testSpacePom() throws Exception { logTestStart(); File basedir = getBasedirForBuild(); Invoker invoker = newInvoker(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( basedir ); request.setPomFileName( "pom with spaces.xml" ); request.setDebug( true ); List goals = new ArrayList(); goals.add( "clean" ); request.setGoals( goals ); InvocationResult result = invoker.execute( request ); assertEquals( 0, result.getExitCode() ); } public void testSpaceSettings() throws Exception { logTestStart(); File basedir = getBasedirForBuild(); Invoker invoker = newInvoker(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( basedir ); request.setUserSettingsFile( new File( basedir, "settings with spaces.xml" ) ); request.setDebug( true ); List goals = new ArrayList(); goals.add( "validate" ); request.setGoals( goals ); InvocationResult result = invoker.execute( request ); assertEquals( 0, result.getExitCode() ); } public void testSpaceLocalRepo() throws Exception { logTestStart(); File basedir = getBasedirForBuild(); Invoker invoker = newInvoker(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( basedir ); request.setLocalRepositoryDirectory( new File( basedir, "repo with spaces" ) ); request.setDebug( true ); List goals = new ArrayList(); goals.add( "validate" ); request.setGoals( goals ); InvocationResult result = invoker.execute( request ); assertEquals( 0, result.getExitCode() ); } public void testSpaceProperties() throws Exception { logTestStart(); File basedir = getBasedirForBuild(); Invoker invoker = newInvoker(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory( basedir ); Properties props = new Properties(); props.setProperty( "key", "value with spaces" ); props.setProperty( "key with spaces", "value" ); request.setProperties( props ); request.setDebug( true ); List goals = new ArrayList(); goals.add( "validate" ); request.setGoals( goals ); InvocationResult result = invoker.execute( request ); assertEquals( 0, result.getExitCode() ); } private Invoker newInvoker() throws IOException { Invoker invoker = new DefaultInvoker(); invoker.setMavenHome( findMavenHome() ); InvokerLogger logger = new SystemOutLogger(); logger.setThreshold( InvokerLogger.DEBUG ); invoker.setLogger( logger ); invoker.setLocalRepositoryDirectory( findLocalRepo() ); return invoker; } private File findMavenHome() throws IOException { String mavenHome = System.getProperty( "maven.home" ); if ( mavenHome == null ) { mavenHome = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" ); } if ( mavenHome == null ) { throw new IllegalStateException( "Cannot find Maven application " + "directory. Either specify \'maven.home\' system property, or M2_HOME environment variable." ); } return new File( mavenHome ); } private File findLocalRepo() { String basedir = System.getProperty( "maven.repo.local", "" ); if ( StringUtils.isNotEmpty( basedir ) ) { return new File( basedir ); } return null; } private File getBasedirForBuild() throws URISyntaxException { StackTraceElement element = new NullPointerException().getStackTrace()[1]; String methodName = element.getMethodName(); String dirName = StringUtils.addAndDeHump( methodName ); ClassLoader cloader = Thread.currentThread().getContextClassLoader(); URL dirResource = cloader.getResource( dirName ); if ( dirResource == null ) { throw new IllegalStateException( "Project: " + dirName + " for test method: " + methodName + " is missing." ); } return new File( new URI( dirResource.toString() ).getPath() ); } // this is just a debugging helper for separating unit test output... private void logTestStart() { NullPointerException npe = new NullPointerException(); StackTraceElement element = npe.getStackTrace()[1]; System.out.println( "Starting: " + element.getMethodName() ); } } maven-invoker-2.1.1/src/test/resources/0000775000175000017500000000000012232232274017405 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/0000775000175000017500000000000012232232274024366 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/0000775000175000017500000000000012232232274025155 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/0000775000175000017500000000000012232232274026134 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/0000775000175000017500000000000012232232274027055 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/0000775000175000017500000000000012232232274027644 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/0000775000175000017500000000000012232232274031065 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/0000775000175000017500000000000012232232274032173 5ustar ebourgebourg././@LongLink0000644000000000000000000000015012232232274011635 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/shared/maven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/shar0000775000175000017500000000000012232232274033051 5ustar ebourgebourg././@LongLink0000644000000000000000000000016012232232274011636 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/shared/invoker/maven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/shar0000775000175000017500000000000012232232274033051 5ustar ebourgebourg././@LongLink0000644000000000000000000000017412232232274011643 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/shared/invoker/AppTest.javamaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/test/java/org/apache/maven/shar0000664000175000017500000000122311020006575033046 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); } } maven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/0000775000175000017500000000000012232232274026101 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/0000775000175000017500000000000012232232274027022 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/0000775000175000017500000000000012232232274027611 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/0000775000175000017500000000000012232232274031032 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/0000775000175000017500000000000012232232274032140 5ustar ebourgebourg././@LongLink0000644000000000000000000000015012232232274011635 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/shared/maven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/shar0000775000175000017500000000000012232232274033016 5ustar ebourgebourg././@LongLink0000644000000000000000000000016012232232274011636 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/shared/invoker/maven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/shar0000775000175000017500000000000012232232274033016 5ustar ebourgebourg././@LongLink0000644000000000000000000000017012232232274011637 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/shared/invoker/App.javamaven-invoker-2.1.1/src/test/resources/test-build-should-succeed/src/main/java/org/apache/maven/shar0000664000175000017500000000030211020006575033010 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /** * Hello world! * */ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); } } maven-invoker-2.1.1/src/test/resources/test-build-should-succeed/pom.xml0000664000175000017500000000114011152230410025665 0ustar ebourgebourg 4.0.0 org.apache.maven.shared.invoker test-build-should-succeed jar 1 junit junit 3.8.2 test maven-invoker-2.1.1/src/test/resources/test-build-should-fail/0000775000175000017500000000000012232232274023666 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/0000775000175000017500000000000012232232274024455 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/0000775000175000017500000000000012232232274025434 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/0000775000175000017500000000000012232232274026355 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/0000775000175000017500000000000012232232274027144 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/0000775000175000017500000000000012232232274030365 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/maven/0000775000175000017500000000000012232232274031473 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/maven/shared/0000775000175000017500000000000012232232274032741 5ustar ebourgebourg././@LongLink0000644000000000000000000000015512232232274011642 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/maven/shared/invoker/maven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/maven/shared/0000775000175000017500000000000012232232274032741 5ustar ebourgebourg././@LongLink0000644000000000000000000000017112232232274011640 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/maven/shared/invoker/AppTest.javamaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/test/java/org/apache/maven/shared/0000664000175000017500000000122311020006575032736 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); } } maven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/0000775000175000017500000000000012232232274025401 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/0000775000175000017500000000000012232232274026322 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/0000775000175000017500000000000012232232274027111 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/0000775000175000017500000000000012232232274030332 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/maven/0000775000175000017500000000000012232232274031440 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/maven/shared/0000775000175000017500000000000012232232274032706 5ustar ebourgebourg././@LongLink0000644000000000000000000000015512232232274011642 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/maven/shared/invoker/maven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/maven/shared/0000775000175000017500000000000012232232274032706 5ustar ebourgebourg././@LongLink0000644000000000000000000000016512232232274011643 Lustar rootrootmaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/maven/shared/invoker/App.javamaven-invoker-2.1.1/src/test/resources/test-build-should-fail/src/main/java/org/apache/maven/shared/0000664000175000017500000000030211020006575032700 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /** * Hello world! * */ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); } } maven-invoker-2.1.1/src/test/resources/test-build-should-fail/pom.xml0000664000175000017500000000063211152230410025172 0ustar ebourgebourg 4.0.0 org.apache.maven.shared.invoker test-build-should-fail jar 1 maven-invoker-2.1.1/src/test/resources/test-space-local-repo/0000775000175000017500000000000012232232274023510 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-space-local-repo/repo with spaces/0000775000175000017500000000000012232232274026650 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-space-local-repo/repo with spaces/readme.txt0000664000175000017500000000012411020101151030622 0ustar ebourgebourgDummy file used to ensure the repo directory is copied over to target/test-classes. maven-invoker-2.1.1/src/test/resources/test-space-local-repo/pom.xml0000664000175000017500000000063111152230410025013 0ustar ebourgebourg 4.0.0 org.apache.maven.shared.invoker test-space-local-repo jar 1 maven-invoker-2.1.1/src/test/resources/test-space-pom/0000775000175000017500000000000012232232274022246 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-space-pom/pom with spaces.xml0000664000175000017500000000061711020101151025741 0ustar ebourgebourg 4.0.0 org.apache.maven.shared.invoker test-space-pom jar 1 maven-invoker-2.1.1/src/test/resources/test-space-settings/0000775000175000017500000000000012232232274023313 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-space-settings/settings with spaces.xml0000664000175000017500000000007611020101151030052 0ustar ebourgebourg maven-invoker-2.1.1/src/test/resources/test-space-settings/pom.xml0000664000175000017500000000062711152230410024623 0ustar ebourgebourg 4.0.0 org.apache.maven.shared.invoker test-space-settings jar 1 maven-invoker-2.1.1/src/test/resources/test-space-properties/0000775000175000017500000000000012232232274023647 5ustar ebourgebourgmaven-invoker-2.1.1/src/test/resources/test-space-properties/pom.xml0000664000175000017500000000316211152230410025154 0ustar ebourgebourg 4.0.0 org.apache.maven.shared.invoker test-space-properties jar 1 org.apache.maven.plugins maven-antrun-plugin 1.1 ${prop0} ${prop1} validate run maven-invoker-2.1.1/src/main/0000775000175000017500000000000012232232274015340 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/assembly/0000775000175000017500000000000012232232274017157 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/assembly/source-release.xml0000664000175000017500000000636511255432611022632 0ustar ebourgebourg source-release zip . / true ${project.build.directory}/** **/maven-eclipse.xml **/.project **/.classpath **/*.iws **/*.ipr **/*.iml **/.settings **/.settings/** **/.externalToolBuilders **/.externalToolBuilders/** **/.deployables **/.deployables/** **/.wtpmodules **/.wtpmodules/** **/cobertura.ser **/pom.xml.releaseBackup **/release.properties ${project.build.directory}/maven-shared-archive-resources/META-INF / maven-invoker-2.1.1/src/main/java/0000775000175000017500000000000012232232273016260 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/java/org/0000775000175000017500000000000012232232273017047 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/java/org/apache/0000775000175000017500000000000012232232273020270 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/java/org/apache/maven/0000775000175000017500000000000012232232273021376 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/java/org/apache/maven/shared/0000775000175000017500000000000012232232273022644 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/0000775000175000017500000000000012232232274024322 5ustar ebourgebourgmaven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java0000664000175000017500000002633712032404465032170 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; /** * Specifies the parameters used to control a Maven invocation. * * @version $Id: DefaultInvocationRequest.java 1392618 2012-10-01 21:20:53Z rfscholte $ */ public class DefaultInvocationRequest implements InvocationRequest { private File basedir; private boolean debug; private InvocationOutputHandler errorHandler; private String failureBehavior = REACTOR_FAIL_FAST; private List goals; private InputStream inputStream; private boolean interactive; private File localRepository; private boolean offline; private boolean recursive = true; private InvocationOutputHandler outputHandler; private File pomFile; private Properties properties; private boolean showErrors; private boolean updateSnapshots; private boolean shellEnvironmentInherited = true; private File userSettings; private File globalSettings; private File toolchains; private String globalChecksumPolicy; private String pomFilename; private File javaHome; private List profiles; private boolean nonPluginUpdates; private Map shellEnvironments; private String mavenOpts; private boolean activatedReactor; private String[] activatedReactorIncludes, activatedReactorExcludes; private List projects; private boolean alsoMake; private boolean alsoMakeDependents; private String resumeFrom; private boolean showVersion; private String threads; public InvocationRequest activateReactor( String[] includes, String[] excludes ) { activatedReactor = true; activatedReactorIncludes = includes; activatedReactorExcludes = excludes; return this; } public File getBaseDirectory() { return basedir; } public File getBaseDirectory( File defaultDirectory ) { return basedir == null ? defaultDirectory : basedir; } public InvocationOutputHandler getErrorHandler( InvocationOutputHandler defaultHandler ) { return errorHandler == null ? defaultHandler : errorHandler; } public String getFailureBehavior() { return failureBehavior; } public List getGoals() { return goals; } public InputStream getInputStream( InputStream defaultStream ) { return inputStream == null ? defaultStream : inputStream; } public File getLocalRepositoryDirectory( File defaultDirectory ) { return localRepository == null ? defaultDirectory : localRepository; } public InvocationOutputHandler getOutputHandler( InvocationOutputHandler defaultHandler ) { return outputHandler == null ? defaultHandler : outputHandler; } public File getPomFile() { return pomFile; } public Properties getProperties() { return properties; } public boolean isDebug() { return debug; } public boolean isInteractive() { return interactive; } public boolean isOffline() { return offline; } public boolean isShowErrors() { return showErrors; } public boolean isUpdateSnapshots() { return updateSnapshots; } public boolean isRecursive() { return recursive; } public InvocationRequest setRecursive( boolean recursive ) { this.recursive = recursive; return this; } public InvocationRequest setBaseDirectory( File basedir ) { this.basedir = basedir; return this; } public InvocationRequest setDebug( boolean debug ) { this.debug = debug; return this; } public InvocationRequest setErrorHandler( InvocationOutputHandler errorHandler ) { this.errorHandler = errorHandler; return this; } public InvocationRequest setFailureBehavior( String failureBehavior ) { this.failureBehavior = failureBehavior; return this; } public InvocationRequest setGoals( List goals ) { this.goals = goals; return this; } public InvocationRequest setInputStream( InputStream inputStream ) { this.inputStream = inputStream; return this; } public InvocationRequest setInteractive( boolean interactive ) { this.interactive = interactive; return this; } public InvocationRequest setLocalRepositoryDirectory( File localRepository ) { this.localRepository = localRepository; return this; } public InvocationRequest setOffline( boolean offline ) { this.offline = offline; return this; } public InvocationRequest setOutputHandler( InvocationOutputHandler outputHandler ) { this.outputHandler = outputHandler; return this; } public InvocationRequest setPomFile( File pomFile ) { this.pomFile = pomFile; return this; } public InvocationRequest setProperties( Properties properties ) { this.properties = properties; return this; } public InvocationRequest setShowErrors( boolean showErrors ) { this.showErrors = showErrors; return this; } public InvocationRequest setUpdateSnapshots( boolean updateSnapshots ) { this.updateSnapshots = updateSnapshots; return this; } public boolean isShellEnvironmentInherited() { return shellEnvironmentInherited; } public InvocationRequest setShellEnvironmentInherited( boolean shellEnvironmentInherited ) { this.shellEnvironmentInherited = shellEnvironmentInherited; return this; } public File getJavaHome() { return javaHome; } public InvocationRequest setJavaHome( File javaHome ) { this.javaHome = javaHome; return this; } public File getUserSettingsFile() { return userSettings; } public InvocationRequest setUserSettingsFile( File userSettings ) { this.userSettings = userSettings; return this; } public File getGlobalSettingsFile() { return globalSettings; } public InvocationRequest setGlobalSettingsFile( File globalSettings ) { this.globalSettings = globalSettings; return this; } public File getToolchainsFile() { return toolchains; } public InvocationRequest setToolchainsFile( File toolchains ) { this.toolchains = toolchains; return this; } public String getGlobalChecksumPolicy() { return globalChecksumPolicy; } public InvocationRequest setGlobalChecksumPolicy( String globalChecksumPolicy ) { this.globalChecksumPolicy = globalChecksumPolicy; return this; } public String getPomFileName() { return pomFilename; } public InvocationRequest setPomFileName( String pomFilename ) { this.pomFilename = pomFilename; return this; } public List getProfiles() { return profiles; } public InvocationRequest setProfiles( List profiles ) { this.profiles = profiles; return this; } public boolean isNonPluginUpdates() { return nonPluginUpdates; } public InvocationRequest setNonPluginUpdates( boolean nonPluginUpdates ) { this.nonPluginUpdates = nonPluginUpdates; return this; } public InvocationRequest addShellEnvironment( String name, String value ) { if ( this.shellEnvironmentInherited ) { this.shellEnvironments = new HashMap(); } this.shellEnvironments.put( name, value ); return this; } public Map getShellEnvironments() { return shellEnvironments == null ? Collections.emptyMap(): shellEnvironments; } public String getMavenOpts() { return mavenOpts; } public InvocationRequest setMavenOpts( String mavenOpts ) { this.mavenOpts = mavenOpts; return this; } public boolean isActivatedReactor() { return activatedReactor; } public String[] getActivatedReactorIncludes() { return activatedReactorIncludes; } public String[] getActivatedReactorExcludes() { return activatedReactorExcludes; } /** * @see org.apache.maven.shared.invoker.InvocationRequest#isShowVersion() */ public boolean isShowVersion() { return this.showVersion; } /** * @see org.apache.maven.shared.invoker.InvocationRequest#setShowVersion(boolean) */ public InvocationRequest setShowVersion( boolean showVersion ) { this.showVersion = showVersion; return this; } /** * {@inheritDoc} */ public String getThreads() { return threads; } /** * {@inheritDoc} */ public InvocationRequest setThreads( String threads ) { this.threads = threads; return this; } /** * {@inheritDoc} */ public List getProjects() { return projects; } /** * {@inheritDoc} */ public InvocationRequest setProjects( List projects ) { this.projects = projects; return this; } /** * {@inheritDoc} */ public boolean isAlsoMake() { return alsoMake; } /** * {@inheritDoc} */ public InvocationRequest setAlsoMake( boolean alsoMake ) { this.alsoMake = alsoMake; return this; } /** * {@inheritDoc} */ public boolean isAlsoMakeDependents() { return alsoMakeDependents; } /** * {@inheritDoc} */ public InvocationRequest setAlsoMakeDependents( boolean alsoMakeDependents ) { this.alsoMakeDependents = alsoMakeDependents; return this; } /** * {@inheritDoc} */ public String getResumeFrom() { return resumeFrom; } /** * {@inheritDoc} */ public InvocationRequest setResumeFrom( String resumeFrom ) { this.resumeFrom = resumeFrom; return this; } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/InvocationResult.java0000664000175000017500000000333212042043133030467 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.codehaus.plexus.util.cli.CommandLineException; /** * Describes the result of a Maven invocation. * * @author jdcasey * @version $Id: InvocationResult.java 1401842 2012-10-24 19:49:47Z rfscholte $ */ public interface InvocationResult { /** * Gets the exception that possibly occurred during the execution of the command line. * * @return The exception that prevented to invoke Maven or null if the command line was successfully * processed by the operating system. */ CommandLineException getExecutionException(); /** * Gets the exit code from the Maven invocation. A non-zero value indicates a build failure. Note: * This value is undefined if {@link #getExecutionException()} reports an exception. * * @return The exit code from the Maven invocation. */ int getExitCode(); } ././@LongLink0000644000000000000000000000015112232232274011636 Lustar rootrootmaven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/CommandLineConfigurationException.javamaven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/CommandLineConfigurationException.0000664000175000017500000000345211020276126033122 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Signals an error during the construction of the command line used to invoke Maven. * * @version $Id: CommandLineConfigurationException.java 662043 2008-05-31 16:27:02Z bentmann $ */ public class CommandLineConfigurationException extends Exception { private static final long serialVersionUID = 1L; /** * Creates a new exception using the specified detail message and cause. * * @param message The detail message for this exception, may be null. * @param cause The nested exception, may be null. */ public CommandLineConfigurationException( String message, Throwable cause ) { super( message, cause ); } /** * Creates a new exception using the specified detail message. * * @param message The detail message for this exception, may be null. */ public CommandLineConfigurationException( String message ) { super( message ); } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/Invoker.java0000664000175000017500000001455612034117565026622 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.InputStream; /** * Provides a facade to invoke Maven. * * @version $Id: Invoker.java 1395172 2012-10-06 21:15:33Z rfscholte $ */ public interface Invoker { /** * The role name used to register implementations of this interface within Plexus. */ String ROLE = Invoker.class.getName(); /** * @deprecated Query this property by yourself, this has nothing to do with invoking Maven and as such does not * belong into this API! */ String userHome = System.getProperty( "user.home" ); /** * Executes Maven using the parameters specified by the given invocation request. Parameters not specified by the * invocation request will be derived from the state of this invoker instance. In case both the invoker instance and * the invocation request provide a value for a particular option, the value from the invocation request dominates. * * @param request The invocation request to execute, must not be null. * @return The result of the Maven invocation, never null. * @throws MavenInvocationException */ InvocationResult execute( InvocationRequest request ) throws MavenInvocationException; /** * Gets the path to the base directory of the local repository to use for the Maven invocation. * * @return The path to the base directory of the local repository or null to use the location from * the settings.xml. */ File getLocalRepositoryDirectory(); /** * Gets the working directory for the Maven invocation. * * @return The working directory for the Maven invocation or null if the working directory is derived * from the base directory of the processed POM. */ File getWorkingDirectory(); /** * Gets the logger used by this invoker to output diagnostic messages. * * @return The logger used by this invoker to output diagnostic messages, never null. */ InvokerLogger getLogger(); /** * Gets the path to the base directory of the Maven installation used to invoke Maven. * * @return The path to the base directory of the Maven installation or null if using the default * Maven installation. */ File getMavenHome(); /** * Sets the path to the base directory of the Maven installation used to invoke Maven. This parameter may be left * unspecified to use the default Maven installation which will be discovered by evaluating the system property * maven.home and the environment variable M2_HOME. * * @param mavenHome The path to the base directory of the Maven installation, may be null to use the * default Maven installation. * @return This invoker instance. */ Invoker setMavenHome( File mavenHome ); /** * Get the customized File of the Maven executable. * * @return the custom Maven executable, otherwise {@code null} */ File getMavenExecutable(); /** * {@code mavenExecutable} can either be a file relative to ${maven.home}/bin/ or an absolute file. * * @param mavenExecutable the executable * @return This invoker instance */ Invoker setMavenExecutable( File mavenExecutable ); /** * Sets the path to the base directory of the local repository to use for the Maven invocation. * * @param localRepositoryDirectory The path to the base directory of the local repository or null to * use the location from the settings.xml. * @return This invoker instance. */ Invoker setLocalRepositoryDirectory( File localRepositoryDirectory ); /** * Sets the logger used by this invoker to output diagnostic messages. * * @param logger The logger used by this invoker to output diagnostic messages, may be null to use a * default logger. * @return This invoker instance. */ Invoker setLogger( InvokerLogger logger ); /** * Sets the working directory for the Maven invocation. * * @param workingDirectory The working directory for the Maven invocation, may be null to derive the * working directory from the base directory of the processed POM. * @return This invoker instance. */ Invoker setWorkingDirectory( File workingDirectory ); /** * Sets the input stream used to provide input for the invoked Maven build. This is in particular useful when * invoking Maven in interactive mode. * * @param inputStream The input stream used to provide input for the invoked Maven build, may be null * if not required. * @return This invoker instance. */ Invoker setInputStream( InputStream inputStream ); /** * Sets the handler used to capture the standard output from the Maven build. * * @param outputHandler The output handler, may be null if the output is not of interest. * @return This invoker instance. */ Invoker setOutputHandler( InvocationOutputHandler outputHandler ); /** * Sets the handler used to capture the error output from the Maven build. * * @param errorHandler The error handler, may be null if the output is not of interest. * @return This invoker instance. */ Invoker setErrorHandler( InvocationOutputHandler errorHandler ); } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/InvocationOutputHandler.java0000664000175000017500000000221112042043133032002 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.codehaus.plexus.util.cli.StreamConsumer; /** * Receives the standard/error output from a Maven invocation. * * @version $Id: InvocationOutputHandler.java 1401842 2012-10-24 19:49:47Z rfscholte $ */ public interface InvocationOutputHandler extends StreamConsumer { // empty by design } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationResult.java0000664000175000017500000000445612042043133032004 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.codehaus.plexus.util.cli.CommandLineException; /** * Describes the result of a Maven invocation. * * @version $Id: DefaultInvocationResult.java 1401842 2012-10-24 19:49:47Z rfscholte $ */ public final class DefaultInvocationResult implements InvocationResult { /** * The exception that prevented to execute the command line, will be null if Maven could be * successfully started. */ private CommandLineException executionException; /** * The exit code reported by the Maven invocation. */ private int exitCode = Integer.MIN_VALUE; /** * Creates a new invocation result */ DefaultInvocationResult() { // hide constructor } public int getExitCode() { return exitCode; } public CommandLineException getExecutionException() { return executionException; } /** * Sets the exit code reported by the Maven invocation. * * @param exitCode The exit code reported by the Maven invocation. */ void setExitCode( int exitCode ) { this.exitCode = exitCode; } /** * Sets the exception that prevented to execute the command line. * * @param executionException The exception that prevented to execute the command line, may be null. */ void setExecutionException( CommandLineException executionException ) { this.executionException = executionException; } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/SystemOutHandler.java0000664000175000017500000000265111020226576030445 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Offers an output handler that writes to {@link System#out}. * * @version $Id: SystemOutHandler.java 661996 2008-05-31 10:50:38Z bentmann $ */ public class SystemOutHandler extends PrintStreamHandler { /** * Creates a new output handler. */ public SystemOutHandler() { this( false ); } /** * Creates a new output handler. * * @param alwaysFlush A flag whether the print stream should be flushed after each line. */ public SystemOutHandler( boolean alwaysFlush ) { super( System.out, alwaysFlush ); } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/PrintStreamHandler.java0000664000175000017500000000446311045044160030736 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.PrintStream; /** * Offers an output handler that writes to a print stream like {@link System#out}. * * @version $Id: PrintStreamHandler.java 681956 2008-08-02 11:43:44Z dennisl $ * @since 2.0.9 */ public class PrintStreamHandler implements InvocationOutputHandler { /** * The print stream to write to, never null. */ private PrintStream out; /** * A flag whether the print stream should be flushed after each line. */ private boolean alwaysFlush; /** * Creates a new output handler that writes to {@link System#out}. */ public PrintStreamHandler() { this( System.out, false ); } /** * Creates a new output handler that writes to the specified print stream. * * @param out The print stream to write to, must not be null. * @param alwaysFlush A flag whether the print stream should be flushed after each line. */ public PrintStreamHandler( PrintStream out, boolean alwaysFlush ) { if ( out == null ) { throw new NullPointerException( "missing output stream" ); } this.out = out; this.alwaysFlush = alwaysFlush; } public void consumeLine( String line ) { if ( line == null ) { out.println(); } else { out.println( line ); } if ( alwaysFlush ) { out.flush(); } } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/SystemOutLogger.java0000664000175000017500000000227611020226576030312 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Offers a logger that writes to {@link System#out}. * * @version $Id: SystemOutLogger.java 661996 2008-05-31 10:50:38Z bentmann $ */ public class SystemOutLogger extends PrintStreamLogger { /** * Creates a new logger with a threshold of {@link #INFO}. */ public SystemOutLogger() { super( System.out, INFO ); } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/MavenInvocationException.java0000664000175000017500000000373411020276126032151 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * Signals an error during the construction of the command line used to invoke Maven, e.g. illegal invocation arguments. * This should not be confused with a failure of the invoked Maven build itself which will be reported by means of a * non-zero exit code. * * @see InvocationResult#getExitCode() * @version $Id: MavenInvocationException.java 662043 2008-05-31 16:27:02Z bentmann $ */ public class MavenInvocationException extends Exception { private static final long serialVersionUID = 1L; /** * Creates a new exception using the specified detail message and cause. * * @param message The detail message for this exception, may be null. * @param cause The nested exception, may be null. */ public MavenInvocationException( String message, Throwable cause ) { super( message, cause ); } /** * Creates a new exception using the specified detail message. * * @param message The detail message for this exception, may be null. */ public MavenInvocationException( String message ) { super( message ); } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java0000664000175000017500000001520112042301555030104 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.InputStream; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; /** * Class intended to be used by clients who wish to invoke a forked Maven process from their applications * * @author jdcasey */ @Component( role = Invoker.class, hint = "default" ) public class DefaultInvoker implements Invoker { public static final String ROLE_HINT = "default"; private static final InvokerLogger DEFAULT_LOGGER = new SystemOutLogger(); private static final InvocationOutputHandler DEFAULT_OUTPUT_HANDLER = new SystemOutHandler(); private File localRepositoryDirectory; private InvokerLogger logger = DEFAULT_LOGGER; private File workingDirectory; private File mavenHome; private File mavenExecutable; private InvocationOutputHandler outputHandler = DEFAULT_OUTPUT_HANDLER; private InputStream inputStream; private InvocationOutputHandler errorHandler = DEFAULT_OUTPUT_HANDLER; public InvocationResult execute( InvocationRequest request ) throws MavenInvocationException { MavenCommandLineBuilder cliBuilder = new MavenCommandLineBuilder(); InvokerLogger logger = getLogger(); if ( logger != null ) { cliBuilder.setLogger( getLogger() ); } File localRepo = getLocalRepositoryDirectory(); if ( localRepo != null ) { cliBuilder.setLocalRepositoryDirectory( getLocalRepositoryDirectory() ); } File mavenHome = getMavenHome(); if ( mavenHome != null ) { cliBuilder.setMavenHome( getMavenHome() ); } File mavenExecutable = getMavenExecutable(); if ( mavenExecutable != null ) { cliBuilder.setMavenExecutable( mavenExecutable ); } File workingDirectory = getWorkingDirectory(); if ( workingDirectory != null ) { cliBuilder.setWorkingDirectory( getWorkingDirectory() ); } Commandline cli; try { cli = cliBuilder.build( request ); } catch ( CommandLineConfigurationException e ) { throw new MavenInvocationException( "Error configuring command-line. Reason: " + e.getMessage(), e ); } DefaultInvocationResult result = new DefaultInvocationResult(); try { int exitCode = executeCommandLine( cli, request ); result.setExitCode( exitCode ); } catch ( CommandLineException e ) { result.setExecutionException( e ); } return result; } private int executeCommandLine( Commandline cli, InvocationRequest request ) throws CommandLineException { int result = Integer.MIN_VALUE; InputStream inputStream = request.getInputStream( this.inputStream ); InvocationOutputHandler outputHandler = request.getOutputHandler( this.outputHandler ); InvocationOutputHandler errorHandler = request.getErrorHandler( this.errorHandler ); if ( getLogger().isDebugEnabled() ) { getLogger().debug( "Executing: " + cli ); } if ( request.isInteractive() ) { if ( inputStream == null ) { getLogger().warn( "Maven will be executed in interactive mode" + ", but no input stream has been configured for this MavenInvoker instance." ); result = CommandLineUtils.executeCommandLine( cli, outputHandler, errorHandler ); } else { result = CommandLineUtils.executeCommandLine( cli, inputStream, outputHandler, errorHandler ); } } else { if ( inputStream != null ) { getLogger().info( "Executing in batch mode. The configured input stream will be ignored." ); } result = CommandLineUtils.executeCommandLine( cli, outputHandler, errorHandler ); } return result; } public File getLocalRepositoryDirectory() { return localRepositoryDirectory; } public InvokerLogger getLogger() { return logger; } public Invoker setLocalRepositoryDirectory( File localRepositoryDirectory ) { this.localRepositoryDirectory = localRepositoryDirectory; return this; } public Invoker setLogger( InvokerLogger logger ) { this.logger = ( logger != null ) ? logger : DEFAULT_LOGGER; return this; } public File getWorkingDirectory() { return workingDirectory; } public Invoker setWorkingDirectory( File workingDirectory ) { this.workingDirectory = workingDirectory; return this; } public File getMavenHome() { return mavenHome; } public Invoker setMavenHome( File mavenHome ) { this.mavenHome = mavenHome; return this; } public File getMavenExecutable() { return mavenExecutable; } public Invoker setMavenExecutable( File mavenExecutable ) { this.mavenExecutable = mavenExecutable; return this; } public Invoker setErrorHandler( InvocationOutputHandler errorHandler ) { this.errorHandler = errorHandler; return this; } public Invoker setInputStream( InputStream inputStream ) { this.inputStream = inputStream; return this; } public Invoker setOutputHandler( InvocationOutputHandler outputHandler ) { this.outputHandler = outputHandler; return this; } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java0000664000175000017500000005062012042043133031645 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; /** * @version $Id: MavenCommandLineBuilder.java 1401842 2012-10-24 19:49:47Z rfscholte $ */ public class MavenCommandLineBuilder { private static final InvokerLogger DEFAULT_LOGGER = new SystemOutLogger(); private InvokerLogger logger = DEFAULT_LOGGER; private File workingDirectory; private File localRepositoryDirectory; private File mavenHome; private File mavenExecutable; private Properties systemEnvVars; public Commandline build( InvocationRequest request ) throws CommandLineConfigurationException { try { checkRequiredState(); } catch ( IOException e ) { throw new CommandLineConfigurationException( e.getMessage(), e ); } File mvn = null; try { mvn = findMavenExecutable(); } catch ( IOException e ) { throw new CommandLineConfigurationException( e.getMessage(), e ); } Commandline cli = new Commandline(); cli.setExecutable( mvn.getAbsolutePath() ); // handling for OS-level envars setShellEnvironment( request, cli ); // interactive, offline, update-snapshots, // debug/show-errors, checksum policy setFlags( request, cli ); // failure behavior and [eventually] forced-reactor // includes/excludes, etc. setReactorBehavior( request, cli ); // working directory and local repository location setEnvironmentPaths( request, cli ); // pom-file and basedir handling setPomLocation( request, cli ); setSettingsLocation( request, cli ); setToolchainsLocation( request, cli ); setProperties( request, cli ); setProfiles( request, cli ); setGoals( request, cli ); setThreads( request, cli ); return cli; } protected void checkRequiredState() throws IOException { if ( logger == null ) { throw new IllegalStateException( "A logger instance is required." ); } if ( ( mavenHome == null ) && ( System.getProperty( "maven.home" ) == null ) ) // can be restored with 1.5 // && ( System.getenv( "M2_HOME" ) != null ) ) { if ( !getSystemEnvVars().containsKey( "M2_HOME" ) ) { throw new IllegalStateException( "Maven application directory was not " + "specified, and ${maven.home} is not provided in the system " + "properties. Please specify at least on of these." ); } } } protected void setSettingsLocation( InvocationRequest request, Commandline cli ) { File userSettingsFile = request.getUserSettingsFile(); if ( userSettingsFile != null ) { try { File canSet = userSettingsFile.getCanonicalFile(); userSettingsFile = canSet; } catch ( IOException e ) { logger.debug( "Failed to canonicalize user settings path: " + userSettingsFile.getAbsolutePath() + ". Using as-is.", e ); } cli.createArg().setValue( "-s" ); cli.createArg().setValue( userSettingsFile.getPath() ); } File globalSettingsFile = request.getGlobalSettingsFile(); if ( globalSettingsFile != null ) { try { File canSet = globalSettingsFile.getCanonicalFile(); globalSettingsFile = canSet; } catch ( IOException e ) { logger.debug( "Failed to canonicalize global settings path: " + globalSettingsFile.getAbsolutePath() + ". Using as-is.", e ); } cli.createArg().setValue( "-gs" ); cli.createArg().setValue( globalSettingsFile.getPath() ); } } protected void setToolchainsLocation( InvocationRequest request, Commandline cli ) { File toolchainsFile = request.getToolchainsFile(); if ( toolchainsFile != null ) { try { File canSet = toolchainsFile.getCanonicalFile(); toolchainsFile = canSet; } catch ( IOException e ) { logger.debug( "Failed to canonicalize toolchains path: " + toolchainsFile.getAbsolutePath() + ". Using as-is.", e ); } cli.createArg().setValue( "-t" ); cli.createArg().setValue( toolchainsFile.getPath() ); } } protected void setShellEnvironment( InvocationRequest request, Commandline cli ) throws CommandLineConfigurationException { if ( request.isShellEnvironmentInherited() ) { try { cli.addSystemEnvironment(); cli.addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); } catch ( IOException e ) { throw new CommandLineConfigurationException( "Error reading shell environment variables. Reason: " + e.getMessage(), e ); } catch ( Exception e ) { if ( e instanceof RuntimeException ) { throw (RuntimeException) e; } else { IllegalStateException error = new IllegalStateException( "Unknown error retrieving shell environment variables. Reason: " + e.getMessage() ); error.initCause( e ); throw error; } } } if ( request.getJavaHome() != null ) { cli.addEnvironment( "JAVA_HOME", request.getJavaHome().getAbsolutePath() ); } if ( request.getMavenOpts() != null ) { cli.addEnvironment( "MAVEN_OPTS", request.getMavenOpts() ); } for ( Map.Entry entry : request.getShellEnvironments().entrySet() ) { cli.addEnvironment( entry.getKey(), entry.getValue() ); } } protected void setProfiles( InvocationRequest request, Commandline cli ) { List profiles = request.getProfiles(); if ( ( profiles != null ) && !profiles.isEmpty() ) { cli.createArg().setValue( "-P" ); cli.createArg().setValue( StringUtils.join( profiles.iterator(), "," ) ); } } protected void setGoals( InvocationRequest request, Commandline cli ) { List goals = request.getGoals(); if ( ( goals != null ) && !goals.isEmpty() ) { cli.createArg().setLine( StringUtils.join( goals.iterator(), " " ) ); } } protected void setProperties( InvocationRequest request, Commandline cli ) { Properties properties = request.getProperties(); if ( properties != null ) { for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); cli.createArg().setValue( "-D" ); cli.createArg().setValue( key + '=' + value ); } } } protected void setPomLocation( InvocationRequest request, Commandline cli ) { boolean pomSpecified = false; File pom = request.getPomFile(); String pomFilename = request.getPomFileName(); File baseDirectory = request.getBaseDirectory(); if ( pom != null ) { pomSpecified = true; } else if ( baseDirectory != null ) { if ( baseDirectory.isDirectory() ) { if ( pomFilename != null ) { pom = new File( baseDirectory, pomFilename ); pomSpecified = true; } else { pom = new File( baseDirectory, "pom.xml" ); } } else { logger.warn( "Base directory is a file. Using base directory as POM location." ); pom = baseDirectory; pomSpecified = true; } } if ( pomSpecified ) { try { File canPom = pom.getCanonicalFile(); pom = canPom; } catch ( IOException e ) { logger.debug( "Failed to canonicalize the POM path: " + pom + ". Using as-is.", e ); } if ( !"pom.xml".equals( pom.getName() ) ) { logger.debug( "Specified POM file is not named \'pom.xml\'. " + "Using the \'-f\' command-line option to accommodate non-standard filename..." ); cli.createArg().setValue( "-f" ); cli.createArg().setValue( pom.getName() ); } } } protected void setEnvironmentPaths( InvocationRequest request, Commandline cli ) { File workingDirectory = request.getBaseDirectory(); if ( workingDirectory == null ) { File pomFile = request.getPomFile(); if ( pomFile != null ) { workingDirectory = pomFile.getParentFile(); } } if ( workingDirectory == null ) { workingDirectory = this.workingDirectory; } if ( workingDirectory == null ) { workingDirectory = new File( System.getProperty( "user.dir" ) ); } else if ( workingDirectory.isFile() ) { logger.warn( "Specified base directory (" + workingDirectory + ") is a file." + " Using its parent directory..." ); workingDirectory = workingDirectory.getParentFile(); } try { cli.setWorkingDirectory( workingDirectory.getCanonicalPath() ); } catch ( IOException e ) { logger.debug( "Failed to canonicalize base directory: " + workingDirectory + ". Using as-is.", e ); cli.setWorkingDirectory( workingDirectory.getAbsolutePath() ); } File localRepositoryDirectory = request.getLocalRepositoryDirectory( this.localRepositoryDirectory ); if ( localRepositoryDirectory != null ) { try { File canLRD = localRepositoryDirectory.getCanonicalFile(); localRepositoryDirectory = canLRD; } catch ( IOException e ) { logger.debug( "Failed to canonicalize local repository directory: " + localRepositoryDirectory + ". Using as-is.", e ); } if ( !localRepositoryDirectory.isDirectory() ) { throw new IllegalArgumentException( "Local repository location: \'" + localRepositoryDirectory + "\' is NOT a directory." ); } cli.createArg().setValue( "-D" ); cli.createArg().setValue( "maven.repo.local=" + localRepositoryDirectory.getPath() ); } } protected void setReactorBehavior( InvocationRequest request, Commandline cli ) { // NOTE: The default is "fail-fast" String failureBehavior = request.getFailureBehavior(); if ( StringUtils.isNotEmpty( failureBehavior ) ) { if ( InvocationRequest.REACTOR_FAIL_AT_END.equals( failureBehavior ) ) { cli.createArg().setValue( "-fae" ); } else if ( InvocationRequest.REACTOR_FAIL_NEVER.equals( failureBehavior ) ) { cli.createArg().setValue( "-fn" ); } } if ( request.isActivatedReactor() ) { cli.createArg().setValue( "-r" ); String[] includes = request.getActivatedReactorIncludes(); String[] excludes = request.getActivatedReactorExcludes(); if ( includes != null ) { cli.createArg().setValue( "-D" ); cli.createArg().setValue( "maven.reactor.includes=" + StringUtils.join( includes, "," ) ); } if ( excludes != null ) { cli.createArg().setValue( "-D" ); cli.createArg().setValue( "maven.reactor.excludes=" + StringUtils.join( excludes, "," ) ); } } if( StringUtils.isNotEmpty( request.getResumeFrom() ) ) { cli.createArg().setValue( "-rf" ); cli.createArg().setValue( request.getResumeFrom() ); } List projectList = request.getProjects(); if ( projectList != null ) { cli.createArg().setValue( "-pl" ); cli.createArg().setValue( StringUtils.join( projectList.iterator(), "," ) ); if ( request.isAlsoMake() ) { cli.createArg().setValue( "-am" ); } if ( request.isAlsoMakeDependents() ) { cli.createArg().setValue( "-amd" ); } } } protected void setFlags( InvocationRequest request, Commandline cli ) { if ( !request.isInteractive() ) { cli.createArg().setValue( "-B" ); } if ( request.isOffline() ) { cli.createArg().setValue( "-o" ); } if ( request.isUpdateSnapshots() ) { cli.createArg().setValue( "-U" ); } if ( !request.isRecursive() ) { cli.createArg().setValue( "-N" ); } if ( request.isDebug() ) { cli.createArg().setValue( "-X" ); } // this is superceded by -X, if it exists. else if ( request.isShowErrors() ) { cli.createArg().setValue( "-e" ); } String checksumPolicy = request.getGlobalChecksumPolicy(); if ( InvocationRequest.CHECKSUM_POLICY_FAIL.equals( checksumPolicy ) ) { cli.createArg().setValue( "-C" ); } else if ( InvocationRequest.CHECKSUM_POLICY_WARN.equals( checksumPolicy ) ) { cli.createArg().setValue( "-c" ); } if ( request.isNonPluginUpdates() ) { cli.createArg().setValue( "-npu" ); } if ( request.isShowVersion() ) { cli.createArg().setValue( "-V" ); } } protected void setThreads( InvocationRequest request, Commandline cli ) { String threads = request.getThreads(); if ( StringUtils.isNotEmpty( threads ) ) { cli.createArg().setValue( "-T" ); cli.createArg().setValue( threads ); } } protected File findMavenExecutable() throws CommandLineConfigurationException, IOException { if ( mavenHome == null ) { String mavenHomeProperty = System.getProperty( "maven.home" ); if ( mavenHomeProperty != null ) { mavenHome = new File( mavenHomeProperty ); if ( !mavenHome.isDirectory() ) { File binDir = mavenHome.getParentFile(); if ( "bin".equals( binDir.getName() ) ) { // ah, they specified the mvn // executable instead... mavenHome = binDir.getParentFile(); } else { throw new IllegalStateException( "${maven.home} is not specified as a directory: \'" + mavenHomeProperty + "\'." ); } } } if ( ( mavenHome == null ) && ( getSystemEnvVars().getProperty( "M2_HOME" ) != null ) ) { mavenHome = new File( getSystemEnvVars().getProperty( "M2_HOME" ) ); } } logger.debug( "Using ${maven.home} of: \'" + mavenHome + "\'." ); if ( mavenExecutable == null || !mavenExecutable.isAbsolute() ) { String executable; if( mavenExecutable != null ) { executable = mavenExecutable.getPath(); } else if ( Os.isFamily( "windows" ) ) { executable = "mvn.bat"; } else { executable = "mvn"; } mavenExecutable = new File( mavenHome, "/bin/" + executable ); try { File canonicalMvn = mavenExecutable.getCanonicalFile(); mavenExecutable = canonicalMvn; } catch ( IOException e ) { logger.debug( "Failed to canonicalize maven executable: " + mavenExecutable + ". Using as-is.", e ); } if ( !mavenExecutable.isFile() ) { throw new CommandLineConfigurationException( "Maven executable not found at: " + mavenExecutable ); } } return mavenExecutable; } /** * Wraps a path with quotes to handle paths with spaces. If no spaces are found, the original string is returned. * * @param path string to wrap if containing spaces * @return quote wrapped string * @deprecated Quoting of command line arguments should be left to the Commandline from plexus-utils. */ public String wrapStringWithQuotes( String path ) { if ( path.indexOf( " " ) > -1 ) { return "\"" + path + "\""; } else { return path; } } private Properties getSystemEnvVars() throws IOException { if ( this.systemEnvVars == null ) { // with 1.5 replace with System.getenv() this.systemEnvVars = CommandLineUtils.getSystemEnvVars(); } return this.systemEnvVars; } public File getLocalRepositoryDirectory() { return localRepositoryDirectory; } public void setLocalRepositoryDirectory( File localRepositoryDirectory ) { this.localRepositoryDirectory = localRepositoryDirectory; } public InvokerLogger getLogger() { return logger; } public void setLogger( InvokerLogger logger ) { this.logger = logger; } public File getMavenHome() { return mavenHome; } public void setMavenHome( File mavenHome ) { this.mavenHome = mavenHome; } public File getWorkingDirectory() { return workingDirectory; } public void setWorkingDirectory( File workingDirectory ) { this.workingDirectory = workingDirectory; } /** * {@code mavenExecutable} can either be relative to ${maven.home}/bin/ or absolute * * @param mavenExecutable the executable */ public void setMavenExecutable( File mavenExecutable ) { this.mavenExecutable = mavenExecutable; } public File getMavenExecutable() { return mavenExecutable; } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/PrintStreamLogger.java0000664000175000017500000001273311020226576030605 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; /** * Offers a logger that writes to a print stream like {@link System#out}. * * @version $Id: PrintStreamLogger.java 661996 2008-05-31 10:50:38Z bentmann $ * @since 2.0.9 */ public class PrintStreamLogger implements InvokerLogger { /** * The print stream to write to, never null. */ private PrintStream out; /** * The threshold used to filter messages. */ private int threshold; /** * Creates a new logger that writes to {@link System#out} and has a threshold of {@link #INFO}. */ public PrintStreamLogger() { this( System.out, INFO ); } /** * Creates a new logger that writes to the specified print stream. * * @param out The print stream to write to, must not be null. * @param threshold The threshold for the logger. */ public PrintStreamLogger( PrintStream out, int threshold ) { if ( out == null ) { throw new NullPointerException( "missing output stream" ); } this.out = out; setThreshold( threshold ); } /** * Writes the specified message and exception to the print stream. * * @param level The priority level of the message. * @param message The message to log, may be null. * @param error The exception to log, may be null. */ private void log( int level, String message, Throwable error ) { if ( level > threshold ) { // don't log when it doesn't match your threshold. return; } if ( message == null && error == null ) { // don't log when there's nothing to log. return; } StringBuffer buffer = new StringBuffer(); switch ( level ) { case ( DEBUG ): { buffer.append( "[DEBUG]" ); break; } case ( INFO ): { buffer.append( "[INFO]" ); break; } case ( WARN ): { buffer.append( "[WARN]" ); break; } case ( ERROR ): { buffer.append( "[ERROR]" ); break; } case ( FATAL ): { buffer.append( "[FATAL]" ); break; } } buffer.append( ' ' ); if ( message != null ) { buffer.append( message ); } if ( error != null ) { StringWriter writer = new StringWriter(); PrintWriter pWriter = new PrintWriter( writer ); error.printStackTrace( pWriter ); if ( message != null ) { buffer.append( '\n' ); } buffer.append( "Error:\n" ); buffer.append( writer.toString() ); } out.println( buffer.toString() ); } public void debug( String message ) { log( DEBUG, message, null ); } public void debug( String message, Throwable throwable ) { log( DEBUG, message, throwable ); } public void info( String message ) { log( INFO, message, null ); } public void info( String message, Throwable throwable ) { log( INFO, message, throwable ); } public void warn( String message ) { log( WARN, message, null ); } public void warn( String message, Throwable throwable ) { log( WARN, message, throwable ); } public void error( String message ) { log( ERROR, message, null ); } public void error( String message, Throwable throwable ) { log( ERROR, message, throwable ); } public void fatalError( String message ) { log( FATAL, message, null ); } public void fatalError( String message, Throwable throwable ) { log( FATAL, message, throwable ); } public boolean isDebugEnabled() { return threshold >= DEBUG; } public boolean isErrorEnabled() { return threshold >= ERROR; } public boolean isFatalErrorEnabled() { return threshold >= FATAL; } public boolean isInfoEnabled() { return threshold >= INFO; } public boolean isWarnEnabled() { return threshold >= WARN; } public int getThreshold() { return threshold; } public void setThreshold( int threshold ) { this.threshold = threshold; } } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/InvokerLogger.java0000664000175000017500000001304211020276126027740 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * A logger used by {@link Invoker} instances to output diagnostic messages. * * @see Invoker#setLogger(InvokerLogger) * @author Jason van Zyl * @version $Id: InvokerLogger.java 662043 2008-05-31 16:27:02Z bentmann $ */ public interface InvokerLogger { /** * The threshold for debug output. */ public static final int DEBUG = 4; /** * The threshold for info output. */ public static final int INFO = 3; /** * The threshold for warn output. */ public static final int WARN = 2; /** * The threshold for error output. */ public static final int ERROR = 1; /** * The threshold for fatal error output. */ public static final int FATAL = 0; /** * Logs the specified debug message. * * @param message The message to log, may be null. */ void debug( String message ); /** * Logs the specified debug message and the accompanying exception. * * @param message The message to log, may be null. * @param throwable The exception to log, may be null. */ void debug( String message, Throwable throwable ); /** * Tests whether debug output is enabled for this logger. * * @return true if messages with priority "debug" or above are logged, false * otherwise. */ boolean isDebugEnabled(); /** * Logs the specified info message. * * @param message The message to log, may be null. */ void info( String message ); /** * Logs the specified info message and the accompanying exception. * * @param message The message to log, may be null. * @param throwable The exception to log, may be null. */ void info( String message, Throwable throwable ); /** * Tests whether info output is enabled for this logger. * * @return true if messages with priority "info" or above are logged, false otherwise. */ boolean isInfoEnabled(); /** * Logs the specified warning message. * * @param message The message to log, may be null. */ void warn( String message ); /** * Logs the specified warning message and the accompanying exception. * * @param message The message to log, may be null. * @param throwable The exception to log, may be null. */ void warn( String message, Throwable throwable ); /** * Tests whether warn output is enabled for this logger. * * @return true if messages with priority "warn" or above are logged, false otherwise. */ boolean isWarnEnabled(); /** * Logs the specified error message. * * @param message The message to log, may be null. */ void error( String message ); /** * Logs the specified error message and the accompanying exception. * * @param message The message to log, may be null. * @param throwable The exception to log, may be null. */ void error( String message, Throwable throwable ); /** * Tests whether error output is enabled for this logger. * * @return true if messages with priority "error" or above are logged, false * otherwise. */ boolean isErrorEnabled(); /** * Logs the specified fatal error message. * * @param message The message to log, may be null. */ void fatalError( String message ); /** * Logs the specified fatal error message and the accompanying exception. * * @param message The message to log, may be null. * @param throwable The exception to log, may be null. */ void fatalError( String message, Throwable throwable ); /** * Tests whether fatal error output is enabled for this logger. * * @return true if messages with priority "fatal" or above are logged, false * otherwise. */ boolean isFatalErrorEnabled(); /** * Sets the logger's threshold. * * @param threshold The logger's threshold, must be one of {@link #DEBUG}, {@link #INFO}, {@link #WARN}, * {@link #ERROR} and {@link #FATAL}. */ void setThreshold( int threshold ); /** * Gets the logger's threshold. * * @return The logger's threshold, one of {@link #DEBUG}, {@link #INFO}, {@link #WARN}, {@link #ERROR} and * {@link #FATAL}. */ int getThreshold(); } maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java0000664000175000017500000006206412034352202030651 0ustar ebourgebourgpackage org.apache.maven.shared.invoker; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.io.InputStream; import java.util.List; import java.util.Map; import java.util.Properties; /** * Specifies the parameters used to control a Maven invocation. * * @version $Id: InvocationRequest.java 1395369 2012-10-07 19:14:10Z rfscholte $ */ public interface InvocationRequest { // TODO: handle forced-reactor executions using -r/includes/excludes /** * Gets the interaction mode of the Maven invocation. By default, Maven is executed in batch mode. * * @return true if Maven should be executed in interactive mode, false if the batch * mode is used. */ boolean isInteractive(); /** * Gets the network mode of the Maven invocation. By default, Maven is executed in online mode. * * @return true if Maven should be executed in offline mode, false if the online mode * is used. */ boolean isOffline(); /** * Indicates whether Maven should enforce an update check for plugins and snapshots. By default, no update check is * performed. * * @return true if plugins and snapshots should be updated, false otherwise. */ boolean isUpdateSnapshots(); /** * Gets the recursion behavior of a reactor invocation. By default, Maven will recursive the build into sub modules. * * @return true if sub modules should be build, false otherwise. */ boolean isRecursive(); /** * Gets whether Maven should search subdirectories to build a dynamic reactor * @return true if we should search subdirectories, false otherwise */ public boolean isActivatedReactor(); /** * Gets the list of subdirectory patterns to search * @return list of subdirectory patterns to search, or null in which case defaults should be used */ public String[] getActivatedReactorIncludes(); /** * Gets the list of subdirectory patterns to exclude from search * @return list of subdirectory patterns to exclude search, or null in which case nothing should be excluded */ public String[] getActivatedReactorExcludes(); /** * A list of specified reactor projects to build instead of all projects. * A project can be specified by [groupId]:artifactId or by its relative path. * * @return the list of projects to add to reactor build, otherwise {@code null} * @since 2.1 */ public List getProjects(); /** * Get the value of the {@code also-make} argument. * * @return {@code true} if the argument {@code also-make} was specified, otherwise {@code false} * @since 2.1 */ boolean isAlsoMake(); /** * Get the value of the {@code also-make-dependents} * * @return {@code true} if the argument {@code also-make-dependents} was specified, otherwise {@code false} * @since 2.1 */ boolean isAlsoMakeDependents(); /** * Get the value of {@code resume-from} * * @return specified reactor project to resume from * @since 2.1 */ String getResumeFrom(); /** * Gets the debug mode of the Maven invocation. By default, Maven is executed in normal mode. * * @return true if Maven should be executed in debug mode, false if the normal mode * should be used. */ boolean isDebug(); /** * Gets the exception output mode of the Maven invocation. By default, Maven will not print stack traces of build * exceptions. * * @return true if Maven should print stack traces, false otherwise. */ boolean isShowErrors(); /** * Indicates whether the environment variables of the current process should be propagated to the Maven invocation. * By default, the current environment variables are inherited by the new Maven invocation. * * @return true if the environment variables should be propagated, false otherwise. */ boolean isShellEnvironmentInherited(); /** * Indicates whether Maven should check for plugin updates. By default, plugin updates are not suppressed. * * @return true if plugin updates should be suppressed, false otherwise. */ boolean isNonPluginUpdates(); /** * Gets the failure mode of the Maven invocation. By default, the mode {@link #REACTOR_FAIL_FAST} is used. * * @return The failure mode, one of {@link #REACTOR_FAIL_FAST}, {@link #REACTOR_FAIL_AT_END} and * {@link #REACTOR_FAIL_NEVER}. */ String getFailureBehavior(); /** * Gets the path to the base directory of the local repository to use for the Maven invocation. * * @param defaultDirectory The default location to use if no location is configured for this request, may be * null. * @return The path to the base directory of the local repository or null to use the location from * the settings.xml. */ File getLocalRepositoryDirectory( File defaultDirectory ); /** * Gets the input stream used to provide input for the invoked Maven build. This is in particular useful when * invoking Maven in interactive mode. * * @return The input stream used to provide input for the invoked Maven build or null if not set. */ InputStream getInputStream( InputStream defaultStream ); /** * Gets the handler used to capture the standard output from the Maven build. * * @return The output handler or null if not set. */ InvocationOutputHandler getOutputHandler( InvocationOutputHandler defaultHandler ); /** * Gets the handler used to capture the error output from the Maven build. * * @return The error handler or null if not set. */ InvocationOutputHandler getErrorHandler( InvocationOutputHandler defaultHandler ); /** * Gets the path to the POM for the Maven invocation. If no base directory is set, the parent directory of this POM * will be used as the working directory for the Maven invocation. * * @return The path to the POM for the Maven invocation or null if not set. */ File getPomFile(); /** * Gets the (unqualified) filename of the POM for the Maven invocation. This setting is ignored if * {@link #getPomFile()} does not return null. Otherwise, the base directory is assumed to contain a * POM with this name. By default, a file named pom.xml is used. * * @return The (unqualified) filename of the POM for the Maven invocation or null if not set. */ String getPomFileName(); /** * Gets the path to the base directory of the POM for the Maven invocation. If {@link #getPomFile()} does not return * null, this setting only affects the working directory for the Maven invocation. * * @return The path to the base directory of the POM or null if not set. */ File getBaseDirectory(); /** * Gets the path to the base directory of the POM for the Maven invocation. If {@link #getPomFile()} does not return * null, this setting only affects the working directory for the Maven invocation. * * @param defaultDirectory The default base directory to use if none is configured for this request, may be * null. * @return The path to the base directory of the POM or null if not set. */ File getBaseDirectory( File defaultDirectory ); /** * Gets the path to the base directory of the Java installation used to run Maven. * * @return The path to the base directory of the Java installation used to run Maven or null to use * the default Java home. */ File getJavaHome(); /** * Gets the system properties for the Maven invocation. * * @return The system properties for the Maven invocation or null if not set. */ Properties getProperties(); /** * Gets the goals for the Maven invocation. * * @return The goals for the Maven invocation or null if not set. */ List getGoals(); /** * Gets the path to the user settings for the Maven invocation. * * @return The path to the user settings for the Maven invocation or null to load the user settings * from the default location. */ File getUserSettingsFile(); /** * Gets the path to the global settings for the Maven invocation. * * @return The path to the global settings for the Maven invocation or null to load the global settings * from the default location. * @since 2.1 */ File getGlobalSettingsFile(); /** * Gets the path to the custom toolchains file * * @return The path to the custom toolchains file or null to load the toolchains from the default location * @since 2.1 */ File getToolchainsFile(); /** * Gets the checksum mode of the Maven invocation. * * @return The checksum mode, one of {@link #CHECKSUM_POLICY_WARN} and {@link #CHECKSUM_POLICY_FAIL}. */ String getGlobalChecksumPolicy(); /** * Gets the profiles for the Maven invocation. * * @return The profiles for the Maven invocation or null if not set. */ List getProfiles(); /** * Gets the environment variables for the Maven invocation. * * @return The environment variables for the Maven invocation or null if not set. */ Map getShellEnvironments(); /** * Gets the value of the MAVEN_OPTS environment variable. * * @return The value of the MAVEN_OPTS environment variable or null if not set. */ String getMavenOpts(); /** * The show version behaviour (-V option) * @return The show version behaviour * @since 2.0.11 */ boolean isShowVersion(); /** * Get the value of the {@code threads} argument. * * @return the value of the {@code threads} argument or {@code null} if not set * @since 2.1 */ String getThreads(); // ---------------------------------------------------------------------- // Reactor Failure Mode // ---------------------------------------------------------------------- /** * The failure mode "fail-fast" where the build is stopped by the first failure. */ static final String REACTOR_FAIL_FAST = "fail-fast"; /** * The failure mode "fail-at-end" where the build is only failed at its very end if necessary. */ static final String REACTOR_FAIL_AT_END = "fail-at-end"; /** * The failure mode "fail-never" in which Maven will always exit with code 0 regardless of build failures. */ static final String REACTOR_FAIL_NEVER = "fail-never"; // ---------------------------------------------------------------------- // Artifact repository policies // ---------------------------------------------------------------------- /** * The strict checksum policy which fails the build if a corrupt artifact is detected. */ static final String CHECKSUM_POLICY_FAIL = "fail"; /** * The lax checksum policy which only outputs a warning if a corrupt artifact is detected. */ static final String CHECKSUM_POLICY_WARN = "warn"; // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- /** * Sets the interaction mode of the Maven invocation. * Inverse equivalent of {@code -B} and {@code --batch-mode} * * @param interactive true if Maven should be executed in interactive mode, false if * the batch mode is used. * @return This invocation request. */ InvocationRequest setInteractive( boolean interactive ); /** * Sets the network mode of the Maven invocation. * Equivalent of {@code -o} and {@code --offline} * * @param offline true if Maven should be executed in offline mode, false if the * online mode is used. * @return This invocation request. */ InvocationRequest setOffline( boolean offline ); /** * Sets the debug mode of the Maven invocation. * Equivalent of {@code -X} and {@code --debug} * * @param debug true if Maven should be executed in debug mode, false if the normal * mode should be used. * @return This invocation request. */ InvocationRequest setDebug( boolean debug ); /** * Sets the exception output mode of the Maven invocation. * Equivalent of {@code -e} and {@code --errors} * * @param showErrors true if Maven should print stack traces, false otherwise. * @return This invocation request. */ InvocationRequest setShowErrors( boolean showErrors ); /** * Specifies whether Maven should enforce an update check for plugins and snapshots. * Equivalent of {@code -U} and {@code --update-snapshots} * * @param updateSnapshots true if plugins and snapshots should be updated, false * otherwise. * @return This invocation request. */ InvocationRequest setUpdateSnapshots( boolean updateSnapshots ); /** * Sets the failure mode of the Maven invocation. * Equivalent of {@code -ff} and {@code --fail-fast}, {@code -fae} and {@code --fail-at-end}, {@code -fn} and {@code --fail-never} * * @param failureBehavior The failure mode, must be one of {@link #REACTOR_FAIL_FAST}, {@link #REACTOR_FAIL_AT_END} * and {@link #REACTOR_FAIL_NEVER}. * @return This invocation request. */ InvocationRequest setFailureBehavior( String failureBehavior ); /** * Dynamically constructs a reactor using the subdirectories of the current directory * @param includes a list of filename patterns to include, or null, in which case the default is */pom.xml * @param excludes a list of filename patterns to exclude, or null, in which case nothing is excluded * @return This invocation request */ InvocationRequest activateReactor( String[] includes, String[] excludes ); /** * Sets the path to the base directory of the local repository to use for the Maven invocation. * * @param localRepository The path to the base directory of the local repository, may be null. * @return This invocation request. */ InvocationRequest setLocalRepositoryDirectory( File localRepository ); /** * Sets the input stream used to provide input for the invoked Maven build. This is in particular useful when * invoking Maven in interactive mode. * * @param inputStream The input stream used to provide input for the invoked Maven build, may be null * if not required. * @return This invocation request. */ InvocationRequest setInputStream( InputStream inputStream ); /** * Sets the handler used to capture the standard output from the Maven build. * * @param outputHandler The output handler, may be null if the output is not of interest. * @return This invocation request. */ InvocationRequest setOutputHandler( InvocationOutputHandler outputHandler ); /** * Sets the handler used to capture the error output from the Maven build. * * @param errorHandler The error handler, may be null if the output is not of interest. * @return This invocation request. */ InvocationRequest setErrorHandler( InvocationOutputHandler errorHandler ); /** * Sets the path to the POM for the Maven invocation. If no base directory is set, the parent directory of this POM * will be used as the working directory for the Maven invocation. * * @param pomFile The path to the POM for the Maven invocation, may be null if not used. * @return This invocation request. */ InvocationRequest setPomFile( File pomFile ); /** * Sets the (unqualified) filename of the POM for the Maven invocation. This setting is ignored if * {@link #getPomFile()} does not return null. Otherwise, the base directory is assumed to contain a * POM with this name. * * @param pomFilename The (unqualified) filename of the POM for the Maven invocation, may be null if * not used. * @return This invocation request. */ InvocationRequest setPomFileName( String pomFilename ); /** * Sets the path to the base directory of the POM for the Maven invocation. If {@link #getPomFile()} does not return * null, this setting only affects the working directory for the Maven invocation. * * @param basedir The path to the base directory of the POM, may be null if not used. * @return This invocation request. */ InvocationRequest setBaseDirectory( File basedir ); /** * Sets the path to the base directory of the Java installation used to run Maven. * * @param javaHome The path to the base directory of the Java installation used to run Maven, may be * null to use the default Java home. * @return This invocation request. */ InvocationRequest setJavaHome( File javaHome ); /** * Sets the system properties for the Maven invocation. * * @param properties The system properties for the Maven invocation, may be null if not set. * @return This invocation request. */ InvocationRequest setProperties( Properties properties ); /** * Sets the goals for the Maven invocation. * * @param goals The goals for the Maven invocation, may be null to execute the POMs default goal. * @return This invocation request. */ InvocationRequest setGoals( List goals ); /** * Sets the profiles for the Maven invocation. * Equivalent of {@code -P} and {@code --active-profiles} * * @param profiles The profiles for the Maven invocation, may be null to use the default profiles. * @return This invocation request. */ InvocationRequest setProfiles( List profiles ); /** * Specifies whether the environment variables of the current process should be propagated to the Maven invocation. * * @param shellEnvironmentInherited true if the environment variables should be propagated, * false otherwise. * @return This invocation request. */ InvocationRequest setShellEnvironmentInherited( boolean shellEnvironmentInherited ); /** * Sets the path to the user settings for the Maven invocation. * Equivalent of {@code -s} and {@code --settings} * * @param userSettings The path to the user settings for the Maven invocation, may be null to load * the user settings from the default location. * @return This invocation request. */ InvocationRequest setUserSettingsFile( File userSettings ); /** * Sets the path to the global settings for the Maven invocation. * Equivalent of {@code -gs} and {@code --global-settings} * * @param globalSettings The path to the global settings for the Maven invocation, may be null to load * the global settings from the default location. * @return This invocation request. * @since 2.1 */ InvocationRequest setGlobalSettingsFile( File globalSettings ); /** * Sets the alternate path for the user toolchains file * Equivalent of {@code -t} or {@code --toolchains} *

* note: available since Maven3 *

* * @param toolchains the alternate path for the user toolchains file * @return This invocation request * @since 2.1 */ InvocationRequest setToolchainsFile( File toolchains ); /** * Sets the checksum mode of the Maven invocation. * Equivalent of {@code -c} or {@code --lax-checksums}, {@code -C} or {@code --strict-checksums} * * @param globalChecksumPolicy The checksum mode, must be one of {@link #CHECKSUM_POLICY_WARN} and * {@link #CHECKSUM_POLICY_FAIL}. * @return This invocation request. */ InvocationRequest setGlobalChecksumPolicy( String globalChecksumPolicy ); /** * Specifies whether Maven should check for plugin updates. *

* Equivalent of {@code -npu} or {@code --no-plugin-updates}
* note: Ineffective with Maven3, only kept for backward compatibility *

* @param nonPluginUpdates true if plugin updates should be suppressed, false * otherwise. * @return This invocation request. */ InvocationRequest setNonPluginUpdates( boolean nonPluginUpdates ); /** * Sets the recursion behavior of a reactor invocation. * Inverse equivalent of {@code -N} and {@code --non-recursive} * * @param recursive true if sub modules should be build, false otherwise. * @return This invocation request. */ InvocationRequest setRecursive( boolean recursive ); /** * Adds the specified environment variable to the Maven invocation. * * @param name The name of the environment variable, must not be null. * @param value The value of the environment variable, must not be null. * @return This invocation request. */ InvocationRequest addShellEnvironment( String name, String value ); /** * Sets the value of the MAVEN_OPTS environment variable. * * @param mavenOpts The value of the MAVEN_OPTS environment variable, may be null to * use the default options. * @return This invocation request. */ InvocationRequest setMavenOpts( String mavenOpts ); /** * enable displaying version without stopping the build * Equivalent of {@code -V} or {@code --show-version} * * @param showVersion enable displaying version * @return This invocation request. * @since 2.0.11 */ InvocationRequest setShowVersion( boolean showVersion ); /** * Thread count, for instance 2.0C where C is core multiplied * Equivalent of {@code -T} or {@code --threads} *

* note: available since Maven3 *

* * @param threads the threadcount * @return This invocation request. * @since 2.1 */ InvocationRequest setThreads( String threads ); /** * Sets the reactor project list. * Equivalent of {@code -P} or {@code --projects} * * @param projects the reactor project list * @return This invocation request. * @since 2.1 */ InvocationRequest setProjects( List projects ); /** * Enable the 'also make' mode. * Equivalent of {@code -am} or {@code --also-make} * * @param alsoMake enable 'also make' mode * @return This invocation request. * @since 2.1 */ InvocationRequest setAlsoMake( boolean alsoMake ); /** * Enable the 'also make dependents' mode. * Equivalent of {@code -amd} or {@code --also-make-dependents} * * @param alsoMake enable 'also make' mode * @return This invocation request. * @since 2.1 */ InvocationRequest setAlsoMakeDependents( boolean alsoMakeDependents ); /** * Resume reactor from specified project. * Equivalent of {@code -rf} or {@code --resume-from} * * @param resumeFrom set the project to resume from * @return This invocation request * @since 2.1 */ InvocationRequest setResumeFrom( String resumeFrom ); } maven-invoker-2.1.1/pom.xml0000664000175000017500000001242412047031155015144 0ustar ebourgebourg 4.0.0 org.apache.maven.shared maven-shared-components 18 ../maven-shared-components/pom.xml maven-invoker 2.1.1 Maven Invoker A component to programmatically invoke Maven. scm:svn:http://svn.apache.org/repos/asf/maven/shared/tags/maven-invoker-2.1.1 scm:svn:https://svn.apache.org/repos/asf/maven/shared/tags/maven-invoker-2.1.1 http://svn.apache.org/viewvc/maven/shared/tags/maven-invoker-2.1.1 jira http://jira.codehaus.org/browse/MSHARED/component/13271 Lucien Weller org.codehaus.plexus plexus-utils 3.0.8 org.codehaus.plexus plexus-component-annotations 1.5.5 junit junit 3.8.2 test maven-surefire-plugin true maven.home ${maven.home} test-build-should*/** org.codehaus.plexus plexus-component-metadata create-component-descriptor generate-metadata maven-repo-local maven.repo.local maven-surefire-plugin maven.repo.local ${maven.repo.local} apache-release maven-assembly-plugin source-release-assembly true source-release-assembly-fixed package single src/main/assembly/source-release.xml gnu