Browse Source

Fix #363

pull/376/head
Decebal Suiu 5 years ago
parent
commit
ec03fd022f
  1. 8
      pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
  2. 17
      pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java
  3. 21
      pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java

8
pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java

@ -356,9 +356,11 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
// search recursively through all annotations
for (Annotation annotation : clazz.getAnnotations()) {
Class<? extends Annotation> annotationClass = annotation.annotationType();
Extension extensionAnnotation = findExtensionAnnotation(annotationClass);
if (extensionAnnotation != null) {
return extensionAnnotation;
if (!annotationClass.getName().startsWith("java.lang.annotation")) {
Extension extensionAnnotation = findExtensionAnnotation(annotationClass);
if (extensionAnnotation != null) {
return extensionAnnotation;
}
}
}

17
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java

@ -37,6 +37,7 @@ import java.util.Set;
import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.eq;
@ -217,6 +218,22 @@ public class AbstractExtensionFinderTest {
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);
}
static class JavaFileObjectClassLoader extends ClassLoader {
public Map<String, Class<?>> loadClasses(List<JavaFileObject> classes) throws IOException {

21
pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java

@ -103,6 +103,27 @@ public class ExtensionAnnotationProcessorTest {
" }",
"}");
/**
* The same like {@link #SpinnakerExtension} but without {@code Extension} annotation.
*/
public static final JavaFileObject SpinnakerExtension_NoExtension = JavaFileObjects.forSourceLines(
"SpinnakerExtension",
"package test;",
"",
"import org.pf4j.Extension;",
"import java.lang.annotation.Documented;",
"import java.lang.annotation.ElementType;",
"import java.lang.annotation.Retention;",
"import java.lang.annotation.RetentionPolicy;",
"import java.lang.annotation.Target;",
"",
// "@Extension",
"@Retention(RetentionPolicy.RUNTIME)",
"@Target(ElementType.TYPE)",
"@Documented",
"public @interface SpinnakerExtension {",
"}");
@Test
public void getSupportedAnnotationTypes() {
ExtensionAnnotationProcessor instance = new ExtensionAnnotationProcessor();

Loading…
Cancel
Save