Repository: karaf Updated Branches: refs/heads/master c50929336 -> bc22e0b3b
[KARAF-4060] Throw an error when we remove a repo containing installed features Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/bc22e0b3 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/bc22e0b3 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/bc22e0b3 Branch: refs/heads/master Commit: bc22e0b3bed48a665f559a9ea5dd04914fbcb0b8 Parents: c509293 Author: Guillaume Nodet <[email protected]> Authored: Thu Nov 3 15:31:29 2016 +0100 Committer: Guillaume Nodet <[email protected]> Committed: Thu Nov 3 15:31:29 2016 +0100 ---------------------------------------------------------------------- .../internal/service/FeaturesServiceImpl.java | 34 ++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/bc22e0b3/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java index 090112f..aa4050d 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java @@ -473,8 +473,27 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public void removeRepository(URI uri, boolean uninstall) throws Exception { - // TODO: check we don't have any feature installed from this repository - Repository repo; + Repository repo = getRepository(uri); + if (repo == null) { + return; + } + + Set<String> features = new HashSet<>(); + synchronized (lock) { + for (Feature feature : repo.getFeatures()) { + if (isRequired(feature)) { + features.add(feature.getId()); + } + } + } + if (!features.isEmpty()) { + if (uninstall) { + uninstallFeatures(features, EnumSet.noneOf(Option.class)); + } else { + throw new IllegalStateException("The following features are required from the repository: " + String.join(", ", features)); + } + } + synchronized (lock) { // Remove repo if (!state.repositories.remove(uri.toString())) { @@ -495,18 +514,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } saveState(); } - if (repo == null) { - repo = new RepositoryImpl(uri, blacklisted); - } callListeners(new RepositoryEvent(repo, RepositoryEvent.EventType.RepositoryRemoved, false)); - // uninstall the features from the repository - if (uninstall) { - HashSet<String> features = new HashSet<>(); - for (Feature feature : repo.getFeatures()) { - features.add(feature.getName() + "/" + feature.getVersion()); - } - uninstallFeatures(features, EnumSet.noneOf(FeaturesService.Option.class)); - } } @Override
