Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 243851865C for ; Tue, 13 Oct 2015 06:38:23 +0000 (UTC) Received: (qmail 32456 invoked by uid 500); 13 Oct 2015 06:38:23 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 32422 invoked by uid 500); 13 Oct 2015 06:38:22 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 32413 invoked by uid 99); 13 Oct 2015 06:38:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Oct 2015 06:38:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 68001E095C; Tue, 13 Oct 2015 06:38:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lukaszlenart@apache.org To: commits@struts.apache.org Message-Id: <222b1e2353664accb22f581d9cd0065a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: struts git commit: Drops deprecation interceptor Date: Tue, 13 Oct 2015 06:38:22 +0000 (UTC) Repository: struts Updated Branches: refs/heads/master 9c5c568fc -> 0dd0f045d Drops deprecation interceptor Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/0dd0f045 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/0dd0f045 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/0dd0f045 Branch: refs/heads/master Commit: 0dd0f045d2cbe6dc6144299e444fe05aa03c0180 Parents: 9c5c568 Author: Lukasz Lenart Authored: Tue Oct 13 08:38:09 2015 +0200 Committer: Lukasz Lenart Committed: Tue Oct 13 08:38:09 2015 +0200 ---------------------------------------------------------------------- .../interceptor/DeprecationInterceptor.java | 106 ------------------- core/src/main/resources/struts-default.xml | 3 - 2 files changed, 109 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/0dd0f045/core/src/main/java/org/apache/struts2/interceptor/DeprecationInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/interceptor/DeprecationInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/DeprecationInterceptor.java deleted file mode 100644 index 3722efe..0000000 --- a/core/src/main/java/org/apache/struts2/interceptor/DeprecationInterceptor.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.apache.struts2.interceptor; - -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.XWorkConstants; -import com.opensymphony.xwork2.inject.Container; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.interceptor.AbstractInterceptor; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.struts2.StrutsConstants; - -import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.Set; - -/** - * - * In devMode checks if application uses deprecated or unknown constants and displays warning - * when logging level is set to DEBUG - * - * - * - * no special parameters yet - * - */ -public class DeprecationInterceptor extends AbstractInterceptor { - - private static final Logger LOG = LogManager.getLogger(DeprecationInterceptor.class); - - private Container container; - private boolean devMode; - - @Override - public String intercept(ActionInvocation invocation) throws Exception { - if (devMode) { - String message = validate(); - if (message != null) { - LOG.debug(message); - } - } - return invocation.invoke(); - } - - /** - * Validates constants. Validation goes on only if devMode is set. - * - * @throws Exception - */ - private String validate() throws Exception { - Set constants = new HashSet<>(); - - readConstants(constants, StrutsConstants.class); - readConstants(constants, XWorkConstants.class); - - Set applicationConstants = container.getInstanceNames(String.class); - String message = null; - if (!constants.containsAll(applicationConstants)) { - Set deprecated = new HashSet<>(applicationConstants); - deprecated.removeAll(constants); - message = prepareMessage(deprecated); - } - return message; - } - - private void readConstants(Set constants, Class clazz) throws IllegalAccessException { - for (Field field : clazz.getDeclaredFields()) { - if (String.class.equals(field.getType())) { - constants.add((String) field.get(clazz)); - } - } - } - - /** - * Prepares message to display - * - * @param deprecated A set with deprecated/unknown constants - */ - private String prepareMessage(Set deprecated) { - StringBuilder sb = new StringBuilder("\n"); - sb.append("*******************************************************************************\n"); - sb.append("** **\n"); - sb.append("** WARNING **\n"); - sb.append("** YOU USE DEPRECATED / UNKNOWN CONSTANTS **\n"); - sb.append("** **\n"); - - for (String dep : deprecated) { - sb.append(String.format("** -> %-69s **\n", dep)); - } - - sb.append("*******************************************************************************\n"); - - return sb.toString(); - } - - @Inject(StrutsConstants.STRUTS_DEVMODE) - public void setDevMode(String state) { - this.devMode = BooleanUtils.toBoolean(state); - } - - @Inject - public void setContainer(Container container) { - this.container = container; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/0dd0f045/core/src/main/resources/struts-default.xml ---------------------------------------------------------------------- diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml index b95a1a0..1f5fa17 100644 --- a/core/src/main/resources/struts-default.xml +++ b/core/src/main/resources/struts-default.xml @@ -215,7 +215,6 @@ - @@ -228,7 +227,6 @@ - @@ -334,7 +332,6 @@ input,back,cancel,browse -