o roll back to wagon beta-2 to fix the rash of problems with m2eclipse plugin

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@516654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-03-10 05:38:50 +00:00
parent d8689fd0f5
commit badcd2287f
28 changed files with 938 additions and 1210 deletions

View File

@ -16,13 +16,13 @@
# under the License.
classworlds.version=1.2-alpha-7
plexus.version=1.0-alpha-19-SNAPSHOT
plexus.version=1.0-alpha-19
plexus-archiver.version=1.0-alpha-8
plexus-utils.version=1.4
plexus-interactivity-api.version=1.0-alpha-6-SNAPSHOT
commons-cli.version=1.0
commons-lang.version=2.1
wagon.version=1.0-beta-3-SNAPSHOT
wagon.version=1.0-beta-2
jsch.version=0.1.27
doxia.version=1.0-alpha-9-SNAPSHOT
modello.version=1.0-alpha-13

View File

@ -10,6 +10,6 @@ mv target/maven-2.1-SNAPSHOT-sources.jar $dir/maven-embedder-$ds-depsrc.zip
cd maven-embedder
sed "s@<bundleVersion>.*</bundleVersion>@<bundleVersion>$ds</bundleVersion>@" pom.xml > tmp; mv tmp pom.xml
mvn clean assembly:assembly
mv target/maven-embedder-$ds-dep.jar $dir
mvn clean install
mv target/maven-embedder-*-ueber.jar $dir/maven-embedder-$ds-dep.jar
)

View File

@ -50,8 +50,11 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-manager</artifactId>
<scope>compile</scope>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
</dependency>
<dependency>
<groupId>easymock</groupId>

View File

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

View File

@ -1,138 +0,0 @@
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.
*/
/*
* 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

@ -1,572 +0,0 @@
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.
*/
/*
* 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,24 +1,5 @@
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.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -41,189 +22,838 @@ package org.apache.maven.artifact.manager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
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.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;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
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.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.HashMap;
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
implements WagonManager, Contextualizable
{
private ArtifactManager artifactManager;
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 TransferListener downloadMonitor;
private RepositorySettings getRepositorySettings( String repositoryId )
{
return artifactManager.getWagonManager().getRepositorySettings( repositoryId );
}
private boolean online = true;
public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey,
String passphrase )
{
RepositorySettings settings = getRepositorySettings( repositoryId );
settings.setAuthentication( username, password, privateKey, passphrase );
}
private ArtifactRepositoryFactory repositoryFactory;
public void addConfiguration( String repositoryId, Xpp3Dom configuration )
{
RepositorySettings settings = getRepositorySettings( repositoryId );
settings.setConfiguration( new XmlPlexusConfiguration( configuration ) );
}
private boolean interactive = true;
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() );
}
private Map availableWagons = new HashMap();
public void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions )
// 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
{
RepositorySettings settings = getRepositorySettings( repositoryId );
settings.setPermissions( /* group */null, filePermissions, directoryPermissions );
}
String protocol = repository.getProtocol();
public void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
artifactManager.getWagonManager().addProxy( protocol, host, port, username, password, nonProxyHosts );
}
if ( protocol == null )
{
throw new UnsupportedProtocolException( "The repository " + repository + " does not specify a protocol" );
}
public void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException
{
artifactManager.getArtifact( artifact, remoteRepositories );
}
Wagon wagon = getWagon( protocol );
public void getArtifact( Artifact artifact, ArtifactRepository repository )
throws TransferFailedException, ResourceDoesNotExistException
{
artifactManager.getArtifact( artifact, repository );
}
configureWagon( wagon, repository.getId() );
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 );
return wagon;
}
public Wagon getWagon( String protocol )
throws UnsupportedProtocolException
{
return null;
}
PlexusContainer container = getWagonContainer( protocol );
public Wagon getWagon( Repository repository )
throws UnsupportedProtocolException
{
Wagon wagon;
try
{
return artifactManager.getWagonManager().getWagon( repository.getId() );
wagon = (Wagon) container.lookup( Wagon.ROLE, protocol );
}
catch ( RepositoryNotFoundException e )
catch ( ComponentLookupException e1 )
{
// 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 );
throw new UnsupportedProtocolException(
"Cannot find wagon which supports the requested protocol: " + protocol, e1 );
}
return null;
wagon.setInteractive( interactive );
return wagon;
}
public boolean isOnline()
private PlexusContainer getWagonContainer( String protocol )
{
return artifactManager.isOnline();
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
{
artifactManager.putArtifact( source, artifact, deploymentRepository );
putRemoteFile( deploymentRepository, source, deploymentRepository.pathOf( artifact ), downloadMonitor );
}
public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository )
throws TransferFailedException
{
artifactManager.putArtifactMetadata( source, artifactMetadata, repository );
getLogger().info( "Uploading " + artifactMetadata );
putRemoteFile( repository, source, repository.pathOfRemoteRepositoryMetadata( artifactMetadata ), null );
}
public void registerWagons( Collection wagons, PlexusContainer extensionContainer )
private void putRemoteFile( ArtifactRepository repository, File source, String remotePath,
TransferListener downloadMonitor )
throws TransferFailedException
{
/* do nothing */
}
failIfNotOnline();
public void setDownloadMonitor( TransferListener monitor )
{
// Remove previous (to maintain API contract)
if ( this.downloadMonitor != null )
String protocol = repository.getProtocol();
Wagon wagon;
try
{
artifactManager.getWagonManager().removeTransferListener( this.downloadMonitor );
wagon = getWagon( protocol );
configureWagon( wagon, repository );
}
catch ( UnsupportedProtocolException e )
{
throw new TransferFailedException( "Unsupported Protocol: '" + protocol + "': " + e.getMessage(), e );
}
this.downloadMonitor = monitor;
// Add new (to maintain API contract)
if ( this.downloadMonitor != null )
if ( downloadMonitor != null )
{
artifactManager.getWagonManager().addTransferListener( this.downloadMonitor );
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 setInteractive( boolean interactive )
public void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException
{
artifactManager.getWagonManager().setInteractive( interactive );
// 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;
}
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 )
{
artifactManager.getWagonManager().setOnline( 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 = new BasicComponentConfigurator();
componentConfigurator.configureComponent( wagon, (PlexusConfiguration) serverConfigurationMap
.get( repositoryId ), container.getContainerRealm() );
}
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() );
}
}
}
}
}
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 );
}
}

View File

@ -42,7 +42,6 @@ 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
{
@ -70,7 +69,7 @@ public interface WagonManager
* @throws WagonConfigurationException if the wagon can't be configured for the repository
*/
Wagon getWagon( Repository repository )
throws UnsupportedProtocolException;
throws UnsupportedProtocolException, WagonConfigurationException;
void getArtifact( Artifact artifact, List remoteRepositories )
throws TransferFailedException, ResourceDoesNotExistException;

View File

@ -19,7 +19,7 @@ package org.apache.maven.artifact.repository.metadata;
* under the License.
*/
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@ -43,17 +43,12 @@ 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 ArtifactManager artifactManager;
private WagonManager wagonManager;
/**
* @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.
@ -308,7 +303,7 @@ public class DefaultRepositoryMetadataManager
ArtifactRepository remoteRepository )
throws RepositoryMetadataResolutionException
{
if ( !artifactManager.isOnline() )
if ( !wagonManager.isOnline() )
{
// metadata is required for deployment, can't be offline
throw new RepositoryMetadataResolutionException(
@ -348,7 +343,7 @@ public class DefaultRepositoryMetadataManager
String checksumPolicy, boolean allowBlacklisting )
throws RepositoryMetadataResolutionException, TransferFailedException
{
if ( !artifactManager.isOnline() )
if ( !wagonManager.isOnline() )
{
if ( allowBlacklisting )
{
@ -366,7 +361,7 @@ public class DefaultRepositoryMetadataManager
try
{
artifactManager.getArtifactMetadata( metadata, repository, file, checksumPolicy );
wagonManager.getArtifactMetadata( metadata, repository, file, checksumPolicy );
}
catch ( ResourceDoesNotExistException e )
{
@ -399,7 +394,7 @@ public class DefaultRepositoryMetadataManager
ArtifactRepository deploymentRepository )
throws RepositoryMetadataDeploymentException
{
if ( !artifactManager.isOnline() )
if ( !wagonManager.isOnline() )
{
// deployment shouldn't silently fail when offline
throw new RepositoryMetadataDeploymentException(
@ -439,7 +434,7 @@ public class DefaultRepositoryMetadataManager
try
{
artifactManager.putArtifactMetadata( file, metadata, deploymentRepository );
wagonManager.putArtifactMetadata( file, metadata, deploymentRepository );
}
catch ( TransferFailedException e )
{

View File

@ -21,7 +21,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.ArtifactManager;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -55,7 +55,7 @@ public class DefaultArtifactResolver
// Components
// ----------------------------------------------------------------------
private ArtifactManager artifactManager;
private WagonManager wagonManager;
private ArtifactTransformationManager transformationManager;
@ -89,7 +89,7 @@ public class DefaultArtifactResolver
{
File systemFile = artifact.getFile();
if ( systemFile == null || !systemFile.exists() )
if ( !systemFile.exists() )
{
throw new ArtifactNotFoundException(
"System artifact: " + artifact + " not found in path: " + systemFile, artifact );
@ -167,7 +167,7 @@ public class DefaultArtifactResolver
boolean resolved = false;
if ( !destination.exists() || force )
{
if ( !artifactManager.isOnline() )
if ( !wagonManager.isOnline() )
{
throw new ArtifactNotFoundException( "System is offline.", artifact );
}
@ -178,11 +178,11 @@ public class DefaultArtifactResolver
if ( artifact.getRepository() != null )
{
// the transformations discovered the artifact - so use it exclusively
artifactManager.getArtifact( artifact, artifact.getRepository() );
wagonManager.getArtifact( artifact, artifact.getRepository() );
}
else
{
artifactManager.getArtifact( artifact, repositories );
wagonManager.getArtifact( artifact, repositories );
}
if ( !artifact.isResolved() && !destination.exists() )

View File

@ -20,6 +20,7 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
@ -45,6 +46,8 @@ public abstract class AbstractVersionTransformation
{
protected RepositoryMetadataManager repositoryMetadataManager;
protected WagonManager wagonManager;
protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws RepositoryMetadataResolutionException
{

View File

@ -21,7 +21,6 @@ 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;
@ -47,14 +46,14 @@ 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" );
private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
@ -153,7 +152,7 @@ public class SnapshotTransformation
{
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
if ( !artifactManager.isOnline() )
if ( !wagonManager.isOnline() )
{
// build number is a required feature for metadata consistency
throw new RepositoryMetadataResolutionException(

View File

@ -19,12 +19,9 @@ under the License.
<component-set>
<components>
<!--
|
| Old WagonManager
|
| !!Deprecated!!
| WagonManager
|
-->
<component>
@ -32,23 +29,7 @@ under the License.
<implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
<requirements>
<requirement>
<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>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirements>
</component>
@ -58,7 +39,7 @@ under the License.
<implementation>org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
</requirements>
</component>
@ -74,7 +55,7 @@ under the License.
<implementation>org.apache.maven.artifact.transform.SnapshotTransformation</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
@ -87,6 +68,9 @@ under the License.
<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>
@ -98,6 +82,9 @@ under the License.
<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>
@ -128,10 +115,9 @@ under the License.
<component>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
<implementation>org.apache.maven.artifact.resolver.DefaultArtifactResolver</implementation>
<role-hint>default</role-hint>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
@ -173,7 +159,7 @@ under the License.
<implementation>org.apache.maven.artifact.deployer.DefaultArtifactDeployer</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>

View File

@ -1,167 +0,0 @@
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.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

@ -0,0 +1,47 @@
<!--
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.
-->
<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

@ -38,7 +38,6 @@ under the License.
-->
<component>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager</implementation>
<requirements>
<requirement>
@ -194,7 +193,6 @@ under the License.
<component>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.artifact.factory.DefaultArtifactFactory</implementation>
<requirements>
<requirement>
@ -205,7 +203,6 @@ under the License.
<component>
<role>org.apache.maven.artifact.resolver.ArtifactCollector</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.artifact.resolver.DefaultArtifactCollector</implementation>
</component>
</components>

View File

@ -20,8 +20,10 @@ package org.apache.maven.extension;
*/
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -34,7 +36,6 @@ 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.manager.WagonManager;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
@ -47,6 +48,7 @@ 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.
@ -158,7 +160,9 @@ public class DefaultExtensionManager
{
try
{
wagonManager.registerExtensionContainer( container );
Map wagons = container.lookupMap( Wagon.ROLE );
wagonManager.registerWagons( wagons.keySet(), container );
}
catch ( ComponentLookupException e )
{

View File

@ -19,40 +19,16 @@ package org.apache.maven.usability;
* under the License.
*/
/*
* 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.manager.ArtifactManager;
import org.apache.maven.artifact.manager.WagonManager;
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 ArtifactManager artifactManager;
private WagonManager wagonManager;
public boolean canDiagnose( Throwable error )
{
@ -73,7 +49,7 @@ public class ArtifactNotFoundDiagnoser
message.append( "\n\n" );
message.append( "Reason: " ).append( exception.getMessage() );
if ( !artifactManager.isOnline() )
if ( !wagonManager.isOnline() )
{
message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );
}

View File

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

View File

@ -107,7 +107,7 @@ under the License.
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.wagon.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role-hint>default</role-hint>
</requirement>
</requirements>
@ -221,7 +221,7 @@ under the License.
<implementation>org.apache.maven.usability.ArtifactNotFoundDiagnoser</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
</requirements>
</component>
@ -236,7 +236,7 @@ under the License.
<implementation>org.apache.maven.usability.ArtifactResolverDiagnoser</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
</requirements>
</component>

View File

@ -30,7 +30,7 @@ under the License.
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<properties>
<bundleVersion>2.1.0.v20070228-1415</bundleVersion>
<bundleVersion>2.1.0.v20070309-1753</bundleVersion>
</properties>
<build>
<resources>

View File

@ -20,6 +20,7 @@ package org.apache.maven.embedder.execution;
*/
import org.apache.maven.SettingsConfigurationException;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
@ -33,11 +34,10 @@ 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.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
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;
@ -115,7 +115,7 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
{
wagonManager.setInteractive( request.isInteractiveMode() );
wagonManager.addTransferListener( request.getTransferListener() );
wagonManager.setDownloadMonitor( request.getTransferListener() );
wagonManager.setOnline( true );
}
@ -124,7 +124,7 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
{
resolveParameters( request.getSettings() );
}
catch ( SettingsConfigurationException e )
catch ( Exception e )
{
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
}
@ -151,52 +151,51 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
}
private void resolveParameters( Settings settings )
throws SettingsConfigurationException
throws ComponentLookupException, ComponentLifecycleException, SettingsConfigurationException
{
Proxy proxy = settings.getActiveProxy();
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
if ( proxy != null )
try
{
if ( proxy.getHost() == null )
Proxy proxy = settings.getActiveProxy();
if ( proxy != null )
{
throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
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() );
}
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 )
for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
{
repoSetting.setConfiguration( new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() ) );
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() );
}
}
for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
finally
{
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 );
}
container.release( wagonManager );
}
}

View File

@ -24,7 +24,7 @@ under the License.
<implementation>org.apache.maven.embedder.execution.DefaultMavenExecutionRequestDefaultsPopulator</implementation>
<requirements>
<requirement>
<role>org.apache.maven.wagon.manager.WagonManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role-hint>default</role-hint>
</requirement>
<requirement>

View File

@ -20,7 +20,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;
@ -28,8 +28,6 @@ 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}
*
@ -39,19 +37,20 @@ import java.io.File;
public abstract class AbstractConsoleDownloadMonitorTest
extends TestCase
{
private MavenTransferListener monitor;
private AbstractConsoleDownloadMonitor monitor;
public AbstractConsoleDownloadMonitorTest()
{
super();
}
public void setMonitor( MavenTransferListener monitor )
public void setMonitor( AbstractConsoleDownloadMonitor monitor )
{
this.monitor = monitor;
}
public MavenTransferListener getMonitor()
public AbstractConsoleDownloadMonitor getMonitor()
{
return monitor;
}
@ -92,18 +91,6 @@ 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
@ -111,19 +98,19 @@ public abstract class AbstractConsoleDownloadMonitorTest
public TransferEventMock()
throws ConnectionException, AuthenticationException
{
super( new FileWagon(), new RepositoryMock(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
getResource().setContentLength( 100000 );
getWagon().setRepository( new RepositoryMock() );
getWagon().connect();
Repository repository = new Repository();
getWagon().connect( repository );
}
public TransferEventMock( Exception exception )
throws ConnectionException, AuthenticationException
{
super( new FileWagon(), new RepositoryMock(), new Resource(), exception, TransferEvent.REQUEST_GET );
super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
getResource().setContentLength( 100000 );
getWagon().setRepository( new RepositoryMock() );
getWagon().connect();
Repository repository = new Repository();
getWagon().connect( repository );
}
}
}
}

View File

@ -43,8 +43,8 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactStatus;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.ArtifactManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@ -195,10 +195,10 @@ public class DefaultMavenProjectBuilder
// 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
// Probably no longer relevant with wagonManager/wagonManager change - joakime
// ----------------------------------------------------------------------
private ArtifactManager artifactManager;
private WagonManager wagonManager;
public static final String MAVEN_MODEL_VERSION = "4.0.0";
@ -382,7 +382,7 @@ public class DefaultMavenProjectBuilder
if ( transferListener != null )
{
artifactManager.getWagonManager().addTransferListener( transferListener );
wagonManager.setDownloadMonitor( transferListener );
}
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),

View File

@ -30,7 +30,7 @@ under the License.
<role-hint>project-cache-aware</role-hint>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
@ -185,7 +185,7 @@ under the License.
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.MavenTools</role>

View File

@ -59,9 +59,11 @@ under the License.
<role>org.apache.maven.project.TestArtifactResolver</role>
<implementation>org.apache.maven.project.TestArtifactResolver</implementation>
<requirements>
<!--
<requirement>
<role>org.apache.maven.artifact.manager.ArtifactManager</role>
</requirement>
-->
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
@ -120,4 +122,4 @@ under the License.
</requirements>
</component>
</components>
</plexus>
</plexus>

38
pom.xml
View File

@ -39,33 +39,6 @@ under the License.
<url>http://jira.codehaus.org/browse/MNG</url>
</issueManagement>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- For plexus snapshots -->
<repositories>
<repository>
<id>codehaus.snapshots</id>
<url>http://snapshots.repository.codehaus.org</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<mailingLists>
<mailingList>
<name>Maven User List</name>
@ -163,8 +136,8 @@ under the License.
<module>maven-embedder</module>
</modules>
<properties>
<plexusVersion>1.0-alpha-19-SNAPSHOT</plexusVersion>
<wagonVersion>1.0-beta-3-SNAPSHOT</wagonVersion>
<plexusVersion>1.0-alpha-19</plexusVersion>
<wagonVersion>1.0-beta-2</wagonVersion>
</properties>
<dependencies>
<dependency>
@ -198,7 +171,12 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-manager</artifactId>
<artifactId>wagon-provider-api</artifactId>
<version>${wagonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<version>${wagonVersion}</version>
</dependency>
<dependency>