Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Joakim Erdfelt 2020-10-28 11:35:12 -05:00
commit c182595a0f
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
3 changed files with 26 additions and 5 deletions

View File

@ -100,13 +100,13 @@
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.15.300</version>
<version>3.16.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
<version>3.8.0</version>
<version>3.9.0</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -26,6 +26,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@ -416,14 +417,17 @@ public class ResourceCollection extends Resource
public String[] list()
{
assertResourcesSet();
HashSet<String> set = new HashSet<>();
for (Resource r : _resources)
{
Collections.addAll(set, r.list());
String[] list = r.list();
if (list != null)
Collections.addAll(set, list);
}
return (String[])set.stream().sorted().toArray();
String[] result = set.toArray(new String[0]);
Arrays.sort(result);
return result;
}
@Override

View File

@ -23,6 +23,7 @@ import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.Arrays;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -33,7 +34,10 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.emptyArray;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -175,6 +179,19 @@ public class ResourceCollectionTest
});
}
@Test
public void testList() throws Exception
{
ResourceCollection rc1 = new ResourceCollection(
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/one/"),
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/two/"),
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/three/"));
assertThat(Arrays.asList(rc1.list()), contains("1.txt", "2.txt", "3.txt", "dir/"));
assertThat(Arrays.asList(rc1.addPath("dir").list()), contains("1.txt", "2.txt", "3.txt"));
assertThat(rc1.addPath("unknown").list(), emptyArray());
}
@Test
public void testMultipleSources1() throws Exception
{