You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/05/10 14:34:06 UTC

[sling-slingfeature-maven-plugin] branch master updated (41b701b -> 3fefcc9)

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

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


    from 41b701b  SLING-8412 - APIs jar MOJO includes wrapped classes which are not OSGi exported and potentially override public APIs
     new 9e6c701  SLING-8412 - APIs jar MOJO includes wrapped classes which are not OSGi exported and potentially override public APIs
     new 3fefcc9  SLING-8340 - APIs jar MOJO doesn't handle OSGi wrapper bundles

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:
 .../invoker.properties                             |  0
 .../pom.xml                                        |  5 --
 .../src/main/features/main.json                    | 21 ++++++
 .../apis-jar-wrapped-flattened-classes/verify.bsh  | 88 ++++++++++++++++++++++
 .../sling/feature/maven/mojos/ApisJarMojo.java     | 62 ++++++++-------
 5 files changed, 143 insertions(+), 33 deletions(-)
 copy src/it/{apis-jar => apis-jar-wrapped-flattened-classes}/invoker.properties (100%)
 copy src/it/{apis-jar => apis-jar-wrapped-flattened-classes}/pom.xml (88%)
 create mode 100644 src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json
 create mode 100644 src/it/apis-jar-wrapped-flattened-classes/verify.bsh


[sling-slingfeature-maven-plugin] 01/02: SLING-8412 - APIs jar MOJO includes wrapped classes which are not OSGi exported and potentially override public APIs

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

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

commit 9e6c7017414e7af05e3977f30aef82bb4e7d2f61
Author: stripodi <st...@simos-mbp>
AuthorDate: Fri May 10 16:31:34 2019 +0200

    SLING-8412 - APIs jar MOJO includes wrapped classes which are not OSGi
    exported and potentially override public APIs
    
    added integration test
---
 .../invoker.properties                             | 17 +++++
 src/it/apis-jar-wrapped-flattened-classes/pom.xml  | 53 +++++++++++++
 .../src/main/features/main.json                    | 21 ++++++
 .../apis-jar-wrapped-flattened-classes/verify.bsh  | 88 ++++++++++++++++++++++
 4 files changed, 179 insertions(+)

diff --git a/src/it/apis-jar-wrapped-flattened-classes/invoker.properties b/src/it/apis-jar-wrapped-flattened-classes/invoker.properties
new file mode 100644
index 0000000..91f59c8
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/invoker.properties
@@ -0,0 +1,17 @@
+# 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 org.apache.sling:slingfeature-maven-plugin:apis-jar
+invoker.debug = true
diff --git a/src/it/apis-jar-wrapped-flattened-classes/pom.xml b/src/it/apis-jar-wrapped-flattened-classes/pom.xml
new file mode 100644
index 0000000..1ecf87e
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/pom.xml
@@ -0,0 +1,53 @@
+<?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>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json b/src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json
new file mode 100644
index 0000000..1590cff
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json
@@ -0,0 +1,21 @@
+{
+  "id":"org.apache.sling:slingfeature-maven-plugin-test:1.0.0-SNAPSHOT",
+  "bundles":[
+    {
+      "id":"org.apache.jackrabbit:oak-lucene:1.10.2",
+      "start-level":"4"
+    },
+    {
+      "id":"org.apache.jackrabbit:oak-solr-osgi:1.10.2",
+      "start-level":"5"
+    }
+  ],
+  "api-regions:JSON|false": [
+    {
+      "name": "base",
+      "exports": [
+        "org.apache.lucene.analysis.standard"
+      ]
+    }
+  ]
+}
diff --git a/src/it/apis-jar-wrapped-flattened-classes/verify.bsh b/src/it/apis-jar-wrapped-flattened-classes/verify.bsh
new file mode 100644
index 0000000..a94a0cd
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/verify.bsh
@@ -0,0 +1,88 @@
+/*
+ * 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.io.*;
+import java.util.*;
+import java.util.jar.*;
+
+import org.codehaus.plexus.util.*;
+
+    boolean check() throws Exception {
+        File apisJarDir = new File(basedir, "target/apis-jars");
+
+        // base
+
+        File baseApiJar = new File(apisJarDir, "slingfeature-maven-plugin-test-1.0.0-SNAPSHOT-base-apis.jar");
+        if (!baseApiJar.exists()) {
+            System.out.println("FAILED!");
+            System.out.println("File '" + file + "' not found");
+            return false;
+        }
+
+        InputStream bytecodeStream = null;
+        JarFile jarFile = null;
+        try {
+            jarFile = new JarFile(baseApiJar);
+            Manifest manifest= jarFile.getManifest();
+            String exportPackageHeader = manifest.getMainAttributes().getValue("Export-Package");
+
+            if (exportPackageHeader.indexOf("org.apache.lucene.analysis.standard") < 0) {
+                System.out.println("FAILED!");
+                System.out.println("Export-Package header '" + exportPackageHeader + "' does not contain 'org.apache.lucene.analysis.standard' in bundle " + file);
+                return false;
+            }
+
+            JarEntry jarEntry = jarFile.getJarEntry("org/apache/lucene/analysis/standard/StandardAnalyzer.class");
+            if (jarEntry == null) {
+                System.out.println("FAILED!");
+                System.out.println("Entry 'org/apache/lucene/analysis/standard/StandardAnalyzer.class' does not exist in bundle " + file);
+            }
+
+            bytecodeStream = jarFile.getInputStream(jarEntry);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] buf = new byte[1024];
+            int len = 0;
+            while ((len = bytecodeStream.read(buf)) >= 0) {
+                baos.write(buf, 0, len);
+            }
+
+            if (!baos.toString().contains("#(Lorg/apache/lucene/util/Version;)V")) {
+                System.out.println("FAILED!");
+                System.out.println("Expected org.apache.lucene.analysis.standard.StandardAnalyzer class containing a constructor with 'org.apache.lucene.util.Version' argument");
+                return false;
+            }
+        } finally {
+            if (jarFile != null) {
+                jarFile.close();
+            }
+
+            if (bytecodeStream != null) {
+                bytecodeStream.close();
+            }
+        }
+
+        return true;
+    }
+
+    try {
+        return check();
+    } catch(Throwable t) {
+        t.printStackTrace();
+        return false;
+    }
+
+    return true;


[sling-slingfeature-maven-plugin] 02/02: SLING-8340 - APIs jar MOJO doesn't handle OSGi wrapper bundles

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

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

commit 3fefcc9e623f728c7d46d89618abc0408301d814
Author: stripodi <st...@simos-mbp>
AuthorDate: Fri May 10 16:32:25 2019 +0200

    SLING-8340 - APIs jar MOJO doesn't handle OSGi wrapper bundles
    
    in the new scenario, wrapped bundles have to inherit wrapping Manifest
    to calculate which classes have to be exported
---
 .../sling/feature/maven/mojos/ApisJarMojo.java     | 62 ++++++++++++----------
 1 file changed, 34 insertions(+), 28 deletions(-)

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 cc45ce7..389995e 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
@@ -224,7 +224,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
 
         // for each artifact included in the feature file:
         for (Artifact artifact : feature.getBundles()) {
-            onArtifact(artifact, apiRegions, javadocClasspath, deflatedBinDir, deflatedSourcesDir, checkedOutSourcesDir);
+            onArtifact(artifact, null, apiRegions, javadocClasspath, deflatedBinDir, deflatedSourcesDir, checkedOutSourcesDir);
         }
 
         // recollect and package stuff
@@ -256,6 +256,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
     }
 
     private void onArtifact(Artifact artifact,
+                            Manifest wrappingBundleManifest,
                             List<ApiRegion> apiRegions,
                             Set<String> javadocClasspath,
                             File deflatedBinDir,
@@ -264,41 +265,46 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
         ArtifactId artifactId = artifact.getId();
         File bundleFile = retrieve(artifactId);
 
-        try (JarFile bundle = new JarFile(bundleFile)) {
-            getLog().debug("Reading Manifest headers from bundle " + bundleFile);
+        Manifest manifest;
+        if (wrappingBundleManifest == null) {
+            try (JarFile bundle = new JarFile(bundleFile)) {
+                getLog().debug("Reading Manifest headers from bundle " + bundleFile);
 
-            Manifest manifest = bundle.getManifest();
+                manifest = bundle.getManifest();
 
-            if (manifest == null) {
-                throw new MojoExecutionException("Manifest file not included in "
-                        + bundleFile
-                        + " bundle");
+                if (manifest == null) {
+                    throw new MojoExecutionException("Manifest file not included in "
+                            + bundleFile
+                            + " bundle");
+                }
+            } catch (IOException e) {
+                throw new MojoExecutionException("An error occurred while reading " + bundleFile + " file", e);
             }
+        } else {
+            manifest = wrappingBundleManifest;
+        }
 
-            // calculate the exported versioned packages in the manifest file for each region
-            // and calculate the exported versioned packages in the manifest file for each region
-            String[] exportedPackages = computeExportPackage(apiRegions, manifest);
+        // calculate the exported versioned packages in the manifest file for each region
+        // and calculate the exported versioned packages in the manifest file for each region
+        String[] exportedPackages = computeExportPackage(apiRegions, manifest);
 
-            // deflate all bundles first, in order to copy APIs and resources later, depending to the region
-            String[] exportedPackagesAndWrappedBundles = Stream.concat(Stream.concat(Stream.of(exportedPackages), Stream.of("**/*.jar")),
-                                                                       Stream.of(includeResources))
-                                                               .toArray(String[]::new);
-            File deflatedBundleDirectory = deflate(deflatedBinDir, bundleFile, exportedPackagesAndWrappedBundles);
+        // deflate all bundles first, in order to copy APIs and resources later, depending to the region
+        String[] exportedPackagesAndWrappedBundles = Stream.concat(Stream.concat(Stream.of(exportedPackages), Stream.of("**/*.jar")),
+                                                                   Stream.of(includeResources))
+                                                           .toArray(String[]::new);
+        File deflatedBundleDirectory = deflate(deflatedBinDir, bundleFile, exportedPackagesAndWrappedBundles);
 
-            // check if the bundle wraps other bundles
-            computeWrappedBundles(manifest, deflatedBundleDirectory, apiRegions, javadocClasspath, deflatedBinDir, deflatedSourcesDir, checkedOutSourcesDir);
+        // check if the bundle wraps other bundles
+        computeWrappedBundles(manifest, deflatedBundleDirectory, apiRegions, javadocClasspath, deflatedBinDir, deflatedSourcesDir, checkedOutSourcesDir);
 
-            // renaming potential name-collapsing resources
-            renameResources(deflatedBundleDirectory, artifactId);
+        // renaming potential name-collapsing resources
+        renameResources(deflatedBundleDirectory, artifactId);
 
-            // download sources
-            downloadSources(artifact, deflatedSourcesDir, checkedOutSourcesDir, exportedPackages);
+        // download sources
+        downloadSources(artifact, deflatedSourcesDir, checkedOutSourcesDir, exportedPackages);
 
-            // to suppress any javadoc error
-            buildJavadocClasspath(javadocClasspath, artifactId);
-        } catch (IOException e) {
-            throw new MojoExecutionException("An error occurred while reading " + bundleFile + " file", e);
-        }
+        // to suppress any javadoc error
+        buildJavadocClasspath(javadocClasspath, artifactId);
     }
 
     private void computeWrappedBundles(Manifest manifest,
@@ -358,7 +364,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
             }
 
             Artifact syntheticArtifact = new Artifact(new ArtifactId(groupId, artifactId, version, classifier, null));
-            onArtifact(syntheticArtifact, apiRegions, javadocClasspath, deflatedBinDir, deflatedSourcesDir, checkedOutSourcesDir);
+            onArtifact(syntheticArtifact, manifest, apiRegions, javadocClasspath, deflatedBinDir, deflatedSourcesDir, checkedOutSourcesDir);
         }
     }