Search in sources :

Example 21 with Dependency

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ResolvedProjectConfiguration(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration) DefaultLenientConfiguration(org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration) Configuration(org.gradle.api.artifacts.Configuration) DefaultDependencyConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyConstraint) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) Dependency(org.gradle.api.artifacts.Dependency) TaskDependency(org.gradle.api.tasks.TaskDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AbstractTaskDependency(org.gradle.api.internal.tasks.AbstractTaskDependency) ExcludeRule(org.gradle.api.artifacts.ExcludeRule) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) RootComponentMetadataBuilder(org.gradle.api.internal.artifacts.ivyservice.moduleconverter.RootComponentMetadataBuilder)

Example 22 with Dependency

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;
}
Also used : Dependency(org.gradle.api.artifacts.Dependency)

Example 23 with Dependency

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);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) Dependency(org.gradle.api.artifacts.Dependency) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) Timer(org.gradle.internal.time.Timer) ResolvedConfigurationIdentifier(org.gradle.api.internal.artifacts.ResolvedConfigurationIdentifier)

Example 24 with Dependency

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;
}
Also used : ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) Configuration(org.gradle.api.artifacts.Configuration) Dependency(org.gradle.api.artifacts.Dependency)

Example 25 with Dependency

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);
            }
        }
    };
}
Also used : GroovyJarFile(org.gradle.api.internal.plugins.GroovyJarFile) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) GradleException(org.gradle.api.GradleException) LazilyInitializedFileCollection(org.gradle.api.internal.file.collections.LazilyInitializedFileCollection) Dependency(org.gradle.api.artifacts.Dependency) Buildable(org.gradle.api.Buildable)

Aggregations

Dependency (org.gradle.api.artifacts.Dependency)25 Configuration (org.gradle.api.artifacts.Configuration)9 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)7 File (java.io.File)4 DependencySet (org.gradle.api.artifacts.DependencySet)4 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)4 TaskDependency (org.gradle.api.tasks.TaskDependency)4 LinkedHashSet (java.util.LinkedHashSet)3 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)3 SelfResolvingDependency (org.gradle.api.artifacts.SelfResolvingDependency)3 AbstractTaskDependency (org.gradle.api.internal.tasks.AbstractTaskDependency)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)2 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)2 UnresolvedDependency (org.gradle.api.artifacts.UnresolvedDependency)2 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)2 DependencyGraphNodeResult (org.gradle.api.internal.artifacts.DependencyGraphNodeResult)2 DefaultExternalModuleDependency (org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)2 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)2