You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kw...@apache.org on 2026/08/17 15:43:35 UTC

(maven-resolver) branch feature/deprecated-tag-support created (now a3d7a4a70)

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

kwin pushed a change to branch feature/deprecated-tag-support
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


      at a3d7a4a70 Support deprecated tag.

This branch includes the following new commits:

     new a3d7a4a70 Support deprecated tag.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-resolver) 01/01: Support deprecated tag.

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/deprecated-tag-support
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit a3d7a4a701f227b1cd0be9d9ba9c9188ee23fd36
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Aug 17 17:43:21 2026 +0200

    Support deprecated tag.
    
    Emit similar to regular javadoc as description prefix with bold text
    "Deprecated." followed by italic deprecated reason.
---
 .../eclipse/aether/tools/CollectConfiguration.java |  4 +-
 .../aether/tools/ConfigurationCollectorDoclet.java | 55 ++++++++++++++++++----
 .../src/main/resources/configuration.md.vm         |  2 +-
 .../tools/ConfigurationCollectorDocletTest.java    |  4 ++
 .../aether/sample/SampleConfigurationKeys.java     |  2 +
 5 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/CollectConfiguration.java b/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/CollectConfiguration.java
index 79d662b6b..8cbaee72c 100644
--- a/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/CollectConfiguration.java
+++ b/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/CollectConfiguration.java
@@ -79,7 +79,9 @@ public class CollectConfiguration implements Callable<Integer> {
             "since",
             "configurationSource",
             "configurationType",
-            "supportRepoIdSuffix");
+            "supportRepoIdSuffix",
+            "deprecated",
+            "deprecatedSince");
 
     /**
      * Javadoc block tag marking a constant field as a configuration key.
diff --git a/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java b/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java
index 61aa713b3..ec378e274 100644
--- a/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java
+++ b/maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java
@@ -57,6 +57,7 @@ import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 
+import com.sun.source.doctree.DeprecatedTree;
 import com.sun.source.doctree.DocCommentTree;
 import com.sun.source.doctree.DocTree;
 import com.sun.source.doctree.EntityTree;
@@ -122,7 +123,10 @@ public class ConfigurationCollectorDoclet implements Doclet {
             String since,
             String source,
             String type,
-            boolean supportsRepoIdSuffix) {
+            boolean supportsRepoIdSuffix,
+            String deprecated, // is null if not deprecated, empty if deprecated but no reason is given, otherwise
+            // contains the deprecation reason
+            String deprecatedSince) {
 
         public ConfigurationEntry {
             Objects.requireNonNull(key);
@@ -185,12 +189,12 @@ public class ConfigurationCollectorDoclet implements Doclet {
 
     @Override
     public boolean run(DocletEnvironment environment) {
-        try {
-            return doRun(environment);
-        } catch (RuntimeException e) {
+        // try {
+        return doRun(environment);
+        /*} catch (RuntimeException e) {
             reportError("Error running ConfigurationCollectorDoclet: " + e.getMessage());
             return false;
-        }
+        }*/
     }
 
     private boolean doRun(DocletEnvironment environment) {
@@ -310,7 +314,28 @@ public class ConfigurationCollectorDoclet implements Doclet {
                 getSince(path).orElse(""),
                 getConfigurationSource(path, blockTags).orElse(""),
                 getConfigurationType(path, blockTags),
-                isSupportsRepoIdSuffix(path, blockTags));
+                isSupportsRepoIdSuffix(path, blockTags),
+                getDeprecated(path, field).orElse(""),
+                getDeprecatedSince(field).orElse(""));
+    }
+
+    private Optional<String> getDeprecated(DocTreePath path, VariableElement field) {
+        // first check for deprecated annotation
+        if (field.getAnnotation(Deprecated.class) == null) {
+            return Optional.empty();
+        }
+        Optional<? extends DocTree> deprecatedTag = path.getDocComment().getBlockTags().stream()
+                .filter(t -> com.sun.source.doctree.DocTree.Kind.DEPRECATED == t.getKind())
+                .findFirst();
+        if (deprecatedTag.isPresent()) {
+            return Optional.of(renderContent(DocTreePath.getPath(path, deprecatedTag.get()), RenderMode.HTML, true));
+        }
+        return Optional.of("This key deprecated");
+    }
+
+    private Optional<String> getDeprecatedSince(VariableElement field) {
+        Optional<Deprecated> deprecatedAnnotation = Optional.ofNullable(field.getAnnotation(Deprecated.class));
+        return deprecatedAnnotation.map(Deprecated::since);
     }
 
     private boolean isSupportsRepoIdSuffix(DocTreePath path, Map<String, UnknownBlockTagTree> blockTags) {
@@ -380,7 +405,6 @@ public class ConfigurationCollectorDoclet implements Doclet {
         } else if (configurationType.startsWith("java.util.")) {
             configurationType = configurationType.substring("java.util.".length());
         }
-
         return new ConfigurationEntry(
                 String.valueOf(field.getConstantValue()),
                 path.getDocComment() != null ? getFullBodyContent(path) : "",
@@ -389,7 +413,9 @@ public class ConfigurationCollectorDoclet implements Doclet {
                 getSince(path).orElse(""),
                 source,
                 configurationType,
-                false);
+                false,
+                getDeprecated(path, field).orElse(""),
+                getDeprecatedSince(field).orElse(""));
     }
 
     private AnnotationMirror getAnnotation(Element element, String fqName) {
@@ -427,12 +453,17 @@ public class ConfigurationCollectorDoclet implements Doclet {
         properties.setProperty(prefix + "configurationSource", entry.source());
         properties.setProperty(prefix + "configurationType", entry.type());
         properties.setProperty(prefix + "supportRepoIdSuffix", toYesNo(entry.supportsRepoIdSuffix()));
+        properties.setProperty(prefix + "deprecated", entry.deprecated());
+        properties.setProperty(prefix + "deprecatedSince", entry.deprecatedSince());
     }
 
     // --- Javadoc extraction helpers -------------------------------------------------------------------------------
 
     private Map<String, UnknownBlockTagTree> collectBlockTags(DocCommentTree docComment) {
         Map<String, UnknownBlockTagTree> result = new LinkedHashMap<>();
+        if (docComment == null) {
+            return result;
+        }
         for (DocTree tag : docComment.getBlockTags()) {
             if (tag instanceof UnknownBlockTagTree unknownBlockTree) {
                 result.put(unknownBlockTree.getTagName(), unknownBlockTree);
@@ -675,11 +706,17 @@ public class ConfigurationCollectorDoclet implements Doclet {
                 return escape(mode, node.getBody().toString());
             }
 
+            @Override
+            public String visitDeprecated(DeprecatedTree node, Void p) {
+                StringBuilder sb = new StringBuilder();
+                node.getBody().forEach(child -> sb.append(child.accept(this, p)));
+                return sb.toString();
+            }
+
             @Override
             protected String defaultAction(DocTree node, Void p) {
                 // the default action internally calls node.toString(), which uses
                 // com.sun.tools.javac.tree.DCTree.toString() which relies on com.sun.tools.javac.tree.DocPretty to
-                // render the node
                 return node.toString();
             }
         };
diff --git a/maven-resolver-tools/src/main/resources/configuration.md.vm b/maven-resolver-tools/src/main/resources/configuration.md.vm
index a4c614ccf..31a9bf6da 100644
--- a/maven-resolver-tools/src/main/resources/configuration.md.vm
+++ b/maven-resolver-tools/src/main/resources/configuration.md.vm
@@ -52,7 +52,7 @@ To modify this file, edit the template and regenerate.
 | Key | Type | Description | Default Value | Since | Supports Repo ID suffix | Source |
 | --- | --- | --- | --- | --- | --- | --- |
 #foreach($key in $keys)
-| `$key.key` | `$key.configurationType` | $key.description | #value( $key.defaultValue ) | $key.since |  $key.supportRepoIdSuffix  | $key.configurationSource |
+| `$key.key` | `$key.configurationType` | #if($key.deprecated) **Deprecated**. *$key.deprecated*<br/>#end$key.description | #value( $key.defaultValue ) | $key.since |  $key.supportRepoIdSuffix  | $key.configurationSource |
 #end
 
 #[[
diff --git a/maven-resolver-tools/src/test/java/org/eclipse/aether/tools/ConfigurationCollectorDocletTest.java b/maven-resolver-tools/src/test/java/org/eclipse/aether/tools/ConfigurationCollectorDocletTest.java
index 98d82096c..fffd5700b 100644
--- a/maven-resolver-tools/src/test/java/org/eclipse/aether/tools/ConfigurationCollectorDocletTest.java
+++ b/maven-resolver-tools/src/test/java/org/eclipse/aether/tools/ConfigurationCollectorDocletTest.java
@@ -101,6 +101,8 @@ class ConfigurationCollectorDocletTest {
         assertEquals("No", bool.get("supportRepoIdSuffix"));
         assertEquals("Java System Properties", bool.get("configurationSource"));
         assertEquals("A boolean flag.", bool.get("description"));
+        assertEquals("", bool.get("deprecated"));
+        assertEquals("", bool.get("deprecatedSince"));
 
         Map<String, String> string = keys.get("sample.string");
         assertNotNull(string, "string key missing");
@@ -118,6 +120,8 @@ class ConfigurationCollectorDocletTest {
         assertEquals("VALUE_A", enumKey.get("defaultValue"));
         // no @configurationRepoIdSuffix -> defaults to "No"
         assertEquals("No", enumKey.get("supportRepoIdSuffix"));
+        assertEquals("Use <code>ENUM2_KEY</code> instead", enumKey.get("deprecated"));
+        assertEquals("2.0", enumKey.get("deprecatedSince"));
 
         Map<String, String> enum2Key = keys.get("sample.enum2");
         assertNotNull(enum2Key, "enum key missing");
diff --git a/maven-resolver-tools/src/test/resources/org/eclipse/aether/sample/SampleConfigurationKeys.java b/maven-resolver-tools/src/test/resources/org/eclipse/aether/sample/SampleConfigurationKeys.java
index b7a7730ee..b5c9bbdfd 100644
--- a/maven-resolver-tools/src/test/resources/org/eclipse/aether/sample/SampleConfigurationKeys.java
+++ b/maven-resolver-tools/src/test/resources/org/eclipse/aether/sample/SampleConfigurationKeys.java
@@ -62,7 +62,9 @@ public final class SampleConfigurationKeys {
      * @configurationSource {@link System#getProperty(String,String)}
      * @configurationType {@link SampleEnum}
      * @configurationDefaultValue {@link #DEFAULT_ENUM}
+     * @deprecated Use {@link ENUM2_KEY} instead
      */
+    @Deprecated(since="2.0")
     public static final String ENUM_KEY = "sample.enum";
 
     public static final SampleEnum DEFAULT_ENUM = SampleEnum.VALUE_A;