You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/09/22 17:45:42 UTC

svn commit: r1174223 - in /openejb/trunk/openejb3/container/openejb-core/src/main: java/org/apache/openejb/config/ java/org/apache/openejb/config/rules/ resources/org/apache/openejb/config/rules/

Author: dblevins
Date: Thu Sep 22 15:45:42 2011
New Revision: 1174223

URL: http://svn.apache.org/viewvc?rev=1174223&view=rev
Log:
OPENEJB-1683: Validation: @Inject InectionPoint not used on servlet classes

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckInjectionPointUsage.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
    openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java?rev=1174223&r1=1174222&r2=1174223&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java Thu Sep 22 15:45:42 2011
@@ -32,6 +32,7 @@ import org.apache.openejb.config.rules.C
 import org.apache.openejb.config.rules.CheckClasses;
 import org.apache.openejb.config.rules.CheckDependsOn;
 import org.apache.openejb.config.rules.CheckDescriptorLocation;
+import org.apache.openejb.config.rules.CheckInjectionPointUsage;
 import org.apache.openejb.config.rules.CheckInjectionTargets;
 import org.apache.openejb.config.rules.CheckMethods;
 import org.apache.openejb.config.rules.CheckPersistenceRefs;
@@ -105,6 +106,7 @@ public class AppValidator {
                 new CheckCallbacks(),
                 new CheckAssemblyBindings(),
                 new CheckInjectionTargets(),
+                new CheckInjectionPointUsage(),
                 new CheckPersistenceRefs(),
                 new CheckDependsOn(),
                 new CheckUserTransactionRefs(),

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckInjectionPointUsage.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckInjectionPointUsage.java?rev=1174223&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckInjectionPointUsage.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckInjectionPointUsage.java Thu Sep 22 15:45:42 2011
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 org.apache.openejb.config.rules;
+
+import org.apache.openejb.config.EjbModule;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServlet;
+import java.lang.reflect.Field;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CheckInjectionPointUsage extends ValidationBase {
+
+    @Override
+    public void validate(EjbModule ejbModule) {
+        if (ejbModule.getBeans() == null) return;
+
+        for (Field field : ejbModule.getFinder().findAnnotatedFields(Inject.class)) {
+            if (!field.getType().equals(InjectionPoint.class)) continue;
+            if (!HttpServlet.class.isAssignableFrom(field.getDeclaringClass())) continue;
+
+            fail(field.getDeclaringClass().getSimpleName(), "cdi.injectionPointOnNonBean", field.getDeclaringClass().getName(), field.getName());
+        }
+    }
+}

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=1174223&r1=1174222&r2=1174223&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties Thu Sep 22 15:45:42 2011
@@ -872,4 +872,7 @@ public interface {0} extends {2}'{}'
 2.descriptor.incorrectLocation = Descriptor {0} placed in incorrect location {1}
 3.descriptor.incorrectLocation = Found descriptor file {0} directly under base-directory {1}. Descriptors are to be placed at base-directory/META-INF or base-directory/WEB-INF 
 
-
+# TODO improve this message.  It's a little short and not helpful
+1.cdi.injectionPointOnNonBean = Invalid @Inject InjectionPoint (see CDI 1.0 section 5.5.7)
+2.cdi.injectionPointOnNonBean = Invalid @Inject InjectionPoint (see CDI 1.0 section 5.5.7): class {0} field {1}
+3.cdi.injectionPointOnNonBean = Invalid @Inject InjectionPoint (see CDI 1.0 section 5.5.7): class {0} field {1}