You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/05/10 16:03:22 UTC

[activemq-artemis] 03/19: fail on duplicate

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 79607e66e3d5ff8ef32fc82760ad3d0231686fc4
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Mon May 2 17:11:59 2022 -0400

    fail on duplicate
---
 .../logprocessor/processor/LogProcessor.java       | 32 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/processor/LogProcessor.java b/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/processor/LogProcessor.java
index 4721be1963..f2b031de9f 100644
--- a/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/processor/LogProcessor.java
+++ b/artemis-log-processor/src/main/java/org/apache/activemq/artemis/logprocessor/processor/LogProcessor.java
@@ -27,6 +27,7 @@ import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
 import javax.tools.Diagnostic;
 import java.io.PrintWriter;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Set;
 
@@ -37,8 +38,11 @@ import org.apache.activemq.artemis.logprocessor.annotation.Message;
 @SupportedAnnotationTypes({"org.apache.activemq.artemis.logprocessor.annotation.ArtemisBundle"})
 public class LogProcessor extends AbstractProcessor {
 
+
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+      HashMap<Integer, String> messages = new HashMap<>();
+
       try {
 
          System.out.println("*******************************************************************************************************************************");
@@ -94,9 +98,9 @@ public class LogProcessor extends AbstractProcessor {
                      }
 
                      if (messageAnnotation != null) {
-                        generateMessage(bundleAnnotation, writerOutput, executableMember, messageAnnotation);
+                        generateMessage(bundleAnnotation, writerOutput, executableMember, messageAnnotation, messages);
                      } else if (logAnnotation != null) {
-                        generateLogger(bundleAnnotation, writerOutput, executableMember, logAnnotation);
+                        generateLogger(bundleAnnotation, writerOutput, executableMember, logAnnotation, messages);
                      } else {
                         processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Annotation not found at " + el);
                         return false;
@@ -122,7 +126,17 @@ public class LogProcessor extends AbstractProcessor {
    private void generateMessage(ArtemisBundle bundleAnnotation,
                                 PrintWriter writerOutput,
                                 ExecutableElement executableMember,
-                                Message messageAnnotation) {
+                                Message messageAnnotation,
+                                HashMap<Integer, String> processedMessages) {
+
+      String previousMessage = processedMessages.get(messageAnnotation.id());
+
+      if (processedMessages.containsKey(messageAnnotation.id())) {
+         throw new IllegalStateException("message " + messageAnnotation.id() + " with definition = " + messageAnnotation.value() + " was previously defined as " + previousMessage);
+      }
+
+      processedMessages.put(messageAnnotation.id(), messageAnnotation.value());
+
       // This is really a debug output
       writerOutput.println("   // " + messageAnnotation.toString());
 
@@ -169,7 +183,17 @@ public class LogProcessor extends AbstractProcessor {
    private void generateLogger(ArtemisBundle bundleAnnotation,
                                PrintWriter writerOutput,
                                ExecutableElement executableMember,
-                               LogMessage messageAnnotation) {
+                               LogMessage messageAnnotation,
+                               HashMap<Integer, String> processedMessages) {
+
+      String previousMessage = processedMessages.get(messageAnnotation.id());
+
+      if (processedMessages.containsKey(messageAnnotation.id())) {
+         throw new IllegalStateException("message " + messageAnnotation.id() + " with definition = " + messageAnnotation.value() + " was previously defined as " + previousMessage);
+      }
+
+      processedMessages.put(messageAnnotation.id(), messageAnnotation.value());
+
       // This is really a debug output
       writerOutput.println("   // " + messageAnnotation.toString());