o Enabled reuse of MavenCli for embedded execution during the ITs

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@823736 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-09 23:16:40 +00:00
parent e33b97e832
commit b55562328b
9 changed files with 278 additions and 141 deletions

View File

@ -19,6 +19,7 @@ package org.apache.maven.project.artifact;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -29,6 +30,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@Component( role = MavenMetadataCache.class ) @Component( role = MavenMetadataCache.class )
@ -39,6 +41,7 @@ public class DefaultMavenMetadataCache
public static class CacheKey public static class CacheKey
{ {
private final Artifact artifact; private final Artifact artifact;
private final long pomHash;
private final boolean resolveManagedVersions; private final boolean resolveManagedVersions;
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>(); private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
private final int hashCode; private final int hashCode;
@ -46,7 +49,16 @@ public class DefaultMavenMetadataCache
public CacheKey( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository, public CacheKey( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories ) List<ArtifactRepository> remoteRepositories )
{ {
File file = artifact.getFile();
this.artifact = ArtifactUtils.copyArtifact( artifact ); this.artifact = ArtifactUtils.copyArtifact( artifact );
if ( "pom".equals( artifact.getType() ) && file != null )
{
pomHash = file.getPath().hashCode() + file.lastModified();
}
else
{
pomHash = 0;
}
this.resolveManagedVersions = resolveManagedVersions; this.resolveManagedVersions = resolveManagedVersions;
this.repositories.add( localRepository ); this.repositories.add( localRepository );
this.repositories.addAll( remoteRepositories ); this.repositories.addAll( remoteRepositories );
@ -54,7 +66,7 @@ public class DefaultMavenMetadataCache
int hash = 17; int hash = 17;
hash = hash * 31 + artifactHashCode( artifact ); hash = hash * 31 + artifactHashCode( artifact );
hash = hash * 31 + ( resolveManagedVersions ? 1 : 2 ); hash = hash * 31 + ( resolveManagedVersions ? 1 : 2 );
hash = hash * 31 + repositories.hashCode(); hash = hash * 31 + repositoriesHashCode( repositories );
this.hashCode = hash; this.hashCode = hash;
} }
@ -78,9 +90,10 @@ public class DefaultMavenMetadataCache
} }
CacheKey other = (CacheKey) o; CacheKey other = (CacheKey) o;
return artifactEquals( artifact, other.artifact ) && resolveManagedVersions == other.resolveManagedVersions return pomHash == other.pomHash && artifactEquals( artifact, other.artifact )
&& repositories.equals( other.repositories ); && resolveManagedVersions == other.resolveManagedVersions
&& repositoriesEquals( repositories, other.repositories );
} }
} }
@ -107,7 +120,7 @@ public class DefaultMavenMetadataCache
{ {
return true; return true;
} }
return eq( a1.getGroupId(), a2.getGroupId() ) return eq( a1.getGroupId(), a2.getGroupId() )
&& eq( a1.getArtifactId(), a2.getArtifactId() ) && eq( a1.getArtifactId(), a2.getArtifactId() )
&& eq( a1.getType(), a2.getType() ) && eq( a1.getType(), a2.getType() )
@ -118,6 +131,63 @@ public class DefaultMavenMetadataCache
&& a1.isOptional() == a2.isOptional(); && a1.isOptional() == a2.isOptional();
} }
private static int repositoryHashCode( ArtifactRepository repository )
{
int result = 17;
result = 31 * result + ( repository.getId() != null ? repository.getId().hashCode() : 0 );
return result;
}
private static int repositoriesHashCode( List<ArtifactRepository> repositories )
{
int result = 17;
for ( ArtifactRepository repository : repositories )
{
result = 31 * result + repositoryHashCode( repository );
}
return result;
}
private static boolean repositoryEquals( ArtifactRepository r1, ArtifactRepository r2 )
{
if ( r1 == r2 )
{
return true;
}
return eq( r1.getId(), r2.getId() ) && eq( r1.getUrl(), r2.getUrl() )
&& repositoryPolicyEquals( r1.getReleases(), r2.getReleases() )
&& repositoryPolicyEquals( r1.getSnapshots(), r2.getSnapshots() );
}
private static boolean repositoryPolicyEquals( ArtifactRepositoryPolicy p1, ArtifactRepositoryPolicy p2 )
{
if ( p1 == p2 )
{
return true;
}
return p1.isEnabled() == p2.isEnabled() && eq( p1.getUpdatePolicy(), p2.getUpdatePolicy() );
}
private static boolean repositoriesEquals( List<ArtifactRepository> r1, List<ArtifactRepository> r2 )
{
if ( r1.size() != r2.size() )
{
return false;
}
for ( Iterator<ArtifactRepository> it1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); )
{
if ( !repositoryEquals( it1.next(), it2.next() ) )
{
return false;
}
}
return true;
}
private static <T> boolean eq( T s1, T s2 ) private static <T> boolean eq( T s1, T s2 )
{ {
return s1 != null? s1.equals( s2 ): s2 == null; return s1 != null? s1.equals( s2 ): s2 == null;
@ -190,9 +260,26 @@ public class DefaultMavenMetadataCache
public boolean isStale() public boolean isStale()
{ {
File pomFile = pomArtifact.getFile(); File pomFile = pomArtifact.getFile();
if ( pomFile != null && pomFile.canRead() ) if ( pomFile != null )
{ {
return length != pomFile.length() || timestamp != pomFile.lastModified(); if ( pomFile.canRead() )
{
return length != pomFile.length() || timestamp != pomFile.lastModified();
}
else
{
// if the POM didn't exist, retry if any repo is configured to always update
boolean snapshot = pomArtifact.isSnapshot();
for ( ArtifactRepository repository : remoteRepositories )
{
ArtifactRepositoryPolicy policy =
snapshot ? repository.getSnapshots() : repository.getReleases();
if ( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy.getUpdatePolicy() ) )
{
return true;
}
}
}
} }
return length != -1 || timestamp != -1; return length != -1 || timestamp != -1;

View File

@ -132,7 +132,11 @@ public class MavenMetadataSource
if ( cached != null ) if ( cached != null )
{ {
return cached; // if the POM has no file, we cached a missing artifact, only return the cached data if no update forced
if ( !request.isForceUpdate() || hasFile( cached.getPomArtifact() ) )
{
return cached;
}
} }
List<Dependency> dependencies; List<Dependency> dependencies;
@ -229,6 +233,11 @@ public class MavenMetadataSource
return result; return result;
} }
private boolean hasFile( Artifact artifact )
{
return artifact != null && artifact.getFile() != null && artifact.getFile().exists();
}
private List<ArtifactRepository> aggregateRepositories( List<ArtifactRepository> requestRepositories, private List<ArtifactRepository> aggregateRepositories( List<ArtifactRepository> requestRepositories,
List<ArtifactRepository> pomRepositories ) List<ArtifactRepository> pomRepositories )
{ {

View File

@ -15,6 +15,8 @@ package org.apache.maven.cli;
* the License. * the License.
*/ */
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -247,12 +249,18 @@ public class CLIManager
return cleanArgs; return cleanArgs;
} }
public void displayHelp() public void displayHelp( PrintStream stdout )
{ {
System.out.println(); stdout.println();
PrintWriter pw = new PrintWriter( stdout );
HelpFormatter formatter = new HelpFormatter(); HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "mvn [options] [<goal(s)>] [<phase(s)>]", "\nOptions:", options, "\n" ); formatter.printHelp( pw, HelpFormatter.DEFAULT_WIDTH, "mvn [options] [<goal(s)>] [<phase(s)>]", "\nOptions:",
options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "\n", false );
pw.flush();
} }
} }

View File

@ -21,6 +21,7 @@ package org.apache.maven.cli;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -47,7 +48,7 @@ public final class CLIReportingUtils
public static final int SEC_PER_MIN = 60; public static final int SEC_PER_MIN = 60;
public static void showVersion() public static void showVersion( PrintStream stdout )
{ {
Properties properties = getBuildProperties(); Properties properties = getBuildProperties();
@ -70,17 +71,17 @@ public final class CLIReportingUtils
msg += ")"; msg += ")";
} }
System.out.println( msg ); stdout.println( msg );
System.out.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" ) ); stdout.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" ) );
System.out.println( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) ); stdout.println( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) );
System.out.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " stdout.println( "Default locale: " + Locale.getDefault() + ", platform encoding: "
+ System.getProperty( "file.encoding", "<unknown encoding>" ) ); + System.getProperty( "file.encoding", "<unknown encoding>" ) );
System.out.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION stdout.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + "\" arch: \"" + Os.OS_ARCH
+ "\" arch: \"" + Os.OS_ARCH + "\" Family: \"" + Os.OS_FAMILY + "\"" ); + "\" Family: \"" + Os.OS_FAMILY + "\"" );
} }
private static String reduce( String s ) private static String reduce( String s )

View File

@ -53,7 +53,8 @@ final class CLIRequestUtils
} }
public static MavenExecutionRequest populateRequest( MavenExecutionRequest request, CommandLine commandLine, public static MavenExecutionRequest populateRequest( MavenExecutionRequest request, CommandLine commandLine,
boolean debug, boolean quiet, boolean showErrors ) String workingDirectory, boolean debug, boolean quiet,
boolean showErrors )
{ {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Now that we have everything that we need we will fire up plexus and // Now that we have everything that we need we will fire up plexus and
@ -135,7 +136,7 @@ final class CLIRequestUtils
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
} }
File baseDirectory = new File( System.getProperty( "user.dir" ) ); File baseDirectory = new File( workingDirectory, "" ).getAbsoluteFile();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Profile Activation // Profile Activation
@ -220,6 +221,7 @@ final class CLIRequestUtils
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_TOOLCHAINS ) ) if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_TOOLCHAINS ) )
{ {
userToolchainsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_TOOLCHAINS ) ); userToolchainsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_TOOLCHAINS ) );
userToolchainsFile = resolveFile( userToolchainsFile, workingDirectory );
} }
else else
{ {
@ -249,6 +251,7 @@ final class CLIRequestUtils
if ( alternatePomFile != null ) if ( alternatePomFile != null )
{ {
pom = new File( alternatePomFile ); pom = new File( alternatePomFile );
pom = resolveFile( pom, workingDirectory );
} }
else else
{ {
@ -302,6 +305,27 @@ final class CLIRequestUtils
return request; return request;
} }
static File resolveFile( File file, String workingDirectory )
{
if ( file == null )
{
return null;
}
else if ( file.isAbsolute() )
{
return file;
}
else if ( file.getPath().startsWith( File.separator ) )
{
// drive-relative Windows path
return file.getAbsoluteFile();
}
else
{
return new File( workingDirectory, file.getPath() );
}
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// System properties handling // System properties handling
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View File

@ -1,51 +0,0 @@
package org.apache.maven.cli;
/*
* 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.FileNotFoundException;
import java.io.PrintStream;
/**
* @author Jason van Zyl
* @todo document the need to call close() once successfully constructed, otherwise file handles can be leaked. Might be good to add a finalizer too, just in case.
*/
public final class FileLogger
extends PrintStreamLogger
{
public FileLogger( File logFile )
{
super( openStream( logFile ) );
}
private static PrintStream openStream( File logFile )
{
try
{
return new PrintStream( logFile );
}
catch ( FileNotFoundException e )
{
throw new IllegalArgumentException( "Cannot open specified log file " + logFile, e );
}
}
}

View File

@ -16,7 +16,9 @@ package org.apache.maven.cli;
*/ */
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader; import java.io.Reader;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
@ -68,12 +70,14 @@ public class MavenCli
new File( System.getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" ); new File( System.getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" );
public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File( userMavenConfigurationHome, "toolchains.xml" ); public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File( userMavenConfigurationHome, "toolchains.xml" );
private DefaultPlexusContainer container;
private PrintStreamLogger logger;
public static void main( String[] args ) public static void main( String[] args )
{ {
ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() ); int result = main( args, null );
int result = main( args, classWorld );
System.exit( result ); System.exit( result );
} }
@ -81,13 +85,55 @@ public class MavenCli
/** @noinspection ConfusingMainMethod */ /** @noinspection ConfusingMainMethod */
public static int main( String[] args, ClassWorld classWorld ) public static int main( String[] args, ClassWorld classWorld )
{ {
MavenCli cli = new MavenCli(); MavenCli cli = new MavenCli( classWorld );
return cli.doMain( args, classWorld ); return cli.doMain( args, null, System.out, System.err );
} }
public int doMain( String[] args, ClassWorld classWorld ) public MavenCli()
{ {
this( null );
}
public MavenCli( ClassWorld classWorld )
{
if ( classWorld == null )
{
classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
}
try
{
ContainerConfiguration cc =
new DefaultContainerConfiguration().setClassWorld( classWorld ).setName( "embedder" );
container = new DefaultPlexusContainer( cc );
}
catch ( PlexusContainerException e )
{
throw new IllegalStateException( "Could not start component container: " + e.getMessage(), e );
}
logger = new PrintStreamLogger( System.out );
container.setLoggerManager( new MavenLoggerManager( logger ) );
}
public int doMain( String[] args, String workingDirectory, PrintStream stdout, PrintStream stderr )
{
if ( stdout == null )
{
stdout = System.out;
}
if ( stderr == null )
{
stderr = System.err;
}
if ( workingDirectory == null )
{
workingDirectory = System.getProperty( "user.dir" );
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Setup the command line parser // Setup the command line parser
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -101,8 +147,8 @@ public class MavenCli
} }
catch ( ParseException e ) catch ( ParseException e )
{ {
System.err.println( "Unable to parse command line options: " + e.getMessage() ); stderr.println( "Unable to parse command line options: " + e.getMessage() );
cliManager.displayHelp(); cliManager.displayHelp( stdout );
return 1; return 1;
} }
@ -118,14 +164,14 @@ public class MavenCli
if ( commandLine.hasOption( CLIManager.HELP ) ) if ( commandLine.hasOption( CLIManager.HELP ) )
{ {
cliManager.displayHelp(); cliManager.displayHelp( stdout );
return 0; return 0;
} }
if ( commandLine.hasOption( CLIManager.VERSION ) ) if ( commandLine.hasOption( CLIManager.VERSION ) )
{ {
CLIReportingUtils.showVersion(); CLIReportingUtils.showVersion( stdout );
return 0; return 0;
} }
@ -138,41 +184,37 @@ public class MavenCli
System.setProperty( "maven.home", new File( mavenHome ).getAbsolutePath() ); System.setProperty( "maven.home", new File( mavenHome ).getAbsolutePath() );
} }
PrintStream fileStream = null;
if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
{
File logFile = new File( commandLine.getOptionValue( CLIManager.LOG_FILE ) );
logFile = CLIRequestUtils.resolveFile( logFile, workingDirectory );
try
{
fileStream = new PrintStream( logFile );
logger.setStream( fileStream );
}
catch ( FileNotFoundException e )
{
stderr.println( e );
logger.setStream( stdout );
}
}
else
{
logger.setStream( stdout );
}
// //
Maven maven; Maven maven;
DefaultPlexusContainer container;
Logger logger;
try try
{ {
ContainerConfiguration cc = new DefaultContainerConfiguration()
.setClassWorld( classWorld )
.setName( "embedder" );
container = new DefaultPlexusContainer( cc );
logger = container.getLogger();
if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
{
File logFile = new File( commandLine.getOptionValue( CLIManager.LOG_FILE ) ).getAbsoluteFile();
logger = new FileLogger( logFile );
container.setLoggerManager( new MavenLoggerManager( logger ) );
}
maven = container.lookup( Maven.class ); maven = container.lookup( Maven.class );
} }
catch ( PlexusContainerException e )
{
CLIReportingUtils.showError( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName() ), "Unable to start the embedder: ", e, showErrors );
return 1;
}
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
CLIReportingUtils.showError( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName() ), "Unable to start the embedder: ", e, showErrors ); CLIReportingUtils.showError( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName() ), "Unable to start the embedder: ", e, showErrors );
@ -180,7 +222,7 @@ public class MavenCli
return 1; return 1;
} }
Configuration configuration = buildEmbedderConfiguration( commandLine ); Configuration configuration = buildEmbedderConfiguration( commandLine, workingDirectory );
MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionRequest request = new DefaultMavenExecutionRequest();
@ -263,7 +305,7 @@ public class MavenCli
return 1; return 1;
} }
CLIRequestUtils.populateRequest( request, commandLine, debug, quiet, showErrors ); CLIRequestUtils.populateRequest( request, commandLine, workingDirectory, debug, quiet, showErrors );
request.setExecutionListener( new ExecutionEventLogger( logger ) ); request.setExecutionListener( new ExecutionEventLogger( logger ) );
@ -271,7 +313,7 @@ public class MavenCli
if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) ) if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) )
{ {
CLIReportingUtils.showVersion(); CLIReportingUtils.showVersion( stdout );
} }
if ( showErrors ) if ( showErrors )
@ -306,8 +348,7 @@ public class MavenCli
DefaultPlexusCipher cipher = new DefaultPlexusCipher(); DefaultPlexusCipher cipher = new DefaultPlexusCipher();
System.out.println( cipher.encryptAndDecorate( passwd, stdout.println( cipher.encryptAndDecorate( passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) );
DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) );
return 0; return 0;
} }
@ -335,21 +376,21 @@ public class MavenCli
if ( master == null ) if ( master == null )
{ {
System.err.println( "Master password is not set in the setting security file" ); stderr.println( "Master password is not set in the setting security file" );
return 1; return 1;
} }
DefaultPlexusCipher cipher = new DefaultPlexusCipher(); DefaultPlexusCipher cipher = new DefaultPlexusCipher();
String masterPasswd = cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ); String masterPasswd = cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION );
System.out.println( cipher.encryptAndDecorate( passwd, masterPasswd ) ); stdout.println( cipher.encryptAndDecorate( passwd, masterPasswd ) );
return 0; return 0;
} }
} }
catch ( Exception e ) catch ( Exception e )
{ {
System.err.println( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage() ); stderr.println( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage() );
return 1; return 1;
} }
@ -375,50 +416,61 @@ public class MavenCli
// The exception handling should be handled in Maven itself. // The exception handling should be handled in Maven itself.
if ( result.hasExceptions() ) try
{ {
ExceptionSummary es = result.getExceptionSummary(); if ( result.hasExceptions() )
{
ExceptionSummary es = result.getExceptionSummary();
if ( es == null ) if ( es == null )
{
logger.error( "", result.getExceptions().get( 0 ) );
}
else
{
if ( showErrors )
{ {
logger.error( es.getMessage(), es.getException() ); logger.error( "", result.getExceptions().get( 0 ) );
} }
else else
{ {
logger.error( es.getMessage() ); if ( showErrors )
{
logger.error( es.getMessage(), es.getException() );
}
else
{
logger.error( es.getMessage() );
}
} }
}
if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( request.getReactorFailureBehavior() ) ) if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( request.getReactorFailureBehavior() ) )
{ {
logger.info( "Build failures were ignored." ); logger.info( "Build failures were ignored." );
return 0; return 0;
}
else
{
return 1;
}
} }
else else
{ {
return 1; return 0;
} }
} }
else finally
{ {
return 0; if ( fileStream != null )
{
fileStream.close();
}
} }
} }
private Configuration buildEmbedderConfiguration( CommandLine commandLine ) private Configuration buildEmbedderConfiguration( CommandLine commandLine, String workingDirectory )
{ {
File userSettingsFile; File userSettingsFile;
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) ) if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
{ {
userSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) ); userSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) );
userSettingsFile = CLIRequestUtils.resolveFile( userSettingsFile, workingDirectory );
} }
else else
{ {
@ -430,6 +482,7 @@ public class MavenCli
if ( commandLine.hasOption( CLIManager.ALTERNATE_GLOBAL_SETTINGS ) ) if ( commandLine.hasOption( CLIManager.ALTERNATE_GLOBAL_SETTINGS ) )
{ {
globalSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_GLOBAL_SETTINGS ) ); globalSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_GLOBAL_SETTINGS ) );
globalSettingsFile = CLIRequestUtils.resolveFile( globalSettingsFile, workingDirectory );
} }
else else
{ {
@ -512,4 +565,5 @@ public class MavenCli
return result; return result;
} }
} }

View File

@ -34,7 +34,7 @@ public class PrintStreamLogger
extends AbstractLogger extends AbstractLogger
{ {
private final PrintStream out; private PrintStream out;
private static final String FATAL_ERROR = "[FATAL] "; private static final String FATAL_ERROR = "[FATAL] ";
@ -50,6 +50,11 @@ public class PrintStreamLogger
{ {
super( Logger.LEVEL_INFO, Maven.class.getName() ); super( Logger.LEVEL_INFO, Maven.class.getName() );
setStream( out );
}
public void setStream( PrintStream out )
{
if ( out == null ) if ( out == null )
{ {
throw new IllegalArgumentException( "output stream missing" ); throw new IllegalArgumentException( "output stream missing" );

View File

@ -60,7 +60,7 @@ public class CLIRequestUtilsTest
assertEquals( 1, commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY ).length ); assertEquals( 1, commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY ).length );
MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request = CLIRequestUtils.populateRequest( request, commandLine, false, false, false ); request = CLIRequestUtils.populateRequest( request, commandLine, null, false, false, false );
Properties userProperties = request.getUserProperties(); Properties userProperties = request.getUserProperties();
@ -108,7 +108,7 @@ public class CLIRequestUtilsTest
String path = new File( "" ).getAbsolutePath(); String path = new File( "" ).getAbsolutePath();
MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionRequest request = new DefaultMavenExecutionRequest();
CLIRequestUtils.populateRequest( request, parse( "-Dmaven.repo.local=" + path ), false, false, false ); CLIRequestUtils.populateRequest( request, parse( "-Dmaven.repo.local=" + path ), null, false, false, false );
assertEquals( path, request.getLocalRepositoryPath().getAbsolutePath() ); assertEquals( path, request.getLocalRepositoryPath().getAbsolutePath() );
} }