]> source.dussan.org Git - archiva.git/commitdiff
more moving of maven2 logic from dav
authorOlivier Lamy <olamy@apache.org>
Wed, 4 Dec 2013 12:09:22 +0000 (12:09 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 4 Dec 2013 12:09:22 +0000 (12:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1547780 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/pom.xml
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/RepositoryPathUtil.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletRepositoryGroupTest.java
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 4e348b78169d885494ff47d7a5c85fdd5ee18ff4..ceacd17e22ece938cb297f8b2bba76814790ef2b 100644 (file)
       <artifactId>redback-common-test-resources</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
index 5e121406e0f2d62298c6256bfc2b1ec32b798080..7b32bdb796c4a7c94b44b7c49fb900ea819a4e1a 100644 (file)
@@ -198,7 +198,7 @@ public class ArchivaDavResourceFactory
     @PostConstruct
     public void initialize()
     {
-
+        // no op
     }
 
     public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request,
@@ -227,10 +227,17 @@ public class ArchivaDavResourceFactory
             log.debug( "Repository group '{}' accessed by '{}", repoGroupConfig.getId(), activePrincipal );
 
             // handle browse requests for virtual repos
-            if ( RepositoryPathUtil.getLogicalResource( archivaLocator.getOrigResourcePath() ).endsWith( "/" ) )
+            if ( getLogicalResource( archivaLocator, null, true ).endsWith( "/" ) )
             {
-                return getResourceFromGroup( request, repoGroupConfig.getRepositories(), archivaLocator,
-                                             repoGroupConfig );
+                try
+                {
+                    return getResourceFromGroup( request, repoGroupConfig.getRepositories(), archivaLocator,
+                                                 repoGroupConfig );
+                }
+                catch ( RepositoryAdminException e )
+                {
+                    throw new DavException( 500, e );
+                }
             }
             else
             {
@@ -252,7 +259,7 @@ public class ArchivaDavResourceFactory
 
                 if ( remoteRepository != null )
                 {
-                    String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
+                    String logicalResource = getLogicalResource( archivaLocator, null, false );
                     IndexingContext indexingContext = remoteRepositoryAdmin.createIndexContext( remoteRepository );
                     File resourceFile = StringUtils.equals( logicalResource, "/" )
                         ? new File( indexingContext.getIndexDirectoryFile().getParent() )
@@ -275,7 +282,8 @@ public class ArchivaDavResourceFactory
 
             try
             {
-                managedRepositoryContent = repositoryFactory.getManagedRepositoryContent( archivaLocator.getRepositoryId() );
+                managedRepositoryContent =
+                    repositoryFactory.getManagedRepositoryContent( archivaLocator.getRepositoryId() );
             }
             catch ( RepositoryNotFoundException e )
             {
@@ -292,16 +300,18 @@ public class ArchivaDavResourceFactory
             try
             {
                 resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent,
-                                              managedRepositoryAdmin.getManagedRepository( archivaLocator.getRepositoryId() ) );
+                                              managedRepositoryAdmin.getManagedRepository(
+                                                  archivaLocator.getRepositoryId() ) );
+
+                String logicalResource = getLogicalResource( archivaLocator, null, false );
+                resourcesInAbsolutePath.add(
+                    new File( managedRepositoryContent.getRepoRoot(), logicalResource ).getAbsolutePath() );
+
             }
             catch ( RepositoryAdminException e )
             {
                 throw new DavException( 500, e );
             }
-
-            String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
-            resourcesInAbsolutePath.add(
-                new File( managedRepositoryContent.getRepoRoot(), logicalResource ).getAbsolutePath() );
         }
 
         String requestedResource = request.getRequestURI();
@@ -329,7 +339,7 @@ public class ArchivaDavResourceFactory
                     if ( metadataChecksum.exists() )
                     {
                         LogicalResource logicalResource =
-                            new LogicalResource( RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ) );
+                            new LogicalResource (getLogicalResource( archivaLocator, null, false ) );
 
                         resource =
                             new ArchivaDavResource( metadataChecksum.getAbsolutePath(), logicalResource.getPath(), null,
@@ -367,8 +377,7 @@ public class ArchivaDavResourceFactory
                         {
                             File resourceFile = writeMergedMetadataToFile( mergedMetadata, filePath );
 
-                            LogicalResource logicalResource = new LogicalResource(
-                                RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ) );
+                            LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) );
 
                             resource =
                                 new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), null,
@@ -389,7 +398,7 @@ public class ArchivaDavResourceFactory
                         catch ( DigesterException de )
                         {
                             throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                                                    "Error occurred while generating checksum files." );
+                                                    "Error occurred while generating checksum files." + de.getMessage() );
                         }
                     }
                 }
@@ -437,10 +446,10 @@ public class ArchivaDavResourceFactory
         {
             for ( String repositoryId : repositories )
             {
-                ManagedRepositoryContent managedRepository;
+                ManagedRepositoryContent managedRepositoryContent;
                 try
                 {
-                    managedRepository = repositoryFactory.getManagedRepositoryContent( repositoryId );
+                    managedRepositoryContent = repositoryFactory.getManagedRepositoryContent( repositoryId );
                 }
                 catch ( RepositoryNotFoundException e )
                 {
@@ -453,21 +462,22 @@ public class ArchivaDavResourceFactory
 
                 try
                 {
+                    ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository( repositoryId );
                     DavResource updatedResource =
-                        processRepository( request, archivaLocator, activePrincipal, managedRepository,
-                                           managedRepositoryAdmin.getManagedRepository( repositoryId ) );
+                        processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent,
+                                           managedRepository );
                     if ( resource == null )
                     {
                         resource = updatedResource;
                     }
 
-                    String logicalResource = RepositoryPathUtil.getLogicalResource( archivaLocator.getResourcePath() );
+                    String logicalResource = getLogicalResource( archivaLocator, null, false );
                     if ( logicalResource.endsWith( "/" ) )
                     {
                         logicalResource = logicalResource.substring( 1 );
                     }
                     resourcesInAbsolutePath.add(
-                        new File( managedRepository.getRepoRoot(), logicalResource ).getAbsolutePath() );
+                        new File( managedRepositoryContent.getRepoRoot(), logicalResource ).getAbsolutePath() );
                 }
                 catch ( DavException e )
                 {
@@ -502,6 +512,21 @@ public class ArchivaDavResourceFactory
         return resource;
     }
 
+    private String getLogicalResource( ArchivaDavResourceLocator archivaLocator, ManagedRepository managedRepository,
+                                       boolean useOrigResourcePath )
+    {
+        // FIXME remove this hack
+        // but currently managedRepository can be null in case of group
+        String layout = managedRepository == null ? new ManagedRepository( ).getLayout() : managedRepository.getLayout();
+        RepositoryStorage repositoryStorage =
+            this.applicationContext.getBean( "repositoryStorage#" + layout, RepositoryStorage.class );
+        String path = repositoryStorage.getFilePath(
+            useOrigResourcePath ? archivaLocator.getOrigResourcePath() : archivaLocator.getResourcePath(), managedRepository );
+        log.debug( "found path {} for resourcePath: '{}' with managedRepo '{}' and layout '{}'", path,
+                   archivaLocator.getResourcePath(), managedRepository == null ? "null" : managedRepository.getId(), layout );
+        return path;
+    }
+
     private DavResource processRepository( final DavServletRequest request, ArchivaDavResourceLocator archivaLocator,
                                            String activePrincipal, ManagedRepositoryContent managedRepositoryContent,
                                            ManagedRepository managedRepository )
@@ -510,10 +535,7 @@ public class ArchivaDavResourceFactory
         DavResource resource = null;
         if ( isAuthorized( request, managedRepositoryContent.getId() ) )
         {
-            RepositoryStorage repositoryStorage =
-                this.applicationContext.getBean( "repositoryStorage#" + managedRepository.getLayout(),
-                                                 RepositoryStorage.class );
-            String path = repositoryStorage.getFilePath( archivaLocator.getResourcePath(), managedRepository );
+            String path = getLogicalResource( archivaLocator, managedRepository, false );
             if ( path.startsWith( "/" ) )
             {
                 path = path.substring( 1 );
@@ -641,7 +663,8 @@ public class ArchivaDavResourceFactory
                                        AuditEvent.CREATE_DIR, activePrincipal );
                 }
             }
-        } return resource;
+        }
+        return resource;
     }
 
     public DavResource createResource( final DavResourceLocator locator, final DavSession davSession )
@@ -649,10 +672,11 @@ public class ArchivaDavResourceFactory
     {
         ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator( locator );
 
-        ManagedRepositoryContent managedRepository;
+        ManagedRepositoryContent managedRepositoryContent;
         try
         {
-            managedRepository = repositoryFactory.getManagedRepositoryContent( archivaLocator.getRepositoryId() );
+            managedRepositoryContent =
+                repositoryFactory.getManagedRepositoryContent( archivaLocator.getRepositoryId() );
         }
         catch ( RepositoryNotFoundException e )
         {
@@ -664,17 +688,26 @@ public class ArchivaDavResourceFactory
             throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
         }
 
-        String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
-        if ( logicalResource.startsWith( "/" ) )
+        DavResource resource = null;
+        try
         {
-            logicalResource = logicalResource.substring( 1 );
-        }
-        File resourceFile = new File( managedRepository.getRepoRoot(), logicalResource );
-        DavResource resource =
-            new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource, managedRepository.getRepository(),
-                                    davSession, archivaLocator, this, mimeTypes, auditListeners, scheduler );
+            String logicalResource = getLogicalResource( archivaLocator, managedRepositoryAdmin.getManagedRepository(
+                archivaLocator.getRepositoryId() ), false );
+            if ( logicalResource.startsWith( "/" ) )
+            {
+                logicalResource = logicalResource.substring( 1 );
+            }
+            File resourceFile = new File( managedRepositoryContent.getRepoRoot(), logicalResource );
+            resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource,
+                                               managedRepositoryContent.getRepository(), davSession, archivaLocator,
+                                               this, mimeTypes, auditListeners, scheduler );
 
-        resource.addLockManager( lockManager );
+            resource.addLockManager( lockManager );
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new DavException( 500, e );
+        }
         return resource;
     }
 
@@ -893,10 +926,15 @@ public class ArchivaDavResourceFactory
     private DavResource getResourceFromGroup( DavServletRequest request, List<String> repositories,
                                               ArchivaDavResourceLocator locator,
                                               RepositoryGroupConfiguration repositoryGroupConfiguration )
-        throws DavException
+        throws DavException, RepositoryAdminException
     {
         List<File> mergedRepositoryContents = new ArrayList<File>();
-        String path = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
+        // multiple repo types so we guess they are all the same type
+        // so use the first one
+        // FIXME add a method with group in the repository storage
+        String firstRepoId = repositoryGroupConfiguration.getRepositories().get( 1 );
+
+        String path = getLogicalResource( locator, managedRepositoryAdmin.getManagedRepository( firstRepoId ), false );
         if ( path.startsWith( "/" ) )
         {
             path = path.substring( 1 );
index 7d5da69c10c52d078dcafb723d01a38bbc9d2e4f..9498d6b9495a125fbb3ba173844d5522ebeaf75a 100644 (file)
@@ -26,46 +26,6 @@ import org.apache.commons.lang.StringUtils;
  */
 public class RepositoryPathUtil
 {
-    public static String getLogicalResource( final String href )
-    {
-        String logicalResource = null;
-        String requestPathInfo = StringUtils.defaultString( href );
-
-        //remove prefix ie /repository/blah becomes /blah
-        requestPathInfo = removePrefix( requestPathInfo );
-
-        // Remove prefixing slash as the repository id doesn't contain it;
-        if ( requestPathInfo.startsWith( "/" ) )
-        {
-            requestPathInfo = requestPathInfo.substring( 1 );
-        }
-
-        int slash = requestPathInfo.indexOf( '/' );
-        if ( slash > 0 )
-        {
-            logicalResource = requestPathInfo.substring( slash );
-
-            if ( logicalResource.endsWith( "/.." ) )
-            {
-                logicalResource += "/";
-            }
-
-            if ( logicalResource != null && logicalResource.startsWith( "//" ) )
-            {
-                logicalResource = logicalResource.substring( 1 );
-            }
-
-            if ( logicalResource == null )
-            {
-                logicalResource = "/";
-            }
-        }
-        else
-        {
-            logicalResource = "/";
-        }
-        return logicalResource;
-    }
 
     public static String getRepositoryName( final String href )
     {
index 0171effebcb41117eab981d1553760b0fb581423..65afb1da1d0cc95bacfa87276de249891fb27d2a 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.archiva.maven2.metadata.MavenMetadataReader;
 import org.apache.archiva.model.ArchivaRepositoryMetadata;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
+import org.fest.assertions.api.Assertions;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -324,7 +325,8 @@ public class RepositoryServletRepositoryGroupTest
         assertTrue( StringUtils.contains( response.getText(), "Collection" ) );
         assertTrue( StringUtils.contains( response.getText(), "dummy/dummy-artifact" ) );
         assertTrue( StringUtils.contains( response.getText(), "1.0" ) );
-        assertTrue( StringUtils.contains( response.getText(), "2.0" ) );
+        Assertions.assertThat( response.getText() ).contains( "2.0" );
+        //assertTrue( StringUtils.contains( response.getText(), "2.0" ) );
     }
 
     protected void assertResponseMethodNotAllowed( WebResponse response )
index 4425880423602dabc753dd349616118b5f7dfe58..d5b203778500206f9d0d1aa66fa48815091fc112 100644 (file)
@@ -62,8 +62,10 @@ public interface RepositoryStorage
         throws ProxyDownloadException;
 
     /**
+     * add an other method to evaluate real path as when receiving -SNAPSHOT (for maven storage)
+     * request redirect to the last build
      * @param requestPath the web uri request
-     * @param managedRepository the used managed repository
+     * @param managedRepository the used managed repository can be <code>null</code> so last version won't be resolved
      * @return the file path
      * @since 2.0.0
      */
index e89d1e1ea60fbd356ba3daa42c27939fa1828aa5..699f41bfce5b1d7f8e16e4d4fdb1830de2f370fe 100644 (file)
@@ -713,6 +713,7 @@ public class Maven2RepositoryStorage
 
     public String getFilePath( String requestPath, ManagedRepository managedRepository )
     {
+        // managedRepository can be null
         // extract artifact reference from url
         // groupId:artifactId:version:packaging:classifier
         //org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar