Author: markt
Date: Fri May  4 18:38:28 2018
New Revision: 1830929

URL: http://svn.apache.org/viewvc?rev=1830929&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62353
Enable Tomcat to run on Java 6 with Common Annotations 1.0. Document 
requirement to use endorsed mechanism to use Common Annotations 1.1.

Modified:
    tomcat/tc7.0.x/trunk/RELEASE-NOTES
    tomcat/tc7.0.x/trunk/RUNNING.txt
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
    tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml

Modified: tomcat/tc7.0.x/trunk/RELEASE-NOTES
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/RELEASE-NOTES?rev=1830929&r1=1830928&r2=1830929&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/RELEASE-NOTES (original)
+++ tomcat/tc7.0.x/trunk/RELEASE-NOTES Fri May  4 18:38:28 2018
@@ -123,7 +123,13 @@ or by placing them in JAR files in the "
 
 To override the XML parser implementation or interfaces, use the endorsed
 mechanism of the JVM. The default configuration defines JARs located in
-"endorsed" as endorsed. This mechanism is no longer supported with Java 9.
+"$CATALINA_HOME/endorsed" as endorsed. This mechanism is no longer supported
+with Java 9.
+
+When running on Java 6, the Common Annotations 1.0 implementation provided
+by the JRE will be used. To use the Common Annotations 1.1 provided by
+Tomcat, use the endorsed mechanism of the JVM. The default configuration
+defines JARs located in "$CATALINA_HOME/endorsed" as endorsed.
 
 
 ================================================================

Modified: tomcat/tc7.0.x/trunk/RUNNING.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/RUNNING.txt?rev=1830929&r1=1830928&r2=1830929&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/RUNNING.txt (original)
+++ tomcat/tc7.0.x/trunk/RUNNING.txt Fri May  4 18:38:28 2018
@@ -38,6 +38,11 @@ Running With JRE 6 Or Later
       You may also use a full Java Development Kit (JDK) rather than just
       a JRE.
 
+(1.3) When running on Java 6, the Common Annotations 1.0 implementation
+      provided by the JRE will be used. To use the Common Annotations 1.1
+      provided by Tomcat, use the endorsed mechanism of the JVM. The
+      default configuration defines JARs located in
+      "$CATALINA_HOME/endorsed" as endorsed.
 
 (2) Download and Install Apache Tomcat
 

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java?rev=1830929&r1=1830928&r2=1830929&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java 
Fri May  4 18:38:28 2018
@@ -37,6 +37,7 @@ import org.apache.catalina.deploy.Contex
 import org.apache.catalina.deploy.FilterDef;
 import org.apache.catalina.deploy.MessageDestinationRef;
 import org.apache.catalina.util.Introspection;
+import org.apache.tomcat.util.compat.JreCompat;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -338,7 +339,9 @@ public class WebAnnotationSet {
             resource.setType(type);
             resource.setDescription(annotation.description());
             resource.setProperty(MAPPED_NAME_PROPERTY, 
annotation.mappedName());
-            resource.setLookupName(annotation.lookup());
+            if (JreCompat.getInstance().isCommonsAnnotations1_1Available()) {
+                resource.setLookupName(annotation.lookup());
+            }
 
             context.getNamingResources().addEnvironment(resource);
 
@@ -351,7 +354,9 @@ public class WebAnnotationSet {
             service.setWsdlfile(annotation.mappedName());
             service.setType(type);
             service.setDescription(annotation.description());
-            service.setLookupName(annotation.lookup());
+            if (JreCompat.getInstance().isCommonsAnnotations1_1Available()) {
+                service.setLookupName(annotation.lookup());
+            }
 
             context.getNamingResources().addService(service);
 
@@ -380,7 +385,9 @@ public class WebAnnotationSet {
             resource.setScope(annotation.shareable() ? "Shareable" : 
"Unshareable");
             resource.setProperty(MAPPED_NAME_PROPERTY, 
annotation.mappedName());
             resource.setDescription(annotation.description());
-            resource.setLookupName(annotation.lookup());
+            if (JreCompat.getInstance().isCommonsAnnotations1_1Available()) {
+                resource.setLookupName(annotation.lookup());
+            }
 
             context.getNamingResources().addResource(resource);
 
@@ -394,7 +401,9 @@ public class WebAnnotationSet {
             resource.setType(type);
             resource.setUsage(annotation.mappedName());
             resource.setDescription(annotation.description());
-            resource.setLookupName(annotation.lookup());
+            if (JreCompat.getInstance().isCommonsAnnotations1_1Available()) {
+                resource.setLookupName(annotation.lookup());
+            }
 
             context.getNamingResources().addMessageDestinationRef(resource);
 
@@ -412,7 +421,9 @@ public class WebAnnotationSet {
             resource.setType(type);
             resource.setProperty(MAPPED_NAME_PROPERTY, 
annotation.mappedName());
             resource.setDescription(annotation.description());
-            resource.setLookupName(annotation.lookup());
+            if (JreCompat.getInstance().isCommonsAnnotations1_1Available()) {
+                resource.setLookupName(annotation.lookup());
+            }
 
             context.getNamingResources().addResourceEnvRef(resource);
         }

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java?rev=1830929&r1=1830928&r2=1830929&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java Fri 
May  4 18:38:28 2018
@@ -86,4 +86,14 @@ class Jre7Compat extends JreCompat {
     public int jarFileRuntimeMajorVersion() {
         return RUNTIME_MAJOR_VERSION;
     }
+
+
+    @Override
+    public boolean isCommonsAnnotations1_1Available() {
+        // True for all Java versions from 7 upwards
+        // Java 7 and Java 8 include it.
+        // Java 9 onwards does not include it and in that case the version
+        // supplied by Tomcat will be used so it will still be available.
+        return true;
+    }
 }

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java?rev=1830929&r1=1830928&r2=1830929&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java Fri 
May  4 18:38:28 2018
@@ -19,6 +19,7 @@ package org.apache.tomcat.util.compat;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Deque;
@@ -26,6 +27,7 @@ import java.util.Locale;
 import java.util.jar.JarFile;
 import java.util.zip.GZIPOutputStream;
 
+import javax.annotation.Resource;
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLServerSocket;
 
@@ -128,7 +130,7 @@ public class JreCompat {
         return true;
     }
 
-    
+
     @SuppressWarnings("unused")
     public GZIPOutputStream getFlushableGZipOutputStream(OutputStream os) {
         throw new UnsupportedOperationException(
@@ -237,4 +239,16 @@ public class JreCompat {
     public int jarFileRuntimeMajorVersion() {
         return RUNTIME_MAJOR_VERSION;
     }
+
+
+    public boolean isCommonsAnnotations1_1Available() {
+        Class<Resource> clazz = Resource.class;
+        Method[] methods = clazz.getDeclaredMethods();
+        for (Method method : methods) {
+            if (method.getName().equals("lookup")) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

Modified: tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml?rev=1830929&r1=1830928&r2=1830929&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml (original)
+++ tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml Fri May  4 
18:38:28 2018
@@ -126,6 +126,9 @@
       <allow pkg="org.apache.tomcat.jni"/>
       <allow pkg="org.apache.tomcat.util"/>
       <disallow pkg="org.apache.util.scan"/>
+      <subpackage name="compat">
+        <allow pkg="javax.annotation"/>
+      </subpackage>
       <subpackage name="scan">
         <allow pkg="org.apache.tomcat" exact-match="true"/>
       </subpackage>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to