* Migrating to wagon-manager 1.0-beta-3-SNAPSHOT

* Created org.apache.maven.artifact.manager.ArtifactManager
* Deprecated org.apache.maven.artifact.manager.WagonManager in favor of new ArtifactManager
* Updated the rest of maven to utilize this new ArtifactManager.
* The default wagon providers list is now managed from within wagon-manager's dependency list.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@505520 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-02-09 21:53:27 +00:00
parent 9e03384f41
commit 33f23db7de
40 changed files with 1425 additions and 1346 deletions

View File

@ -32,11 +32,6 @@
<artifactId>maven-repository-metadata</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
@ -52,7 +47,8 @@
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<artifactId>wagon-manager</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>easymock</groupId>

View File

@ -17,7 +17,7 @@ package org.apache.maven.artifact.deployer;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataDeploymentException;
@ -35,7 +35,7 @@ public class DefaultArtifactDeployer
extends AbstractLogEnabled
implements ArtifactDeployer
{
private WagonManager wagonManager;
private ArtifactManager artifactManager;
private ArtifactTransformationManager transformationManager;
@ -57,7 +57,7 @@ public class DefaultArtifactDeployer
ArtifactRepository localRepository )
throws ArtifactDeploymentException
{
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
// deployment shouldn't silently fail when offline
throw new ArtifactDeploymentException( "System is offline. Cannot deploy artifact: " + artifact + "." );
@ -74,7 +74,7 @@ public class DefaultArtifactDeployer
FileUtils.copyFile( source, artifactFile );
}
wagonManager.putArtifact( source, artifact, deploymentRepository );
artifactManager.putArtifact( source, artifact, deploymentRepository );
// must be after the artifact is installed
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )

View File

@ -0,0 +1,119 @@
package org.apache.maven.artifact.manager;
/*
* 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 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.ArtifactRepositoryPolicy;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.manager.WagonManager;
import java.io.File;
import java.util.List;
/**
* Manages artifact get and put related operations in Maven.
*
* Can get artifacts from remote repositories, or place local artifacts into remote repositories.
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$
*/
public interface ArtifactManager
{
String ROLE = ArtifactManager.class.getName();
/**
* Flag indicating state of the ArtifactManager connectivity.
*
* @return true means we are online, false means we are offline.
*/
boolean isOnline();
/**
* Get the WagonManager that this ArtifactManager is using.
*
* @return the wagon manager in use.
*/
WagonManager getWagonManager();
/**
* Get an artifact from the specified List of remoteRepositories.
*
* @param artifact the artifact to fetch.
* @param remoteRepositories the list of {@link ArtifactRepository} objects to search.
* @throws TransferFailedException if the transfer failed.
* @throws ResourceDoesNotExistException if the resource does not exist on any remote repository.
*/
void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException;
/**
* Get an {@link Artifact} from the specified {@link ArtifactRepository}.
*
* @param artifact the artifact to fetch.
* @param repository the remote repository to search.
* @throws TransferFailedException if the transfer failed.
* @throws ResourceDoesNotExistException if the resource does not exist on the remote repository.
*/
void getArtifact( Artifact artifact, ArtifactRepository repository )
throws TransferFailedException, ResourceDoesNotExistException;
/**
* Perform a Put of the source {@link File} to the {@link Artifact} on the specified {@link ArtifactRepository}
*
* @param source the file containing the artifact on the local file system.
* @param artifact the artifact to put to the remote repository.
* @param deploymentRepository the remote repository to put the artifact into.
* @throws TransferFailedException if the transfer failed.
*/
void putArtifact( File source, Artifact artifact, ArtifactRepository deploymentRepository )
throws TransferFailedException;
/**
* Perform a Put of the source {@link File} to the {@link ArtifactMetadata} on the specified {@link ArtifactRepository}
*
* @param source the file containing the metadata on the local file system.
* @param artifactMetadata the artifact metadata to put to the remote repository.
* @param repository the remote repository to put the artifact into.
* @throws TransferFailedException if the transfer failed.
*/
void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository )
throws TransferFailedException;
/**
* Get the {@link ArtifactMetadata} from the Remote {@link ArtifactRepository}.
*
* @param metadata the metadata to attempt to fetch.
* @param remoteRepository the remote repository to find the metadata in.
* @param destination the destination file on the local file system.
* @param checksumPolicy the checksum policy to use when fetching file.
* Can be either the value {@link ArtifactRepositoryPolicy#CHECKSUM_POLICY_FAIL} or
* {@link ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE}, all other values are treated as
* {@link ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE}.
* @throws TransferFailedException
* @throws ResourceDoesNotExistException
*/
void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination,
String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException;
}

View File

@ -0,0 +1,553 @@
package org.apache.maven.artifact.manager;
/*
* 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 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.ArtifactRepositoryPolicy;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
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.authorization.AuthorizationException;
import org.apache.maven.wagon.manager.NotOnlineException;
import org.apache.maven.wagon.manager.RepositoryNotFoundException;
import org.apache.maven.wagon.manager.WagonConfigurationException;
import org.apache.maven.wagon.manager.WagonManager;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* DefaultArtifactManager
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class DefaultArtifactManager
extends AbstractLogEnabled
implements ArtifactManager
{
private WagonManager wagonManager;
public void putArtifact( File source, Artifact artifact, ArtifactRepository deploymentRepository )
throws TransferFailedException
{
putRemoteFile( deploymentRepository, source, deploymentRepository.pathOf( artifact ) );
}
public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository )
throws TransferFailedException
{
getLogger().info( "Uploading " + artifactMetadata );
putRemoteFile( repository, source, repository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
}
private void putRemoteFile( ArtifactRepository repository, File source, String remotePath )
throws TransferFailedException
{
failIfNotOnline();
addWagonRepository( repository );
Wagon wagon = null;
try
{
wagon = wagonManager.getWagon( repository.getId() );
Map checksums = new HashMap( 2 );
Map sums = new HashMap( 2 );
// TODO: configure these on the repository
try
{
ChecksumObserver checksumObserver = new ChecksumObserver( "MD5" );
wagon.addTransferListener( checksumObserver );
checksums.put( "md5", checksumObserver );
checksumObserver = new ChecksumObserver( "SHA-1" );
wagon.addTransferListener( checksumObserver );
checksums.put( "sha1", checksumObserver );
}
catch ( NoSuchAlgorithmException e )
{
throw new TransferFailedException( "Unable to add checksum methods: " + e.getMessage(), e );
}
wagon.connect();
wagon.put( source, remotePath );
// Pre-store the checksums as any future puts will overwrite them
for ( Iterator i = checksums.keySet().iterator(); i.hasNext(); )
{
String extension = (String) i.next();
ChecksumObserver observer = (ChecksumObserver) checksums.get( extension );
sums.put( extension, observer.getActualChecksum() );
}
// We do this in here so we can checksum the artifact metadata too, otherwise it could be metadata itself
for ( Iterator i = checksums.keySet().iterator(); i.hasNext(); )
{
String extension = (String) i.next();
// TODO: shouldn't need a file intermediatary - improve wagon to take a stream
File temp = File.createTempFile( "maven-artifact", null );
temp.deleteOnExit();
FileUtils.fileWrite( temp.getAbsolutePath(), (String) sums.get( extension ) );
wagon.put( temp, remotePath + "." + extension );
}
}
catch ( ConnectionException e )
{
throw new TransferFailedException( "Connection failed: " + e.getMessage(), e );
}
catch ( AuthenticationException e )
{
throw new TransferFailedException( "Authentication failed: " + e.getMessage(), e );
}
catch ( AuthorizationException e )
{
throw new TransferFailedException( "Authorization failed: " + e.getMessage(), e );
}
catch ( ResourceDoesNotExistException e )
{
throw new TransferFailedException( "Resource to deploy not found: " + e.getMessage(), e );
}
catch ( IOException e )
{
throw new TransferFailedException( "Error creating temporary file for deployment: " + e.getMessage(), e );
}
catch ( UnsupportedProtocolException e )
{
throw new TransferFailedException( "Protocol not supported.", e );
}
catch ( RepositoryNotFoundException e )
{
throw new TransferFailedException( "Repository not found.", e );
}
catch ( WagonConfigurationException e )
{
throw new TransferFailedException( "Wagon configuration exception.", e );
}
catch ( NotOnlineException e )
{
throw new TransferFailedException( "Wagon has been configured to be offline: " + e.getMessage(), e );
}
finally
{
// Note: releaseWagon will disconnect too.
wagonManager.releaseWagon( wagon );
}
}
private void addWagonRepository( ArtifactRepository repository )
{
if ( repository instanceof Repository )
{
wagonManager.addRepository( (Repository) repository );
}
else
{
wagonManager.addRepository( new Repository( repository.getId(), repository.getUrl() ) );
}
}
public void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException
{
// TODO [BP]: The exception handling here needs some work
boolean successful = false;
for ( Iterator iter = remoteRepositories.iterator(); iter.hasNext() && !successful; )
{
ArtifactRepository repository = (ArtifactRepository) iter.next();
try
{
getArtifact( artifact, repository );
successful = artifact.isResolved();
}
catch ( ResourceDoesNotExistException e )
{
// This one we will eat when looking through remote repositories
// because we want to cycle through them all before squawking.
getLogger().warn(
"Unable to get resource '" + artifact.getId() + "' from repository "
+ repository.getId() + " (" + repository.getUrl() + ")" );
}
catch ( TransferFailedException e )
{
getLogger().warn(
"Unable to get resource '" + artifact.getId() + "' from repository "
+ repository.getId() + " (" + repository.getUrl() + ")" );
}
}
// if it already exists locally we were just trying to force it - ignore the update
if ( !successful && !artifact.getFile().exists() )
{
throw new ResourceDoesNotExistException( "Unable to download the artifact from any repository" );
}
}
public void getArtifact( Artifact artifact, ArtifactRepository repository )
throws TransferFailedException, ResourceDoesNotExistException
{
String remotePath = repository.pathOf( artifact );
ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots() : repository.getReleases();
if ( !policy.isEnabled() )
{
getLogger().debug( "Skipping disabled repository " + repository.getId() );
}
else if ( repository.isBlacklisted() )
{
getLogger().debug( "Skipping blacklisted repository " + repository.getId() );
}
else
{
getLogger().debug( "Trying repository " + repository.getId() );
getRemoteFile( repository, artifact.getFile(), remotePath, policy.getChecksumPolicy(), false );
getLogger().debug( " Artifact resolved" );
artifact.setResolved( true );
}
}
public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository repository, File destination,
String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException
{
String remotePath = repository.pathOfRemoteRepositoryMetadata( metadata );
getRemoteFile( repository, destination, remotePath, checksumPolicy, true );
}
private void getRemoteFile( ArtifactRepository repository, File destination, String remotePath,
String checksumPolicy, boolean force )
throws TransferFailedException, ResourceDoesNotExistException
{
// TODO: better exceptions - transfer failed is not enough?
failIfNotOnline();
addWagonRepository( repository );
Wagon wagon = null;
File temp = new File( destination + ".tmp" );
temp.deleteOnExit();
boolean downloaded = false;
try
{
wagon = wagonManager.getWagon( repository.getId() );
// TODO: configure on repository
ChecksumObserver md5ChecksumObserver;
ChecksumObserver sha1ChecksumObserver;
try
{
md5ChecksumObserver = new ChecksumObserver( "MD5" );
wagon.addTransferListener( md5ChecksumObserver );
sha1ChecksumObserver = new ChecksumObserver( "SHA-1" );
wagon.addTransferListener( sha1ChecksumObserver );
}
catch ( NoSuchAlgorithmException e )
{
throw new TransferFailedException( "Unable to add checksum methods: " + e.getMessage(), e );
}
wagon.connect();
boolean firstRun = true;
boolean retry = true;
// this will run at most twice. The first time, the firstRun flag is turned off, and if the retry flag
// is set on the first run, it will be turned off and not re-set on the second try. This is because the
// only way the retry flag can be set is if ( firstRun == true ).
while ( firstRun || retry )
{
// reset the retry flag.
retry = false;
// This should take care of creating destination directory now on
if ( destination.exists() && !force )
{
try
{
downloaded = wagon.getIfNewer( remotePath, temp, destination.lastModified() );
if ( !downloaded )
{
// prevent additional checks of this artifact until it expires again
destination.setLastModified( System.currentTimeMillis() );
}
}
catch ( UnsupportedOperationException e )
{
// older wagons throw this. Just get() instead
wagon.get( remotePath, temp );
downloaded = true;
}
}
else
{
wagon.get( remotePath, temp );
downloaded = true;
}
if ( downloaded )
{
// try to verify the SHA-1 checksum for this file.
try
{
verifyChecksum( sha1ChecksumObserver, destination, temp, remotePath, ".sha1", wagon );
}
catch ( ChecksumFailedException e )
{
// if we catch a ChecksumFailedException, it means the transfer/read succeeded, but the checksum
// doesn't match. This could be a problem with the server (ibiblio HTTP-200 error page), so we'll
// try this up to two times. On the second try, we'll handle it as a bona-fide error, based on the
// repository's checksum checking policy.
if ( firstRun )
{
getLogger().warn( "*** CHECKSUM FAILED - " + e.getMessage() + " - RETRYING" );
retry = true;
}
else
{
handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
}
}
catch ( ResourceDoesNotExistException sha1TryException )
{
getLogger().debug( "SHA1 not found, trying MD5", sha1TryException );
// if this IS NOT a ChecksumFailedException, it was a problem with transfer/read of the checksum
// file...we'll try again with the MD5 checksum.
try
{
verifyChecksum( md5ChecksumObserver, destination, temp, remotePath, ".md5", wagon );
}
catch ( ChecksumFailedException e )
{
// if we also fail to verify based on the MD5 checksum, and the checksum transfer/read
// succeeded, then we need to determine whether to retry or handle it as a failure.
if ( firstRun )
{
retry = true;
}
else
{
handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
}
}
catch ( ResourceDoesNotExistException md5TryException )
{
// this was a failed transfer, and we don't want to retry.
handleChecksumFailure( checksumPolicy, "Error retrieving checksum file for " + remotePath,
md5TryException );
}
}
}
// unset the firstRun flag, so we don't get caught in an infinite loop...
firstRun = false;
}
}
catch ( ConnectionException e )
{
throw new TransferFailedException( "Connection failed: " + e.getMessage(), e );
}
catch ( AuthenticationException e )
{
throw new TransferFailedException( "Authentication failed: " + e.getMessage(), e );
}
catch ( AuthorizationException e )
{
throw new TransferFailedException( "Authorization failed: " + e.getMessage(), e );
}
catch ( UnsupportedProtocolException e )
{
throw new TransferFailedException( "Transfer Failed: " + e.getMessage(), e );
}
catch ( RepositoryNotFoundException e )
{
throw new TransferFailedException( "Internal Error: " + e.getMessage(), e );
}
catch ( WagonConfigurationException e )
{
throw new TransferFailedException( "Wagon Configuration Error: " + e.getMessage(), e );
}
catch ( NotOnlineException e )
{
throw new TransferFailedException( "Wagon has been configured to be offline: " + e.getMessage(), e );
}
finally
{
wagonManager.releaseWagon( wagon );
}
if ( downloaded )
{
if ( !temp.exists() )
{
throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp );
}
// The temporary file is named destination + ".tmp" and is done this way to ensure
// that the temporary file is in the same file system as the destination because the
// File.renameTo operation doesn't really work across file systems.
// So we will attempt to do a File.renameTo for efficiency and atomicity, if this fails
// then we will use a brute force copy and delete the temporary file.
if ( !temp.renameTo( destination ) )
{
try
{
FileUtils.copyFile( temp, destination );
temp.delete();
}
catch ( IOException e )
{
throw new TransferFailedException( "Error copying temporary file to the final destination: "
+ e.getMessage(), e );
}
}
}
}
private void failIfNotOnline()
throws TransferFailedException
{
if ( !isOnline() )
{
throw new TransferFailedException( "System is offline." );
}
}
private void handleChecksumFailure( String checksumPolicy, String message, Throwable cause )
throws ChecksumFailedException
{
if ( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL.equals( checksumPolicy ) )
{
throw new ChecksumFailedException( message, cause );
}
else if ( !ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE.equals( checksumPolicy ) )
{
// warn if it is set to anything other than ignore
getLogger().warn( "*** CHECKSUM FAILED - " + message + " - IGNORING" );
}
// otherwise it is ignore
}
private void verifyChecksum( ChecksumObserver checksumObserver, File destination, File tempDestination,
String remotePath, String checksumFileExtension, Wagon wagon )
throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException
{
try
{
// grab it first, because it's about to change...
String actualChecksum = checksumObserver.getActualChecksum();
File tempChecksumFile = new File( tempDestination + checksumFileExtension + ".tmp" );
tempChecksumFile.deleteOnExit();
wagon.get( remotePath + checksumFileExtension, tempChecksumFile );
String expectedChecksum = FileUtils.fileRead( tempChecksumFile );
// remove whitespaces at the end
expectedChecksum = expectedChecksum.trim();
// check for 'MD5 (name) = CHECKSUM'
if ( expectedChecksum.startsWith( "MD5" ) )
{
int lastSpacePos = expectedChecksum.lastIndexOf( ' ' );
expectedChecksum = expectedChecksum.substring( lastSpacePos + 1 );
}
else
{
// remove everything after the first space (if available)
int spacePos = expectedChecksum.indexOf( ' ' );
if ( spacePos != -1 )
{
expectedChecksum = expectedChecksum.substring( 0, spacePos );
}
}
if ( expectedChecksum.equals( actualChecksum ) )
{
File checksumFile = new File( destination + checksumFileExtension );
if ( checksumFile.exists() )
{
checksumFile.delete();
}
FileUtils.copyFile( tempChecksumFile, checksumFile );
}
else
{
throw new ChecksumFailedException( "Checksum failed on download: local = '" + actualChecksum
+ "'; remote = '" + expectedChecksum + "'" );
}
}
catch ( IOException e )
{
throw new ChecksumFailedException( "Invalid checksum file", e );
}
}
public boolean isOnline()
{
return wagonManager.isOnline();
}
public WagonManager getWagonManager()
{
return wagonManager;
}
/* public void registerWagons( Collection wagons, PlexusContainer extensionContainer )
{
for ( Iterator i = wagons.iterator(); i.hasNext(); )
{
availableWagons.put( i.next(), extensionContainer );
}
}*/
}

View File

@ -1,19 +1,22 @@
package org.apache.maven.artifact.manager;
/*
* Copyright 2001-2006 The Apache Software Foundation.
* 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
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.Artifact;
@ -31,6 +34,10 @@ 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.manager.NotOnlineException;
import org.apache.maven.wagon.manager.RepositoryNotFoundException;
import org.apache.maven.wagon.manager.RepositorySettings;
import org.apache.maven.wagon.manager.WagonConfigurationException;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
@ -59,803 +66,168 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* DefaultWagonManager
*
* @version $Id$
* @deprecated in favor of {@link ArtifactManager} and {@link WagonManager}
*/
public class DefaultWagonManager
extends AbstractLogEnabled
implements WagonManager, Contextualizable
implements WagonManager
{
private static final String WILDCARD = "*";
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 proxies = new HashMap();
private Map authenticationInfoMap = new HashMap();
private Map serverPermissionsMap = new HashMap();
private Map mirrors = new HashMap();
/**
* Map( String, XmlPlexusConfiguration ) with the repository id and the wagon configuration
*/
private Map serverConfigurationMap = new HashMap();
private ArtifactManager artifactManager;
private TransferListener downloadMonitor;
private boolean online = true;
private ArtifactRepositoryFactory repositoryFactory;
private boolean interactive = true;
private Map availableWagons = new HashMap();
// 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
private RepositorySettings getRepositorySettings( String repositoryId )
{
String protocol = repository.getProtocol();
if ( protocol == null )
{
throw new UnsupportedProtocolException( "The repository " + repository + " does not specify a protocol" );
}
Wagon wagon = getWagon( protocol );
configureWagon( wagon, repository.getId() );
return wagon;
}
public Wagon getWagon( String protocol )
throws UnsupportedProtocolException
{
PlexusContainer container = getWagonContainer( protocol );
Wagon wagon;
try
{
wagon = (Wagon) container.lookup( Wagon.ROLE, protocol );
}
catch ( ComponentLookupException e1 )
{
e1.printStackTrace();
throw new UnsupportedProtocolException(
"Cannot find wagon which supports the requested protocol: " + protocol, e1 );
}
wagon.setInteractive( interactive );
return wagon;
}
private PlexusContainer getWagonContainer( String protocol )
{
PlexusContainer container = this.container;
if ( availableWagons.containsKey( protocol ) )
{
container = (PlexusContainer) availableWagons.get( protocol );
}
return container;
}
public void putArtifact( File source, Artifact artifact, ArtifactRepository deploymentRepository )
throws TransferFailedException
{
putRemoteFile( deploymentRepository, source, deploymentRepository.pathOf( artifact ), downloadMonitor );
}
public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository )
throws TransferFailedException
{
getLogger().info( "Uploading " + artifactMetadata );
putRemoteFile( repository, source, repository.pathOfRemoteRepositoryMetadata( artifactMetadata ), null );
}
private void putRemoteFile( ArtifactRepository repository, File source, String remotePath,
TransferListener downloadMonitor )
throws TransferFailedException
{
failIfNotOnline();
String protocol = repository.getProtocol();
Wagon wagon;
try
{
wagon = getWagon( protocol );
configureWagon( wagon, repository );
}
catch ( UnsupportedProtocolException e )
{
throw new TransferFailedException( "Unsupported Protocol: '" + protocol + "': " + e.getMessage(), e );
}
if ( downloadMonitor != null )
{
wagon.addTransferListener( downloadMonitor );
}
Map checksums = new HashMap( 2 );
Map sums = new HashMap( 2 );
// TODO: configure these on the repository
try
{
ChecksumObserver checksumObserver = new ChecksumObserver( "MD5" );
wagon.addTransferListener( checksumObserver );
checksums.put( "md5", checksumObserver );
checksumObserver = new ChecksumObserver( "SHA-1" );
wagon.addTransferListener( checksumObserver );
checksums.put( "sha1", checksumObserver );
}
catch ( NoSuchAlgorithmException e )
{
throw new TransferFailedException( "Unable to add checksum methods: " + e.getMessage(), e );
}
try
{
Repository artifactRepository = new Repository( repository.getId(), repository.getUrl() );
if ( serverPermissionsMap.containsKey( repository.getId() ) )
{
RepositoryPermissions perms = (RepositoryPermissions) 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() ), getProxy( protocol ) );
wagon.put( source, remotePath );
wagon.removeTransferListener( downloadMonitor );
// Pre-store the checksums as any future puts will overwrite them
for ( Iterator i = checksums.keySet().iterator(); i.hasNext(); )
{
String extension = (String) i.next();
ChecksumObserver observer = (ChecksumObserver) checksums.get( extension );
sums.put( extension, observer.getActualChecksum() );
}
// We do this in here so we can checksum the artifact metadata too, otherwise it could be metadata itself
for ( Iterator i = checksums.keySet().iterator(); i.hasNext(); )
{
String extension = (String) i.next();
// TODO: shouldn't need a file intermediatary - improve wagon to take a stream
File temp = File.createTempFile( "maven-artifact", null );
temp.deleteOnExit();
FileUtils.fileWrite( temp.getAbsolutePath(), (String) sums.get( extension ) );
wagon.put( temp, remotePath + "." + extension );
}
}
catch ( ConnectionException e )
{
throw new TransferFailedException( "Connection failed: " + e.getMessage(), e );
}
catch ( AuthenticationException e )
{
throw new TransferFailedException( "Authentication failed: " + e.getMessage(), e );
}
catch ( AuthorizationException e )
{
throw new TransferFailedException( "Authorization failed: " + e.getMessage(), e );
}
catch ( ResourceDoesNotExistException e )
{
throw new TransferFailedException( "Resource to deploy not found: " + e.getMessage(), e );
}
catch ( IOException e )
{
throw new TransferFailedException( "Error creating temporary file for deployment: " + e.getMessage(), e );
}
finally
{
disconnectWagon( wagon );
releaseWagon( protocol, wagon );
}
}
public void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException
{
// TODO [BP]: The exception handling here needs some work
boolean successful = false;
for ( Iterator iter = remoteRepositories.iterator(); iter.hasNext() && !successful; )
{
ArtifactRepository repository = (ArtifactRepository) iter.next();
try
{
getArtifact( artifact, repository );
successful = artifact.isResolved();
}
catch ( ResourceDoesNotExistException e )
{
// This one we will eat when looking through remote repositories
// because we want to cycle through them all before squawking.
getLogger().warn( "Unable to get resource '" + artifact.getId() + "' from repository " +
repository.getId() + " (" + repository.getUrl() + ")" );
}
catch ( TransferFailedException e )
{
getLogger().warn( "Unable to get resource '" + artifact.getId() + "' from repository " +
repository.getId() + " (" + repository.getUrl() + ")" );
}
}
// if it already exists locally we were just trying to force it - ignore the update
if ( !successful && !artifact.getFile().exists() )
{
throw new ResourceDoesNotExistException( "Unable to download the artifact from any repository" );
}
}
public void getArtifact( Artifact artifact, ArtifactRepository repository )
throws TransferFailedException, ResourceDoesNotExistException
{
String remotePath = repository.pathOf( artifact );
ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots() : repository.getReleases();
if ( !policy.isEnabled() )
{
getLogger().debug( "Skipping disabled repository " + repository.getId() );
}
else if ( repository.isBlacklisted() )
{
getLogger().debug( "Skipping blacklisted repository " + repository.getId() );
}
else
{
getLogger().debug( "Trying repository " + repository.getId() );
getRemoteFile( repository, artifact.getFile(), remotePath, downloadMonitor, policy.getChecksumPolicy(),
false );
getLogger().debug( " Artifact resolved" );
artifact.setResolved( true );
}
}
public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository repository, File destination,
String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException
{
String remotePath = repository.pathOfRemoteRepositoryMetadata( metadata );
getRemoteFile( repository, destination, remotePath, null, checksumPolicy, true );
}
private void getRemoteFile( ArtifactRepository repository, File destination, String remotePath,
TransferListener downloadMonitor, String checksumPolicy, boolean force )
throws TransferFailedException, ResourceDoesNotExistException
{
// TODO: better excetpions - transfer failed is not enough?
failIfNotOnline();
ArtifactRepository mirror = getMirror( repository.getId() );
if ( mirror != null )
{
repository = repositoryFactory.createArtifactRepository( mirror.getId(), mirror.getUrl(),
repository.getLayout(), repository.getSnapshots(),
repository.getReleases() );
}
String protocol = repository.getProtocol();
Wagon wagon;
try
{
wagon = getWagon( protocol );
configureWagon( wagon, repository );
}
catch ( UnsupportedProtocolException e )
{
throw new TransferFailedException( "Unsupported Protocol: '" + protocol + "': " + e.getMessage(), e );
}
if ( downloadMonitor != null )
{
wagon.addTransferListener( downloadMonitor );
}
// TODO: configure on repository
ChecksumObserver md5ChecksumObserver;
ChecksumObserver sha1ChecksumObserver;
try
{
md5ChecksumObserver = new ChecksumObserver( "MD5" );
wagon.addTransferListener( md5ChecksumObserver );
sha1ChecksumObserver = new ChecksumObserver( "SHA-1" );
wagon.addTransferListener( sha1ChecksumObserver );
}
catch ( NoSuchAlgorithmException e )
{
throw new TransferFailedException( "Unable to add checksum methods: " + e.getMessage(), e );
}
File temp = new File( destination + ".tmp" );
temp.deleteOnExit();
boolean downloaded = false;
try
{
wagon.connect( new Repository( repository.getId(), repository.getUrl() ),
getAuthenticationInfo( repository.getId() ), getProxy( protocol ) );
boolean firstRun = true;
boolean retry = true;
// this will run at most twice. The first time, the firstRun flag is turned off, and if the retry flag
// is set on the first run, it will be turned off and not re-set on the second try. This is because the
// only way the retry flag can be set is if ( firstRun == true ).
while ( firstRun || retry )
{
// reset the retry flag.
retry = false;
// This should take care of creating destination directory now on
if ( destination.exists() && !force )
{
try
{
downloaded = wagon.getIfNewer( remotePath, temp, destination.lastModified() );
if ( !downloaded )
{
// prevent additional checks of this artifact until it expires again
destination.setLastModified( System.currentTimeMillis() );
}
}
catch ( UnsupportedOperationException e )
{
// older wagons throw this. Just get() instead
wagon.get( remotePath, temp );
downloaded = true;
}
}
else
{
wagon.get( remotePath, temp );
downloaded = true;
}
if ( downloaded )
{
// keep the checksum files from showing up on the download monitor...
if ( downloadMonitor != null )
{
wagon.removeTransferListener( downloadMonitor );
}
// try to verify the SHA-1 checksum for this file.
try
{
verifyChecksum( sha1ChecksumObserver, destination, temp, remotePath, ".sha1", wagon );
}
catch ( ChecksumFailedException e )
{
// if we catch a ChecksumFailedException, it means the transfer/read succeeded, but the checksum
// doesn't match. This could be a problem with the server (ibiblio HTTP-200 error page), so we'll
// try this up to two times. On the second try, we'll handle it as a bona-fide error, based on the
// repository's checksum checking policy.
if ( firstRun )
{
getLogger().warn( "*** CHECKSUM FAILED - " + e.getMessage() + " - RETRYING" );
retry = true;
}
else
{
handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
}
}
catch ( ResourceDoesNotExistException sha1TryException )
{
getLogger().debug( "SHA1 not found, trying MD5", sha1TryException );
// if this IS NOT a ChecksumFailedException, it was a problem with transfer/read of the checksum
// file...we'll try again with the MD5 checksum.
try
{
verifyChecksum( md5ChecksumObserver, destination, temp, remotePath, ".md5", wagon );
}
catch ( ChecksumFailedException e )
{
// if we also fail to verify based on the MD5 checksum, and the checksum transfer/read
// succeeded, then we need to determine whether to retry or handle it as a failure.
if ( firstRun )
{
retry = true;
}
else
{
handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
}
}
catch ( ResourceDoesNotExistException md5TryException )
{
// this was a failed transfer, and we don't want to retry.
handleChecksumFailure( checksumPolicy, "Error retrieving checksum file for " + remotePath,
md5TryException );
}
}
// reinstate the download monitor...
if ( downloadMonitor != null )
{
wagon.addTransferListener( downloadMonitor );
}
}
// unset the firstRun flag, so we don't get caught in an infinite loop...
firstRun = false;
}
}
catch ( ConnectionException e )
{
throw new TransferFailedException( "Connection failed: " + e.getMessage(), e );
}
catch ( AuthenticationException e )
{
throw new TransferFailedException( "Authentication failed: " + e.getMessage(), e );
}
catch ( AuthorizationException e )
{
throw new TransferFailedException( "Authorization failed: " + e.getMessage(), e );
}
finally
{
disconnectWagon( wagon );
releaseWagon( protocol, wagon );
}
if ( downloaded )
{
if ( !temp.exists() )
{
throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp );
}
// The temporary file is named destination + ".tmp" and is done this way to ensure
// that the temporary file is in the same file system as the destination because the
// File.renameTo operation doesn't really work across file systems.
// So we will attempt to do a File.renameTo for efficiency and atomicity, if this fails
// then we will use a brute force copy and delete the temporary file.
if ( !temp.renameTo( destination ) )
{
try
{
FileUtils.copyFile( temp, destination );
temp.delete();
}
catch ( IOException e )
{
throw new TransferFailedException(
"Error copying temporary file to the final destination: " + e.getMessage(), e );
}
}
}
}
private void failIfNotOnline()
throws TransferFailedException
{
if ( !isOnline() )
{
throw new TransferFailedException( "System is offline." );
}
}
private void handleChecksumFailure( String checksumPolicy, String message, Throwable cause )
throws ChecksumFailedException
{
if ( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL.equals( checksumPolicy ) )
{
throw new ChecksumFailedException( message, cause );
}
else if ( !ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE.equals( checksumPolicy ) )
{
// warn if it is set to anything other than ignore
getLogger().warn( "*** CHECKSUM FAILED - " + message + " - IGNORING" );
}
// otherwise it is ignore
}
private void verifyChecksum( ChecksumObserver checksumObserver, File destination, File tempDestination,
String remotePath, String checksumFileExtension, Wagon wagon )
throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException
{
try
{
// grab it first, because it's about to change...
String actualChecksum = checksumObserver.getActualChecksum();
File tempChecksumFile = new File( tempDestination + checksumFileExtension + ".tmp" );
tempChecksumFile.deleteOnExit();
wagon.get( remotePath + checksumFileExtension, tempChecksumFile );
String expectedChecksum = FileUtils.fileRead( tempChecksumFile );
// remove whitespaces at the end
expectedChecksum = expectedChecksum.trim();
// check for 'MD5 (name) = CHECKSUM'
if ( expectedChecksum.startsWith( "MD5" ) )
{
int lastSpacePos = expectedChecksum.lastIndexOf( ' ' );
expectedChecksum = expectedChecksum.substring( lastSpacePos + 1 );
}
else
{
// remove everything after the first space (if available)
int spacePos = expectedChecksum.indexOf( ' ' );
if ( spacePos != -1 )
{
expectedChecksum = expectedChecksum.substring( 0, spacePos );
}
}
if ( expectedChecksum.equals( actualChecksum ) )
{
File checksumFile = new File( destination + checksumFileExtension );
if ( checksumFile.exists() )
{
checksumFile.delete();
}
FileUtils.copyFile( tempChecksumFile, checksumFile );
}
else
{
throw new ChecksumFailedException( "Checksum failed on download: local = '" + actualChecksum +
"'; remote = '" + expectedChecksum + "'" );
}
}
catch ( IOException e )
{
throw new ChecksumFailedException( "Invalid checksum file", e );
}
}
private void disconnectWagon( Wagon wagon )
{
try
{
wagon.disconnect();
}
catch ( ConnectionException e )
{
getLogger().error( "Problem disconnecting from wagon - ignoring: " + e.getMessage() );
}
}
private void releaseWagon( String protocol, Wagon wagon )
{
PlexusContainer container = getWagonContainer( protocol );
try
{
container.release( wagon );
}
catch ( ComponentLifecycleException e )
{
getLogger().error( "Problem releasing wagon - ignoring: " + e.getMessage() );
}
}
public ProxyInfo getProxy( String protocol )
{
return (ProxyInfo) proxies.get( protocol );
}
public AuthenticationInfo getAuthenticationInfo( String id )
{
return (AuthenticationInfo) authenticationInfoMap.get( id );
}
public ArtifactRepository getMirror( String mirrorOf )
{
ArtifactRepository repository = (ArtifactRepository) mirrors.get( mirrorOf );
if ( repository == null )
{
repository = (ArtifactRepository) mirrors.get( WILDCARD );
}
return repository;
}
/**
* 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;
return artifactManager.getWagonManager().getRepositorySettings( repositoryId );
}
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 );
}
}
public void addMirror( String id, String mirrorOf, String url )
{
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 registerWagons( Collection wagons, PlexusContainer extensionContainer )
{
for ( Iterator i = wagons.iterator(); i.hasNext(); )
{
availableWagons.put( i.next(), extensionContainer );
}
}
/**
* Applies the server configuration to the wagon
*
* @param wagon the wagon to configure
* @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 )
throws WagonConfigurationException
{
configureWagon( wagon, repository.getId() );
}
private void configureWagon( Wagon wagon, String repositoryId )
throws WagonConfigurationException
{
if ( serverConfigurationMap.containsKey( repositoryId ) )
{
ComponentConfigurator componentConfigurator = null;
try
{
componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE );
componentConfigurator.configureComponent( wagon, (PlexusConfiguration) serverConfigurationMap
.get( repositoryId ), container.getContainerRealm() );
}
catch ( final ComponentLookupException e )
{
throw new WagonConfigurationException( repositoryId,
"Unable to lookup wagon configurator. Wagon configuration cannot be applied.",
e );
}
catch ( ComponentConfigurationException e )
{
throw new WagonConfigurationException( repositoryId, "Unable to apply wagon configuration.", e );
}
finally
{
if ( componentConfigurator != null )
{
try
{
container.release( componentConfigurator );
}
catch ( ComponentLifecycleException e )
{
getLogger().error( "Problem releasing configurator - ignoring: " + e.getMessage() );
}
}
}
}
RepositorySettings settings = getRepositorySettings( repositoryId );
settings.setAuthentication( username, password, privateKey, passphrase );
}
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 );
RepositorySettings settings = getRepositorySettings( repositoryId );
settings.setConfiguration( new XmlPlexusConfiguration( configuration ) );
}
public void addMirror( String id, String mirrorOf, String url )
{
RepositorySettings settings = getRepositorySettings( mirrorOf );
Repository repository = new Repository( id, url );
artifactManager.getWagonManager().addRepository( repository );
settings.addMirror( repository.getId() );
}
public void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions )
{
RepositorySettings settings = getRepositorySettings( repositoryId );
settings.setPermissions( /* group */null, filePermissions, directoryPermissions );
}
public void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
artifactManager.getWagonManager().addProxy( protocol, host, port, username, password, nonProxyHosts );
}
public void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException
{
artifactManager.getArtifact( artifact, remoteRepositories );
}
public void getArtifact( Artifact artifact, ArtifactRepository repository )
throws TransferFailedException, ResourceDoesNotExistException
{
artifactManager.getArtifact( artifact, repository );
}
public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination,
String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException
{
artifactManager.getArtifactMetadata( metadata, remoteRepository, destination, checksumPolicy );
}
public AuthenticationInfo getAuthenticationInfo( String id )
{
RepositorySettings settings = getRepositorySettings( id );
return settings.getAuthentication();
}
public ProxyInfo getProxy( String protocol )
{
return artifactManager.getWagonManager().getProxy( protocol );
}
public Wagon getWagon( String protocol )
throws UnsupportedProtocolException
{
return null;
}
public Wagon getWagon( Repository repository )
throws UnsupportedProtocolException
{
try
{
return artifactManager.getWagonManager().getWagon( repository.getId() );
}
catch ( RepositoryNotFoundException e )
{
// Not throwing to maintain API contract.
// TODO: Need to remove this class in prior to maven 2.1 anyway.
getLogger().error( e.getMessage(), e );
}
catch ( WagonConfigurationException e )
{
// Not throwing to maintain API contract.
// TODO: Need to remove this class in prior to maven 2.1 anyway.
getLogger().error( e.getMessage(), e );
}
catch ( NotOnlineException e )
{
// Not throwing to maintain API contract.
// TODO: Need to remove this class in prior to maven 2.1 anyway.
getLogger().error( e.getMessage(), e );
}
return null;
}
public boolean isOnline()
{
return artifactManager.isOnline();
}
public void putArtifact( File source, Artifact artifact, ArtifactRepository deploymentRepository )
throws TransferFailedException
{
artifactManager.putArtifact( source, artifact, deploymentRepository );
}
public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository )
throws TransferFailedException
{
artifactManager.putArtifactMetadata( source, artifactMetadata, repository );
}
public void registerWagons( Collection wagons, PlexusContainer extensionContainer )
{
/* do nothing */
}
public void setDownloadMonitor( TransferListener monitor )
{
// Remove previous (to maintain API contract)
if ( this.downloadMonitor != null )
{
artifactManager.getWagonManager().removeTransferListener( this.downloadMonitor );
}
this.downloadMonitor = monitor;
// Add new (to maintain API contract)
if ( this.downloadMonitor != null )
{
artifactManager.getWagonManager().addTransferListener( this.downloadMonitor );
}
}
public void setInteractive( boolean interactive )
{
artifactManager.getWagonManager().setInteractive( interactive );
}
public void setOnline( boolean online )
{
artifactManager.getWagonManager().setOnline( online );
}
}

View File

@ -1,41 +0,0 @@
package org.apache.maven.artifact.manager;
import org.apache.maven.wagon.TransferFailedException;
public class WagonConfigurationException
extends TransferFailedException
{
static final long serialVersionUID = 1;
private final String originalMessage;
private final String repositoryId;
public WagonConfigurationException( String repositoryId, String message, Throwable cause )
{
super( "While configuring wagon for \'" + repositoryId + "\': " + message, cause );
this.repositoryId = repositoryId;
this.originalMessage = message;
}
public WagonConfigurationException( String repositoryId, String message )
{
super( "While configuring wagon for \'" + repositoryId + "\': " + message );
this.repositoryId = repositoryId;
this.originalMessage = message;
}
public final String getRepositoryId()
{
return repositoryId;
}
public final String getOriginalMessage()
{
return originalMessage;
}
}

View File

@ -39,6 +39,7 @@ import java.util.List;
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$
* @deprecated in favor of {@link ArtifactManager} and {@link org.apache.maven.wagon.manager.WagonManager}
*/
public interface WagonManager
{
@ -66,7 +67,7 @@ public interface WagonManager
* @throws WagonConfigurationException if the wagon can't be configured for the repository
*/
Wagon getWagon( Repository repository )
throws UnsupportedProtocolException, WagonConfigurationException;
throws UnsupportedProtocolException;
void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException;

View File

@ -16,7 +16,7 @@ package org.apache.maven.artifact.repository.metadata;
* limitations under the License.
*/
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@ -40,12 +40,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* DefaultRepositoryMetadataManager
*
* @version $Id$
*/
public class DefaultRepositoryMetadataManager
extends AbstractLogEnabled
implements RepositoryMetadataManager
{
// component requirement
private WagonManager wagonManager;
private ArtifactManager artifactManager;
/**
* @todo very primitive. Probably we can cache artifacts themselves in a central location, as well as reset the flag over time in a long running process.
@ -300,7 +305,7 @@ public class DefaultRepositoryMetadataManager
ArtifactRepository remoteRepository )
throws RepositoryMetadataResolutionException
{
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
// metadata is required for deployment, can't be offline
throw new RepositoryMetadataResolutionException(
@ -340,7 +345,7 @@ public class DefaultRepositoryMetadataManager
String checksumPolicy, boolean allowBlacklisting )
throws RepositoryMetadataResolutionException, TransferFailedException
{
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
if ( allowBlacklisting )
{
@ -358,7 +363,7 @@ public class DefaultRepositoryMetadataManager
try
{
wagonManager.getArtifactMetadata( metadata, repository, file, checksumPolicy );
artifactManager.getArtifactMetadata( metadata, repository, file, checksumPolicy );
}
catch ( ResourceDoesNotExistException e )
{
@ -391,7 +396,7 @@ public class DefaultRepositoryMetadataManager
ArtifactRepository deploymentRepository )
throws RepositoryMetadataDeploymentException
{
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
// deployment shouldn't silently fail when offline
throw new RepositoryMetadataDeploymentException(
@ -431,7 +436,7 @@ public class DefaultRepositoryMetadataManager
try
{
wagonManager.putArtifactMetadata( file, metadata, deploymentRepository );
artifactManager.putArtifactMetadata( file, metadata, deploymentRepository );
}
catch ( TransferFailedException e )
{

View File

@ -18,7 +18,7 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -52,7 +52,7 @@ public class DefaultArtifactResolver
// Components
// ----------------------------------------------------------------------
private WagonManager wagonManager;
private ArtifactManager artifactManager;
private ArtifactTransformationManager transformationManager;
@ -164,7 +164,7 @@ public class DefaultArtifactResolver
boolean resolved = false;
if ( !destination.exists() || force )
{
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
throw new ArtifactNotFoundException( "System is offline.", artifact );
}
@ -175,11 +175,11 @@ public class DefaultArtifactResolver
if ( artifact.getRepository() != null )
{
// the transformations discovered the artifact - so use it exclusively
wagonManager.getArtifact( artifact, artifact.getRepository() );
artifactManager.getArtifact( artifact, artifact.getRepository() );
}
else
{
wagonManager.getArtifact( artifact, repositories );
artifactManager.getArtifact( artifact, repositories );
}
if ( !artifact.isResolved() && !destination.exists() )

View File

@ -43,8 +43,6 @@ public abstract class AbstractVersionTransformation
{
protected RepositoryMetadataManager repositoryMetadataManager;
protected WagonManager wagonManager;
protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws RepositoryMetadataResolutionException
{

View File

@ -18,6 +18,7 @@ package org.apache.maven.artifact.transform;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
@ -43,6 +44,8 @@ import java.util.TimeZone;
public class SnapshotTransformation
extends AbstractVersionTransformation
{
private ArtifactManager artifactManager;
private String deploymentTimestamp;
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
@ -147,7 +150,7 @@ public class SnapshotTransformation
{
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
// build number is a required feature for metadata consistency
throw new RepositoryMetadataResolutionException(

View File

@ -1,8 +1,11 @@
<component-set>
<components>
<!--
|
| WagonManager
| Old WagonManager
|
| !!Deprecated!!
|
-->
<component>
@ -10,7 +13,23 @@
<implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
</requirements>
</component>
<!--
|
| ArtifactManager
|
-->
<component>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<implementation>org.apache.maven.artifact.manager.DefaultArtifactManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.wagon.manager.WagonManager</role>
<role-hint>default</role-hint>
</requirement>
</requirements>
</component>
@ -20,7 +39,7 @@
<implementation>org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
</requirements>
</component>
@ -36,7 +55,7 @@
<implementation>org.apache.maven.artifact.transform.SnapshotTransformation</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
@ -49,9 +68,6 @@
<role-hint>release</role-hint>
<implementation>org.apache.maven.artifact.transform.ReleaseArtifactTransformation</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
@ -63,9 +79,6 @@
<role-hint>latest</role-hint>
<implementation>org.apache.maven.artifact.transform.LatestArtifactTransformation</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
@ -98,7 +111,7 @@
<implementation>org.apache.maven.artifact.resolver.DefaultArtifactResolver</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
@ -140,7 +153,7 @@
<implementation>org.apache.maven.artifact.deployer.DefaultArtifactDeployer</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>

View File

@ -0,0 +1,148 @@
package org.apache.maven.artifact.manager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
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.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
public class DefaultArtifactManagerTest
extends PlexusTestCase
{
private ArtifactFactory artifactFactory;
private ArtifactManager artifactManager;
private File localTestRepo;
private File remoteTestRepo;
protected void setUp()
throws Exception
{
super.setUp();
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifactManager = (ArtifactManager) lookup( ArtifactManager.ROLE );
localTestRepo = setupDir( "target/test-classes/repositories/" + getName() + "/local-repository" );
remoteTestRepo = setupDir( "target/test-classes/repositories/" + getName() + "/remote-repository" );
}
private File setupDir( String rootPath )
throws IOException
{
File rootDir = new File( getBasedir(), rootPath );
// Clean up from old tests.
if ( rootDir.exists() )
{
FileUtils.deleteDirectory( rootDir );
}
// Create dir
rootDir.mkdirs();
return rootDir;
}
protected void tearDown()
throws Exception
{
release( artifactManager );
super.tearDown();
}
private Artifact createArtifact( String groupId, String artifactId, String version, String type )
throws Exception
{
Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
ArtifactRepository repository = localRepository();
String artifactPath = repository.pathOf( artifact );
File f = new File( localTestRepo, artifactPath );
artifact.setFile( f );
return artifact;
}
protected ArtifactRepository localRepository()
throws Exception
{
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
return new DefaultArtifactRepository( "local", "file://" + localTestRepo.getPath(), repoLayout );
}
protected ArtifactRepository remoteRepository()
throws Exception
{
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
return new DefaultArtifactRepository( "test", "file://" + remoteTestRepo.getPath(), repoLayout,
new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() );
}
public void testOnline()
throws ResourceDoesNotExistException, Exception
{
artifactManager.getWagonManager().setOnline( false );
assertFalse( artifactManager.isOnline() );
// Attempt to get a wagon.
artifactManager.getWagonManager().addRepository( new Repository( "test", "http://localhost:10007/" ) );
try
{
Artifact artifact = createArtifact( "test", "testLib", "1.0", "jar" );
artifactManager.getArtifact( artifact, localRepository() );
fail( "Should have thrown TransferFailedException as we are offline." );
}
catch ( TransferFailedException e )
{
/* expected path */
assertEquals( "System is offline.", e.getMessage() );
}
}
public void testGetArtifact()
throws ResourceDoesNotExistException, Exception
{
artifactManager.getWagonManager().setOnline( true );
assertTrue( artifactManager.isOnline() );
Artifact artifact = createArtifact( "test", "testLib", "1.0", "jar" );
setupRemoteTestArtifact( artifact );
artifactManager.getArtifact( artifact, remoteRepository() );
assertTrue( artifact.isResolved() );
assertTrue( artifact.getFile().exists() );
}
private void setupRemoteTestArtifact( Artifact artifact )
throws Exception
{
ArtifactRepository remoterepo = remoteRepository();
String artifactPath = remoterepo.pathOf( artifact );
File actualRemoteFile = new File( remoteTestRepo, artifactPath );
actualRemoteFile.getParentFile().mkdirs();
FileUtils.fileWrite( actualRemoteFile.getAbsolutePath(),
"Virtual Cess Pool of Totally Useless and Trivial Information" );
}
}

View File

@ -1,147 +0,0 @@
package org.apache.maven.artifact.manager;
/*
* Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.wagon.UnsupportedProtocolException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id$
*/
public class DefaultWagonManagerTest
extends PlexusTestCase
{
private WagonManager wagonManager;
protected void setUp()
throws Exception
{
super.setUp();
wagonManager = (WagonManager) lookup( WagonManager.ROLE );
}
public void testDefaultWagonManager()
throws Exception
{
assertWagon( "a" );
assertWagon( "b1" );
assertWagon( "b2" );
assertWagon( "c" );
try
{
assertWagon( "d" );
fail( "Expected :" + UnsupportedProtocolException.class.getName() );
}
catch ( UnsupportedProtocolException e )
{
//ok
assertTrue( true );
}
}
public void testGetWagonRepository()
throws Exception
{
assertWagonRepository( "a" );
assertWagonRepository( "b1" );
assertWagonRepository( "b2" );
assertWagonRepository( "c" );
try
{
assertWagonRepository( "d" );
fail( "Expected :" + UnsupportedProtocolException.class.getName() );
}
catch ( UnsupportedProtocolException e )
{
//ok
assertTrue( true );
}
}
public void testGetWagonRepositoryNullProtocol()
throws Exception
{
try
{
Repository repository = new Repository();
repository.setProtocol( null );
Wagon wagon = (Wagon) wagonManager.getWagon( repository );
fail( "Expected :" + UnsupportedProtocolException.class.getName() );
}
catch ( UnsupportedProtocolException e )
{
//ok
assertTrue( true );
}
}
private void assertWagon( String protocol )
throws Exception
{
Wagon wagon = (Wagon) wagonManager.getWagon( protocol );
assertNotNull( "Check wagon, protocol=" + protocol, wagon );
}
private void assertWagonRepository( String protocol )
throws Exception
{
Repository repository = new Repository();
String s = "value=" + protocol;
repository.setId( "id=" + protocol );
repository.setProtocol( protocol );
Xpp3Dom conf = new Xpp3Dom( "configuration" );
Xpp3Dom configurableField = new Xpp3Dom( "configurableField" );
configurableField.setValue( s );
conf.addChild( configurableField );
wagonManager.addConfiguration( repository.getId(), conf );
WagonMock wagon = (WagonMock) wagonManager.getWagon( repository );
assertNotNull( "Check wagon, protocol=" + protocol, wagon );
assertEquals( "Check configuration for wagon, protocol=" + protocol, s, wagon.getConfigurableField() );
}
}

View File

@ -1,46 +0,0 @@
<!--
/*
* Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<plexus>
<components>
<component>
<role>org.apache.maven.wagon.Wagon</role>
<role-hint>a</role-hint>
<implementation>org.apache.maven.artifact.manager.WagonA</implementation>
</component>
<component>
<role>org.apache.maven.wagon.Wagon</role>
<role-hint>b1</role-hint>
<implementation>org.apache.maven.artifact.manager.WagonB</implementation>
</component>
<component>
<role>org.apache.maven.wagon.Wagon</role>
<role-hint>b2</role-hint>
<implementation>org.apache.maven.artifact.manager.WagonB</implementation>
</component>
<component>
<role>org.apache.maven.wagon.Wagon</role>
<role-hint>c</role-hint>
<implementation>org.apache.maven.artifact.manager.WagonC</implementation>
</component>
<component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components>
</plexus>

View File

@ -44,7 +44,7 @@
<goal>attached</goal>
</goals>
</execution>
</executions>
</executions>
</plugin>
</plugins>
</build>
@ -62,6 +62,10 @@
<artifactId>maven-embedder</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>

View File

@ -16,6 +16,7 @@ package org.apache.maven.cli;
* limitations under the License.
*/
import org.apache.commons.lang.StringUtils;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.wagon.WagonConstants;
import org.apache.maven.wagon.events.TransferEvent;
@ -32,9 +33,37 @@ public abstract class AbstractConsoleDownloadMonitor
extends AbstractLogEnabled
implements MavenTransferListener
{
private boolean showChecksumEvents = false;
protected boolean showEvent( TransferEvent event )
{
if ( event.getResource() == null )
{
return true;
}
String resource = event.getResource().getName();
if ( StringUtils.isBlank( resource ) )
{
return true;
}
if ( resource.endsWith( ".sha1" ) || resource.endsWith( ".md5" ) )
{
return showChecksumEvents;
}
return true;
}
public void transferInitiated( TransferEvent transferEvent )
{
if ( !showEvent( transferEvent ) )
{
return;
}
String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
String url = transferEvent.getWagon().getRepository().getUrl();
@ -85,4 +114,13 @@ public abstract class AbstractConsoleDownloadMonitor
// getLogger().debug( message );
}
public boolean isShowChecksumEvents()
{
return showChecksumEvents;
}
public void setShowChecksumEvents( boolean showChecksumEvents )
{
this.showChecksumEvents = showChecksumEvents;
}
}

View File

@ -29,6 +29,11 @@ public class BatchModeDownloadMonitor
{
public void transferInitiated( TransferEvent transferEvent )
{
if ( !showEvent( transferEvent ) )
{
return;
}
String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
String url = transferEvent.getWagon().getRepository().getUrl();

View File

@ -41,6 +41,12 @@ public class ConsoleDownloadMonitor
{
long total = transferEvent.getResource().getContentLength();
complete += length;
if ( !showEvent( transferEvent ) )
{
return;
}
// TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()?
if ( total >= 1024 )
{

View File

@ -278,6 +278,8 @@ public class MavenCli
{
transferListener = new BatchModeDownloadMonitor();
}
transferListener.setShowChecksumEvents( false );
// This means to scan a directory structure for POMs and process them.
boolean useReactor = false;

View File

@ -18,6 +18,7 @@ package org.apache.maven.cli;
import junit.framework.TestCase;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.events.TransferEvent;
@ -25,6 +26,8 @@ import org.apache.maven.wagon.providers.file.FileWagon;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;
import java.io.File;
/**
* Test for {@link AbstractConsoleDownloadMonitor}
*
@ -34,19 +37,19 @@ import org.apache.maven.wagon.resource.Resource;
public abstract class AbstractConsoleDownloadMonitorTest
extends TestCase
{
private AbstractConsoleDownloadMonitor monitor;
private MavenTransferListener monitor;
public AbstractConsoleDownloadMonitorTest()
{
super();
}
public void setMonitor( AbstractConsoleDownloadMonitor monitor )
public void setMonitor( MavenTransferListener monitor )
{
this.monitor = monitor;
}
public AbstractConsoleDownloadMonitor getMonitor()
public MavenTransferListener getMonitor()
{
return monitor;
}
@ -87,6 +90,18 @@ public abstract class AbstractConsoleDownloadMonitorTest
{
monitor.debug( "msg" );
}
private class RepositoryMock
extends Repository
{
public RepositoryMock()
{
super();
setId("mock");
File basedir = new File(System.getProperty( "basedir", "." ));
setUrl( "file://" + basedir.getAbsolutePath() + "/target/" );
}
}
private class TransferEventMock
extends TransferEvent
@ -94,19 +109,19 @@ public abstract class AbstractConsoleDownloadMonitorTest
public TransferEventMock()
throws ConnectionException, AuthenticationException
{
super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
super( new FileWagon(), new RepositoryMock(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
getResource().setContentLength( 100000 );
Repository repository = new Repository();
getWagon().connect( repository );
getWagon().setRepository( new RepositoryMock() );
getWagon().connect();
}
public TransferEventMock( Exception exception )
throws ConnectionException, AuthenticationException
{
super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
super( new FileWagon(), new RepositoryMock(), new Resource(), exception, TransferEvent.REQUEST_GET );
getResource().setContentLength( 100000 );
Repository repository = new Repository();
getWagon().connect( repository );
getWagon().setRepository( new RepositoryMock() );
getWagon().connect();
}
}
}

View File

@ -37,21 +37,11 @@
<artifactId>maven-settings</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-parameter-documenter</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
@ -72,10 +62,6 @@
<artifactId>maven-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
@ -154,16 +140,6 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-tools</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>

View File

@ -1,5 +1,24 @@
package org.apache.maven;
/*
* 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 org.apache.maven.wagon.events.TransferListener;
/**
@ -9,4 +28,7 @@ import org.apache.maven.wagon.events.TransferListener;
public interface MavenTransferListener
extends TransferListener
{
public boolean isShowChecksumEvents();
public void setShowChecksumEvents( boolean showChecksumEvents );
}

View File

@ -24,7 +24,6 @@ import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -94,8 +93,6 @@ public class DefaultBuildExtensionScanner
}
getLogger().debug( "Finished pre-scanning: " + pom + " for build extensions." );
extensionManager.registerWagons();
}
catch ( ModelInterpolationException e )
{

View File

@ -20,7 +20,6 @@ import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
@ -32,11 +31,9 @@ import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.Wagon;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -45,7 +42,6 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Used to locate extensions.
@ -69,8 +65,6 @@ public class DefaultExtensionManager
private ArtifactFilterManager artifactFilterManager;
private WagonManager wagonManager;
public void addExtension( Extension extension,
Model originatingModel,
List remoteRepositories,
@ -153,19 +147,6 @@ public class DefaultExtensionManager
}
}
public void registerWagons()
{
try
{
Map wagons = container.lookupMap( Wagon.ROLE );
wagonManager.registerWagons( wagons.keySet(), container );
}
catch ( ComponentLookupException e )
{
// now wagons found in the extension
}
}
public void contextualize( Context context )
throws ContextException
{

View File

@ -37,8 +37,6 @@ public interface ExtensionManager
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException;
void registerWagons();
void addExtension( Extension extension, Model originatingModel, List remoteRepositories,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException;

View File

@ -1,31 +1,39 @@
package org.apache.maven.usability;
/*
* Copyright 2001-2005 The Apache Software Foundation.
* 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
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
/**
* ArtifactNotFoundDiagnoser
*
* @version $Id$
*/
public class ArtifactNotFoundDiagnoser
implements ErrorDiagnoser
{
private WagonManager wagonManager;
private ArtifactManager artifactManager;
public boolean canDiagnose( Throwable error )
{
@ -46,7 +54,7 @@ public class ArtifactNotFoundDiagnoser
message.append( "\n\n" );
message.append( "Reason: " ).append( exception.getMessage() );
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );
}

View File

@ -16,7 +16,7 @@ package org.apache.maven.usability;
* limitations under the License.
*/
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
@ -27,7 +27,7 @@ public class ArtifactResolverDiagnoser
implements ErrorDiagnoser
{
private WagonManager wagonManager;
private ArtifactManager artifactManager;
public boolean canDiagnose( Throwable error )
{
@ -52,7 +52,7 @@ public class ArtifactResolverDiagnoser
message.append( "\n\nCaused by I/O exception: " ).append( ioe.getMessage() );
}
if ( !wagonManager.isOnline() )
if ( !artifactManager.isOnline() )
{
message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );
}

View File

@ -82,9 +82,6 @@
<requirement>
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
</requirements>
</component>
@ -196,7 +193,7 @@
<implementation>org.apache.maven.usability.ArtifactNotFoundDiagnoser</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
</requirements>
</component>
@ -211,7 +208,7 @@
<implementation>org.apache.maven.usability.ArtifactResolverDiagnoser</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
</requirements>
</component>

View File

@ -65,6 +65,10 @@
<artifactId>maven-tools</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>

View File

@ -344,8 +344,6 @@ public class MavenEmbedder
project = mavenProjectBuilder.buildWithDependencies( new File( request.getPomFile() ),
request.getLocalRepository(), profileManager,
request.getTransferListener() );
}
catch (PluginManagerException e)
{

View File

@ -1,47 +1,75 @@
package org.apache.maven.embedder.execution;
/*
* 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 org.apache.maven.MavenTools;
import org.apache.maven.SettingsConfigurationException;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.plugin.Mojo;
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.usability.SystemWarnings;
import org.apache.maven.wagon.manager.RepositorySettings;
import org.apache.maven.wagon.manager.WagonManager;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.util.Iterator;
import org.apache.maven.MavenTools;
import org.apache.maven.SettingsConfigurationException;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Mirror;
import org.apache.maven.usability.SystemWarnings;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* DefaultMavenExecutionRequestDefaultsPopulator
*
* @version $Id$
*/
public class DefaultMavenExecutionRequestDefaultsPopulator
extends AbstractLogEnabled
implements MavenExecutionRequestDefaultsPopulator, Contextualizable
implements MavenExecutionRequestDefaultsPopulator, Contextualizable
{
private MavenTools mavenTools;
private ArtifactRepositoryFactory artifactRepositoryFactory;
private MavenTools mavenTools;
private ArtifactRepositoryFactory artifactRepositoryFactory;
private PlexusContainer container;
public MavenExecutionRequest populateDefaults(MavenExecutionRequest request)
private WagonManager wagonManager;
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request )
throws MavenEmbedderException
{
// Settings
// Settings
if ( request.getSettings() == null )
{
@ -53,9 +81,9 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
try
{
request.setSettings( mavenTools.buildSettings( userSettingsPath, globalSettingsFile, request.isInteractiveMode(),
request.isOffline(), request.isUsePluginRegistry(),
request.isUsePluginUpdateOverride() ) );
request.setSettings( mavenTools.buildSettings( userSettingsPath, globalSettingsFile, request
.isInteractiveMode(), request.isOffline(), request.isUsePluginRegistry(), request
.isUsePluginUpdateOverride() ) );
}
catch ( SettingsConfigurationException e )
{
@ -64,7 +92,7 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
}
// Local repository
if ( request.getLocalRepository() == null )
{
String localRepositoryPath = mavenTools.getLocalRepositoryPath( request.getSettings() );
@ -72,11 +100,11 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
if ( request.getLocalRepository() == null )
{
request.setLocalRepository( mavenTools.createLocalRepository( new File( localRepositoryPath ) ) );
}
}
}
// Repository update policies
boolean snapshotPolicySet = false;
if ( request.isOffline() )
@ -84,59 +112,40 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
snapshotPolicySet = true;
}
if ( !snapshotPolicySet ) {
if ( !snapshotPolicySet )
{
if ( request.isUpdateSnapshots() )
{
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
}
else if ( request.isNoSnapshotUpdates() )
{
getLogger().info( "+ Supressing SNAPSHOT updates.");
getLogger().info( "+ Supressing SNAPSHOT updates." );
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
}
}
artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() );
artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() );
// Wagon
// Wagon
wagonManager.setOnline( !request.isOffline() );
if ( request.getSettings().isOffline() )
{
getLogger().info( SystemWarnings.getOfflineWarning() );
WagonManager wagonManager = null;
try
if ( request.isOffline() )
{
wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
if ( request.isOffline() )
{
wagonManager.setOnline( false );
}
else
{
wagonManager.setInteractive( request.isInteractiveMode() );
wagonManager.setDownloadMonitor( request.getTransferListener() );
wagonManager.setOnline( true );
}
wagonManager.setOnline( false );
}
catch ( ComponentLookupException e )
else
{
throw new MavenEmbedderException( "Cannot retrieve WagonManager in order to set offline mode.", e );
}
finally
{
try
{
container.release( wagonManager );
}
catch ( ComponentLifecycleException e )
{
getLogger().warn( "Cannot release WagonManager.", e );
}
wagonManager.setInteractive( request.isInteractiveMode() );
wagonManager.addTransferListener( request.getTransferListener() );
wagonManager.setOnline( true );
}
}
@ -144,14 +153,6 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
{
resolveParameters( request.getSettings() );
}
catch ( ComponentLookupException e )
{
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
}
catch ( ComponentLifecycleException e )
{
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
}
catch ( SettingsConfigurationException e )
{
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
@ -179,51 +180,52 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
}
private void resolveParameters( Settings settings )
throws ComponentLookupException, ComponentLifecycleException, SettingsConfigurationException
throws SettingsConfigurationException
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
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() );
throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
}
for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
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();
RepositorySettings repoSetting = wagonManager.getRepositorySettings( server.getId() );
repoSetting.setAuthentication( server.getUsername(), server.getPassword(), server.getPrivateKey(), server
.getPassphrase() );
repoSetting
.setPermissions( /* group */null, server.getFilePermissions(), server.getDirectoryPermissions() );
if ( server.getConfiguration() != null )
{
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() );
}
}
for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
{
Mirror mirror = (Mirror) i.next();
wagonManager.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() );
repoSetting.setConfiguration( new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() ) );
}
}
finally
for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
{
container.release( wagonManager );
Mirror mirror = (Mirror) i.next();
try
{
wagonManager.addRepositoryMirror( mirror.getMirrorOf(), mirror.getId(), mirror.getUrl() );
}
catch ( IllegalArgumentException e )
{
throw new SettingsConfigurationException( "Unable to configure mirror " + mirror + ": "
+ e.getMessage(), e );
}
}
}

View File

@ -4,13 +4,17 @@
<role>org.apache.maven.embedder.execution.MavenExecutionRequestDefaultsPopulator</role>
<implementation>org.apache.maven.embedder.execution.DefaultMavenExecutionRequestDefaultsPopulator</implementation>
<requirements>
<requirement>
<role>org.apache.maven.wagon.manager.WagonManager</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.MavenTools</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirement>
</requirements>
</component>
</components>
</component-set>
</component-set>

View File

@ -47,6 +47,26 @@ public class MavenEmbedderTest
maven.stop();
}
private void assertNoExceptions( MavenExecutionResult result )
{
List exceptions = result.getExceptions();
if ( ( exceptions == null ) || exceptions.isEmpty() )
{
// everything is a-ok.
return;
}
System.err.println( "Encountered " + exceptions.size() + " exception(s)." );
Iterator it = exceptions.iterator();
while ( it.hasNext() )
{
Exception exception = (Exception) it.next();
exception.printStackTrace( System.err );
}
fail( "Encountered Exceptions in MavenExecutionResult during " + getName() );
}
// ----------------------------------------------------------------------
// Goal/Phase execution tests
// ----------------------------------------------------------------------
@ -60,13 +80,13 @@ public class MavenEmbedderTest
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setBaseDirectory( targetDirectory )
.setShowErrors( true )
.setGoals( Arrays.asList( new String[]{ "package" } ) );
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( targetDirectory )
.setShowErrors( true ).setGoals( Arrays.asList( new String[] { "package" } ) );
MavenExecutionResult result = maven.execute( request );
assertNoExceptions( result );
MavenProject project = result.getMavenProject();
assertEquals( "embedder-test-project", project.getArtifactId() );
@ -85,13 +105,16 @@ public class MavenEmbedderTest
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setPomFile( new File( targetDirectory, "pom.xml" ).getAbsolutePath() )
.setShowErrors( true )
.setGoals( Arrays.asList( new String[]{ "package" } ) );
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPomFile(
new File( targetDirectory,
"pom.xml" )
.getAbsolutePath() )
.setShowErrors( true ).setGoals( Arrays.asList( new String[] { "package" } ) );
MavenExecutionResult result = maven.execute( request );
assertNoExceptions( result );
MavenProject project = result.getMavenProject();
assertEquals( "embedder-test-project", project.getArtifactId() );
@ -113,11 +136,12 @@ public class MavenEmbedderTest
// Check with profile not active
MavenExecutionRequest requestWithoutProfile = new DefaultMavenExecutionRequest()
.setPomFile( new File( targetDirectory, "pom.xml" ).getAbsolutePath() )
.setShowErrors( true )
.setGoals( Arrays.asList( new String[]{ "validate" } ) );
.setPomFile( new File( targetDirectory, "pom.xml" ).getAbsolutePath() ).setShowErrors( true )
.setGoals( Arrays.asList( new String[] { "validate" } ) );
MavenExecutionResult r0 = maven.execute( requestWithoutProfile );
assertNoExceptions( r0 );
MavenProject p0 = r0.getMavenProject();
@ -129,10 +153,11 @@ public class MavenEmbedderTest
// Check with profile activated
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setPomFile( new File( targetDirectory, "pom.xml" ).getAbsolutePath() )
.setShowErrors( true )
.setGoals( Arrays.asList( new String[]{ "validate" } ) )
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPomFile(
new File( targetDirectory,
"pom.xml" )
.getAbsolutePath() )
.setShowErrors( true ).setGoals( Arrays.asList( new String[] { "validate" } ) )
.addActiveProfile( "embedderProfile" );
MavenExecutionResult r1 = maven.execute( request );
@ -191,11 +216,12 @@ public class MavenEmbedderTest
public void testProjectReading()
throws Exception
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setShowErrors( true )
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors( true )
.setPomFile( getPomFile().getAbsolutePath() );
MavenExecutionResult result = maven.readProjectWithDependencies( request );
assertNoExceptions( result );
assertEquals( "org.apache.maven", result.getMavenProject().getGroupId() );
@ -207,34 +233,34 @@ public class MavenEmbedderTest
System.out.println( "artifact = " + artifact );
}
public void testProjectWithExtensionsReading()
throws Exception
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setShowErrors( true )
.setPomFile(new File( basedir, "src/test/resources/pom2.xml" ).getAbsolutePath());
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors( true )
.setPomFile( new File( basedir, "src/test/resources/pom2.xml" ).getAbsolutePath() );
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
MavenExecutionResult result = new ExtendableMavenEmbedder(classLoader).readProjectWithDependencies( request );
// Iterator it = result.getMavenProject().getTestClasspathElements().iterator();
// while(it.hasNext()) {
// Object object = (Object) it.next();
// System.out.println(" element=" + object);
// }
MavenExecutionResult result = new ExtendableMavenEmbedder( classLoader ).readProjectWithDependencies( request );
assertNoExceptions( result );
// Iterator it = result.getMavenProject().getTestClasspathElements().iterator();
// while(it.hasNext()) {
// Object object = (Object) it.next();
// System.out.println(" element=" + object);
// }
// sources, test sources, and the junit jar..
assertEquals( 3, result.getMavenProject().getTestClasspathElements().size());
assertEquals( 3, result.getMavenProject().getTestClasspathElements().size() );
}
// ----------------------------------------------------------------------------
// Model Writing
// ----------------------------------------------------------------------------
public void testModelWriting()
public void testModelWriting()
throws Exception
{
Model model = maven.readModel( getPomFile() );
@ -262,52 +288,68 @@ public class MavenEmbedderTest
{
return new File( basedir, "src/test/resources/pom.xml" );
}
private class ExtendableMavenEmbedder extends MavenEmbedder {
public ExtendableMavenEmbedder(ClassLoader classLoader) throws MavenEmbedderException {
super( classLoader, new MavenEmbedderConsoleLogger());
private class ExtendableMavenEmbedder
extends MavenEmbedder
{
public ExtendableMavenEmbedder( ClassLoader classLoader )
throws MavenEmbedderException
{
super( classLoader, new MavenEmbedderConsoleLogger() );
}
protected Map getPluginExtensionComponents(Plugin plugin) throws PluginManagerException {
Map toReturn = new HashMap();
protected Map getPluginExtensionComponents( Plugin plugin )
throws PluginManagerException
{
Map toReturn = new HashMap();
MyArtifactHandler handler = new MyArtifactHandler();
toReturn.put("mkleint", handler);
toReturn.put( "mkleint", handler );
return toReturn;
}
protected void verifyPlugin( Plugin plugin, MavenProject project ) {
protected void verifyPlugin( Plugin plugin, MavenProject project )
{
//ignore don't want to actually verify in test
}
}
private class MyArtifactHandler implements ArtifactHandler {
public String getExtension() {
private class MyArtifactHandler
implements ArtifactHandler
{
public String getExtension()
{
return "jar";
}
public String getDirectory() {
throw new UnsupportedOperationException("Not supported yet.");
public String getDirectory()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getClassifier() {
public String getClassifier()
{
return null;
}
public String getPackaging() {
public String getPackaging()
{
return "mkleint";
}
public boolean isIncludesDependencies() {
public boolean isIncludesDependencies()
{
return false;
}
public String getLanguage() {
public String getLanguage()
{
return "java";
}
public boolean isAddedToClasspath() {
public boolean isAddedToClasspath()
{
return true;
}
}

View File

@ -78,10 +78,5 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.ArtifactStatus;
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.ArtifactManager;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -175,9 +176,11 @@ public class DefaultMavenProjectBuilder
// I am making this available for use with a new method that takes a
// a monitor wagon monitor as a parameter so that tools can use the
// methods here and receive callbacks. MNG-1015
//
// Probably no longer relevant with wagonManager/artifactManager change - joakime
// ----------------------------------------------------------------------
private WagonManager wagonManager;
private ArtifactManager artifactManager;
public static final String MAVEN_MODEL_VERSION = "4.0.0";
@ -361,7 +364,7 @@ public class DefaultMavenProjectBuilder
if ( transferListener != null )
{
wagonManager.setDownloadMonitor( transferListener );
artifactManager.getWagonManager().addTransferListener( transferListener );
}
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),

View File

@ -127,7 +127,7 @@
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
<requirement>
<role>org.apache.maven.MavenTools</role>

View File

@ -41,7 +41,7 @@
<implementation>org.apache.maven.project.TestArtifactResolver</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>

View File

@ -528,6 +528,25 @@
</field>
-->
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0</version>
<code><![CDATA[
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append( "Mirror[" );
sb.append( "id=" ).append( this.getId() );
sb.append( ",mirrorOf=" ).append( mirrorOf );
sb.append( ",url=" ).append( this.url );
sb.append( ",name=" ).append( this.name );
sb.append( "]" );
return sb.toString();
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<!-- Profile support -->
<class>

29
pom.xml
View File

@ -168,7 +168,6 @@
<module>maven-tools</module>
</modules>
<properties>
<wagonVersion>1.0-beta-3-SNAPSHOT</wagonVersion>
<plexusVersion>1.0-alpha-16</plexusVersion>
</properties>
<dependencies>
@ -190,7 +189,7 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
<version>${plexusVersion}</version>
</dependency>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
@ -201,30 +200,20 @@
<artifactId>plexus-utils</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>${wagonVersion}</version>
<version>1.0-beta-3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>${wagonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>${wagonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<version>${wagonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>${wagonVersion}</version>
<artifactId>wagon-manager</artifactId>
<version>1.0-beta-3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>easymock</groupId>