From 4306c19f95221683015d753102e141837d6015c4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 5 Apr 2012 13:05:24 +0000 Subject: [PATCH] [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 --- .../rest/api/model/ArtifactContentEntry.java | 2 ++ .../rest/services/DefaultBrowseService.java | 28 ++++++++----------- .../services/ArtifactContentEntriesTests.java | 21 +++++++++++++- .../rest/services/BrowseServiceTest.java | 4 +-- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactContentEntry.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactContentEntry.java index 7a9b2ff91..7a68af9b9 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactContentEntry.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactContentEntry.java @@ -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; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 85a0da594..fae29e386 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -670,37 +670,33 @@ public class DefaultBrowseService Enumeration 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 filteredArtifactContentEntryMap = new HashMap(); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java index 4bee1351b..7edaf5a7b 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java @@ -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 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 ) ); + + } + } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java index 854886f8a..e4bf009a4 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java @@ -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 ); } } -- 2.39.5