]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1761] Returned URL in search result does not work for SNAPSHOTS
authorOlivier Lamy <olamy@apache.org>
Mon, 9 Dec 2013 02:46:56 +0000 (02:46 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 9 Dec 2013 02:46:56 +0000 (02:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549368 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/metadata/metadata-repository-api/pom.xml
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java

index 293e230e5a8da8686bf09e69ef5b3f3cb24c8ccd..6132dfe01a782630677433835bcef0b1a97be79e 100644 (file)
@@ -527,6 +527,28 @@ public class ArchivaDavResourceFactory
         return path;
     }
 
+    private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent )
+        throws DavException
+    {
+        String layout = managedRepositoryContent.getRepository() == null ? new ManagedRepository( ).getLayout() : managedRepositoryContent.getRepository().getLayout();
+        RepositoryStorage repositoryStorage =
+            this.applicationContext.getBean( "repositoryStorage#" + layout, RepositoryStorage.class );
+        try
+        {
+            return repositoryStorage.getFilePathWithVersion( archivaLocator.getResourcePath(), managedRepositoryContent );
+        }
+        catch ( LayoutException e )
+        {
+            log.error( e.getMessage(), e );
+            throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
+        }
+        catch ( XMLException e )
+        {
+            log.error( e.getMessage(), e );
+            throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
+        }
+    }
+
     private DavResource processRepository( final DavServletRequest request, ArchivaDavResourceLocator archivaLocator,
                                            String activePrincipal, ManagedRepositoryContent managedRepositoryContent,
                                            ManagedRepository managedRepository )
@@ -535,7 +557,8 @@ public class ArchivaDavResourceFactory
         DavResource resource = null;
         if ( isAuthorized( request, managedRepositoryContent.getId() ) )
         {
-            String path = getLogicalResource( archivaLocator, managedRepository, false );
+            // Maven Centric part ask evaluation if -SNAPSHOT
+            String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent);
             if ( path.startsWith( "/" ) )
             {
                 path = path.substring( 1 );
index 4b8e36834d67e397bf32e539d145971baa717b24..0b508762c506c77a7c55ffda429844e8d2c95019 100644 (file)
@@ -91,7 +91,9 @@
               org.apache.archiva.model,
               org.apache.archiva.policies,
               org.apache.archiva.repository,
-              org.apache.archiva.admin.model.beans
+              org.apache.archiva.admin.model.beans,
+              org.apache.archiva.repository.layout,
+              org.apache.archiva.xml
             </Import-Package>
           </instructions>
         </configuration>
index d5b203778500206f9d0d1aa66fa48815091fc112..fee01b7751a8028ff4ec67af8b75b1db8f92b65c 100644 (file)
@@ -27,6 +27,8 @@ import org.apache.archiva.metadata.repository.filter.Filter;
 import org.apache.archiva.model.ArtifactReference;
 import org.apache.archiva.policies.ProxyDownloadException;
 import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.archiva.xml.XMLException;
 
 import java.util.Collection;
 
@@ -70,4 +72,9 @@ public interface RepositoryStorage
      * @since 2.0.0
      */
     String getFilePath( String requestPath, ManagedRepository managedRepository );
+
+    String getFilePathWithVersion( final String requestPath, ManagedRepositoryContent managedRepositoryContent )
+        throws LayoutException, XMLException;
+
+
 }
index 699f41bfce5b1d7f8e16e4d4fdb1830de2f370fe..30cc569583792c48271098b0d5995b1f928131ef 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.archiva.maven2.metadata.MavenMetadataReader;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.metadata.repository.filter.Filter;
 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
@@ -50,6 +51,8 @@ import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
 import org.apache.archiva.reports.RepositoryProblemFacet;
 import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.layout.LayoutException;
 import org.apache.archiva.xml.XMLException;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
@@ -131,6 +134,10 @@ public class Maven2RepositoryStorage
     @Inject
     private ApplicationContext applicationContext;
 
+    @Inject
+    @Named ( value = "pathParser#default")
+    private PathParser pathParser;
+
     private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
 
     private static final String METADATA_FILENAME_START = "maven-metadata";
@@ -757,6 +764,34 @@ public class Maven2RepositoryStorage
 
     }
 
+    public String getFilePathWithVersion( final String requestPath, ManagedRepositoryContent managedRepositoryContent )
+        throws LayoutException, XMLException
+    {
+        String requestPathNoRepository = removePrefix( requestPath );
+        ArtifactReference artifactReference = pathParser.toArtifactReference( requestPathNoRepository );
+
+        String filePath = getFilePath( requestPath, managedRepositoryContent.getRepository() );
+
+        if (StringUtils.endsWith( artifactReference.getVersion(), "SNAPSHOT" ))
+        {
+            // read maven metadata to get last timestamp
+            File metadataDir = new File( managedRepositoryContent.getRepoRoot(), filePath).getParentFile();
+            ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( new File(metadataDir, METADATA_FILENAME ) );
+            int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
+            String timestamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();
+
+            // org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar
+            // ->  archiva-checksum-1.4-M4-20130425.081822-1.jar
+
+            filePath = StringUtils.replace( filePath, artifactReference.getArtifactId() + "-" + artifactReference.getVersion(),
+                                            artifactReference.getArtifactId() + "-" + StringUtils.remove( artifactReference.getVersion(), "-SNAPSHOT")
+                                                + "-" + timestamp + "-" + buildNumber );
+
+        }
+
+        return filePath;
+    }
+
 
 
     //-----------------------------
@@ -1002,4 +1037,13 @@ public class Maven2RepositoryStorage
     }
 
 
+    public PathParser getPathParser()
+    {
+        return pathParser;
+    }
+
+    public void setPathParser( PathParser pathParser )
+    {
+        this.pathParser = pathParser;
+    }
 }