[java-support] branch maint-8 updated: Add at-risk warning feature.

Scott Cantor cantor.2 at osu.edu
Mon Aug 8 14:18:45 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch maint-8
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=d44fdc3f2c33a352fa13593fbba8502812631c30

The following commit(s) were added to refs/heads/maint-8 by this push:
     new d44fdc3  Add at-risk warning feature.
d44fdc3 is described below

commit d44fdc3f2c33a352fa13593fbba8502812631c30
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Aug 8 10:18:42 2022 -0400

    Add at-risk warning feature.
---
 .../java/support/primitive/DeprecationSupport.java | 67 ++++++++++++++++++++--
 1 file changed, 63 insertions(+), 4 deletions(-)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/primitive/DeprecationSupport.java b/src/main/java/net/shibboleth/utilities/java/support/primitive/DeprecationSupport.java
index 5309806..ade4872 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/primitive/DeprecationSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/primitive/DeprecationSupport.java
@@ -41,7 +41,10 @@ public final class DeprecationSupport {
     
     /** Tracks issued warnings. */
     @Nonnull @NonnullElements private static final Set<String> WARNED_SET = new HashSet<>();
-    
+
+    /** Tracks issued at-risks. */
+    @Nonnull @NonnullElements private static final Set<String> AT_RISK_SET = new HashSet<>();
+
     /** Constructor. */
     private DeprecationSupport() {
         
@@ -127,13 +130,13 @@ public final class DeprecationSupport {
                     type, name, context, replacement);
         } else if (context != null) {
             LOG.warn("{} '{}', ({}): This will be removed in the next major version of this software",
-                type, name, context);
+                    type, name, context);
         } else if (replacement != null) {
             LOG.warn("{} '{}':"
                     + " This will be removed in the next major version of this software; replacement is {}",
-                type, name, replacement);
+                    type, name, replacement);
         } else {
-            LOG.warn("{} '{}': This will be removed in the next major version of this software.",
+            LOG.warn("{} '{}': This will be removed in the next major version of this software",
                     type, name);
         }
     }
@@ -159,6 +162,49 @@ public final class DeprecationSupport {
         warn(type, name, context, replacement);
     }
     
+    /**
+     * Emit an at-risk warning for an object or feature of the system.
+     * 
+     * @param type type of object or feature
+     * @param name name of object or feature
+     * @param context surrounding context for at-risk warning
+     * 
+     * @since 4.3.0
+     */
+    public static void atRisk(@Nonnull final ObjectType type, @Nonnull @NotEmpty final String name,
+            @Nullable final String context) {
+        
+        if (context != null) {
+            LOG.warn("{} '{}', ({}): This feature is at-risk for removal in a future version",
+                    type, name, context);
+        } else {
+            LOG.warn("{} '{}': This feature is at-risk for removal in a future version",
+                    type, name);
+        }
+    }
+    
+    /**
+     * Emit a deprecation warning for an object or feature of the system but limit to a single warning
+     * for the life of the process or until state is cleared.
+     * 
+     * @param type type of object or feature
+     * @param name name of object or feature
+     * @param context surrounding context for deprecation warning
+     * 
+     * @since 4.3.0
+     */
+    public static void atRiskOnce(@Nonnull final ObjectType type, @Nonnull @NotEmpty final String name,
+            @Nullable final String context) {
+        
+        synchronized(AT_RISK_SET) {
+            if (!AT_RISK_SET.add(type.toString() + ':' + name)) {
+                return;
+            }
+        }
+        
+        atRisk(type, name, context);
+    }
+    
     /**
      * Clear the previously warned state.
      */
@@ -168,5 +214,18 @@ public final class DeprecationSupport {
             WARNED_SET.clear();
         }
     }
+
     
+    /**
+     * Clear the previously at-risk state.
+     * 
+     * @since 4.3.0
+     */
+    public static void clearAtRiskState() {
+        
+        synchronized(AT_RISK_SET) {
+            AT_RISK_SET.clear();
+        }
+    }
+
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list