PR: MNG-1110

differentiate between an artifact that is not found, and failure to obtain an artifact

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307034 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-07 06:44:59 +00:00
parent 152130b172
commit 245d512c4a
31 changed files with 660 additions and 371 deletions

View File

@ -21,6 +21,7 @@ import org.apache.maven.archetype.descriptor.ArchetypeDescriptorBuilder;
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.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Build;
@ -66,8 +67,8 @@ public class DefaultArchetype
private static final String DEFAULT_RESOURCE_DIR = "/src/main/resources";
private static final String DEFAULT_SOURCE_DIR = "/src/main/java";
private VelocityComponent velocity;
private ArtifactResolver artifactResolver;
@ -82,12 +83,8 @@ public class DefaultArchetype
// artifactId = maven-foo-archetype
// version = latest
public void createArchetype( String archetypeGroupId,
String archetypeArtifactId,
String archetypeVersion,
ArtifactRepository localRepository,
List remoteRepositories,
Map parameters )
public void createArchetype( String archetypeGroupId, String archetypeArtifactId, String archetypeVersion,
ArtifactRepository localRepository, List remoteRepositories, Map parameters )
throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException
{
// ----------------------------------------------------------------------
@ -102,6 +99,11 @@ public class DefaultArchetype
artifactResolver.resolve( archetypeArtifact, remoteRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
// TODO: this is an error now, not "not found"
throw new ArchetypeNotFoundException( "Cannot download archetype.", e );
}
catch ( ArtifactNotFoundException e )
{
throw new ArchetypeNotFoundException( "Cannot download archetype.", e );
}
@ -115,7 +117,8 @@ public class DefaultArchetype
{
getLogger().info( "----------------------------------------------------------------------------" );
getLogger().info( "Using following parameters for creating Archetype: " + archetypeArtifactId + ":" + archetypeVersion );
getLogger().info( "Using following parameters for creating Archetype: " + archetypeArtifactId + ":" +
archetypeVersion );
getLogger().info( "----------------------------------------------------------------------------" );
@ -160,7 +163,8 @@ public class DefaultArchetype
if ( is == null )
{
throw new ArchetypeDescriptorException( "The " + ARCHETYPE_DESCRIPTOR + " descriptor cannot be found." );
throw new ArchetypeDescriptorException(
"The " + ARCHETYPE_DESCRIPTOR + " descriptor cannot be found." );
}
descriptor = (ArchetypeDescriptor) builder.build( new InputStreamReader( is ) );
@ -192,7 +196,8 @@ public class DefaultArchetype
if ( outputDirectoryFile.exists() )
{
throw new ArchetypeTemplateProcessingException( outputDirectoryFile.getName() + " already exists - please run from a clean directory" );
throw new ArchetypeTemplateProcessingException(
outputDirectoryFile.getName() + " already exists - please run from a clean directory" );
}
pomFile = new File( outputDirectoryFile, ARCHETYPE_POM );
@ -263,14 +268,15 @@ public class DefaultArchetype
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "********************* Debug info for resources created from generated Model ***********************" );
getLogger().debug(
"********************* Debug info for resources created from generated Model ***********************" );
}
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Was build element found in generated POM?: " + foundBuildElement );
}
// create source directory if specified in POM
if ( foundBuildElement && null != build.getSourceDirectory() )
{
@ -285,7 +291,8 @@ public class DefaultArchetype
srcDirectory = StringUtils.replace( srcDirectory, "\\", "/" );
FileUtils.mkdir( outputDirectory + ( srcDirectory.startsWith( "/" ) ? srcDirectory : ( "/" + srcDirectory ) ) );
FileUtils.mkdir(
outputDirectory + ( srcDirectory.startsWith( "/" ) ? srcDirectory : ( "/" + srcDirectory ) ) );
}
// create script source directory if specified in POM
@ -303,7 +310,7 @@ public class DefaultArchetype
scriptSourceDirectory = StringUtils.replace( scriptSourceDirectory, "\\", "/" );
FileUtils.mkdir( outputDirectory + ( scriptSourceDirectory.startsWith( "/" ) ? scriptSourceDirectory
: ( "/" + scriptSourceDirectory ) ) );
: ( "/" + scriptSourceDirectory ) ) );
}
// create resource director(y/ies) if specified in POM
@ -326,7 +333,8 @@ public class DefaultArchetype
resourceDirectory = StringUtils.replace( resourceDirectory, "\\", "/" );
FileUtils.mkdir( outputDirectory + ( resourceDirectory.startsWith( "/" ) ? resourceDirectory : ( "/" + resourceDirectory ) ) );
FileUtils.mkdir( outputDirectory +
( resourceDirectory.startsWith( "/" ) ? resourceDirectory : ( "/" + resourceDirectory ) ) );
}
}
// create test source directory if specified in POM
@ -343,7 +351,8 @@ public class DefaultArchetype
testDirectory = StringUtils.replace( testDirectory, "\\", "/" );
FileUtils.mkdir( outputDirectory + ( testDirectory.startsWith( "/" ) ? testDirectory : ( "/" + testDirectory ) ) );
FileUtils.mkdir(
outputDirectory + ( testDirectory.startsWith( "/" ) ? testDirectory : ( "/" + testDirectory ) ) );
}
// create test resource directory if specified in POM
@ -367,11 +376,12 @@ public class DefaultArchetype
testResourceDirectory = StringUtils.replace( testResourceDirectory, "\\", "/" );
FileUtils.mkdir( outputDirectory + ( testResourceDirectory.startsWith( "/" ) ? testResourceDirectory
: ( "/" + testResourceDirectory ) ) );
: ( "/" + testResourceDirectory ) ) );
}
}
getLogger().info( "********************* End of debug info from resources from generated POM ***********************" );
getLogger().info(
"********************* End of debug info from resources from generated POM ***********************" );
// ----------------------------------------------------------------------
// Main
@ -473,8 +483,8 @@ public class DefaultArchetype
}
}
protected void processTemplate( String outputDirectory, Context context, String template,
boolean packageInFileName, String packageName )
protected void processTemplate( String outputDirectory, Context context, String template, boolean packageInFileName,
String packageName )
throws Exception
{
File f;

View File

@ -21,6 +21,7 @@ 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;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -177,6 +178,11 @@ public class DependenciesTask
{
throw new BuildException( "Unable to resolve artifact", e );
}
catch ( ArtifactNotFoundException e )
{
// TODO: improve handling
throw new BuildException( "Unable to locate artifact", e );
}
if ( pathId != null && getProject().getReference( pathId ) != null )
{

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -105,6 +106,10 @@ public class InstallWagonProviderTask
{
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
}
catch ( ArtifactNotFoundException e )
{
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
}
}
}

View File

@ -59,20 +59,20 @@ public class DefaultArtifactResolver
// ----------------------------------------------------------------------
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
resolve( artifact, remoteRepositories, localRepository, false );
}
public void resolveAlways( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
resolve( artifact, remoteRepositories, localRepository, true );
}
private void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository,
boolean force )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
if ( artifact != null )
{
@ -82,7 +82,7 @@ public class DefaultArtifactResolver
if ( !systemFile.exists() )
{
throw new ArtifactResolutionException(
throw new ArtifactNotFoundException(
"System artifact: " + artifact.getId() + " not found in path: " + systemFile, artifact );
}
else
@ -143,7 +143,7 @@ public class DefaultArtifactResolver
}
catch ( ResourceDoesNotExistException e )
{
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
throw new ArtifactNotFoundException( e.getMessage(), artifact, remoteRepositories, e );
}
catch ( TransferFailedException e )
{
@ -179,7 +179,7 @@ public class DefaultArtifactResolver
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
remoteRepositories, source, filter );
@ -189,7 +189,7 @@ public class DefaultArtifactResolver
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
remoteRepositories, source, null );
@ -199,7 +199,7 @@ public class DefaultArtifactResolver
Map managedVersions, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
// TODO: this is simplistic
List listeners = new ArrayList();
@ -219,7 +219,7 @@ public class DefaultArtifactResolver
Map managedVersions, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter, List listeners )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
ArtifactResolutionResult artifactResolutionResult;
artifactResolutionResult = artifactCollector.collect( artifacts, originatingArtifact, managedVersions,
@ -238,7 +238,7 @@ public class DefaultArtifactResolver
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, source, null );
}
@ -246,7 +246,7 @@ public class DefaultArtifactResolver
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source, List listeners )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
remoteRepositories, source, null, listeners );

View File

@ -205,7 +205,7 @@ public class ArtifactResolverTest
artifactResolver.resolve( k, remoteRepositories(), localRepository() );
fail( "Resolution succeeded when it should have failed" );
}
catch ( ArtifactResolutionException expected )
catch ( ArtifactNotFoundException expected )
{
assertTrue( true );
}

View File

@ -20,6 +20,8 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import java.io.File;
@ -154,4 +156,10 @@ public interface Artifact
void setAvailableVersions( List versions );
boolean isOptional();
ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException;
boolean isSelectedVersionKnown()
throws OverConstrainedVersionException;
}

View File

@ -20,6 +20,8 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.util.StringUtils;
@ -520,4 +522,16 @@ public class DefaultArtifact
{
return optional;
}
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return versionRange.getSelectedVersion( this );
}
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return versionRange.isSelectedVersionKnown( this );
}
}

View File

@ -0,0 +1,188 @@
package org.apache.maven.artifact.resolver;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.Iterator;
import java.util.List;
/**
* Base class for artifact resolution exceptions.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class AbstractArtifactResolutionException
extends Exception
{
private String groupId;
private String artifactId;
private String version;
private String type;
private List remoteRepositories;
private final String originalMessage;
private final String path;
static final String LS = System.getProperty( "line.separator" );
protected AbstractArtifactResolutionException( String message, String groupId, String artifactId, String version,
String type, List remoteRepositories, List path )
{
super( constructMessageBase( message, groupId, artifactId, version, type, remoteRepositories, path ) );
this.originalMessage = message;
this.groupId = groupId;
this.artifactId = artifactId;
this.type = type;
this.version = version;
this.remoteRepositories = remoteRepositories;
this.path = constructArtifactPath( path );
}
protected AbstractArtifactResolutionException( String message, String groupId, String artifactId, String version,
String type, List remoteRepositories, List path, Throwable t )
{
super( constructMessageBase( message, groupId, artifactId, version, type, remoteRepositories, path ), t );
this.originalMessage = message;
this.groupId = groupId;
this.artifactId = artifactId;
this.type = type;
this.version = version;
this.remoteRepositories = remoteRepositories;
this.path = constructArtifactPath( path );
}
protected AbstractArtifactResolutionException( String message, Artifact artifact )
{
this( message, artifact, null );
}
protected AbstractArtifactResolutionException( String message, Artifact artifact, List remoteRepositories )
{
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
remoteRepositories, artifact.getDependencyTrail() );
}
protected AbstractArtifactResolutionException( String message, Artifact artifact, List remoteRepositories,
Throwable t )
{
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
remoteRepositories, artifact.getDependencyTrail(), t );
}
public String getGroupId()
{
return groupId;
}
public String getArtifactId()
{
return artifactId;
}
public String getVersion()
{
return version;
}
public String getType()
{
return type;
}
public List getRemoteRepositories()
{
return remoteRepositories;
}
public String getOriginalMessage()
{
return originalMessage;
}
protected static String constructArtifactPath( List path )
{
StringBuffer sb = new StringBuffer();
if ( path != null )
{
sb.append( LS );
sb.append( "Path to dependency: " );
sb.append( LS );
int num = 1;
for ( Iterator i = path.iterator(); i.hasNext(); )
{
sb.append( "\t" );
sb.append( num++ );
sb.append( ") " );
sb.append( i.next() );
sb.append( LS );
}
}
return sb.toString();
}
private static String constructMessageBase( String message, String groupId, String artifactId, String version,
String type, List remoteRepositories, List path )
{
StringBuffer sb = new StringBuffer();
sb.append( message );
sb.append( LS );
sb.append( " " + groupId + ":" + artifactId + ":" + version + ":" + type );
sb.append( LS );
if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
{
sb.append( LS );
sb.append( "from the specified remote repositories:" );
sb.append( LS + " " );
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository remoteRepository = (ArtifactRepository) i.next();
sb.append( remoteRepository.getId() );
sb.append( " (" );
sb.append( remoteRepository.getUrl() );
sb.append( ")" );
if ( i.hasNext() )
{
sb.append( ",\n " );
}
}
}
sb.append( constructArtifactPath( path ) );
sb.append( LS );
return sb.toString();
}
public String getArtifactPath()
{
return path;
}
}

View File

@ -0,0 +1,97 @@
package org.apache.maven.artifact.resolver;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class ArtifactNotFoundException
extends AbstractArtifactResolutionException
{
private String downloadUrl;
protected ArtifactNotFoundException( String message, Artifact artifact )
{
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), null,
null );
}
protected ArtifactNotFoundException( String message, Artifact artifact, List remoteRepositories, Throwable t )
{
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
remoteRepositories, null, t );
}
public ArtifactNotFoundException( String message, String groupId, String artifactId, String version, String type,
List remoteRepositories, String downloadUrl, Throwable t )
{
super( constructMessage( message, groupId, artifactId, version, type, downloadUrl ), groupId, artifactId,
version, type, remoteRepositories, null, t );
this.downloadUrl = downloadUrl;
}
private ArtifactNotFoundException( String message, String groupId, String artifactId, String version, String type,
List remoteRepositories, String downloadUrl )
{
super( constructMessage( message, groupId, artifactId, version, type, downloadUrl ), groupId, artifactId,
version, type, remoteRepositories, null );
this.downloadUrl = downloadUrl;
}
private static String constructMessage( String message, String groupId, String artifactId, String version,
String type, String downloadUrl )
{
StringBuffer sb = new StringBuffer( message );
if ( downloadUrl != null && !"pom".equals( type ) )
{
sb.append( LS );
sb.append( LS );
sb.append( "Try downloading the file manually from" );
sb.append( LS );
sb.append( " " );
sb.append( downloadUrl );
sb.append( LS );
sb.append( "and install it using the command: " );
sb.append( LS );
sb.append( " m2 install:install-file -DgroupId=" );
sb.append( groupId );
sb.append( " -DartifactId=" );
sb.append( artifactId );
sb.append( " -Dversion=" );
sb.append( version );
sb.append( " -Dpackaging=" );
sb.append( type );
sb.append( " -Dfile=/path/to/file" );
}
return sb.toString();
}
public String getDownloadUrl()
{
return downloadUrl;
}
}

View File

@ -17,9 +17,7 @@ package org.apache.maven.artifact.resolver;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.Iterator;
import java.util.List;
/**
@ -27,38 +25,44 @@ import java.util.List;
* @version $Id$
*/
public class ArtifactResolutionException
extends Exception
extends AbstractArtifactResolutionException
{
private String groupId;
public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type,
List remoteRepositories, List path, Throwable t )
{
super( message, groupId, artifactId, version, type, remoteRepositories, path, t );
}
private String artifactId;
public ArtifactResolutionException( String message, Artifact artifact )
{
super( message, artifact );
}
private String version;
protected ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories )
{
super( message, artifact, remoteRepositories );
}
private String type;
private String downloadUrl;
private List remoteRepositories;
private final String originalMessage;
private final String path;
protected ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t )
{
super( message, artifact, remoteRepositories, t );
}
/*
public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type,
List remoteRepositories, String downloadUrl, List path, Throwable t )
{
super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, path ),
t );
this.originalMessage = message;
this.groupId = groupId;
this.artifactId = artifactId;
this.type = type;
this.version = version;
this.remoteRepositories = remoteRepositories;
this.downloadUrl = downloadUrl;
this.path = constructArtifactPath( path );
this.downloadUrl = downloadUrl;
}
public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type,
@ -81,93 +85,6 @@ public class ArtifactResolutionException
this.downloadUrl = downloadUrl;
this.path = constructArtifactPath( path );
}
public String getOriginalMessage()
{
return originalMessage;
}
private static final String LS = System.getProperty( "line.separator" );
private static String constructArtifactPath( List path )
{
StringBuffer sb = new StringBuffer();
if ( path != null )
{
sb.append( LS );
sb.append( "Path to dependency: " );
sb.append( LS );
int num = 1;
for ( Iterator i = path.iterator(); i.hasNext(); )
{
sb.append( "\t" );
sb.append( num++ );
sb.append( ") " );
sb.append( i.next() );
sb.append( LS );
}
}
return sb.toString();
}
private static String constructMessage( String message, String groupId, String artifactId, String version,
String type, List remoteRepositories, String downloadUrl, List path )
{
StringBuffer sb = new StringBuffer();
sb.append( message );
sb.append( LS );
sb.append( " " + groupId + ":" + artifactId + ":" + version + ":" + type );
sb.append( LS );
if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
{
sb.append( LS );
sb.append( "from the specified remote repositories:" );
sb.append( LS + " " );
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository remoteRepository = (ArtifactRepository) i.next();
sb.append( remoteRepository.getId() );
sb.append( " (" );
sb.append( remoteRepository.getUrl() );
sb.append( ")" );
if ( i.hasNext() )
{
sb.append( ",\n " );
}
}
}
sb.append( constructArtifactPath( path ) );
sb.append( LS );
if ( downloadUrl != null && !type.equals( "pom" ) )
{
sb.append( LS );
sb.append( LS );
sb.append( "Try downloading the file manually from" );
sb.append( LS );
sb.append( " " + downloadUrl );
sb.append( LS );
sb.append( "and install it using the command: " );
sb.append( LS );
sb.append( " m2 install:install-file -DgroupId=" );
sb.append( groupId );
sb.append( " -DartifactId=" );
sb.append( artifactId );
sb.append( " -Dversion=" );
sb.append( version );
sb.append( " -Dpackaging=" );
sb.append( type );
sb.append( " -Dfile=/path/to/file" );
}
return sb.toString();
}
public ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t )
{
@ -190,44 +107,10 @@ public class ArtifactResolutionException
public ArtifactResolutionException( String message, Throwable cause )
{
super( message, cause );
this.originalMessage = message;
this.path = "";
}
public String getGroupId()
{
return groupId;
}
public String getArtifactId()
{
return artifactId;
}
public String getVersion()
{
return version;
}
public String getType()
{
return type;
}
public List getRemoteRepositories()
{
return remoteRepositories;
}
public String getDownloadUrl()
{
return downloadUrl;
}
public String getArtifactPath()
{
return path;
}
*/
}

View File

@ -38,37 +38,37 @@ public interface ArtifactResolver
String ROLE = ArtifactResolver.class.getName();
void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source,
List listeners )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, Map managedVersions,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, Map managedVersions,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, Map managedVersions,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter, List listeners )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
void resolveAlways( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException;
throws ArtifactResolutionException, ArtifactNotFoundException;
}

View File

@ -62,44 +62,37 @@ public class DefaultArtifactCollector
ResolutionNode root = new ResolutionNode( originatingArtifact, remoteRepositories );
try
root.addDependencies( artifacts, remoteRepositories, filter );
recurse( root, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter,
listeners );
Set set = new HashSet();
for ( Iterator i = resolvedArtifacts.values().iterator(); i.hasNext(); )
{
root.addDependencies( artifacts, remoteRepositories, filter );
recurse( root, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter,
listeners );
Set set = new HashSet();
for ( Iterator i = resolvedArtifacts.values().iterator(); i.hasNext(); )
List nodes = (List) i.next();
for ( Iterator j = nodes.iterator(); j.hasNext(); )
{
List nodes = (List) i.next();
for ( Iterator j = nodes.iterator(); j.hasNext(); )
ResolutionNode node = (ResolutionNode) j.next();
if ( !node.equals( root ) && node.isActive() )
{
ResolutionNode node = (ResolutionNode) j.next();
if ( !node.equals( root ) && node.isActive() )
Artifact artifact = node.getArtifact();
// If it was optional, we don't add it or its children, just allow the update of the version and scope
if ( !node.getArtifact().isOptional() )
{
Artifact artifact = node.getArtifact();
artifact.setDependencyTrail( node.getDependencyTrail() );
// If it was optional, we don't add it or its children, just allow the update of the version and scope
if ( !node.getArtifact().isOptional() )
{
artifact.setDependencyTrail( node.getDependencyTrail() );
set.add( node );
}
set.add( node );
}
}
}
}
ArtifactResolutionResult result = new ArtifactResolutionResult();
result.setArtifactResolutionNodes( set );
return result;
}
catch ( OverConstrainedVersionException e )
{
throw new ArtifactResolutionException( "Unable to mediate dependency", e );
}
ArtifactResolutionResult result = new ArtifactResolutionResult();
result.setArtifactResolutionNodes( set );
return result;
}
private void recurse( ResolutionNode node, Map resolvedArtifacts, Map managedVersions,
@ -212,11 +205,9 @@ public class DefaultArtifactCollector
if ( artifact.getVersion() == null )
{
// set the recommended version
VersionRange versionRange = artifact.getVersionRange();
// TODO: maybe its better to just pass the range through to retrieval and use a transformation?
ArtifactVersion version;
if ( !versionRange.isSelectedVersionKnown() )
if ( !artifact.isSelectedVersionKnown() )
{
List versions = artifact.getAvailableVersions();
if ( versions == null )
@ -226,6 +217,7 @@ public class DefaultArtifactCollector
artifact.setAvailableVersions( versions );
}
VersionRange versionRange = artifact.getVersionRange();
version = versionRange.matchVersion( versions );
if ( version == null )
@ -234,18 +226,19 @@ public class DefaultArtifactCollector
{
throw new OverConstrainedVersionException(
"No versions are present in the repository for the artifact with a range " +
versionRange );
versionRange, artifact, remoteRepositories );
}
else
{
throw new OverConstrainedVersionException( "Couldn't find a version in " +
versions + " to match range " + versionRange );
versions + " to match range " + versionRange, artifact,
remoteRepositories );
}
}
}
else
{
version = versionRange.getSelectedVersion();
version = artifact.getSelectedVersion();
}
artifact.selectVersion( version.toString() );

View File

@ -116,7 +116,7 @@ public class ResolutionNode
{
// set the recommended version
VersionRange versionRange = artifact.getVersionRange();
String version = versionRange.getSelectedVersion().toString();
String version = artifact.getSelectedVersion().toString();
artifact.selectVersion( version );
}

View File

@ -32,9 +32,4 @@ public class TransitiveArtifactResolutionException
{
super( message, artifact, remoteRepositories, t );
}
public TransitiveArtifactResolutionException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -1,5 +1,10 @@
package org.apache.maven.artifact.versioning;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import java.util.List;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
@ -23,10 +28,16 @@ package org.apache.maven.artifact.versioning;
* @version $Id$
*/
public class OverConstrainedVersionException
extends Exception
extends ArtifactResolutionException
{
public OverConstrainedVersionException( String msg )
public OverConstrainedVersionException( String msg, Artifact artifact )
{
super( msg );
super( msg, artifact );
}
public OverConstrainedVersionException( String msg, Artifact artifact, List remoteRepositories )
{
super( msg, artifact, remoteRepositories );
}
}

View File

@ -16,6 +16,8 @@ package org.apache.maven.artifact.versioning;
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -377,27 +379,7 @@ public class VersionRange
return restrictions;
}
private ArtifactVersion max( ArtifactVersion v1, ArtifactVersion v2 )
{
if ( v1 == null )
{
return v2;
}
if ( v2 == null )
{
return v1;
}
else if ( v1.compareTo( v2 ) > 0 )
{
return v1;
}
else
{
return v2;
}
}
public ArtifactVersion getSelectedVersion()
public ArtifactVersion getSelectedVersion( Artifact artifact )
throws OverConstrainedVersionException
{
ArtifactVersion version;
@ -409,7 +391,7 @@ public class VersionRange
{
if ( restrictions.size() == 0 )
{
throw new OverConstrainedVersionException( "The artifact has no valid ranges" );
throw new OverConstrainedVersionException( "The artifact has no valid ranges", artifact );
}
else
{
@ -425,7 +407,7 @@ public class VersionRange
return version;
}
public boolean isSelectedVersionKnown()
public boolean isSelectedVersionKnown( Artifact artifact )
throws OverConstrainedVersionException
{
boolean value = false;
@ -437,7 +419,7 @@ public class VersionRange
{
if ( restrictions.size() == 0 )
{
throw new OverConstrainedVersionException( "The artifact has no valid ranges" );
throw new OverConstrainedVersionException( "The artifact has no valid ranges", artifact );
}
else
{

View File

@ -18,6 +18,7 @@ package org.apache.maven;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.MavenExecutionRequest;
@ -255,7 +256,7 @@ public class DefaultMaven
logError( response );
}
}
else if ( exception instanceof ArtifactResolutionException )
else if ( exception instanceof ArtifactNotFoundException )
{
logFailure( response, exception, null );
}
@ -487,13 +488,8 @@ public class DefaultMaven
protected MavenSession createSession( MavenExecutionRequest request, ReactorManager rpm )
{
return new MavenSession( container,
request.getSettings(),
request.getLocalRepository(),
request.getEventDispatcher(),
rpm,
request.getGoals(),
request.getBaseDirectory(),
return new MavenSession( container, request.getSettings(), request.getLocalRepository(),
request.getEventDispatcher(), rpm, request.getGoals(), request.getBaseDirectory(),
request.getExecutionProperties() );
}

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -52,10 +53,11 @@ public class DefaultExtensionManager
private PlexusContainer container;
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException
throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException,
ArtifactNotFoundException
{
String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
Artifact artifact = (Artifact) project.getExtensionArtifactMap().get( extensionId );
if ( artifact != null )

View File

@ -17,6 +17,7 @@ package org.apache.maven.extension;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Extension;
@ -32,5 +33,6 @@ import org.codehaus.plexus.PlexusContainerException;
public interface ExtensionManager
{
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException;
throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException,
ArtifactNotFoundException;
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.lifecycle;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenExecutionResponse;
@ -38,7 +39,6 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.lifecycle.Execution;
@ -157,6 +157,10 @@ public class DefaultLifecycleExecutor
{
response.setException( e );
}
catch ( ArtifactNotFoundException e )
{
response.setException( e );
}
catch ( ArtifactResolutionException e )
{
response.setException( e );
@ -196,8 +200,7 @@ public class DefaultLifecycleExecutor
private void executeTaskSegments( List taskSegments, ReactorManager rm, MavenSession session,
MavenProject rootProject, EventDispatcher dispatcher,
MavenExecutionResponse response )
throws PluginNotFoundException, MojoExecutionException, ArtifactResolutionException,
LifecycleExecutionException, MojoFailureException
throws ArtifactNotFoundException, MojoExecutionException, LifecycleExecutionException, MojoFailureException
{
for ( Iterator it = taskSegments.iterator(); it.hasNext(); )
{
@ -234,16 +237,22 @@ public class DefaultLifecycleExecutor
}
catch ( MojoExecutionException e )
{
// TODO: should this be removed?
handleExecutionFailure( rm, rootProject, e, task );
}
catch ( ArtifactResolutionException e )
{
// TODO: should this be removed?
handleExecutionFailure( rm, rootProject, e, task );
}
catch ( MojoFailureException e )
{
handleExecutionFailure( rm, rootProject, e, task );
}
catch ( ArtifactNotFoundException e )
{
handleExecutionFailure( rm, rootProject, e, task );
}
}
dispatcher.dispatchEnd( event, rootProject.getId() + " ( " + segment + " )" );
@ -308,16 +317,22 @@ public class DefaultLifecycleExecutor
}
catch ( MojoExecutionException e )
{
// TODO: should this be removed?
handleExecutionFailure( rm, currentProject, e, task );
}
catch ( ArtifactResolutionException e )
{
// TODO: should this be removed?
handleExecutionFailure( rm, currentProject, e, task );
}
catch ( MojoFailureException e )
{
handleExecutionFailure( rm, currentProject, e, task );
}
catch ( ArtifactNotFoundException e )
{
handleExecutionFailure( rm, currentProject, e, task );
}
}
dispatcher.dispatchEnd( event, currentProject.getId() + " ( " + segment + " )" );
@ -348,7 +363,7 @@ public class DefaultLifecycleExecutor
}
private void handleExecutionFailure( ReactorManager rm, MavenProject project, Exception e, String task )
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException
throws MojoExecutionException, MojoFailureException, ArtifactNotFoundException
{
if ( ReactorManager.FAIL_FAST.equals( rm.getFailureBehavior() ) )
{
@ -362,9 +377,9 @@ public class DefaultLifecycleExecutor
{
throw (MojoFailureException) e;
}
else if ( e instanceof ArtifactResolutionException )
else if ( e instanceof ArtifactNotFoundException )
{
throw (ArtifactResolutionException) e;
throw (ArtifactNotFoundException) e;
}
else
{
@ -383,6 +398,7 @@ public class DefaultLifecycleExecutor
}
private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project )
throws LifecycleExecutionException
{
List segments = new ArrayList();
@ -419,13 +435,13 @@ public class DefaultLifecycleExecutor
// definitely a CLI goal, can use prefix
mojo = getMojoDescriptor( task, session, project, task, true );
}
catch ( LifecycleExecutionException e )
catch ( ArtifactResolutionException e )
{
getLogger().info(
"Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." );
getLogger().debug( "", e );
}
catch ( ArtifactResolutionException e )
catch ( ArtifactNotFoundException e )
{
getLogger().info(
"Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." );
@ -484,7 +500,7 @@ public class DefaultLifecycleExecutor
}
private void executeGoal( String task, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException,
throws LifecycleExecutionException, ArtifactNotFoundException, MojoExecutionException,
ArtifactResolutionException, MojoFailureException
{
if ( phases.contains( task ) )
@ -501,7 +517,8 @@ public class DefaultLifecycleExecutor
private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings,
MavenProject project, MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
{
List goals = processGoalChain( task, lifecycleMappings );
@ -510,7 +527,8 @@ public class DefaultLifecycleExecutor
private void executeStandaloneGoal( String task, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
{
// guaranteed to come from the CLI and not be part of a phase
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true );
@ -518,7 +536,8 @@ public class DefaultLifecycleExecutor
}
private void executeGoals( List goals, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException
{
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
@ -561,7 +580,7 @@ public class DefaultLifecycleExecutor
}
private List getReports( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, LifecycleExecutionException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
{
List reportPlugins = project.getReportPlugins();
@ -658,7 +677,8 @@ public class DefaultLifecycleExecutor
private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
MojoExecution mojoExecution )
throws PluginManagerException, PluginVersionResolutionException, ArtifactResolutionException
throws PluginManagerException, PluginVersionResolutionException, ArtifactResolutionException,
ArtifactNotFoundException
{
PluginDescriptor pluginDescriptor = pluginManager.verifyReportPlugin( reportPlugin, project, session );
@ -694,7 +714,8 @@ public class DefaultLifecycleExecutor
private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
getLogger().info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
@ -724,7 +745,8 @@ public class DefaultLifecycleExecutor
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -841,7 +863,7 @@ public class DefaultLifecycleExecutor
}
private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
{
// first, bind those associated with the packaging
Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project );
@ -858,7 +880,7 @@ public class DefaultLifecycleExecutor
}
private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
{
Map mappings = findMappingsForLifecycle( session, project );
@ -901,7 +923,7 @@ public class DefaultLifecycleExecutor
}
private Map findMappingsForLifecycle( MavenSession session, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
{
String packaging = project.getPackaging();
LifecycleMapping m;
@ -940,7 +962,8 @@ public class DefaultLifecycleExecutor
private Object findExtension( MavenProject project, String role, String roleHint, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
ArtifactNotFoundException
{
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{
@ -969,7 +992,8 @@ public class DefaultLifecycleExecutor
* lookup directly, or have them passed in
*/
private Map findArtifactTypeHandlers( MavenProject project, Settings settings, ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
ArtifactNotFoundException
{
Map map = new HashMap();
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
@ -1014,7 +1038,7 @@ public class DefaultLifecycleExecutor
* @param session
*/
private void bindPluginToLifecycle( Plugin plugin, MavenSession session, Map phaseMap, MavenProject project )
throws LifecycleExecutionException, ArtifactResolutionException
throws LifecycleExecutionException, ArtifactResolutionException, ArtifactNotFoundException
{
PluginDescriptor pluginDescriptor;
Settings settings = session.getSettings();
@ -1048,7 +1072,7 @@ public class DefaultLifecycleExecutor
}
private PluginDescriptor verifyPlugin( Plugin plugin, MavenSession session, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
{
PluginDescriptor pluginDescriptor;
try
@ -1154,7 +1178,7 @@ public class DefaultLifecycleExecutor
private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project,
String invokedVia, boolean canUsePrefix )
throws ArtifactResolutionException, LifecycleExecutionException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
{
String goal;
Plugin plugin = null;

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -74,7 +75,6 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@ -147,7 +147,8 @@ public class DefaultPluginManager
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
ArtifactNotFoundException
{
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
@ -163,7 +164,8 @@ public class DefaultPluginManager
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project,
ArtifactRepository localRepository )
throws PluginVersionResolutionException, PluginManagerException, ArtifactResolutionException
throws PluginVersionResolutionException, PluginManagerException, ArtifactNotFoundException,
ArtifactResolutionException
{
// TODO: this might result in an artifact "RELEASE" being resolved continuously
// FIXME: need to find out how a plugin gets marked as 'installed'
@ -187,7 +189,7 @@ public class DefaultPluginManager
project.addPlugin( plugin );
}
catch ( ArtifactResolutionException e )
catch ( ArtifactNotFoundException e )
{
String groupId = plugin.getGroupId();
String artifactId = plugin.getArtifactId();
@ -255,7 +257,7 @@ public class DefaultPluginManager
protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException
throws ArtifactResolutionException, PluginManagerException, ArtifactNotFoundException
{
// TODO: share with MMS? Not sure if it belongs here
if ( project.getProjectReferences() != null && !project.getProjectReferences().isEmpty() )
@ -330,7 +332,8 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException, MojoFailureException
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -461,7 +464,7 @@ public class DefaultPluginManager
}
public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws PluginManagerException
throws PluginManagerException, ArtifactNotFoundException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
@ -489,7 +492,8 @@ public class DefaultPluginManager
}
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException,
ArtifactNotFoundException
{
String version = reportPlugin.getVersion();
@ -527,7 +531,7 @@ public class DefaultPluginManager
private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report,
MojoExecution mojoExecution )
throws ComponentLookupException, PluginConfigurationException, PluginManagerException
throws ComponentLookupException, PluginConfigurationException, PluginManagerException, ArtifactNotFoundException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -593,7 +597,7 @@ public class DefaultPluginManager
private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor, PlexusContainer pluginContainer,
MavenProject project, MavenSession session )
throws PluginConfigurationException
throws PluginConfigurationException, ArtifactNotFoundException
{
// if the plugin's already been used once, don't re-do this step...
// otherwise, we have to finish resolving the plugin's classpath and start the container.
@ -662,7 +666,7 @@ public class DefaultPluginManager
private void resolveCoreArtifacts( List unresolved, ArtifactRepository localRepository,
List resolutionRepositories )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
for ( Iterator it = unresolved.iterator(); it.hasNext(); )
{
@ -1152,7 +1156,7 @@ public class DefaultPluginManager
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver, String scope,
ArtifactFactory artifactFactory, MavenProject project )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
ArtifactFilter filter = new ScopeArtifactFilter( scope );
@ -1172,7 +1176,8 @@ public class DefaultPluginManager
}
catch ( InvalidVersionSpecificationException e )
{
throw new ArtifactResolutionException( "Error in dependency version", e );
// TODO: should that exception be derived from ArtifactResolutionException instead?
throw new ArtifactResolutionException( e.getMessage(), artifact );
}
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
artifact, context.getLocalRepository(),
@ -1187,7 +1192,7 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
private void downloadDependencies( MavenProject project, MavenSession context, ArtifactResolver artifactResolver )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
ArtifactRepository localRepository = context.getLocalRepository();
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();

View File

@ -17,6 +17,7 @@ package org.apache.maven.plugin;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
@ -39,10 +40,11 @@ public interface PluginManager
String ROLE = PluginManager.class.getName();
void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException, MojoFailureException;
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException;
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws PluginManagerException;
throws PluginManagerException, ArtifactNotFoundException;
PluginDescriptor getPluginDescriptorForPrefix( String prefix );
@ -51,10 +53,12 @@ public interface PluginManager
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
ArtifactNotFoundException;
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException;
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException,
ArtifactNotFoundException;
Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws ComponentLookupException, PluginManagerException;

View File

@ -16,7 +16,7 @@ package org.apache.maven.plugin;
* limitations under the License.
*/
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
/**
* Exception occurring trying to resolve a plugin.
@ -25,11 +25,11 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
* @version $Id$
*/
public class PluginNotFoundException
extends ArtifactResolutionException
extends ArtifactNotFoundException
{
public PluginNotFoundException( ArtifactResolutionException e )
public PluginNotFoundException( ArtifactNotFoundException e )
{
super( "Mojo could not be found - check that the goal name is correct", e.getGroupId(), e.getArtifactId(),
e.getVersion(), "maven-plugin", e.getRemoteRepositories(), e.getDownloadUrl(), e );
super( "Plugin could not be found - check that the goal name is correct", e.getGroupId(), e.getArtifactId(),
e.getVersion(), "maven-plugin", e.getRemoteRepositories(), e.getDownloadUrl(), e.getCause() );
}
}

View File

@ -17,43 +17,45 @@ package org.apache.maven.usability;
*/
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
public class ArtifactResolverDiagnoser
implements ErrorDiagnoser
{
private WagonManager wagonManager;
public boolean canDiagnose( Throwable error )
{
return DiagnosisUtils.containsInCausality( error, ArtifactResolutionException.class );
return DiagnosisUtils.containsInCausality( error, AbstractArtifactResolutionException.class );
}
public String diagnose( Throwable error )
{
ArtifactResolutionException exception = (ArtifactResolutionException) DiagnosisUtils.getFromCausality( error, ArtifactResolutionException.class );
AbstractArtifactResolutionException exception = (AbstractArtifactResolutionException) DiagnosisUtils.getFromCausality(
error, ArtifactResolutionException.class );
StringBuffer message = new StringBuffer();
message.append( "Failed to resolve artifact." );
message.append( "\n\n");
message.append( "\n\n" );
message.append( exception.getMessage() );
if ( !wagonManager.isOnline() )
{
message.append( "\n" ).append( DiagnosisUtils.getOfflineWarning() );
}
Throwable root = DiagnosisUtils.getRootCause( exception );
if ( root != null )
{
message.append( "\nRoot Cause: " ).append( root.getMessage() );
}
message.append( "\n" );
return message.toString();
}

View File

@ -10,6 +10,9 @@
<packaging>maven-plugin</packaging>
<name>Maven Eclipse Plugin</name>
<version>2.0-beta-2-SNAPSHOT</version>
<prerequisites>
<maven>2.0-beta-4-SNAPSHOT</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -19,10 +22,15 @@
<groupId>plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-beta-3</version>
<version>2.0-beta-4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -16,16 +16,10 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License.
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
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.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.logging.Log;
@ -34,8 +28,16 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Writes eclipse .classpath file.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
* @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
@ -52,13 +54,13 @@ public class EclipseClasspathWriter
}
/**
* @todo the list of needed parameters is really long, maybe this should become a Plexus component
* @param outputDirectory TODO
* @todo the list of needed parameters is really long, maybe this should become a Plexus component
*/
protected void write( File projectBaseDir, File basedir, MavenProject project, List referencedReactorArtifacts,
EclipseSourceDir[] sourceDirs, List classpathContainers, ArtifactRepository localRepository,
ArtifactResolver artifactResolver, ArtifactFactory artifactFactory,
List remoteArtifactRepositories, boolean downloadSources, String outputDirectory )
EclipseSourceDir[] sourceDirs, List classpathContainers, ArtifactRepository localRepository,
ArtifactResolver artifactResolver, ArtifactFactory artifactFactory,
List remoteArtifactRepositories, boolean downloadSources, String outputDirectory )
throws EclipsePluginException
{
@ -70,7 +72,8 @@ public class EclipseClasspathWriter
}
catch ( IOException ex )
{
throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ),
ex ); //$NON-NLS-1$
}
XMLWriter writer = new PrettyPrintXMLWriter( w );
@ -105,7 +108,7 @@ public class EclipseClasspathWriter
writer.startElement( "classpathentry" ); //$NON-NLS-1$
writer.addAttribute( "kind", "output" ); //$NON-NLS-1$ //$NON-NLS-2$
writer.addAttribute( "path", EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, //$NON-NLS-1$
outputDirectory, false ) );
outputDirectory, false ) );
writer.endElement();
// ----------------------------------------------------------------------
@ -150,9 +153,10 @@ public class EclipseClasspathWriter
}
private void addDependency( XMLWriter writer, Artifact artifact, List referencedReactorArtifacts,
ArtifactRepository localRepository, ArtifactResolver artifactResolver,
ArtifactFactory artifactFactory, List remoteArtifactRepositories,
boolean downloadSources )
ArtifactRepository localRepository, ArtifactResolver artifactResolver,
ArtifactFactory artifactFactory, List remoteArtifactRepositories,
boolean downloadSources )
throws EclipsePluginException
{
String path;
@ -183,9 +187,9 @@ public class EclipseClasspathWriter
if ( downloadSources )
{
Artifact sourceArtifact = retrieveSourceArtifact( artifact, remoteArtifactRepositories,
localRepository, artifactResolver, artifactFactory );
Artifact sourceArtifact = retrieveSourceArtifact( artifact, remoteArtifactRepositories, localRepository,
artifactResolver, artifactFactory );
if ( !sourceArtifact.isResolved() )
{
log.info( Messages.getString( "EclipseClasspathWriter.sourcesnotavailable", //$NON-NLS-1$
@ -194,12 +198,12 @@ public class EclipseClasspathWriter
else
{
log.debug( Messages.getString( "EclipseClasspathWriter.sourcesavailable", //$NON-NLS-1$
new Object[] {
sourceArtifact.getArtifactId(),
sourceArtifact.getFile().getAbsolutePath() } ) );
new Object[]{sourceArtifact.getArtifactId(),
sourceArtifact.getFile().getAbsolutePath()} ) );
sourcepath = "M2_REPO/" //$NON-NLS-1$
+ EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, sourceArtifact.getFile().getAbsolutePath(), false );
+ EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile,
sourceArtifact.getFile().getAbsolutePath(), false );
}
}
@ -220,22 +224,26 @@ public class EclipseClasspathWriter
}
private Artifact retrieveSourceArtifact( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository, ArtifactResolver artifactResolver,
ArtifactFactory artifactFactory )
private Artifact retrieveSourceArtifact( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository, ArtifactResolver artifactResolver,
ArtifactFactory artifactFactory )
throws EclipsePluginException
{
// source artifact: use the "sources" classifier added by the source plugin
Artifact sourceArtifact = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact
.getArtifactId(), artifact.getVersion(), "java-source", "sources" ); //$NON-NLS-1$ //$NON-NLS-2$
Artifact sourceArtifact = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(), "java-source",
"sources" ); //$NON-NLS-1$ //$NON-NLS-2$
try
{
log.debug( Messages.getString( "EclipseClasspathWriter.lookingforsources", //$NON-NLS-1$
sourceArtifact.getArtifactId() ) );
sourceArtifact.getArtifactId() ) );
artifactResolver.resolve( sourceArtifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
catch ( ArtifactNotFoundException e )
{
// ignore, the jar has not been found
if ( log.isDebugEnabled() )
@ -243,7 +251,11 @@ public class EclipseClasspathWriter
log.debug( "Cannot resolve source artifact", e );
}
}
catch ( ArtifactResolutionException e )
{
throw new EclipsePluginException( "Error getting soruce artifact", e );
}
return sourceArtifact;
}
}

View File

@ -24,6 +24,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
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.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -153,7 +154,7 @@ public class DefaultMavenProjectBuilder
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{
return buildWithDependencies( projectDescriptor, localRepository, profileManager, null );
}
@ -163,7 +164,7 @@ public class DefaultMavenProjectBuilder
*/
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager, TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager );
@ -373,8 +374,8 @@ public class DefaultMavenProjectBuilder
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
{
getLogger().info(
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
getLogger().info( projectArtifact.getArtifactId() +
": updating metadata due to status of '" + status + "'" );
try
{
projectArtifact.setResolved( false );
@ -386,6 +387,13 @@ public class DefaultMavenProjectBuilder
getLogger().warn( "Error updating POM - using existing version" );
getLogger().debug( "Cause", e );
}
catch ( ArtifactNotFoundException e )
{
getLogger().warn( "Error updating POM - not found. Removing local copy." );
getLogger().debug( "Cause", e );
file.delete();
throw e;
}
}
}
@ -407,10 +415,10 @@ public class DefaultMavenProjectBuilder
}
catch ( ArtifactResolutionException e )
{
// TODO: a not found would be better vs other errors
// only not found should have the below behaviour
// throw new ProjectBuildingException( "Unable to find the POM in the repository", e );
throw new ProjectBuildingException( "Error getting the POM in the repository", e );
}
catch ( ArtifactNotFoundException e )
{
model = createStubModel( projectArtifact );
}
}
@ -422,7 +430,7 @@ public class DefaultMavenProjectBuilder
return model;
}
private Model createStubModel(Artifact projectArtifact)
private Model createStubModel( Artifact projectArtifact )
{
getLogger().warn( "\n ***** Using defaults for missing POM " + projectArtifact.getId() + " *****\n" );
@ -676,10 +684,9 @@ public class DefaultMavenProjectBuilder
"\'.\n\n Reason(s):\n" + validationResult.render( " " ) );
}
project.setRemoteArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getRepositories(),
artifactRepositoryFactory,
container ) );
project.setRemoteArtifactRepositories(
ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, container ) );
// TODO: these aren't taking active project artifacts into consideration in the reactor
project.setPluginArtifacts( createPluginArtifacts( project.getBuildPlugins() ) );
project.setReportArtifacts( createReportArtifacts( project.getReportPlugins() ) );

View File

@ -18,6 +18,7 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.wagon.events.TransferListener;
@ -44,11 +45,11 @@ public interface MavenProjectBuilder
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager, TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException;
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager )
throws ProjectBuildingException, ArtifactResolutionException;
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException;
// ----------------------------------------------------------------------
//

View File

@ -21,6 +21,8 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.project.MavenProject;
@ -276,4 +278,16 @@ public class ActiveProjectArtifact
{
return artifact.isOptional();
}
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return artifact.getSelectedVersion();
}
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return artifact.isSelectedVersionKnown();
}
}

View File

@ -1,5 +1,21 @@
package org.apache.maven.project.artifact;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.InvalidArtifactRTException;
@ -19,19 +35,22 @@ public class AttachedArtifact
private final Artifact parent;
public AttachedArtifact ( Artifact parent, String type, String classifier )
public AttachedArtifact( Artifact parent, String type, String classifier )
{
super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, classifier, parent.getArtifactHandler(), parent.isOptional() );
super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
classifier, parent.getArtifactHandler(), parent.isOptional() );
this.parent = parent;
if ( type == null || type.trim().length() < 1 )
{
throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), getVersion(), type, "Attached artifacts must specify a type." );
throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), getVersion(), type,
"Attached artifacts must specify a type." );
}
if ( classifier == null || classifier.trim().length() < 1 )
{
throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), getVersion(), type, "Attached artifacts must specify a classifier." );
throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), getVersion(), type,
"Attached artifacts must specify a classifier." );
}
}

View File

@ -23,6 +23,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
@ -192,7 +193,7 @@ public class TestArtifactResolver
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
return super.resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories,
new Source( artifactFactory, repositoryFactory, container ), filter );
@ -201,7 +202,7 @@ public class TestArtifactResolver
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException
throws ArtifactResolutionException, ArtifactNotFoundException
{
return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository,
new Source( artifactFactory, repositoryFactory, container ) );