org.gradle.api.internalivyservice.ivyresolve.ComponentSelectionRulesProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 5.5.1 API redistribution.
/*
* Copyright 2014 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.artifacts.ivyservice.ivyresolve;
import org.gradle.api.InvalidUserCodeException;
import org.gradle.api.artifacts.ComponentMetadata;
import org.gradle.api.artifacts.ComponentSelection;
import org.gradle.api.artifacts.ivy.IvyModuleDescriptor;
import org.gradle.api.internal.artifacts.ComponentSelectionInternal;
import org.gradle.api.specs.Spec;
import org.gradle.api.specs.Specs;
import org.gradle.internal.rules.SpecRuleAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class ComponentSelectionRulesProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(ComponentSelectionRulesProcessor.class);
private final Spec> withNoInputs = new Spec>() {
public boolean isSatisfiedBy(SpecRuleAction element) {
return element.getAction().getInputTypes().isEmpty();
}
};
private final Spec> withInputs = Specs.negate(withNoInputs);
void apply(ComponentSelectionInternal selection, Collection> specRuleActions, MetadataProvider metadataProvider) {
if (processRules(specRuleActions, withNoInputs, selection, metadataProvider)) {
processRules(specRuleActions, withInputs, selection, metadataProvider);
}
}
private boolean processRules(Collection> specRuleActions, Spec> filter, ComponentSelectionInternal selection, MetadataProvider metadataProvider) {
for (SpecRuleAction rule : specRuleActions) {
if (filter.isSatisfiedBy(rule)) {
processRule(rule, selection, metadataProvider);
if (selection.isRejected()) {
LOGGER.info("Selection of {} rejected by component selection rule: {}", selection.getCandidate().getDisplayName(), selection.getRejectionReason());
return false;
}
}
}
return true;
}
private void processRule(SpecRuleAction rule, ComponentSelection selection, MetadataProvider metadataProvider) {
if (!rule.getSpec().isSatisfiedBy(selection)) {
return;
}
List