From af42752e144d051c5bcfa2a6353c960c45dfef2a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 10 Jan 2014 03:54:15 +0000 Subject: [PATCH] when browsing we must be more relax to resolve dependencies especially with snapshot having released as parent pom git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1557021 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/DefaultMetadataResolver.java | 2 +- .../storage/ReadMetadataRequest.java | 36 +++++++++++++ .../maven2/Maven3DependencyTreeBuilder.java | 2 +- .../maven2/Maven2RepositoryStorage.java | 53 +++++++++++-------- 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java index d43bed6a6..6d505f13d 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java @@ -101,7 +101,7 @@ public class DefaultMetadataResolver { ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId( repoId ).namespace( namespace ).projectId( - projectId ).projectVersion( projectVersion ); + projectId ).projectVersion( projectVersion ).browsingRequest( true ); metadata = repositoryStorage.readProjectVersionMetadata( readMetadataRequest ); log.debug( "Resolved project version metadata from storage: {}", metadata ); diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/ReadMetadataRequest.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/ReadMetadataRequest.java index 6ee552151..56e9f02d2 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/ReadMetadataRequest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/ReadMetadataRequest.java @@ -36,6 +36,12 @@ public class ReadMetadataRequest private Filter filter; + /** + * define this request as a ui request to remove some constraints added for optimisations + * @since 2.0.0 + */ + private boolean browsingRequest; + public ReadMetadataRequest() { // no op @@ -135,4 +141,34 @@ public class ReadMetadataRequest this.filter = filter; return this; } + + public boolean isBrowsingRequest() + { + return browsingRequest; + } + + public void setBrowsingRequest( boolean browsingRequest ) + { + this.browsingRequest = browsingRequest; + } + + public ReadMetadataRequest browsingRequest( boolean browsingRequest ) + { + this.browsingRequest = browsingRequest; + return this; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder( "ReadMetadataRequest{" ); + sb.append( "repositoryId='" ).append( repositoryId ).append( '\'' ); + sb.append( ", namespace='" ).append( namespace ).append( '\'' ); + sb.append( ", projectId='" ).append( projectId ).append( '\'' ); + sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' ); + sb.append( ", filter=" ).append( filter ); + sb.append( ", browsingRequest=" ).append( browsingRequest ); + sb.append( '}' ); + return sb.toString(); + } } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java index 30dcd3dff..197fc9712 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java @@ -213,7 +213,7 @@ public class Maven3DependencyTreeBuilder collectRequest.setRoot( new Dependency( artifact, "" ) ); // add remote repositories ? - //collectRequest.addRepository( ) + collectRequest.addRepository( new org.sonatype.aether.repository.RemoteRepository( "fake", "default", "http://maven.apache.org" ) ); collectRequest.setRequestContext( "project" ); diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java index 8dab2bfef..46602ac97 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java @@ -169,31 +169,35 @@ public class Maven2RepositoryStorage { ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository( readMetadataRequest.getRepositoryId() ); - String artifactVersion = readMetadataRequest.getProjectVersion(); - if ( VersionUtil.isSnapshot( - readMetadataRequest.getProjectVersion() ) ) // skygo trying to improve speed by honoring managed configuration MRM-1658 + // olamy: in case of browsing via the ui we can mix repos (parent of a SNAPSHOT can come from release repo) + if ( !readMetadataRequest.isBrowsingRequest() ) { - if ( managedRepository.isReleases() && !managedRepository.isSnapshots() ) + + if ( VersionUtil.isSnapshot( + artifactVersion ) ) // skygo trying to improve speed by honoring managed configuration MRM-1658 { - throw new RepositoryStorageRuntimeException( "lookforsnaponreleaseonly", - "managed repo is configured for release only" ); + if ( managedRepository.isReleases() && !managedRepository.isSnapshots() ) + { + throw new RepositoryStorageRuntimeException( "lookforsnaponreleaseonly", + "managed repo is configured for release only" ); + } } - } - else - { - if ( !managedRepository.isReleases() && managedRepository.isSnapshots() ) + else { - throw new RepositoryStorageRuntimeException( "lookforsreleaseonsneponly", - "managed repo is configured for snapshot only" ); + if ( !managedRepository.isReleases() && managedRepository.isSnapshots() ) + { + throw new RepositoryStorageRuntimeException( "lookforsreleaseonsneponly", + "managed repo is configured for snapshot only" ); + } } } File basedir = new File( managedRepository.getLocation() ); - if ( VersionUtil.isSnapshot( readMetadataRequest.getProjectVersion() ) ) + if ( VersionUtil.isSnapshot( artifactVersion ) ) { File metadataFile = pathTranslator.toFile( basedir, readMetadataRequest.getNamespace(), - readMetadataRequest.getProjectId(), - readMetadataRequest.getProjectVersion(), METADATA_FILENAME ); + readMetadataRequest.getProjectId(), artifactVersion, + METADATA_FILENAME ); try { ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); @@ -219,7 +223,7 @@ public class Maven2RepositoryStorage String id = readMetadataRequest.getProjectId() + "-" + artifactVersion + ".pom"; File file = pathTranslator.toFile( basedir, readMetadataRequest.getNamespace(), readMetadataRequest.getProjectId(), - readMetadataRequest.getProjectVersion(), id ); + artifactVersion, id ); if ( !file.exists() ) { @@ -258,6 +262,13 @@ public class Maven2RepositoryStorage } } + // That's a browsing request so we can a mix of SNAPSHOT and release artifacts (especially with snapshots which + // can have released parent pom + if ( readMetadataRequest.isBrowsingRequest() ) + { + remoteRepositories.addAll( remoteRepositoryAdmin.getRemoteRepositories() ); + } + ModelBuildingRequest req = new DefaultModelBuildingRequest().setProcessPlugins( false ).setPomFile( file ).setTwoPhaseBuilding( false ).setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); @@ -809,12 +820,12 @@ public class Maven2RepositoryStorage filePath = StringUtils.replace( filePath, artifactReference.getArtifactId() + "-" + artifactReference.getVersion(), artifactReference.getArtifactId() + "-" + StringUtils.remove( - artifactReference.getVersion(), "-" + VersionUtil.SNAPSHOT ) + "-" + timestamp + "-" - + buildNumber ); + artifactReference.getVersion(), "-" + VersionUtil.SNAPSHOT ) + "-" + timestamp + + "-" + buildNumber ); - throw new RelocationException( - "/repository/" + managedRepositoryContent.getRepository().getId() + - ( StringUtils.startsWith( filePath, "/" ) ? "" : "/" ) + filePath, RelocationException.RelocationType.TEMPORARY ); + throw new RelocationException( "/repository/" + managedRepositoryContent.getRepository().getId() + + ( StringUtils.startsWith( filePath, "/" ) ? "" : "/" ) + filePath, + RelocationException.RelocationType.TEMPORARY ); } -- 2.39.5