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:08 UTC

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

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