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 2018/11/13 13:17:05 UTC

[sling-slingfeature-maven-plugin] branch master updated: Use raw features for version updates and replace artifact at the same place instead of adding a new one at the end

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 2937389  Use raw features for version updates and replace artifact at the same place instead of adding a new one at the end
2937389 is described below

commit 293738940cd51df39ce525242625b94be27939d0
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Nov 13 14:16:56 2018 +0100

    Use raw features for version updates and replace artifact at the same place instead of adding a new one at the end
---
 .../sling/feature/maven/mojos/UpdateVersionsMojo.java    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
index 57af3ed..9107c3d 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
@@ -164,11 +164,16 @@ public class UpdateVersionsMojo extends AbstractIncludingFeatureMojo {
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         // get the features
-        final Map<String, Feature> features = this.getFeatures();
-        if (features.isEmpty()) {
+        final Map<String, Feature> assembledFeatures = this.getFeatures();
+        if (assembledFeatures.isEmpty()) {
             throw new MojoExecutionException("No features found in project!");
         }
 
+        final Map<String, Feature> features = new HashMap<>();
+        for (final Map.Entry<String, Feature> entry : assembledFeatures.entrySet()) {
+            features.put(entry.getKey(), ProjectHelper.getFeatures(project).get(entry.getKey()));
+        }
+
         // create config
         final UpdateConfig cfg = new UpdateConfig();
 
@@ -500,6 +505,7 @@ public class UpdateVersionsMojo extends AbstractIncludingFeatureMojo {
             } else {
                 container = rawFeature.getExtensions().getByName(update.extension.getName()).getArtifacts();
             }
+            final int pos = container.indexOf(update.artifact);
             if (!container.removeExact(update.artifact.getId())) {
                 // check if property is used
                 final Artifact same = container.getSame(update.artifact.getId());
@@ -529,12 +535,14 @@ public class UpdateVersionsMojo extends AbstractIncludingFeatureMojo {
                 }
                 iter.remove();
             } else {
-
+                if (pos == -1) {
+                    throw new MojoExecutionException("MIST " + update.artifact.getId().toMvnId());
+                }
                 final Artifact newArtifact = new Artifact(new ArtifactId(update.artifact.getId().getGroupId(),
                         update.artifact.getId().getArtifactId(), update.newVersion,
                         update.artifact.getId().getClassifier(), update.artifact.getId().getType()));
                 newArtifact.getMetadata().putAll(update.artifact.getMetadata());
-                container.add(newArtifact);
+                container.add(pos, newArtifact);
             }
         }