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

View File

@ -19,7 +19,7 @@ package org.apache.maven.artifact;
import java.io.File; 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$ * @version $Id$
*/ */
public class DefaultArtifact public class DefaultArtifact
@ -161,4 +161,4 @@ public class DefaultArtifact
return this.groupId.equals( other.getGroupId() ) && this.artifactId.equals( other.getArtifactId() ) && this.version.equals( return this.groupId.equals( other.getGroupId() ) && this.artifactId.equals( other.getArtifactId() ) && this.version.equals(
other.getVersion() ) && this.type.equals( other.getType() ); other.getVersion() ) && this.type.equals( other.getType() );
} }
} }

View File

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

View File

@ -25,31 +25,27 @@ import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.events.TransferListener;
import java.io.File; 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$ * @version $Id$
*/ */
public interface WagonManager public interface WagonManager
{ {
String ROLE = WagonManager.class.getName(); String ROLE = WagonManager.class.getName();
Wagon getWagon( String protocol ) Wagon getWagon( String protocol ) throws UnsupportedProtocolException;
throws UnsupportedProtocolException;
// TODO: don't throw exception // TODO: don't throw exception
void releaseWagon( Wagon wagon ) void releaseWagon( Wagon wagon ) throws Exception;
throws Exception;
void get( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository ) void get( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws TransferFailedException; throws TransferFailedException;
// TODO: don't throw exception // TODO: don't throw exception
void put( File source, Artifact artifact, ArtifactRepository deploymentRepository ) void put( File source, Artifact artifact, ArtifactRepository deploymentRepository ) throws Exception;
throws Exception;
void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts ); void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
void setDownloadMonitor( TransferListener downloadMonitor ); void setDownloadMonitor( TransferListener downloadMonitor );

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.metadata;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Set; import java.util.Set;
// Currently the only thing we need from the artifact metadata source is the // Currently the only thing we need from the artifact metadata source is the
@ -27,11 +28,11 @@ import java.util.Set;
// the artifact we may wish to provide in this layer. jvz. // 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$ * @version $Id$
*/ */
public interface ArtifactMetadataSource public interface ArtifactMetadataSource
{ {
Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories ) Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException; throws ArtifactMetadataRetrievalException;
} }

View File

@ -19,71 +19,39 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.wagon.repository.Repository; import org.apache.maven.wagon.repository.Repository;
/** /**
* This class is an abstraction of the location from/to resources * This class is an abstraction of the location from/to resources can be
* can be transfered. * transfered.
* *
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$ * @version $Id$
*/ */
public class ArtifactRepository public class ArtifactRepository
extends Repository extends Repository
{ {
public ArtifactRepository() // public ArtifactRepository()
{ // {
} // }
public ArtifactRepository( String id, String url) public ArtifactRepository( String id, String url )
{ {
super( id, url ); super( id, url );
} }
/* /*
private String layout; * private String layout; public String getLayout() { if ( layout == null ) {
* return "${groupId}/${type}s/${artifactId}-${version}.${extension}"; }
public String getLayout() * return layout; } public String artifactPath( Artifact artifact ) { return
{ * interpolateLayout( artifact.getGroupId(), artifact.getArtifactId(),
if ( layout == null ) * artifact.getVersion(), artifact.getType(), artifact.getExtension() ); }
{ * public String fullArtifactPath( Artifact artifact ) { return getBasedir() +
return "${groupId}/${type}s/${artifactId}-${version}.${extension}"; * "/" + artifactPath( artifact ); } public String artifactUrl( Artifact
} * artifact ) { return getUrl() + "/" + artifactPath( artifact ); } private
* String interpolateLayout( String groupId, String artifactId, String
return layout; * version, String type, String extension ) { String layout = getLayout();
} * layout = StringUtils.replace( layout, "${groupId}", groupId ); layout =
* StringUtils.replace( layout, "${artifactId}", artifactId ); layout =
public String artifactPath( Artifact artifact ) * StringUtils.replace( layout, "${type}", type ); layout =
{ * StringUtils.replace( layout, "${version}", version ); layout =
return interpolateLayout( artifact.getGroupId(), * StringUtils.replace( layout, "${extension}", extension ); return layout; }
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; package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact; 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.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
* I want to use it for hidding the fact that sometime artifact must * I want to use it for hidding the fact that sometime artifact must be
* be downloaded. I am just asking LocalRepository for given artifact * downloaded. I am just asking LocalRepository for given artifact and I don't
* and I don't care if it is alredy there or how it will get there. * 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$ * @version $Id$
*/ */
public interface ArtifactResolver public interface ArtifactResolver
{ {
static String ROLE = ArtifactResolver.class.getName(); static String ROLE = ArtifactResolver.class.getName();
Artifact resolve( Artifact artifact, Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
Set remoteRepositories,
ArtifactRepository localRepository )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Artifact artifact,
Set remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException; throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException;
Set resolve( Set artifacts,
Set remoteRepositories, Set resolve( Set artifacts, List remoteRepositories, ArtifactRepository localRepository )
ArtifactRepository localRepository )
throws ArtifactResolutionException; throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
Set remoteRepositories, ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException;
ArtifactRepository localRepository,
ArtifactMetadataSource source ) ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException; throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, void addArtifactRequestTransformation(
Set remoteRepositories, org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation requestTransformation );
ArtifactRepository localRepository,
ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException;
void addArtifactRequestTransformation( org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation requestTransformation ); }
}

View File

@ -21,7 +21,8 @@ import java.util.Map;
import java.util.Set; 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 public class DefaultArtifactResolver
extends AbstractArtifactComponent extends AbstractArtifactComponent
@ -32,7 +33,7 @@ public class DefaultArtifactResolver
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private List requestTransformations; private List requestTransformations;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Components // Components
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -43,9 +44,7 @@ public class DefaultArtifactResolver
// Implementation // Implementation
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public Artifact resolve( Artifact artifact, public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
Set remoteRepositories,
ArtifactRepository localRepository )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -54,7 +53,8 @@ public class DefaultArtifactResolver
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Check for the existence of the artifact in the specified local // 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. // for resolution has been satisfied.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -83,19 +83,19 @@ public class DefaultArtifactResolver
private static final String LS = System.getProperty( "line.separator" ); 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(); StringBuffer sb = new StringBuffer();
sb.append( "The artifact is not present locally as:" ) sb.append( "The artifact is not present locally as:" )
.append( LS ) .append( LS )
.append( LS ) .append( LS )
.append( artifact.getPath() ) .append( artifact.getPath() )
.append( LS ) .append( LS )
.append( LS ) .append( LS )
.append( "or in any of the specified remote repositories:" ) .append( "or in any of the specified remote repositories:" )
.append( LS ) .append( LS )
.append( LS ); .append( LS );
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{ {
@ -111,9 +111,7 @@ public class DefaultArtifactResolver
return sb.toString(); return sb.toString();
} }
public Set resolve( Set artifacts, public Set resolve( Set artifacts, List remoteRepositories, ArtifactRepository localRepository )
Set remoteRepositories,
ArtifactRepository localRepository )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
Set resolvedArtifacts = new HashSet(); Set resolvedArtifacts = new HashSet();
@ -134,22 +132,15 @@ public class DefaultArtifactResolver
// Transitive modes // Transitive modes
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public ArtifactResolutionResult resolveTransitively( Set artifacts, public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
Set remoteRepositories, ArtifactRepository localRepository, ArtifactMetadataSource source, ArtifactFilter filter )
ArtifactRepository localRepository,
ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
ArtifactResolutionResult artifactResolutionResult; ArtifactResolutionResult artifactResolutionResult;
try try
{ {
artifactResolutionResult = collect( artifacts, artifactResolutionResult = collect( artifacts, localRepository, remoteRepositories, source, filter );
localRepository,
remoteRepositories,
source,
filter );
} }
catch ( TransitiveArtifactResolutionException e ) catch ( TransitiveArtifactResolutionException e )
{ {
@ -164,34 +155,24 @@ public class DefaultArtifactResolver
return artifactResolutionResult; return artifactResolutionResult;
} }
public ArtifactResolutionResult resolveTransitively( Set artifacts, public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
Set remoteRepositories, ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{ {
return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null ); return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null );
} }
public ArtifactResolutionResult resolveTransitively( Artifact artifact, public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
Set remoteRepositories, ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
{ {
return resolveTransitively( Collections.singleton( artifact ), remoteRepositories, localRepository, source ); return resolveTransitively( Collections.singleton( artifact ), remoteRepositories, localRepository, source );
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private ArtifactResolutionResult collect( Set artifacts, private ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository,
ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter )
Set remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter )
throws TransitiveArtifactResolutionException throws TransitiveArtifactResolutionException
{ {
ArtifactResolutionResult result = new ArtifactResolutionResult(); ArtifactResolutionResult result = new ArtifactResolutionResult();
@ -246,10 +227,12 @@ public class DefaultArtifactResolver
} }
catch ( ArtifactMetadataRetrievalException e ) 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 ); queue.add( referencedDependencies );
} }
} }
@ -257,7 +240,8 @@ public class DefaultArtifactResolver
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// the dependencies list is keyed by groupId+artifactId+type // 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(); Map artifactResult = result.getArtifacts();
@ -303,4 +287,4 @@ public class DefaultArtifactResolver
{ {
} }
} }

View File

@ -3,8 +3,8 @@ package org.apache.maven.artifact.resolver.transform;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2004 The Apache Software Foundation.
@ -23,8 +23,9 @@ 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$ * @version $Id: ArtifactRequestTransformation.java,v 1.1 2005/03/03 15:37:25
* jvanzyl Exp $
*/ */
public interface ArtifactRequestTransformation public interface ArtifactRequestTransformation
{ {
@ -33,13 +34,11 @@ public interface ArtifactRequestTransformation
/** /**
* Take in a artifact and return the transformed artifact. If no * Take in a artifact and return the transformed artifact. If no
* transformation has occured the original artifact is returned. * transformation has occured the original artifact is returned.
* *
* @param artifact Artifact to be transformed. * @param artifact
* Artifact to be transformed.
* @return The transformed Artifact * @return The transformed Artifact
*/ */
Artifact transform( Artifact artifact, Artifact transform( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories, Map parameters )
ArtifactRepository localRepository,
Set remoteRepositories,
Map parameters )
throws Exception; throws Exception;
} }

View File

@ -9,23 +9,21 @@ import java.io.File;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
/** /**
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a> * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka </a>
* @version $Id$ * @version $Id: SnapshotRequestTransformation.java,v 1.1 2005/03/03 15:37:25
* jvanzyl Exp $
*/ */
public class SnapshotRequestTransformation public class SnapshotRequestTransformation
implements ArtifactRequestTransformation implements ArtifactRequestTransformation
{ {
private ArtifactResolver artifactResolver; private ArtifactResolver artifactResolver;
public Artifact transform( Artifact artifact, public Artifact transform( Artifact artifact, ArtifactRepository localRepository, List repositories, Map parameters )
ArtifactRepository localRepository,
Set repositories,
Map parameters )
throws Exception throws Exception
{ {
Date localVersion = getLocalVersion( artifact, localRepository ); Date localVersion = getLocalVersion( artifact, localRepository );
@ -34,7 +32,7 @@ public class SnapshotRequestTransformation
if ( remoteVersion != null ) if ( remoteVersion != null )
{ {
//if local version is unknown (null) it means that //if local version is unknown (null) it means that
//we don't have this file locally. so we will be happy //we don't have this file locally. so we will be happy
// to have any snapshot. // to have any snapshot.
// we wil download in two cases: // we wil download in two cases:
@ -49,7 +47,8 @@ public class SnapshotRequestTransformation
// We can change the strategy which is used here later on // We can change the strategy which is used here later on
// @todo we will delete old file first. // @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 // fetch to temprary file and replace the old file with the new
// one once download was finished // one once download was finished
@ -80,7 +79,7 @@ public class SnapshotRequestTransformation
//return new File( localRepository.fullArtifactPath( artifact ) ); //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 throws Exception
{ {
Date retValue = null; Date retValue = null;
@ -119,7 +118,8 @@ public class SnapshotRequestTransformation
if ( retValue == null ) 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(); File file = artifact.getFile();
@ -129,12 +129,10 @@ public class SnapshotRequestTransformation
//@todo we should "normalize" the time. //@todo we should "normalize" the time.
/*TimeZone gmtTimeZone = TimeZone.getTimeZone( "GMT" ); /*
* TimeZone gmtTimeZone = TimeZone.getTimeZone( "GMT" );
TimeZone userTimeZone = TimeZone.getDefault(); * TimeZone userTimeZone = TimeZone.getDefault(); long diff =
*/
long diff =
*/
} }
} }
@ -163,18 +161,17 @@ public class SnapshotRequestTransformation
return retValue; return retValue;
} }
public static Date parseTimestamp ( String timestamp ) public static Date parseTimestamp( String timestamp ) throws ParseException
throws ParseException
{ {
Date retValue = getFormatter().parse( timestamp ); Date retValue = getFormatter().parse( timestamp );
return retValue; return retValue;
} }
public static String getTimestamp ( Date snapshotVersion ) public static String getTimestamp( Date snapshotVersion )
{ {
String retValue = getFormatter().format( snapshotVersion ); String retValue = getFormatter().format( snapshotVersion );
return retValue; return retValue;
} }
} }

View File

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

View File

@ -25,20 +25,20 @@ import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.HashSet; import java.util.ArrayList;
import java.util.Set; import java.util.List;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$ * @version $Id: ArtifactComponentTestCase.java,v 1.5 2004/10/23 13:33:59
* jvanzyl Exp $
*/ */
public abstract class ArtifactComponentTestCase public abstract class ArtifactComponentTestCase
extends PlexusTestCase extends PlexusTestCase
{ {
protected ArtifactHandlerManager artifactHandlerManager; protected ArtifactHandlerManager artifactHandlerManager;
protected void setUp() protected void setUp() throws Exception
throws Exception
{ {
super.setUp(); super.setUp();
@ -47,62 +47,50 @@ public abstract class ArtifactComponentTestCase
protected abstract String component(); protected abstract String component();
/** /** Return an existing file, not a directory - causes creation to fail. */
* Return an existing file, not a directory - causes creation to fail. protected ArtifactRepository badLocalRepository() throws IOException
*/
protected ArtifactRepository badLocalRepository()
throws IOException
{ {
ArtifactRepository localRepository = new ArtifactRepository();
String path = "target/test-classes/repositories/" + component() + "/bad-local-repository"; String path = "target/test-classes/repositories/" + component() + "/bad-local-repository";
File f = new File( getBasedir(), path ); File f = new File( getBasedir(), path );
f.createNewFile(); f.createNewFile();
localRepository.setUrl( "file://" + f.getPath() ); ArtifactRepository localRepository = new ArtifactRepository( "test", "file://" + f.getPath() );
return localRepository; return localRepository;
} }
protected ArtifactRepository localRepository() protected ArtifactRepository localRepository()
{ {
ArtifactRepository localRepository = new ArtifactRepository();
String path = "target/test-classes/repositories/" + component() + "/local-repository"; String path = "target/test-classes/repositories/" + component() + "/local-repository";
File f = new File( getBasedir(), path ); File f = new File( getBasedir(), path );
localRepository.setUrl( "file://" + f.getPath() ); ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" + f.getPath() );
return localRepository; return localRepository;
} }
protected ArtifactRepository remoteRepository() protected ArtifactRepository remoteRepository()
{ {
ArtifactRepository repository = new ArtifactRepository();
String path = "target/test-classes/repositories/" + component() + "/remote-repository"; String path = "target/test-classes/repositories/" + component() + "/remote-repository";
File f = new File( getBasedir(), path ); File f = new File( getBasedir(), path );
repository.setUrl( "file://" + f.getPath() ); ArtifactRepository repository = new ArtifactRepository( "test", "file://" + f.getPath() );
return repository; return repository;
} }
protected ArtifactRepository badRemoteRepository() protected ArtifactRepository badRemoteRepository()
{ {
ArtifactRepository repository = new ArtifactRepository(); ArtifactRepository repository = new ArtifactRepository( "test", "http://foo.bar/repository" );
repository.setUrl( "http://foo.bar/repository" );
return repository; return repository;
} }
protected void assertRemoteArtifactPresent( Artifact artifact ) protected void assertRemoteArtifactPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
throws ArtifactHandlerNotFoundException
{ {
String path = artifactHandlerManager.path( artifact ); String path = artifactHandlerManager.path( artifact );
@ -114,8 +102,7 @@ public abstract class ArtifactComponentTestCase
} }
} }
protected void assertLocalArtifactPresent( Artifact artifact ) protected void assertLocalArtifactPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
throws ArtifactHandlerNotFoundException
{ {
String path = artifactHandlerManager.path( artifact ); String path = artifactHandlerManager.path( artifact );
@ -127,8 +114,7 @@ public abstract class ArtifactComponentTestCase
} }
} }
protected void assertRemoteArtifactNotPresent( Artifact artifact ) protected void assertRemoteArtifactNotPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
throws ArtifactHandlerNotFoundException
{ {
String path = artifactHandlerManager.path( artifact ); String path = artifactHandlerManager.path( artifact );
@ -140,8 +126,7 @@ public abstract class ArtifactComponentTestCase
} }
} }
protected void assertLocalArtifactNotPresent( Artifact artifact ) protected void assertLocalArtifactNotPresent( Artifact artifact ) throws ArtifactHandlerNotFoundException
throws ArtifactHandlerNotFoundException
{ {
String path = artifactHandlerManager.path( artifact ); String path = artifactHandlerManager.path( artifact );
@ -157,9 +142,9 @@ public abstract class ArtifactComponentTestCase
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
protected Set remoteRepositories() protected List remoteRepositories()
{ {
Set remoteRepositories = new HashSet(); List remoteRepositories = new ArrayList();
remoteRepositories.add( remoteRepository() ); remoteRepositories.add( remoteRepository() );
@ -170,8 +155,7 @@ public abstract class ArtifactComponentTestCase
// Test artifact generation for unit tests // Test artifact generation for unit tests
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
protected Artifact createLocalArtifact( String artifactId, String version ) protected Artifact createLocalArtifact( String artifactId, String version ) throws Exception
throws Exception
{ {
Artifact artifact = createArtifact( artifactId, version ); Artifact artifact = createArtifact( artifactId, version );
@ -180,8 +164,7 @@ public abstract class ArtifactComponentTestCase
return artifact; return artifact;
} }
protected Artifact createRemoteArtifact( String artifactId, String version ) protected Artifact createRemoteArtifact( String artifactId, String version ) throws Exception
throws Exception
{ {
Artifact artifact = createArtifact( artifactId, version ); Artifact artifact = createArtifact( artifactId, version );
@ -190,20 +173,17 @@ public abstract class ArtifactComponentTestCase
return artifact; return artifact;
} }
protected void createLocalArtifact( Artifact artifact ) protected void createLocalArtifact( Artifact artifact ) throws Exception
throws Exception
{ {
createArtifact( artifact, localRepository() ); createArtifact( artifact, localRepository() );
} }
protected void createRemoteArtifact( Artifact artifact ) protected void createRemoteArtifact( Artifact artifact ) throws Exception
throws Exception
{ {
createArtifact( artifact, remoteRepository() ); createArtifact( artifact, remoteRepository() );
} }
protected void createArtifact( Artifact artifact, ArtifactRepository repository ) protected void createArtifact( Artifact artifact, ArtifactRepository repository ) throws Exception
throws Exception
{ {
String path = artifactHandlerManager.path( artifact ); String path = artifactHandlerManager.path( artifact );
@ -228,7 +208,7 @@ public abstract class ArtifactComponentTestCase
protected Artifact createArtifact( String artifactId, String version, String type ) 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 ) protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
@ -236,14 +216,12 @@ public abstract class ArtifactComponentTestCase
return new DefaultArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, type, type ); return new DefaultArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, type, type );
} }
protected void deleteLocalArtifact( Artifact artifact ) protected void deleteLocalArtifact( Artifact artifact ) throws Exception
throws Exception
{ {
deleteArtifact( artifact, localRepository() ); deleteArtifact( artifact, localRepository() );
} }
protected void deleteArtifact( Artifact artifact, ArtifactRepository repository ) protected void deleteArtifact( Artifact artifact, ArtifactRepository repository ) throws Exception
throws Exception
{ {
String path = artifactHandlerManager.path( artifact ); 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 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactComponentTestCase; import org.apache.maven.artifact.ArtifactComponentTestCase;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; 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. // 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 // 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 // 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; private ArtifactResolver artifactResolver;
protected void setUp() protected void setUp() throws Exception
throws Exception
{ {
super.setUp(); super.setUp();
@ -52,8 +59,7 @@ public class ArtifactResolverTest
return "resolver"; return "resolver";
} }
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception
throws Exception
{ {
Artifact a = createLocalArtifact( "a", "1.0" ); Artifact a = createLocalArtifact( "a", "1.0" );
@ -73,8 +79,7 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( b ); assertLocalArtifactPresent( b );
} }
public void testResolutionOfASetOfArtifactsWhereTheArtifactsArePresentInTheLocalRepository() public void testResolutionOfASetOfArtifactsWhereTheArtifactsArePresentInTheLocalRepository() throws Exception
throws Exception
{ {
Set artifacts = new HashSet(); Set artifacts = new HashSet();
@ -140,7 +145,7 @@ public class ArtifactResolverTest
ArtifactMetadataSource mds = new ArtifactMetadataSource() 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(); Set dependencies = new HashSet();
@ -178,7 +183,7 @@ public class ArtifactResolverTest
ArtifactMetadataSource mds = new ArtifactMetadataSource() 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(); Set dependencies = new HashSet();
@ -226,7 +231,7 @@ public class ArtifactResolverTest
Artifact l = createRemoteArtifact( "l", "1.0" ); Artifact l = createRemoteArtifact( "l", "1.0" );
deleteLocalArtifact( l ); deleteLocalArtifact( l );
Set repositories = new HashSet(); List repositories = new ArrayList();
repositories.add( remoteRepository() ); repositories.add( remoteRepository() );
repositories.add( badRemoteRepository() ); 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> <role-hint>c</role-hint>
<implementation>org.apache.maven.artifact.manager.WagonC</implementation> <implementation>org.apache.maven.artifact.manager.WagonC</implementation>
</component> </component>
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components> </components>
</plexus> </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.MavenProject;
import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuilder;
import java.io.FileReader; import java.io.FileReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set; 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$ * @version $Id$
*/ */
public class MavenMetadataSource public class MavenMetadataSource
implements ArtifactMetadataSource implements ArtifactMetadataSource
{ {
private MavenProjectBuilder mavenProjectBuilder; private MavenProjectBuilder mavenProjectBuilder;
private ArtifactResolver artifactResolver; private ArtifactResolver artifactResolver;
// TODO: configure? // TODO: configure?
@ -63,7 +67,7 @@ public class MavenMetadataSource
this.mavenProjectBuilder = projectBuilder; this.mavenProjectBuilder = projectBuilder;
} }
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set remoteRepositories ) public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{ {
Set artifacts; Set artifacts;
@ -96,7 +100,7 @@ public class MavenMetadataSource
} }
catch ( Exception e ) catch ( Exception e )
{ {
throw new ArtifactMetadataRetrievalException( "Cannot read artifact source: " + metadataArtifact.getFile(), throw new ArtifactMetadataRetrievalException( "Cannot read artifact source: " + metadataArtifact.getPath(),
e ); e );
} }
return artifacts; 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 @@ package org.apache.maven.execution;
*/ */
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.model.user.UserModel; import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.Log; import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.dag.CycleDetectedException; import org.codehaus.plexus.util.dag.CycleDetectedException;
@ -31,6 +31,9 @@ import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter; import org.codehaus.plexus.util.dag.TopologicalSorter;
import org.codehaus.plexus.util.dag.Vertex; 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.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -65,13 +68,13 @@ public class MavenSession
private final UserModel userModel; private final UserModel userModel;
public MavenSession( PlexusContainer container, PluginManager pluginManager, UserModel userModel, ArtifactRepository localRepository, public MavenSession( PlexusContainer container, PluginManager pluginManager, UserModel userModel,
EventDispatcher eventDispatcher, Log log, List goals ) ArtifactRepository localRepository, EventDispatcher eventDispatcher, Log log, List goals )
{ {
this.container = container; this.container = container;
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
this.userModel = userModel; this.userModel = userModel;
this.localRepository = localRepository; this.localRepository = localRepository;
@ -84,7 +87,7 @@ public class MavenSession
this.goals = goals; this.goals = goals;
} }
public PlexusContainer getContainer() public PlexusContainer getContainer()
{ {
return container; return container;
@ -110,14 +113,26 @@ public class MavenSession
return localRepository; 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() public List getGoals()
@ -148,7 +163,7 @@ public class MavenSession
{ {
return log; return log;
} }
public UserModel getUserModel() public UserModel getUserModel()
{ {
return userModel; return userModel;

View File

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

View File

@ -27,6 +27,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Parent; import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler; import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector; import org.apache.maven.project.injection.ModelDefaultsInjector;
@ -34,7 +35,6 @@ import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
@ -54,10 +54,10 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; 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 public class DefaultMavenProjectBuilder
extends AbstractLogEnabled extends AbstractLogEnabled
@ -103,8 +103,10 @@ public class DefaultMavenProjectBuilder
LinkedList lineage = new LinkedList(); LinkedList lineage = new LinkedList();
Set aggregatedRemoteWagonRepositories = RepositoryUtils.mavenToWagon( superModel.getRepositories() ); List aggregatedRemoteWagonRepositories = buildArtifactRepositories( superModel.getRepositories() );
MavenProject project = assembleLineage( projectDescriptor, localRepository, lineage, MavenProject project = assembleLineage( projectDescriptor,
localRepository,
lineage,
aggregatedRemoteWagonRepositories ); aggregatedRemoteWagonRepositories );
Model previous = superModel; Model previous = superModel;
@ -144,7 +146,7 @@ public class DefaultMavenProjectBuilder
if ( resolveDependencies ) if ( resolveDependencies )
{ {
Set repos = RepositoryUtils.mavenToWagon( project.getRepositories() ); List repos = buildArtifactRepositories( project.getRepositories() );
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this ); MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this );
@ -177,7 +179,7 @@ public class DefaultMavenProjectBuilder
} }
private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository, private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository,
LinkedList lineage, Set aggregatedRemoteWagonRepositories ) LinkedList lineage, List aggregatedRemoteWagonRepositories )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model model = readModel( projectDescriptor ); Model model = readModel( projectDescriptor );
@ -214,7 +216,7 @@ public class DefaultMavenProjectBuilder
// as we go in order to do this. // 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 ); File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories, localRepository );
@ -227,8 +229,24 @@ public class DefaultMavenProjectBuilder
return project; return project;
} }
private Model readModel( File file ) private List buildArtifactRepositories( List repositories )
throws ProjectBuildingException {
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 try
{ {
@ -262,7 +280,7 @@ public class DefaultMavenProjectBuilder
} }
} }
private File findParentModel( Parent parent, Set remoteArtifactRepositories, ArtifactRepository localRepository ) private File findParentModel( Parent parent, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Artifact artifact = artifactFactory.createArtifact( parent.getGroupId(), parent.getArtifactId(), 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; 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.ServerProfile;
import org.apache.maven.model.user.UserModel; import org.apache.maven.model.user.UserModel;
import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Reader; import org.apache.maven.model.user.io.xpp3.MavenUserModelXpp3Reader;
@ -20,88 +18,31 @@ import java.util.List;
public final class UserModelUtils 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 static final String USER_MODEL_LOCATION = "/.m2/user.xml";
private UserModelUtils() 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 ); List serverProfiles = userModel.getServerProfiles();
if ( serverId == null || serverId.trim().length() < 1 ) if ( serverProfiles != null )
{ {
serverId = userModel.getDefaultProfiles().getServerProfileId(); for ( Iterator it = serverProfiles.iterator(); it.hasNext(); )
}
ServerProfile active = null;
for ( Iterator it = servers.iterator(); it.hasNext(); )
{
ServerProfile server = (ServerProfile) it.next();
if ( serverId.equals( server.getId() ) )
{ {
active = server; ServerProfile profile = (ServerProfile) it.next();
break; if ( serverProfileId.equals( profile.getId() ) )
{
result = profile;
break;
}
} }
} }
return active; return result;
}
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;
} }
// TODO: don't throw Exception. // TODO: don't throw Exception.
@ -135,6 +76,11 @@ public final class UserModelUtils
} }
} }
if ( model == null )
{
model = new UserModel();
}
return model; return model;
} }

View File

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

View File

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

View File

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

View File

@ -3,6 +3,15 @@
<component> <component>
<role>org.apache.maven.artifact.ArtifactResolver</role> <role>org.apache.maven.artifact.ArtifactResolver</role>
<implementation>org.apache.maven.project.ProjectClasspathArtifactResolver</implementation> <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> </component>
</components> </components>
</plexus> </plexus>

View File

@ -51,7 +51,7 @@ public class MBoot
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
String[] plexusDeps = new String[] { 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" }; "plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar" };
String[] pluginGeneratorDeps = new String[] { String[] pluginGeneratorDeps = new String[] {
@ -68,7 +68,7 @@ public class MBoot
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
String[] modelloDeps = new String[] { 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-api-1.0-alpha-1-SNAPSHOT.jar",
"plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar", "plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar",
//"plexus/jars/plexus-utils-1.0-alpha-1-SNAPSHOT.jar", //"plexus/jars/plexus-utils-1.0-alpha-1-SNAPSHOT.jar",
@ -253,6 +253,7 @@ public class MBoot
if ( online ) if ( online )
{ {
checkMBootDeps(); checkMBootDeps();
checkModelloDeps();
} }
// Install maven-components POM // Install maven-components POM
@ -712,6 +713,13 @@ public class MBoot
downloader.downloadDependencies( mbootDependencies ); 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 private void createJar( String classes, String buildDir ) throws Exception
{ {
JarMojo jarMojo = new JarMojo(); JarMojo jarMojo = new JarMojo();

View File

@ -26,12 +26,11 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.DistributionManagement;
import org.apache.maven.repository.RepositoryUtils;
import java.io.File; 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$ * @version $Id$
*/ */
public abstract class AbstractDeployMojo public abstract class AbstractDeployMojo
@ -43,8 +42,7 @@ public abstract class AbstractDeployMojo
return false; return false;
} }
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
throws Exception
{ {
MavenProject project = (MavenProject) request.getParameter( "project" ); MavenProject project = (MavenProject) request.getParameter( "project" );
@ -54,8 +52,7 @@ public abstract class AbstractDeployMojo
if ( distributionManagement == null ) if ( distributionManagement == null )
{ {
String msg = "Deployment failed: distributionManagement element" + String msg = "Deployment failed: distributionManagement element" + " was not specified in the pom";
" was not specified in the pom";
throw new Exception( msg ); throw new Exception( msg );
} }
@ -63,26 +60,25 @@ public abstract class AbstractDeployMojo
if ( repository == null ) if ( repository == null )
{ {
String msg = "Deployment failed: repository element" + String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
" was not specified in the pom inside" + + " distributionManagement element";
" distributionManagement element";
throw new Exception( msg ); throw new Exception( msg );
} }
ArtifactRepository deploymentRepository = RepositoryUtils.mavenRepositoryToWagonRepository( repository ); ArtifactRepository deploymentRepository = new ArtifactRepository( repository.getId(), repository.getUrl() );
// Deploy the POM // Deploy the POM
Artifact pomArtifact = new DefaultArtifact( project.getGroupId(), Artifact pomArtifact = new DefaultArtifact( project.getGroupId(),
project.getArtifactId(), project.getArtifactId(),
project.getVersion(), project.getVersion(),
"pom" ); "pom" );
File pom = new File( project.getFile().getParentFile(), "pom.xml" ); File pom = new File( project.getFile().getParentFile(), "pom.xml" );
artifactDeployer.deploy( pom, pomArtifact, deploymentRepository ); artifactDeployer.deploy( pom, pomArtifact, deploymentRepository );
//Deploy artifact //Deploy artifact
if ( ! isPom() ) if ( !isPom() )
{ {
Artifact artifact = new DefaultArtifact( project.getGroupId(), Artifact artifact = new DefaultArtifact( project.getGroupId(),
project.getArtifactId(), project.getArtifactId(),
@ -92,4 +88,4 @@ public abstract class AbstractDeployMojo
artifactDeployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository ); artifactDeployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository );
} }
} }
} }

View File

@ -16,78 +16,58 @@ package org.apache.maven.plugin.jar;
* limitations under the License. * 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.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject; 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 * @goal deploy
*
* @description deploys a JAR to remote repository * @description deploys a JAR to remote repository
* * @parameter name="project" type="org.apache.maven.project.MavenProject"
* @parameter * required="true" validator="" expression="#project" description=""
* name="project" * @parameter name="deployer"
* type="org.apache.maven.project.MavenProject" * type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true" * required="true" validator=""
* validator="" * expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* expression="#project" * description=""
* description=""
*
* @parameter
* name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
*/ */
public class JarDeployMojo public class JarDeployMojo
extends AbstractPlugin extends AbstractPlugin
{ {
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
throws Exception
{ {
MavenProject project = (MavenProject) request.getParameter( "project" ); MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" ); ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" );
//@todo this will be duplicated in case of every mojo which implements
//@todo this will be duplicated in case of every mojo which implements deploy goal // deploy goal
// this should be pushed into the ArtifactDeployer component // this should be pushed into the ArtifactDeployer component
DistributionManagement distributionManagement = project.getDistributionManagement(); DistributionManagement distributionManagement = project.getDistributionManagement();
if ( distributionManagement == null ) if ( distributionManagement == null )
{ {
String msg = "Deployment failed: distributionManagement element" + String msg = "Deployment failed: distributionManagement element" + " was not specified in the pom";
" was not specified in the pom";
throw new Exception( msg ); throw new Exception( msg );
} }
Repository repository = distributionManagement.getRepository(); Repository repository = distributionManagement.getRepository();
if ( repository == null ) if ( repository == null )
{ {
String msg = "Deployment failed: repository element" + String msg = "Deployment failed: repository element" + " was not specified in the pom inside"
" was not specified in the pom inside" + + " distributionManagement element";
" distributionManagement element";
throw new Exception( msg ); throw new Exception( msg );
} }
ArtifactRepository deploymentRepository = new ArtifactRepository( repository.getId(), repository.getUrl() );
ArtifactRepository deploymentRepository =
RepositoryUtils.mavenRepositoryToWagonRepository( repository );
Artifact artifact = new DefaultArtifact( project.getGroupId(), Artifact artifact = new DefaultArtifact( project.getGroupId(),
project.getArtifactId(), project.getArtifactId(),
@ -96,4 +76,4 @@ public class JarDeployMojo
artifactDeployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository ); artifactDeployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository );
} }
} }

View File

@ -20,17 +20,24 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer; import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractPlugin; import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest; import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse; import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositoryUtils;
import java.io.File; import java.io.File;
/** /**
* @goal deploy * @goal deploy
* @description deploys a pom to remote repository * @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" * @parameter name="project"
* type="org.apache.maven.project.MavenProject" * type="org.apache.maven.project.MavenProject"
* required="true" * required="true"
@ -60,15 +67,16 @@ public class PomDeployMojo
// TODO: simple failure response // TODO: simple failure response
throw new Exception( "distributionManagement is required for deployment" ); 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( Artifact artifact = new DefaultArtifact( project.getGroupId(),
project.getDistributionManagement().getRepository() ); project.getArtifactId(),
project.getVersion(),
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
"pom" ); "pom" );
File pom = new File( project.getFile().getParentFile(), "pom.xml" ); File pom = new File( project.getFile().getParentFile(), "pom.xml" );
artifactDeployer.deploy( pom, artifact, deploymentRepository ); artifactDeployer.deploy( pom, artifact, deploymentRepository );
} }
} }

View File

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