Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9A7ED200D36 for ; Mon, 6 Nov 2017 19:55:55 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 98DBA160BEC; Mon, 6 Nov 2017 18:55:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B7B1B160BD5 for ; Mon, 6 Nov 2017 19:55:54 +0100 (CET) Received: (qmail 40793 invoked by uid 500); 6 Nov 2017 18:55:53 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 40783 invoked by uid 99); 6 Nov 2017 18:55:53 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Nov 2017 18:55:53 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 5A2B1806C3; Mon, 6 Nov 2017 18:55:53 +0000 (UTC) Date: Mon, 06 Nov 2017 18:55:53 +0000 To: "commits@karaf.apache.org" Subject: [karaf] branch karaf-4.1.x updated: [KARAF-4756] Redeploying Features in the Deploy directory with install="auto" does not work for same feature versions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <150999455329.26809.10886902361755266350@gitbox.apache.org> From: gnodet@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: karaf X-Git-Refname: refs/heads/karaf-4.1.x X-Git-Reftype: branch X-Git-Oldrev: 72964341c13a717c51513ef508d679007f05b82e X-Git-Newrev: d9a0ec059506b0c06d0ba45d07b212ef978d9235 X-Git-Rev: d9a0ec059506b0c06d0ba45d07b212ef978d9235 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated archived-at: Mon, 06 Nov 2017 18:55:55 -0000 This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch karaf-4.1.x in repository https://gitbox.apache.org/repos/asf/karaf.git The following commit(s) were added to refs/heads/karaf-4.1.x by this push: new d9a0ec0 [KARAF-4756] Redeploying Features in the Deploy directory with install="auto" does not work for same feature versions d9a0ec0 is described below commit d9a0ec059506b0c06d0ba45d07b212ef978d9235 Author: Guillaume Nodet AuthorDate: Mon Nov 6 19:55:41 2017 +0100 [KARAF-4756] Redeploying Features in the Deploy directory with install="auto" does not work for same feature versions --- .../features/FeatureDeploymentListener.java | 86 +++++++++++----------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java b/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java index ab80236..feecad3 100644 --- a/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java +++ b/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java @@ -26,7 +26,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.EnumSet; import java.util.Enumeration; import java.util.HashSet; @@ -186,59 +185,60 @@ public class FeatureDeploymentListener implements ArtifactUrlTransformer, Bundle Bundle bundle = bundleEvent.getBundle(); if (bundleEvent.getType() == BundleEvent.RESOLVED) { try { - List urls = new ArrayList(); - Enumeration featuresUrlEnumeration = bundle.findEntries("/META-INF/" + FEATURE_PATH + "/", "*.xml", false); + List toAdd = new ArrayList<>(); + Enumeration featuresUrlEnumeration = bundle.findEntries("/META-INF/" + FEATURE_PATH + "/", "*.xml", false); while (featuresUrlEnumeration != null && featuresUrlEnumeration.hasMoreElements()) { - URL url = (URL) featuresUrlEnumeration.nextElement(); - try { - featuresService.addRepository(url.toURI()); - URI needRemovedRepo = null; - for (Repository repo : featuresService.listRepositories()) { - if (repo.getURI().equals(url.toURI())) { - Set features = new HashSet(Arrays.asList(repo.getFeatures())); - Set autoInstallFeatures = new HashSet(); - for(Feature feature:features) { - if(feature.getInstall() != null && feature.getInstall().equals(Feature.DEFAULT_INSTALL_MODE)){ - if (!featuresService.isInstalled(feature)) { - autoInstallFeatures.add(feature.getId()); - } - } - } - if (!autoInstallFeatures.isEmpty()) { - featuresService.installFeatures(autoInstallFeatures, EnumSet.noneOf(FeaturesService.Option.class)); - } - } else { - //remove older out-of-data feature repo - if (repo.getURI().toString().contains(FEATURE_PATH)) { - String featureFileName = repo.getURI().toString(); - featureFileName = featureFileName.substring(featureFileName.lastIndexOf('/') + 1); - String newFeatureFileName = url.toURI().toString(); - newFeatureFileName = newFeatureFileName.substring(newFeatureFileName.lastIndexOf('/') + 1); - if (featureFileName.equals(newFeatureFileName)) { - needRemovedRepo = repo.getURI(); - } - } + URI uri = featuresUrlEnumeration.nextElement().toURI(); + toAdd.add(uri); + } + Set toRemove = new HashSet<>(); + synchronized (this) { + String prefix = bundle.getSymbolicName() + "-" + bundle.getVersion(); + String countStr = (String) properties.remove(prefix + ".count"); + if (countStr != null) { + int count = Integer.parseInt(countStr); + for (int i = 0; i < count; i++) { + URI uri = new URI((String) properties.remove(prefix + ".url." + i)); + if (!toAdd.contains(uri)) { + toRemove.add(featuresService.getRepository(uri)); } - } - urls.add(url); - if (needRemovedRepo != null) { - featuresService.removeRepository(needRemovedRepo); + } + } + if (toRemove.isEmpty() && toAdd.isEmpty()) { + return; + } + // Now add and remove repositories + try { + for (Repository repo : toRemove) { + featuresService.removeRepository(repo.getURI(), true); + } + Set featuresToInstall = new HashSet<>(); + for (URI uri : toAdd) { + featuresService.addRepository(uri, false); + Repository repo = featuresService.getRepository(uri); + for (Feature f : repo.getFeatures()) { + if (Feature.DEFAULT_INSTALL_MODE.equals(f.getInstall())) { + featuresToInstall.add(f.getId()); + } } - } catch (Exception e) { - logger.error("Unable to install features", e); } + if (!featuresToInstall.isEmpty()) { + featuresService.installFeatures(featuresToInstall, EnumSet.noneOf(FeaturesService.Option.class)); + } + } catch (Exception e) { + logger.error("Unable to install features", e); } synchronized (this) { String prefix = bundle.getSymbolicName() + "-" + bundle.getVersion(); String old = (String) properties.get(prefix + ".count"); - if (old != null && urls.isEmpty()) { + if (old != null && toAdd.isEmpty()) { properties.remove(prefix + ".count"); saveProperties(); - } else if (!urls.isEmpty()) { - properties.put(prefix + ".count", Integer.toString(urls.size())); - for (int i = 0; i < urls.size(); i++) { - properties.put(prefix + ".url." + i, urls.get(i).toExternalForm()); + } else if (!toAdd.isEmpty()) { + properties.put(prefix + ".count", Integer.toString(toAdd.size())); + for (int i = 0; i < toAdd.size(); i++) { + properties.put(prefix + ".url." + i, toAdd.get(i).toString()); } saveProperties(); } -- To stop receiving notification emails like this one, please contact ['"commits@karaf.apache.org" '].