maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
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 GMT
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.shade.ra</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <name>MSHADE-79</name>
+  <description>
+    Test that annotations are properly relocated.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>shade</id>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <createDependencyReducedPom>false</createDependencyReducedPom>
+              <relocations>
+                <relocation>
+                  <pattern>relocated</pattern>
+                  <shadedPattern>hidden</shadedPattern>
+                </relocation>
+              </relocations>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <version>1.1.1</version>
+        <executions>
+          <execution>
+            <id>run</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>exec</goal>
+            </goals>
+            <configuration>
+              <executable>java</executable>
+              <arguments>
+                <argument>-classpath</argument>
+                <argument>${project.build.directory}/test-1.0.jar</argument>
+                <argument>Main</argument>
+              </arguments>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>

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 );
     }
 
 }



Mime
View raw message