Browse Source

Fixing browse service filter handling

Improved handling of slashes at the beginning of filters
Added patterns for surefire tests to ensure the test runs
tags/archiva-2.2.3
Martin Stockhammer 7 years ago
parent
commit
d61f68e684

+ 4
- 0
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml View File

@@ -455,6 +455,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
</includes>
<argLine>-Xmx512m -Xms512m -server -XX:MaxPermSize=256m ${jacocoagent}</argLine>
<systemPropertyVariables>
<appserver.base>${project.build.directory}/appserver-base</appserver.base>

+ 10
- 9
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java View File

@@ -1093,15 +1093,16 @@ public class DefaultBrowseService
}
}

protected List<ArtifactContentEntry> readFileEntries( File file, String filterPath, String repoId )
protected List<ArtifactContentEntry> readFileEntries(final File file, final String filterPath, final String repoId )
throws IOException
{
String cleanedfilterPath = filterPath==null ? "" : (StringUtils.startsWith(filterPath, "/") ?
StringUtils.substringAfter(filterPath, "/") : filterPath);
Map<String, ArtifactContentEntry> artifactContentEntryMap = new HashMap<>();
int filterDepth = StringUtils.countMatches( filterPath, "/" );
/*if ( filterDepth == 0 )
{
filterDepth = 1;
}*/
int filterDepth = StringUtils.countMatches( cleanedfilterPath, "/" );
if (!StringUtils.endsWith(cleanedfilterPath,"/") && !StringUtils.isEmpty(cleanedfilterPath)) {
filterDepth++;
}
JarFile jarFile = new JarFile( file );
try
{
@@ -1113,7 +1114,7 @@ public class DefaultBrowseService
StringUtils.substringBeforeLast( currentEntry.getName(), "/" ) : currentEntry.getName();
String entryRootPath = getRootPath( cleanedEntryName );
int depth = StringUtils.countMatches( cleanedEntryName, "/" );
if ( StringUtils.isEmpty( filterPath ) //
if ( StringUtils.isEmpty( cleanedfilterPath ) //
&& !artifactContentEntryMap.containsKey( entryRootPath ) //
&& depth == filterDepth )
{
@@ -1124,7 +1125,7 @@ public class DefaultBrowseService
}
else
{
if ( StringUtils.startsWith( cleanedEntryName, filterPath ) //
if ( StringUtils.startsWith( cleanedEntryName, cleanedfilterPath ) //
&& ( depth == filterDepth || ( !currentEntry.isDirectory() && depth == filterDepth ) ) )
{
artifactContentEntryMap.put( cleanedEntryName, new ArtifactContentEntry( cleanedEntryName,
@@ -1134,7 +1135,7 @@ public class DefaultBrowseService
}
}

if ( StringUtils.isNotEmpty( filterPath ) )
if ( StringUtils.isNotEmpty( cleanedfilterPath ) )
{
Map<String, ArtifactContentEntry> filteredArtifactContentEntryMap = new HashMap<>();


+ 2
- 1
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java View File

@@ -20,6 +20,7 @@ package org.apache.archiva.rest.services;

import junit.framework.TestCase;
import org.apache.archiva.rest.api.model.ArtifactContentEntry;
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Olivier Lamy
*/
@RunWith( JUnit4.class )
@RunWith( ArchivaBlockJUnit4ClassRunner.class )
public class ArtifactContentEntriesTests
extends TestCase
{

Loading…
Cancel
Save