[java-support] branch master updated: IDP-1177 - Centralize deprecation warnings through dedicated function
Scott Cantor
cantor.2 at osu.edu
Fri Jun 2 16:52:36 EDT 2017
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=2fb39e2a3d16172e5a4126c117073acc708bdd96
The following commit(s) were added to refs/heads/master by this push:
new 2fb39e2 IDP-1177 - Centralize deprecation warnings through dedicated function
2fb39e2 is described below
commit 2fb39e2a3d16172e5a4126c117073acc708bdd96
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Jun 2 16:52:34 2017 -0400
IDP-1177 - Centralize deprecation warnings through dedicated function
https://issues.shibboleth.net/jira/browse/IDP-1177
Helper class to centralize warnings.
---
.../java/support/primitive/DeprecationSupport.java | 156 +++++++++++++++++++++
1 file changed, 156 insertions(+)
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
new file mode 100644
index 0000000..04527c6
--- /dev/null
+++ b/src/main/java/net/shibboleth/utilities/java/support/primitive/DeprecationSupport.java
@@ -0,0 +1,156 @@
+/*
+ * 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.utilities.java.support.primitive;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
+
+/** Helper methods for reporting usage of deprecated features. */
+public final class DeprecationSupport {
+
+ /** Class logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(DeprecationSupport.class);
+
+ /** Tracks issued warnings. */
+ @Nonnull @NonnullElements private static final Set<String> WARNED_SET = new HashSet<>();
+
+ /** Constructor. */
+ private DeprecationSupport() {
+
+ }
+
+ /**
+ * Type of object, setting, feature, etc. being deprecated.
+ */
+ public enum ObjectType {
+
+ /** Java class/type. */
+ CLASS("Java class"),
+
+ /** Java method. */
+ METHOD("Java class method"),
+
+ /** Key/value property. */
+ PROPERTY("property"),
+
+ /** Spring bean. */
+ BEAN("Spring bean"),
+
+ /** XML namespace. */
+ NAMESPACE("XML Namespace"),
+
+ /** XML type. */
+ XSITYPE("xsi:type"),
+
+ /** XML element. */
+ ELEMENT("XML Element"),
+
+ /** XML attribute. */
+ ATTRIBUTE("XML Attribute"),
+
+ /** Spring web flow. */
+ WEBFLOW("Spring WebFlow");
+
+ /** Printed version. */
+ @Nonnull @NotEmpty private final String text;
+
+ /**
+ * Constructor.
+ *
+ * @param s printed representation
+ */
+ private ObjectType(@Nonnull @NotEmpty final String s) {
+ text = s;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return text;
+ }
+ }
+
+ /**
+ * Emit a deprecation 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 deprecation warning
+ * @param replacement the replacement for the deprecated feature
+ */
+ public static void warn(@Nonnull final ObjectType type, @Nonnull @NotEmpty final String name,
+ @Nullable final String context, @Nullable final String replacement) {
+
+ if (context != null && replacement != null) {
+ LOG.warn("DEPRECATED {} '{}', ({}):"
+ + " This will be removed in the next major version of this software; replacement is {}",
+ type, name, context, replacement);
+ } else if (context != null) {
+ LOG.warn("DEPRECATED {} '{}', ({}): This will be removed in the next major version of this software",
+ type, name, context);
+ } else if (replacement != null) {
+ LOG.warn("DEPRECATED {} '{}':"
+ + " This will be removed in the next major version of this software; replacement is {}",
+ type, name, replacement);
+ } else {
+ LOG.warn("DEPRECATED {} '{}': This will be removed in the next major version of this software.",
+ 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
+ * @param replacement the replacement for the deprecated feature
+ */
+ public static void warnOnce(@Nonnull final ObjectType type, @Nonnull @NotEmpty final String name,
+ @Nullable final String context, @Nullable final String replacement) {
+
+ synchronized(WARNED_SET) {
+ if (!WARNED_SET.add(type.toString() + ':' + name)) {
+ return;
+ }
+ }
+
+ warn(type, name, context, replacement);
+ }
+
+ /**
+ * Clear the previously warned state.
+ */
+ public static void clearWarningState() {
+
+ synchronized(WARNED_SET) {
+ WARNED_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