maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject [maven-plugin-tools] branch master updated: [MPLUGIN-328] warn on ASM failures but don't fail when scanning deps
Date Fri, 19 Jan 2018 00:05:55 GMT
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git


The following commit(s) were added to refs/heads/master by this push:
     new 2bc1364  [MPLUGIN-328] warn on ASM failures but don't fail when scanning deps
2bc1364 is described below

commit 2bc1364372a5285a6ac9b95c65c711e3ada3bbea
Author: Hervé Boutemy <hboutemy@apache.org>
AuthorDate: Fri Jan 19 01:05:53 2018 +0100

    [MPLUGIN-328] warn on ASM failures but don't fail when scanning deps
---
 .../src/it/asm-failure/invoker.properties          | 18 ++++++
 maven-plugin-plugin/src/it/asm-failure/pom.xml     | 67 ++++++++++++++++++++++
 .../org/apache/maven/plugin/coreit/FirstMojo.java  | 51 ++++++++++++++++
 .../src/it/asm-failure/verify.groovy               | 24 ++++++++
 .../scanner/DefaultMojoAnnotationsScanner.java     | 23 ++++++--
 5 files changed, 177 insertions(+), 6 deletions(-)

diff --git a/maven-plugin-plugin/src/it/asm-failure/invoker.properties b/maven-plugin-plugin/src/it/asm-failure/invoker.properties
new file mode 100644
index 0000000..203dc21
--- /dev/null
+++ b/maven-plugin-plugin/src/it/asm-failure/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.debug = false
diff --git a/maven-plugin-plugin/src/it/asm-failure/pom.xml b/maven-plugin-plugin/src/it/asm-failure/pom.xml
new file mode 100644
index 0000000..a45177a
--- /dev/null
+++ b/maven-plugin-plugin/src/it/asm-failure/pom.xml
@@ -0,0 +1,67 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.asm-failure</groupId>
+  <artifactId>asm-failure</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>maven-plugin</packaging>
+
+  <name>MPLUGIN-328 ignore ASM failures when reading .class</name>
+  <description>
+    ASM failure caused by com.ibm.icu:icu4j:2.6.1 dependency, precisely
+    com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class
+    Same failure happens with dependencies compiled with AspectJ
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>3.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <version>@project.version@</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.ibm.icu</groupId>
+      <artifactId>icu4j</artifactId>
+      <version>2.6.1</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/maven-plugin-plugin/src/it/asm-failure/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
b/maven-plugin-plugin/src/it/asm-failure/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
new file mode 100644
index 0000000..8b4d041
--- /dev/null
+++ b/maven-plugin-plugin/src/it/asm-failure/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -0,0 +1,51 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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 org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Touches a test file.
+ *
+ * @since 1.2
+ */
+@Mojo( name = "first" )
+public class FirstMojo
+    extends AbstractMojo
+{
+
+    /**
+     * @since 0.1
+     * @deprecated As of 0.2
+     */
+    @Parameter( alias = "alias" )
+    private String aliasedParam;
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        getLog().info( "touch" );
+    }
+
+}
diff --git a/maven-plugin-plugin/src/it/asm-failure/verify.groovy b/maven-plugin-plugin/src/it/asm-failure/verify.groovy
new file mode 100644
index 0000000..eef5427
--- /dev/null
+++ b/maven-plugin-plugin/src/it/asm-failure/verify.groovy
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+build = new File( basedir, "build.log" ).text
+assert build.contains( "[WARNING] Error analyzing class com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class
in " )
+assert build.contains( "com/ibm/icu/icu4j/2.6.1/icu4j-2.6.1.jar: ignoring class" )
+
+return true;
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
index f4c8301..f545097 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
@@ -133,7 +133,7 @@ public class DefaultMojoAnnotationsScanner
         String zipEntryName = null;
         try
         {
-            
+            String archiveFilename = archiveFile.getAbsolutePath();
             for ( ZipEntry zipEntry = archiveStream.getNextEntry(); zipEntry != null;
                   zipEntry = archiveStream.getNextEntry() )
             {
@@ -142,7 +142,8 @@ public class DefaultMojoAnnotationsScanner
                 {
                     continue;
                 }
-                analyzeClassStream( mojoAnnotatedClasses, archiveStream, artifact, excludeMojo
);
+                analyzeClassStream( mojoAnnotatedClasses, archiveStream, artifact, excludeMojo,
archiveFilename,
+                                    zipEntry.getName() );
             }
         }
         catch ( IllegalArgumentException e )
@@ -184,6 +185,7 @@ public class DefaultMojoAnnotationsScanner
         }
         scanner.scan();
         String[] classFiles = scanner.getIncludedFiles();
+        String classDirname = classDirectory.getAbsolutePath();
 
         for ( String classFile : classFiles )
         {
@@ -195,7 +197,7 @@ public class DefaultMojoAnnotationsScanner
             InputStream is = new BufferedInputStream( new FileInputStream( new File( classDirectory,
classFile ) ) );
             try
             {
-                analyzeClassStream( mojoAnnotatedClasses, is, artifact, excludeMojo );
+                analyzeClassStream( mojoAnnotatedClasses, is, artifact, excludeMojo, classDirname,
classFile );
             }
             finally
             {
@@ -206,13 +208,22 @@ public class DefaultMojoAnnotationsScanner
     }
 
     private void analyzeClassStream( Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
InputStream is,
-                                     Artifact artifact, boolean excludeMojo )
+                                     Artifact artifact, boolean excludeMojo, String source,
String file )
         throws IOException, ExtractionException
     {
         MojoClassVisitor mojoClassVisitor = new MojoClassVisitor( getLogger() );
 
-        ClassReader rdr = new ClassReader( is );
-        rdr.accept( mojoClassVisitor, ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG
);
+        try
+        {
+            ClassReader rdr = new ClassReader( is );
+            rdr.accept( mojoClassVisitor, ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE
| ClassReader.SKIP_DEBUG );
+        }
+        catch ( ArrayIndexOutOfBoundsException aiooe )
+        {
+            getLogger().warn( "Error analyzing class " + file + " in " + source + ": ignoring
class",
+                              getLogger().isDebugEnabled() ? aiooe : null );
+            return;
+        }
 
         analyzeVisitors( mojoClassVisitor );
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@maven.apache.org" <commits@maven.apache.org>'].

Mime
View raw message