o Changed Set to List for remote repo handling so that we can maintain declarative ordering in remote repos we use.

o Added UserModel support, integrated with maven-artifact and wagon via AuthenticationInfoProvider implementation.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-09 05:48:31 +00:00
parent 92fe671087
commit 7f6f4452f2
35 changed files with 560 additions and 593 deletions

View File

@ -24,22 +24,21 @@
/**
* @todo refactor away
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: AbstractArtifactComponent.java,v 1.4 2005/03/08 05:34:52 brett
* Exp $
*/
public class AbstractArtifactComponent
extends AbstractLogEnabled
{
private ArtifactHandlerManager artifactHandlerManager;
protected ArtifactHandler getArtifactHandler( String type )
throws ArtifactHandlerNotFoundException
protected ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException
{
return artifactHandlerManager.getArtifactHandler( type );
}
protected String path( Artifact artifact )
throws ArtifactHandlerNotFoundException
protected String path( Artifact artifact ) throws ArtifactHandlerNotFoundException
{
return artifactHandlerManager.path( artifact );
}
@ -47,6 +46,8 @@ protected String path( Artifact artifact )
protected void setLocalRepositoryPath( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactHandlerNotFoundException
{
artifact.setPath( artifactHandlerManager.localRepositoryPath( artifact, localRepository ) );
String artifactPath = artifactHandlerManager.localRepositoryPath( artifact, localRepository );
artifact.setPath( artifactPath );
}
}

View File

@ -19,7 +19,7 @@
import java.io.File;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class DefaultArtifact

View File

@ -1,25 +1,22 @@
package org.apache.maven.artifact.manager;
/* ====================================================================
* Copyright 2001-2004 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.
/*
* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
import org.apache.maven.artifact.AbstractArtifactComponent;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
@ -41,8 +38,8 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DefaultWagonManager
extends AbstractArtifactComponent
@ -54,8 +51,9 @@ public class DefaultWagonManager
private TransferListener downloadMonitor;
public Wagon getWagon( String protocol )
throws UnsupportedProtocolException
private AuthenticationInfoProvider authenticationInfoProvider;
public Wagon getWagon( String protocol ) throws UnsupportedProtocolException
{
Wagon wagon;
@ -65,23 +63,24 @@ public Wagon getWagon( String protocol )
}
catch ( ComponentLookupException e )
{
throw new UnsupportedProtocolException( "Cannot find wagon which supports the requested protocol: " + protocol, e );
throw new UnsupportedProtocolException( "Cannot find wagon which supports the requested protocol: "
+ protocol, e );
}
return wagon;
}
// TODO: don't throw exception
public void releaseWagon( Wagon wagon )
throws Exception
public void releaseWagon( Wagon wagon ) throws Exception
{
container.release( wagon );
}
// TODO: don't throw exception
public void put( File source, Artifact artifact, ArtifactRepository repository )
throws Exception
public void put( File source, Artifact artifact, ArtifactRepository repository ) throws Exception
{
authenticationInfoProvider.configureAuthenticationInfo( repository );
Wagon wagon = getWagon( repository.getProtocol() );
wagon.connect( repository, getProxy( repository.getProtocol() ) );
@ -93,7 +92,7 @@ public void put( File source, Artifact artifact, ArtifactRepository repository )
releaseWagon( wagon );
}
public void get( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository )
public void get( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws TransferFailedException
{
get( artifact, artifact.getFile(), remoteRepositories );
@ -109,19 +108,18 @@ public void get( Artifact artifact, Set remoteRepositories, ArtifactRepository l
* @param destination
* @throws TransferFailedException
* @todo I want to somehow plug artifact validators at such low level.
* Simply if artifact was downloaded but it was rejected by validator(s)
* the loop should continue. Some of the validators can be feeded directly using events
* so number of i/o operation could be limited.
* <p/>
* If we won't plug validation process here the question is what we can do afterwards?
* We don't know from which ArtifactRepository artifact was fetched and where we should restart.
* We should be also fetching md5 sums and such from the same exact directory then artifacts
* <p/>
* Simply if artifact was downloaded but it was rejected by
* validator(s) the loop should continue. Some of the validators can
* be feeded directly using events so number of i/o operation could be
* limited. <p/>If we won't plug validation process here the question
* is what we can do afterwards? We don't know from which
* ArtifactRepository artifact was fetched and where we should
* restart. We should be also fetching md5 sums and such from the same
* exact directory then artifacts <p/>
* @todo probably all exceptions should just be logged and continue
* @todo is the exception for warnings logged at debug level correct?
*/
public void get( Artifact artifact, File destination, Set repositories )
throws TransferFailedException
public void get( Artifact artifact, File destination, List repositories ) throws TransferFailedException
{
File temp = null;
@ -136,10 +134,13 @@ public void get( Artifact artifact, File destination, Set repositories )
try
{
authenticationInfoProvider.configureAuthenticationInfo( repository );
Wagon wagon = getWagon( repository.getProtocol() );
// ----------------------------------------------------------------------
// These can certainly be configurable ... registering listeners ...
// These can certainly be configurable ... registering listeners
// ...
//ChecksumObserver md5SumObserver = new ChecksumObserver();
@ -203,10 +204,14 @@ public void get( Artifact artifact, File destination, Set repositories )
destination.getParentFile().mkdirs();
}
// The temporary file is named destination + ".tmp" and is done this way to ensure
// that the temporary file is in the same file system as the destination because the
// File.renameTo operation doesn't really work across file systems. So we will attempt
// to do a File.renameTo for efficiency and atomicity, if this fails then we will use
// The temporary file is named destination + ".tmp" and is done this
// way to ensure
// that the temporary file is in the same file system as the
// destination because the
// File.renameTo operation doesn't really work across file systems.
// So we will attempt
// to do a File.renameTo for efficiency and atomicity, if this fails
// then we will use
// a brute force copy and delete the temporary file.
if ( !temp.renameTo( destination ) )
@ -238,17 +243,21 @@ private ProxyInfo getProxy( String protocol )
* Set the proxy used for a particular protocol.
*
* @todo [BP] would be nice to configure this via plexus in some way
*
* @param protocol the protocol (required)
* @param host the proxy host name (required)
* @param port the proxy port (required)
* @param username the username for the proxy, or null if there is none
* @param password the password for the proxy, or null if there is none
* @param nonProxyHosts the set of hosts not to use the proxy for. Follows Java system property format:
* <code>*.foo.com|localhost</code>.
* @param protocol
* the protocol (required)
* @param host
* the proxy host name (required)
* @param port
* the proxy port (required)
* @param username
* the username for the proxy, or null if there is none
* @param password
* the password for the proxy, or null if there is none
* @param nonProxyHosts
* the set of hosts not to use the proxy for. Follows Java system
* property format: <code>*.foo.com|localhost</code>.
*/
public void setProxy( String protocol, String host, int port, String username, String password,
String nonProxyHosts )
public void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost( host );
@ -261,8 +270,7 @@ public void setProxy( String protocol, String host, int port, String username, S
proxies.put( protocol, proxyInfo );
}
public void contextualize( Context context )
throws ContextException
public void contextualize( Context context ) throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}

View File

@ -25,30 +25,26 @@
import org.apache.maven.wagon.events.TransferListener;
import java.io.File;
import java.util.Set;
import java.util.List;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$
*/
public interface WagonManager
{
String ROLE = WagonManager.class.getName();
Wagon getWagon( String protocol )
throws UnsupportedProtocolException;
Wagon getWagon( String protocol ) throws UnsupportedProtocolException;
// TODO: don't throw exception
void releaseWagon( Wagon wagon )
throws Exception;
void releaseWagon( Wagon wagon ) throws Exception;
void get( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository )
void get( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws TransferFailedException;
// TODO: don't throw exception
void put( File source, Artifact artifact, ArtifactRepository deploymentRepository )
throws Exception;
void put( File source, Artifact artifact, ArtifactRepository deploymentRepository ) throws Exception;
void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );

View File

@ -19,6 +19,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Set;
// Currently the only thing we need from the artifact metadata source is the
@ -27,11 +28,11 @@
// the artifact we may wish to provide in this layer. jvz.
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public interface ArtifactMetadataSource
{
Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories )
Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException;
}

View File

@ -19,71 +19,39 @@
import org.apache.maven.wagon.repository.Repository;
/**
* This class is an abstraction of the location from/to resources
* can be transfered.
* This class is an abstraction of the location from/to resources can be
* transfered.
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$
*/
public class ArtifactRepository
extends Repository
{
public ArtifactRepository()
{
}
// public ArtifactRepository()
// {
// }
public ArtifactRepository( String id, String url)
public ArtifactRepository( String id, String url )
{
super( id, url );
}
/*
private String layout;
public String getLayout()
{
if ( layout == null )
{
return "${groupId}/${type}s/${artifactId}-${version}.${extension}";
}
return layout;
}
public String artifactPath( Artifact artifact )
{
return interpolateLayout( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
artifact.getType(),
artifact.getExtension() );
}
public String fullArtifactPath( Artifact artifact )
{
return getBasedir() + "/" + artifactPath( artifact );
}
public String artifactUrl( Artifact artifact )
{
return getUrl() + "/" + artifactPath( artifact );
}
private String interpolateLayout( String groupId, String artifactId, String version, String type, String extension )
{
String layout = getLayout();
layout = StringUtils.replace( layout, "${groupId}", groupId );
layout = StringUtils.replace( layout, "${artifactId}", artifactId );
layout = StringUtils.replace( layout, "${type}", type );
layout = StringUtils.replace( layout, "${version}", version );
layout = StringUtils.replace( layout, "${extension}", extension );
return layout;
}
* private String layout; public String getLayout() { if ( layout == null ) {
* return "${groupId}/${type}s/${artifactId}-${version}.${extension}"; }
* return layout; } public String artifactPath( Artifact artifact ) { return
* interpolateLayout( artifact.getGroupId(), artifact.getArtifactId(),
* artifact.getVersion(), artifact.getType(), artifact.getExtension() ); }
* public String fullArtifactPath( Artifact artifact ) { return getBasedir() +
* "/" + artifactPath( artifact ); } public String artifactUrl( Artifact
* artifact ) { return getUrl() + "/" + artifactPath( artifact ); } private
* String interpolateLayout( String groupId, String artifactId, String
* version, String type, String extension ) { String layout = getLayout();
* layout = StringUtils.replace( layout, "${groupId}", groupId ); layout =
* StringUtils.replace( layout, "${artifactId}", artifactId ); layout =
* StringUtils.replace( layout, "${type}", type ); layout =
* StringUtils.replace( layout, "${version}", version ); layout =
* StringUtils.replace( layout, "${extension}", extension ); return layout; }
*/
}

View File

@ -0,0 +1,15 @@
package org.apache.maven.artifact.repository.authentication;
import org.apache.maven.wagon.repository.Repository;
/**
* @author jdcasey
*/
public interface AuthenticationInfoProvider
{
public static final String ROLE = AuthenticationInfoProvider.class.getName();
// TODO: do not throw Exception.
void configureAuthenticationInfo( Repository wagonRepository ) throws Exception;
}

View File

@ -1,56 +1,42 @@
package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import java.util.List;
import java.util.Set;
/**
* I want to use it for hidding the fact that sometime artifact must
* be downloaded. I am just asking LocalRepository for given artifact
* and I don't care if it is alredy there or how it will get there.
* I want to use it for hidding the fact that sometime artifact must be
* downloaded. I am just asking LocalRepository for given artifact and I don't
* care if it is alredy there or how it will get there.
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$
*/
public interface ArtifactResolver
{
static String ROLE = ArtifactResolver.class.getName();
Artifact resolve( Artifact artifact,
Set remoteRepositories,
ArtifactRepository localRepository )
Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Artifact artifact,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException;
Set resolve( Set artifacts, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException;
Set resolve( Set artifacts,
Set remoteRepositories,
ArtifactRepository localRepository )
ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException;
void addArtifactRequestTransformation( org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation requestTransformation );
void addArtifactRequestTransformation(
org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation requestTransformation );
}

View File

@ -21,7 +21,8 @@
import java.util.Set;
/**
* @todo get rid of {@link AbstractArtifactComponent} and then create an AbstractArtifactResolver that does the transitive boilerplate
* @todo get rid of {@link AbstractArtifactComponent}and then create an
* AbstractArtifactResolver that does the transitive boilerplate
*/
public class DefaultArtifactResolver
extends AbstractArtifactComponent
@ -43,9 +44,7 @@ public class DefaultArtifactResolver
// Implementation
// ----------------------------------------------------------------------
public Artifact resolve( Artifact artifact,
Set remoteRepositories,
ArtifactRepository localRepository )
public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
// ----------------------------------------------------------------------
@ -54,7 +53,8 @@ public Artifact resolve( Artifact artifact,
// ----------------------------------------------------------------------
// Check for the existence of the artifact in the specified local
// ArtifactRepository. If it is present then simply return as the request
// ArtifactRepository. If it is present then simply return as the
// request
// for resolution has been satisfied.
// ----------------------------------------------------------------------
@ -83,7 +83,7 @@ public Artifact resolve( Artifact artifact,
private static final String LS = System.getProperty( "line.separator" );
private String artifactNotFound( Artifact artifact, Set remoteRepositories )
private String artifactNotFound( Artifact artifact, List remoteRepositories )
{
StringBuffer sb = new StringBuffer();
@ -111,9 +111,7 @@ private String artifactNotFound( Artifact artifact, Set remoteRepositories )
return sb.toString();
}
public Set resolve( Set artifacts,
Set remoteRepositories,
ArtifactRepository localRepository )
public Set resolve( Set artifacts, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
Set resolvedArtifacts = new HashSet();
@ -134,22 +132,15 @@ public Set resolve( Set artifacts,
// Transitive modes
// ----------------------------------------------------------------------
public ArtifactResolutionResult resolveTransitively( Set artifacts,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source,
ArtifactFilter filter )
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
ArtifactResolutionResult artifactResolutionResult;
try
{
artifactResolutionResult = collect( artifacts,
localRepository,
remoteRepositories,
source,
filter );
artifactResolutionResult = collect( artifacts, localRepository, remoteRepositories, source, filter );
}
catch ( TransitiveArtifactResolutionException e )
{
@ -164,34 +155,24 @@ public ArtifactResolutionResult resolveTransitively( Set artifacts,
return artifactResolutionResult;
}
public ArtifactResolutionResult resolveTransitively( Set artifacts,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
{
return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
{
return resolveTransitively( Collections.singleton( artifact ), remoteRepositories, localRepository, source );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private ArtifactResolutionResult collect( Set artifacts,
ArtifactRepository localRepository,
Set remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter )
private ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter )
throws TransitiveArtifactResolutionException
{
ArtifactResolutionResult result = new ArtifactResolutionResult();
@ -246,10 +227,12 @@ private ArtifactResolutionResult collect( Set artifacts,
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact + "] : ", e );
throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact
+ "] : ", e );
}
// the pom for given dependency exisit we will add it to the queue
// the pom for given dependency exisit we will add it to the
// queue
queue.add( referencedDependencies );
}
}
@ -257,7 +240,8 @@ private ArtifactResolutionResult collect( Set artifacts,
// ----------------------------------------------------------------------
// the dependencies list is keyed by groupId+artifactId+type
// so it must be 'rekeyed' to the complete id: groupId+artifactId+type+version
// so it must be 'rekeyed' to the complete id:
// groupId+artifactId+type+version
// ----------------------------------------------------------------------
Map artifactResult = result.getArtifacts();

View File

@ -3,8 +3,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Map;
import java.util.Set;
/*
* Copyright 2001-2004 The Apache Software Foundation.
@ -23,8 +23,9 @@
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: ArtifactRequestTransformation.java,v 1.1 2005/03/03 15:37:25
* jvanzyl Exp $
*/
public interface ArtifactRequestTransformation
{
@ -34,12 +35,10 @@ public interface ArtifactRequestTransformation
* Take in a artifact and return the transformed artifact. If no
* transformation has occured the original artifact is returned.
*
* @param artifact Artifact to be transformed.
* @param artifact
* Artifact to be transformed.
* @return The transformed Artifact
*/
Artifact transform( Artifact artifact,
ArtifactRepository localRepository,
Set remoteRepositories,
Map parameters )
Artifact transform( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories, Map parameters )
throws Exception;
}

View File

@ -9,23 +9,21 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
/**
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
* @version $Id$
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka </a>
* @version $Id: SnapshotRequestTransformation.java,v 1.1 2005/03/03 15:37:25
* jvanzyl Exp $
*/
public class SnapshotRequestTransformation
implements ArtifactRequestTransformation
{
private ArtifactResolver artifactResolver;
public Artifact transform( Artifact artifact,
ArtifactRepository localRepository,
Set repositories,
Map parameters )
public Artifact transform( Artifact artifact, ArtifactRepository localRepository, List repositories, Map parameters )
throws Exception
{
Date localVersion = getLocalVersion( artifact, localRepository );
@ -49,7 +47,8 @@ public Artifact transform( Artifact artifact,
// We can change the strategy which is used here later on
// @todo we will delete old file first.
//it is not really a right thing to do. Artifact Dowloader should
//it is not really a right thing to do. Artifact Dowloader
// should
// fetch to temprary file and replace the old file with the new
// one once download was finished
@ -80,7 +79,7 @@ private File getSnapshotVersionFile( Artifact artifact, ArtifactRepository local
//return new File( localRepository.fullArtifactPath( artifact ) );
}
private Date getRemoteVersion( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository )
private Date getRemoteVersion( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws Exception
{
Date retValue = null;
@ -119,7 +118,8 @@ private Date getLocalVersion( Artifact artifact, ArtifactRepository localReposit
if ( retValue == null )
{
//try "traditional method" used in maven1 for obtaining snapshot version
//try "traditional method" used in maven1 for obtaining snapshot
// version
File file = artifact.getFile();
@ -129,11 +129,9 @@ private Date getLocalVersion( Artifact artifact, ArtifactRepository localReposit
//@todo we should "normalize" the time.
/*TimeZone gmtTimeZone = TimeZone.getTimeZone( "GMT" );
TimeZone userTimeZone = TimeZone.getDefault();
long diff =
/*
* TimeZone gmtTimeZone = TimeZone.getTimeZone( "GMT" );
* TimeZone userTimeZone = TimeZone.getDefault(); long diff =
*/
}
}
@ -163,15 +161,14 @@ public static String getTimestamp()
return retValue;
}
public static Date parseTimestamp ( String timestamp )
throws ParseException
public static Date parseTimestamp( String timestamp ) throws ParseException
{
Date retValue = getFormatter().parse( timestamp );
return retValue;
}
public static String getTimestamp ( Date snapshotVersion )
public static String getTimestamp( Date snapshotVersion )
{
String retValue = getFormatter().format( snapshotVersion );

View File

@ -31,6 +31,9 @@
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
</requirement>
</requirements>
</component>

View File

@ -25,20 +25,20 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: ArtifactComponentTestCase.java,v 1.5 2004/10/23 13:33:59
* jvanzyl Exp $
*/
public abstract class ArtifactComponentTestCase
extends PlexusTestCase
{
protected ArtifactHandlerManager artifactHandlerManager;
protected void setUp()
throws Exception
protected void setUp() throws Exception
{
super.setUp();
@ -47,62 +47,50 @@ protected void setUp()
protected abstract String component();
/**
* Return an existing file, not a directory - causes creation to fail.
*/
protected ArtifactRepository badLocalRepository()
throws IOException
/** Return an existing file, not a directory - causes creation to fail. */
protected ArtifactRepository badLocalRepository() throws IOException
{
ArtifactRepository localRepository = new ArtifactRepository();
String path = "target/test-classes/repositories/" + component() + "/bad-local-repository";
File f = new File( getBasedir(), path );
f.createNewFile();
localRepository.setUrl( "file://" + f.getPath() );
ArtifactRepository localRepository = new ArtifactRepository( "test", "file://" + f.getPath() );
return localRepository;
}
protected ArtifactRepository localRepository()
{
ArtifactRepository localRepository = new ArtifactRepository();
String path = "target/test-classes/repositories/" + component() + "/local-repository";
File f = new File( getBasedir(), path );
localRepository.setUrl( "file://" + f.getPath() );
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" + f.getPath() );
return localRepository;
}
protected ArtifactRepository remoteRepository()
{
ArtifactRepository repository = new ArtifactRepository();
String path = "target/test-classes/repositories/" + component() + "/remote-repository";
File f = new File( getBasedir(), path );
repository.setUrl( "file://" + f.getPath() );
ArtifactRepository repository = new ArtifactRepository( "test", "file://" + f.getPath() );
return repository;
}
protected ArtifactRepository badRemoteRepository()
{
ArtifactRepository repository = new ArtifactRepository();
repository.setUrl( "http://foo.bar/repository" );
ArtifactRepository repository = new ArtifactRepository( "test", "http://foo.bar/repository" );
return repository;
}
protected void assertRemoteArtifactPresent( Artifact artifact )
throws ArtifactHandlerNotFoundException
protected void assertRemoteArtifactPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
{
String path = artifactHandlerManager.path( artifact );
@ -114,8 +102,7 @@ protected void assertRemoteArtifactPresent( Artifact artifact )
}
}
protected void assertLocalArtifactPresent( Artifact artifact )
throws ArtifactHandlerNotFoundException
protected void assertLocalArtifactPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
{
String path = artifactHandlerManager.path( artifact );
@ -127,8 +114,7 @@ protected void assertLocalArtifactPresent( Artifact artifact )
}
}
protected void assertRemoteArtifactNotPresent( Artifact artifact )
throws ArtifactHandlerNotFoundException
protected void assertRemoteArtifactNotPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
{
String path = artifactHandlerManager.path( artifact );
@ -140,8 +126,7 @@ protected void assertRemoteArtifactNotPresent( Artifact artifact )
}
}
protected void assertLocalArtifactNotPresent( Artifact artifact )
throws ArtifactHandlerNotFoundException
protected void assertLocalArtifactNotPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
{
String path = artifactHandlerManager.path( artifact );
@ -157,9 +142,9 @@ protected void assertLocalArtifactNotPresent( Artifact artifact )
//
// ----------------------------------------------------------------------
protected Set remoteRepositories()
protected List remoteRepositories()
{
Set remoteRepositories = new HashSet();
List remoteRepositories = new ArrayList();
remoteRepositories.add( remoteRepository() );
@ -170,8 +155,7 @@ protected Set remoteRepositories()
// Test artifact generation for unit tests
// ----------------------------------------------------------------------
protected Artifact createLocalArtifact( String artifactId, String version )
throws Exception
protected Artifact createLocalArtifact( String artifactId, String version ) throws Exception
{
Artifact artifact = createArtifact( artifactId, version );
@ -180,8 +164,7 @@ protected Artifact createLocalArtifact( String artifactId, String version )
return artifact;
}
protected Artifact createRemoteArtifact( String artifactId, String version )
throws Exception
protected Artifact createRemoteArtifact( String artifactId, String version ) throws Exception
{
Artifact artifact = createArtifact( artifactId, version );
@ -190,20 +173,17 @@ protected Artifact createRemoteArtifact( String artifactId, String version )
return artifact;
}
protected void createLocalArtifact( Artifact artifact )
throws Exception
protected void createLocalArtifact( Artifact artifact ) throws Exception
{
createArtifact( artifact, localRepository() );
}
protected void createRemoteArtifact( Artifact artifact )
throws Exception
protected void createRemoteArtifact( Artifact artifact ) throws Exception
{
createArtifact( artifact, remoteRepository() );
}
protected void createArtifact( Artifact artifact, ArtifactRepository repository )
throws Exception
protected void createArtifact( Artifact artifact, ArtifactRepository repository ) throws Exception
{
String path = artifactHandlerManager.path( artifact );
@ -228,7 +208,7 @@ protected Artifact createArtifact( String artifactId, String version )
protected Artifact createArtifact( String artifactId, String version, String type )
{
return createArtifact( "maven", artifactId, version, type );
return new DefaultArtifact( "maven", artifactId, version, type );
}
protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
@ -236,14 +216,12 @@ protected Artifact createArtifact( String groupId, String artifactId, String ver
return new DefaultArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, type, type );
}
protected void deleteLocalArtifact( Artifact artifact )
throws Exception
protected void deleteLocalArtifact( Artifact artifact ) throws Exception
{
deleteArtifact( artifact, localRepository() );
}
protected void deleteArtifact( Artifact artifact, ArtifactRepository repository )
throws Exception
protected void deleteArtifact( Artifact artifact, ArtifactRepository repository ) throws Exception
{
String path = artifactHandlerManager.path( artifact );

View File

@ -0,0 +1,16 @@
package org.apache.maven.artifact.repository.authentication;
import org.apache.maven.wagon.repository.Repository;
/**
* @author jdcasey
*/
public class DummyAuthenticationInfoProvider
implements AuthenticationInfoProvider
{
public void configureAuthenticationInfo( Repository wagonRepository ) throws Exception
{
}
}

View File

@ -18,12 +18,20 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactComponentTestCase;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
// It would be cool if there was a hook that i could use to setup a test environment.
// I want to setup a local/remote repositories for testing but i don't want to have
// to change them when i change the layout of the repositories. So i want to generate
@ -39,8 +47,7 @@ public class ArtifactResolverTest
{
private ArtifactResolver artifactResolver;
protected void setUp()
throws Exception
protected void setUp() throws Exception
{
super.setUp();
@ -52,8 +59,7 @@ protected String component()
return "resolver";
}
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository()
throws Exception
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception
{
Artifact a = createLocalArtifact( "a", "1.0" );
@ -73,8 +79,7 @@ public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAn
assertLocalArtifactPresent( b );
}
public void testResolutionOfASetOfArtifactsWhereTheArtifactsArePresentInTheLocalRepository()
throws Exception
public void testResolutionOfASetOfArtifactsWhereTheArtifactsArePresentInTheLocalRepository() throws Exception
{
Set artifacts = new HashSet();
@ -140,7 +145,7 @@ public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalReposit
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories )
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
@ -178,7 +183,7 @@ public void testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepo
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories )
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
@ -226,7 +231,7 @@ public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood(
Artifact l = createRemoteArtifact( "l", "1.0" );
deleteLocalArtifact( l );
Set repositories = new HashSet();
List repositories = new ArrayList();
repositories.add( remoteRepository() );
repositories.add( badRemoteRepository() );

View File

@ -0,0 +1,8 @@
<plexus>
<components>
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components>
</plexus>

View File

@ -0,0 +1,8 @@
<plexus>
<components>
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components>
</plexus>

View File

@ -20,5 +20,9 @@
<role-hint>c</role-hint>
<implementation>org.apache.maven.artifact.manager.WagonC</implementation>
</component>
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components>
</plexus>

View File

@ -0,0 +1,8 @@
<plexus>
<components>
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components>
</plexus>

View File

@ -29,16 +29,20 @@
import org.apache.maven.project.MavenProjectBuilder;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class MavenMetadataSource
implements ArtifactMetadataSource
{
private MavenProjectBuilder mavenProjectBuilder;
private ArtifactResolver artifactResolver;
// TODO: configure?
@ -63,7 +67,7 @@ public MavenMetadataSource( ArtifactResolver artifactResolver, MavenProjectBuild
this.mavenProjectBuilder = projectBuilder;
}
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories )
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
Set artifacts;
@ -96,7 +100,7 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
}
catch ( Exception e )
{
throw new ArtifactMetadataRetrievalException( "Cannot read artifact source: " + metadataArtifact.getFile(),
throw new ArtifactMetadataRetrievalException( "Cannot read artifact source: " + metadataArtifact.getPath(),
e );
}
return artifacts;

View File

@ -0,0 +1,34 @@
package org.apache.maven.artifact.repository.authentication;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.util.UserModelUtils;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.repository.Repository;
/**
* @author jdcasey
*/
public class MavenAuthenticationInfoProvider
implements AuthenticationInfoProvider
{
public void configureAuthenticationInfo( Repository repo ) throws Exception
{
UserModel userModel = UserModelUtils.getUserModel();
ServerProfile serverProfile = UserModelUtils.getServerProfile( userModel, repo.getId() );
AuthenticationInfo info = new AuthenticationInfo();
if ( serverProfile != null )
{
info.setUserName( serverProfile.getUsername() );
info.setPassword( serverProfile.getPassword() );
info.setPrivateKey( serverProfile.getPrivateKey() );
info.setPassphrase( serverProfile.getPassphrase() );
}
repo.setAuthenticationInfo( info );
}
}

View File

@ -18,12 +18,12 @@
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.dag.CycleDetectedException;
@ -31,6 +31,9 @@
import org.codehaus.plexus.util.dag.TopologicalSorter;
import org.codehaus.plexus.util.dag.Vertex;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -65,8 +68,8 @@ public class MavenSession
private final UserModel userModel;
public MavenSession( PlexusContainer container, PluginManager pluginManager, UserModel userModel, ArtifactRepository localRepository,
EventDispatcher eventDispatcher, Log log, List goals )
public MavenSession( PlexusContainer container, PluginManager pluginManager, UserModel userModel,
ArtifactRepository localRepository, EventDispatcher eventDispatcher, Log log, List goals )
{
this.container = container;
@ -110,14 +113,26 @@ public ArtifactRepository getLocalRepository()
return localRepository;
}
public Set getRemoteRepositories()
public List getRemoteRepositories()
{
if ( remoteRepositories == null )
List result = null;
if ( project != null )
{
remoteRepositories = RepositoryUtils.mavenToWagon( project.getRepositories() );
List repos = project.getRepositories();
result = new ArrayList( repos.size() );
for ( Iterator it = repos.iterator(); it.hasNext(); )
{
Repository repo = (Repository) it.next();
result.add( new ArtifactRepository( repo.getId(), repo.getUrl() ) );
}
}
else
{
result = Collections.EMPTY_LIST;
}
return remoteRepositories;
return result;
}
public List getGoals()

View File

@ -50,6 +50,7 @@
import org.codehaus.plexus.util.CollectionUtils;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -73,7 +74,7 @@ public class DefaultPluginManager
protected PluginDescriptorBuilder pluginDescriptorBuilder;
protected Set remotePluginRepositories;
protected List remotePluginRepositories;
protected ArtifactFilter artifactFilter;
@ -528,7 +529,7 @@ public void initialize()
"wagon-provider-api", "classworlds"} );
// TODO: move this to be configurable from the Maven component
remotePluginRepositories = new HashSet();
remotePluginRepositories = new ArrayList();
// TODO: needs to be configured from the POM element
remotePluginRepositories.add( new ArtifactRepository( "plugin-repository", "http://repo1.maven.org" ) );

View File

@ -27,6 +27,7 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
@ -34,7 +35,6 @@
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.StringUtils;
@ -54,10 +54,10 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @version $Id$
* @version $Id: DefaultMavenProjectBuilder.java,v 1.37 2005/03/08 01:55:22
* trygvis Exp $
*/
public class DefaultMavenProjectBuilder
extends AbstractLogEnabled
@ -103,8 +103,10 @@ public MavenProject build( File projectDescriptor, ArtifactRepository localRepos
LinkedList lineage = new LinkedList();
Set aggregatedRemoteWagonRepositories = RepositoryUtils.mavenToWagon( superModel.getRepositories() );
MavenProject project = assembleLineage( projectDescriptor, localRepository, lineage,
List aggregatedRemoteWagonRepositories = buildArtifactRepositories( superModel.getRepositories() );
MavenProject project = assembleLineage( projectDescriptor,
localRepository,
lineage,
aggregatedRemoteWagonRepositories );
Model previous = superModel;
@ -144,7 +146,7 @@ public MavenProject build( File projectDescriptor, ArtifactRepository localRepos
if ( resolveDependencies )
{
Set repos = RepositoryUtils.mavenToWagon( project.getRepositories() );
List repos = buildArtifactRepositories( project.getRepositories() );
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this );
@ -177,7 +179,7 @@ public MavenProject build( File projectDescriptor, ArtifactRepository localRepos
}
private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository,
LinkedList lineage, Set aggregatedRemoteWagonRepositories )
LinkedList lineage, List aggregatedRemoteWagonRepositories )
throws ProjectBuildingException
{
Model model = readModel( projectDescriptor );
@ -214,7 +216,7 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
// as we go in order to do this.
// ----------------------------------------------------------------------
aggregatedRemoteWagonRepositories.addAll( RepositoryUtils.mavenToWagon( model.getRepositories() ) );
aggregatedRemoteWagonRepositories.addAll( buildArtifactRepositories( model.getRepositories() ) );
File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories, localRepository );
@ -227,8 +229,24 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
return project;
}
private Model readModel( File file )
throws ProjectBuildingException
private List buildArtifactRepositories( List repositories )
{
List repos = new ArrayList();
for ( Iterator i = repositories.iterator(); i.hasNext(); )
{
Repository mavenRepo = (Repository) i.next();
ArtifactRepository artifactRepo = new ArtifactRepository( mavenRepo.getId(), mavenRepo.getUrl() );
if ( !repos.contains( artifactRepo ) )
{
repos.add( artifactRepo );
}
}
return repos;
}
private Model readModel( File file ) throws ProjectBuildingException
{
try
{
@ -262,7 +280,7 @@ private Model readModel( URL url )
}
}
private File findParentModel( Parent parent, Set remoteArtifactRepositories, ArtifactRepository localRepository )
private File findParentModel( Parent parent, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException
{
Artifact artifact = artifactFactory.createArtifact( parent.getGroupId(), parent.getArtifactId(),

View File

@ -1,67 +0,0 @@
package org.apache.maven.repository;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
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;
import java.util.List;
import java.util.Set;
/**
* @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;
}
/**
* @todo [BP]: when deploying to remote, we want to default the username, etc {@link org.apache.maven.wagon.WagonUtils#getAuthInfo()}, and also setup permissions
* @param mavenRepository
* @return
*/
public static ArtifactRepository mavenRepositoryToWagonRepository( Repository mavenRepository )
{
ArtifactRepository retValue = new ArtifactRepository();
if ( mavenRepository.getUsername() != null )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName( mavenRepository.getUsername() );
authInfo.setPassword( mavenRepository.getPassword() );
authInfo.setPrivateKey( mavenRepository.getPrivateKey() );
authInfo.setPassphrase( mavenRepository.getPassphrase() );
retValue.setAuthenticationInfo( authInfo );
}
retValue.setUrl( mavenRepository.getUrl() );
return retValue;
}
}

View File

@ -1,7 +1,5 @@
package org.apache.maven.util;
import org.apache.maven.model.user.JdkProfile;
import org.apache.maven.model.user.MavenProfile;
import org.apache.maven.model.user.ServerProfile;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Reader;
@ -20,88 +18,31 @@
public final class UserModelUtils
{
public static final String JDK_PROFILE_ENVAR = "maven.jdkVersion";
public static final String MAVEN_PROFILE_ENVAR = "maven.mavenProfileId";
public static final String SERVER_PROFILE_ENVAR = "maven.serverProfileId";
private static final String USER_MODEL_LOCATION = "/.m2/user.xml";
private UserModelUtils()
{
}
public static ServerProfile getActiveServer( UserModel userModel )
public static ServerProfile getServerProfile( UserModel userModel, String serverProfileId )
{
List servers = userModel.getServerProfiles();
ServerProfile result = null;
String serverId = System.getProperty( SERVER_PROFILE_ENVAR );
if ( serverId == null || serverId.trim().length() < 1 )
List serverProfiles = userModel.getServerProfiles();
if ( serverProfiles != null )
{
serverId = userModel.getDefaultProfiles().getServerProfileId();
}
ServerProfile active = null;
for ( Iterator it = servers.iterator(); it.hasNext(); )
for ( Iterator it = serverProfiles.iterator(); it.hasNext(); )
{
ServerProfile server = (ServerProfile) it.next();
if ( serverId.equals( server.getId() ) )
ServerProfile profile = (ServerProfile) it.next();
if ( serverProfileId.equals( profile.getId() ) )
{
active = server;
result = profile;
break;
}
}
return active;
}
public static JdkProfile getActiveJdk( UserModel userModel )
{
List jdks = userModel.getJdkProfiles();
String jdkId = System.getProperty( JDK_PROFILE_ENVAR );
if ( jdkId == null || jdkId.trim().length() < 1 )
{
jdkId = userModel.getDefaultProfiles().getJdkVersion();
}
JdkProfile active = null;
for ( Iterator it = jdks.iterator(); it.hasNext(); )
{
JdkProfile jdk = (JdkProfile) it.next();
if ( jdkId.equals( jdk.getVersion() ) )
{
active = jdk;
break;
}
}
return active;
}
public static MavenProfile getActiveRuntimeProfile( UserModel userModel )
{
List mavenProfiles = userModel.getMavenProfiles();
String mavenProfileId = System.getProperty( MAVEN_PROFILE_ENVAR );
if ( mavenProfileId == null || mavenProfileId.trim().length() < 1 )
{
mavenProfileId = userModel.getDefaultProfiles().getMavenProfileId();
}
MavenProfile active = null;
for ( Iterator it = mavenProfiles.iterator(); it.hasNext(); )
{
MavenProfile mavenProfile = (MavenProfile) it.next();
if ( mavenProfileId.equals( mavenProfile.getId() ) )
{
active = mavenProfile;
break;
}
}
return active;
return result;
}
// TODO: don't throw Exception.
@ -135,6 +76,11 @@ public static UserModel getUserModel() throws Exception
}
}
if ( model == null )
{
model = new UserModel();
}
return model;
}

View File

@ -121,6 +121,15 @@
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<implementation>org.apache.maven.artifact.factory.DefaultArtifactFactory</implementation>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.MavenAuthenticationInfoProvider</implementation>
</component>
<!--
|

View File

@ -15,16 +15,16 @@
import java.util.Collections;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: PluginParameterExpressionEvaluatorTest.java,v 1.5 2005/03/08
* 06:06:21 jdcasey Exp $
*/
public class PluginParameterExpressionEvaluatorTest
extends MavenTestCase
{
private MavenProject project;
protected void setUp()
throws Exception
protected void setUp() throws Exception
{
super.setUp();
@ -33,64 +33,79 @@ protected void setUp()
project = getProject( f );
}
public void testValueExtractionWithAPomValueContainingAPath()
throws Exception
public void testValueExtractionWithAPomValueContainingAPath() throws Exception
{
String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
ArtifactRepository repo = new ArtifactRepository("local", "here");
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
ArtifactRepository repo = new ArtifactRepository( "local", "here" );
PluginManager mgr = (PluginManager) lookup( PluginManager.ROLE );
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, new UserModel(), repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
MavenSession session = new MavenSession( container,
mgr,
new UserModel(),
repo,
new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Build build = new Build();
build.setDirectory(expected.substring(0, expected.length() - "/classes".length()));
build.setDirectory( expected.substring( 0, expected.length() - "/classes".length() ) );
Model model = new Model();
model.setBuild(build);
model.setBuild( build );
MavenProject project = new MavenProject(model);
project.setFile(new File("pom.xml").getCanonicalFile());
MavenProject project = new MavenProject( model );
project.setFile( new File( "pom.xml" ).getCanonicalFile() );
session.setProject(project);
session.setProject( project );
Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", session );
String actual = new File( value.toString() ).getCanonicalPath();
System.out.println("Expected value: " + expected);
System.out.println("Resolved value: " + actual);
System.out.println( "Expected value: " + expected );
System.out.println( "Resolved value: " + actual );
assertEquals( expected, actual );
}
public void testParameterThatIsAComponent()
throws Exception
public void testParameterThatIsAComponent() throws Exception
{
String role = "#component.org.apache.maven.project.MavenProjectBuilder";
ArtifactRepository repo = new ArtifactRepository();
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com" );
PluginManager mgr = (PluginManager) lookup( PluginManager.ROLE );
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, new UserModel(), repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
MavenSession session = new MavenSession( container,
mgr,
new UserModel(),
repo,
new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Object value = PluginParameterExpressionEvaluator.evaluate( role, session );
assertNotNull( value );
}
public void testLocalRepositoryExtraction()
throws Exception
public void testLocalRepositoryExtraction() throws Exception
{
ArtifactRepository repo = new ArtifactRepository("local", "target/repo");
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
ArtifactRepository repo = new ArtifactRepository( "local", "target/repo" );
PluginManager mgr = (PluginManager) lookup( PluginManager.ROLE );
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, new UserModel(), repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
MavenSession session = new MavenSession( container,
mgr,
new UserModel(),
repo,
new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", session );
assertEquals( "local", ((ArtifactRepository)value).getId() );
assertEquals( "local", ((ArtifactRepository) value).getId() );
}
}

View File

@ -18,6 +18,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.MavenMetadataSource;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.factory.DefaultArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@ -31,6 +33,7 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Set;
public class ProjectClasspathArtifactResolver
@ -39,12 +42,14 @@ public class ProjectClasspathArtifactResolver
private static class Source
extends MavenMetadataSource
{
private ArtifactFactory artifactFactory = new DefaultArtifactFactory();
public Source( ArtifactResolver artifactResolver )
{
super( artifactResolver );
}
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories )
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
MavenXpp3Reader reader = new MavenXpp3Reader();
@ -63,7 +68,7 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
}
}
public Artifact resolve( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository )
public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
return artifact;
@ -74,26 +79,21 @@ protected void setLocalRepositoryPath( Artifact artifact, ArtifactRepository loc
{
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source, ArtifactFilter filter )
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
{
return super.resolveTransitively( artifacts, remoteRepositories, localRepository, new Source( this ), filter );
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
{
return super.resolveTransitively( artifacts, remoteRepositories, localRepository, new Source( this ) );
}
public ArtifactResolutionResult resolveTransitively( Artifact artifact, Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
{
return super.resolveTransitively( artifact, remoteRepositories, localRepository, new Source( this ) );
}

View File

@ -3,6 +3,15 @@
<component>
<role>org.apache.maven.artifact.ArtifactResolver</role>
<implementation>org.apache.maven.project.ProjectClasspathArtifactResolver</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
<field-name>artifactHandlerManager</field-name>
</requirement>
</requirements>
</component>
</components>
</plexus>

View File

@ -51,7 +51,7 @@ public class MBoot
// ----------------------------------------------------------------------
String[] plexusDeps = new String[] {
"classworlds/jars/classworlds-1.1-SNAPSHOT.jar",
"classworlds/jars/classworlds-1.1-alpha-1.jar",
"plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar" };
String[] pluginGeneratorDeps = new String[] {
@ -68,7 +68,7 @@ public class MBoot
// ----------------------------------------------------------------------
String[] modelloDeps = new String[] {
"classworlds/jars/classworlds-1.1-SNAPSHOT.jar",
"classworlds/jars/classworlds-1.1-alpha-1.jar",
//"plexus/jars/plexus-container-api-1.0-alpha-1-SNAPSHOT.jar",
"plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar",
//"plexus/jars/plexus-utils-1.0-alpha-1-SNAPSHOT.jar",
@ -253,6 +253,7 @@ public void run( String[] args ) throws Exception
if ( online )
{
checkMBootDeps();
checkModelloDeps();
}
// Install maven-components POM
@ -712,6 +713,13 @@ private void checkMBootDeps() throws Exception
downloader.downloadDependencies( mbootDependencies );
}
private void checkModelloDeps() throws Exception
{
System.out.println( "Checking for Modello's dependencies ..." );
downloader.downloadDependencies( Arrays.asList( modelloDeps ) );
}
private void createJar( String classes, String buildDir ) throws Exception
{
JarMojo jarMojo = new JarMojo();

View File

@ -26,12 +26,11 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.model.Repository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.repository.RepositoryUtils;
import java.io.File;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
* @version $Id$
*/
public abstract class AbstractDeployMojo
@ -43,8 +42,7 @@ protected boolean isPom()
return false;
}
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
MavenProject project = (MavenProject) request.getParameter( "project" );
@ -54,8 +52,7 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
if ( distributionManagement == null )
{
String msg = "Deployment failed: distributionManagement element" +
" was not specified in the pom";
String msg = "Deployment failed: distributionManagement element" + " was not specified in the pom";
throw new Exception( msg );
}
@ -63,13 +60,12 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
if ( repository == null )
{
String msg = "Deployment failed: repository element" +
" was not specified in the pom inside" +
" distributionManagement element";
String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
+ " distributionManagement element";
throw new Exception( msg );
}
ArtifactRepository deploymentRepository = RepositoryUtils.mavenRepositoryToWagonRepository( repository );
ArtifactRepository deploymentRepository = new ArtifactRepository( repository.getId(), repository.getUrl() );
// Deploy the POM
Artifact pomArtifact = new DefaultArtifact( project.getGroupId(),
@ -82,7 +78,7 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
artifactDeployer.deploy( pom, pomArtifact, deploymentRepository );
//Deploy artifact
if ( ! isPom() )
if ( !isPom() )
{
Artifact artifact = new DefaultArtifact( project.getGroupId(),
project.getArtifactId(),

View File

@ -16,62 +16,45 @@
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject;
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.model.Repository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
/**
* @goal deploy
*
* @description deploys a JAR to remote repository
*
* @parameter
* name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
*
* @parameter
* name="deployer"
* @parameter name="project" type="org.apache.maven.project.MavenProject"
* required="true" validator="" expression="#project" description=""
* @parameter name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true"
* validator=""
* required="true" validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
*/
public class JarDeployMojo
extends AbstractPlugin
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" );
//@todo this will be duplicated in case of every mojo which implements deploy goal
//@todo this will be duplicated in case of every mojo which implements
// deploy goal
// this should be pushed into the ArtifactDeployer component
DistributionManagement distributionManagement = project.getDistributionManagement();
if ( distributionManagement == null )
{
String msg = "Deployment failed: distributionManagement element" +
" was not specified in the pom";
String msg = "Deployment failed: distributionManagement element" + " was not specified in the pom";
throw new Exception( msg );
}
@ -79,15 +62,12 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
if ( repository == null )
{
String msg = "Deployment failed: repository element" +
" was not specified in the pom inside" +
" distributionManagement element";
String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
+ " distributionManagement element";
throw new Exception( msg );
}
ArtifactRepository deploymentRepository =
RepositoryUtils.mavenRepositoryToWagonRepository( repository );
ArtifactRepository deploymentRepository = new ArtifactRepository( repository.getId(), repository.getUrl() );
Artifact artifact = new DefaultArtifact( project.getGroupId(),
project.getArtifactId(),

View File

@ -20,17 +20,24 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositoryUtils;
import java.io.File;
/**
* @goal deploy
* @description deploys a pom to remote repository
* @parameter name="project" type="org.apache.maven.project.MavenProject"
* required="true" validator="" expression="#project" description=""
* @parameter name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true" validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
* @parameter name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
@ -60,11 +67,12 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
// TODO: simple failure response
throw new Exception( "distributionManagement is required for deployment" );
}
Repository repo = project.getDistributionManagement().getRepository();
ArtifactRepository deploymentRepository = new ArtifactRepository( repo.getId(), repo.getUrl() );
ArtifactRepository deploymentRepository = RepositoryUtils.mavenRepositoryToWagonRepository(
project.getDistributionManagement().getRepository() );
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
Artifact artifact = new DefaultArtifact( project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
"pom" );
File pom = new File( project.getFile().getParentFile(), "pom.xml" );

View File

@ -97,9 +97,9 @@
<type>String</type>
</field>
<field>
<name>passphrase</name>
<name>password</name>
<version>4.0.0</version>
<description><![CDATA[The passphrase used to access this server with this config.]]></description>
<description><![CDATA[The password used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
@ -108,6 +108,12 @@
<description><![CDATA[The private key location used to access this server with this config.]]></description>
<type>String</type>
</field>
<field>
<name>passphrase</name>
<version>4.0.0</version>
<description><![CDATA[The passphrase used to access this server with a private key in this config.]]></description>
<type>String</type>
</field>
</fields>
</class>
<class>