maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Miller (JIRA)" <j...@codehaus.org>
Subject [jira] Commented: (MNG-4047) NPE in resolver if artifact defined with a version range
Date Mon, 23 Mar 2009 14:19:12 GMT

    [ http://jira.codehaus.org/browse/MNG-4047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=170681#action_170681
] 

Alex Miller commented on MNG-4047:
----------------------------------

I got the same behavior with 2.0.10.  Due to how integrated the code was with the Terracotta
source base (and the fact that I couldn't check it in), I don't really have any sample project/command
that illustrated the problem.  I ended up concluding from the code that while DefaultArtifactResolver
takes an Artifact it (implicitly) assumes that that Artifact (which may have a version range
spec) has already been constrained in the VersionRange instance to a specific version (using
restrict()).  The ArtifactResolver does not seem to have logic to resolve the "best" version
from a set of possible versions in the repository.

However, I did find that the ArtifactCollector seemed to be intended for that purpose (javadoc:
 "takes a set of original artifacts and resolves all of the best versions to use along with
their metadata")  so I have reworked the code to use the collector instead.  I now use the
ArtifactCollector to resolve the best version of the artifact in the range and then use the
resolver on the specific version, something like:

{code}
      ArtifactResolutionResult result = artifactCollector.collect(artifacts, originatingArtifact,
localRepository, remoteRepositories, metadataSource, null, Collections.EMPTY_LIST);
      Set nodes = result.getArtifactResolutionNodes();
      
      ResolutionNode resultNode = (ResolutionNode) nodes.iterator().next();
      selectedArtifact = resultNode.getArtifact();
      
      artifactResolver.resolve(selectedArtifact, remoteRepositories, localRepository);
      return selectedArtifact.getFile();
{code}

That code is making the assumption that nodes contains a single result.  That happens to be
guaranteed for me as I control the repository and the version that exists but may not generally
be a solution.

In short, I don't think that my original problem needs to be fixed, although it would be nice
if the DefaultArtifactResolver could understand the situation enough to tell me that it doesn't
support an unrestricted VersionRange rather than throwing an NPE.     

> NPE in resolver if artifact defined with a version range
> --------------------------------------------------------
>
>                 Key: MNG-4047
>                 URL: http://jira.codehaus.org/browse/MNG-4047
>             Project: Maven 2
>          Issue Type: Bug
>          Components: Artifacts and Repositories
>    Affects Versions: 2.0.9
>         Environment: Mac OS X, Maven 2.0.9
>            Reporter: Alex Miller
>             Fix For: 2.1.x
>
>         Attachments: out.txt
>
>
> I'm seeing the following NPE when calling the ArtifactResolver with an Artifact defined
by a VersionRange.  Here the version for this artifact is defined as "[1.0.0-SNAPSHOT,1.1.0-SNAPSHOT)"
and the 1.0.0-SNAPSHOT artifact is in my local repository.  
> java.lang.NullPointerException: version was null for org.terracotta:terracotta-test-api
>         at org.apache.maven.artifact.DefaultArtifact.getBaseVersion(DefaultArtifact.java:362)
>         at org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout.pathOf(DefaultRepositoryLayout.java:47)
>         at org.apache.maven.artifact.repository.DefaultArtifactRepository.pathOf(DefaultArtifactRepository.java:110)
>         at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:125)
>         at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:74)
>         at org.terracotta.maven.plugins.tc.DsoArtifactResolverImpl.resolveArtifact(DsoArtifactResolverImpl.java:82)
>         at org.terracotta.maven.plugins.tc.ManifestMojo.generateRequiredBundles(ManifestMojo.java:336)
>         at org.terracotta.maven.plugins.tc.ManifestMojo.createManifest(ManifestMojo.java:272)
>         at org.terracotta.maven.plugins.tc.ManifestMojo.execute(ManifestMojo.java:205)
>         at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
> The tc-maven-plugin source can be perused here:
> http://svn.terracotta.org/svn/forge/projects/tc-maven-plugin/trunk

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message