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>();
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
- new ArtifactContentEntry( "org/apache", false, 2 ) );
+ new ArtifactContentEntry( "org/apache", false, 1 ) );
}
}
+ @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 ) );
+
+ }
+
}
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 );
}
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 );
}
}