use of java.util.EnumSet in project karaf by apache.
the class FeaturesServiceImpl method uninstallFeatures.
@Override
public void uninstallFeatures(Set<String> features, String region, EnumSet<Option> options) throws Exception {
State state = copyState();
Map<String, Set<String>> required = copy(state.requirements);
if (region == null || region.isEmpty()) {
region = ROOT_REGION;
}
Set<String> fl = required.computeIfAbsent(region, k -> new HashSet<>());
List<String> featuresToRemove = new ArrayList<>();
for (String feature : new HashSet<>(features)) {
List<String> toRemove = new ArrayList<>();
feature = normalize(feature);
if (feature.endsWith("/0.0.0")) {
// Match only on name
String nameSep = FEATURE_OSGI_REQUIREMENT_PREFIX + feature.substring(0, feature.indexOf(VERSION_SEPARATOR) + 1);
for (String f : fl) {
Pattern pattern = Pattern.compile(nameSep.substring(0, nameSep.length() - 1));
Matcher matcher = pattern.matcher(f);
if (matcher.matches() || normalize(f).startsWith(nameSep)) {
toRemove.add(f);
}
}
} else {
// Match on name and version
String name = feature.substring(0, feature.indexOf(VERSION_SEPARATOR));
String version = feature.substring(feature.indexOf(VERSION_SEPARATOR) + 1);
Pattern pattern = getFeaturePattern(name, version);
for (String f : fl) {
Matcher matcher = pattern.matcher(f);
if (matcher.matches()) {
toRemove.add(f);
}
}
}
toRemove.retainAll(fl);
if (toRemove.isEmpty()) {
throw new IllegalArgumentException("Feature named '" + feature + "' is not installed");
}
featuresToRemove.addAll(toRemove);
}
featuresToRemove = new ArrayList<>(new LinkedHashSet<>(featuresToRemove));
print("Removing features: " + join(featuresToRemove), options.contains(Option.Verbose));
fl.removeAll(featuresToRemove);
if (fl.isEmpty()) {
required.remove(region);
}
Map<String, Map<String, FeatureState>> stateChanges = Collections.emptyMap();
doProvisionInThread(required, stateChanges, state, options);
}
use of java.util.EnumSet in project karaf by apache.
the class FeaturesServiceImpl method checkResolve.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void checkResolve() {
File resolveFile = installSupport.getDataFile(RESOLVE_FILE);
if (resolveFile == null || !resolveFile.exists()) {
return;
}
Map<String, Object> request;
try (FileInputStream fis = new FileInputStream(resolveFile)) {
request = (Map<String, Object>) JsonReader.read(fis);
} catch (IOException e) {
LOGGER.warn("Error reading resolution request", e);
return;
}
Map<String, Set<String>> requestedFeatures = toStringStringSetMap((Map) request.get("features"));
Collection<String> opts = (Collection<String>) request.get("options");
EnumSet<Option> options = EnumSet.noneOf(Option.class);
for (String opt : opts) {
options.add(Option.valueOf(opt));
}
// Resolve
try {
Map<String, Map<String, FeatureState>> stateChanges = Collections.emptyMap();
doProvisionInThread(requestedFeatures, stateChanges, copyState(), options);
} catch (Exception e) {
LOGGER.warn("Error updating state", e);
}
}
use of java.util.EnumSet in project karaf by apache.
the class FeaturesServiceImpl method addRequirements.
@Override
public void addRequirements(Map<String, Set<String>> requirements, EnumSet<Option> options) throws Exception {
State state = copyState();
Map<String, Set<String>> required = copy(state.requirements);
add(required, requirements);
Map<String, Map<String, FeatureState>> stateChanges = Collections.emptyMap();
doProvisionInThread(required, stateChanges, state, options);
}
Aggregations