[
https://jira.codehaus.org/browse/MNG-5250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=292360#comment-292360
]
Yoav Abrahami commented on MNG-5250:
------------------------------------
I did not submit a patch as I am not sure if this is the way you wanna fix this
issue. However, I have tested my solution and it seems to work fine for large
maven 2 projects with LATEST for both parent and dependencies
> DefaultVersionResolver.readVersions reads snapshot versions from release only
> repositories
> ------------------------------------------------------------------------------------------
>
> Key: MNG-5250
> URL: https://jira.codehaus.org/browse/MNG-5250
> Project: Maven 2 & 3
> Issue Type: Bug
> Components: Dependencies, Embedding
> Affects Versions: 3.0.4
> Environment: embedded maven
> Reporter: Yoav Abrahami
>
> with the below repositories configuration in settings.xml [1]
> I get an error that a parent of a project is not found if the parent version
> is marked as LATEST.
> The actual error is
> "Could not find artifact XXX in snapshots (URL of SNAPSHOT repository)"
> while debugging the reason, I have found that because the
> DefaultVersionResolver.readVersions() method returns SNAPSHOT versions when
> reading versions from a release only repository (repository with snapshot
> policy not enabled).
> The fix I have in place is to add to the
> DefaultVersionResolver.readVersions() method the following fragment:
> (see the full method below [2]
> {code}
> /*
> * fix for LATEST - repository who does not support snapshots should not
> return shapshot versions
> */
> if (versioning != null && repository instanceof RemoteRepository) {
> RemoteRepository remoteRepository = (RemoteRepository)repository;
> if (!remoteRepository.getPolicy(true).isEnabled()) {
> Versioning repaired = new Versioning();
> repaired.setLastUpdated(versioning.getLastUpdated());
> repaired.setRelease(versioning.getRelease());
> repaired.setVersions(versioning.getVersions());
> versioning = repaired;
> }
> }
> {code}
> [1] :
> {code}
> <repositories>
> <repository>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> <id>central</id>
> <name>libs-releases</name>
> <url>http://repo.dev.wix/artifactory/libs-releases</url>
> </repository>
> <repository>
> <snapshots />
> <id>snapshots</id>
> <name>libs-snapshots</name>
> <url>http://repo.dev.wix/artifactory/libs-snapshots</url>
> </repository>
> </repositories>
> {code}
> [2] :
> {code}
> private Versioning readVersions( RepositorySystemSession session,
> RequestTrace trace, Metadata metadata,
> ArtifactRepository repository,
> VersionResult result )
> {
> Versioning versioning = null;
> FileInputStream fis = null;
> try
> {
> if ( metadata != null )
> {
> SyncContext syncContext = syncContextFactory.newInstance(
> session, true );
> try
> {
> syncContext.acquire( null, Collections.singleton(
> metadata ) );
> if ( metadata.getFile() != null &&
> metadata.getFile().exists() )
> {
> fis = new FileInputStream( metadata.getFile() );
>
> org.apache.maven.artifact.repository.metadata.Metadata m =
> new MetadataXpp3Reader().read( fis, false );
> versioning = m.getVersioning();
> /*
> * NOTE: Users occasionally misuse the id "local" for
> remote repos which screws up the metadata
> * of the local repository. This is especially
> troublesome during snapshot resolution so we try
> * to handle that gracefully.
> */
> if ( versioning != null && repository instanceof
> LocalRepository )
> {
> if ( versioning.getSnapshot() != null &&
> versioning.getSnapshot().getBuildNumber() > 0 )
> {
> Versioning repaired = new Versioning();
> repaired.setLastUpdated(
> versioning.getLastUpdated() );
> Snapshot snapshot = new Snapshot();
> snapshot.setLocalCopy( true );
> repaired.setSnapshot( snapshot );
> versioning = repaired;
> throw new IOException( "Snapshot information
> corrupted with remote repository data"
> + ", please verify that no remote
> repository uses the id '" + repository.getId()
> + "'" );
> }
> }
> /*
> * fix for LATEST - repository who does not support
> snapshots should not return shapshot versions
> */
> if (versioning != null && repository instanceof
> RemoteRepository) {
> RemoteRepository remoteRepository =
> (RemoteRepository)repository;
> if
> (!remoteRepository.getPolicy(true).isEnabled()) {
> Versioning repaired = new Versioning();
>
> repaired.setLastUpdated(versioning.getLastUpdated());
> repaired.setRelease(versioning.getRelease());
>
> repaired.setVersions(versioning.getVersions());
> versioning = repaired;
> }
> }
> }
> }
> finally
> {
> syncContext.release();
> }
> }
> }
> catch ( Exception e )
> {
> invalidMetadata( session, trace, metadata, repository, e );
> result.addException( e );
> }
> finally
> {
> IOUtil.close( fis );
> }
> return ( versioning != null ) ? versioning : new Versioning();
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira