You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2019/11/07 07:46:51 UTC

[sling-slingfeature-maven-plugin] branch master updated: SLING-8831 : Provide more than one source for the api for an artifact

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a56bdc5  SLING-8831 : Provide more than one source for the api for an artifact
a56bdc5 is described below

commit a56bdc580faea3b783be10bcebe2d20cbdfb6804
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Nov 7 08:46:41 2019 +0100

    SLING-8831 : Provide more than one source for the api for an artifact
---
 .../sling/feature/maven/mojos/ApisJarMojo.java     | 65 ++++++++++++++--------
 1 file changed, 42 insertions(+), 23 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 b17dbb3..e5aa5a1 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
@@ -805,38 +805,57 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
         getLog().debug(Arrays.toString(includeResources) + " resources in " + destDirectory + " successfully renamed");
     }
 
+    private boolean downloadSourceAndDeflate(final ArtifactProvider artifactProvider,
+            final ArtifactId sourcesArtifactId, final File deflatedSourcesDir, final String[] exportPackageIncludes,
+            final ArtifactId artifactId, final boolean allowFallback) throws MojoExecutionException {
+        boolean failed = false;
+        try {
+            final URL url = retrieve(artifactProvider, sourcesArtifactId);
+            if (url != null) {
+                File sourcesBundle = IOUtils.getFileFromURL(url, true, null);
+                deflate(deflatedSourcesDir, sourcesBundle, exportPackageIncludes);
+            } else {
+                if (!allowFallback) {
+                    throw new MojoExecutionException("Unable to download sources for " + artifactId.toMvnId()
+                            + " due to missing artifact " + sourcesArtifactId.toMvnId());
+                }
+                getLog().warn("Unable to download sources for " + artifactId.toMvnId() + " due to missing artifact "
+                        + sourcesArtifactId.toMvnId() + ", trying source checkout next...");
+                failed = true;
+            }
+        } catch (final MojoExecutionException mee) {
+            throw mee;
+        } catch (final Throwable t) {
+            if (!allowFallback) {
+                throw new MojoExecutionException("Unable to download sources for " + artifactId.toMvnId()
+                        + " due to missing artifact " + sourcesArtifactId.toMvnId());
+            }
+            getLog().warn("Unable to download sources for " + artifactId.toMvnId() + " from "
+                    + sourcesArtifactId.toMvnId() + " due to " + t.getMessage() + ", trying source checkout next...");
+            failed = true;
+        }
+        return failed;
+    }
+
     private void downloadSources(final ArtifactProvider artifactProvider, Artifact artifact, File deflatedSourcesDir,
             File checkedOutSourcesDir, String[] exportPackageIncludes) throws MojoExecutionException {
         ArtifactId artifactId = artifact.getId();
         getLog().debug("Downloading sources for " + artifactId.toMvnId() + "...");
 
-        ArtifactId sourcesArtifactId;
+        boolean fallback = false;
         if ( artifact.getMetadata().get(SCM_ID) != null ) {
-            sourcesArtifactId = ArtifactId.parse(artifact.getMetadata().get(SCM_ID));
+            final String value = artifact.getMetadata().get(SCM_ID);
+            for (final String id : value.split(",")) {
+                final ArtifactId sourcesArtifactId = ArtifactId.parse(id);
+                downloadSourceAndDeflate(artifactProvider, sourcesArtifactId, deflatedSourcesDir, exportPackageIncludes,
+                        artifactId, false);
+            }
         } else {
-            sourcesArtifactId = newArtifacId(artifactId,
+            final ArtifactId sourcesArtifactId = newArtifacId(artifactId,
                                                     "sources",
                                                     "jar");
-        }
-
-        boolean fallback = false;
-        try {
-            final URL url = retrieve(artifactProvider, sourcesArtifactId);
-            if (url != null) {
-                File sourcesBundle = IOUtils.getFileFromURL(url, true, null);
-                deflate(deflatedSourcesDir, sourcesBundle, exportPackageIncludes);
-            } else {
-                getLog().warn("Impossible to download sources for " + artifactId.toMvnId() + " due to missing artifact "
-                        + sourcesArtifactId.toMvnId() + ", trying source checkout next...");
-                fallback = true;
-            }
-        } catch (Throwable t) {
-            getLog().warn("Impossible to download sources for " + artifactId.toMvnId() + " from "
-                    + sourcesArtifactId.toMvnId()
-                          + " due to "
-                          + t.getMessage()
-                    + ", trying source checkout next...");
-            fallback = true;
+            fallback = downloadSourceAndDeflate(artifactProvider, sourcesArtifactId, deflatedSourcesDir,
+                    exportPackageIncludes, artifactId, true);
         }
 
         if (fallback) {