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.api.internal.attributes;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.gradle.api.Action;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeMatchingStrategy;
import org.gradle.api.attributes.AttributesSchema;
import org.gradle.api.attributes.HasAttributes;
import org.gradle.internal.Cast;
import org.gradle.internal.component.model.AttributeMatcher;
import org.gradle.internal.component.model.AttributeMatchingExplanationBuilder;
import org.gradle.internal.component.model.AttributeSelectionSchema;
import org.gradle.internal.component.model.AttributeSelectionUtils;
import org.gradle.internal.component.model.ComponentAttributeMatcher;
import org.gradle.internal.component.model.DefaultCompatibilityCheckResult;
import org.gradle.internal.component.model.DefaultMultipleCandidateResult;
import org.gradle.internal.instantiation.InstantiatorFactory;
import org.gradle.internal.isolation.IsolatableFactory;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DefaultAttributesSchema implements AttributesSchemaInternal, AttributesSchema {
private final ComponentAttributeMatcher componentAttributeMatcher;
private final InstantiatorFactory instantiatorFactory;
private final Map, AttributeMatchingStrategy>> strategies = Maps.newHashMap();
private final Map> attributesByName = Maps.newHashMap();
private final DefaultAttributeMatcher matcher;
private final IsolatableFactory isolatableFactory;
private final Map[]> extraAttributesCache = Maps.newHashMap();
private final List consumerAttributeDescribers = Lists.newArrayList();
public DefaultAttributesSchema(ComponentAttributeMatcher componentAttributeMatcher, InstantiatorFactory instantiatorFactory, IsolatableFactory isolatableFactory) {
this.componentAttributeMatcher = componentAttributeMatcher;
this.instantiatorFactory = instantiatorFactory;
matcher = new DefaultAttributeMatcher(componentAttributeMatcher, mergeWith(EmptySchema.INSTANCE));
this.isolatableFactory = isolatableFactory;
}
@Override
public AttributeMatchingStrategy getMatchingStrategy(Attribute attribute) {
AttributeMatchingStrategy> strategy = strategies.get(attribute);
if (strategy == null) {
throw new IllegalArgumentException("Unable to find matching strategy for " + attribute);
}
return Cast.uncheckedCast(strategy);
}
@Override
public AttributeMatchingStrategy attribute(Attribute attribute) {
return attribute(attribute, null);
}
@Override
public AttributeMatchingStrategy attribute(Attribute attribute, Action super AttributeMatchingStrategy> configureAction) {
AttributeMatchingStrategy strategy = Cast.uncheckedCast(strategies.get(attribute));
if (strategy == null) {
strategy = Cast.uncheckedCast(instantiatorFactory.decorateLenient().newInstance(DefaultAttributeMatchingStrategy.class, instantiatorFactory, isolatableFactory));
strategies.put(attribute, strategy);
attributesByName.put(attribute.getName(), attribute);
}
if (configureAction != null) {
configureAction.execute(strategy);
}
return strategy;
}
@Override
public Set> getAttributes() {
return strategies.keySet();
}
@Override
public boolean hasAttribute(Attribute> key) {
return strategies.containsKey(key);
}
AttributeSelectionSchema mergeWith(AttributesSchemaInternal producerSchema) {
return new MergedSchema(producerSchema);
}
@Override
public AttributeMatcher withProducer(AttributesSchemaInternal producerSchema) {
return new DefaultAttributeMatcher(componentAttributeMatcher, mergeWith(producerSchema));
}
@Override
public AttributeMatcher matcher() {
return matcher;
}
@Override
public CompatibilityRule