From 01ce6332a90a836e28c71298fd17cb772b77396b Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Sat, 6 Aug 2022 17:58:27 -0700 Subject: [PATCH] Migrate from Hickory to Elementary --- core/pom.xml | 6 +- .../jsr269/ConstructorProcessorTest.java | 223 ++++++++++-------- .../ExportedBeanAnnotationProcessorTest.java | 175 ++++++++------ ...QueryParameterAnnotationProcessorTest.java | 47 ++-- .../SourceGeneratingAnnotationProcessor.java | 2 +- .../org/kohsuke/stapler/jsr269/Utils.java | 39 +-- pom.xml | 4 + 7 files changed, 273 insertions(+), 223 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 8abbc5f469..6465b8fc56 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -112,9 +112,9 @@ provided - com.jolira - hickory - 1.0.0 + com.karuslabs + elementary + 1.1.2 test 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 d8b5369c98..a8ac087682 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/ConstructorProcessorTest.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/ConstructorProcessorTest.java @@ -1,135 +1,162 @@ package org.kohsuke.stapler.jsr269; +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; +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.List; import java.util.Locale; import javax.tools.Diagnostic; import javax.tools.JavaFileObject; -import net.java.dev.hickory.testing.Compilation; -import org.junit.Test; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -public class ConstructorProcessorTest { +@ExtendWith(JavacExtension.class) +@Options("-Werror") +@Processors(ConstructorProcessor.class) +class ConstructorProcessorTest { - @Test public void basicOutput() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public class Stuff {"). - addLine(" @DataBoundConstructor public Stuff(int count, String name) {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEquals("{constructor=count,name}", Utils.normalizeProperties(Utils.getGeneratedResource(compilation, "some/pkg/Stuff.stapler"))); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public class Stuff {", + " @DataBoundConstructor public Stuff(int count, String name) {}", + "}", + }) + @Test + void basicOutput(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEquals("{constructor=count,name}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"))); } - @Test public void preAnnotationCompatibility() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("public class Stuff {"). - addLine(" /** @stapler-constructor */ public Stuff(String name, int count) {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEquals("{constructor=name,count}", Utils.normalizeProperties(Utils.getGeneratedResource(compilation, "some/pkg/Stuff.stapler"))); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "public class Stuff {", + " /** @stapler-constructor */ public Stuff(String name, int count) {}", + "}" + }) + @Test + void preAnnotationCompatibility(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEquals("{constructor=name,count}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"))); } - @Test public void JENKINS_11739() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public class Stuff {"). - addLine(" @DataBoundConstructor public Stuff(int count, String name) {}"). - addLine("}"); - compilation.addSource("some.pkg.package-info"). - addLine("package some.pkg;"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEquals("{constructor=count,name}", Utils.normalizeProperties(Utils.getGeneratedResource(compilation, "some/pkg/Stuff.stapler"))); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public class Stuff {", + " @DataBoundConstructor public Stuff(int count, String name) {}", + "}" + }) + @Inline( + name = "some.pkg.package-info", + source = {"package some.pkg;"}) + @Test + void JENKINS_11739(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEquals("{constructor=count,name}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.stapler"))); } - @Test public void privateConstructor() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public class Stuff {"). - addLine(" @DataBoundConstructor Stuff() {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - List> diagnostics = compilation.getDiagnostics(); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public class Stuff {", + " @DataBoundConstructor Stuff() {}", + "}" + }) + @Test + void privateConstructor(Results results) { + List> diagnostics = results.diagnostics; assertEquals(1, diagnostics.size()); String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg, msg.contains("public")); + assertTrue(msg.contains("public"), msg); } - @Test public void abstractClass() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public abstract class Stuff {"). - addLine(" @DataBoundConstructor public Stuff() {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - List> diagnostics = compilation.getDiagnostics(); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public abstract class Stuff {", + " @DataBoundConstructor public Stuff() {}", + "}" + }) + @Test + void abstractClass(Results results) { + List> diagnostics = results.diagnostics; assertEquals(1, diagnostics.size()); String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg, msg.contains("abstract")); + assertTrue(msg.contains("abstract"), msg); } //issue-179 - @Test public void duplicatedConstructor1() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public class Stuff {"). - addLine(" @DataBoundConstructor public Stuff() {}"). - addLine(" @DataBoundConstructor public Stuff(int i) {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - List> diagnostics = compilation.getDiagnostics(); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public class Stuff {", + " @DataBoundConstructor public Stuff() {}", + " @DataBoundConstructor public Stuff(int i) {}", + "}" + }) + @Test + void duplicatedConstructor1(Results results) { + List> diagnostics = results.diagnostics; assertEquals(1, diagnostics.size()); String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg, msg.contains(ConstructorProcessor.MESSAGE)); + assertTrue(msg.contains(ConstructorProcessor.MESSAGE), msg); } //issue-179 - @Test public void duplicatedConstructor2() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public class Stuff {"). - addLine(" @DataBoundConstructor public Stuff() {}"). - addLine(" /**"). - addLine(" @stapler-constructor Another constructor"). - addLine(" **/"). - addLine(" public Stuff(int i) {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - List> diagnostics = compilation.getDiagnostics(); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public class Stuff {", + " @DataBoundConstructor public Stuff() {}", + " /**", + " @stapler-constructor Another constructor", + " **/", + " public Stuff(int i) {}", + "}" + }) + @Test + void duplicatedConstructor2(Results results) { + List> diagnostics = results.diagnostics; assertEquals(1, diagnostics.size()); String msg = diagnostics.get(0).getMessage(Locale.ENGLISH); - assertTrue(msg, msg.contains(ConstructorProcessor.MESSAGE)); + assertTrue(msg.contains(ConstructorProcessor.MESSAGE), msg); } //issue-179 - @Test public void duplicatedButNotAnnotatedConstructor() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.DataBoundConstructor;"). - addLine("public class Stuff {"). - addLine(" @DataBoundConstructor public Stuff() {}"). - addLine(" public Stuff(int i) {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - List> diagnostics = compilation.getDiagnostics(); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.DataBoundConstructor;", + "public class Stuff {", + " @DataBoundConstructor public Stuff() {}", + " public Stuff(int i) {}", + "}" + }) + @Test + void duplicatedButNotAnnotatedConstructor(Results results) { + List> diagnostics = results.diagnostics; assertEquals(0, diagnostics.size()); } // TODO nested classes use qualified rather than binary name 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 12884511a2..38a7eee677 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/ExportedBeanAnnotationProcessorTest.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/ExportedBeanAnnotationProcessorTest.java @@ -1,96 +1,121 @@ package org.kohsuke.stapler.jsr269; -import java.util.Collections; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import net.java.dev.hickory.testing.Compilation; -import static org.junit.Assert.*; -import org.junit.Test; -import org.kohsuke.stapler.export.Exported; -import org.kohsuke.stapler.export.ExportedBean; +import com.karuslabs.elementary.Results; +import com.karuslabs.elementary.junit.JavacExtension; +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 org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.jvnet.hudson.annotation_indexer.AnnotationProcessorImpl; -public class ExportedBeanAnnotationProcessorTest { +@ExtendWith(JavacExtension.class) +@Options("-Werror") +@Processors({ + AnnotationProcessorImpl.class, + ExportedBeanAnnotationProcessor.class, +}) +class ExportedBeanAnnotationProcessorTest { private void assertEqualsCRLF(String s1, String s2) { assertEquals(s1.replace("\r\n","\n"), s2.replace("\r\n","\n")); } - @Test public void basicOutput() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.export.*;"). - addLine("@ExportedBean public class Stuff {"). - addLine(" /* this is not Javadoc */"). - addLine(" @Exported public int getCount() {return 0;}"). - addLine(" /** This gets the display name. */"). - addLine(" @Exported(name=\"name\") public String getDisplayName() {return null;}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); - assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); - assertEquals("{getDisplayName=This gets the display name. }", Utils.normalizeProperties(Utils.getGeneratedResource(compilation, "some/pkg/Stuff.javadoc"))); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.export.*;", + "@ExportedBean public class Stuff {", + " /* this is not Javadoc */", + " @Exported public int getCount() {return 0;}", + " /** This gets the display name. */", + " @Exported(name=\"name\") public String getDisplayName() {return null;}", + "}" + }) + @Test + void basicOutput(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); + assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); + assertEquals("{getDisplayName=This gets the display name. }", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.javadoc"))); } - @Test public void noJavadoc() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.export.*;"). - addLine("@ExportedBean public class Stuff {"). - addLine(" @Exported public int getCount() {return 0;}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); - assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.export.*;", + "@ExportedBean public class Stuff {", + " @Exported public int getCount() {return 0;}", + "}" + }) + @Test + void noJavadoc(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); + assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); // TODO should it be null, i.e. is it desired to create an empty *.javadoc file? - assertEquals("{}", Utils.normalizeProperties(Utils.getGeneratedResource(compilation, "some/pkg/Stuff.javadoc"))); + assertEquals("{}", Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.javadoc"))); } - - @ExportedBean public static abstract class Super { - @Exported public abstract int getCount(); - } - @Test public void subclassOfExportedBean() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.export.*;"). - addLine("public class Stuff extends " + Super.class.getCanonicalName() + " {"). - addLine(" @Override public int getCount() {return 0;}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); + + @Inline( + name = "some.pkg.Super", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.export.*;", + "@ExportedBean public abstract class Super {", + " @Exported public abstract int getCount();", + "}", + }) + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.export.*;", + "public class Stuff extends some.pkg.Super {", + " @Override public int getCount() {return 0;}", + "}" + }) + @Test + void subclassOfExportedBean(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); /* #7188605: broken in JDK 6u33 + org.jvnet.hudson:annotation-indexer:1.2: - assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); + assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); */ // TODO is it intentional that these are not listed here? (example: hudson.plugins.mercurial.MercurialSCM) - assertNull(Utils.getGeneratedResource(compilation, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); - assertNull(Utils.normalizeProperties(Utils.getGeneratedResource(compilation, "some/pkg/Stuff.javadoc"))); + assertEqualsCRLF("some.pkg.Super\n", Utils.getGeneratedResource(results.sources, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); + assertNull(Utils.normalizeProperties(Utils.getGeneratedResource(results.sources, "some/pkg/Stuff.javadoc"))); } - @Test public void incremental() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.export.*;"). - addLine("@" + SourceGeneratingAnnotation.class.getCanonicalName()). - addLine("@ExportedBean public class Stuff {"). - addLine(" @Exported public int getCount() {return 0;}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEqualsCRLF("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); - compilation = new Compilation(compilation); - compilation.addSource("some.pkg.MoreStuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.export.*;"). - addLine("@ExportedBean public class MoreStuff {"). - addLine(" @Exported public int getCount() {return 0;}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEqualsCRLF("some.pkg.MoreStuff\nsome.pkg.Stuff\n", Utils.getGeneratedResource(compilation, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.export.*;", + "@org.kohsuke.stapler.jsr269.SourceGeneratingAnnotation", + "@ExportedBean public class Stuff {", + " @Exported public int getCount() {return 0;}", + "}" + }) + @Inline( + name = "some.pkg.MoreStuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.export.*;", + "@ExportedBean public class MoreStuff {", + " @Exported public int getCount() {return 0;}", + "}" + }) + @Test + void multiple(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEqualsCRLF("some.pkg.MoreStuff\nsome.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, "META-INF/services/annotations/org.kohsuke.stapler.export.ExportedBean")); + assertEqualsCRLF("some.pkg.MoreStuff\nsome.pkg.Stuff\n", Utils.getGeneratedResource(results.sources, ExportedBeanAnnotationProcessor.STAPLER_BEAN_FILE)); } // TODO nested classes - currently saved as qualified rather than binary name, intentional? 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 068cb9e679..621d584cb1 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessorTest.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/QueryParameterAnnotationProcessorTest.java @@ -1,27 +1,36 @@ package org.kohsuke.stapler.jsr269; -import java.util.Collections; - -import net.java.dev.hickory.testing.Compilation; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.*; +import com.karuslabs.elementary.Results; +import com.karuslabs.elementary.junit.JavacExtension; +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 org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -public class QueryParameterAnnotationProcessorTest { +@ExtendWith(JavacExtension.class) +@Options("-Werror") +@Processors(QueryParameterAnnotationProcessor.class) +class QueryParameterAnnotationProcessorTest { - @Test public void basicOutput() { - Compilation compilation = new Compilation(); - compilation.addSource("some.pkg.Stuff"). - addLine("package some.pkg;"). - addLine("import org.kohsuke.stapler.QueryParameter;"). - addLine("public class Stuff {"). - addLine(" public void doOneThing(@QueryParameter String key) {}"). - addLine(" public void doAnother(@QueryParameter(\"ignoredHere\") String name, @QueryParameter String address) {}"). - addLine("}"); - compilation.doCompile(null, "-source", "8", "-Xlint:none"); - assertEquals(Collections.emptyList(), compilation.getDiagnostics()); - assertEquals("key", Utils.getGeneratedResource(compilation, "some/pkg/Stuff/doOneThing.stapler")); - assertEquals("name,address", Utils.getGeneratedResource(compilation, "some/pkg/Stuff/doAnother.stapler")); + @Inline( + name = "some.pkg.Stuff", + source = { + "package some.pkg;", + "import org.kohsuke.stapler.QueryParameter;", + "public class Stuff {", + " public void doOneThing(@QueryParameter String key) {}", + " public void doAnother(@QueryParameter(\"ignoredHere\") String name, @QueryParameter String address) {}", + "}", + }) + @Test + void basicOutput(Results results) { + assertEquals(Collections.emptyList(), results.diagnostics); + assertEquals("key", Utils.getGeneratedResource(results.sources, "some/pkg/Stuff/doOneThing.stapler")); + assertEquals("name,address", Utils.getGeneratedResource(results.sources, "some/pkg/Stuff/doAnother.stapler")); } // TODO nested classes use qualified rather than binary name diff --git a/core/src/test/java/org/kohsuke/stapler/jsr269/SourceGeneratingAnnotationProcessor.java b/core/src/test/java/org/kohsuke/stapler/jsr269/SourceGeneratingAnnotationProcessor.java index bc57b45820..c3f8f6ab4f 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/SourceGeneratingAnnotationProcessor.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/SourceGeneratingAnnotationProcessor.java @@ -41,7 +41,7 @@ import javax.tools.JavaFileObject; import org.kohsuke.MetaInfServices; -@SupportedSourceVersion(SourceVersion.RELEASE_8) +@SupportedSourceVersion(SourceVersion.RELEASE_11) @SupportedAnnotationTypes("org.kohsuke.stapler.jsr269.SourceGeneratingAnnotation") @MetaInfServices(Processor.class) public class SourceGeneratingAnnotationProcessor extends AbstractProcessor { diff --git a/core/src/test/java/org/kohsuke/stapler/jsr269/Utils.java b/core/src/test/java/org/kohsuke/stapler/jsr269/Utils.java index bb314ffa8b..52b85607af 100644 --- a/core/src/test/java/org/kohsuke/stapler/jsr269/Utils.java +++ b/core/src/test/java/org/kohsuke/stapler/jsr269/Utils.java @@ -1,42 +1,27 @@ package org.kohsuke.stapler.jsr269; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; -import java.lang.reflect.Field; +import java.io.UncheckedIOException; +import java.util.List; import java.util.Properties; import java.util.TreeMap; -import javax.tools.FileObject; -import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; import javax.tools.StandardLocation; -import net.java.dev.hickory.testing.Compilation; class Utils { - private static JavaFileManager fileManager(Compilation compilation) { - try { - Field f = Compilation.class.getDeclaredField("jfm"); - f.setAccessible(true); - return (JavaFileManager) f.get(compilation); - } catch (Exception x) { - throw new AssertionError(x); + public static String getGeneratedResource(List generated, String filename) { + JavaFileObject fo = generated.stream() + .filter(it -> it.getName().equals("/" + StandardLocation.CLASS_OUTPUT + "/" + filename)) + .findFirst() + .orElse(null); + if (fo == null) { + return null; } - } - - /** - * Replacement for {@link Compilation#getGeneratedResource} that actually works. - * https://code.google.com/p/jolira-tools/issues/detail?id=11 - */ - public static String getGeneratedResource(Compilation compilation, String filename) { try { - FileObject fo = fileManager(compilation).getFileForOutput(StandardLocation.CLASS_OUTPUT, "", filename, null); - if (fo == null) { - return null; - } return fo.getCharContent(true).toString(); - } catch (FileNotFoundException x) { - return null; - } catch (IOException x) { - throw new RuntimeException(x); + } catch (IOException e) { + throw new UncheckedIOException(e); } } diff --git a/pom.xml b/pom.xml index 0102724e94..9ac3e6d7e6 100644 --- a/pom.xml +++ b/pom.xml @@ -120,6 +120,10 @@ repo.jenkins-ci.org https://repo.jenkins-ci.org/public/ + + elementary-releases + https://repo.karuslabs.com/repository/elementary-releases/ +