Skip to content

Commit

Permalink
JERSEY-2274: Shadow ASM classes with jersey specific packageas it uses
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Michal Gajdos committed Jan 16, 2014
1 parent 8c803c0 commit 411f767
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ nb-configuration.xml
.settings/*
.project
.classpath

#Maven plugins noise
dependency-reduced-pom.xml
23 changes: 23 additions & 0 deletions bundles/jaxrs-ri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
<artifactId>hk2-locator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>asm-all-repackaged</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -263,6 +268,7 @@
com.sun.research.ws.wadl.*;version=${project.version}
</Export-Package>
<Import-Package>
!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)",
Expand All @@ -278,6 +284,23 @@
<excludeDependencies>*;scope=compile</excludeDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<artifactSet>
<includes>
<include>org.glassfish.hk2.external:asm-all-repackaged:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>${jersey.shade.package.prefix}.objectweb.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<!-- producing zipped archives -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
34 changes: 31 additions & 3 deletions core-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@
<configuration>
<instructions>
<!-- Note: When you're changing these properties change them also in bundles/jaxrs-ri/pom.xml. -->
<Export-Package>org.glassfish.jersey.server.*;version=${project.version},com.sun.research.ws.wadl.*;version=${project.version}</Export-Package>
<Import-Package>*</Import-Package>
<Export-Package>
org.glassfish.jersey.server.*;version=${project.version},
com.sun.research.ws.wadl.*;version=${project.version}
</Export-Package>
<Import-Package>
!org.objectweb.asm.*,
*
</Import-Package>
</instructions>
<unpackBundle>true</unpackBundle>
</configuration>
Expand All @@ -101,6 +107,24 @@
</includeSchemas>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<artifactSet>
<includes>
<include>org.glassfish.hk2.external:asm-all-repackaged:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>${jersey.shade.package.prefix}.objectweb.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -136,7 +160,6 @@
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -151,6 +174,11 @@
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-locator</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>asm-all-repackaged</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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<? extends Annotation>... annotations) {
public AnnotationAcceptingListener(final Class<? extends Annotation>... annotations) {
this(AccessController.doPrivileged(ReflectionHelper.getContextClassLoaderPA()), annotations);
}

Expand All @@ -134,8 +135,8 @@ public AnnotationAcceptingListener(Class<? extends Annotation>... annotations) {
* @param annotations the set of annotation classes to check on Java class
* files.
*/
public AnnotationAcceptingListener(ClassLoader classloader,
Class<? extends Annotation>... annotations) {
public AnnotationAcceptingListener(final ClassLoader classloader,
final Class<? extends Annotation>... annotations) {
this.classloader = classloader;
this.classes = new LinkedHashSet<Class<?>>();
this.annotations = getAnnotationSet(annotations);
Expand All @@ -151,27 +152,27 @@ public Set<Class<?>> getAnnotatedClasses() {
return classes;
}

private Set<String> getAnnotationSet(Class<? extends Annotation>... annotations) {
Set<String> a = new HashSet<String>();
for (Class c : annotations) {
private Set<String> getAnnotationSet(final Class<? extends Annotation>... annotations) {
final Set<String> a = new HashSet<String>();
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.
Expand All @@ -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
Expand All @@ -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();

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions examples/extended-wadl-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@
<artifactId>jettison</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>asm-all-repackaged</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>aopalliance-repackaged</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 16 additions & 0 deletions examples/osgi-helloworld-webapp/functional-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>asm-all-repackaged</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>aopalliance-repackaged</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<scope>test</scope>
</dependency>

<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -152,7 +152,8 @@ public List<Option> genericOsgiOptions() {
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(),

// Google Guava
mavenBundle().groupId("com.google.guava").artifactId("guava").versionAsInProject(),
Expand Down
Loading

0 comments on commit 411f767

Please sign in to comment.