karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [karaf] branch karaf-4.2.x updated: [KARAF-6183] Fix override for classified artifacts.
Date Wed, 06 Mar 2019 17:47:46 GMT
This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new 1d14e58  [KARAF-6183] Fix override for classified artifacts.
1d14e58 is described below

commit 1d14e58349e3853dce15a4441bd866a17c0513ed
Author: Daniel Estermann <d.estermann@seeburger.de>
AuthorDate: Tue Mar 5 17:34:05 2019 +0100

    [KARAF-6183] Fix override for classified artifacts.
    
    We take now the pattern from override.properties, which
    matches best (i.e. has the biggest length), not the last one
---
 .../internal/service/FeaturesProcessorImpl.java    | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
index 518401e..6b759d8 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
@@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
@@ -220,20 +221,24 @@ public class FeaturesProcessorImpl implements FeaturesProcessor {
     private void staticOverrideBundle(Bundle bundle) {
         bundle.setOverriden(BundleInfo.BundleOverrideMode.NONE);
 
+        String originalLocation = bundle.getLocation();
+        final List<BundleReplacements.OverrideBundle> candidates = new ArrayList<>();
         for (BundleReplacements.OverrideBundle override : this.getInstructions().getBundleReplacements().getOverrideBundles())
{
-            String originalLocation = bundle.getLocation();
             if (override.getOriginalUriPattern().matches(originalLocation)) {
-                LOG.debug("Overriding bundle location \"" + originalLocation + "\" with \""
+ override.getReplacement() + "\"");
-                bundle.setOriginalLocation(originalLocation);
-                if (override.getMode() == BundleReplacements.BundleOverrideMode.MAVEN) {
-                    bundle.setOverriden(BundleInfo.BundleOverrideMode.MAVEN);
-                } else {
-                    bundle.setOverriden(BundleInfo.BundleOverrideMode.OSGI);
-                }
-                bundle.setLocation(override.getReplacement());
-                // TOCHECK: last rule wins - no break!!!
-                //break;
+                candidates.add(override);
+            }
+        }
+        if (!candidates.isEmpty()) {
+            BundleReplacements.OverrideBundle bestMatch = candidates.stream()
+                    .max((o1, o2) -> Integer.compare(o1.getReplacement().length(), o2.getReplacement().length())).get();
+            LOG.debug("Overriding bundle location \"" + originalLocation + "\" with \"" +
bestMatch.getReplacement() + "\"");
+            bundle.setOriginalLocation(originalLocation);
+            if (bestMatch.getMode() == BundleReplacements.BundleOverrideMode.MAVEN) {
+                bundle.setOverriden(BundleInfo.BundleOverrideMode.MAVEN);
+            } else {
+                bundle.setOverriden(BundleInfo.BundleOverrideMode.OSGI);
             }
+            bundle.setLocation(bestMatch.getReplacement());
         }
     }
 


Mime
View raw message