From af42752e144d051c5bcfa2a6353c960c45dfef2a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 10 Jan 2014 03:54:15 +0000 Subject: 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 --- .../tree/maven2/Maven3DependencyTreeBuilder.java | 2 +- .../storage/maven2/Maven2RepositoryStorage.java | 53 +++++++++++++--------- 2 files changed, 33 insertions(+), 22 deletions(-) (limited to 'archiva-modules/plugins/maven2-repository/src') 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 ); } -- cgit v1.2.3