]> source.dussan.org Git - archiva.git/commitdiff
extract code to an internal method
authorOlivier Lamy <olamy@apache.org>
Mon, 12 Mar 2012 08:30:40 +0000 (08:30 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 12 Mar 2012 08:30:40 +0000 (08:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299577 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java

index f5f0be4d7a8d9d3c0519fe950801a90ee27b0a60..9ef2745b24a22fef38e59d4d2cff1d1919f4be23 100644 (file)
@@ -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
     {