]> source.dussan.org Git - archiva.git/commitdiff
[MRM-901]
authorMaria Odea B. Ching <oching@apache.org>
Wed, 18 Mar 2009 09:56:41 +0000 (09:56 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Wed, 18 Mar 2009 09:56:41 +0000 (09:56 +0000)
o merge all versions of artifacts with same groupId in all repos under a group (browse)
o added test case

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755532 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/MockServletAuthenticator.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletRepositoryGroupTest.java
archiva-modules/archiva-web/archiva-webdav/src/test/resources/org/apache/maven/archiva/webdav/RepositoryServletTest.xml

index 201bb828d04b8593dfbb4caeee3676502bc51f1c..54fb20e500c41521dd60d237cae1914edaaba740 100644 (file)
@@ -192,7 +192,7 @@ public class ArchivaDavResourceFactory
             repositories.addAll( repoGroupConfig.getRepositories() );
 
             // handle browse requests for virtual repos
-            if ( RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ).endsWith( "/" ) )
+            if ( RepositoryPathUtil.getLogicalResource( archivaLocator.getOrigResourcePath() ).endsWith( "/" ) )
             {
                 return getResource( request, repositories, archivaLocator );
             }
index 828667b7a7937017527d664a64bc249398e26b34..30c5335f77a46d12503440b9c1169bc4a9905a39 100644 (file)
@@ -37,6 +37,10 @@ public class ArchivaDavResourceLocator
     private final String repositoryId;
 
     private final DavLocatorFactory davLocatorFactory;
+    
+    // retains the trailing '/' at the end of the path, which is used to determine if it is a
+    //      virtual repo browse request
+    private final String origResourcePath;
 
     public ArchivaDavResourceLocator( String prefix, String resourcePath, String repositoryId,
                                       DavLocatorFactory davLocatorFactory )
@@ -63,8 +67,10 @@ public class ArchivaDavResourceLocator
 
         href = hrefPrefix + escapedPath;
         
+        this.origResourcePath = path;
+        
         //Remove trailing slashes otherwise Text.getRelativeParent fails
-        if (resourcePath.endsWith("/") && resourcePath.length() > 1)
+        if ( resourcePath.endsWith( "/" ) && resourcePath.length() > 1 )
         {
             path = resourcePath.substring( 0, resourcePath.length() - 1 );
         }
@@ -155,4 +161,9 @@ public class ArchivaDavResourceLocator
         }
         return false;
     }
+
+    public String getOrigResourcePath()
+    {
+        return origResourcePath;
+    }
 }
index 25e9955322db344c4d73fb50634f1130f16c2c31..4df207416b475f7e55047d95c3645e407dbdc02d 100644 (file)
@@ -125,26 +125,45 @@ public class IndexWriter
         else 
         {            
             // virtual repository - filter unique directories
-            Map<String, File> uniqueChildFiles = new HashMap<String, File>();
+            Map<String, List<String>> uniqueChildFiles = new HashMap<String, List<String>>();
             List<String> sortedList = new ArrayList<String>();
             for( File resource : localResources )
-            {
+            {   
                 List<File> files = new ArrayList<File>( Arrays.asList( resource.listFiles() ) ); 
-                                                
                 for ( File file : files )
                 {   
+                    List<String> mergedChildFiles = new ArrayList<String>();
                     if( uniqueChildFiles.get( file.getName() ) == null )
                     {
-                        uniqueChildFiles.put( file.getName(), file );
-                        sortedList.add( file.getName() );
-                    }                    
+                        mergedChildFiles.add( file.getAbsolutePath() );                        
+                    }
+                    else
+                    {
+                        mergedChildFiles = uniqueChildFiles.get( file.getName() );
+                        if( !mergedChildFiles.contains( file.getAbsolutePath() ) )
+                        {
+                            mergedChildFiles.add( file.getAbsolutePath() );
+                        }
+                    }
+                    uniqueChildFiles.put( file.getName(), mergedChildFiles );
+                    sortedList.add( file.getName() );
                 }
             }
              
             Collections.sort( sortedList );
+            List<String> written = new ArrayList<String>();
             for ( String fileName : sortedList )
-            {
-                writeHyperlink( writer, fileName, ( (File) uniqueChildFiles.get( fileName ) ).isDirectory());
+            {   
+                List<String> childFilesFromMap = uniqueChildFiles.get( fileName );
+                for( String childFilePath : childFilesFromMap )
+                {   
+                    File childFile = new File( childFilePath );
+                    if( !written.contains( childFile.getName() ) )
+                    {   
+                        written.add( childFile.getName() );
+                        writeHyperlink( writer, fileName, childFile.isDirectory() );                        
+                    }
+                }
             }
         }
     }
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/MockServletAuthenticator.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/MockServletAuthenticator.java
new file mode 100644 (file)
index 0000000..4ea71a9
--- /dev/null
@@ -0,0 +1,34 @@
+package org.apache.maven.archiva.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.security.ArchivaServletAuthenticator;
+import org.codehaus.plexus.redback.authorization.UnauthorizedException;
+
+public class MockServletAuthenticator
+    extends ArchivaServletAuthenticator
+{
+    @Override
+    public boolean isAuthorized( String principal, String repoId, boolean isWriteRequest )
+        throws UnauthorizedException
+    {
+        return true;
+    }
+}
index 853af6d17c3ef5e7a2243897596c702f225fa126..47a94a9e36f55c89aed66df2e24093986c8b4343 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
@@ -210,17 +211,7 @@ public class RepositoryServletRepositoryGroupTest
          
         assertResponseMethodNotAllowed( response );
     }
-    
-    public void testBrowseRepositoryGroup()
-        throws Exception
-    {
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS );
-        WebResponse response = sc.getResponse( request ); 
-                
-        assertNotNull( "Should have received a response", response );
-        assertEquals( "Should have been an 401 response code.", HttpServletResponse.SC_UNAUTHORIZED, response.getResponseCode() );
-    }
-    
+        
     // MRM-872
     public void testGetMergedMetadata()
         throws Exception
@@ -287,6 +278,32 @@ public class RepositoryServletRepositoryGroupTest
         assertResponseOK( response );
         assertEquals( "5b85ea4aa5f52bb76760041a52f98de8  maven-metadata-group-with-valid-repos.xml", response.getText().trim() );
     }
+    
+    // MRM-901
+    public void testBrowseWithTwoArtifactsWithSameGroupIdInRepos()
+        throws Exception
+    {
+        String resourceName = "dummy/dummy-artifact/1.0/dummy-artifact-1.0.txt";
+        
+        File dummyInternalResourceFile = new File( repoRootFirst, resourceName );
+        dummyInternalResourceFile.getParentFile().mkdirs();
+        FileUtils.writeStringToFile( dummyInternalResourceFile, "first", null );
+        
+        resourceName = "dummy/dummy-artifact/2.0/dummy-artifact-2.0.txt";
+        
+        File dummyReleasesResourceFile = new File( repoRootLast, resourceName );
+        dummyReleasesResourceFile.getParentFile().mkdirs();
+        FileUtils.writeStringToFile( dummyReleasesResourceFile, "last", null );
+        
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/dummy-artifact/" );
+        WebResponse response = sc.getResource( request );
+        
+        assertResponseOK( response );
+        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" ) );
+    }
         
     protected void assertResponseMethodNotAllowed( WebResponse response )
     {
index e73c0f41f0f7f708ee3f620e7f44c7ecc023ed1a..017d761b8a0124d0285a9a2f15f90e1fac8254a0 100644 (file)
       <role-hint>default</role-hint>
       <implementation>org.apache.maven.archiva.webdav.BypassSecuritySystem</implementation>
     </component>
+    
+    <component>
+      <role>org.apache.maven.archiva.security.ServletAuthenticator</role>
+      <implementation>org.apache.maven.archiva.webdav.MockServletAuthenticator</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.system.SecuritySystem</role>
+          <field-name>securitySystem</field-name>
+        </requirement>
+      </requirements>
+    </component>
        
        <component>
       <role>org.apache.maven.archiva.webdav.ArchivaDavResourceFactory</role>