Skip to content

Commit

Permalink
Merge pull request #258 from graalvm/gradinac/fix-junit-annotation-sc…
Browse files Browse the repository at this point in the history
…anning

Fix JUnit annotation scanning during the image build
  • Loading branch information
gradinac committed Jun 29, 2022
2 parents e9ea7bd + a34f6c4 commit 9f85a67
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void onLoad(NativeImageConfiguration config) {
"org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor",
"org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor",
"org.junit.jupiter.engine.execution.ConditionEvaluator",
"org.junit.jupiter.engine.execution.ExecutableInvoker"
"org.junit.jupiter.engine.execution.ExecutableInvoker",
"org.junit.jupiter.params.provider.EnumSource$Mode",
};
for (String className : buildTimeInitializedClasses) {
config.initializeAtBuildTime(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
package org.graalvm.junit.platform.config.util;

import org.graalvm.junit.platform.config.core.NativeImageConfiguration;
import org.graalvm.util.GuardedAnnotationAccess;
import org.junit.platform.commons.support.AnnotationSupport;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -96,7 +95,7 @@ private static void forEachMethod(Class<?> clazz, Consumer<Method> consumer) {
}

private static <A extends Annotation> List<A> getAnnotations(AnnotatedElement element, Class<A> annotation) {
if (GuardedAnnotationAccess.getAnnotation(annotation, Repeatable.class) != null) {
if (annotation.getAnnotation(Repeatable.class) != null) {
return AnnotationSupport.findRepeatableAnnotations(element, annotation);
} else {
Optional<A> optionalAnnotation = AnnotationSupport.findAnnotation(element, annotation);
Expand Down
14 changes: 0 additions & 14 deletions config/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@
<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
<module name="SuppressWarningsHolder" />
<!-- Disallows direct calls to "AnnotatedElement.get(Declared)Annotation(s)". This check can yield false positives,
i.e., it will match any ".get(Declared)Annotation(s)" calls that are not preceded by "GuardedAnnotationAccess"
since checkstyle relies only on pattern matching and it cannot determine the type of the call's receiver object. -->
<module name="RegexpSinglelineJava">
<property name="id" value="annotationAccess"/>
<metadata name="net.sf.eclipsecs.core.comment"
value="Disallow calls to AnnotatedElement.get(Declared)Annotation(s)."/>
<property name="severity" value="error"/>
<property name="format"
value="\b(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="message"
value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use either org.graalvm.util.GuardedAnnotationAccess or org.graalvm.util.DirectAnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="Checkstyle: allow direct annotation access"/>
<property name="onCommentFormat" value="Checkstyle: disallow direct annotation access"/>
Expand Down
8 changes: 8 additions & 0 deletions docs/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ If you are using alternative build systems, see <<alternative-build-systems.adoc

[[changelog]]
== Changelog
=== Release 0.9.13

=== Gradle plugin
* Reverted a change in the `NativeImagePlugin` that removed publicly accessible constants. This should prevent breakage of external plugins.

=== JUnit testing support
* Adapted the JUnit automatic metadata registration to changes in annotation handling on newer native image versions.

=== Release 0.9.12

==== Gradle plugin
Expand Down
2 changes: 1 addition & 1 deletion samples/java-application-with-custom-packaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<micronaut.version>3.3.4</micronaut.version>
<exec.mainClass>org.graalvm.demo.Application</exec.mainClass>
<micronaut.runtime>netty</micronaut.runtime>
<maven.native.plugin.version>0.9.12-SNAPSHOT</maven.native.plugin.version>
<maven.native.plugin.version>0.9.13-SNAPSHOT</maven.native.plugin.version>
</properties>

<repositories>
Expand Down

0 comments on commit 9f85a67

Please sign in to comment.