]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1620] add a tab to browse artifact content in artifact detail view
authorOlivier Lamy <olamy@apache.org>
Thu, 5 Apr 2012 13:05:24 +0000 (13:05 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 5 Apr 2012 13:05:24 +0000 (13:05 +0000)
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

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactContentEntry.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java

index 7a9b2ff91fb1dacd4aa933be850c50e34dea63fb..7a68af9b9df0f56907927a46bae819a90c2955db 100644 (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;
 
index 85a0da594e1c79843849cbf3742dddc2fb704a6c..fae29e386eefc480c8664a097f0241b52a66fbf6 100644 (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>();
 
index 4bee1351b7be3619e50d5403fc3b6aad9ea49439..7edaf5a7b4fe1662e6da8b9b57ecfacc7016b8cb 100644 (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 ) );
+
+    }
+
 
 }
index 854886f8a1e4bf036f54af5b78d658d6c32c8297..e4bf009a465e02fefa11662ad1f8cb0b5ae20468 100644 (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 );
     }
 }