o add basic auth to model and lightweight wagon

o add proxy configuration in lightweight wagon
o not yet wiring in the properties from maven.properties into the repository


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163334 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-02-03 11:39:27 +00:00
parent 6503a19dfc
commit e480dd8d3e
11 changed files with 101 additions and 115 deletions

View File

@ -47,20 +47,17 @@
public class MavenCli
{
public static final String POMv4 = "pom.xml";
public static final String userHome = System.getProperty( "user.home" );
public static File userDir = new File( System.getProperty( "user.dir" ) );
public static int main( String[] args, ClassWorld classWorld )
throws Exception
throws Exception
{
// ----------------------------------------------------------------------
// Setup the command line parser
// ----------------------------------------------------------------------
CLIManager cliManager = new CLIManager();
CommandLine commandLine = cliManager.parse( args );
// ----------------------------------------------------------------------
@ -72,9 +69,7 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
File userConfigurationDirectory = getUserConfigurationDirectory();
Properties mavenProperties = getMavenProperties( userConfigurationDirectory );
ArtifactRepository localRepository = getLocalRepository( mavenProperties, userConfigurationDirectory );
// ----------------------------------------------------------------------
@ -90,14 +85,11 @@ public static int main( String[] args, ClassWorld classWorld )
if ( commandLine.hasOption( CLIManager.HELP ) )
{
cliManager.displayHelp();
return 0;
}
if ( commandLine.hasOption( CLIManager.VERSION ) )
{
System.out.println( "Maven version: " );
return 0;
}
@ -108,29 +100,27 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
MavenExecutionRequest request = null;
File projectFile = new File( userDir, POMv4 );
if ( projectFile.exists() )
{
if ( commandLine.hasOption( CLIManager.REACTOR ) )
{
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
request = new MavenReactorExecutionRequest( localRepository, commandLine.getArgList(), includes, excludes, userDir );
request = new MavenReactorExecutionRequest( localRepository, mavenProperties, commandLine.getArgList(),
includes, excludes, userDir );
}
else
{
request = new MavenProjectExecutionRequest( localRepository, commandLine.getArgList(), projectFile );
request = new MavenProjectExecutionRequest( localRepository, mavenProperties, commandLine.getArgList(),
projectFile );
}
}
else
{
request = new MavenInitializingExecutionRequest( localRepository, commandLine.getArgList() );
request = new MavenInitializingExecutionRequest( localRepository, mavenProperties,
commandLine.getArgList() );
}
MavenExecutionResponse response = new MavenExecutionResponse();
// ----------------------------------------------------------------------
@ -139,9 +129,7 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
embedder.start( classWorld );
Maven maven = (Maven) embedder.lookup( Maven.ROLE );
// ----------------------------------------------------------------------
@ -149,7 +137,6 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
response = maven.execute( request );
if ( response.isExecutionFailure() )
{
return 1;
@ -175,7 +162,6 @@ private static void initializeSystemProperties( CommandLine commandLine )
if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
{
String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
for ( int i = 0; i < defStrs.length; ++i )
{
setCliProperty( defStrs[i] );
@ -186,24 +172,18 @@ private static void initializeSystemProperties( CommandLine commandLine )
private static void setCliProperty( String property )
{
String name = null;
String value = null;
int i = property.indexOf( "=" );
if ( i <= 0 )
{
name = property.trim();
value = "true";
}
else
{
name = property.substring( 0, i ).trim();
value = property.substring( i + 1 ).trim();
}
System.setProperty( name, value );
}
@ -214,86 +194,68 @@ private static void setCliProperty( String property )
static class CLIManager
{
public static final char NO_BANNER = 'b';
public static final char SET_SYSTEM_PROPERTY = 'D';
public static final char WORK_OFFLINE = 'o';
public static final char REACTOR = 'r';
public static final char DEBUG = 'X';
public static final char HELP = 'h';
public static final char VERSION = 'v';
public static final char LIST_GOALS = 'g';
private Options options = null;
public CLIManager()
{
options = new Options();
options.addOption( OptionBuilder
.withLongOpt( "nobanner" )
.withDescription( "Suppress logo banner" )
.create( NO_BANNER ) );
options.addOption( OptionBuilder
.withLongOpt( "define" )
.hasArg()
.withDescription( "Define a system property" )
.create( SET_SYSTEM_PROPERTY ) );
options.addOption( OptionBuilder
.withLongOpt( "offline" )
.hasArg()
.withDescription( "Work offline" )
.create( WORK_OFFLINE ) );
options.addOption( OptionBuilder
.withLongOpt( "mojoDescriptors" )
.withDescription( "Display available mojoDescriptors" )
.create( LIST_GOALS ) );
options.addOption( OptionBuilder
.withLongOpt( "help" )
.withDescription( "Display help information" )
.create( HELP ) );
options.addOption( OptionBuilder
.withLongOpt( "offline" )
.withDescription( "Build is happening offline" )
.create( WORK_OFFLINE ) );
options.addOption( OptionBuilder
.withLongOpt( "version" )
.withDescription( "Display version information" )
.create( VERSION ) );
options.addOption( OptionBuilder
.withLongOpt( "debug" )
.withDescription( "Produce execution debug output" )
.create( DEBUG ) );
options.addOption( OptionBuilder
.withLongOpt( "reactor" )
.withDescription( "Execute goals for project found in the reactor" )
.create( REACTOR ) );
}
public CommandLine parse( String[] args ) throws ParseException
public CommandLine parse( String[] args )
throws ParseException
{
CommandLineParser parser = new PosixParser();
return parser.parse( options, args );
}
public void displayHelp()
{
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", "\nOptions:", options, "\n" );
}
}
@ -305,7 +267,6 @@ public void displayHelp()
protected static File getUserConfigurationDirectory()
{
File mavenUserConfigurationDirectory = new File( userHome, MavenConstants.MAVEN_USER_CONFIGURATION_DIRECTORY );
if ( !mavenUserConfigurationDirectory.exists() )
{
if ( !mavenUserConfigurationDirectory.mkdirs() )
@ -313,39 +274,35 @@ protected static File getUserConfigurationDirectory()
//throw a configuration exception
}
}
return mavenUserConfigurationDirectory;
}
protected static Properties getMavenProperties( File mavenHomeLocal )
{
Properties mavenProperties = new Properties();
File mavenPropertiesFile = new File( mavenHomeLocal, MavenConstants.MAVEN_PROPERTIES );
try
{
{
mavenProperties.load( new FileInputStream( mavenPropertiesFile ) );
}
catch ( Exception e )
{
// do nothing
}
return mavenProperties;
}
protected static ArtifactRepository getLocalRepository( Properties mavenProperties, File userConfigurationDirectory )
protected static ArtifactRepository getLocalRepository( Properties mavenProperties,
File userConfigurationDirectory )
{
String localRepository = mavenProperties.getProperty( MavenConstants.MAVEN_REPO_LOCAL );
if ( localRepository == null )
{
localRepository = new File( userConfigurationDirectory, MavenConstants.MAVEN_REPOSITORY ).getAbsolutePath();
}
// TODO [BP]: this should not be necessary - grep for and remove
System.setProperty( MavenConstants.MAVEN_REPO_LOCAL, localRepository );
return RepositoryUtils.localRepositoryToWagonRepository( localRepository );
}
}

View File

@ -18,29 +18,30 @@
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.project.MavenProject;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class AbstractMavenExecutionRequest
implements MavenExecutionRequest
implements MavenExecutionRequest
{
protected ArtifactRepository localRepository;
protected final Properties parameters;
protected List goals;
protected String type;
protected MavenSession session;
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, List goals )
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, Properties parameters, List goals )
{
this.localRepository = localRepository;
this.parameters = parameters;
this.goals = goals;
}
@ -59,6 +60,11 @@ public String getType()
return type;
}
public String getParameter( String name )
{
return parameters.getProperty( name );
}
// ----------------------------------------------------------------------
// Putting the session here but it can probably be folded right in here.
// ----------------------------------------------------------------------
@ -72,4 +78,9 @@ public void setSession( MavenSession session )
{
this.session = session;
}
public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project )
{
return new MavenProjectExecutionRequest( getLocalRepository(), parameters, getGoals(), project.getFile() );
}
}

View File

@ -18,7 +18,9 @@
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.project.MavenProject;
import java.util.List;
@ -30,6 +32,8 @@ public interface MavenExecutionRequest
{
ArtifactRepository getLocalRepository();
String getParameter( String name );
List getGoals();
String getType();
@ -37,4 +41,6 @@ public interface MavenExecutionRequest
void setSession( MavenSession session );
MavenSession getSession();
MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project );
}

View File

@ -20,18 +20,18 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenSetupExecutionRequest
extends AbstractMavenExecutionRequest
extends AbstractMavenExecutionRequest
{
public MavenSetupExecutionRequest( ArtifactRepository localRepository, List goals )
public MavenSetupExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals )
{
super( localRepository, goals );
super( localRepository, properties, goals );
type = "setup";
}
}

View File

@ -21,18 +21,18 @@
import org.apache.maven.execution.AbstractMavenExecutionRequest;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenInitializingExecutionRequest
extends AbstractMavenExecutionRequest
extends AbstractMavenExecutionRequest
{
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, List goals )
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals )
{
super( localRepository, goals );
type = "initializing";
super( localRepository, properties, goals );
type = "initializing";
}
}

View File

@ -22,22 +22,22 @@
import java.io.File;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenProjectExecutionRequest
extends AbstractMavenExecutionRequest
extends AbstractMavenExecutionRequest
{
private File pom;
public MavenProjectExecutionRequest( ArtifactRepository localRepository, List goals, File pom )
public MavenProjectExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals,
File pom )
{
super( localRepository, goals );
super( localRepository, properties, goals );
this.pom = pom;
type = "project";
}

View File

@ -22,30 +22,26 @@
import java.io.File;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenReactorExecutionRequest
extends AbstractMavenExecutionRequest
extends AbstractMavenExecutionRequest
{
private String includes;
private String excludes;
private File baseDirectory;
public MavenReactorExecutionRequest( ArtifactRepository localRepository, List goals, String includes, String excludes, File baseDirectory )
public MavenReactorExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals,
String includes, String excludes, File baseDirectory )
{
super( localRepository, goals );
super( localRepository, properties, goals );
this.includes = includes;
this.excludes = excludes;
this.baseDirectory = baseDirectory;
type = "reactor";
}

View File

@ -35,63 +35,45 @@
* @version $Id$
*/
public class MavenReactorExecutionRequestHandler
extends MavenProjectExecutionRequestHandler
extends MavenProjectExecutionRequestHandler
{
public void handle( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception
throws Exception
{
List projects = new ArrayList();
getLogger().info( "Starting the reactor..." );
try
{
{
List files = FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ),
( (MavenReactorExecutionRequest) request ).getIncludes(),
( (MavenReactorExecutionRequest) request ).getExcludes() );
for ( Iterator iterator = files.iterator(); iterator.hasNext(); )
{
File file = (File) iterator.next();
MavenProject project = getProject( file, request.getLocalRepository() );
projects.add( project );
}
projects = projectBuilder.getSortedProjects( projects );
}
catch ( Exception e )
{
throw new ReactorException( "Error processing projects for the reactor: ", e );
}
getLogger().info( "Our processing order:" );
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
getLogger().info( project.getName() );
}
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
System.out.println( "\n\n\n" );
line();
getLogger().info( "Building " + project.getName() );
line();
MavenProjectExecutionRequest projectExecutionRequest =
new MavenProjectExecutionRequest( request.getLocalRepository(), request.getGoals(), project.getFile() );
MavenProjectExecutionRequest projectExecutionRequest = request.createProjectExecutionRequest( project );
super.handle( projectExecutionRequest, response );
if ( response.isExecutionFailure() )
{
break;
@ -103,7 +85,8 @@ public void handle( MavenExecutionRequest request, MavenExecutionResponse respon
// Reactor
// ----------------------------------------------------------------------
public List getSortedProjects( List projects ) throws Exception
public List getSortedProjects( List projects )
throws Exception
{
return projectBuilder.getSortedProjects( projects );
}

View File

@ -1,6 +1,21 @@
// TODO Attach license header here.
package org.apache.maven.project;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author jdcasey Created on Feb 1, 2005
*/

View File

@ -19,6 +19,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import java.util.HashSet;
import java.util.Iterator;
@ -26,30 +27,34 @@
import java.util.Set;
/**
* @todo not sure "wagon" notation is appropriate here - it is really maven-artifact which is not the same as wagon
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @version $Id$
* @todo not sure "wagon" notation is appropriate here - it is really maven-artifact which is not the same as wagon
*/
public class RepositoryUtils
{
public static Set mavenToWagon( List repositories )
{
Set repos = new HashSet();
for ( Iterator i = repositories.iterator(); i.hasNext(); )
{
repos.add( mavenRepositoryToWagonRepository( (Repository) i.next() ) );
}
return repos;
}
public static ArtifactRepository
mavenRepositoryToWagonRepository( Repository mavenRepository )
mavenRepositoryToWagonRepository( Repository mavenRepository )
{
ArtifactRepository retValue = new ArtifactRepository();
if ( mavenRepository.getUsername() != null )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName( mavenRepository.getUsername() );
authInfo.setPassword( mavenRepository.getPassword() );
retValue.setAuthenticationInfo( authInfo );
}
retValue.setUrl( mavenRepository.getUrl() );
return retValue;
}

View File

@ -1565,6 +1565,19 @@
]]></description>
<type>String</type>
</field>
<field>
<name>username</name>
<version>4.0.0</version>
<description>The username to connect to the repository with. If omitted, none is used.</description>
<type>String</type>
</field>
<!-- @todo this should be encrypted in some way or be a keystore lookup and m2 can provide a way to generate it -->
<field>
<name>password</name>
<version>4.0.0</version>
<description>The password to use when connecting to the repository. If omitted, none is used.</description>
<type>String</type>
</field>
</fields>
<codeSegments>
<codeSegment>