Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.internal.component.model;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.gradle.api.GradleException;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeContainer;
import org.gradle.api.attributes.AttributeMatchingStrategy;
import org.gradle.api.attributes.AttributesSchema;
import org.gradle.api.attributes.CompatibilityCheckDetails;
import org.gradle.api.attributes.HasAttributes;
import org.gradle.api.attributes.MultipleCandidatesDetails;
import org.gradle.api.internal.attributes.AttributeValue;
import org.gradle.api.internal.attributes.AttributesSchemaInternal;
import org.gradle.api.internal.attributes.CompatibilityRuleChainInternal;
import org.gradle.api.internal.attributes.DisambiguationRuleChainInternal;
import org.gradle.internal.Cast;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ComponentAttributeMatcher {
private final boolean ignoreAdditionalProducerAttributes;
private final boolean ignoreAdditionalConsumerAttributes;
public ComponentAttributeMatcher() {
this(false, false);
}
private ComponentAttributeMatcher(boolean ignoreAdditionalProducerAttributes, boolean ignoreAdditionalConsumerAttributes) {
this.ignoreAdditionalProducerAttributes = ignoreAdditionalProducerAttributes;
this.ignoreAdditionalConsumerAttributes = ignoreAdditionalConsumerAttributes;
}
public ComponentAttributeMatcher ignoreAdditionalProducerAttributes() {
return new ComponentAttributeMatcher(true, ignoreAdditionalConsumerAttributes);
}
public ComponentAttributeMatcher ignoreAdditionalConsumerAttributes() {
return new ComponentAttributeMatcher(ignoreAdditionalProducerAttributes, true);
}
/**
* Determines whether the given candidate is compatible with the requested criteria, according to the given schema.
*/
public boolean isMatching(AttributesSchemaInternal schema, AttributeContainer candidate, AttributeContainer requested) {
MatchDetails details = new MatchDetails();
doMatchCandidate(schema, schema, candidate, requested, details);
return details.compatible;
}
/**
* Selects the candidates from the given set that are compatible with the requested criteria, according to the given schema.
*/
public List match(AttributesSchemaInternal consumerAttributeSchema, AttributesSchemaInternal producerAttributeSchema, List candidates, AttributeContainer requested) {
return new Matcher(consumerAttributeSchema, producerAttributeSchema, candidates, requested).getMatches();
}
private void doMatchCandidate(AttributesSchemaInternal consumerAttributeSchema, AttributesSchemaInternal producerAttributeSchema,
HasAttributes candidate, AttributeContainer requested, MatchDetails details) {
Set> requestedAttributes = Cast.uncheckedCast(requested.keySet());
AttributeContainer candidateAttributesContainer = candidate.getAttributes();
Set> candidateAttributes = Cast.uncheckedCast(candidateAttributesContainer.keySet());
Set> allAttributes = Sets.union(requestedAttributes, candidateAttributes);
for (Attribute