You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2019/12/05 22:26:50 UTC

[sling-slingfeature-maven-plugin] branch master updated (5a404b0 -> 0418cfe)

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

rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git.


    from 5a404b0  SLING-8880 - Allow configuring the source release for the javadoc invocation
     new b273e4d  SLING-8876 - ApisJar mojo includess invalid javadoc package roots
     new 0418cfe  SLING-8876 - ApisJar mojo includess invalid javadoc package roots

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .sling-module.json                                 |  5 +++
 .../invoker.properties                             |  4 +++
 .../{apis-jar => apis-jar-invalid-javadoc}/pom.xml |  0
 .../src/main/features/main.json                    | 17 +++++++++
 .../sling/feature/maven/mojos/ApisJarMojo.java     | 42 +++++++++++++++++++---
 5 files changed, 63 insertions(+), 5 deletions(-)
 create mode 100644 .sling-module.json
 copy src/it/{apis-jar-wrapped-flattened-classes => apis-jar-invalid-javadoc}/invoker.properties (84%)
 copy src/it/{apis-jar => apis-jar-invalid-javadoc}/pom.xml (100%)
 create mode 100644 src/it/apis-jar-invalid-javadoc/src/main/features/main.json


[sling-slingfeature-maven-plugin] 02/02: SLING-8876 - ApisJar mojo includess invalid javadoc package roots

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0418cfe3b038fa69618dd1b7417b2bbc788fc104
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Dec 5 15:59:55 2019 +0100

    SLING-8876 - ApisJar mojo includess invalid javadoc package roots
    
    Build project with Java 11 on Jenkins as well, to protect from various
    javadoc behaviour changes.
---
 .sling-module.json | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/.sling-module.json b/.sling-module.json
new file mode 100644
index 0000000..21ac44e
--- /dev/null
+++ b/.sling-module.json
@@ -0,0 +1,5 @@
+{
+    "jenkins": {
+        "jdks": [8, 11]
+    }
+}


[sling-slingfeature-maven-plugin] 01/02: SLING-8876 - ApisJar mojo includess invalid javadoc package roots

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b273e4d603cba9953bcdf3fe9908fab0c5fc2f06
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Dec 5 15:58:34 2019 +0100

    SLING-8876 - ApisJar mojo includess invalid javadoc package roots
    
    Java 11 seems to be more diligent when following references for Javadoc
    information. Ensure that we only consider top-level directories that
    contain java files.
---
 src/it/apis-jar-invalid-javadoc/invoker.properties | 21 ++++++++
 src/it/apis-jar-invalid-javadoc/pom.xml            | 59 ++++++++++++++++++++++
 .../src/main/features/main.json                    | 17 +++++++
 .../sling/feature/maven/mojos/ApisJarMojo.java     | 42 +++++++++++++--
 4 files changed, 134 insertions(+), 5 deletions(-)

diff --git a/src/it/apis-jar-invalid-javadoc/invoker.properties b/src/it/apis-jar-invalid-javadoc/invoker.properties
new file mode 100644
index 0000000..aa87eb6
--- /dev/null
+++ b/src/it/apis-jar-invalid-javadoc/invoker.properties
@@ -0,0 +1,21 @@
+# 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.
+
+# the goal of this check is to validate the fix for SLING-8876
+# therefore we don't need to check anything in addition to the build
+# completing succesfully
+
+invoker.goals = clean org.apache.sling:slingfeature-maven-plugin:apis-jar
+invoker.debug = true
diff --git a/src/it/apis-jar-invalid-javadoc/pom.xml b/src/it/apis-jar-invalid-javadoc/pom.xml
new file mode 100644
index 0000000..0f803ea
--- /dev/null
+++ b/src/it/apis-jar-invalid-javadoc/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.sling</groupId>
+  <artifactId>slingfeature-maven-plugin-test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0.0-SNAPSHOT</version>
+
+  <name>Apache Sling Features Maven plugin test</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <extensions>true</extensions>
+        <executions>
+          <execution>
+            <id>analyze</id>
+            <phase>package</phase>
+            <goals>
+              <goal>apis-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <selection>
+            <filesInclude>**/*.json</filesInclude>
+          </selection>
+          <includeResources>
+            <includeResource>*.cnd</includeResource>
+            <includeResource>*.tld</includeResource>
+          </includeResources>
+          <javadocLinks>
+            <javadocLink>https://osgi.org/javadoc/r6/core/</javadocLink>
+            <javadocLink>https://osgi.org/javadoc/r6/annotation/</javadocLink>
+            <javadocLink>https://osgi.org/javadoc/r6/cmpn/</javadocLink>
+          </javadocLinks>
+          <incrementalApis>false</incrementalApis>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/apis-jar-invalid-javadoc/src/main/features/main.json b/src/it/apis-jar-invalid-javadoc/src/main/features/main.json
new file mode 100644
index 0000000..ec0ba98
--- /dev/null
+++ b/src/it/apis-jar-invalid-javadoc/src/main/features/main.json
@@ -0,0 +1,17 @@
+{
+  "id":"org.apache.sling:slingfeature-maven-plugin-test:1.0.0-SNAPSHOT",
+  "bundles":[
+    {
+      "id":"org.apache.servicemix.bundles:org.apache.servicemix.bundles.xmlbeans:3.1.0_1",
+      "sourceId": "org.apache.xmlbeans:xmlbeans:jar:sources:3.1.0"
+    }
+  ],
+  "api-regions:JSON|false": [
+    {
+      "name": "base",
+      "exports": [
+        "org.apache.xmlbeans.impl.xb.xmlschema"
+      ]
+    }
+  ]
+}
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
index b6b9261..346f746 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
@@ -17,10 +17,14 @@
 package org.apache.sling.feature.maven.mojos;
 
 import java.io.File;
+import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -34,11 +38,13 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.function.BiPredicate;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import javax.json.JsonArray;
@@ -136,6 +142,8 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
 
     private static final String PROPERTY_BUNDLE = ApisJarMojo.class.getName() + ".bundle";
 
+    private static final BiPredicate<Path, BasicFileAttributes> IS_JAVA_FILE = (p,a) -> p.toFile().isFile() && p.toFile().getName().endsWith(JAVA_EXTENSION);
+
     /**
      * Select the features for api generation.
      */
@@ -444,14 +452,15 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
                     this.apiSourceResources);
             report(sourceJar, SOURCES, apiRegion, "java");
 
-            if (sourcesDir.list().length > 0) {
+            List<String> subpackageDirectories = calculateSubpackageDirectories(sourcesDir);
+            if (!subpackageDirectories.isEmpty()) {
                 File javadocsDir = new File(regionDir, JAVADOC);
-                generateJavadoc(sourcesDir, javadocsDir, javadocClasspath);
+                generateJavadoc(sourcesDir, javadocsDir, javadocClasspath, subpackageDirectories);
                 final File javadocJar = createArchive(feature.getId(), javadocsDir, apiRegion, JAVADOC, null,
                         this.apiJavadocResources);
                 report(javadocJar, JAVADOC, apiRegion, "html");
             } else {
-                getLog().warn("Javadoc JAR will NOT be generated - sources directory was empty!");
+                getLog().warn("Javadoc JAR will NOT be generated - sources directory " + sourcesDir +" was empty or contained no Java files!");
             }
         }
 
@@ -1216,7 +1225,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
         return target;
     }
 
-    private void generateJavadoc(File sourcesDir, File javadocDir, Set<String> javadocClasspath)
+    private void generateJavadoc(File sourcesDir, File javadocDir, Set<String> javadocClasspath, List<String> subpackageDirectories)
             throws MojoExecutionException {
         javadocDir.mkdirs();
 
@@ -1271,12 +1280,35 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
 
         // use the -subpackages to reduce the list of the arguments
         javadocExecutor.addArgument("-subpackages", false);
-        javadocExecutor.addArgument(sourcesDir.list(), File.pathSeparator);
+        javadocExecutor.addArgument(subpackageDirectories, File.pathSeparator);
 
         // .addArgument("-J-Xmx2048m")
         javadocExecutor.execute(javadocDir, getLog(), this.ignoreJavadocErrors);
     }
 
+    /**
+     * Returns the list of subdirectories that have at least one Java source file
+     *
+     * @param sourcesDir the directory with source files
+     * @return a list of subpackages, potentially empty, never <code>null</code>
+     */
+    private List<String> calculateSubpackageDirectories(File sourcesDir) {
+        // make sure to only include files that have at least one java source file
+        return Arrays.stream(sourcesDir.listFiles( new FileFilter() {
+            @Override
+            public boolean accept(File pathname) {
+                try {
+                    try ( Stream<Path> javaFiles = Files.find(pathname.toPath(), Integer.MAX_VALUE, IS_JAVA_FILE)) {
+                        return javaFiles.findFirst().isPresent();
+                    }
+                } catch (IOException e) {
+                    getLog().warn("Failed scanning " + pathname + " for Java files", e);
+                    return false;
+                }
+            }
+        })).map( File::getName ).collect(Collectors.toList());
+    }
+
     private static ArtifactId newArtifacId(ArtifactId original, String classifier, String type) {
         return new ArtifactId(original.getGroupId(),
                               original.getArtifactId(),