You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2008/12/21 22:14:28 UTC
svn commit: r728504 - in /maven/components/branches/MNG-3932: ./
maven-compat/src/main/java/org/apache/maven/artifact/manager/
maven-core/src/main/java/org/apache/maven/
maven-core/src/main/java/org/apache/maven/listeners/
maven-embedder/src/main/java/...
Author: jvanzyl
Date: Sun Dec 21 13:14:28 2008
New Revision: 728504
URL: http://svn.apache.org/viewvc?rev=728504&view=rev
Log:
MNG-3932: first cut at making one entry point for an artifact system
Added:
maven/components/branches/MNG-3932/
- copied from r728123, maven/components/trunk/
Modified:
maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java
maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/DefaultMavenModelEventProcessor.java
maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventListener.java
maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventProcessor.java
maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java
maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java
maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/MavenTools.java
maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
maven/components/branches/MNG-3932/pom.xml
Modified: maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (original)
+++ maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java Sun Dec 21 13:14:28 2008
@@ -72,54 +72,19 @@
extends AbstractLogEnabled
implements WagonManager, Contextualizable
{
- private static final String WILDCARD = "*";
-
- private static final String EXTERNAL_WILDCARD = "external:*";
-
private static final String[] CHECKSUM_IDS = {"md5", "sha1"};
/** have to match the CHECKSUM_IDS */
private static final String[] CHECKSUM_ALGORITHMS = {"MD5", "SHA-1"};
-
- private static final String MAVEN_ARTIFACT_PROPERTIES = "META-INF/maven/org.apache.maven.artifact/maven-artifact/pom.properties";
-
- private static int anonymousMirrorIdSeed = 0;
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 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 TransferListener downloadMonitor;
-
- private boolean online = true;
-
- private boolean interactive = true;
-
- private RepositoryPermissions defaultRepositoryPermissions;
-
- // Components
-
/** @plexus.requirement */
private ArtifactRepositoryFactory repositoryFactory;
/** @plexus.requirement role="org.apache.maven.wagon.Wagon" */
private Map wagons;
- /** encapsulates access to Server credentials */
- private CredentialsDataSource credentialsDataSource;
-
/** @plexus.requirement */
private UpdateCheckManager updateCheckManager;
@@ -160,8 +125,6 @@
"Cannot find wagon which supports the requested protocol: " + protocol );
}
- wagon.setInteractive( interactive );
-
return wagon;
}
@@ -225,20 +188,6 @@
{
Repository artifactRepository = new Repository( repository.getId(), repository.getUrl() );
- if ( serverPermissionsMap.containsKey( repository.getId() ) )
- {
- RepositoryPermissions perms = serverPermissionsMap.get( repository.getId() );
-
- getLogger().debug(
- "adding permissions to wagon connection: " + perms.getFileMode() + " " + perms.getDirectoryMode() );
-
- artifactRepository.setPermissions( perms );
- }
- else
- {
- getLogger().debug( "not adding permissions to wagon connection" );
- }
-
wagon.connect( artifactRepository, getAuthenticationInfo( repository.getId() ), new ProxyInfoProvider()
{
public ProxyInfo getProxyInfo( String protocol )
@@ -412,8 +361,7 @@
try
{
- getRemoteFile( getMirrorRepository( repository ), artifact.getFile(), remotePath, downloadMonitor,
- policy.getChecksumPolicy(), false );
+ getRemoteFile( getMirrorRepository( repository ), artifact.getFile(), remotePath, downloadMonitor, policy.getChecksumPolicy(), false );
}
finally
{
@@ -438,8 +386,7 @@
try
{
- getRemoteFile( getMirrorRepository( repository ), artifact.getFile(), remotePath, downloadMonitor,
- policy.getChecksumPolicy(), false );
+ getRemoteFile( getMirrorRepository( repository ), artifact.getFile(), remotePath, downloadMonitor, policy.getChecksumPolicy(), false );
}
catch ( ResourceDoesNotExistException e )
{
@@ -732,26 +679,6 @@
}
}
- public ArtifactRepository getMirrorRepository( ArtifactRepository repository )
- {
- ArtifactRepository mirror = getMirror( repository );
- if ( mirror != null )
- {
- String id = mirror.getId();
- if ( id == null )
- {
- // TODO: this should be illegal in settings.xml
- id = repository.getId();
- }
-
- getLogger().debug( "Using mirror: " + mirror.getId() + " for repository: " + repository.getId() + "\n(mirror url: " + mirror.getUrl() + ")" );
- repository = repositoryFactory.createArtifactRepository( id, mirror.getUrl(),
- repository.getLayout(), repository.getSnapshots(),
- repository.getReleases() );
- }
- return repository;
- }
-
private void failIfNotOnline()
throws TransferFailedException
{
@@ -865,282 +792,12 @@
}
}
- public ProxyInfo getProxy( String protocol )
- {
- return proxies.get( protocol );
- }
-
- public AuthenticationInfo getAuthenticationInfo( String id )
- throws CredentialsDataSourceException
- {
- return credentialsDataSource == null
- ? authenticationInfoMap.get( id )
- : credentialsDataSource.get( id );
- }
-
- /**
- * This method finds a matching mirror for the selected repository. If there is an exact match, this will be used.
- * If there is no exact match, then the list of mirrors is examined to see if a pattern applies.
- *
- * @param originalRepository See if there is a mirror for this repository.
- * @return the selected mirror or null if none are found.
- */
- public ArtifactRepository getMirror( ArtifactRepository originalRepository )
- {
- ArtifactRepository selectedMirror = mirrors.get( originalRepository.getId() );
- if ( null == selectedMirror )
- {
- // Process the patterns in order. First one that matches wins.
- Set<String> keySet = mirrors.keySet();
- if ( keySet != null )
- {
- for (String pattern : keySet) {
- if (matchPattern(originalRepository, pattern)) {
- selectedMirror = mirrors.get(pattern);
- }
- }
- }
-
- }
- return selectedMirror;
- }
-
- /**
- * This method checks if the pattern matches the originalRepository.
- * Valid patterns:
- * * = everything
- * external:* = everything not on the localhost and not file based.
- * repo,repo1 = repo or repo1
- * *,!repo1 = everything except repo1
- *
- * @param originalRepository to compare for a match.
- * @param pattern used for match. Currently only '*' is supported.
- * @return true if the repository is a match to this pattern.
- */
- public boolean matchPattern( ArtifactRepository originalRepository, String pattern )
- {
- boolean result = false;
- String originalId = originalRepository.getId();
-
- // simple checks first to short circuit processing below.
- if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) )
- {
- result = true;
- }
- else
- {
- // process the list
- String[] repos = pattern.split( "," );
- for (String repo : repos) {
- // see if this is a negative match
- if (repo.length() > 1 && repo.startsWith("!")) {
- if (originalId.equals(repo.substring(1))) {
- // explicitly exclude. Set result and stop processing.
- result = false;
- break;
- }
- }
- // check for exact match
- else if (originalId.equals(repo)) {
- result = true;
- break;
- }
- // check for external:*
- else if (EXTERNAL_WILDCARD.equals(repo) && isExternalRepo(originalRepository)) {
- result = true;
- // don't stop processing in case a future segment explicitly excludes this repo
- } else if (WILDCARD.equals(repo)) {
- result = true;
- // don't stop processing in case a future segment explicitly excludes this repo
- }
- }
- }
- return result;
- }
-
- /**
- * Checks the URL to see if this repository refers to an external repository
- *
- * @param originalRepository
- * @return true if external.
- */
- public boolean isExternalRepo( ArtifactRepository originalRepository )
- {
- try
- {
- URL url = new URL( originalRepository.getUrl() );
- return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) || url.getProtocol().equals("file" ) );
- }
- catch ( MalformedURLException e )
- {
- // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it
- 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 );
- }
-
public void contextualize( Context context )
throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
- /** @todo I'd rather not be setting this explicitly. */
- public void setDownloadMonitor( TransferListener downloadMonitor )
- {
- this.downloadMonitor = downloadMonitor;
- }
-
- // 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 );
- }
-
- // This is the new way of handling authentication that will allow us to help users setup
- // authentication requirements.
- public void addAuthenticationCredentials( String repositoryId,
- String username,
- String password,
- String privateKey,
- String passphrase
- )
- throws CredentialsDataSourceException
- {
- AuthenticationInfo authInfo = new AuthenticationInfo();
- authInfo.setUserName( username );
- authInfo.setPassword( password );
- authInfo.setPrivateKey( privateKey );
- authInfo.setPassphrase( passphrase );
-
- if ( credentialsDataSource == null )
- {
- authenticationInfoMap.put( repositoryId, authInfo );
- }
- else
- {
- credentialsDataSource.set( new CredentialsChangeRequest( repositoryId, authInfo, null ) );
- }
- }
-
- 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 );
- }
- }
-
- public void addMirror( String id,
- String mirrorOf,
- String url )
- {
- if ( id == null )
- {
- id = "mirror-" + anonymousMirrorIdSeed++;
- getLogger().warn( "You are using a mirror that doesn't declare an <id/> element. Using \'" + id + "\' instead:\nId: " + id + "\nmirrorOf: " + mirrorOf + "\nurl: " + url + "\n" );
- }
-
- ArtifactRepository mirror = new DefaultArtifactRepository( id, url, null );
-
- mirrors.put( mirrorOf, mirror );
- }
-
- public void setOnline( boolean online )
- {
- this.online = online;
- }
-
- public boolean isOnline()
- {
- return online;
- }
-
- public void setInteractive( boolean interactive )
- {
- this.interactive = interactive;
- }
-
- public void findAndRegisterWagons( PlexusContainer container )
- {
- try
- {
- Map wagons = container.lookupMap( Wagon.ROLE );
-
- registerWagons( wagons.keySet(), container );
- }
- catch ( ComponentLookupException e )
- {
- // no wagons found in the extension
- }
- }
-
- /** @deprecated Wagons are discovered in plugin and extension realms now. */
- @Deprecated
- public void registerWagons( Collection wagons,
- PlexusContainer extensionContainer )
- {
- }
/**
* Applies the server configuration to the wagon
@@ -1149,16 +806,13 @@
* @param repository the repository that has the configuration
* @throws WagonConfigurationException wraps any error given during configuration of the wagon instance
*/
- private void configureWagon( Wagon wagon,
- ArtifactRepository repository )
+ private void configureWagon( Wagon wagon, ArtifactRepository repository )
throws WagonConfigurationException
{
configureWagon( wagon, repository.getId(), repository.getProtocol() );
}
- private void configureWagon( Wagon wagon,
- String repositoryId,
- String protocol )
+ private void configureWagon( Wagon wagon, String repositoryId, String protocol )
throws WagonConfigurationException
{
PlexusConfiguration config = (PlexusConfiguration) serverConfigurationMap.get( repositoryId );
@@ -1220,34 +874,6 @@
return config;
}
-
- public void addConfiguration( String repositoryId,
- Xpp3Dom configuration )
- {
- if ( ( repositoryId == null ) || ( configuration == null ) )
- {
- throw new IllegalArgumentException( "arguments can't be null" );
- }
-
- final XmlPlexusConfiguration xmlConf = new XmlPlexusConfiguration( configuration );
-
- serverConfigurationMap.put( repositoryId, xmlConf );
- }
-
- public void setDefaultRepositoryPermissions( RepositoryPermissions defaultRepositoryPermissions )
- {
- this.defaultRepositoryPermissions = defaultRepositoryPermissions;
- }
-
- public void registerCredentialsDataSource( CredentialsDataSource cds )
- {
- credentialsDataSource = cds;
- }
-
- public void setUpdateCheckManager( UpdateCheckManager updateCheckManager )
- {
- this.updateCheckManager = updateCheckManager;
- }
/**
* {@inheritDoc}
Modified: maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonManager.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonManager.java (original)
+++ maven/components/branches/MNG-3932/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonManager.java Sun Dec 21 13:14:28 2008
@@ -111,66 +111,4 @@
void getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
File file, String checksumPolicyWarn )
throws TransferFailedException, ResourceDoesNotExistException;
-
- void setOnline( boolean online );
-
- boolean isOnline();
-
- void addProxy( String protocol,
- String host,
- int port,
- String username,
- String password,
- String nonProxyHosts );
-
- void registerCredentialsDataSource( CredentialsDataSource cds );
-
- public void addAuthenticationCredentials( String repositoryId,
- String username,
- String password,
- String privateKey,
- String passphrase )
- throws CredentialsDataSourceException;
-
- void addAuthenticationInfo( String repositoryId,
- String username,
- String password,
- String privateKey,
- String passphrase );
-
- void addMirror( String id,
- String mirrorOf,
- String url );
-
- void setDownloadMonitor( TransferListener downloadMonitor );
-
- void addPermissionInfo( String repositoryId,
- String filePermissions,
- String directoryPermissions );
-
- ProxyInfo getProxy( String protocol );
-
- AuthenticationInfo getAuthenticationInfo( String id )
- throws CredentialsDataSourceException;
-
- /**
- * Set the configuration for a repository
- *
- * @param repositoryId id of the repository to set the configuration to
- * @param configuration dom tree of the xml with the configuration for the {@link Wagon}
- */
- void addConfiguration( String repositoryId,
- Xpp3Dom configuration );
-
- void setInteractive( boolean interactive );
-
- @Deprecated
- void registerWagons( Collection wagons,
- PlexusContainer extensionContainer );
-
- void findAndRegisterWagons( PlexusContainer container );
-
- void setDefaultRepositoryPermissions( RepositoryPermissions permissions );
-
- ArtifactRepository getMirrorRepository( ArtifactRepository repository );
}
Modified: maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (original)
+++ maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/DefaultMaven.java Sun Dec 21 13:14:28 2008
@@ -39,6 +39,8 @@
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.TaskValidationResult;
+import org.apache.maven.listeners.MavenModelEventProcessingException;
+import org.apache.maven.listeners.MavenModelEventProcessor;
import org.apache.maven.monitor.event.DeprecationEventDispatcher;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
@@ -79,6 +81,9 @@
@Requirement
protected RuntimeInformation runtimeInformation;
+ @Requirement
+ protected MavenModelEventProcessor modelEventProcessor;
+
private Logger logger;
// ----------------------------------------------------------------------
@@ -201,7 +206,17 @@
getLogger().info( " " + project.getName() );
}
}
-
+
+ try
+ {
+ modelEventProcessor.processModelContainers( session );
+ }
+ catch ( MavenModelEventProcessingException e )
+ {
+ result.addException( e );
+ return result;
+ }
+
try
{
lifecycleExecutor.execute( session, reactorManager, dispatcher );
Modified: maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java (original)
+++ maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java Sun Dec 21 13:14:28 2008
@@ -1,5 +1,6 @@
package org.apache.maven.listeners;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -12,6 +13,7 @@
import org.apache.maven.shared.model.DataSourceException;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelContainerFactory;
+import org.apache.maven.shared.model.ModelEventListener;
import org.apache.maven.shared.model.ModelProperty;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component;
@@ -33,7 +35,7 @@
* @author Jason van Zyl
*
*/
-@Component(role = MavenModelEventListener.class, hint="extensions", instantiationStrategy="per-lookup" )
+@Component(role = ModelEventListener.class, hint="extensions" )
public class BuildExtensionListener
implements MavenModelEventListener
{
@@ -129,14 +131,16 @@
* @param session Maven session used as the execution context for the current Maven project.
*/
public void processModelContainers( MavenSession session )
- {
+ throws MavenModelEventProcessingException
+ {
+ System.out.println( buildExtensions.size() );
for ( BuildExtension be : buildExtensions )
{
PluginResolutionRequest request = new PluginResolutionRequest()
.setPluginMetadata( new PluginMetadata( be.groupId, be.artifactId, be.version ) )
- .addLocalRepository( session.getRequest().getLocalRepositoryPath() )
+ .addLocalRepository( new File( session.getRequest().getLocalRepository().getBasedir() ) )
.setRemoteRepositories( convertToMercuryRepositories( session.getRequest().getRemoteRepositories() ) );
-
+
PluginResolutionResult result = null;
try
@@ -151,11 +155,11 @@
}
catch ( Exception e )
{
- e.printStackTrace();
+ throw new MavenModelEventProcessingException( "" );
}
}
}
-
+
List<String> convertToMercuryRepositories( List<ArtifactRepository> repositories )
{
List<String> repos = new ArrayList<String>();
@@ -164,6 +168,8 @@
{
for ( ArtifactRepository r : repositories )
{
+ System.out.println( "###### " + r );
+
repos.add( r.getUrl() );
}
}
Modified: maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/DefaultMavenModelEventProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/DefaultMavenModelEventProcessor.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/DefaultMavenModelEventProcessor.java (original)
+++ maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/DefaultMavenModelEventProcessor.java Sun Dec 21 13:14:28 2008
@@ -3,6 +3,7 @@
import java.util.List;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.shared.model.ModelEventListener;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@@ -10,11 +11,12 @@
public class DefaultMavenModelEventProcessor
implements MavenModelEventProcessor
{
- @Requirement
+ @Requirement(role = ModelEventListener.class)
List<MavenModelEventListener> listeners;
public void processModelContainers( MavenSession session )
- {
+ throws MavenModelEventProcessingException
+ {
for( MavenModelEventListener listener : listeners )
{
listener.processModelContainers( session );
Modified: maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventListener.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventListener.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventListener.java (original)
+++ maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventListener.java Sun Dec 21 13:14:28 2008
@@ -6,5 +6,6 @@
public interface MavenModelEventListener
extends ModelEventListener
{
- void processModelContainers( MavenSession session );
+ void processModelContainers( MavenSession session )
+ throws MavenModelEventProcessingException;
}
Modified: maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventProcessor.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventProcessor.java (original)
+++ maven/components/branches/MNG-3932/maven-core/src/main/java/org/apache/maven/listeners/MavenModelEventProcessor.java Sun Dec 21 13:14:28 2008
@@ -4,5 +4,6 @@
public interface MavenModelEventProcessor
{
- void processModelContainers( MavenSession session );
+ void processModelContainers( MavenSession session )
+ throws MavenModelEventProcessingException;
}
Modified: maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java (original)
+++ maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java Sun Dec 21 13:14:28 2008
@@ -35,8 +35,6 @@
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
Modified: maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java (original)
+++ maven/components/branches/MNG-3932/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java Sun Dec 21 13:14:28 2008
@@ -84,9 +84,6 @@
private PlexusContainer container;
@Requirement
- private WagonManager wagonManager;
-
- @Requirement
private MavenSettingsBuilder settingsBuilder;
@Requirement
@@ -327,8 +324,7 @@
}
}
- private void localRepository( MavenExecutionRequest request,
- Configuration configuration )
+ private void localRepository( MavenExecutionRequest request, Configuration configuration )
throws MavenEmbedderException
{
// ------------------------------------------------------------------------
@@ -402,21 +398,19 @@
if ( request.isOffline() )
{
- wagonManager.setOnline( false );
+ mavenTools.setOnline( false );
}
else if ( ( request.getSettings() != null ) && request.getSettings().isOffline() )
{
- wagonManager.setOnline( false );
+ mavenTools.setOnline( false );
}
else
{
- wagonManager.findAndRegisterWagons( container );
+ mavenTools.setInteractive( request.isInteractiveMode() );
- wagonManager.setInteractive( request.isInteractiveMode() );
+ mavenTools.setDownloadMonitor( request.getTransferListener() );
- wagonManager.setDownloadMonitor( request.getTransferListener() );
-
- wagonManager.setOnline( true );
+ mavenTools.setOnline( true );
}
try
@@ -432,54 +426,32 @@
private void resolveParameters( Settings settings )
throws ComponentLookupException, ComponentLifecycleException, SettingsConfigurationException
{
- WagonManager wagonManager = container.lookup( WagonManager.class );
+ Proxy proxy = settings.getActiveProxy();
- try
+ if ( proxy != null )
{
- Proxy proxy = settings.getActiveProxy();
-
- if ( proxy != null )
+ if ( proxy.getHost() == null )
{
- if ( proxy.getHost() == null )
- {
- throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
- }
-
- wagonManager.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts() );
- }
-
- for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
- {
- Server server = (Server) i.next();
-
- wagonManager.addAuthenticationInfo( server.getId(), server.getUsername(), server.getPassword(), server.getPrivateKey(), server.getPassphrase() );
-
- wagonManager.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() );
-
- if ( server.getConfiguration() != null )
- {
- wagonManager.addConfiguration( server.getId(), (Xpp3Dom) server.getConfiguration() );
- }
+ throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
}
- RepositoryPermissions defaultPermissions = new RepositoryPermissions();
-
- defaultPermissions.setDirectoryMode( "775" );
-
- defaultPermissions.setFileMode( "664" );
+ mavenTools.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts() );
+ }
- wagonManager.setDefaultRepositoryPermissions( defaultPermissions );
+ for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
+ {
+ Server server = (Server) i.next();
- for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
- {
- Mirror mirror = (Mirror) i.next();
+ mavenTools.addAuthenticationInfo( server.getId(), server.getUsername(), server.getPassword(), server.getPrivateKey(), server.getPassphrase() );
- wagonManager.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() );
- }
+ mavenTools.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() );
}
- finally
+
+ for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
{
- container.release( wagonManager );
+ Mirror mirror = (Mirror) i.next();
+
+ mavenTools.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() );
}
}
@@ -522,13 +494,10 @@
// Eventing
// ------------------------------------------------------------------------
- private void eventing( MavenExecutionRequest request,
- Configuration configuration )
+ private void eventing( MavenExecutionRequest request, Configuration configuration )
{
// ------------------------------------------------------------------------
// Event Monitor/Logging
- //
- //
// ------------------------------------------------------------------------
if ( ( request.getEventMonitors() == null ) || request.getEventMonitors().isEmpty() )
Modified: maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java (original)
+++ maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java Sun Dec 21 13:14:28 2008
@@ -21,18 +21,25 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
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.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -41,8 +48,11 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
-import org.apache.maven.project.MissingRepositoryElementException;
import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.apache.maven.wagon.events.TransferListener;
+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.logging.LogEnabled;
@@ -69,6 +79,9 @@
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
@Requirement
+ private WagonManager wagonManager;
+
+ @Requirement
private Logger logger;
private static HashMap<String, Artifact> cache = new HashMap<String, Artifact>();
@@ -396,4 +409,232 @@
throw new IOException( e.getMessage() );
}
}
+
+ // ------------------------------------------------------------------------
+ // Extracted from DefaultWagonManager
+ // ------------------------------------------------------------------------
+
+ private static final String WILDCARD = "*";
+
+ private static final String EXTERNAL_WILDCARD = "external:*";
+
+ private static int anonymousMirrorIdSeed = 0;
+
+ private boolean online = true;
+
+ private boolean interactive = true;
+
+ private TransferListener downloadMonitor;
+
+ private Map<String,ProxyInfo> proxies = new HashMap<String,ProxyInfo>();
+
+ private 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>();
+
+ public ArtifactRepository getMirrorRepository( ArtifactRepository repository )
+ {
+ ArtifactRepository mirror = getMirror( repository );
+ if ( mirror != null )
+ {
+ String id = mirror.getId();
+ if ( id == null )
+ {
+ // TODO: this should be illegal in settings.xml
+ id = repository.getId();
+ }
+
+ logger.debug( "Using mirror: " + mirror.getId() + " for repository: " + repository.getId() + "\n(mirror url: " + mirror.getUrl() + ")" );
+ repository = artifactRepositoryFactory.createArtifactRepository( id, mirror.getUrl(),
+ repository.getLayout(), repository.getSnapshots(),
+ repository.getReleases() );
+ }
+ return repository;
+ }
+
+ /**
+ * This method finds a matching mirror for the selected repository. If there is an exact match, this will be used.
+ * If there is no exact match, then the list of mirrors is examined to see if a pattern applies.
+ *
+ * @param originalRepository See if there is a mirror for this repository.
+ * @return the selected mirror or null if none are found.
+ */
+ public ArtifactRepository getMirror( ArtifactRepository originalRepository )
+ {
+ ArtifactRepository selectedMirror = mirrors.get( originalRepository.getId() );
+ if ( null == selectedMirror )
+ {
+ // Process the patterns in order. First one that matches wins.
+ Set<String> keySet = mirrors.keySet();
+ if ( keySet != null )
+ {
+ for ( String pattern : keySet )
+ {
+ if ( matchPattern( originalRepository, pattern ) )
+ {
+ selectedMirror = mirrors.get( pattern );
+ }
+ }
+ }
+
+ }
+ return selectedMirror;
+ }
+
+ /**
+ * This method checks if the pattern matches the originalRepository.
+ * Valid patterns:
+ * * = everything
+ * external:* = everything not on the localhost and not file based.
+ * repo,repo1 = repo or repo1
+ * *,!repo1 = everything except repo1
+ *
+ * @param originalRepository to compare for a match.
+ * @param pattern used for match. Currently only '*' is supported.
+ * @return true if the repository is a match to this pattern.
+ */
+ public boolean matchPattern( ArtifactRepository originalRepository, String pattern )
+ {
+ boolean result = false;
+ String originalId = originalRepository.getId();
+
+ // simple checks first to short circuit processing below.
+ if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) )
+ {
+ result = true;
+ }
+ else
+ {
+ // process the list
+ String[] repos = pattern.split( "," );
+ for (String repo : repos) {
+ // see if this is a negative match
+ if (repo.length() > 1 && repo.startsWith("!")) {
+ if (originalId.equals(repo.substring(1))) {
+ // explicitly exclude. Set result and stop processing.
+ result = false;
+ break;
+ }
+ }
+ // check for exact match
+ else if (originalId.equals(repo)) {
+ result = true;
+ break;
+ }
+ // check for external:*
+ else if (EXTERNAL_WILDCARD.equals(repo) && isExternalRepo(originalRepository)) {
+ result = true;
+ // don't stop processing in case a future segment explicitly excludes this repo
+ } else if (WILDCARD.equals(repo)) {
+ result = true;
+ // don't stop processing in case a future segment explicitly excludes this repo
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Checks the URL to see if this repository refers to an external repository
+ *
+ * @param originalRepository
+ * @return true if external.
+ */
+ public boolean isExternalRepo( ArtifactRepository originalRepository )
+ {
+ try
+ {
+ URL url = new URL( originalRepository.getUrl() );
+ return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) || url.getProtocol().equals("file" ) );
+ }
+ catch ( MalformedURLException e )
+ {
+ // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it
+ return false;
+ }
+ }
+
+ public void addMirror( String id, String mirrorOf, String url )
+ {
+ if ( id == null )
+ {
+ id = "mirror-" + anonymousMirrorIdSeed++;
+ logger.warn( "You are using a mirror that doesn't declare an <id/> element. Using \'" + id + "\' instead:\nId: " + id + "\nmirrorOf: " + mirrorOf + "\nurl: " + url + "\n" );
+ }
+
+ ArtifactRepository mirror = new DefaultArtifactRepository( id, url, null );
+
+ mirrors.put( mirrorOf, mirror );
+ }
+
+ public void setOnline( boolean online )
+ {
+ this.online = online;
+ }
+
+ public boolean isOnline()
+ {
+ return online;
+ }
+
+ public void setInteractive( boolean interactive )
+ {
+ this.interactive = interactive;
+ }
+
+ public void setDownloadMonitor( TransferListener downloadMonitor )
+ {
+ this.downloadMonitor = downloadMonitor;
+ }
+
+ 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 );
+ }
+
+ 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 );
+ }
+ }
}
Modified: maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/MavenTools.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/MavenTools.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/MavenTools.java (original)
+++ maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/MavenTools.java Sun Dec 21 13:14:28 2008
@@ -28,6 +28,7 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.wagon.events.TransferListener;
import java.io.IOException;
import java.util.List;
@@ -69,4 +70,30 @@
void resolve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws IOException;
+
+ // WagonManager
+
+ ArtifactRepository getMirrorRepository( ArtifactRepository repository );
+
+ ArtifactRepository getMirror( ArtifactRepository originalRepository );
+
+ boolean matchPattern( ArtifactRepository originalRepository, String pattern );
+
+ boolean isExternalRepo( ArtifactRepository originalRepository );
+
+ void addMirror( String id, String mirrorOf, String url );
+
+ void setOnline( boolean online );
+
+ boolean isOnline();
+
+ void setInteractive( boolean interactive );
+
+ void setDownloadMonitor( TransferListener downloadMonitor );
+
+ 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 );
}
Modified: maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java (original)
+++ maven/components/branches/MNG-3932/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java Sun Dec 21 13:14:28 2008
@@ -68,7 +68,7 @@
@Requirement
private MavenTools mavenTools;
- @Requirement
+ @Requirement(role = ModelEventListener.class)
List<ModelEventListener> listeners;
private Logger logger;
Modified: maven/components/branches/MNG-3932/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-3932/pom.xml?rev=728504&r1=728123&r2=728504&view=diff
==============================================================================
--- maven/components/branches/MNG-3932/pom.xml (original)
+++ maven/components/branches/MNG-3932/pom.xml Sun Dec 21 13:14:28 2008
@@ -52,7 +52,7 @@
<plexusVersion>1.0-beta-3.0.1</plexusVersion>
<plexusInteractivityVersion>1.0-alpha-6</plexusInteractivityVersion>
<plexusInterpolationVersion>1.1</plexusInterpolationVersion>
- <plexusPluginManagerVersion>1.0-alpha-1</plexusPluginManagerVersion>
+ <plexusPluginManagerVersion>1.0-SNAPSHOT</plexusPluginManagerVersion>
<plexusUtilsVersion>1.5.5</plexusUtilsVersion>
<wagonVersion>1.0-beta-4</wagonVersion>
<modelBuilderVersion>1.0</modelBuilderVersion>