From 411f767d3686ee494000741ee60f24419264679c Mon Sep 17 00:00:00 2001 From: Michal Gajdos Date: Wed, 15 Jan 2014 18:53:26 +0100 Subject: [PATCH] JERSEY-2274: Shadow ASM classes with jersey specific packageas it uses old ASM version conflicting with other software using ASM 4.x and above JERSEY-2278: Update to ASM 5.0 beta. - Updated to HK2 2.2.0 - Updated to ASM 5.0 - Repackaging ASM in core-server and jaxrs-ri - Updated dependencies in OSGi tests (in OSGi we're not able to drop dependency on asm because hk2-locator lists asm in imports) - Added ASM dependency to test-framework to make tests pass in IDE Change-Id: I0a75cccabf524d507ec8c9766e7734ed2d614253 Signed-off-by: Michal Gajdos --- .gitignore | 3 + bundles/jaxrs-ri/pom.xml | 23 ++++++ core-server/pom.xml | 34 ++++++++- .../scanning/AnnotationAcceptingListener.java | 75 +++++++++---------- .../server/internal/localization.properties | 3 +- examples/extended-wadl-webapp/pom.xml | 15 ++++ .../ExtendedWadlWebappOsgiTest.java | 5 +- .../functional-test/pom.xml | 16 ++++ .../helloworld/test/AbstractWebAppTest.java | 5 +- .../osgi-http-service/functional-test/pom.xml | 16 ++++ .../test/AbstractHttpServiceTest.java | 5 +- pom.xml | 39 +++++++++- test-framework/pom.xml | 4 + tests/osgi/functional/pom.xml | 15 ++++ .../jersey/osgi/test/util/Helper.java | 5 +- 15 files changed, 212 insertions(+), 51 deletions(-) diff --git a/.gitignore b/.gitignore index 2824d4b51d..14a6d1baa2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ nb-configuration.xml .settings/* .project .classpath + +#Maven plugins noise +dependency-reduced-pom.xml diff --git a/bundles/jaxrs-ri/pom.xml b/bundles/jaxrs-ri/pom.xml index baec0d6b21..cd5223c78a 100644 --- a/bundles/jaxrs-ri/pom.xml +++ b/bundles/jaxrs-ri/pom.xml @@ -143,6 +143,11 @@ hk2-locator provided + + org.glassfish.hk2.external + asm-all-repackaged + true + com.google.guava guava @@ -263,6 +268,7 @@ com.sun.research.ws.wadl.*;version=${project.version} + !org.objectweb.asm.*, javax.servlet.annotation.*;resolution:=optional;version="${range;[==,+);${servlet3.version}}", javax.servlet.descriptor.*;resolution:=optional;version="${range;[==,+);${servlet3.version}}", javax.servlet.*;version="[2.4,4.0)", @@ -278,6 +284,23 @@ *;scope=compile + + org.apache.maven.plugins + maven-shade-plugin + + + + org.glassfish.hk2.external:asm-all-repackaged:* + + + + + org.objectweb.asm + ${jersey.shade.package.prefix}.objectweb.asm + + + + maven-assembly-plugin diff --git a/core-server/pom.xml b/core-server/pom.xml index 48f69680c9..d5cbeaa8a0 100644 --- a/core-server/pom.xml +++ b/core-server/pom.xml @@ -76,8 +76,14 @@ - org.glassfish.jersey.server.*;version=${project.version},com.sun.research.ws.wadl.*;version=${project.version} - * + + org.glassfish.jersey.server.*;version=${project.version}, + com.sun.research.ws.wadl.*;version=${project.version} + + + !org.objectweb.asm.*, + * + true @@ -101,6 +107,24 @@ + + org.apache.maven.plugins + maven-shade-plugin + true + + + + org.glassfish.hk2.external:asm-all-repackaged:* + + + + + org.objectweb.asm + ${jersey.shade.package.prefix}.objectweb.asm + + + + @@ -136,7 +160,6 @@ javax.annotation javax.annotation-api - provided @@ -151,6 +174,11 @@ org.glassfish.hk2 hk2-locator + + org.glassfish.hk2.external + asm-all-repackaged + true + javax.validation diff --git a/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java b/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java index 781899b540..ff36e8566f 100644 --- a/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/AnnotationAcceptingListener.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -54,6 +54,7 @@ import org.glassfish.jersey.internal.OsgiRegistry; import org.glassfish.jersey.internal.util.ReflectionHelper; +import org.glassfish.jersey.server.internal.LocalizationMessages; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; @@ -110,7 +111,7 @@ public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener() * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. */ @SuppressWarnings({"unchecked"}) - public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(ClassLoader classLoader) { + public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(final ClassLoader classLoader) { return new AnnotationAcceptingListener(classLoader, Path.class, Provider.class); } @@ -121,7 +122,7 @@ public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(Cl * @param annotations the set of annotation classes to check on Java class * files. */ - public AnnotationAcceptingListener(Class... annotations) { + public AnnotationAcceptingListener(final Class... annotations) { this(AccessController.doPrivileged(ReflectionHelper.getContextClassLoaderPA()), annotations); } @@ -134,8 +135,8 @@ public AnnotationAcceptingListener(Class... annotations) { * @param annotations the set of annotation classes to check on Java class * files. */ - public AnnotationAcceptingListener(ClassLoader classloader, - Class... annotations) { + public AnnotationAcceptingListener(final ClassLoader classloader, + final Class... annotations) { this.classloader = classloader; this.classes = new LinkedHashSet>(); this.annotations = getAnnotationSet(annotations); @@ -151,27 +152,27 @@ public Set> getAnnotatedClasses() { return classes; } - private Set getAnnotationSet(Class... annotations) { - Set a = new HashSet(); - for (Class c : annotations) { + private Set getAnnotationSet(final Class... annotations) { + final Set a = new HashSet(); + for (final Class c : annotations) { a.add("L" + c.getName().replaceAll("\\.", "/") + ";"); } return a; } // ScannerListener - public boolean accept(String name) { + public boolean accept(final String name) { return !(name == null || name.isEmpty()) && name.endsWith(".class"); } - public void process(String name, InputStream in) throws IOException { + public void process(final String name, final InputStream in) throws IOException { new ClassReader(in).accept(classVisitor, 0); } // - private final class AnnotatedClassVisitor implements ClassVisitor { + private final class AnnotatedClassVisitor extends ClassVisitor { /** * The name of the visited class. @@ -186,20 +187,24 @@ private final class AnnotatedClassVisitor implements ClassVisitor { */ private boolean isAnnotated; - public void visit(int version, int access, String name, - String signature, String superName, String[] interfaces) { + private AnnotatedClassVisitor() { + super(Opcodes.ASM5); + } + + public void visit(final int version, final int access, final String name, + final String signature, final String superName, final String[] interfaces) { className = name; isScoped = (access & Opcodes.ACC_PUBLIC) != 0; isAnnotated = false; } - public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) { isAnnotated |= annotations.contains(desc); return null; } - public void visitInnerClass(String name, String outerName, - String innerName, int access) { + public void visitInnerClass(final String name, final String outerName, + final String innerName, final int access) { // If the name of the class that was visited is equal // to the name of this visited inner class then // this access field needs to be used for checking the scope @@ -220,34 +225,34 @@ public void visitEnd() { } } - public void visitOuterClass(String string, String string0, - String string1) { + public void visitOuterClass(final String string, final String string0, + final String string1) { // Do nothing } - public FieldVisitor visitField(int i, String string, - String string0, String string1, - Object object) { + public FieldVisitor visitField(final int i, final String string, + final String string0, final String string1, + final Object object) { // Do nothing return null; } - public void visitSource(String string, String string0) { + public void visitSource(final String string, final String string0) { // Do nothing } - public void visitAttribute(Attribute attribute) { + public void visitAttribute(final Attribute attribute) { // Do nothing } - public MethodVisitor visitMethod(int i, String string, - String string0, String string1, - String[] string2) { + public MethodVisitor visitMethod(final int i, final String string, + final String string0, final String string1, + final String[] string2) { // Do nothing return null; } - private Class getClassForName(String className) { + private Class getClassForName(final String className) { try { final OsgiRegistry osgiRegistry = ReflectionHelper.getOsgiRegistryInstance(); @@ -256,21 +261,15 @@ private Class getClassForName(String className) { } else { return AccessController.doPrivileged(ReflectionHelper.classForNameWithExceptionPEA(className, classloader)); } - } catch (ClassNotFoundException ex) { - String s = "A class file of the class name, " + - className + - "is identified but the class could not be found"; - throw new RuntimeException(s, ex); - } catch (PrivilegedActionException pae) { + } catch (final ClassNotFoundException ex) { + throw new RuntimeException(LocalizationMessages.ERROR_SCANNING_CLASS_NOT_FOUND(className), ex); + } catch (final PrivilegedActionException pae) { final Throwable cause = pae.getCause(); if (cause instanceof ClassNotFoundException) { - String s = "A class file of the class name, " + - className + - "is identified but the class could not be found"; - throw new RuntimeException(s, cause); + throw new RuntimeException(LocalizationMessages.ERROR_SCANNING_CLASS_NOT_FOUND(className), cause); } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; - }else { + } else { throw new RuntimeException(cause); } } diff --git a/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties b/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties index 0fbb44d109..aab2698db0 100644 --- a/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties +++ b/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties @@ -1,7 +1,7 @@ # # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # -# Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common Development @@ -76,6 +76,7 @@ error.resources.cannot.merge=Resources do not have the same path and cannot be m error.request.abort.in.response.phase=The request cannot be aborted as it is already in the response processing phase. error.request.set.entity.stream.in.response.phase=The entity stream cannot be set in the request as it is already in the response processing phase. error.request.set.security.context.in.response.phase=The security context cannot be set in the request as it is already in the response processing phase. +error.scanning.class.not.found=A class file of the class name, {0}, is identified but the class could not be found. error.sub.resource.locator.more.resources=Sub resource locator returned {0} in the resource model. Exactly one resource must be returned. error.suspending.chunked.output.response=Attempt to suspend a client connection associated with a chunked output has failed in the underlying container. error.suspending.async.request=Attempt to suspend a connection of an asynchronous request failed in the underlying container. diff --git a/examples/extended-wadl-webapp/pom.xml b/examples/extended-wadl-webapp/pom.xml index d6f0e56888..99868bfce3 100644 --- a/examples/extended-wadl-webapp/pom.xml +++ b/examples/extended-wadl-webapp/pom.xml @@ -137,6 +137,21 @@ jettison + + org.glassfish.hk2.external + asm-all-repackaged + test + + + org.glassfish.hk2.external + aopalliance-repackaged + test + + + org.javassist + javassist + test + diff --git a/examples/extended-wadl-webapp/src/test/java/org/glassfish/jersey/examples/extendedwadl/ExtendedWadlWebappOsgiTest.java b/examples/extended-wadl-webapp/src/test/java/org/glassfish/jersey/examples/extendedwadl/ExtendedWadlWebappOsgiTest.java index 6ee4d88065..63c23134e5 100644 --- a/examples/extended-wadl-webapp/src/test/java/org/glassfish/jersey/examples/extendedwadl/ExtendedWadlWebappOsgiTest.java +++ b/examples/extended-wadl-webapp/src/test/java/org/glassfish/jersey/examples/extendedwadl/ExtendedWadlWebappOsgiTest.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -138,7 +138,8 @@ public static Option[] configuration() { mavenBundle().groupId("org.glassfish.hk2").artifactId("hk2-utils").versionAsInProject(), mavenBundle().groupId("org.glassfish.hk2.external").artifactId("javax.inject").versionAsInProject(), mavenBundle().groupId("org.glassfish.hk2.external").artifactId("asm-all-repackaged").versionAsInProject(), - mavenBundle().groupId("org.glassfish.hk2.external").artifactId("cglib").versionAsInProject(), + mavenBundle().groupId("org.glassfish.hk2.external").artifactId("aopalliance-repackaged").versionAsInProject(), + mavenBundle().groupId("org.javassist").artifactId("javassist").versionAsInProject(), // JAX-RS API mavenBundle().groupId("javax.ws.rs").artifactId("javax.ws.rs-api").versionAsInProject(), diff --git a/examples/osgi-helloworld-webapp/functional-test/pom.xml b/examples/osgi-helloworld-webapp/functional-test/pom.xml index 141f732766..61b110db1d 100644 --- a/examples/osgi-helloworld-webapp/functional-test/pom.xml +++ b/examples/osgi-helloworld-webapp/functional-test/pom.xml @@ -94,6 +94,22 @@ test + + org.glassfish.hk2.external + asm-all-repackaged + test + + + org.glassfish.hk2.external + aopalliance-repackaged + test + + + org.javassist + javassist + test + + org.slf4j diff --git a/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/AbstractWebAppTest.java b/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/AbstractWebAppTest.java index bce3cae0fe..4fdf915197 100644 --- a/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/AbstractWebAppTest.java +++ b/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/AbstractWebAppTest.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -152,7 +152,8 @@ public List + + org.glassfish.hk2.external + asm-all-repackaged + test + + + org.glassfish.hk2.external + aopalliance-repackaged + test + + + org.javassist + javassist + test + + org.apache.felix diff --git a/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/AbstractHttpServiceTest.java b/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/AbstractHttpServiceTest.java index a85e7acaad..eb3481fe5b 100644 --- a/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/AbstractHttpServiceTest.java +++ b/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/AbstractHttpServiceTest.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -133,7 +133,8 @@ public List + + org.glassfish.hk2.external + asm-all-repackaged + ${hk2.version} + + + org.glassfish.hk2.external + aopalliance-repackaged + ${hk2.version} + + + org.javassist + javassist + ${javassist.version} + org.glassfish.grizzly @@ -1295,6 +1330,7 @@ 1.6 etc/config/javadoc-stylesheet.css + org.glassfish.jersey.shaded gf-cddl-gpl UTF-8 UTF-8 @@ -1316,9 +1352,10 @@ 1.6 2.3.8 1.3 - 2.2.0-b21 + 2.2.0 1.9.13 2.2.3 + 3.18.1-GA 1.2 1.2 2.2.4 diff --git a/test-framework/pom.xml b/test-framework/pom.xml index 85eccdf21b..05cfecbb4d 100644 --- a/test-framework/pom.xml +++ b/test-framework/pom.xml @@ -66,5 +66,9 @@ junit compile + + org.glassfish.hk2.external + asm-all-repackaged + diff --git a/tests/osgi/functional/pom.xml b/tests/osgi/functional/pom.xml index 5d99e70d16..e7acc50104 100644 --- a/tests/osgi/functional/pom.xml +++ b/tests/osgi/functional/pom.xml @@ -299,6 +299,21 @@ jsonp-jaxrs test + + org.glassfish.hk2.external + asm-all-repackaged + test + + + org.glassfish.hk2.external + aopalliance-repackaged + test + + + org.javassist + javassist + test + diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java index a82a9348db..1d21ad7cda 100644 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java +++ b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -167,7 +167,8 @@ public static List