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();
}
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);
}
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);
}
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);
}
}
}
}
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);
}
}
}
}
Aggregations