From b55562328b6c050116becbc5f1ea0cc59c6e1718 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 9 Oct 2009 23:16:40 +0000 Subject: [PATCH] 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 --- .../artifact/DefaultMavenMetadataCache.java | 101 +++++++++- .../project/artifact/MavenMetadataSource.java | 11 +- .../java/org/apache/maven/cli/CLIManager.java | 14 +- .../apache/maven/cli/CLIReportingUtils.java | 17 +- .../org/apache/maven/cli/CLIRequestUtils.java | 28 ++- .../java/org/apache/maven/cli/FileLogger.java | 51 ----- .../java/org/apache/maven/cli/MavenCli.java | 186 +++++++++++------- .../apache/maven/cli/PrintStreamLogger.java | 7 +- .../apache/maven/cli/CLIRequestUtilsTest.java | 4 +- 9 files changed, 278 insertions(+), 141 deletions(-) delete mode 100644 maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java index 95bbc61579..814b2d2a3e 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java @@ -19,6 +19,7 @@ package org.apache.maven.project.artifact; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; 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.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.codehaus.plexus.component.annotations.Component; @Component( role = MavenMetadataCache.class ) @@ -39,6 +41,7 @@ public class DefaultMavenMetadataCache public static class CacheKey { private final Artifact artifact; + private final long pomHash; private final boolean resolveManagedVersions; private final List repositories = new ArrayList(); private final int hashCode; @@ -46,7 +49,16 @@ public class DefaultMavenMetadataCache public CacheKey( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository, List remoteRepositories ) { + File file = artifact.getFile(); 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.repositories.add( localRepository ); this.repositories.addAll( remoteRepositories ); @@ -54,7 +66,7 @@ public class DefaultMavenMetadataCache int hash = 17; hash = hash * 31 + artifactHashCode( artifact ); hash = hash * 31 + ( resolveManagedVersions ? 1 : 2 ); - hash = hash * 31 + repositories.hashCode(); + hash = hash * 31 + repositoriesHashCode( repositories ); this.hashCode = hash; } @@ -78,9 +90,10 @@ public class DefaultMavenMetadataCache } CacheKey other = (CacheKey) o; - - return artifactEquals( artifact, other.artifact ) && resolveManagedVersions == other.resolveManagedVersions - && repositories.equals( other.repositories ); + + return pomHash == other.pomHash && artifactEquals( artifact, other.artifact ) + && resolveManagedVersions == other.resolveManagedVersions + && repositoriesEquals( repositories, other.repositories ); } } @@ -107,7 +120,7 @@ public class DefaultMavenMetadataCache { return true; } - + return eq( a1.getGroupId(), a2.getGroupId() ) && eq( a1.getArtifactId(), a2.getArtifactId() ) && eq( a1.getType(), a2.getType() ) @@ -118,6 +131,63 @@ public class DefaultMavenMetadataCache && 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 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 r1, List r2 ) + { + if ( r1.size() != r2.size() ) + { + return false; + } + + for ( Iterator it1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); ) + { + if ( !repositoryEquals( it1.next(), it2.next() ) ) + { + return false; + } + } + + return true; + } + private static boolean eq( T s1, T s2 ) { return s1 != null? s1.equals( s2 ): s2 == null; @@ -190,9 +260,26 @@ public class DefaultMavenMetadataCache public boolean isStale() { 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; diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 199e8aa13d..a734af5f01 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -132,7 +132,11 @@ public class MavenMetadataSource 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 dependencies; @@ -229,6 +233,11 @@ public class MavenMetadataSource return result; } + private boolean hasFile( Artifact artifact ) + { + return artifact != null && artifact.getFile() != null && artifact.getFile().exists(); + } + private List aggregateRepositories( List requestRepositories, List pomRepositories ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index 2449d9a245..f80564041e 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -15,6 +15,8 @@ package org.apache.maven.cli; * the License. */ +import java.io.PrintStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -247,12 +249,18 @@ public class CLIManager return cleanArgs; } - public void displayHelp() + public void displayHelp( PrintStream stdout ) { - System.out.println(); + stdout.println(); + + PrintWriter pw = new PrintWriter( stdout ); HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp( "mvn [options] [] []", "\nOptions:", options, "\n" ); + formatter.printHelp( pw, HelpFormatter.DEFAULT_WIDTH, "mvn [options] [] []", "\nOptions:", + options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "\n", false ); + + pw.flush(); } + } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 9d574591bd..1d82460f8c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -21,6 +21,7 @@ package org.apache.maven.cli; import java.io.IOException; import java.io.InputStream; +import java.io.PrintStream; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -47,7 +48,7 @@ public final class CLIReportingUtils public static final int SEC_PER_MIN = 60; - public static void showVersion() + public static void showVersion( PrintStream stdout ) { Properties properties = getBuildProperties(); @@ -70,17 +71,17 @@ public final class CLIReportingUtils msg += ")"; } - System.out.println( msg ); + stdout.println( msg ); - System.out.println( "Java version: " + System.getProperty( "java.version", "" ) ); + stdout.println( "Java version: " + System.getProperty( "java.version", "" ) ); - System.out.println( "Java home: " + System.getProperty( "java.home", "" ) ); + stdout.println( "Java home: " + System.getProperty( "java.home", "" ) ); - System.out.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " - + System.getProperty( "file.encoding", "" ) ); + stdout.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " + + System.getProperty( "file.encoding", "" ) ); - System.out.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION - + "\" arch: \"" + Os.OS_ARCH + "\" Family: \"" + Os.OS_FAMILY + "\"" ); + stdout.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + "\" arch: \"" + Os.OS_ARCH + + "\" Family: \"" + Os.OS_FAMILY + "\"" ); } private static String reduce( String s ) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java index f702db9fab..1bbaffb5ef 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java @@ -53,7 +53,8 @@ final class CLIRequestUtils } 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 @@ -135,7 +136,7 @@ final class CLIRequestUtils globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } - File baseDirectory = new File( System.getProperty( "user.dir" ) ); + File baseDirectory = new File( workingDirectory, "" ).getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation @@ -220,6 +221,7 @@ final class CLIRequestUtils if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_TOOLCHAINS ) ) { userToolchainsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_TOOLCHAINS ) ); + userToolchainsFile = resolveFile( userToolchainsFile, workingDirectory ); } else { @@ -249,6 +251,7 @@ final class CLIRequestUtils if ( alternatePomFile != null ) { pom = new File( alternatePomFile ); + pom = resolveFile( pom, workingDirectory ); } else { @@ -302,6 +305,27 @@ final class CLIRequestUtils 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 // ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java deleted file mode 100644 index e0921a2fca..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java +++ /dev/null @@ -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 ); - } - } - -} diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index f0b1e6f85d..c0d4f0b1a5 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -16,7 +16,9 @@ package org.apache.maven.cli; */ import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintStream; import java.io.Reader; 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" ); 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 ) { - ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() ); - - int result = main( args, classWorld ); + int result = main( args, null ); System.exit( result ); } @@ -81,13 +85,55 @@ public class MavenCli /** @noinspection ConfusingMainMethod */ 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 // ---------------------------------------------------------------------- @@ -101,8 +147,8 @@ public class MavenCli } catch ( ParseException e ) { - System.err.println( "Unable to parse command line options: " + e.getMessage() ); - cliManager.displayHelp(); + stderr.println( "Unable to parse command line options: " + e.getMessage() ); + cliManager.displayHelp( stdout ); return 1; } @@ -118,14 +164,14 @@ public class MavenCli if ( commandLine.hasOption( CLIManager.HELP ) ) { - cliManager.displayHelp(); + cliManager.displayHelp( stdout ); return 0; } if ( commandLine.hasOption( CLIManager.VERSION ) ) { - CLIReportingUtils.showVersion(); + CLIReportingUtils.showVersion( stdout ); return 0; } @@ -138,41 +184,37 @@ public class MavenCli 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; - DefaultPlexusContainer container; - - Logger logger; - 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 ); } - 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 ) { 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; } - Configuration configuration = buildEmbedderConfiguration( commandLine ); + Configuration configuration = buildEmbedderConfiguration( commandLine, workingDirectory ); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); @@ -263,7 +305,7 @@ public class MavenCli return 1; } - CLIRequestUtils.populateRequest( request, commandLine, debug, quiet, showErrors ); + CLIRequestUtils.populateRequest( request, commandLine, workingDirectory, debug, quiet, showErrors ); request.setExecutionListener( new ExecutionEventLogger( logger ) ); @@ -271,7 +313,7 @@ public class MavenCli if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) ) { - CLIReportingUtils.showVersion(); + CLIReportingUtils.showVersion( stdout ); } if ( showErrors ) @@ -306,8 +348,7 @@ public class MavenCli DefaultPlexusCipher cipher = new DefaultPlexusCipher(); - System.out.println( cipher.encryptAndDecorate( passwd, - DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) ); + stdout.println( cipher.encryptAndDecorate( passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) ); return 0; } @@ -335,21 +376,21 @@ public class MavenCli 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; } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); 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; } } catch ( Exception e ) { - System.err.println( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage() ); + stderr.println( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage() ); return 1; } @@ -375,50 +416,61 @@ public class MavenCli // 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 ) - { - logger.error( "", result.getExceptions().get( 0 ) ); - } - else - { - if ( showErrors ) + if ( es == null ) { - logger.error( es.getMessage(), es.getException() ); + logger.error( "", result.getExceptions().get( 0 ) ); } 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() ) ) - { - logger.info( "Build failures were ignored." ); + if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( request.getReactorFailureBehavior() ) ) + { + logger.info( "Build failures were ignored." ); - return 0; + return 0; + } + else + { + return 1; + } } 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; if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) ) { userSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) ); + userSettingsFile = CLIRequestUtils.resolveFile( userSettingsFile, workingDirectory ); } else { @@ -430,6 +482,7 @@ public class MavenCli if ( commandLine.hasOption( CLIManager.ALTERNATE_GLOBAL_SETTINGS ) ) { globalSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_GLOBAL_SETTINGS ) ); + globalSettingsFile = CLIRequestUtils.resolveFile( globalSettingsFile, workingDirectory ); } else { @@ -512,4 +565,5 @@ public class MavenCli return result; } + } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java index 2b26b31510..44a724dcc6 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java @@ -34,7 +34,7 @@ public class PrintStreamLogger extends AbstractLogger { - private final PrintStream out; + private PrintStream out; private static final String FATAL_ERROR = "[FATAL] "; @@ -50,6 +50,11 @@ public class PrintStreamLogger { super( Logger.LEVEL_INFO, Maven.class.getName() ); + setStream( out ); + } + + public void setStream( PrintStream out ) + { if ( out == null ) { throw new IllegalArgumentException( "output stream missing" ); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java index 769a119f7f..83a6f8eaf3 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java @@ -60,7 +60,7 @@ public class CLIRequestUtilsTest assertEquals( 1, commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY ).length ); 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(); @@ -108,7 +108,7 @@ public class CLIRequestUtilsTest String path = new File( "" ).getAbsolutePath(); 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() ); }