[MRM-901]

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
This commit is contained in:
Maria Odea B. Ching 2009-03-18 09:56:41 +00:00
parent 7ec2e6c8a5
commit aab7502db7
6 changed files with 113 additions and 21 deletions

View 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 );
}

View File

@ -38,6 +38,10 @@ public class ArchivaDavResourceLocator
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;
}
}

View 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() );
}
}
}
}
}

View File

@ -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;
}
}

View 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;
@ -211,16 +212,6 @@ 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
@ -288,6 +279,32 @@ public class RepositoryServletRepositoryGroupTest
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 )
{
assertNotNull( "Should have recieved a response", response );

View File

@ -94,6 +94,17 @@
<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>
<implementation>org.apache.maven.archiva.webdav.UnauthenticatedDavResourceFactory</implementation>