-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support scanning for classpath resources #3705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcphilipp
merged 43 commits into
junit-team:main
from
mpkorstanje:support-classpath-resources-scanning
Jul 17, 2024
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
02ef108
Support scanning for class path resources
mpkorstanje 2f76493
Formatting
mpkorstanje 277272a
Doc
mpkorstanje f683deb
Fix
mpkorstanje c457b58
Clean up todos
mpkorstanje c9b3b0e
Clean up todos
mpkorstanje e5a1751
Clean up
mpkorstanje 2bab069
Extract common code in findClassesForPath and findResourcesForPath
mpkorstanje f34c4c9
Extract common file visitor code
mpkorstanje c84ad5e
Docs
mpkorstanje e43258e
Tests
mpkorstanje c374b93
Spotless
mpkorstanje 440e0e7
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje 6cca62a
Update CHANGELOG
mpkorstanje 704e584
Update CHANGELOG
mpkorstanje 9f99477
Remove resource name filter predicate
mpkorstanje 2df5201
Clean up to do.
mpkorstanje 862cb3b
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje f5d892b
Replace resource filter with predicate
mpkorstanje 6e95eeb
Revert "Replace resource filter with predicate"
mpkorstanje e59cc59
Revert "Remove resource name filter predicate"
mpkorstanje 767dcf4
Load canonical resources through classloader
mpkorstanje 94215bc
Touch up
mpkorstanje 794793a
Correctly resolve shadowed resources
mpkorstanje ac77e69
Fixup changelog
mpkorstanje 79f13bf
Fix up java doc
mpkorstanje cdeb3ea
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje 966e21f
Fix tryToLoadResource
mpkorstanje 358693f
Wrap class loader call in try
mpkorstanje 917f004
Add more tryToLoadResource tests
mpkorstanje ca1f81b
Touchups
mpkorstanje 59705ba
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje 7ffff49
Remove unnesesary try-catch
mpkorstanje 2144abe
Add more reflection support tests
mpkorstanje 27c0750
Merge branch 'main' into support-classpath-resources-scanning
mpkorstanje 52e5884
Merge remote-tracking branch 'origin/main' into support-classpath-res…
mpkorstanje 7df46a3
Find all available resources, including duplicates
mpkorstanje ee7b42a
Remove unused tryToLoadResource
mpkorstanje c0c9ee6
Suppress warnings
mpkorstanje 8621935
Remove resourceNameFilter predicate from Javadoc
marcphilipp 3a14696
Add test for finding duplicate resources
marcphilipp 3f348b3
Merge branch 'main' into support-classpath-resources-scanning
marcphilipp b826b32
Clean up unused import
mpkorstanje File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
junit-platform-commons/src/main/java/org/junit/platform/commons/support/Resource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.support; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.function.Predicate; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* Represents a resource on the classpath. | ||
* @since 1.11 | ||
* @see ReflectionSupport#findAllResourcesInClasspathRoot(URI, Predicate) | ||
* @see ReflectionSupport#findAllResourcesInPackage(String, Predicate) | ||
* @see ReflectionSupport#findAllResourcesInModule(String, Predicate) | ||
* @see ReflectionSupport#streamAllResourcesInClasspathRoot(URI, Predicate) | ||
* @see ReflectionSupport#streamAllResourcesInPackage(String, Predicate) | ||
* @see ReflectionSupport#streamAllResourcesInModule(String, Predicate) | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "1.11") | ||
public interface Resource { | ||
|
||
/** | ||
* Get the resource name. | ||
* <p> | ||
* The resource name is a {@code /}-separated path. The path is relative to | ||
* the classpath root in which the resource is located. | ||
* | ||
* @return the resource name; never {@code null} | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Get URI to a resource. | ||
* | ||
* @return the uri of the resource; never {@code null} | ||
*/ | ||
URI getUri(); | ||
|
||
/** | ||
* Returns an input stream for reading this resource. | ||
* | ||
* @return an input stream for this resource; never {@code null} | ||
* @throws IOException if an I/O exception occurs | ||
*/ | ||
default InputStream getInputStream() throws IOException { | ||
return getUri().toURL().openStream(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathFilters.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.util; | ||
|
||
import java.nio.file.Path; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* @since 1.11 | ||
*/ | ||
class ClasspathFilters { | ||
|
||
static final String CLASS_FILE_SUFFIX = ".class"; | ||
private static final String PACKAGE_INFO_FILE_NAME = "package-info" + CLASS_FILE_SUFFIX; | ||
private static final String MODULE_INFO_FILE_NAME = "module-info" + CLASS_FILE_SUFFIX; | ||
|
||
static Predicate<Path> classFiles() { | ||
return file -> isNotPackageInfo(file) && isNotModuleInfo(file) && isClassFile(file); | ||
} | ||
|
||
static Predicate<Path> resourceFiles() { | ||
return file -> !isClassFile(file); | ||
mpkorstanje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private static boolean isNotPackageInfo(Path path) { | ||
return !path.endsWith(PACKAGE_INFO_FILE_NAME); | ||
} | ||
|
||
private static boolean isNotModuleInfo(Path path) { | ||
return !path.endsWith(MODULE_INFO_FILE_NAME); | ||
} | ||
|
||
private static boolean isClassFile(Path file) { | ||
return file.getFileName().toString().endsWith(CLASS_FILE_SUFFIX); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.