-
Notifications
You must be signed in to change notification settings - Fork 3.5k
remove dependency on org.reflections #18295
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11379,26 +11379,6 @@ distributed under the License is distributed on an "AS IS" BASIS, | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| ========== | ||
| Notice for: org.reflections:reflections-0.10.2 | ||
| ---------- | ||
|
|
||
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
| Version 2, December 2004 | ||
|
|
||
| Copyright (C) 2004 Sam Hocevar <[email protected]> | ||
|
|
||
| Everyone is permitted to copy and distribute verbatim or modified | ||
| copies of this license document, and changing it is allowed as long | ||
| as the name is changed. | ||
|
|
||
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
| TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
|
||
| 0. You just DO WHAT THE FUCK YOU WANT TO. | ||
|
|
||
| Also licensed under BSD-2-Clause according to https://github.com/ronmamo/reflections/blob/0.9.11/pom.xml#L20-L22 | ||
|
|
||
| ========== | ||
| Notice for: org.slf4j:slf4j-api-1.7.30 | ||
| ---------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,128 @@ | ||||||||||||||||||||||||||||||||||||||||||
| package org.logstash.plugins.discovery; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||
| import java.io.UncheckedIOException; | ||||||||||||||||||||||||||||||||||||||||||
| import java.lang.annotation.Annotation; | ||||||||||||||||||||||||||||||||||||||||||
| import java.net.JarURLConnection; | ||||||||||||||||||||||||||||||||||||||||||
| import java.net.URISyntaxException; | ||||||||||||||||||||||||||||||||||||||||||
| import java.net.URL; | ||||||||||||||||||||||||||||||||||||||||||
| import java.net.URLConnection; | ||||||||||||||||||||||||||||||||||||||||||
| import java.nio.file.Files; | ||||||||||||||||||||||||||||||||||||||||||
| import java.nio.file.Path; | ||||||||||||||||||||||||||||||||||||||||||
| import java.nio.file.Paths; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.Enumeration; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.HashSet; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.jar.JarEntry; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.jar.JarFile; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Minimal package scanner to locate classes within Logstash's own packages. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| final class PackageScanner { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private static final String CLASS_SUFFIX = ".class"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private PackageScanner() { | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private static String toClassName(String resourcePath) { | ||||||||||||||||||||||||||||||||||||||||||
| return resourcePath | ||||||||||||||||||||||||||||||||||||||||||
| .substring(0, resourcePath.length() - CLASS_SUFFIX.length()) | ||||||||||||||||||||||||||||||||||||||||||
| .replace('/', '.') | ||||||||||||||||||||||||||||||||||||||||||
| .replace('\\', '.'); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| static Set<Class<?>> scanForAnnotation(String basePackage, Class<? extends Annotation> annotation, ClassLoader loader) { | ||||||||||||||||||||||||||||||||||||||||||
| Set<String> classNames = collectClassNames(basePackage, loader); | ||||||||||||||||||||||||||||||||||||||||||
| Set<Class<?>> result = new HashSet<>(); | ||||||||||||||||||||||||||||||||||||||||||
| for (String className : classNames) { | ||||||||||||||||||||||||||||||||||||||||||
| if (className.contains("$")) { | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||
| Class<?> candidate = Class.forName(className, false, loader); | ||||||||||||||||||||||||||||||||||||||||||
| if (candidate.isAnnotationPresent(annotation)) { | ||||||||||||||||||||||||||||||||||||||||||
| result.add(candidate); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } catch (ClassNotFoundException | LinkageError e) { | ||||||||||||||||||||||||||||||||||||||||||
| throw new IllegalStateException("Unable to load class discovered during scanning: " + className, e); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
jsvd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+52
Contributor
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. Given that the size of
Suggested change
where the private static Class<?> loadClass(ClassLoader loader, String className) {
try {
return Class.forName(className, false, loader);
} catch (ClassNotFoundException | LinkageError e) {
throw new IllegalStateException("Unable to load class discovered during scanning: " + className, e);
}
}
private static boolean isInnerClass(String name) {
return name.contains("$");
} |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private static Set<String> collectClassNames(String basePackage, ClassLoader loader) { | ||||||||||||||||||||||||||||||||||||||||||
| String resourcePath = basePackage.replace('.', '/'); | ||||||||||||||||||||||||||||||||||||||||||
| Set<String> classNames = new HashSet<>(); | ||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||
| Enumeration<URL> resources = loader.getResources(resourcePath); | ||||||||||||||||||||||||||||||||||||||||||
| while (resources.hasMoreElements()) { | ||||||||||||||||||||||||||||||||||||||||||
| URL resource = resources.nextElement(); | ||||||||||||||||||||||||||||||||||||||||||
| String protocol = resource.getProtocol(); | ||||||||||||||||||||||||||||||||||||||||||
| if ("file".equals(protocol)) { | ||||||||||||||||||||||||||||||||||||||||||
| scanDirectory(resource, basePackage, classNames); | ||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||
| // Open connection once to check type and reuse for scanning | ||||||||||||||||||||||||||||||||||||||||||
| URLConnection connection = resource.openConnection(); | ||||||||||||||||||||||||||||||||||||||||||
| if (connection instanceof JarURLConnection) { | ||||||||||||||||||||||||||||||||||||||||||
| scanJar((JarURLConnection) connection, resourcePath, classNames); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+70
|
||||||||||||||||||||||||||||||||||||||||||
| URLConnection connection = resource.openConnection(); | |
| if (connection instanceof JarURLConnection) { | |
| scanJar((JarURLConnection) connection, resourcePath, classNames); | |
| } | |
| try (URLConnection connection = resource.openConnection()) { | |
| if (connection instanceof JarURLConnection) { | |
| scanJar((JarURLConnection) connection, resourcePath, classNames); | |
| } | |
| } |
jsvd marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.logstash.plugins.discovery; | ||
|
|
||
| import co.elastic.logstash.api.Codec; | ||
| import co.elastic.logstash.api.Filter; | ||
| import co.elastic.logstash.api.Input; | ||
| import co.elastic.logstash.api.Output; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class PluginRegistryTest { | ||
|
|
||
| private final PluginRegistry registry = PluginRegistry.getInstance(); | ||
|
|
||
| @Test | ||
| public void discoversBuiltInInputPlugin() { | ||
| Class<?> input = registry.getInputClass("java_stdin"); | ||
| assertNotNull(input); | ||
| assertTrue(Input.class.isAssignableFrom(input)); | ||
| } | ||
|
|
||
| @Test | ||
| public void discoversBuiltInOutputPlugin() { | ||
| Class<?> output = registry.getOutputClass("java_stdout"); | ||
| assertNotNull(output); | ||
| assertTrue(Output.class.isAssignableFrom(output)); | ||
| } | ||
|
|
||
| @Test | ||
| public void discoversBuiltInFilterPlugin() { | ||
| Class<?> filter = registry.getFilterClass("java_uuid"); | ||
| assertNotNull(filter); | ||
| assertTrue(Filter.class.isAssignableFrom(filter)); | ||
| } | ||
|
|
||
| @Test | ||
| public void discoversBuiltInCodecPlugin() { | ||
| Class<?> codec = registry.getCodecClass("java_line"); | ||
| assertNotNull(codec); | ||
| assertTrue(Codec.class.isAssignableFrom(codec)); | ||
| } | ||
| } |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.