AbstractExtensionFinder implements ExtensionFinder, PluginStateListener { public static Extension findExtensionAnnotation(Class<?> clazz) { if (clazz.isAnnotationPresent(Extension.class)) { return clazz.getAnnotation(Extension.class); } for (Annotation annotation : clazz.getAnnotations()) { Class<? extends Annotation> annotationClass = annotation.annotationType(); if (!annotationClass.getName().startsWith("java.lang.annotation")) { Extension extensionAnnotation = findExtensionAnnotation(annotationClass); if (extensionAnnotation != null) { return extensionAnnotation; } } } return null; } AbstractExtensionFinder(PluginManager pluginManager); abstract Map<String, Set<String>> readPluginsStorages(); abstract Map<String, Set<String>> readClasspathStorages(); @Override @SuppressWarnings("unchecked") List<ExtensionWrapper<T>> find(Class<T> type); @Override @SuppressWarnings("unchecked") List<ExtensionWrapper<T>> find(Class<T> type, String pluginId); @Override List<ExtensionWrapper> find(String pluginId); @Override Set<String> findClassNames(String pluginId); @Override void pluginStateChanged(PluginStateEvent event); final boolean isCheckForExtensionDependencies(); void setCheckForExtensionDependencies(boolean checkForExtensionDependencies); static Extension findExtensionAnnotation(Class<?> clazz);  }
@Test public void findExtensionAnnotation() throws Exception { Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting, ExtensionAnnotationProcessorTest.WhazzupGreeting); assertThat(compilation).succeededWithoutWarnings(); ImmutableList<JavaFileObject> generatedFiles = compilation.generatedFiles(); assertEquals(2, generatedFiles.size()); JavaFileObjectClassLoader classLoader = new JavaFileObjectClassLoader(); Map<String, Class<?>> loadedClasses = classLoader.loadClasses(new ArrayList<>(generatedFiles)); Class<?> clazz = loadedClasses.get("test.WhazzupGreeting"); Extension extension = AbstractExtensionFinder.findExtensionAnnotation(clazz); assertNotNull(extension); }
@Test public void findExtensionAnnotationThatMissing() throws Exception { Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting, ExtensionAnnotationProcessorTest.SpinnakerExtension_NoExtension, ExtensionAnnotationProcessorTest.WhazzupGreeting_SpinnakerExtension); assertThat(compilation).succeededWithoutWarnings(); ImmutableList<JavaFileObject> generatedFiles = compilation.generatedFiles(); assertEquals(3, generatedFiles.size()); JavaFileObjectClassLoader classLoader = new JavaFileObjectClassLoader(); Map<String, Class<?>> loadedClasses = classLoader.loadClasses(new ArrayList<>(generatedFiles)); Class<?> clazz = loadedClasses.get("test.WhazzupGreeting"); Extension extension = AbstractExtensionFinder.findExtensionAnnotation(clazz); assertNull(extension); }