o delegating local repository implementation that chains the reactor and user local repository

o removal of more state from the WagonManager and pushing it into the request in an attempt to bridge the way for Mercury



git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@773456 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-11 04:08:29 +00:00
parent 4fdc5512eb
commit 3398024a0f
42 changed files with 614 additions and 1427 deletions

View File

@ -32,12 +32,6 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
/**
* Description of an artifact.
*
* @todo do we really need an interface here?
* @todo get rid of the multiple states we can have (project, parent, etc artifacts, file == null, snapshot, etc) - construct subclasses and use accordingly?
*/
public interface Artifact
extends Comparable
{
@ -73,20 +67,12 @@ public interface Artifact
void setVersion( String version );
/**
* Get the artifactScope of the artifact. If the artifact is a standalone rather than a dependency, it's artifactScope will be
* <code>null</code>. The artifactScope may not be the same as it was declared on the original dependency, as this is the
* result of combining it with the main project artifactScope.
*
* @return the artifactScope
*/
String getScope();
String getType();
String getClassifier();
// only providing this since classifier is *very* optional...
boolean hasClassifier();
File getFile();
@ -95,11 +81,8 @@ public interface Artifact
String getBaseVersion();
/** @todo would like to get rid of this - or at least only have one. Base version should be immutable. */
void setBaseVersion( String baseVersion );
// ----------------------------------------------------------------------
String getId();
String getDependencyConflictId();
@ -112,8 +95,7 @@ public interface Artifact
ArtifactRepository getRepository();
void updateVersion( String version,
ArtifactRepository localRepository );
void updateVersion( String version, ArtifactRepository localRepository );
String getDownloadUrl();
@ -125,14 +107,8 @@ public interface Artifact
ArtifactHandler getArtifactHandler();
/**
* @return {@link List} &lt; {@link String} > with artifact ids
*/
List<String> getDependencyTrail();
/**
* @param dependencyTrail {@link List} &lt; {@link String} > with artifact ids
*/
void setDependencyTrail( List<String> dependencyTrail );
void setScope( String scope );
@ -155,7 +131,6 @@ public interface Artifact
void setResolvedVersion( String version );
/** @todo remove, a quick hack for the lifecycle executor */
void setArtifactHandler( ArtifactHandler handler );
boolean isRelease();
@ -175,4 +150,8 @@ public interface Artifact
boolean isSelectedVersionKnown()
throws OverConstrainedVersionException;
void setFromAuthoritativeRepository( boolean fromAuthoritativeRepository );
boolean isFromAuthoritativeRepository();
}

View File

@ -30,17 +30,6 @@ import org.apache.maven.artifact.versioning.VersionRange;
public final class ArtifactUtils
{
private ArtifactUtils()
{
}
public static boolean isSnapshot( String version )
{
return ( version != null ) &&
( version.toUpperCase().endsWith( Artifact.SNAPSHOT_VERSION ) || Artifact.VERSION_FILE_PATTERN.matcher( version )
.matches() );
}
public static String toSnapshotVersion( String version )
{
if(version == null)
@ -58,50 +47,56 @@ public final class ArtifactUtils
return version;
}
}
public static String versionlessKey( Artifact artifact )
{
return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
}
public static String versionlessKey( String groupId,
String artifactId )
public static String versionlessKey( String groupId, String artifactId )
{
if ( groupId == null )
{
throw new NullPointerException( "groupId was null" );
throw new NullPointerException( "groupId is null" );
}
if ( artifactId == null )
{
throw new NullPointerException( "artifactId was null" );
throw new NullPointerException( "artifactId is null" );
}
return groupId + ":" + artifactId;
}
public static String artifactId( String groupId,
String artifactId,
String type,
String version )
public static String key( Artifact artifact )
{
return artifactId( groupId, artifactId, type, null, version );
}
return key( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
}
public static String artifactId( String groupId,
String artifactId,
String type,
String classifier,
String baseVersion )
public static String key( String groupId, String artifactId, String version )
{
return groupId + ":" + artifactId + ":" + type + ( classifier != null ? ":" + classifier : "" ) + ":" + baseVersion;
}
if ( groupId == null )
{
throw new NullPointerException( "groupId is null" );
}
if ( artifactId == null )
{
throw new NullPointerException( "artifactId is null" );
}
if ( version == null )
{
throw new NullPointerException( "version is null" );
}
return groupId + ":" + artifactId + ":" + version;
}
public static Map<String,Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
{
Map<String,Artifact> artifactMap = new LinkedHashMap<String,Artifact>();
if ( artifacts != null )
{
for (Artifact artifact : artifacts) {
for (Artifact artifact : artifacts)
{
artifactMap.put(versionlessKey(artifact), artifact);
}
}
@ -109,20 +104,6 @@ public final class ArtifactUtils
return artifactMap;
}
public static Map<String,Artifact> artifactMapByArtifactId( Collection<Artifact> artifacts )
{
Map<String,Artifact> artifactMap = new LinkedHashMap<String,Artifact>();
if ( artifacts != null )
{
for (Artifact artifact : artifacts) {
artifactMap.put(artifact.getId(), artifact);
}
}
return artifactMap;
}
public static Artifact copyArtifact( Artifact artifact )
{
VersionRange range = artifact.getVersionRange();

View File

@ -47,11 +47,6 @@ public class DefaultArtifact
private String artifactId;
/**
* The resolved version for the artifact after conflict resolution, that has not been transformed.
*
* @todo should be final
*/
private String baseVersion;
private final String type;
@ -86,25 +81,12 @@ public class DefaultArtifact
private boolean optional;
public DefaultArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String scope,
String type,
String classifier,
ArtifactHandler artifactHandler )
public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, String classifier, ArtifactHandler artifactHandler )
{
this( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler, false );
}
public DefaultArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String scope,
String type,
String classifier,
ArtifactHandler artifactHandler,
boolean optional )
public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, String classifier, ArtifactHandler artifactHandler, boolean optional )
{
this.groupId = groupId;
@ -398,6 +380,7 @@ public class DefaultArtifact
protected void setBaseVersionInternal( String baseVersion )
{
Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion );
if ( m.matches() )
{
this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION;
@ -451,8 +434,7 @@ public class DefaultArtifact
return result;
}
public void updateVersion( String version,
ArtifactRepository localRepository )
public void updateVersion( String version, ArtifactRepository localRepository )
{
setResolvedVersion( version );
setFile( new File( localRepository.getBasedir(), localRepository.pathOf( this ) ) );
@ -606,4 +588,18 @@ public class DefaultArtifact
{
this.optional = optional;
}
//
private boolean fromAuthoritativeRepository;
public void setFromAuthoritativeRepository( boolean fromAuthoritativeRepository )
{
this.fromAuthoritativeRepository = fromAuthoritativeRepository;
}
public boolean isFromAuthoritativeRepository()
{
return fromAuthoritativeRepository;
}
}

View File

@ -21,14 +21,12 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@ -36,14 +34,10 @@ import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.proxy.ProxyInfoProvider;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -71,33 +65,12 @@ public class DefaultWagonManager
@Requirement
private PlexusContainer container;
// TODO: proxies, authentication and mirrors are via settings, and should come in via an alternate method - perhaps
// attached to ArtifactRepository before the method is called (so AR would be composed of WR, not inherit it)
private Map<String, ProxyInfo> proxies = new HashMap<String, ProxyInfo>();
private static Map<String, AuthenticationInfo> authenticationInfoMap = new HashMap<String, AuthenticationInfo>();
private Map<String, RepositoryPermissions> serverPermissionsMap = new HashMap<String, RepositoryPermissions>();
//used LinkedMap to preserve the order.
private Map<String, ArtifactRepository> mirrors = new LinkedHashMap<String, ArtifactRepository>();
/** Map( String, XmlPlexusConfiguration ) with the repository id and the wagon configuration */
private Map<String, XmlPlexusConfiguration> serverConfigurationMap = new HashMap<String, XmlPlexusConfiguration>();
private RepositoryPermissions defaultRepositoryPermissions;
// Components
@Requirement
private ArtifactRepositoryFactory repositoryFactory;
@Requirement(role = Wagon.class)
private Map<String,Wagon> wagons;
//@Requirement
private CredentialsDataSource credentialsDataSource;
@Requirement
private UpdateCheckManager updateCheckManager;
@ -110,13 +83,10 @@ public class DefaultWagonManager
this.downloadMonitor = downloadMonitor;
}
// TODO: this leaks the component in the public api - it is never released back to the container
public Wagon getWagon( Repository repository )
throws UnsupportedProtocolException, WagonConfigurationException
{
String protocol = repository.getProtocol();
System.out.println( "PROTOCOL: " + protocol );
if ( protocol == null )
{
@ -203,27 +173,11 @@ public class DefaultWagonManager
try
{
try
{
Repository artifactRepository = new Repository( repository.getId(), repository.getUrl() );
AuthenticationInfo authenticationInfo = getAuthenticationInfo( repository.getId() );
wagon.connect( artifactRepository, authenticationInfo, new ProxyInfoProvider()
{
public ProxyInfo getProxyInfo( String protocol )
{
return getProxy( protocol );
}
} );
{
wagon.connect( new Repository( repository.getId(), repository.getUrl() ) );
wagon.put( source, remotePath );
}
catch ( CredentialsDataSourceException e )
{
String err = "Problem with server credentials: " + e.getMessage();
logger.error( err );
throw new TransferFailedException( err );
}
finally
{
if ( downloadMonitor != null )
@ -363,6 +317,8 @@ public class DefaultWagonManager
getArtifact( artifact, repository, downloadMonitor, true );
}
//TODO: all of this needs to move into the repository system
public void getArtifact( Artifact artifact, ArtifactRepository repository, TransferListener downloadMonitor, boolean force )
throws TransferFailedException, ResourceDoesNotExistException
{
@ -500,14 +456,8 @@ public class DefaultWagonManager
boolean downloaded = false;
try
{
wagon.connect( new Repository( repository.getId(), repository.getUrl() ), getAuthenticationInfo( repository.getId() ), new ProxyInfoProvider()
{
public ProxyInfo getProxyInfo( String protocol )
{
return getProxy( protocol );
}
} );
{
wagon.connect( new Repository( repository.getId(), repository.getUrl() ) );
boolean firstRun = true;
boolean retry = true;
@ -645,10 +595,6 @@ public class DefaultWagonManager
{
throw new TransferFailedException( "Authorization failed: " + e.getMessage(), e );
}
catch ( CredentialsDataSourceException e )
{
throw new TransferFailedException( "Retrieving credentials failed: " + e.getMessage(), e );
}
finally
{
// Remove remaining TransferListener instances (checksum handlers removed in above finally clause)
@ -785,17 +731,6 @@ public class DefaultWagonManager
}
}
public ProxyInfo getProxy( String protocol )
{
return proxies.get( protocol );
}
public AuthenticationInfo getAuthenticationInfo( String id )
throws CredentialsDataSourceException
{
return authenticationInfoMap.get( id );
}
/**
* Checks the URL to see if this repository refers to an external repository
*
@ -815,70 +750,7 @@ public class DefaultWagonManager
return false;
}
}
/**
* Set the proxy used for a particular protocol.
*
* @param protocol the protocol (required)
* @param host the proxy host name (required)
* @param port the proxy port (required)
* @param username the username for the proxy, or null if there is none
* @param password the password for the proxy, or null if there is none
* @param nonProxyHosts the set of hosts not to use the proxy for. Follows Java system property
* format: <code>*.foo.com|localhost</code>.
* @todo [BP] would be nice to configure this via plexus in some way
*/
public void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost( host );
proxyInfo.setType( protocol );
proxyInfo.setPort( port );
proxyInfo.setNonProxyHosts( nonProxyHosts );
proxyInfo.setUserName( username );
proxyInfo.setPassword( password );
proxies.put( protocol, proxyInfo );
}
// We are leaving this method here so that we can attempt to use the new maven-artifact
// library from the 2.0.x code so that we aren't maintaining two lines of code
// for the artifact management.
public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName( username );
authInfo.setPassword( password );
authInfo.setPrivateKey( privateKey );
authInfo.setPassphrase( passphrase );
authenticationInfoMap.put( repositoryId, authInfo );
}
public void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions )
{
RepositoryPermissions permissions = new RepositoryPermissions();
boolean addPermissions = false;
if ( filePermissions != null )
{
permissions.setFileMode( filePermissions );
addPermissions = true;
}
if ( directoryPermissions != null )
{
permissions.setDirectoryMode( directoryPermissions );
addPermissions = true;
}
if ( addPermissions )
{
serverPermissionsMap.put( repositoryId, permissions );
}
}
/**
* Applies the server configuration to the wagon
*

View File

@ -84,10 +84,5 @@ public interface WagonManager
throws TransferFailedException, ResourceDoesNotExistException;
void getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File file, String checksumPolicyWarn )
throws TransferFailedException, ResourceDoesNotExistException;
void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase );
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
throws TransferFailedException, ResourceDoesNotExistException;
}

View File

@ -44,6 +44,10 @@ public class DefaultArtifactRepository
private boolean blacklisted;
public DefaultArtifactRepository()
{
}
/**
* Create a local repository or a test repository.
*
@ -170,10 +174,18 @@ public class DefaultArtifactRepository
sb.append( " id: " ).append( getId() ).append( "\n" );
sb.append( " url: " ).append( getUrl() ).append( "\n" );
sb.append( " layout: " ).append( layout != null ? layout.getId() : "none" ).append( "\n" );
sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );
sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" );
sb.append( " releases: [enabled => " ).append( releases.isEnabled() );
sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" );
if ( snapshots != null )
{
sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );
sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" );
}
if ( releases != null )
{
sb.append( " releases: [enabled => " ).append( releases.isEnabled() );
sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" );
}
return sb.toString();
}

View File

@ -67,8 +67,7 @@ public class DefaultRepositoryLayout
return path.toString();
}
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata,
ArtifactRepository repository )
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
}

View File

@ -56,7 +56,7 @@ public abstract class AbstractRepositoryMetadata
}
public String getLocalFilename( ArtifactRepository repository )
{
{
return "maven-metadata-" + repository.getKey() + ".xml";
}

View File

@ -53,17 +53,6 @@ public class DefaultRepositoryMetadataManager
@Requirement
private UpdateCheckManager updateCheckManager;
protected DefaultRepositoryMetadataManager( WagonManager wagonManager, UpdateCheckManager updateCheckManager, Logger logger )
{
this.wagonManager = wagonManager;
this.updateCheckManager = updateCheckManager;
enableLogging( logger );
}
public DefaultRepositoryMetadataManager()
{
}
public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataResolutionException
{

View File

@ -26,14 +26,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
public interface RepositoryMetadataManager
{
void resolve( RepositoryMetadata repositoryMetadata,
List<ArtifactRepository> repositories,
ArtifactRepository localRepository )
void resolve( RepositoryMetadata repositoryMetadata, List<ArtifactRepository> repositories, ArtifactRepository localRepository )
throws RepositoryMetadataResolutionException;
void resolveAlways( RepositoryMetadata metadata,
ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws RepositoryMetadataResolutionException;
/**
@ -43,9 +39,7 @@ public interface RepositoryMetadataManager
* @param localRepository the local repository to install to first
* @param deploymentRepository the remote repository to deploy to
*/
void deploy( ArtifactMetadata metadata,
ArtifactRepository localRepository,
ArtifactRepository deploymentRepository )
void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository, ArtifactRepository deploymentRepository )
throws RepositoryMetadataDeploymentException;
/**
@ -54,7 +48,6 @@ public interface RepositoryMetadataManager
* @param metadata the metadata
* @param localRepository the local repository
*/
void install( ArtifactMetadata metadata,
ArtifactRepository localRepository )
void install( ArtifactMetadata metadata, ArtifactRepository localRepository )
throws RepositoryMetadataInstallationException;
}

View File

@ -38,33 +38,6 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
*/
public interface ArtifactCollector
{
/**
* The plexus role for this component.
*
* @since 3.0
*/
String ROLE = ArtifactCollector.class.getName();
// TODO: deprecate since conflict resolvers should always be specified
ArtifactResolutionResult collect( Set<Artifact> artifacts,
Artifact originatingArtifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners );
// TODO: deprecate since conflict resolvers should always be specified
ArtifactResolutionResult collect( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners );
/** @since 3.0 */
ArtifactResolutionResult collect( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
@ -73,6 +46,5 @@ public interface ArtifactCollector
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
throws ArtifactResolutionException;
List<ConflictResolver> conflictResolvers );
}

View File

@ -34,17 +34,14 @@ import org.apache.maven.wagon.events.TransferListener;
*/
public interface ArtifactResolver
{
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
// The rest is deprecated
// USED BY MAVEN ASSEMBLY PLUGIN 2.2-beta-2
@Deprecated
String ROLE = ArtifactResolver.class.getName();
void setOnline( boolean online );
boolean isOnline();
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
// USED BY SUREFIRE
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,

View File

@ -42,55 +42,29 @@ import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
/**
* Default implementation of the artifact collector.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author Jason van Zyl
* @version $Id$
* @todo This needs to collect all errors and not die on the first error. If there are problems retrieving the metadata
* then we need all the information so that we can tell users about what we attempted to do.
* @todo there 8 places where we can can range exceptions which is bad, again the result of not using a graph.
*/
@Component(role=ArtifactCollector.class)
public class DefaultArtifactCollector
implements ArtifactCollector, LogEnabled
implements ArtifactCollector
{
/**
* The conflict resolver to use when none is specified.
*/
@Requirement(hint="nearest")
private ConflictResolver defaultConflictResolver;
@Requirement
private Logger logger;
public ArtifactResolutionResult collect( Set<Artifact> artifacts, Artifact originatingArtifact,
public ArtifactResolutionResult collect( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
List<ResolutionListener> listeners )
{
return collect( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories,
source, filter, listeners );
}
public ArtifactResolutionResult collect( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
List<ResolutionListener> listeners )
{
return collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source,
filter, listeners, null );
}
public ArtifactResolutionResult collect( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
{
@ -100,8 +74,6 @@ public class DefaultArtifactCollector
if ( conflictResolvers == null )
{
// TODO: warn that we're using the default conflict resolver
conflictResolvers = Collections.singletonList( defaultConflictResolver );
}
@ -130,8 +102,7 @@ public class DefaultArtifactCollector
try
{
recurse( result, root, resolvedArtifacts, versionMap, localRepository, remoteRepositories, source, filter,
listeners, conflictResolvers );
recurse( result, root, resolvedArtifacts, versionMap, localRepository, remoteRepositories, source, filter, listeners, conflictResolvers );
}
catch ( CyclicDependencyException e )
{
@ -224,10 +195,15 @@ public class DefaultArtifactCollector
return versionMap;
}
private void recurse( ArtifactResolutionResult result, ResolutionNode node,
Map<Object, List<ResolutionNode>> resolvedArtifacts, ManagedVersionMap managedVersions,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
private void recurse( ArtifactResolutionResult result,
ResolutionNode node,
Map<Object, List<ResolutionNode>> resolvedArtifacts,
ManagedVersionMap managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
throws ArtifactResolutionException
{
@ -293,26 +269,19 @@ public class DefaultArtifactCollector
{
try
{
versions =
source.retrieveAvailableVersions( resetArtifact, localRepository,
remoteRepositories );
versions = source.retrieveAvailableVersions( resetArtifact, localRepository, remoteRepositories );
resetArtifact.setAvailableVersions( versions );
}
catch ( ArtifactMetadataRetrievalException e )
{
resetArtifact.setDependencyTrail( node.getDependencyTrail() );
throw new ArtifactResolutionException(
"Unable to get dependency information: "
+ e.getMessage(), resetArtifact,
remoteRepositories, e );
throw new ArtifactResolutionException( "Unable to get dependency information: " + e.getMessage(), resetArtifact, remoteRepositories, e );
}
}
// end hack
// MNG-2861: match version can return null
ArtifactVersion selectedVersion =
resetArtifact.getVersionRange().matchVersion(
resetArtifact.getAvailableVersions() );
ArtifactVersion selectedVersion = resetArtifact.getVersionRange().matchVersion( resetArtifact.getAvailableVersions() );
if ( selectedVersion != null )
{
resetArtifact.selectVersion( selectedVersion.toString() );
@ -341,20 +310,15 @@ public class DefaultArtifactCollector
if ( resolved == null )
{
// TODO: add better exception that can detail the two conflicting artifacts
result.addVersionRangeViolation( new ArtifactResolutionException(
"Cannot resolve artifact version conflict between "
+ previous.getArtifact().getVersion()
+ " and "
+ node.getArtifact().getVersion(),
previous.getArtifact() ) );
ArtifactResolutionException are = new ArtifactResolutionException( "Cannot resolve artifact version conflict between " + previous.getArtifact().getVersion()
+ " and " + node.getArtifact().getVersion(), previous.getArtifact() );
result.addVersionRangeViolation( are );
}
if ( ( resolved != previous ) && ( resolved != node ) )
{
// TODO: add better exception
result.addVersionRangeViolation( new ArtifactResolutionException(
"Conflict resolver returned unknown resolution node: ",
resolved.getArtifact() ) );
result.addVersionRangeViolation( new ArtifactResolutionException( "Conflict resolver returned unknown resolution node: ", resolved.getArtifact() ) );
}
// TODO: should this be part of mediation?
@ -565,8 +529,7 @@ public class DefaultArtifactCollector
}
}
private void manageArtifact( ResolutionNode node, ManagedVersionMap managedVersions,
List<ResolutionListener> listeners )
private void manageArtifact( ResolutionNode node, ManagedVersionMap managedVersions, List<ResolutionListener> listeners )
{
Artifact artifact = (Artifact) managedVersions.get( node.getKey() );
@ -737,9 +700,4 @@ public class DefaultArtifactCollector
}
}
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
}

View File

@ -56,13 +56,6 @@ import org.codehaus.plexus.util.FileUtils;
public class DefaultArtifactResolver
implements ArtifactResolver
{
private boolean online = true;
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
@Requirement
private Logger logger;
@ -84,23 +77,6 @@ public class DefaultArtifactResolver
@Requirement
private PlexusContainer container;
//@Requirement
private ArtifactMetadataSource metadataSource;
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
public void setOnline( boolean online )
{
this.online = online;
}
public boolean isOnline()
{
return online;
}
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, TransferListener resolutionListener )
throws ArtifactResolutionException, ArtifactNotFoundException
{
@ -122,6 +98,7 @@ public class DefaultArtifactResolver
}
File destination;
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
{
File systemFile = artifact.getFile();
@ -142,8 +119,11 @@ public class DefaultArtifactResolver
}
artifact.setResolved( true );
return;
}
else if ( !artifact.isResolved() )
if ( !artifact.isResolved() )
{
// ----------------------------------------------------------------------
// Check for the existence of the artifact in the specified local
@ -151,9 +131,21 @@ public class DefaultArtifactResolver
// request for resolution has been satisfied.
// ----------------------------------------------------------------------
String localPath = localRepository.pathOf( artifact );
artifact = localRepository.find( artifact );
if ( artifact.isFromAuthoritativeRepository() )
{
return;
}
if ( artifact.isSnapshot() && artifact.isResolved() )
{
return;
}
//String localPath = localRepository.pathOf( artifact );
artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
//artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
transformationManager.transformForResolve( artifact, remoteRepositories, localRepository );
@ -168,15 +160,8 @@ public class DefaultArtifactResolver
// 2. the artifact's file doesn't exist (this would be true for release or snapshot artifacts)
// 3. the artifact is a snapshot and is not a locally installed snapshot
// TODO: Should it matter whether it's a locally installed snapshot??
if ( force || !destination.exists() || ( artifact.isSnapshot() && !localCopy && isOnline() ) )
if ( force || !destination.exists() || ( artifact.isSnapshot() && !localCopy ) )
{
if ( !isOnline() )
{
throw new ArtifactResolutionException( "The repository system is offline and the artifact "
+ artifact + " is not available in the local repository.", artifact );
}
try
{
if ( artifact.getRepository() != null )
@ -209,18 +194,27 @@ public class DefaultArtifactResolver
if ( destination.exists() )
{
// locally resolved...no need to hit the remote repo.
artifact.setResolved( true );
}
// 1.0-SNAPSHOT
//
// 1) pom = 1.0-SoNAPSHOT
// 2) pom = 1.0-yyyymmdd.hhmmss
// 3) baseVersion = 1.0-SNAPSHOT
if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals( artifact.getVersion() ) )
{
String version = artifact.getVersion();
// 1.0-SNAPSHOT
artifact.selectVersion( artifact.getBaseVersion() );
// Make a file with a 1.0-SNAPSHOT format
File copy = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
// if the timestamped version was resolved or the copy doesn't exist then copy a version
// of the file like 1.0-SNAPSHOT. Even if there is a timestamped version the non-timestamped
// version will be created.
if ( resolved || !copy.exists() )
{
// recopy file if it was reresolved, or doesn't exist.
@ -236,13 +230,15 @@ public class DefaultArtifactResolver
}
}
// We are only going to use the 1.0-SNAPSHOT version
artifact.setFile( copy );
// Set the version to the 1.0-SNAPSHOT version
artifact.selectVersion( version );
}
}
}
private boolean isLocalCopy( Artifact artifact )
{
boolean localCopy = false;
@ -427,8 +423,7 @@ public class DefaultArtifactResolver
{
try
{
Set<Artifact> directArtifacts =
source.retrieve( rootArtifact, localRepository, remoteRepositories ).getArtifacts();
Set<Artifact> directArtifacts = source.retrieve( rootArtifact, localRepository, remoteRepositories ).getArtifacts();
if ( artifacts == null || artifacts.isEmpty() )
{
@ -467,7 +462,7 @@ public class DefaultArtifactResolver
}
// After the collection we will have the artifact object in the result but they will not be resolved yet.
result = artifactCollector.collect( artifacts, rootArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners );
result = artifactCollector.collect( artifacts, rootArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners, null );
// We have metadata retrieval problems, or there are cycles that have been detected
// so we give this back to the calling code and let them deal with this information

View File

@ -51,9 +51,7 @@ public abstract class AbstractVersionTransformation
@Requirement
protected WagonManager wagonManager;
protected String resolveVersion( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws RepositoryMetadataResolutionException
{
RepositoryMetadata metadata;
@ -110,6 +108,5 @@ public abstract class AbstractVersionTransformation
return version;
}
protected abstract String constructVersion( Versioning versioning,
String baseVersion );
protected abstract String constructVersion( Versioning versioning, String baseVersion );
}

View File

@ -41,9 +41,7 @@ public interface ArtifactTransformationManager
* @param remoteRepositories the repositories to check
* @param localRepository the local repository
*/
void transformForResolve( Artifact artifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
void transformForResolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException;
/**
@ -53,8 +51,7 @@ public interface ArtifactTransformationManager
* @param artifact Artifact to be transformed.
* @param localRepository the local repository it will be stored in
*/
void transformForInstall( Artifact artifact,
ArtifactRepository localRepository )
void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactInstallationException;
/**
@ -65,11 +62,8 @@ public interface ArtifactTransformationManager
* @param remoteRepository the repository to deploy to
* @param localRepository the local repository the metadata is stored in
*/
void transformForDeployment( Artifact artifact,
ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository )
throws ArtifactDeploymentException;
List getArtifactTransformations();
}

View File

@ -54,9 +54,7 @@ public class SnapshotTransformation
private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
public void transformForResolve( Artifact artifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
public void transformForResolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
// Only select snapshots that are unresolved (eg 1.0-SNAPSHOT, not 1.0-20050607.123456)

View File

@ -73,7 +73,7 @@ public class DefaultArtifactCollectorTest
source = new Source();
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifactCollector = (ArtifactCollector) lookup( ArtifactCollector.ROLE );
artifactCollector = (ArtifactCollector) lookup( ArtifactCollector.class );
projectArtifact = createArtifactSpec( "project", "1.0", null );
}
@ -726,23 +726,23 @@ public class DefaultArtifactCollectorTest
private ArtifactResolutionResult collect( Set artifacts, ArtifactFilter filter )
throws ArtifactResolutionException
{
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, source, filter,
Collections.EMPTY_LIST );
{
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, null, source, filter,
Collections.EMPTY_LIST, null );
}
private ArtifactResolutionResult collect( ArtifactSpec a )
throws ArtifactResolutionException
{
return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, null, null,
source, null, Collections.EMPTY_LIST );
null, source, null, Collections.EMPTY_LIST, null );
}
private ArtifactResolutionResult collect( ArtifactSpec a, ArtifactFilter filter )
throws ArtifactResolutionException
{
return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, null, null,
source, filter, Collections.EMPTY_LIST );
null, source, filter, Collections.EMPTY_LIST, null );
}
private ArtifactResolutionResult collect( ArtifactSpec a, Artifact managedVersion )
@ -750,7 +750,7 @@ public class DefaultArtifactCollectorTest
{
Map managedVersions = Collections.singletonMap( managedVersion.getDependencyConflictId(), managedVersion );
return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact,
managedVersions, null, null, source, null, Collections.EMPTY_LIST );
managedVersions, null, null, source, null, Collections.EMPTY_LIST, null );
}
private ArtifactSpec createArtifactSpec( String id, String version )

View File

@ -21,8 +21,12 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.exception.DefaultExceptionHandler;
import org.apache.maven.exception.ExceptionHandler;
@ -69,14 +73,6 @@ public class DefaultMaven
return lifecycleExecutor.getLifecyclePhases();
}
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------
// project build
// artifact resolution
// lifecycle execution
public MavenExecutionResult execute( MavenExecutionRequest request )
{
// Need a general way to inject standard properties
@ -88,117 +84,110 @@ public class DefaultMaven
request.setStartTime( new Date() );
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenSession session = createMavenSession( request, result );
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository = new DelegatingLocalArtifactRepository();
delegatingLocalArtifactRepository.addLocalArtifactRepository( new UserLocalArtifactRepository( request.getLocalRepository() ) );
request.setLocalRepository( delegatingLocalArtifactRepository );
MavenSession session;
Map<String,MavenProject> projects;
try
{
projects = getProjects( request );
//TODO: We really need to get rid of this requirement in here. If we know there is no project present
if ( projects.isEmpty() )
{
MavenProject project = projectBuilder.buildStandaloneSuperProject( request.getProjectBuildingConfiguration() );
projects.put( ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
request.setProjectPresent( false );
}
}
catch ( ProjectBuildingException e )
{
return processResult( result, e );
}
catch ( MavenExecutionException e )
{
return processResult( result, e );
}
try
{
ProjectSorter projectSorter = new ProjectSorter( projects.values() );
session = new MavenSession( container, request, projectSorter.getSortedProjects() );
}
catch ( CycleDetectedException e )
{
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
ProjectCycleException error = new ProjectCycleException( message, e );
return processResult( result, error );
}
catch ( DuplicateProjectException e )
{
return processResult( result, e );
}
delegatingLocalArtifactRepository.addLocalArtifactRepository( new ReactorArtifactRepository( projects ) );
if ( result.hasExceptions() )
{
return result;
}
try
{
lifecycleExecutor.execute( session );
}
catch ( Exception e )
{
ExceptionHandler handler = new DefaultExceptionHandler();
// This will only be more then one if we have fail at end on and we collect
// them per project.
ExceptionSummary es = handler.handleException( e );
result.addException( e );
result.setExceptionSummary( es );
return result;
return processResult( result, e );
}
result.setTopologicallySortedProjects( session.getSortedProjects() );
result.setTopologicallySortedProjects( session.getProjects() );
result.setProject( session.getTopLevelProject() );
return result;
}
public MavenSession createMavenSession( MavenExecutionRequest request, MavenExecutionResult result )
private MavenExecutionResult processResult( MavenExecutionResult result, Exception e )
{
MavenSession session;
ExceptionHandler handler = new DefaultExceptionHandler();
List<MavenProject> projects;
try
{
projects = getProjects( request );
if ( projects.isEmpty() )
{
projects.add( projectBuilder.buildStandaloneSuperProject( request.getProjectBuildingConfiguration() ) );
request.setProjectPresent( false );
}
}
catch ( ProjectBuildingException e )
{
result.addException( e );
return null;
}
catch ( MavenExecutionException e )
{
result.addException( e );
return null;
}
try
{
ProjectSorter projectSorter = new ProjectSorter( projects );
session = new MavenSession( container, request, projectSorter.getSortedProjects() );
}
catch ( CycleDetectedException e )
{
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
ProjectCycleException error = new ProjectCycleException( projects, message, e );
result.addException( error );
return null;
}
catch ( DuplicateProjectException e )
{
result.addException( e );
return null;
}
return session;
ExceptionSummary es = handler.handleException( e );
result.addException( e );
result.setExceptionSummary( es );
return result;
}
protected List<MavenProject> getProjects( MavenExecutionRequest request )
throws MavenExecutionException
protected Map<String,MavenProject> getProjects( MavenExecutionRequest request )
throws MavenExecutionException, ProjectBuildingException
{
List<File> files = Arrays.asList( new File[] { request.getPom() } );
List<MavenProject> projects = collectProjects( files, request );
Map<String,MavenProject> projects = collectProjects( files, request );
return projects;
}
private List<MavenProject> collectProjects( List<File> files, MavenExecutionRequest request )
throws MavenExecutionException
private Map<String,MavenProject> collectProjects( List<File> files, MavenExecutionRequest request )
throws MavenExecutionException, ProjectBuildingException
{
List<MavenProject> projects = new ArrayList<MavenProject>();
Map<String,MavenProject> projects = new LinkedHashMap<String,MavenProject>();
for ( File file : files )
{
MavenProject project;
try
{
project = projectBuilder.build( file, request.getProjectBuildingConfiguration() );
}
catch ( ProjectBuildingException e )
{
throw new MavenExecutionException( "Failed to build MavenProject instance for: " + file, file, e );
}
MavenProject project = projectBuilder.build( file, request.getProjectBuildingConfiguration() );
if ( ( project.getPrerequisites() != null ) && ( project.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
@ -253,14 +242,12 @@ public class DefaultMaven
moduleFiles.add( moduleFile );
}
List<MavenProject> collectedProjects = collectProjects( moduleFiles, request );
Map<String,MavenProject> collectedProjects = collectProjects( moduleFiles, request );
projects.addAll( collectedProjects );
project.setCollectedProjects( collectedProjects );
projects.putAll( collectedProjects );
}
projects.add( project );
projects.put( ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
}
return projects;

View File

@ -0,0 +1,76 @@
package org.apache.maven;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
public class DelegatingLocalArtifactRepository
extends DefaultArtifactRepository
{
private List<LocalArtifactRepository> localRepositories;
public void addLocalArtifactRepository( LocalArtifactRepository localRepository )
{
if ( localRepositories == null )
{
localRepositories = new ArrayList<LocalArtifactRepository>();
}
localRepositories.add( localRepository );
}
@Override
public Artifact find( Artifact artifact )
{
for( LocalArtifactRepository repository : localRepositories )
{
artifact = repository.find( artifact );
if ( artifact.isResolved() )
{
return artifact;
}
}
return artifact;
}
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
for( LocalArtifactRepository localRepository : localRepositories )
{
if ( localRepository.hasLocalMetadata() )
{
return localRepository.pathOfLocalRepositoryMetadata( metadata, localRepository );
}
}
return null;
}
// This ID is necessary of the metadata lookup doesn't work correctly.
public String getId()
{
return "local";
}
@Override
public String pathOf( Artifact artifact )
{
for( LocalArtifactRepository localRepository : localRepositories )
{
if( localRepository.hasLocalMetadata() )
{
String path = localRepository.pathOf( artifact );
return path;
}
}
return null;
}
}

View File

@ -0,0 +1,22 @@
package org.apache.maven;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
public abstract class LocalArtifactRepository
extends DefaultArtifactRepository
{
public abstract Artifact find( Artifact artifact );
/**
* If an artifact is found in this repository and this method returns true the search is over. This would
* be the case if we look for artifacts in the reactor or a IDE workspace. We don't want to search any
* further.
*
* @return
*/
// workspace or reactor
public abstract boolean isAuthoritative();
public abstract boolean hasLocalMetadata();
}

View File

@ -1,7 +1,5 @@
package org.apache.maven;
import java.util.List;
import org.codehaus.plexus.util.dag.CycleDetectedException;
/**
@ -10,19 +8,8 @@ import org.codehaus.plexus.util.dag.CycleDetectedException;
public class ProjectCycleException
extends BuildFailureException
{
private final List projects;
public ProjectCycleException( List projects, String message,
CycleDetectedException cause )
public ProjectCycleException( String message, CycleDetectedException cause )
{
super( message, cause );
this.projects = projects;
}
public List getProjects()
{
return projects;
}
}

View File

@ -0,0 +1,82 @@
package org.apache.maven;
import java.io.File;
import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.project.MavenProject;
/**
* An implementation of a repository that knows how to search the Maven reactor for artifacts.
*
* @author Jason van Zyl
*/
// maven-compat
// target/classes
// maven-core
// target/classes
// maven-embedder
// target/classes
// maven-model
// target/classes
// maven-model-builder
// target/classes
// maven-plugin-api
// target/classes
// maven-repository
// target/classes
// maven-toolchain
// target/classes
public class ReactorArtifactRepository
extends LocalArtifactRepository
{
private Map<String,MavenProject> reactorProjects;
public ReactorArtifactRepository( Map<String,MavenProject> reactorProjects )
{
this.reactorProjects = reactorProjects;
}
@Override
public Artifact find( Artifact artifact )
{
String projectKey = ArtifactUtils.key( artifact );
MavenProject project = reactorProjects.get( projectKey );
if ( project != null )
{
//TODO: determine if we want to pass the artifact produced by the project if it
// is present and under what conditions we will do such a thing.
File classesDirectory = new File( project.getBuild().getOutputDirectory() );
if( classesDirectory.exists() )
{
artifact.setFile( classesDirectory );
artifact.setFromAuthoritativeRepository( true );
artifact.setResolved( true );
}
}
return artifact;
}
@Override
public boolean isAuthoritative()
{
return true;
}
@Override
public boolean hasLocalMetadata()
{
return false;
}
}

View File

@ -0,0 +1,64 @@
package org.apache.maven;
import java.io.File;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
public class UserLocalArtifactRepository
extends LocalArtifactRepository
{
private ArtifactRepository localRepository;
public UserLocalArtifactRepository( ArtifactRepository localRepository )
{
this.localRepository = localRepository;
}
@Override
public Artifact find( Artifact artifact )
{
File artifactFile = new File( localRepository.getBasedir(), pathOf( artifact ) );
if( artifactFile.exists() )
{
artifact.setFile( artifactFile );
artifact.setResolved( true );
}
return artifact;
}
@Override
public String getId()
{
return localRepository.getId();
}
@Override
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return localRepository.pathOfLocalRepositoryMetadata( metadata, repository );
}
@Override
public String pathOf( Artifact artifact )
{
return localRepository.pathOf( artifact );
}
@Override
public boolean isAuthoritative()
{
return false;
}
@Override
public boolean hasLocalMetadata()
{
return true;
}
}

View File

@ -701,6 +701,7 @@ public class DefaultMavenExecutionRequest
projectBuildingConfiguration.setExecutionProperties( getProperties() );
projectBuildingConfiguration.setGlobalProfileManager( getProfileManager() );
projectBuildingConfiguration.setRemoteRepositories( getRemoteRepositories() );
projectBuildingConfiguration.setProcessPlugins( true );
}
return projectBuildingConfiguration;

View File

@ -21,6 +21,7 @@ package org.apache.maven.execution;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -42,6 +43,10 @@ public class MavenSession
private MavenProject currentProject;
/**
* These projects have already been topologically sorted in the {@link org.apache.maven.Maven} component before
* being passed into the session.
*/
private List<MavenProject> projects;
private MavenProject topLevelProject;
@ -91,8 +96,8 @@ public class MavenSession
{
return request.getSettings();
}
public List<MavenProject> getSortedProjects()
public List<MavenProject> getProjects()
{
return projects;
}

View File

@ -4,6 +4,7 @@
package org.apache.maven.execution;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -49,7 +50,7 @@ public class ProjectSorter
// In this case, both the verify and the report goals are called
// in a different lifecycle. Though the compiler-plugin has a valid usecase, although
// that seems to work fine. We need to take versions and lifecycle into account.
public ProjectSorter( List<MavenProject> projects )
public ProjectSorter( Collection<MavenProject> projects )
throws CycleDetectedException, DuplicateProjectException
{
dag = new DAG();

View File

@ -107,7 +107,7 @@ public class DefaultLifecycleExecutor
throw new LifecycleExecutionException( "\n\nYou must specify at least one goal. Try 'mvn install' to build or 'mvn --help' for options \nSee http://maven.apache.org for more information.\n\n" );
}
for ( MavenProject currentProject : session.getSortedProjects() )
for ( MavenProject currentProject : session.getProjects() )
{
logger.info( "Building " + currentProject.getName() );
@ -508,9 +508,7 @@ public class DefaultLifecycleExecutor
return mojoDescriptor;
}
private static int count = 0;
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
MojoDescriptor getMojoDescriptor( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository )
throws LifecycleExecutionException
@ -523,10 +521,7 @@ public class DefaultLifecycleExecutor
MojoDescriptor mojoDescriptor;
//need to do the active project thing as the site plugin is referencing itself
if ( artifactId.equals( "maven-site-plugin" ) ){ count++; System.out.println( count ); };
System.out.println( ">>> " + artifactId );
try
{
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, project, localRepository );

View File

@ -25,7 +25,6 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -106,6 +105,9 @@ public class DefaultPluginManager
@Requirement
private ResolutionErrorHandler resolutionErrorHandler;
@Requirement
private PluginClassLoaderCache pluginClassLoaderCache;
private Map<String, PluginDescriptor> pluginDescriptors;
public DefaultPluginManager()
@ -174,9 +176,6 @@ public class DefaultPluginManager
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin );
//TODO: this is assuming plugins in the reactor. must be replaced with a reactor local repository implementation
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
ArtifactResolutionResult result = repositorySystem.resolve( request );
@ -199,6 +198,8 @@ public class DefaultPluginManager
}
}
//pluginRealm.display();
try
{
logger.debug( "Discovering components in realm: " + pluginRealm );
@ -214,8 +215,10 @@ public class DefaultPluginManager
throw new PluginContainerException( plugin, pluginRealm, "Error scanning plugin realm for components.", e );
}
pluginClassLoaderCache.cachePluginClassLoader( constructPluginKey( plugin ), pluginRealm );
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin );
// We just need to keep track of the realm, if we need to augment we will wrap the realm
pluginDescriptor.setPluginArtifact( pluginArtifact );
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( pluginArtifacts ) );
@ -266,24 +269,9 @@ public class DefaultPluginManager
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
Set<Artifact> resolved = new LinkedHashSet<Artifact>();
logger.debug( "Using the following artifacts for classpath of: " + pluginArtifact.getId() + ":\n\n" + result.getArtifacts().toString().replace( ',', '\n' ) );
//TODO: this is also assuming artifacts in the reactor.
for ( Iterator<Artifact> it = result.getArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = it.next();
if ( !artifact.equals( pluginArtifact ) )
{
artifact = project.replaceWithActiveArtifact( artifact );
}
resolved.add( artifact );
}
logger.debug( "Using the following artifacts for classpath of: " + pluginArtifact.getId() + ":\n\n" + resolved.toString().replace( ',', '\n' ) );
return resolved;
return result.getArtifacts();
}
// ----------------------------------------------------------------------
@ -356,7 +344,8 @@ public class DefaultPluginManager
{
mojo = getConfiguredMojo( session, mojoExecution, project, false, mojoExecution );
pluginRealm = pluginDescriptor.getClassRealm();
//pluginRealm = pluginDescriptor.getClassRealm();
pluginRealm = pluginClassLoaderCache.getPluginClassLoader( constructPluginKey( mojoDescriptor.getPluginDescriptor() ) );
Thread.currentThread().setContextClassLoader( pluginRealm );

View File

@ -151,7 +151,7 @@ public class PluginParameterExpressionEvaluator
}
else if ( "reactorProjects".equals( expression ) )
{
value = session.getSortedProjects();
value = session.getProjects();
}
else if ("mojoExecution".equals(expression))
{
@ -246,7 +246,7 @@ public class PluginParameterExpressionEvaluator
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression,
e );
}
}
}
else if ( "settings".equals( expression ) )
{
value = session.getSettings();

View File

@ -20,7 +20,9 @@ import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.artifact.Artifact;
@ -89,8 +91,8 @@ public class DefaultMavenProjectBuilder
@Requirement
private ResolutionErrorHandler resolutionErrorHandler;
//private static HashMap<String, MavenProject> hm = new HashMap<String, MavenProject>();
private Map<File, MavenProject> projectCache = new HashMap<File, MavenProject>();
private MavenProject superProject;
@ -101,6 +103,13 @@ public class DefaultMavenProjectBuilder
public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException
{
MavenProject project = projectCache.get( pomFile );
if ( project != null )
{
return project;
}
DomainModel domainModel;
try
@ -124,7 +133,7 @@ public class DefaultMavenProjectBuilder
}
catch ( ProfileActivationException e )
{
throw new ProjectBuildingException( "", "Failed to activate pom profiles." );
throw new ProjectBuildingException( "", "Failed to activate pom profiles.", e );
}
try
@ -143,56 +152,60 @@ public class DefaultMavenProjectBuilder
}
catch ( IOException e )
{
throw new ProjectBuildingException( "", "" );
throw new ProjectBuildingException( "", "", e );
}
//Interpolation & Management
MavenProject project;
try
{
Model model = interpolateDomainModel( domainModel, configuration, pomFile );
lifecycleBindingsInjector.injectLifecycleBindings( model );
if ( configuration.isProcessPlugins() )
{
lifecycleBindingsInjector.injectLifecycleBindings( model );
}
ProcessorContext.processManagementNodes( model );
project = this.fromDomainModelToMavenProject( model, domainModel.getParentFile(), configuration, pomFile );
Collection<Plugin> pluginsFromProject = project.getModel().getBuild().getPlugins();
if ( configuration.isProcessPlugins() )
{
Collection<Plugin> pluginsFromProject = project.getModel().getBuild().getPlugins();
// Merge the various sources for mojo configuration:
// 1. default values from mojo descriptor
// 2. POM values from per-plugin configuration
// 3. POM values from per-execution configuration
// These configuration sources are given in increasing order of dominance.
// Merge the various sources for mojo configuration:
// 1. default values from mojo descriptor
// 2. POM values from per-plugin configuration
// 3. POM values from per-execution configuration
// These configuration sources are given in increasing order of dominance.
// push plugin configuration down to executions
for ( Plugin buildPlugin : pluginsFromProject )
{
Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration();
if ( dom != null )
// push plugin configuration down to executions
for ( Plugin buildPlugin : pluginsFromProject )
{
for ( PluginExecution e : buildPlugin.getExecutions() )
Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration();
if ( dom != null )
{
Xpp3Dom dom1 = Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) e.getConfiguration(), new Xpp3Dom( dom ) );
e.setConfiguration( dom1 );
for ( PluginExecution e : buildPlugin.getExecutions() )
{
Xpp3Dom dom1 = Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) e.getConfiguration(), new Xpp3Dom( dom ) );
e.setConfiguration( dom1 );
}
}
}
// merge in default values from mojo descriptor
lifecycle.populateDefaultConfigurationForPlugins( pluginsFromProject, project, configuration.getLocalRepository() );
project.getModel().getBuild().setPlugins( new ArrayList<Plugin>( pluginsFromProject ) );
}
// merge in default values from mojo descriptor
lifecycle.populateDefaultConfigurationForPlugins( pluginsFromProject, project, configuration.getLocalRepository() );
project.getModel().getBuild().setPlugins( new ArrayList<Plugin>( pluginsFromProject ) );
}
catch ( IOException e )
{
throw new ProjectBuildingException( "", "" );
throw new ProjectBuildingException( "", "", e );
}
catch ( LifecycleExecutionException e )
{
throw new ProjectBuildingException( "", e.getMessage() );
throw new ProjectBuildingException( "", e.getMessage(), e );
}
//project.setActiveProfiles( projectProfiles );
@ -208,6 +221,8 @@ public class DefaultMavenProjectBuilder
setBuildOutputDirectoryOnParent( project );
projectCache.put( pomFile, project );
return project;
}

View File

@ -43,6 +43,8 @@ public class DefaultProjectBuilderConfiguration
private MavenProject topProject;
private boolean processPlugins = false;
public DefaultProjectBuilderConfiguration()
{
}
@ -117,4 +119,15 @@ public class DefaultProjectBuilderConfiguration
this.listeners = listeners;
return this;
}
public boolean isProcessPlugins()
{
return processPlugins;
}
public ProjectBuilderConfiguration setProcessPlugins( boolean processPlugins )
{
this.processPlugins = processPlugins;
return this;
}
}

View File

@ -66,8 +66,6 @@ import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.repository.MavenRepositoryWrapper;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -87,7 +85,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
* </ol>
*/
public class MavenProject
implements Cloneable, MavenRepositoryWrapper
implements Cloneable
{
public static final String EMPTY_PROJECT_GROUP_ID = "unknown";
@ -109,8 +107,6 @@ public class MavenProject
private List<ArtifactRepository> remoteArtifactRepositories;
private List<MavenProject> collectedProjects = Collections.emptyList();
private List<Artifact> attachedArtifacts;
private MavenProject executionProject;
@ -121,8 +117,6 @@ public class MavenProject
private List<String> scriptSourceRoots = new ArrayList<String>();
private List<ArtifactRepository> pluginArtifactRepositories;
private ArtifactRepository releaseArtifactRepository;
private ArtifactRepository snapshotArtifactRepository;
@ -508,14 +502,12 @@ public class MavenProject
for ( Artifact a : getArtifacts() )
{
System.out.println( "++> " + a.getArtifactId() );
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
addArtifactPath( a, list );
System.out.println( "--> " + a.getArtifactId() );
}
}
}
@ -1323,19 +1315,8 @@ public class MavenProject
return build;
}
public List<MavenProject> getCollectedProjects()
{
return collectedProjects;
}
public void setCollectedProjects( List<MavenProject> collectedProjects )
{
this.collectedProjects = collectedProjects;
}
public void setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
{
this.pluginArtifactRepositories = pluginArtifactRepositories;
}
/**
@ -1672,157 +1653,7 @@ public class MavenProject
{
return getBuild() != null ? getBuild().getDefaultGoal() : null;
}
public Artifact find( Artifact artifact )
{
return replaceWithActiveArtifact( artifact );
}
public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
{
if ( ( getProjectReferences() != null ) && !getProjectReferences().isEmpty() )
{
String refId = getProjectReferenceId( pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(), pluginArtifact.getVersion() );
MavenProject ref = getProjectReferences().get( refId );
if ( ref != null )
{
if ( ref.getArtifact() != null
&& ref.getArtifact().getDependencyConflictId().equals( pluginArtifact.getDependencyConflictId() ) )
{
// if the project artifact doesn't exist, don't use it. We haven't built that far.
if ( ref.getArtifact().getFile() != null && ref.getArtifact().getFile().exists() )
{
// FIXME: Why aren't we using project.getArtifact() for the second parameter here??
Artifact resultArtifact = new ActiveProjectArtifact( ref, pluginArtifact );
return resultArtifact;
}
else
{
logMissingSiblingProjectArtifact( pluginArtifact );
}
}
Artifact attached = findMatchingArtifact( ref.getAttachedArtifacts(), pluginArtifact );
if ( attached != null )
{
if ( attached.getFile() != null && attached.getFile().exists() )
{
Artifact resultArtifact = ArtifactUtils.copyArtifact( attached );
resultArtifact.setScope( pluginArtifact.getScope() );
return resultArtifact;
}
else
{
logMissingSiblingProjectArtifact( pluginArtifact );
}
}
/**
* Patch/workaround for: MNG-2871
*
* We want to use orginal artifact (packaging:ejb) when we are resolving ejb-client
* package and we didn't manage to find attached to project one.
*
* The scenario is such that somebody run "mvn test" in composity project, and
* ejb-client.jar will not be attached to ejb.jar (because it is done in package
* phase)
*
* We prefer in such a case use orginal sources (of ejb.jar) instead of failure
*/
if ( ( ref.getArtifactId().equals( pluginArtifact.getArtifactId() ) ) && ( ref.getGroupId().equals( pluginArtifact.getGroupId() ) ) && ( ref.getArtifact().getType().equals( "ejb" ) )
&& ( pluginArtifact.getType().equals( "ejb-client" ) ) && ( ( ref.getArtifact().getFile() != null ) && ref.getArtifact().getFile().exists() ) )
{
pluginArtifact = new ActiveProjectArtifact( ref, pluginArtifact );
return pluginArtifact;
}
}
}
return pluginArtifact;
}
/**
* Tries to resolve the specified artifact from the given collection of attached project artifacts.
*
* @param artifacts The attached artifacts, may be <code>null</code>.
* @param requestedArtifact The artifact to resolve, must not be <code>null</code>.
* @return The matching artifact or <code>null</code> if not found.
*/
private Artifact findMatchingArtifact( List<Artifact> artifacts, Artifact requestedArtifact )
{
if ( artifacts != null && !artifacts.isEmpty() )
{
// first try matching by dependency conflict id
String requestedId = requestedArtifact.getDependencyConflictId();
for ( Artifact artifact : artifacts )
{
if ( requestedId.equals( artifact.getDependencyConflictId() ) )
{
return artifact;
}
}
// next try matching by repository conflict id
requestedId = getRepositoryConflictId( requestedArtifact );
for ( Artifact artifact : artifacts )
{
if ( requestedId.equals( getRepositoryConflictId( artifact ) ) )
{
return artifact;
}
}
}
return null;
}
/**
* Gets the repository conflict id of the specified artifact. Unlike the dependency conflict id, the repository
* conflict id uses the artifact file extension instead of the artifact type. Hence, the repository conflict id more
* closely reflects the identity of artifacts as perceived by a repository.
*
* @param artifact The artifact, must not be <code>null</code>.
* @return The repository conflict id, never <code>null</code>.
*/
private String getRepositoryConflictId( Artifact artifact )
{
StringBuffer buffer = new StringBuffer( 128 );
buffer.append( artifact.getGroupId() );
buffer.append( ':' ).append( artifact.getArtifactId() );
if ( artifact.getArtifactHandler() != null )
{
buffer.append( ':' ).append( artifact.getArtifactHandler().getExtension() );
}
else
{
buffer.append( ':' ).append( artifact.getType() );
}
if ( artifact.hasClassifier() )
{
buffer.append( ':' ).append( artifact.getClassifier() );
}
return buffer.toString();
}
private void logMissingSiblingProjectArtifact( Artifact artifact )
{
/* TODO
if ( logger == null )
{
return;
}
StringBuffer message = new StringBuffer();
message.append( "A dependency of the current project (or of one the plugins used in its build) was found in the reactor, " );
message.append( "\nbut had not been built at the time it was requested. It will be resolved from the repository instead." );
message.append( "\n\nCurrent Project: " ).append( getName() );
message.append( "\nRequested Dependency: " ).append( artifact.getId() );
message.append( "\n\nNOTE: You may need to run this build to the 'compile' lifecycle phase, or farther, in order to build the dependency artifact." );
message.append( "\n" );
logger.warn( message.toString() );
*/
}
public void clearExecutionProject()
{
if ( !previousExecutionProjects.isEmpty() )
@ -1990,11 +1821,6 @@ public class MavenProject
setPluginArtifactRepositories( ( Collections.unmodifiableList( project.getPluginArtifactRepositories() ) ) );
}
if ( project.getCollectedProjects() != null )
{
setCollectedProjects( ( Collections.unmodifiableList( project.getCollectedProjects() ) ) );
}
if ( project.getActiveProfiles() != null )
{
setActiveProfiles( ( Collections.unmodifiableList( project.getActiveProfiles() ) ) );

View File

@ -8,24 +8,28 @@ import org.apache.maven.profiles.ProfileManager;
public interface ProjectBuilderConfiguration
{
ArtifactRepository getLocalRepository();
List<ArtifactRepository> getRemoteRepositories();
ProfileManager getGlobalProfileManager();
Properties getExecutionProperties();
ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager );
ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository );
ArtifactRepository getLocalRepository();
ProjectBuilderConfiguration setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
List<ArtifactRepository> getRemoteRepositories();
ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager );
ProfileManager getGlobalProfileManager();
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
MavenProject getTopLevelProjectFromReactor();
Properties getExecutionProperties();
void setTopLevelProjectForReactor(MavenProject mavenProject);
MavenProject getTopLevelProjectFromReactor();
ProjectBuilderConfiguration setProcessPlugins( boolean processPlugins );
boolean isProcessPlugins();
}

View File

@ -41,9 +41,9 @@ public class ProjectBuildingException
private File pomFile;
public ProjectBuildingException( String projectId, String message )
public ProjectBuildingException( String projectId, String message, Throwable cause )
{
super( message );
super( message, cause );
this.projectId = projectId;
}

View File

@ -1,500 +0,0 @@
package org.apache.maven.project.artifact;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.Collection;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.project.MavenProject;
/**
* Wraps an active project instance to be able to receive updates from its artifact without affecting the original
* attributes of this artifact.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @todo I think this exposes a design flaw in that the immutable and mutable parts of an artifact are in one class and
* should be split. ie scope, file, etc depend on the context of use, whereas everything else is immutable.
*/
public class ActiveProjectArtifact
implements Artifact
{
private final Artifact artifact;
private final MavenProject project;
public ActiveProjectArtifact( MavenProject project, Artifact artifact )
{
this.artifact = artifact;
this.project = project;
artifact.setFile( project.getArtifact().getFile() );
artifact.setResolved( true );
}
/**
* {@inheritDoc}
*/
public File getFile()
{
// we need to get the latest file for the project, not the artifact that was created at one point in time
return project.getArtifact().getFile();
}
/**
* {@inheritDoc}
*/
public String getGroupId()
{
return artifact.getGroupId();
}
/**
* {@inheritDoc}
*/
public String getArtifactId()
{
return artifact.getArtifactId();
}
/**
* {@inheritDoc}
*/
public String getVersion()
{
return artifact.getVersion();
}
/**
* {@inheritDoc}
*/
public void setVersion( String version )
{
artifact.setVersion( version );
}
/**
* {@inheritDoc}
*/
public String getScope()
{
return artifact.getScope();
}
/**
* {@inheritDoc}
*/
public String getType()
{
return artifact.getType();
}
/**
* {@inheritDoc}
*/
public String getClassifier()
{
return artifact.getClassifier();
}
/**
* {@inheritDoc}
*/
public boolean hasClassifier()
{
return artifact.hasClassifier();
}
/**
* {@inheritDoc}
*/
public void setFile( File destination )
{
artifact.setFile( destination );
project.getArtifact().setFile( destination );
}
/**
* {@inheritDoc}
*/
public String getBaseVersion()
{
return artifact.getBaseVersion();
}
/**
* {@inheritDoc}
*/
public void setBaseVersion( String baseVersion )
{
artifact.setBaseVersion( baseVersion );
}
/**
* {@inheritDoc}
*/
public String getId()
{
return artifact.getId();
}
/**
* {@inheritDoc}
*/
public String getDependencyConflictId()
{
return artifact.getDependencyConflictId();
}
/**
* {@inheritDoc}
*/
public void addMetadata( ArtifactMetadata metadata )
{
artifact.addMetadata( metadata );
}
/**
* {@inheritDoc}
*/
public Collection getMetadataList()
{
return artifact.getMetadataList();
}
/**
* {@inheritDoc}
*/
public void setRepository( ArtifactRepository remoteRepository )
{
artifact.setRepository( remoteRepository );
}
/**
* {@inheritDoc}
*/
public ArtifactRepository getRepository()
{
return artifact.getRepository();
}
/**
* {@inheritDoc}
*/
public void updateVersion( String version, ArtifactRepository localRepository )
{
artifact.updateVersion( version, localRepository );
}
/**
* {@inheritDoc}
*/
public String getDownloadUrl()
{
return artifact.getDownloadUrl();
}
/**
* {@inheritDoc}
*/
public void setDownloadUrl( String downloadUrl )
{
artifact.setDownloadUrl( downloadUrl );
}
/**
* {@inheritDoc}
*/
public ArtifactFilter getDependencyFilter()
{
return artifact.getDependencyFilter();
}
/**
* {@inheritDoc}
*/
public void setDependencyFilter( ArtifactFilter artifactFilter )
{
artifact.setDependencyFilter( artifactFilter );
}
/**
* {@inheritDoc}
*/
public ArtifactHandler getArtifactHandler()
{
return artifact.getArtifactHandler();
}
/**
* {@inheritDoc}
*/
public List getDependencyTrail()
{
return artifact.getDependencyTrail();
}
/**
* {@inheritDoc}
*/
public void setDependencyTrail( List dependencyTrail )
{
artifact.setDependencyTrail( dependencyTrail );
}
/**
* {@inheritDoc}
*/
public void setScope( String scope )
{
artifact.setScope( scope );
}
/**
* {@inheritDoc}
*/
public VersionRange getVersionRange()
{
return artifact.getVersionRange();
}
/**
* {@inheritDoc}
*/
public void setVersionRange( VersionRange newRange )
{
artifact.setVersionRange( newRange );
}
/**
* {@inheritDoc}
*/
public void selectVersion( String version )
{
artifact.selectVersion( version );
}
/**
* {@inheritDoc}
*/
public void setGroupId( String groupId )
{
artifact.setGroupId( groupId );
}
/**
* {@inheritDoc}
*/
public void setArtifactId( String artifactId )
{
artifact.setArtifactId( artifactId );
}
/**
* {@inheritDoc}
*/
public boolean isSnapshot()
{
return artifact.isSnapshot();
}
/**
* {@inheritDoc}
*/
public int compareTo( Object o )
{
return artifact.compareTo( o );
}
/**
* {@inheritDoc}
*/
public void setResolved( boolean resolved )
{
artifact.setResolved( resolved );
}
/**
* {@inheritDoc}
*/
public boolean isResolved()
{
return artifact.isResolved();
}
/**
* {@inheritDoc}
*/
public void setResolvedVersion( String version )
{
artifact.setResolvedVersion( version );
}
/**
* {@inheritDoc}
*/
public void setArtifactHandler( ArtifactHandler handler )
{
artifact.setArtifactHandler( handler );
}
/**
* {@inheritDoc}
*/
public String toString()
{
return "active project artifact:\n\tartifact = " + artifact + ";\n\tproject: " + project;
}
/**
* {@inheritDoc}
*/
public boolean isRelease()
{
return artifact.isRelease();
}
/**
* {@inheritDoc}
*/
public void setRelease( boolean release )
{
artifact.setRelease( release );
}
/**
* {@inheritDoc}
*/
public List getAvailableVersions()
{
return artifact.getAvailableVersions();
}
/**
* {@inheritDoc}
*/
public void setAvailableVersions( List versions )
{
artifact.setAvailableVersions( versions );
}
/**
* {@inheritDoc}
*/
public boolean isOptional()
{
return artifact.isOptional();
}
/**
* {@inheritDoc}
*/
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return artifact.getSelectedVersion();
}
/**
* {@inheritDoc}
*/
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return artifact.isSelectedVersionKnown();
}
/**
* {@inheritDoc}
*/
public void setOptional( boolean optional )
{
artifact.setOptional( optional );
}
/**
* {@inheritDoc}
*/
public int hashCode()
{
int result = 17;
result = 37 * result + getGroupId().hashCode();
result = 37 * result + getArtifactId().hashCode();
result = 37 * result + getType().hashCode();
if ( getVersion() != null )
{
result = 37 * result + getVersion().hashCode();
}
result = 37 * result + ( getClassifier() != null ? getClassifier().hashCode() : 0 );
return result;
}
/**
* {@inheritDoc}
*/
public boolean equals( Object o )
{
if ( o == this )
{
return true;
}
if ( !( o instanceof Artifact ) )
{
return false;
}
Artifact a = (Artifact) o;
if ( !a.getGroupId().equals( getGroupId() ) )
{
return false;
}
else if ( !a.getArtifactId().equals( getArtifactId() ) )
{
return false;
}
else if ( !a.getVersion().equals( getVersion() ) )
{
return false;
}
else if ( !a.getType().equals( getType() ) )
{
return false;
}
else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) )
{
return false;
}
return true;
}
}

View File

@ -79,6 +79,8 @@ public class MavenMetadataSource
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration();
configuration.setLocalRepository( localRepository );
configuration.setRemoteRepositories( remoteRepositories );
// We don't care about processing plugins here, all we're interested in is the dependencies.
configuration.setProcessPlugins( false );
MavenProject project;
@ -96,9 +98,7 @@ public class MavenMetadataSource
if ( effectiveScope != null )
{
Artifact dependencyArtifact =
repositorySystem.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
effectiveScope, d.getType() );
Artifact dependencyArtifact = repositorySystem.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), effectiveScope, d.getType() );
artifacts.add( dependencyArtifact );
}
@ -193,10 +193,13 @@ public class MavenMetadataSource
private List<ArtifactVersion> retrieveAvailableVersionsFromMetadata( Metadata repoMetadata )
{
List<ArtifactVersion> versions;
if ( ( repoMetadata != null ) && ( repoMetadata.getVersioning() != null ) )
{
List<String> metadataVersions = repoMetadata.getVersioning().getVersions();
versions = new ArrayList<ArtifactVersion>( metadataVersions.size() );
for ( String version : metadataVersions )
{
versions.add( new DefaultArtifactVersion( version ) );

View File

@ -16,7 +16,6 @@ package org.apache.maven.embedder.execution;
*/
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -37,18 +36,13 @@ import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.toolchain.ToolchainsBuilder;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
/**
* Things that we deal with in this populator to ensure that we have a valid
@ -63,9 +57,7 @@ public class DefaultMavenExecutionRequestPopulator
extends AbstractLogEnabled
implements MavenExecutionRequestPopulator
{
@Requirement
private PlexusContainer container;
//TODO: this needs to be pushed up to the front-end
@Requirement
private MavenSettingsBuilder settingsBuilder;
@ -75,10 +67,6 @@ public class DefaultMavenExecutionRequestPopulator
@Requirement
private ToolchainsBuilder toolchainsBuilder;
// 2009-03-05 Oleg: this component is defined sub-classed in this package
@Requirement(hint = "maven")
private SecDispatcher securityDispatcher;
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request, Configuration configuration )
throws MavenEmbedderException
{
@ -226,6 +214,7 @@ public class DefaultMavenExecutionRequestPopulator
{
Settings settings = request.getSettings();
/*
Proxy proxy = settings.getActiveProxy();
if ( proxy != null )
@ -257,6 +246,7 @@ public class DefaultMavenExecutionRequestPopulator
repositorySystem.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() );
}
*/
for ( Mirror mirror : settings.getMirrors() )
{
@ -367,9 +357,9 @@ public class DefaultMavenExecutionRequestPopulator
try
{
return repositorySystem.createLocalRepository( localRepositoryPath, RepositorySystem.DEFAULT_LOCAL_REPO_ID );
return repositorySystem.createLocalRepository( new File( localRepositoryPath ) );
}
catch ( IOException e )
catch ( InvalidRepositoryException e )
{
throw new MavenEmbedderException( "Cannot create local repository.", e );
}

View File

@ -18,33 +18,23 @@ package org.apache.maven.repository;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
@ -53,7 +43,6 @@ import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.StringUtils;
/**
* @author Jason van Zyl
@ -62,9 +51,6 @@ import org.codehaus.plexus.util.StringUtils;
public class LegacyRepositorySystem
implements RepositorySystem
{
@Requirement
private WagonManager wagonManager;
@Requirement
private ArtifactFactory artifactFactory;
@ -77,9 +63,6 @@ public class LegacyRepositorySystem
@Requirement
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
@Requirement
private ArtifactCollector artifactCollector;
@Requirement
private MirrorBuilder mirrorBuilder;
@ -281,14 +264,11 @@ public class LegacyRepositorySystem
String releaseUpdates, boolean snapshots, String snapshotUpdates,
String checksumPolicy )
{
ArtifactRepositoryPolicy snapshotsPolicy =
new ArtifactRepositoryPolicy( snapshots, snapshotUpdates, checksumPolicy );
ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( snapshots, snapshotUpdates, checksumPolicy );
ArtifactRepositoryPolicy releasesPolicy =
new ArtifactRepositoryPolicy( releases, releaseUpdates, checksumPolicy );
ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( releases, releaseUpdates, checksumPolicy );
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout,
snapshotsPolicy, releasesPolicy );
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy );
}
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
@ -296,16 +276,7 @@ public class LegacyRepositorySystem
return artifactResolver.resolve( request );
}
public void setOnline( boolean online )
{
artifactResolver.setOnline( online );
}
public boolean isOnline()
{
return artifactResolver.isOnline();
}
/*
public void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
ProxyInfo proxyInfo = new ProxyInfo();
@ -320,7 +291,9 @@ public class LegacyRepositorySystem
wagonManager.addProxy( protocol, host, port, username, password, nonProxyHosts );
}
*/
/*
public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
@ -333,7 +306,9 @@ public class LegacyRepositorySystem
wagonManager.addAuthenticationInfo( repositoryId, username, password, privateKey, passphrase );
}
*/
/*
public void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions )
{
RepositoryPermissions permissions = new RepositoryPermissions();
@ -357,6 +332,7 @@ public class LegacyRepositorySystem
serverPermissionsMap.put( repositoryId, permissions );
}
}
*/
// Mirror

View File

@ -1,53 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.maven.repository;
import java.io.File;
import org.apache.maven.artifact.Artifact;
/**
* small repository implementation used to find artifact in a local source
* instead of going out to the real repo. Used to search reactor for matches
*
* @author Oleg Gusakov
* @version $Id$
*
*/
public interface MavenRepositoryWrapper
{
/**
* finds supplied artifact, if any, in the wrapped source
*
* @param artifact
* @return
*/
Artifact find( Artifact artifact );
/**
* @return
*/
String getId();
/**
* @return
*/
File getFile();
}

View File

@ -34,7 +34,6 @@ import org.apache.maven.model.Repository;
*/
public interface RepositorySystem
{
// Default local repository
static final String DEFAULT_LOCAL_REPO_ID = "local";
static final String userHome = System.getProperty( "user.home" );
@ -43,7 +42,6 @@ public interface RepositorySystem
static final File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" );
// Default remote repository
static final String DEFAULT_REMOTE_REPO_ID = "central";
static final String DEFAULT_REMOTE_REPO_URL = "http://repo1.maven.org/maven2";
@ -55,18 +53,10 @@ public interface RepositorySystem
Artifact createPluginArtifact( Plugin plugin );
Artifact createDependencyArtifact( Dependency dependency );
//TODO: this needs a project to do anything useful
//Set<Artifact> createArtifacts();
// maven model
ArtifactRepository buildArtifactRepository( Repository repository )
throws InvalidRepositoryException;
//!!jvz Change this to use a file
ArtifactRepository createLocalRepository( String url, String repositoryId )
throws IOException;
ArtifactRepository createDefaultRemoteRepository()
throws InvalidRepositoryException;
@ -76,9 +66,6 @@ public interface RepositorySystem
ArtifactRepository createLocalRepository( File localRepository )
throws InvalidRepositoryException;
//correct all uses to let the resolver find the deps of the root and
//pass in overrides where necessary
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
/**
@ -92,15 +79,8 @@ public interface RepositorySystem
*/
MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request );
//REMOVE
// These should be associated with repositories and the repositories should be examine as part of metadatda and
// artifact resolution. So these methods should also not be here.
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase );
void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions );
// Mirrors
//TODO: remove the request should already be processed to select the mirror for the request instead of the processing happen internally.
// Mirrors
void addMirror( String id, String mirrorOf, String url );
List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories );
}

View File

@ -22,16 +22,13 @@ under the License.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven-parent</artifactId>
<version>11</version>
<relativePath>../pom/maven/pom.xml</relativePath>
</parent>
-->
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
<packaging>pom</packaging>