diff --git a/core/src/main/java/org/kohsuke/stapler/jsr269/AbstractProcessorImpl.java b/core/src/main/java/org/kohsuke/stapler/jsr269/AbstractProcessorImpl.java index d4466a481..008aa817b 100644 --- a/core/src/main/java/org/kohsuke/stapler/jsr269/AbstractProcessorImpl.java +++ b/core/src/main/java/org/kohsuke/stapler/jsr269/AbstractProcessorImpl.java @@ -63,9 +63,7 @@ protected String getJavadoc(Element md) { } protected void notice(String msg, Element location) { - // IntelliJ flags this as an error. So disabling it for now. - // See http://youtrack.jetbrains.net/issue/IDEA-71822 - // processingEnv.getMessager().printMessage(NOTE, msg, location); + processingEnv.getMessager().printMessage(Kind.NOTE, msg, location); } protected void writePropertyFile(Properties p, String name) throws IOException { diff --git a/core/src/main/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessor.java b/core/src/main/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessor.java index c152e7579..57810894e 100644 --- a/core/src/main/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessor.java +++ b/core/src/main/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessor.java @@ -69,9 +69,9 @@ private void write(ExecutableElement m) throws IOException { } TypeElement t = (TypeElement) m.getEnclosingElement(); - FileObject f = createResource( - t.getQualifiedName().toString().replace('.', '/') + "/" + m.getSimpleName() + ".stapler"); - notice("Generating " + f, m); + String name = t.getQualifiedName().toString().replace('.', '/') + "/" + m.getSimpleName() + ".stapler"; + FileObject f = createResource(name); + notice("Generating " + name, m); try (OutputStream os = f.openOutputStream()) { os.write(buf.toString().getBytes(StandardCharsets.UTF_8)); diff --git a/core/src/test/java/org/kohsuke/stapler/jsr269/ConstructorProcessorTest.java b/core/src/test/java/org/kohsuke/stapler/jsr269/ConstructorProcessorTest.java index 432a0c863..c3d4824d4 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/ConstructorProcessorTest.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/ConstructorProcessorTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import com.karuslabs.elementary.Results; import com.karuslabs.elementary.junit.JavacExtension; @@ -12,11 +11,9 @@ import com.karuslabs.elementary.junit.annotations.Options; import com.karuslabs.elementary.junit.annotations.Processors; import java.time.Year; -import java.util.Collections; -import java.util.List; import java.util.Locale; -import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -36,7 +33,10 @@ class ConstructorProcessorTest { }) @Test void basicOutput(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler"), diagnostics); assertEquals( "{constructor=count,name}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"))); @@ -52,7 +52,10 @@ void basicOutput(Results results) { }) @Test void preAnnotationCompatibility(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler"), diagnostics); assertEquals( "{constructor=name,count}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"))); @@ -70,7 +73,10 @@ void preAnnotationCompatibility(Results results) { @Inline(name = "some.pkg.package-info", source = "package some.pkg;") @Test void JENKINS_11739(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler"), diagnostics); assertEquals( "{constructor=count,name}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"))); @@ -87,10 +93,10 @@ void JENKINS_11739(Results results) { }) @Test void privateConstructor(Results results) { - List> diagnostics = results.diagnostics; - assertEquals(1, diagnostics.size()); - String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg.contains("public"), msg); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("@DataBoundConstructor must be applied to a public constructor"), diagnostics); } @Inline( @@ -104,10 +110,12 @@ void privateConstructor(Results results) { }) @Test void abstractClass(Results results) { - List> diagnostics = results.diagnostics; - assertEquals(1, diagnostics.size()); - String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg.contains("abstract"), msg); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals( + Set.of("@DataBoundConstructor may not be used on an abstract class (only on concrete subclasses)"), + diagnostics); } // issue-179 @@ -123,10 +131,10 @@ void abstractClass(Results results) { }) @Test void duplicatedConstructor1(Results results) { - List> diagnostics = results.diagnostics; - assertEquals(1, diagnostics.size()); - String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg.contains(ConstructorProcessor.MESSAGE), msg); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler", ConstructorProcessor.MESSAGE), diagnostics); } // issue-179 @@ -145,10 +153,10 @@ void duplicatedConstructor1(Results results) { }) @Test void duplicatedConstructor2(Results results) { - List> diagnostics = results.diagnostics; - assertEquals(1, diagnostics.size()); - String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg.contains(ConstructorProcessor.MESSAGE), msg); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler", ConstructorProcessor.MESSAGE), diagnostics); } // issue-179 @@ -164,8 +172,10 @@ void duplicatedConstructor2(Results results) { }) @Test void duplicatedButNotAnnotatedConstructor(Results results) { - List> diagnostics = results.diagnostics; - assertEquals(0, diagnostics.size()); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler"), diagnostics); } // TODO nested classes use qualified rather than binary name @@ -181,7 +191,10 @@ void duplicatedButNotAnnotatedConstructor(Results results) { }) @Test void reproducibleBuild(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.stapler"), diagnostics); assertThat( Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"), not(containsString(Integer.toString(Year.now().getValue())))); diff --git a/core/src/test/java/org/kohsuke/stapler/jsr269/ExportedBeanAnnotationProcessorTest.java b/core/src/test/java/org/kohsuke/stapler/jsr269/ExportedBeanAnnotationProcessorTest.java index d1aadde2a..d1fc3cc3f 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/ExportedBeanAnnotationProcessorTest.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/ExportedBeanAnnotationProcessorTest.java @@ -8,7 +8,9 @@ import com.karuslabs.elementary.junit.annotations.Inline; import com.karuslabs.elementary.junit.annotations.Options; import com.karuslabs.elementary.junit.annotations.Processors; -import java.util.Collections; +import java.util.Locale; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.jvnet.hudson.annotation_indexer.AnnotationProcessorImpl; @@ -36,7 +38,10 @@ private void assertEqualsCRLF(String s1, String s2) { }) @Test void basicOutput(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.javadoc"), diagnostics); assertEqualsCRLF( "some.pkg.Stuff\n", Utils.getGeneratedResource( @@ -60,7 +65,10 @@ void basicOutput(Results results) { }) @Test void noJavadoc(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.javadoc"), diagnostics); assertEqualsCRLF( "some.pkg.Stuff\n", Utils.getGeneratedResource( @@ -93,7 +101,10 @@ void noJavadoc(Results results) { }) @Test void subclassOfExportedBean(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Super.javadoc"), diagnostics); /* #7188605: broken in JDK 6u33 + org.jvnet.hudson:annotation-indexer:1.2: assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); */ @@ -125,7 +136,10 @@ void subclassOfExportedBean(Results results) { }) @Test void multiple(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals(Set.of("Generating some/pkg/Stuff.javadoc", "Generating some/pkg/MoreStuff.javadoc"), diagnostics); assertEqualsCRLF( "some.pkg.MoreStuff\nsome.pkg.Stuff\n", Utils.getGeneratedResource( diff --git a/core/src/test/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessorTest.java b/core/src/test/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessorTest.java index f8d33b77d..2768ae035 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessorTest.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessorTest.java @@ -7,7 +7,9 @@ import com.karuslabs.elementary.junit.annotations.Inline; import com.karuslabs.elementary.junit.annotations.Options; import com.karuslabs.elementary.junit.annotations.Processors; -import java.util.Collections; +import java.util.Locale; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,7 +30,12 @@ class QueryParameterAnnotationProcessorTest { }) @Test void basicOutput(Results results) { - assertEquals(Collections.emptyList(), results.diagnostics); + Set diagnostics = results.diagnostics.stream() + .map(d -> d.getMessage(Locale.ENGLISH)) + .collect(Collectors.toSet()); + assertEquals( + Set.of("Generating some/pkg/Stuff/doOneThing.stapler", "Generating some/pkg/Stuff/doAnother.stapler"), + diagnostics); assertEquals("key", Utils.getGeneratedResource(results.sources, "some/pkg/Stuff/doOneThing.stapler")); assertEquals("name,address", Utils.getGeneratedResource(results.sources, "some/pkg/Stuff/doAnother.stapler")); }