Add support for deprecated parameters to DeprecationWarning
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/d5d75031 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/d5d75031 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/d5d75031 Branch: refs/heads/5.4-js-rewrite Commit: d5d750317194c76b48270dcac05bae202f354927 Parents: 7384c03 Author: Howard M. Lewis Ship <[email protected]> Authored: Mon Aug 13 10:51:08 2012 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Mon Aug 13 10:51:08 2012 -0700 ---------------------------------------------------------------------- .../compatibility/DeprecationWarningImpl.java | 59 ++++++++++++++- .../services/compatibility/DeprecationWarning.java | 16 ++++ 2 files changed, 74 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d5d75031/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java index 88a84fc..5312432 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java @@ -30,6 +30,39 @@ public class DeprecationWarningImpl implements DeprecationWarning { private final Logger logger; + static class ParameterDeprecationKey + { + final String completeId, parameterName; + + ParameterDeprecationKey(String completeId, String parameterName) + { + this.completeId = completeId; + this.parameterName = parameterName; + } + + @Override + public boolean equals(Object o) + { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ParameterDeprecationKey that = (ParameterDeprecationKey) o; + + if (!completeId.equals(that.completeId)) return false; + if (!parameterName.equals(that.parameterName)) return false; + + return true; + } + + @Override + public int hashCode() + { + int result = completeId.hashCode(); + result = 31 * result + parameterName.hashCode(); + return result; + } + } + static class ParameterValueDeprecationKey { final String completeId, parameterName; @@ -76,6 +109,25 @@ public class DeprecationWarningImpl implements DeprecationWarning } @Override + public void componentParameter(ComponentResources resources, String parameterName, String message) + { + assert resources != null; + assert InternalUtils.isNonBlank(parameterName); + assert InternalUtils.isNonBlank(message); + + ParameterDeprecationKey key = new ParameterDeprecationKey(resources.getCompleteId(), parameterName); + + if (deprecations.containsKey(key)) + { + return; + } + + deprecations.put(key, true); + + logMessage(resources, parameterName, message); + } + + @Override public void componentParameterValue(ComponentResources resources, String parameterName, Object parameterValue, String message) { assert resources != null; @@ -91,8 +143,13 @@ public class DeprecationWarningImpl implements DeprecationWarning deprecations.put(key, true); + logMessage(resources, parameterName, message); + } + + private void logMessage(ComponentResources resources, String parameterName, String message) + { logger.error(String.format("Component %s, parameter %s: %s\n(at %s)", - key.completeId, + resources.getCompleteId(), parameterName, message, resources.getLocation())); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d5d75031/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java index 7ee616b..b93ee27 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java @@ -23,6 +23,22 @@ import org.apache.tapestry5.ComponentResources; */ public interface DeprecationWarning { + + /** + * Used to identify a component parameter that has been deprecated. Typically, such parameters are simply + * ignored, but the message should be specific about this. + * + * @param resources + * identifies the component, including its location + * @param parameterName + * name of the deprecated parameter + * @param message + * message to display; typically explains what action will be taken, such as simply ignoring the parameter entirely. This should clarify + * the issue to the developer, guiding them torwards resolving the deprecation, typically be eliminating + * the parameter entirely. + */ + void componentParameter(ComponentResources resources, String parameterName, String message); + /** * Used to identify a specific parameter value that is no longer supported. The first time this combination of * component, parameter name, and parameter value are provided, an error is logged against this service's
