You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/04/24 17:50:58 UTC

[maven-javadoc-plugin] branch master updated: [MJAVADOC-661] tagletArtifact fails to scan multi-release JARs (MRJARs) for Taglets

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 981ac78  [MJAVADOC-661] tagletArtifact fails to scan multi-release JARs (MRJARs) for Taglets
981ac78 is described below

commit 981ac787ef2339dca42cbd2fe624a013bf5f810e
Author: Allen D. Ball <ba...@hcf.dev>
AuthorDate: Sat Apr 24 19:50:38 2021 +0200

    [MJAVADOC-661] tagletArtifact fails to scan multi-release JARs (MRJARs) for Taglets
    
    Signed-off-by: rfscholte <rf...@apache.org>
---
 .../projects/MJAVADOC-661_mrjar/invoker.properties |  19 ++
 src/it/projects/MJAVADOC-661_mrjar/pom.xml         | 216 +++++++++++++++++++++
 .../src/main/java/com/foo/AbstractTaglet.java      |  55 ++++++
 .../src/main/java/com/foo/Taglet9.java             |  24 +++
 .../src/main/java10/com/foo/Taglet10.java          |  24 +++
 .../src/main/java11/com/foo/Taglet11.java          |  24 +++
 .../src/main/java12/com/foo/Taglet12.java          |  24 +++
 .../src/main/java13/com/foo/Taglet13.java          |  24 +++
 src/it/projects/MJAVADOC-661_mrjar/verify.groovy   |  35 ++++
 .../apache/maven/plugins/javadoc/JavadocUtil.java  |  14 +-
 10 files changed, 455 insertions(+), 4 deletions(-)

diff --git a/src/it/projects/MJAVADOC-661_mrjar/invoker.properties b/src/it/projects/MJAVADOC-661_mrjar/invoker.properties
new file mode 100644
index 0000000..0451eba
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/invoker.properties
@@ -0,0 +1,19 @@
+# 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.goals = clean install javadoc:javadoc
+invoker.java.version = 9+
diff --git a/src/it/projects/MJAVADOC-661_mrjar/pom.xml b/src/it/projects/MJAVADOC-661_mrjar/pom.xml
new file mode 100644
index 0000000..aa23a61
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/pom.xml
@@ -0,0 +1,216 @@
+<?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.plugins.javadoc.it</groupId>
+  <artifactId>mjavadoc661</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>https://issues.apache.org/jira/browse/MJAVADOC-661</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <profiles>
+    <profile>
+      <id>jdk10+</id>
+      <activation><jdk>[10,)</jdk></activation>
+      <build>
+        <pluginManagement>
+          <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-compiler-plugin</artifactId>
+              <executions>
+                <execution>
+                  <id>jdk10</id>
+                  <goals>
+                    <goal>compile</goal>
+                  </goals>
+                  <configuration>
+                    <release>10</release>
+                    <compileSourceRoots>
+                      <compileSourceRoot>${project.basedir}/src/main/java10</compileSourceRoot>
+                    </compileSourceRoots>
+                    <multiReleaseOutput>true</multiReleaseOutput>
+                  </configuration>
+                </execution>
+              </executions>
+            </plugin>
+          </plugins>
+        </pluginManagement>
+      </build>
+    </profile>
+    <profile>
+      <id>jdk11+</id>
+      <activation><jdk>[11,)</jdk></activation>
+      <build>
+        <pluginManagement>
+          <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-compiler-plugin</artifactId>
+              <executions>
+                <execution>
+                  <id>jdk11</id>
+                  <goals>
+                    <goal>compile</goal>
+                  </goals>
+                  <configuration>
+                    <release>11</release>
+                    <compileSourceRoots>
+                      <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
+                    </compileSourceRoots>
+                    <multiReleaseOutput>true</multiReleaseOutput>
+                  </configuration>
+                </execution>
+              </executions>
+            </plugin>
+          </plugins>
+        </pluginManagement>
+      </build>
+    </profile>
+    <profile>
+      <id>jdk12+</id>
+      <activation><jdk>[12,)</jdk></activation>
+      <build>
+        <pluginManagement>
+          <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-compiler-plugin</artifactId>
+              <executions>
+                <execution>
+                  <id>jdk12</id>
+                  <goals>
+                    <goal>compile</goal>
+                  </goals>
+                  <configuration>
+                    <release>12</release>
+                    <compileSourceRoots>
+                      <compileSourceRoot>${project.basedir}/src/main/java12</compileSourceRoot>
+                    </compileSourceRoots>
+                    <multiReleaseOutput>true</multiReleaseOutput>
+                  </configuration>
+                </execution>
+              </executions>
+            </plugin>
+          </plugins>
+        </pluginManagement>
+      </build>
+    </profile>
+    <profile>
+      <id>jdk13+</id>
+      <activation><jdk>[13,)</jdk></activation>
+      <build>
+        <pluginManagement>
+          <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-compiler-plugin</artifactId>
+              <executions>
+                <execution>
+                  <id>jdk13</id>
+                  <goals>
+                    <goal>compile</goal>
+                  </goals>
+                  <configuration>
+                    <release>13</release>
+                    <compileSourceRoots>
+                      <compileSourceRoot>${project.basedir}/src/main/java13</compileSourceRoot>
+                    </compileSourceRoots>
+                    <multiReleaseOutput>true</multiReleaseOutput>
+                  </configuration>
+                </execution>
+              </executions>
+            </plugin>
+          </plugins>
+        </pluginManagement>
+      </build>
+    </profile>
+  </profiles>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.1</version>
+          <executions>
+            <execution>
+              <id>default-compile</id>
+              <configuration>
+                <release>9</release>
+              </configuration>
+            </execution>
+          </executions>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.2.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>default-jar</id>
+            <configuration>
+              <archive>
+                <manifestEntries>
+                  <Multi-Release>true</Multi-Release>
+                </manifestEntries>
+              </archive>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <tagletArtifacts>
+            <tagletArtifact>
+              <groupId>${project.groupId}</groupId>
+              <artifactId>${project.artifactId}</artifactId>
+              <version>${project.version}</version>
+            </tagletArtifact>
+          </tagletArtifacts>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/projects/MJAVADOC-661_mrjar/src/main/java/com/foo/AbstractTaglet.java b/src/it/projects/MJAVADOC-661_mrjar/src/main/java/com/foo/AbstractTaglet.java
new file mode 100644
index 0000000..2fe528b
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/src/main/java/com/foo/AbstractTaglet.java
@@ -0,0 +1,55 @@
+package com.foo;
+
+/*
+ * 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 com.sun.source.doctree.DocTree;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import javax.lang.model.element.Element;
+import jdk.javadoc.doclet.Taglet;
+
+public abstract class AbstractTaglet implements Taglet
+{
+    @Override
+    public String getName( )
+    {
+        return getClass( ).getSimpleName( );
+    }
+
+    @Override
+    public boolean isInlineTag( )
+    {
+        return true;
+    }
+
+
+    @Override
+    public Set<Taglet.Location> getAllowedLocations()
+    {
+        return EnumSet.allOf(Taglet.Location.class);
+    }
+
+    @Override
+    public String toString( List<? extends DocTree> tags, Element element )
+    {
+        return getName( );
+    }
+}
diff --git a/src/it/projects/MJAVADOC-661_mrjar/src/main/java/com/foo/Taglet9.java b/src/it/projects/MJAVADOC-661_mrjar/src/main/java/com/foo/Taglet9.java
new file mode 100644
index 0000000..832a346
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/src/main/java/com/foo/Taglet9.java
@@ -0,0 +1,24 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+public class Taglet9 extends AbstractTaglet
+{
+}
diff --git a/src/it/projects/MJAVADOC-661_mrjar/src/main/java10/com/foo/Taglet10.java b/src/it/projects/MJAVADOC-661_mrjar/src/main/java10/com/foo/Taglet10.java
new file mode 100644
index 0000000..6829318
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/src/main/java10/com/foo/Taglet10.java
@@ -0,0 +1,24 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+public class Taglet10 extends AbstractTaglet
+{
+}
diff --git a/src/it/projects/MJAVADOC-661_mrjar/src/main/java11/com/foo/Taglet11.java b/src/it/projects/MJAVADOC-661_mrjar/src/main/java11/com/foo/Taglet11.java
new file mode 100644
index 0000000..59de6b3
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/src/main/java11/com/foo/Taglet11.java
@@ -0,0 +1,24 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+public class Taglet11 extends AbstractTaglet
+{
+}
diff --git a/src/it/projects/MJAVADOC-661_mrjar/src/main/java12/com/foo/Taglet12.java b/src/it/projects/MJAVADOC-661_mrjar/src/main/java12/com/foo/Taglet12.java
new file mode 100644
index 0000000..b55fda7
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/src/main/java12/com/foo/Taglet12.java
@@ -0,0 +1,24 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+public class Taglet12 extends AbstractTaglet
+{
+}
diff --git a/src/it/projects/MJAVADOC-661_mrjar/src/main/java13/com/foo/Taglet13.java b/src/it/projects/MJAVADOC-661_mrjar/src/main/java13/com/foo/Taglet13.java
new file mode 100644
index 0000000..92dbc05
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/src/main/java13/com/foo/Taglet13.java
@@ -0,0 +1,24 @@
+package com.foo;
+
+/*
+ * 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.
+ */
+
+public class Taglet13 extends AbstractTaglet
+{
+}
diff --git a/src/it/projects/MJAVADOC-661_mrjar/verify.groovy b/src/it/projects/MJAVADOC-661_mrjar/verify.groovy
new file mode 100644
index 0000000..817ea3d
--- /dev/null
+++ b/src/it/projects/MJAVADOC-661_mrjar/verify.groovy
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+int javaVersion = System.getProperty( "java.specification.version" ) as Integer
+def versions = 9..Math.min( 13, javaVersion )
+def required = []
+
+versions.each { required << "'com.foo.Taglet" + it + "'" }
+
+def options = new File( basedir, 'target/site/apidocs/options' );
+
+assert options.exists() : options + " not found"
+
+def lines = options.readLines( )
+def found = lines.findAll { it.matches( "'com.foo.Taglet[0-9]+'" ) }
+
+required.removeAll( found )
+
+assert required.size( ) == 0 : required + " not found"
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index 0f8c822..6e5e650 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -49,7 +49,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Locale;
 import java.util.NoSuchElementException;
 import java.util.Properties;
 import java.util.Set;
@@ -1017,16 +1016,23 @@ public class JavadocUtil
         }
 
         List<String> classes = new ArrayList<>();
+        Pattern pattern =
+            Pattern.compile( "(?i)^(META-INF/versions/(?<v>[0-9]+)/)?(?<n>.+)[.]class$" );
         try ( JarInputStream jarStream = new JarInputStream( new FileInputStream( jarFile ) ) )
         {
             for ( JarEntry jarEntry = jarStream.getNextJarEntry(); jarEntry != null; jarEntry =
                 jarStream.getNextJarEntry() )
             {
-                if ( jarEntry.getName().toLowerCase( Locale.ENGLISH ).endsWith( ".class" ) )
+                Matcher matcher = pattern.matcher( jarEntry.getName() );
+                if ( matcher.matches() )
                 {
-                    String name = jarEntry.getName().substring( 0, jarEntry.getName().indexOf( "." ) );
+                    String version = matcher.group( "v" );
+                    if ( StringUtils.isEmpty( version ) || JavaVersion.JAVA_VERSION.isAtLeast( version ) )
+                    {
+                        String name = matcher.group( "n" );
 
-                    classes.add( name.replaceAll( "/", "\\." ) );
+                        classes.add( name.replaceAll( "/", "\\." ) );
+                    }
                 }
 
                 jarStream.closeEntry();