Search in sources :

Example 56 with EnumSet

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Pattern(java.util.regex.Pattern) EnumSet(java.util.EnumSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) FeatureState(org.apache.karaf.features.FeatureState) StateStorage.toStringStringSetMap(org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 57 with EnumSet

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);
    }
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Collection(java.util.Collection) File(java.io.File) StateStorage.toStringStringSetMap(org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 58 with EnumSet

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);
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FeatureState(org.apache.karaf.features.FeatureState) StateStorage.toStringStringSetMap(org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

EnumSet (java.util.EnumSet)58 Set (java.util.Set)18 Map (java.util.Map)16 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 TreeSet (java.util.TreeSet)7 Test (org.junit.Test)7 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 List (java.util.List)5 TreeMap (java.util.TreeMap)5 StateStorage.toStringStringSetMap (org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap)5 PathAddress (org.jboss.as.controller.PathAddress)5 PathElement (org.jboss.as.controller.PathElement)5 ModelNode (org.jboss.dmr.ModelNode)5 FeatureState (org.apache.karaf.features.FeatureState)4 Nullable (com.android.annotations.Nullable)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2