[MRM-1620] add a tab to browse artifact content in artifact detail view

fix impl for mix of directories and files in the tree.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1309833 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-04-05 13:05:24 +00:00
parent 333ef52eb3
commit 4306c19f95
4 changed files with 36 additions and 19 deletions

View File

@ -19,6 +19,7 @@ package org.apache.archiva.rest.api.model;
*/
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
* @author Olivier Lamy
@ -26,6 +27,7 @@ import javax.xml.bind.annotation.XmlRootElement;
*/
@XmlRootElement( name = "artifactContentEntry" )
public class ArtifactContentEntry
implements Serializable
{
private String name;

View File

@ -670,37 +670,33 @@ public class DefaultBrowseService
Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();
while ( jarEntryEnumeration.hasMoreElements() )
{
JarEntry entry = jarEntryEnumeration.nextElement();
String entryName = entry.getName();
String entryRootPath = getRootPath( entryName );
int depth = StringUtils.countMatches( entryName, "/" );
JarEntry currentEntry = jarEntryEnumeration.nextElement();
String cleanedEntryName =
StringUtils.endsWith( currentEntry.getName(), "/" ) ? StringUtils.substringBeforeLast(
currentEntry.getName(), "/" ) : currentEntry.getName();
String entryRootPath = getRootPath( cleanedEntryName );
int depth = StringUtils.countMatches( cleanedEntryName, "/" );
if ( StringUtils.isEmpty( filterPath ) && !artifactContentEntryMap.containsKey( entryRootPath ) )
{
artifactContentEntryMap.put( entryRootPath,
new ArtifactContentEntry( entryRootPath, !entry.isDirectory(),
new ArtifactContentEntry( entryRootPath, !currentEntry.isDirectory(),
depth ) );
}
else
{
if ( StringUtils.startsWith( entryName, filterPath ) && ( depth > filterDepth || (
!entry.isDirectory() && depth == filterDepth ) ) )
if ( StringUtils.startsWith( cleanedEntryName, filterPath ) && ( depth >= filterDepth || (
!currentEntry.isDirectory() && depth == filterDepth ) ) )
{
// remove last /
String cleanedEntryName = StringUtils.endsWith( entryName, "/" )
? StringUtils.substringBeforeLast( entryName, "/" )
: entryName;
artifactContentEntryMap.put( cleanedEntryName,
new ArtifactContentEntry( cleanedEntryName, !entry.isDirectory(),
depth ) );
artifactContentEntryMap.put( cleanedEntryName, new ArtifactContentEntry( cleanedEntryName,
!currentEntry.isDirectory(),
depth ) );
}
}
}
if ( StringUtils.isNotEmpty( filterPath ) )
{
// apply more filtering here
// search entries filterPath/blabla
Map<String, ArtifactContentEntry> filteredArtifactContentEntryMap =
new HashMap<String, ArtifactContentEntry>();

View File

@ -63,7 +63,7 @@ public class ArtifactContentEntriesTests
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
new ArtifactContentEntry( "org/apache", false, 2 ) );
new ArtifactContentEntry( "org/apache", false, 1 ) );
}
@ -85,5 +85,24 @@ public class ArtifactContentEntriesTests
}
@Test
public void readArtifactContentEntriesDirectoryAndFiles()
throws Exception
{
File file = new File( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries =
browseService.readFileEntries( file, "org/apache/commons/logging/" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 10 ).contains(
new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4 ),
new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4 ) );
}
}

View File

@ -246,7 +246,7 @@ public class BrowseServiceTest
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
new ArtifactContentEntry( "org", false, 1 ), new ArtifactContentEntry( "META-INF", false, 1 ) );
new ArtifactContentEntry( "org", false, 0 ), new ArtifactContentEntry( "META-INF", false, 0 ) );
deleteTestRepo( testRepoId );
}
@ -272,7 +272,7 @@ public class BrowseServiceTest
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
new ArtifactContentEntry( "org/apache", false, 2 ) );
new ArtifactContentEntry( "org/apache", false, 1 ) );
deleteTestRepo( testRepoId );
}
}