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.tasks.diagnostics;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.StringUtils;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Incubating;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.result.DependencyResult;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.artifacts.result.ResolvedVariantResult;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeContainer;
import org.gradle.api.attributes.HasAttributes;
import org.gradle.api.internal.artifacts.ResolverResults;
import org.gradle.api.internal.artifacts.configurations.ConfigurationInternal;
import org.gradle.api.internal.artifacts.configurations.ResolutionResultProvider;
import org.gradle.api.internal.artifacts.configurations.ResolvableDependenciesInternal;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionComparator;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionParser;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelectorScheme;
import org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.results.VisitedGraphResults;
import org.gradle.api.internal.artifacts.resolver.ResolutionOutputsInternal;
import org.gradle.api.internal.attributes.AttributeContainerInternal;
import org.gradle.api.internal.attributes.ImmutableAttributesFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.diagnostics.internal.ConfigurationFinder;
import org.gradle.api.tasks.diagnostics.internal.dependencies.AttributeMatchDetails;
import org.gradle.api.tasks.diagnostics.internal.dependencies.MatchType;
import org.gradle.api.tasks.diagnostics.internal.dsl.DependencyResultSpecNotationConverter;
import org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphsRenderer;
import org.gradle.api.tasks.diagnostics.internal.graph.NodeRenderer;
import org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency;
import org.gradle.api.tasks.diagnostics.internal.graph.nodes.Section;
import org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter;
import org.gradle.api.tasks.diagnostics.internal.text.StyledTable;
import org.gradle.api.tasks.options.Option;
import org.gradle.initialization.StartParameterBuildOptions;
import org.gradle.internal.graph.GraphRenderer;
import org.gradle.internal.instrumentation.api.annotations.ToBeReplacedByLazyProperty;
import org.gradle.internal.logging.text.StyledTextOutput;
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import org.gradle.internal.typeconversion.NotationParser;
import org.gradle.work.DisableCachingByDefault;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Description;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Failure;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Header;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Identifier;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Info;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Normal;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.UserInput;
/**
* Generates a report that attempts to answer questions like:
*
*
Why is this dependency in the dependency graph?
*
Exactly which dependencies are pulling this dependency into the graph?
*
What is the actual version (i.e. *selected* version) of the dependency that will be used? Is it the same as what was *requested*?
*
Why is the *selected* version of a dependency different to the *requested*?
*
What variants are available for this dependency?
*
*
* Use this task to get insight into a particular dependency (or dependencies)
* and find out what exactly happens during dependency resolution and conflict resolution.
* If the dependency version was forced or selected by the conflict resolution
* this information will be available in the report.
*
* While the regular dependencies report ({@link DependencyReportTask}) shows the path from the top level dependencies down through the transitive dependencies,
* the dependency insight report shows the path from a particular dependency to the dependencies that pulled it in.
* That is, it is an inverted view of the regular dependencies report.
*
* The task requires setting the dependency spec and the configuration.
* For more information on how to configure those please refer to docs for {@link #setDependencySpec(Object)} and
* {@link #setConfiguration(String)}.
*
* The task can also be configured from the command line.
* For more information please refer to {@link #setDependencySpec(Object)}, {@link #setConfiguration(String)},
* {@link #setShowSinglePathToDependency(boolean)}, and {@link #getShowingAllVariants()}.
*/
@DisableCachingByDefault(because = "Produces only non-cacheable console output")
public abstract class DependencyInsightReportTask extends DefaultTask {
private Spec dependencySpec;
private boolean showSinglePathToDependency;
private final Property showingAllVariants = getProject().getObjects().property(Boolean.class);
private transient Configuration configuration;
private final Property rootComponentProperty = getProject().getObjects().property(ResolvedComponentResult.class);
// this field is named with a starting `z` to be serialized after `rootComponentProperty`
// because the serialization of `rootComponentProperty` can still trigger callback that can affect
// a value of `configuration.getAttributes()`.
// TODO:configuration-cache find a way to clean up this #23732
private Provider zConfigurationAttributes;
private ResolutionErrorRenderer errorHandler;
private String configurationName;
private String configurationDescription;
/**
* The root component of the dependency graph to be inspected.
*
* @since 7.5
*/
@Input
@Optional
@Incubating
public Property getRootComponentProperty() {
// Required to maintain DslObject mapping
Configuration configuration = getConfiguration();
if (!rootComponentProperty.isPresent() && configuration != null && getDependencySpec() != null) {
if (getShowingAllVariants().get()) {
ConfigurationInternal configurationInternal = (ConfigurationInternal) configuration;
if (!configurationInternal.isCanBeMutated()) {
throw new IllegalStateException(
"The configuration '" + configuration.getName() + "' is not mutable. " +
"In order to use the '--all-variants' option, the configuration must not be resolved before this task is executed."
);
}
configurationInternal.getResolutionStrategy().setIncludeAllSelectableVariantResults(true);
}
configurationName = configuration.getName();
configurationDescription = configuration.toString();
zConfigurationAttributes = getProject().provider(configuration::getAttributes);
ProviderFactory providerFactory = getProject().getProviders();
ResolutionOutputsInternal resolutionOutputs = ((ResolvableDependenciesInternal) configuration.getIncoming()).getResolutionOutputs();
ResolutionResultProvider graphResultsProvider = resolutionOutputs.getRawResults().map(ResolverResults::getVisitedGraph);
errorHandler.addErrorSource(providerFactory.provider(() ->
graphResultsProvider.getValue().getResolutionFailure()
.map(Collections::singletonList)
.orElse(Collections.emptyList()))
);
rootComponentProperty.set(providerFactory.provider(() -> {
// We do not use the public resolution result API to avoid throwing exceptions that we visit above
return graphResultsProvider.getValue().getResolutionResult().getRootSource().get();
}));
}
return rootComponentProperty;
}
/**
* Selects the dependency (or dependencies if multiple matches found) to show the report for.
*/
@Internal
@ToBeReplacedByLazyProperty(comment = "Should Spec> be lazy?")
public @Nullable Spec getDependencySpec() {
return dependencySpec;
}
/**
* The dependency spec selects the dependency (or dependencies if multiple matches found) to show the report for.
* The spec receives an instance of {@link DependencyResult} as parameter.
*/
public void setDependencySpec(@Nullable Spec dependencySpec) {
this.dependencySpec = dependencySpec;
this.errorHandler = new ResolutionErrorRenderer(dependencySpec);
}
/**
* Configures the dependency to show the report for.
* Multiple notation formats are supported: Strings, instances of {@link Spec}
* and groovy closures. Spec and closure receive {@link DependencyResult} as parameter.
* Examples of String notation: 'org.slf4j:slf4j-api', 'slf4j-api', or simply: 'slf4j'.
* The input may potentially match multiple dependencies.
* See also {@link #setDependencySpec(Spec)}
*
* This method is exposed to the command line interface. Example usage:
*
gradle dependencyInsight --dependency slf4j
*/
@Option(option = "dependency", description = "Shows the details of given dependency.")
public void setDependencySpec(@Nullable Object dependencyInsightNotation) {
NotationParser