use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class DefaultConfiguration method createCopy.
private DefaultConfiguration createCopy(Set<Dependency> dependencies, Set<DependencyConstraint> dependencyConstraints, boolean recursive) {
DetachedConfigurationsProvider configurationsProvider = new DetachedConfigurationsProvider();
RootComponentMetadataBuilder rootComponentMetadataBuilder = this.rootComponentMetadataBuilder.withConfigurationsProvider(configurationsProvider);
String newName = name + "Copy";
Factory<ResolutionStrategyInternal> childResolutionStrategy = resolutionStrategy != null ? Factories.constant(resolutionStrategy.copy()) : resolutionStrategyFactory;
DefaultConfiguration copiedConfiguration = instantiator.newInstance(DefaultConfiguration.class, domainObjectContext, newName, configurationsProvider, resolver, listenerManager, metaDataProvider, childResolutionStrategy, projectAccessListener, projectFinder, fileCollectionFactory, buildOperationExecutor, instantiator, artifactNotationParser, capabilityNotationParser, attributesFactory, rootComponentMetadataBuilder);
configurationsProvider.setTheOnlyConfiguration(copiedConfiguration);
// state, cachedResolvedConfiguration, and extendsFrom intentionally not copied - must re-resolve copy
// copying extendsFrom could mess up dependencies when copy was re-resolved
copiedConfiguration.visible = visible;
copiedConfiguration.transitive = transitive;
copiedConfiguration.description = description;
copiedConfiguration.defaultDependencyActions = defaultDependencyActions;
copiedConfiguration.dependencyResolutionListeners = dependencyResolutionListeners;
copiedConfiguration.canBeConsumed = canBeConsumed;
copiedConfiguration.canBeResolved = canBeResolved;
copiedConfiguration.getArtifacts().addAll(getAllArtifacts());
if (!configurationAttributes.isEmpty()) {
for (Attribute<?> attribute : configurationAttributes.keySet()) {
Object value = configurationAttributes.getAttribute(attribute);
copiedConfiguration.getAttributes().attribute(Cast.<Attribute<Object>>uncheckedCast(attribute), value);
}
}
// todo An ExcludeRule is a value object but we don't enforce immutability for DefaultExcludeRule as strong as we
// should (we expose the Map). We should provide a better API for ExcludeRule (I don't want to use unmodifiable Map).
// As soon as DefaultExcludeRule is truly immutable, we don't need to create a new instance of DefaultExcludeRule.
Set<Configuration> excludeRuleSources = new LinkedHashSet<Configuration>();
excludeRuleSources.add(this);
if (recursive) {
excludeRuleSources.addAll(getHierarchy());
}
for (Configuration excludeRuleSource : excludeRuleSources) {
for (ExcludeRule excludeRule : excludeRuleSource.getExcludeRules()) {
copiedConfiguration.excludeRules.add(new DefaultExcludeRule(excludeRule.getGroup(), excludeRule.getModule()));
}
}
DomainObjectSet<Dependency> copiedDependencies = copiedConfiguration.getDependencies();
for (Dependency dependency : dependencies) {
copiedDependencies.add(dependency.copy());
}
DomainObjectSet<DependencyConstraint> copiedDependencyConstraints = copiedConfiguration.getDependencyConstraints();
for (DependencyConstraint dependencyConstraint : dependencyConstraints) {
copiedDependencyConstraints.add(((DefaultDependencyConstraint) dependencyConstraint).copy());
}
return copiedConfiguration;
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class DefaultConfigurationContainer method detachedConfiguration.
public ConfigurationInternal detachedConfiguration(Dependency... dependencies) {
String name = DETACHED_CONFIGURATION_DEFAULT_NAME + detachedConfigurationDefaultNameCounter++;
DetachedConfigurationsProvider detachedConfigurationsProvider = new DetachedConfigurationsProvider();
DefaultConfiguration detachedConfiguration = instantiator.newInstance(DefaultConfiguration.class, context, name, detachedConfigurationsProvider, resolver, listenerManager, dependencyMetaDataProvider, resolutionStrategyFactory, projectAccessListener, projectFinder, fileCollectionFactory, buildOperationExecutor, instantiator, artifactNotationParser, capabilityNotationParser, attributesFactory, rootComponentMetadataBuilder.withConfigurationsProvider(detachedConfigurationsProvider));
DomainObjectSet<Dependency> detachedDependencies = detachedConfiguration.getDependencies();
for (Dependency dependency : dependencies) {
detachedDependencies.add(dependency.copy());
}
detachedConfigurationsProvider.setTheOnlyConfiguration(detachedConfiguration);
return detachedConfiguration;
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class TransientConfigurationResultsBuilder method deserialize.
private TransientConfigurationResults deserialize(Decoder decoder, ResolvedGraphResults graphResults, SelectedArtifactResults artifactResults, BuildOperationExecutor buildOperationProcessor) {
Timer clock = Time.startTimer();
Map<Long, DefaultResolvedDependency> allDependencies = new HashMap<Long, DefaultResolvedDependency>();
Map<Dependency, DependencyGraphNodeResult> firstLevelDependencies = new LinkedHashMap<Dependency, DependencyGraphNodeResult>();
DependencyGraphNodeResult root;
int valuesRead = 0;
byte type = -1;
long id;
ResolvedArtifactSet artifacts;
try {
while (true) {
type = decoder.readByte();
valuesRead++;
switch(type) {
case NODE:
id = decoder.readSmallLong();
ResolvedConfigurationIdentifier details = resolvedConfigurationIdentifierSerializer.read(decoder);
allDependencies.put(id, new DefaultResolvedDependency(id, details, buildOperationProcessor));
break;
case ROOT:
id = decoder.readSmallLong();
root = allDependencies.get(id);
if (root == null) {
throw new IllegalStateException(String.format("Unexpected root id %s. Seen ids: %s", id, allDependencies.keySet()));
}
// root should be the last entry
LOG.debug("Loaded resolved configuration results ({}) from {}", clock.getElapsed(), binaryStore);
return new DefaultTransientConfigurationResults(root, firstLevelDependencies);
case FIRST_LEVEL:
id = decoder.readSmallLong();
DefaultResolvedDependency dependency = allDependencies.get(id);
if (dependency == null) {
throw new IllegalStateException(String.format("Unexpected first level id %s. Seen ids: %s", id, allDependencies.keySet()));
}
firstLevelDependencies.put(graphResults.getModuleDependency(id), dependency);
break;
case EDGE:
long parentId = decoder.readSmallLong();
long childId = decoder.readSmallLong();
DefaultResolvedDependency parent = allDependencies.get(parentId);
DefaultResolvedDependency child = allDependencies.get(childId);
if (parent == null) {
throw new IllegalStateException(String.format("Unexpected parent dependency id %s. Seen ids: %s", parentId, allDependencies.keySet()));
}
if (child == null) {
throw new IllegalStateException(String.format("Unexpected child dependency id %s. Seen ids: %s", childId, allDependencies.keySet()));
}
parent.addChild(child);
artifacts = artifactResults.getArtifactsWithId(decoder.readSmallInt());
child.addParentSpecificArtifacts(parent, artifacts);
break;
case NODE_ARTIFACTS:
id = decoder.readSmallLong();
DefaultResolvedDependency node = allDependencies.get(id);
if (node == null) {
throw new IllegalStateException(String.format("Unexpected node id %s. Seen ids: %s", node, allDependencies.keySet()));
}
artifacts = artifactResults.getArtifactsWithId(decoder.readSmallInt());
node.addModuleArtifacts(artifacts);
break;
default:
throw new IOException("Unknown value type read from stream: " + type);
}
}
} catch (IOException e) {
throw new RuntimeException("Problems loading the resolved configuration. Read " + valuesRead + " values, last was: " + type, e);
}
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class DefaultAutoAppliedPluginHandler method isAlreadyRequestedInBuildScriptBlock.
private static boolean isAlreadyRequestedInBuildScriptBlock(PluginRequestInternal autoAppliedPlugin, ScriptHandler scriptHandler) {
ModuleVersionSelector module = autoAppliedPlugin.getModule();
if (module == null) {
return false;
}
Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
for (Dependency dependency : classpathConfiguration.getDependencies()) {
if (module.getGroup().equals(dependency.getGroup()) && module.getName().equals(dependency.getName())) {
return true;
}
}
return false;
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class GroovyRuntime method inferGroovyClasspath.
/**
* Searches the specified class path for Groovy Jars ({@code groovy(-indy)}, {@code groovy-all(-indy)}) and returns a corresponding class path for executing Groovy tools such as the Groovy
* compiler and Groovydoc tool. The tool versions will match those of the Groovy Jars found. If no Groovy Jars are found on the specified class path, a class path with the contents of the {@code
* groovy} configuration will be returned.
*
* <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
*
* @param classpath a class path containing Groovy Jars
* @return a corresponding class path for executing Groovy tools such as the Groovy compiler and Groovydoc tool
*/
public FileCollection inferGroovyClasspath(final Iterable<File> classpath) {
// would differ in at least the following ways: 1. live 2. no autowiring
return new LazilyInitializedFileCollection() {
@Override
public String getDisplayName() {
return "Groovy runtime classpath";
}
@Override
public FileCollection createDelegate() {
GroovyJarFile groovyJar = findGroovyJarFile(classpath);
if (groovyJar == null) {
throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", Iterables.toString(classpath)));
}
if (groovyJar.isGroovyAll()) {
return Cast.cast(FileCollectionInternal.class, project.files(groovyJar.getFile()));
}
if (project.getRepositories().isEmpty()) {
throw new GradleException("Cannot infer Groovy class path because no repository is declared for the project.");
}
String notation = groovyJar.getDependencyNotation();
List<Dependency> dependencies = Lists.newArrayList();
// project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier
dependencies.add(project.getDependencies().create(notation));
if (groovyJar.getVersion().getMajor() >= 2) {
// add groovy-ant to bring in Groovydoc
dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:")));
}
return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[0]));
}
// let's override this so that delegate isn't created at autowiring time (which would mean on every build)
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
if (classpath instanceof Buildable) {
context.add(classpath);
}
}
};
}
Aggregations