Return-Path: Delivered-To: apmail-maven-commits-archive@www.apache.org Received: (qmail 87507 invoked from network); 8 May 2010 11:58:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 May 2010 11:58:38 -0000 Received: (qmail 55328 invoked by uid 500); 8 May 2010 11:58:38 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 55269 invoked by uid 500); 8 May 2010 11:58:38 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 55262 invoked by uid 99); 8 May 2010 11:58:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 May 2010 11:58:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 May 2010 11:58:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 065FD23888DD; Sat, 8 May 2010 11:57:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r942370 - in /maven/plugins/trunk/maven-shade-plugin/src: it/reloc-anno/ it/reloc-anno/src/ it/reloc-anno/src/main/ it/reloc-anno/src/main/java/ it/reloc-anno/src/main/java/relocated/ main/java/org/apache/maven/plugins/shade/ Date: Sat, 08 May 2010 11:57:36 -0000 To: commits@maven.apache.org From: bentmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100508115737.065FD23888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bentmann Date: Sat May 8 11:57:36 2010 New Revision: 942370 URL: http://svn.apache.org/viewvc?rev=942370&view=rev Log: [MSHADE-79] Annotations are not shaded o Extended original patch to fix field annotations as well o Added IT Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties (with props) maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml (with props) maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java (with props) maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java (with props) Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/TempRemappingClassAdapter.java Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties?rev=942370&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties Sat May 8 11:57:36 2010 @@ -0,0 +1 @@ +invoker.java.version = 1.5+ Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml?rev=942370&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml Sat May 8 11:57:36 2010 @@ -0,0 +1,108 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.ra + test + 1.0 + jar + + MSHADE-79 + + Test that annotations are properly relocated. + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + org.apache.maven.plugins + maven-resources-plugin + 2.2 + + + org.apache.maven.plugins + maven-shade-plugin + @project.version@ + + + shade + package + + shade + + + false + + + relocated + hidden + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + run + verify + + exec + + + java + + -classpath + ${project.build.directory}/test-1.0.jar + Main + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.3.1 + + + + Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java?rev=942370&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java Sat May 8 11:57:36 2010 @@ -0,0 +1,59 @@ +/* + * 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. + */ + +import java.lang.reflect.*; + +import relocated.*; + +@MyAnno +public class Main +{ + + @MyAnno + public String field = ""; + + @MyAnno + public Main() + { + } + + @MyAnno + public void method() + { + } + + public static void main( String[] args ) + throws Exception + { + Class type = Main.class; + Field field = type.getField( "field" ); + Method method = type.getMethod( "method" ); + Constructor constructor = type.getConstructor(); + + AnnotatedElement[] elements = { type, method, constructor, field }; + for ( AnnotatedElement element : elements ) + { + if ( !element.isAnnotationPresent( MyAnno.class ) ) + { + throw new IllegalStateException( "annotation missing on " + element ); + } + } + } + +} Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/Main.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java?rev=942370&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java Sat May 8 11:57:36 2010 @@ -0,0 +1,25 @@ +package relocated; + +/* + * 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. + */ + +@java.lang.annotation.Retention( java.lang.annotation.RetentionPolicy.RUNTIME ) +public @interface MyAnno +{ +} Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-anno/src/main/java/relocated/MyAnno.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/TempRemappingClassAdapter.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/TempRemappingClassAdapter.java?rev=942370&r1=942369&r2=942370&view=diff ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/TempRemappingClassAdapter.java (original) +++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/TempRemappingClassAdapter.java Sat May 8 11:57:36 2010 @@ -21,10 +21,12 @@ package org.apache.maven.plugins.shade; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.commons.RemappingAnnotationAdapter; import org.objectweb.asm.commons.RemappingClassAdapter; +import org.objectweb.asm.commons.RemappingFieldAdapter; import org.objectweb.asm.commons.RemappingMethodAdapter; /** @@ -36,22 +38,45 @@ class TempRemappingClassAdapter extends RemappingClassAdapter { - private static class MethRemapVisitor + private static class MethodRemapVisitor extends RemappingMethodAdapter { - public MethRemapVisitor( int access, String desc, MethodVisitor mv, Remapper renamer ) + public MethodRemapVisitor( int access, String desc, MethodVisitor mv, Remapper renamer ) { super( access, desc, mv, renamer ); } public AnnotationVisitor visitAnnotation( String desc, boolean visible ) { - // The original source from asm did not have the call to remapper.mapDesc() + // The original source from asm:3.2 does not have the call to remapper.mapDesc() AnnotationVisitor av = mv.visitAnnotation( remapper.mapDesc( desc ), visible ); return av == null ? av : new RemappingAnnotationAdapter( av, remapper ); } } + private static class FieldRemapVisitor + extends RemappingFieldAdapter + { + + private final FieldVisitor fv; + + private final Remapper remapper; + + public FieldRemapVisitor( FieldVisitor fv, Remapper remapper ) + { + super( fv, remapper ); + this.fv = fv; + this.remapper = remapper; + } + + public AnnotationVisitor visitAnnotation( String desc, boolean visible ) + { + // The original source from asm:3.2 does not have the call to remapper.mapDesc() + AnnotationVisitor av = fv.visitAnnotation( remapper.mapDesc( desc ), visible ); + return av == null ? null : new RemappingAnnotationAdapter( av, remapper ); + } + } + public TempRemappingClassAdapter( ClassVisitor cv, Remapper remapper ) { super( cv, remapper ); @@ -59,7 +84,12 @@ class TempRemappingClassAdapter protected MethodVisitor createRemappingMethodAdapter( int access, String newDesc, MethodVisitor mv ) { - return new MethRemapVisitor( access, newDesc, mv, remapper ); + return new MethodRemapVisitor( access, newDesc, mv, remapper ); + } + + protected FieldVisitor createRemappingFieldAdapter( FieldVisitor fv ) + { + return new FieldRemapVisitor( fv, remapper ); } }