From 6fb7cbd8cceb3e2f825435c1b3ecbd4afa5ff990 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 17 Feb 2023 10:00:25 +0100 Subject: [PATCH 1/4] Update for next development version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 76bda5d..d620c65 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.maven.archetypes annotationprocessor-archetype - 0.8.0 + 0.8.1-SNAPSHOT maven-archetype annotationprocessor-archetype From d58f26204179539dd6982dc6139d8e5bd3544b6f Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Sat, 15 Apr 2023 03:47:33 +0200 Subject: [PATCH 2/4] Switched to generated compiler message class --- .../__rootArtifactId__-processor/pom.xml | 17 +++++- .../__annotationName__Processor.java | 10 +++- .../__annotationName__ProcessorMessages.java | 58 ------------------- ...annotationName__ProcessorMessagesTest.java | 4 +- .../__annotationName__ProcessorTest.java | 2 +- .../resources/archetype-resources/pom.xml | 9 ++- 6 files changed, 34 insertions(+), 66 deletions(-) delete mode 100644 src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__ProcessorMessages.java diff --git a/src/main/resources/archetype-resources/__rootArtifactId__-processor/pom.xml b/src/main/resources/archetype-resources/__rootArtifactId__-processor/pom.xml index ec2753e..171602b 100644 --- a/src/main/resources/archetype-resources/__rootArtifactId__-processor/pom.xml +++ b/src/main/resources/archetype-resources/__rootArtifactId__-processor/pom.xml @@ -32,6 +32,11 @@ aptk-annotationwrapper-api + + io.toolisticon.aptk + aptk-compilermessages-api + + io.toolisticon.spiap spiap-api @@ -112,7 +117,17 @@ io.toolisticon.aptk aptk-annotationwrapper-api ${aptk.version} - > + + + io.toolisticon.aptk + aptk-compilermessages-processor + ${aptk.version} + + + io.toolisticon.aptk + aptk-compilermessages-api + ${aptk.version} + diff --git a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__Processor.java b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__Processor.java index c5b81bd..c5c50c8 100644 --- a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__Processor.java +++ b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__Processor.java @@ -5,6 +5,8 @@ import ${package}.api.${annotationName}; +import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessage; +import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessageCodePrefix; import io.toolisticon.aptk.tools.AbstractAnnotationProcessor; import io.toolisticon.aptk.tools.ElementUtils; import io.toolisticon.aptk.tools.FilerUtils; @@ -35,6 +37,7 @@ */ @SpiService(Processor.class) +@DeclareCompilerMessageCodePrefix("${annotationName}") public class ${annotationName}Processor extends AbstractAnnotationProcessor { private final static Set SUPPORTED_ANNOTATIONS = createSupportedAnnotationSet(${annotationName}.class); @@ -79,7 +82,7 @@ void processAnnotation(TypeElementWrapper wrappedTypeElement, ${annotationName}W } - + @DeclareCompilerMessage(code = "ERROR_002", enumValueName = "ERROR_VALUE_MUST_NOT_BE_EMPTY", message = "Value must not be empty") boolean validateUsage(TypeElementWrapper wrappedTypeElement, ${annotationName}Wrapper annotation) { // ---------------------------------------------------------- @@ -93,7 +96,7 @@ boolean validateUsage(TypeElementWrapper wrappedTypeElement, ${annotationName}Wr .validateAndIssueMessages(); if(annotation.value().isEmpty()) { - wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY); + wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorCompilerMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY); result = false; } return result; @@ -110,6 +113,7 @@ boolean validateUsage(TypeElementWrapper wrappedTypeElement, ${annotationName}Wr * @param wrappedTypeElement The TypeElement representing the annotated class * @param annotation The ${annotationName} annotation */ + @DeclareCompilerMessage(code = "ERROR_001", enumValueName = "ERROR_COULD_NOT_CREATE_CLASS", message = "Could not create class ${symbol_dollar}{0} : ${symbol_dollar}{1}") private void createClass(TypeElementWrapper wrappedTypeElement, ${annotationName}Wrapper annotation) { @@ -129,7 +133,7 @@ private void createClass(TypeElementWrapper wrappedTypeElement, ${annotationName javaWriter.writeTemplate("/${annotationName}.tpl", model); javaWriter.close(); } catch (IOException e) { - wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorMessages.ERROR_COULD_NOT_CREATE_CLASS, filePath, e.getMessage()); + wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorCompilerMessages.ERROR_COULD_NOT_CREATE_CLASS, filePath, e.getMessage()); } } diff --git a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__ProcessorMessages.java b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__ProcessorMessages.java deleted file mode 100644 index fbb06a0..0000000 --- a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/main/java/processor/__annotationName__ProcessorMessages.java +++ /dev/null @@ -1,58 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.processor; - - -import io.toolisticon.aptk.tools.corematcher.ValidationMessage; - -/** - * Messages used by annotation processors. - */ -public enum ${annotationName}ProcessorMessages implements ValidationMessage { - - // TODO: Replace this by your own error messages - ERROR_COULD_NOT_CREATE_CLASS("${annotationName}_ERROR_001", "Could not create class ${symbol_dollar}{0} : ${symbol_dollar}{1}"), - ERROR_VALUE_MUST_NOT_BE_EMPTY("${annotationName}_ERROR_002", "Value must not be empty"); - - - /** - * the message code. - */ - private final String code; - /** - * the message text. - */ - private final String message; - - /** - * Constructor. - * - * @param code the message code - * @param message the message text - */ - ${annotationName}ProcessorMessages(String code, String message) { - this.code = code; - this.message = message; - } - - /** - * Gets the code of the message. - * - * @return the message code - */ - public String getCode() { - return this.code; - } - - /** - * Gets the message text. - * - * @return the message text - */ - public String getMessage() { - return message; - } - - -} diff --git a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorMessagesTest.java b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorMessagesTest.java index 1156edf..c40f894 100644 --- a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorMessagesTest.java +++ b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorMessagesTest.java @@ -18,8 +18,8 @@ public class ${annotationName}ProcessorMessagesTest { @Test public void test_enum() { - MatcherAssert.assertThat(${annotationName}ProcessorMessages.ERROR_COULD_NOT_CREATE_CLASS.getCode(), Matchers.startsWith("${annotationName}")); - MatcherAssert.assertThat(${annotationName}ProcessorMessages.ERROR_COULD_NOT_CREATE_CLASS.getMessage(), Matchers.containsString("create class")); + MatcherAssert.assertThat(${annotationName}ProcessorCompilerMessages.ERROR_COULD_NOT_CREATE_CLASS.getCode(), Matchers.startsWith("${annotationName}")); + MatcherAssert.assertThat(${annotationName}ProcessorCompilerMessages.ERROR_COULD_NOT_CREATE_CLASS.getMessage(), Matchers.containsString("create class")); } diff --git a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java index 87e2593..b6253b8 100644 --- a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java +++ b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java @@ -50,7 +50,7 @@ public void test_invalid_usage_with_empty_value() { compileTestBuilder .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageWithEmptyValue.java")) .compilationShouldFail() - .expectErrorMessageThatContains(${annotationName}ProcessorMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY.getCode()) + .expectErrorMessageThatContains(${annotationName}ProcessorCompilerMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY.getCode()) .executeTest(); } diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index ea73de4..ebad0a0 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -75,7 +75,7 @@ 0.12.0 0.11.0 - 0.20.2 + 0.21.0 4.13.1 @@ -562,6 +562,13 @@ provided + + io.toolisticon.aptk + aptk-compilermessages-api + ${aptk.version} + provided + + io.toolisticon.spiap spiap-api From 18288d4567bf49a4e9f84576f7a5002e910ab594 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 9 Feb 2024 14:58:32 +0100 Subject: [PATCH 3/4] Upgrade to newest cute version --- .../__annotationName__ProcessorTest.java | 41 ++++++++++--------- .../resources/archetype-resources/pom.xml | 4 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java index b6253b8..ff5fa53 100644 --- a/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java +++ b/src/main/resources/archetype-resources/__rootArtifactId__-processor/src/test/java/processor/__annotationName__ProcessorTest.java @@ -5,13 +5,11 @@ import io.toolisticon.aptk.tools.MessagerUtils; import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages; -import io.toolisticon.cute.CompileTestBuilder; -import io.toolisticon.cute.JavaFileObjectUtils; +import io.toolisticon.cute.Cute; +import io.toolisticon.cute.CuteApi; import org.junit.Before; import org.junit.Test; -import javax.tools.JavaFileObject; -import javax.tools.StandardLocation; /** @@ -23,15 +21,16 @@ public class ${annotationName}ProcessorTest { - CompileTestBuilder.CompilationTestBuilder compileTestBuilder; + CuteApi.BlackBoxTestSourceFilesInterface compileTestBuilder; @Before public void init() { MessagerUtils.setPrintMessageCodes(true); - compileTestBuilder = CompileTestBuilder - .compilationTest() - .addProcessors(${annotationName}Processor.class); + compileTestBuilder = Cute + .blackBoxTest() + .given() + .processors(${annotationName}Processor.class); } @@ -39,8 +38,9 @@ public void init() { public void test_valid_usage() { compileTestBuilder - .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsage.java")) - .compilationShouldSucceed() + .andSourceFiles("testcases/TestcaseValidUsage.java") + .whenCompiled() + .thenExpectThat().compilationSucceeds() .executeTest(); } @@ -48,9 +48,10 @@ public void test_valid_usage() { public void test_invalid_usage_with_empty_value() { compileTestBuilder - .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageWithEmptyValue.java")) - .compilationShouldFail() - .expectErrorMessageThatContains(${annotationName}ProcessorCompilerMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY.getCode()) + .andSourceFiles("testcases/TestcaseInvalidUsageWithEmptyValue.java") + .whenCompiled() + .thenExpectThat().compilationFails() + .andThat().compilerMessage().ofKindError().contains(${annotationName}ProcessorCompilerMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY.getCode()) .executeTest(); } @@ -58,9 +59,10 @@ public void test_invalid_usage_with_empty_value() { public void test_invalid_usage_on_enum() { compileTestBuilder - .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageOnEnum.java")) - .compilationShouldFail() - .expectErrorMessageThatContains(CoreMatcherValidationMessages.IS_CLASS.getCode()) + .andSourceFiles("testcases/TestcaseInvalidUsageOnEnum.java") + .whenCompiled() + .thenExpectThat().compilationFails() + .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_CLASS.getCode()) .executeTest(); } @@ -68,9 +70,10 @@ public void test_invalid_usage_on_enum() { public void test_Test_invalid_usage_on_interface() { compileTestBuilder - .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageOnInterface.java")) - .compilationShouldFail() - .expectErrorMessageThatContains(CoreMatcherValidationMessages.IS_CLASS.getCode()) + .andSourceFiles("testcases/TestcaseInvalidUsageOnInterface.java") + .whenCompiled() + .thenExpectThat().compilationFails() + .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_CLASS.getCode()) .executeTest(); } diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index ebad0a0..3c82b5a 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -73,9 +73,9 @@ - 0.12.0 + 1.0.1 0.11.0 - 0.21.0 + 0.22.11 4.13.1 From 94b6ec01408b53a18b3b3f34806b81291007b324 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 9 Feb 2024 14:59:23 +0100 Subject: [PATCH 4/4] Update versions for release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d620c65..5791efb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.maven.archetypes annotationprocessor-archetype - 0.8.1-SNAPSHOT + 0.9.0 maven-archetype annotationprocessor-archetype