You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/08/13 20:47:05 UTC
[6/9] git commit: Create a new DeprecationWarning service for
tracking deprecated parameters, etc.,
in components Move CompatibilityImpl to the correct package
Create a new DeprecationWarning service for tracking deprecated parameters, etc., in components
Move CompatibilityImpl to the correct package
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/749fbf9e
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/749fbf9e
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/749fbf9e
Branch: refs/heads/5.4-js-rewrite
Commit: 749fbf9ec6aca260635c9ffdd4f2cae0ddd50c85
Parents: 4ea77f4
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Aug 13 10:25:16 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Aug 13 10:25:16 2012 -0700
----------------------------------------------------------------------
.../internal/compatibility/CompatibilityImpl.java | 41 -----
.../services/compatibility/CompatibilityImpl.java | 41 +++++
.../compatibility/DeprecationWarningImpl.java | 115 +++++++++++++++
.../compatibility/CompatibilityModule.java | 4 +-
.../services/compatibility/DeprecationWarning.java | 44 ++++++
5 files changed, 203 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/749fbf9e/tapestry-core/src/main/java/org/apache/tapestry5/internal/compatibility/CompatibilityImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/compatibility/CompatibilityImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/compatibility/CompatibilityImpl.java
deleted file mode 100644
index be70f99..0000000
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/compatibility/CompatibilityImpl.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2012 The Apache Software Foundation
-//
-// Licensed 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 org.apache.tapestry5.internal.compatibility;
-
-import org.apache.tapestry5.services.compatibility.Compatibility;
-import org.apache.tapestry5.services.compatibility.Trait;
-
-import java.util.Collection;
-import java.util.EnumSet;
-
-public class CompatibilityImpl implements Compatibility
-{
- private final EnumSet<Trait> traits;
-
- public CompatibilityImpl(Collection<Trait> configuration)
- {
- traits = EnumSet.noneOf(Trait.class);
-
- traits.addAll(configuration);
- }
-
- @Override
- public boolean enabled(Trait trait)
- {
- assert trait != null;
-
- return traits.contains(trait);
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/749fbf9e/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/CompatibilityImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/CompatibilityImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/CompatibilityImpl.java
new file mode 100644
index 0000000..296dd82
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/CompatibilityImpl.java
@@ -0,0 +1,41 @@
+// Copyright 2012 The Apache Software Foundation
+//
+// Licensed 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 org.apache.tapestry5.internal.services.compatibility;
+
+import org.apache.tapestry5.services.compatibility.Compatibility;
+import org.apache.tapestry5.services.compatibility.Trait;
+
+import java.util.Collection;
+import java.util.EnumSet;
+
+public class CompatibilityImpl implements Compatibility
+{
+ private final EnumSet<Trait> traits;
+
+ public CompatibilityImpl(Collection<Trait> configuration)
+ {
+ traits = EnumSet.noneOf(Trait.class);
+
+ traits.addAll(configuration);
+ }
+
+ @Override
+ public boolean enabled(Trait trait)
+ {
+ assert trait != null;
+
+ return traits.contains(trait);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/749fbf9e/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
new file mode 100644
index 0000000..aeb6b22
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java
@@ -0,0 +1,115 @@
+// Copyright 2012 The Apache Software Foundation
+//
+// Licensed 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 org.apache.tapestry5.internal.services.compatibility;
+
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.services.ComponentClasses;
+import org.apache.tapestry5.services.ComponentMessages;
+import org.apache.tapestry5.services.ComponentTemplates;
+import org.apache.tapestry5.services.InvalidationEventHub;
+import org.apache.tapestry5.services.compatibility.DeprecationWarning;
+import org.slf4j.Logger;
+
+import java.util.Map;
+
+public class DeprecationWarningImpl implements DeprecationWarning
+{
+ private final Logger logger;
+
+ static class ParameterValueDeprecationKey
+ {
+ final String completeId, parameterName;
+ final Object value;
+
+ ParameterValueDeprecationKey(String completeId, String parameterName, Object value)
+ {
+ this.completeId = completeId;
+ this.parameterName = parameterName;
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ParameterValueDeprecationKey that = (ParameterValueDeprecationKey) o;
+
+ if (!completeId.equals(that.completeId)) return false;
+ if (!parameterName.equals(that.parameterName)) return false;
+ if (value != null ? !value.equals(that.value) : that.value != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = completeId.hashCode();
+ result = 31 * result + parameterName.hashCode();
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+ }
+
+ // Really used as a set.
+ private final Map<Object, Boolean> deprecations = CollectionFactory.newConcurrentMap();
+
+ public DeprecationWarningImpl(Logger logger)
+ {
+ this.logger = logger;
+ }
+
+ @Override
+ public void componentParameterValue(ComponentResources resources, String parameterName, Object parameterValue, String message)
+ {
+ assert resources != null;
+ assert InternalUtils.isNonBlank(parameterName);
+ assert InternalUtils.isNonBlank(message);
+
+ ParameterValueDeprecationKey key = new ParameterValueDeprecationKey(resources.getCompleteId(), parameterName, parameterValue);
+
+ if (deprecations.containsKey(key))
+ {
+ return;
+ }
+
+ deprecations.put(key, true);
+
+ logger.error(String.format("Component %s, parameter %s. %s\n(at %s)",
+ key.completeId,
+ parameterName,
+ message,
+ resources.getLocation());
+ }
+
+ public void setupClearDeprecationsWhenInvalidated(
+ @ComponentClasses
+ InvalidationEventHub componentClassesHub,
+ @ComponentMessages
+ InvalidationEventHub messagesHub,
+ @ComponentTemplates
+ InvalidationEventHub templatesHub)
+ {
+ componentClassesHub.clearOnInvalidation(deprecations);
+ messagesHub.clearOnInvalidation(deprecations);
+ templatesHub.clearOnInvalidation(deprecations);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/749fbf9e/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/CompatibilityModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/CompatibilityModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/CompatibilityModule.java
index 29eb254..0070ff9 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/CompatibilityModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/CompatibilityModule.java
@@ -14,7 +14,8 @@
package org.apache.tapestry5.services.compatibility;
-import org.apache.tapestry5.internal.compatibility.CompatibilityImpl;
+import org.apache.tapestry5.internal.services.compatibility.CompatibilityImpl;
+import org.apache.tapestry5.internal.services.compatibility.DeprecationWarningImpl;
import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Contribute;
@@ -29,6 +30,7 @@ public class CompatibilityModule
public static void bind(ServiceBinder binder)
{
binder.bind(Compatibility.class, CompatibilityImpl.class);
+ binder.bind(DeprecationWarning.class, DeprecationWarningImpl.class);
}
@Contribute(Compatibility.class)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/749fbf9e/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
new file mode 100644
index 0000000..7ee616b
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java
@@ -0,0 +1,44 @@
+// Copyright 2012 The Apache Software Foundation
+//
+// Licensed 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 org.apache.tapestry5.services.compatibility;
+
+import org.apache.tapestry5.ComponentResources;
+
+/**
+ * Used to report deprecation warnings for components.
+ *
+ * @since 5.4
+ */
+public interface DeprecationWarning
+{
+ /**
+ * 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
+ * logger, including the component type and complete id, name of parameter (but not the value), the message, and the location of
+ * the component.
+ *
+ * @param resources
+ * identifies the component, including its location.
+ * @param parameterName
+ * name of parameter containing illegal value.
+ * @param parameterValue
+ * value that is not supported (typically, an enum type). May be null.
+ * @param message
+ * message to display; typically explains that action will be taken, such as treating the value as an alternate value,
+ * or simply ignoring the value. This should clarify the issue to the developer, guiding them towards resolving
+ * the deprecation, by changing the value, or eliminating the use of the parameter entirely.
+ */
+ void componentParameterValue(ComponentResources resources, String parameterName, Object parameterValue, String message);
+}