-
Notifications
You must be signed in to change notification settings - Fork 357
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
Fixes #4304: ResourceConfig not properly using specified ClassLoader #4305
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -655,6 +655,27 @@ public final ResourceConfig packages(final boolean recursive, final String... pa | |
return registerFinder(new PackageNamesScanner(packages, recursive)); | ||
} | ||
|
||
/** | ||
* Adds array of package names which will be used to scan for components. | ||
* <p/> | ||
* Package scanning ignores an inheritance and therefore {@link Path} annotation | ||
* on parent classes and interfaces will be ignored. | ||
* <p/> | ||
* @param recursive defines whether any nested packages in the collection of specified | ||
* package names should be recursively scanned (value of {@code true}) | ||
* as part of the package scanning or not (value of {@code false}). | ||
* @param classLoader defines the classloader used for scanning the packages and loading the classes. | ||
* @param packages array of package names. | ||
* @return updated resource configuration instance. | ||
* @see #packages(String...) | ||
*/ | ||
public final ResourceConfig packages(final boolean recursive, final ClassLoader classLoader, final String... packages) { | ||
if (packages == null || packages.length == 0) { | ||
return this; | ||
} | ||
return registerFinder(new PackageNamesScanner(classLoader, packages, recursive)); | ||
} | ||
|
||
/** | ||
* Adds array of file and directory names to scan for components. | ||
* <p/> | ||
|
@@ -877,11 +898,21 @@ private Set<Class<?>> scanClasses() { | |
rfs.add(new FilesScanner(classPathElements, true)); | ||
} | ||
|
||
final AnnotationAcceptingListener afl = | ||
final AnnotationAcceptingListener parentAfl = | ||
AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(_state.getClassLoader()); | ||
|
||
for (final ResourceFinder resourceFinder : rfs) { | ||
AnnotationAcceptingListener afl = parentAfl; | ||
|
||
// Workaround because otherwise classes from a different classloader can't be loaded | ||
if (resourceFinder instanceof PackageNamesScanner) { | ||
final ClassLoader classLoader = ((PackageNamesScanner) resourceFinder).getClassloader(); | ||
afl = AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(classLoader); | ||
} | ||
|
||
while (resourceFinder.hasNext()) { | ||
final String next = resourceFinder.next(); | ||
|
||
if (afl.accept(next)) { | ||
final InputStream in = resourceFinder.open(); | ||
try { | ||
|
@@ -896,10 +927,11 @@ private Set<Class<?>> scanClasses() { | |
} | ||
} | ||
} | ||
|
||
result.addAll(afl.getAnnotatedClasses()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
result.addAll(afl.getAnnotatedClasses()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + |
||
return result; | ||
} | ||
|
||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not do this when the default ClassLoader: