[spring-extensions] branch master updated: Utility bean to detect and warn about deprecated bean names.

Scott Cantor cantor.2 at osu.edu
Wed Jun 10 14:34:27 UTC 2020


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

scantor pushed a commit to branch master
in repository spring-extensions.

View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=8ca1ad7a03ebc401d8eb27f7f3cddea1bfd7bbbb

The following commit(s) were added to refs/heads/master by this push:
       new  8ca1ad7   Utility bean to detect and warn about deprecated bean names.
8ca1ad7 is described below

commit 8ca1ad7a03ebc401d8eb27f7f3cddea1bfd7bbbb
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jun 10 10:34:25 2020 -0400

    Utility bean to detect and warn about deprecated bean names.
---
 .../ext/spring/util/DeprecatedBeanDetector.java    | 83 ++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/src/main/java/net/shibboleth/ext/spring/util/DeprecatedBeanDetector.java b/src/main/java/net/shibboleth/ext/spring/util/DeprecatedBeanDetector.java
new file mode 100644
index 0000000..da78051
--- /dev/null
+++ b/src/main/java/net/shibboleth/ext/spring/util/DeprecatedBeanDetector.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.ext.spring.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * A utility bean to look for and warn about deprecated bean names.
+ * 
+ * <p>In practice this is difficult to use effectively because it has to be run only
+ * after all other beans are in place, so it's best-suited to injection into application
+ * workflows such that it's deliberately used at a known point in the process.</p>
+ * 
+ * @since 6.1.0
+ */
+public class DeprecatedBeanDetector implements ApplicationListener<ContextRefreshedEvent> {
+
+    /** Context for log warnings. */
+    @Nullable private final String warnContext;
+    
+    /** Deprecated bean names. */
+    @Nonnull @NonnullElements private final Map<String,String> beanNames; 
+    
+    /**
+     * Constructor.
+     *
+     * @param map bean names to detect with replacements identified
+     * @param logContext context for log warnings
+     */
+    public DeprecatedBeanDetector(@Nonnull final Map<String,String> map, @Nullable final String logContext) {
+        
+        beanNames = new HashMap<>(map.size());
+        map.forEach((k,v) -> {
+            final String key = StringSupport.trimOrNull(k);
+            final String val = StringSupport.trimOrNull(v);
+            if (key != null) {
+                beanNames.put(key, val);
+            }
+        });
+        
+        warnContext = logContext;
+    }
+
+    /** {@inheritDoc} */
+    public void onApplicationEvent(final ContextRefreshedEvent event) {
+        
+        final ApplicationContext applicationContext = (ApplicationContext) event.getSource();
+        beanNames.forEach((k,v) -> {
+            if (applicationContext.containsLocalBean(k)) {
+                DeprecationSupport.warn(ObjectType.BEAN, k, warnContext, v);
+            }
+        });
+    }
+
+}
\ 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