From: Olivier Lamy Date: Mon, 12 Mar 2012 08:30:40 +0000 (+0000) Subject: extract code to an internal method X-Git-Tag: archiva-1.4-M3~1065 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=89dbc0561ffcaaa33028ad0157be545dc674c649;p=archiva.git extract code to an internal method git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299577 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java index f5f0be4d7..9ef2745b2 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java @@ -112,35 +112,12 @@ public class RepositoryModelResolver // is a SNAPSHOT ? if ( StringUtils.contains( version, "SNAPSHOT" ) ) { - // reading metadata if there - File mavenMetadata = new File( model.getParent(), METADATA_FILENAME ); - if ( mavenMetadata.exists() ) + model = findTimeStampedSnapshotPom( groupId, artifactId, version, model.getParent() ); + if ( model != null ) { - try - { - ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( mavenMetadata ); - SnapshotVersion snapshotVersion = archivaRepositoryMetadata.getSnapshotVersion(); - if ( snapshotVersion != null ) - { - String lastVersion = snapshotVersion.getTimestamp(); - int buildNumber = snapshotVersion.getBuildNumber(); - String snapshotPath = - StringUtils.replaceChars( groupId, '.', '/' ) + '/' + artifactId + '/' + version + '/' - + artifactId + '-' + StringUtils.remove( version, "-SNAPSHOT" ) + '-' + lastVersion - + '-' + buildNumber + ".pom"; - model = new File( basedir, snapshotPath ); - //model = pathTranslator.toFile( basedir, groupId, artifactId, lastVersion, filename ); - if ( model.exists() ) - { - return new FileModelSource( model ); - } - } - } - catch ( XMLException e ) - { - log.warn( "fail to read {}, {}", mavenMetadata.getAbsolutePath(), e.getCause() ); - } + return new FileModelSource( model ); } + } for ( RemoteRepository remoteRepository : remoteRepositories ) @@ -168,6 +145,43 @@ public class RepositoryModelResolver return new FileModelSource( model ); } + protected File findTimeStampedSnapshotPom( String groupId, String artifactId, String version, + String parentDirectory ) + { + + // reading metadata if there + File mavenMetadata = new File( parentDirectory, METADATA_FILENAME ); + if ( mavenMetadata.exists() ) + { + try + { + ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( mavenMetadata ); + SnapshotVersion snapshotVersion = archivaRepositoryMetadata.getSnapshotVersion(); + if ( snapshotVersion != null ) + { + String lastVersion = snapshotVersion.getTimestamp(); + int buildNumber = snapshotVersion.getBuildNumber(); + String snapshotPath = + StringUtils.replaceChars( groupId, '.', '/' ) + '/' + artifactId + '/' + version + '/' + + artifactId + '-' + StringUtils.remove( version, "-SNAPSHOT" ) + '-' + lastVersion + '-' + + buildNumber + ".pom"; + File model = new File( basedir, snapshotPath ); + //model = pathTranslator.toFile( basedir, groupId, artifactId, lastVersion, filename ); + if ( model.exists() ) + { + return model; + } + } + } + catch ( XMLException e ) + { + log.warn( "fail to read {}, {}", mavenMetadata.getAbsolutePath(), e.getCause() ); + } + } + + return null; + } + public void addRepository( Repository repository ) throws InvalidRepositoryException {