Search in sources :

Example 26 with EnumSet

use of java.util.EnumSet in project kotlin by JetBrains.

the class LintDriver method computeRepeatingDetectors.

private void computeRepeatingDetectors(List<Detector> detectors, Project project) {
    // Ensure that the current visitor is recomputed
    mCurrentFolderType = null;
    mCurrentVisitor = null;
    mCurrentXmlDetectors = null;
    mCurrentBinaryDetectors = null;
    // Create map from detector class to issue such that we can
    // compute applicable issues for each detector in the list of detectors
    // to be repeated
    List<Issue> issues = mRegistry.getIssues();
    Multimap<Class<? extends Detector>, Issue> issueMap = ArrayListMultimap.create(issues.size(), 3);
    for (Issue issue : issues) {
        issueMap.put(issue.getImplementation().getDetectorClass(), issue);
    }
    Map<Class<? extends Detector>, EnumSet<Scope>> detectorToScope = new HashMap<Class<? extends Detector>, EnumSet<Scope>>();
    Map<Scope, List<Detector>> scopeToDetectors = new EnumMap<Scope, List<Detector>>(Scope.class);
    List<Detector> detectorList = new ArrayList<Detector>();
    // Compute the list of detectors (narrowed down from mRepeatingDetectors),
    // and simultaneously build up the detectorToScope map which tracks
    // the scopes each detector is affected by (this is used to populate
    // the mScopeDetectors map which is used during iteration).
    Configuration configuration = project.getConfiguration(this);
    for (Detector detector : detectors) {
        Class<? extends Detector> detectorClass = detector.getClass();
        Collection<Issue> detectorIssues = issueMap.get(detectorClass);
        if (detectorIssues != null) {
            boolean add = false;
            for (Issue issue : detectorIssues) {
                // the detector is enabled here.
                if (!configuration.isEnabled(issue)) {
                    continue;
                }
                // Include detector if any of its issues are enabled
                add = true;
                EnumSet<Scope> s = detectorToScope.get(detectorClass);
                EnumSet<Scope> issueScope = issue.getImplementation().getScope();
                if (s == null) {
                    detectorToScope.put(detectorClass, issueScope);
                } else if (!s.containsAll(issueScope)) {
                    EnumSet<Scope> union = EnumSet.copyOf(s);
                    union.addAll(issueScope);
                    detectorToScope.put(detectorClass, union);
                }
            }
            if (add) {
                detectorList.add(detector);
                EnumSet<Scope> union = detectorToScope.get(detector.getClass());
                for (Scope s : union) {
                    List<Detector> list = scopeToDetectors.get(s);
                    if (list == null) {
                        list = new ArrayList<Detector>();
                        scopeToDetectors.put(s, list);
                    }
                    list.add(detector);
                }
            }
        }
    }
    mApplicableDetectors = detectorList;
    mScopeDetectors = scopeToDetectors;
    mRepeatingDetectors = null;
    mRepeatScope = null;
    validateScopeList();
}
Also used : Issue(com.android.tools.klint.detector.api.Issue) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList) ResourceXmlDetector(com.android.tools.klint.detector.api.ResourceXmlDetector) Detector(com.android.tools.klint.detector.api.Detector) Scope(com.android.tools.klint.detector.api.Scope) LintUtils.isAnonymousClass(com.android.tools.klint.detector.api.LintUtils.isAnonymousClass) PsiModifierList(com.intellij.psi.PsiModifierList) InsnList(org.jetbrains.org.objectweb.asm.tree.InsnList) ArrayList(java.util.ArrayList) PsiAnnotationParameterList(com.intellij.psi.PsiAnnotationParameterList) List(java.util.List) EnumMap(java.util.EnumMap)

Example 27 with EnumSet

use of java.util.EnumSet in project karaf by apache.

the class FeaturesServiceImpl method removeRequirements.

@Override
public void removeRequirements(Map<String, Set<String>> requirements, EnumSet<Option> options) throws Exception {
    State state = copyState();
    Map<String, Set<String>> required = copy(state.requirements);
    remove(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)

Example 28 with EnumSet

use of java.util.EnumSet in project karaf by apache.

the class FeaturesServiceImpl method installFeatures.

@Override
public void installFeatures(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<>());
    Map<String, Map<String, Feature>> allFeatures = getFeatures();
    List<String> featuresToAdd = new ArrayList<>();
    List<String> featuresToRemove = new ArrayList<>();
    for (String feature : features) {
        feature = normalize(feature);
        String name = feature.substring(0, feature.indexOf(VERSION_SEPARATOR));
        String version = feature.substring(feature.indexOf(VERSION_SEPARATOR) + 1);
        Pattern pattern = Pattern.compile(name);
        boolean matched = false;
        for (String fKey : allFeatures.keySet()) {
            Matcher matcher = pattern.matcher(fKey);
            if (matcher.matches()) {
                Feature f = getFeatureMatching(allFeatures.get(fKey), version);
                if (f != null) {
                    String req = getFeatureRequirement(f);
                    featuresToAdd.add(req);
                    Feature[] installedFeatures = listInstalledFeatures();
                    for (Feature installedFeature : installedFeatures) {
                        if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) {
                            LOGGER.info("The specified feature: '{}' version '{}' {}", f.getName(), f.getVersion(), f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded" : "is already installed");
                        }
                    }
                    matched = true;
                }
            }
        }
        if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) {
            throw new IllegalArgumentException("No matching features for " + feature);
        }
        if (options.contains(Option.Upgrade)) {
            for (String existentFeatureReq : fl) {
                //remove requirement prefix feature:
                String existentFeature = existentFeatureReq.substring(FEATURE_OSGI_REQUIREMENT_PREFIX.length());
                if (existentFeature.startsWith(name + VERSION_SEPARATOR) && !featuresToAdd.contains(existentFeature)) {
                    featuresToRemove.add(existentFeature);
                //do not break cycle to remove all old versions of feature
                }
            }
        }
    }
    if (!featuresToRemove.isEmpty()) {
        print("Removing features: " + join(featuresToRemove), options.contains(Option.Verbose));
        for (String featureReq : featuresToRemove) {
            fl.remove(FEATURE_OSGI_REQUIREMENT_PREFIX + featureReq);
        }
    }
    featuresToAdd = new ArrayList<>(new LinkedHashSet<>(featuresToAdd));
    print("Adding features: " + join(featuresToAdd), options.contains(Option.Verbose));
    for (String feature : featuresToAdd) {
        fl.add(FEATURE_OSGI_REQUIREMENT_PREFIX + feature);
    }
    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) Feature(org.apache.karaf.features.Feature) 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)

Example 29 with EnumSet

use of java.util.EnumSet in project wildfly by wildfly.

the class SecuritySubsystemParser method parseIdentityTrust.

private void parseIdentityTrust(List<ModelNode> list, PathAddress parentAddress, XMLExtendedStreamReader reader) throws XMLStreamException {
    requireNoAttributes(reader);
    PathAddress address = parentAddress.append(IDENTITY_TRUST, CLASSIC);
    ModelNode op = Util.createAddOperation(address);
    list.add(op);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case TRUST_MODULE:
                {
                    EnumSet<Attribute> required = EnumSet.of(Attribute.CODE, Attribute.FLAG);
                    EnumSet<Attribute> notAllowed = EnumSet.of(Attribute.TYPE, Attribute.LOGIN_MODULE_STACK_REF);
                    parseCommonModule(reader, address, TRUST_MODULE, required, notAllowed, list);
                    break;
                }
            default:
                {
                    throw unexpectedElement(reader);
                }
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) EnumSet(java.util.EnumSet) ModelNode(org.jboss.dmr.ModelNode)

Example 30 with EnumSet

use of java.util.EnumSet in project wildfly by wildfly.

the class JacORBSubsystemParser method parsePOAConfig.

/**
     * <p>
     * Parses the {@code poa} section of the JacORB subsystem configuration.
     * </p>
     *
     * @param namespace the expected {@code Namespace} of the parsed elements.
     * @param reader the {@code XMLExtendedStreamReader} used to read the configuration XML.
     * @param node   the {@code ModelNode} that will hold the parsed POA configuration.
     * @throws javax.xml.stream.XMLStreamException
     *          if an error occurs while parsing the XML.
     */
private void parsePOAConfig(Namespace namespace, XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
    // parse the poa config attributes.
    EnumSet<Attribute> expectedAttributes = EnumSet.of(Attribute.POA_MONITORING, Attribute.POA_QUEUE_WAIT, Attribute.POA_QUEUE_MIN, Attribute.POA_QUEUE_MAX);
    this.parseAttributes(reader, node, expectedAttributes, null);
    // parse the poa config elements.
    EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        // check the element namespace.
        if (namespace != Namespace.forUri(reader.getNamespaceURI()))
            throw unexpectedElement(reader);
        final Element element = Element.forName(reader.getLocalName());
        // check for duplicate elements.
        if (!encountered.add(element)) {
            throw duplicateNamedElement(reader, element.getLocalName());
        }
        switch(element) {
            case POA_REQUEST_PROC:
                {
                    // parse the poa request-processors config attributes.
                    EnumSet<Attribute> attributes = EnumSet.of(Attribute.POA_REQUEST_PROC_POOL_SIZE, Attribute.POA_REQUEST_PROC_MAX_THREADS);
                    this.parseAttributes(reader, node, attributes, null);
                    // the request-processors element doesn't have child elements.
                    requireNoContent(reader);
                    break;
                }
            default:
                {
                    throw unexpectedElement(reader);
                }
        }
    }
}
Also used : ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.duplicateAttribute(org.jboss.as.controller.parsing.ParseUtils.duplicateAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) ParseUtils.duplicateNamedElement(org.jboss.as.controller.parsing.ParseUtils.duplicateNamedElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) EnumSet(java.util.EnumSet)

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