Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
02ef108
Support scanning for class path resources
mpkorstanje Jan 9, 2024
2f76493
Formatting
mpkorstanje Feb 25, 2024
277272a
Doc
mpkorstanje Feb 25, 2024
f683deb
Fix
mpkorstanje Feb 25, 2024
c457b58
Clean up todos
mpkorstanje Feb 29, 2024
c9b3b0e
Clean up todos
mpkorstanje Feb 29, 2024
e5a1751
Clean up
mpkorstanje Mar 7, 2024
2bab069
Extract common code in findClassesForPath and findResourcesForPath
mpkorstanje Mar 7, 2024
f34c4c9
Extract common file visitor code
mpkorstanje Mar 7, 2024
c84ad5e
Docs
mpkorstanje Mar 7, 2024
e43258e
Tests
mpkorstanje Mar 7, 2024
c374b93
Spotless
mpkorstanje Mar 7, 2024
440e0e7
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje Mar 7, 2024
6cca62a
Update CHANGELOG
mpkorstanje Mar 7, 2024
704e584
Update CHANGELOG
mpkorstanje Mar 7, 2024
9f99477
Remove resource name filter predicate
mpkorstanje Jun 13, 2024
2df5201
Clean up to do.
mpkorstanje Jun 13, 2024
862cb3b
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje Jun 13, 2024
f5d892b
Replace resource filter with predicate
mpkorstanje Jun 14, 2024
6e95eeb
Revert "Replace resource filter with predicate"
mpkorstanje Jun 14, 2024
e59cc59
Revert "Remove resource name filter predicate"
mpkorstanje Jun 14, 2024
767dcf4
Load canonical resources through classloader
mpkorstanje Jun 14, 2024
94215bc
Touch up
mpkorstanje Jun 14, 2024
794793a
Correctly resolve shadowed resources
mpkorstanje Jun 14, 2024
ac77e69
Fixup changelog
mpkorstanje Jun 14, 2024
79f13bf
Fix up java doc
mpkorstanje Jun 14, 2024
cdeb3ea
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje Jun 14, 2024
966e21f
Fix tryToLoadResource
mpkorstanje Jun 15, 2024
358693f
Wrap class loader call in try
mpkorstanje Jun 15, 2024
917f004
Add more tryToLoadResource tests
mpkorstanje Jun 15, 2024
ca1f81b
Touchups
mpkorstanje Jun 15, 2024
59705ba
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje Jun 15, 2024
7ffff49
Remove unnesesary try-catch
mpkorstanje Jun 15, 2024
2144abe
Add more reflection support tests
mpkorstanje Jun 15, 2024
27c0750
Merge branch 'main' into support-classpath-resources-scanning
mpkorstanje Jun 17, 2024
52e5884
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje Jun 26, 2024
7df46a3
Find all available resources, including duplicates
mpkorstanje Jul 8, 2024
ee7b42a
Remove unused tryToLoadResource
mpkorstanje Jul 8, 2024
c0c9ee6
Suppress warnings
mpkorstanje Jul 8, 2024
8621935
Remove resourceNameFilter predicate from Javadoc
marcphilipp Jul 9, 2024
3a14696
Add test for finding duplicate resources
marcphilipp Jul 9, 2024
3f348b3
Merge branch 'main' into support-classpath-resources-scanning
marcphilipp Jul 9, 2024
b826b32
Clean up unused import
mpkorstanje Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Correctly resolve shadowed resources
  • Loading branch information
mpkorstanje committed Jun 14, 2024
commit 794793a9f396f60acd5f451e8305deecbd71b062
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void scanForClassesInClasspathRootWithinJarWithSpacesInPath() throws Exception {
private void scanForClassesInClasspathRootWithinJarFile(String resourceName) throws Exception {
var jarfile = getClass().getResource(resourceName);

try (var classLoader = new URLClassLoader(new URL[] { jarfile })) {
try (var classLoader = new URLClassLoader(new URL[] { jarfile }, null)) {
var classpathScanner = new ClasspathScanner(() -> classLoader, ReflectionUtils::tryToLoadClass,
ReflectionUtils::tryToLoadResource);

Expand All @@ -217,7 +217,7 @@ void scanForResourcesInClasspathRootWithinJarWithSpacesInPath() throws Exception
private void scanForResourcesInClasspathRootWithinJarFile(String resourceName) throws Exception {
var jarfile = getClass().getResource(resourceName);

try (var classLoader = new URLClassLoader(new URL[] { jarfile })) {
try (var classLoader = new URLClassLoader(new URL[] { jarfile }, null)) {
var classpathScanner = new ClasspathScanner(() -> classLoader, ReflectionUtils::tryToLoadClass,
ReflectionUtils::tryToLoadResource);

Expand All @@ -230,6 +230,43 @@ private void scanForResourcesInClasspathRootWithinJarFile(String resourceName) t
}
}

@Test
void scanForResourcesInShadowedClassPathRoot() throws Exception {
var jarFile = getClass().getResource("/jartest.jar");
var shadowedJarFile = getClass().getResource("/jartest-shadowed.jar");

try (var classLoader = new URLClassLoader(new URL[] { jarFile, shadowedJarFile }, null)) {
var classpathScanner = new ClasspathScanner(() -> classLoader, ReflectionUtils::tryToLoadClass,
ReflectionUtils::tryToLoadResource);

var resources = classpathScanner.scanForResourcesInClasspathRoot(shadowedJarFile.toURI(), allResources);
assertThat(resources).extracting(Resource::getName).containsExactlyInAnyOrder(
"org/junit/platform/jartest/included/unique.resource",
"org/junit/platform/jartest/included/included.resource",
"org/junit/platform/jartest/included/recursive/recursively-included.resource", "META-INF/MANIFEST.MF");

assertThat(resources).extracting(Resource::getUri) //
.map(ClasspathScannerTests::jarFileAndEntry) //
.containsExactlyInAnyOrder(
// This resource only exists in the shadowed jar file
"jartest-shadowed.jar!/org/junit/platform/jartest/included/unique.resource",
// These resources exist in both the jar and shadowed jar file.
// So they're discovered in the shadowed jar, but loaded from the regular jar.
"jartest.jar!/org/junit/platform/jartest/included/included.resource",
"jartest.jar!/org/junit/platform/jartest/included/recursive/recursively-included.resource",
"jartest.jar!/META-INF/MANIFEST.MF");
}
}

private static String jarFileAndEntry(URI uri) {
var uriString = uri.toString();
int lastJarUriSeparator = uriString.lastIndexOf("!/");
var jarUri = uriString.substring(0, lastJarUriSeparator);
var jarEntry = uriString.substring(lastJarUriSeparator + 1);
var fileName = jarUri.substring(jarUri.lastIndexOf("/") + 1);
return fileName + "!" + jarEntry;
}

@Test
void scanForClassesInPackage() {
var classes = classpathScanner.scanForClassesInPackage("org.junit.platform.commons", allClasses);
Expand Down
Binary file not shown.