in features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRemoveCommand.java [68:151]
protected Object doExecute() throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
if (group == null) {
System.err.println("Cluster group " + groupName + " doesn't exist");
return null;
}
// check if the event producer is ON
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
System.err.println("Cluster event producer is OFF");
return null;
}
// get the features repositories in the cluster group
Map<String, String> clusterRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName);
// get the features in the cluster group
Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + groupName);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
List<String> urls = new ArrayList<String>();
Pattern pattern = Pattern.compile(repository);
for (String repositoryUrl : clusterRepositories.keySet()) {
String repositoryName = clusterRepositories.get(repositoryUrl);
if (repositoryName != null && !repositoryName.isEmpty()) {
// repository has name, try regex on the name
Matcher nameMatcher = pattern.matcher(repositoryName);
if (nameMatcher.matches()) {
urls.add(repositoryUrl);
} else {
// the name regex doesn't match, fallback to repository URI regex
Matcher uriMatcher = pattern.matcher(repositoryUrl);
if (uriMatcher.matches()) {
urls.add(repositoryUrl);
}
}
} else {
// the repository name is not defined, use repository URI regex
Matcher uriMatcher = pattern.matcher(repositoryUrl);
if (uriMatcher.matches()) {
urls.add(repositoryUrl);
}
}
}
for (String url : urls) {
// looking for the URL in the list
boolean found = false;
for (String repository : clusterRepositories.keySet()) {
if (this.repository.equals(url)) {
found = true;
break;
}
}
if (found) {
Features repositoryModel = JaxbUtil.unmarshal(url, true);
// update the features repositories in the cluster group
clusterRepositories.remove(url);
// update the features in the cluster group
for (Feature feature : repositoryModel.getFeature()) {
clusterFeatures.remove(feature.getName() + "/" + feature.getVersion());
}
// broadcast a cluster event
ClusterRepositoryEvent event = new ClusterRepositoryEvent(url, RepositoryEvent.EventType.RepositoryRemoved);
event.setUninstall(uninstall);
event.setSourceGroup(group);
event.setSourceNode(clusterManager.getNode());
eventProducer.produce(event);
} else {
System.err.println("Features repository URL " + url + " not found in cluster group " + groupName);
}
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
return null;
}