mirror of https://github.com/apache/maven.git
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:
parent
e33b97e832
commit
b55562328b
|
@ -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<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
|
||||
private final int hashCode;
|
||||
|
@ -46,7 +49,16 @@ public class DefaultMavenMetadataCache
|
|||
public CacheKey( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> 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;
|
||||
}
|
||||
|
||||
|
@ -79,8 +91,9 @@ 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<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 )
|
||||
{
|
||||
return s1 != null? s1.equals( s2 ): s2 == null;
|
||||
|
@ -190,10 +260,27 @@ public class DefaultMavenMetadataCache
|
|||
public boolean isStale()
|
||||
{
|
||||
File pomFile = pomArtifact.getFile();
|
||||
if ( pomFile != null && pomFile.canRead() )
|
||||
if ( pomFile != null )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -131,9 +131,13 @@ public class MavenMetadataSource
|
|||
request.getRemoteRepositories() );
|
||||
|
||||
if ( cached != null )
|
||||
{
|
||||
// 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;
|
||||
|
||||
|
@ -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<ArtifactRepository> aggregateRepositories( List<ArtifactRepository> requestRepositories,
|
||||
List<ArtifactRepository> pomRepositories )
|
||||
{
|
||||
|
|
|
@ -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] [<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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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", "<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.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 )
|
||||
|
|
|
@ -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
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -69,11 +71,13 @@ public class MavenCli
|
|||
|
||||
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,6 +416,8 @@ public class MavenCli
|
|||
|
||||
// The exception handling should be handled in Maven itself.
|
||||
|
||||
try
|
||||
{
|
||||
if ( result.hasExceptions() )
|
||||
{
|
||||
ExceptionSummary es = result.getExceptionSummary();
|
||||
|
@ -411,14 +454,23 @@ public class MavenCli
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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" );
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue