Author: olamy
Date: Mon Mar 12 08:30:40 2012
New Revision: 1299577

URL: http://svn.apache.org/viewvc?rev=1299577&view=rev
Log:
extract code to an internal method

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

Modified: 
archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
URL: 
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java?rev=1299577&r1=1299576&r2=1299577&view=diff
==============================================================================
--- 
archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
 (original)
+++ 
archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
 Mon Mar 12 08:30:40 2012
@@ -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
     {


Reply via email to