Search in sources :

Example 11 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class DefaultDependenciesToModuleDescriptorConverter method addDependencies.

private void addDependencies(BuildableLocalComponentMetadata metaData, ConfigurationInternal configuration) {
    AttributeContainerInternal attributes = configuration.getAttributes();
    for (Dependency dependency : configuration.getDependencies()) {
        if (dependency instanceof ModuleDependency) {
            ModuleDependency moduleDependency = (ModuleDependency) dependency;
            metaData.addDependency(dependencyDescriptorFactory.createDependencyDescriptor(configuration.getName(), attributes, moduleDependency));
        } else if (dependency instanceof FileCollectionDependency) {
            final FileCollectionDependency fileDependency = (FileCollectionDependency) dependency;
            metaData.addFiles(configuration.getName(), new DefaultLocalFileDependencyMetadata(fileDependency));
        } else {
            throw new IllegalArgumentException("Cannot convert dependency " + dependency + " to local component dependency metadata.");
        }
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) Dependency(org.gradle.api.artifacts.Dependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 12 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class ModuleFactoryDelegateTest method dependency.

@Test
public void dependency() {
    final String dependencyNotation = "someNotation";
    final ModuleDependency dependencyDummy = context.mock(ModuleDependency.class);
    letFactoryStubReturnDependency(dependencyNotation, dependencyDummy);
    moduleFactoryDelegate.dependency(dependencyNotation);
    assertThat(clientModule.getDependencies(), Matchers.equalTo(WrapUtil.toSet(dependencyDummy)));
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Test(org.junit.Test)

Example 13 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class ModuleFactoryDelegateTest method dependencyWithClosure.

@Test
public void dependencyWithClosure() {
    final String dependencyNotation = "someNotation";
    final Closure configureClosure = TestUtil.toClosure("{}");
    final ModuleDependency dependencyDummy = context.mock(ModuleDependency.class);
    letFactoryStubReturnDependency(dependencyNotation, dependencyDummy);
    moduleFactoryDelegate.dependency(dependencyNotation, configureClosure);
    assertThat(clientModule.getDependencies(), Matchers.equalTo(WrapUtil.toSet(dependencyDummy)));
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Closure(groovy.lang.Closure) Test(org.junit.Test)

Example 14 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class ModuleFactoryDelegateTest method dependencies.

@Test
public void dependencies() {
    final String dependencyNotation1 = "someNotation1";
    final String dependencyNotation2 = "someNotation2";
    final ModuleDependency dependencyDummy1 = context.mock(ModuleDependency.class, "dep1");
    final ModuleDependency dependencyDummy2 = context.mock(ModuleDependency.class, "dep2");
    letFactoryStubReturnDependency(dependencyNotation1, dependencyDummy1);
    letFactoryStubReturnDependency(dependencyNotation2, dependencyDummy2);
    moduleFactoryDelegate.dependencies((Object[]) WrapUtil.toArray(dependencyNotation1, dependencyNotation2));
    assertThat(clientModule.getDependencies(), Matchers.equalTo(WrapUtil.toSet(dependencyDummy1, dependencyDummy2)));
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Test(org.junit.Test)

Example 15 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class DefaultIvyPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    configurations.maybeCreate("default");
    Set<PublishArtifact> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        Usage usage = usageContext.getUsage();
        String conf = mapUsage(usage);
        configurations.maybeCreate(conf);
        configurations.getByName("default").extend(conf);
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            if (!seenArtifacts.contains(publishArtifact)) {
                seenArtifacts.add(publishArtifact);
                artifact(publishArtifact).setConf(conf);
            }
        }
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id.
                String confMapping = String.format("%s->%s", conf, dependency.getTargetConfiguration() == null ? Dependency.DEFAULT_CONFIGURATION : dependency.getTargetConfiguration());
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, confMapping);
                } else {
                    addExternalDependency((ExternalDependency) dependency, confMapping);
                }
            }
        }
    }
}
Also used : Usage(org.gradle.api.attributes.Usage) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) UsageContext(org.gradle.api.internal.component.UsageContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Aggregations

ModuleDependency (org.gradle.api.artifacts.ModuleDependency)25 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)8 Dependency (org.gradle.api.artifacts.Dependency)6 Test (org.junit.Test)5 Closure (groovy.lang.Closure)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)3 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)3 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)3 UsageContext (org.gradle.api.internal.component.UsageContext)3 HashMap (java.util.HashMap)2 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)2 ExternalDependency (org.gradle.api.artifacts.ExternalDependency)2 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)2 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)2 HasConfigurableAttributes (org.gradle.api.attributes.HasConfigurableAttributes)2 Capability (org.gradle.api.capabilities.Capability)2 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)2 MavenDependency (org.gradle.api.publish.maven.MavenDependency)2 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)2