Search in sources :

Example 1 with UsageContext

use of org.gradle.api.internal.component.UsageContext in project gradle by gradle.

the class DefaultMavenPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    Set<PublishArtifact> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            if (seenArtifacts.add(publishArtifact)) {
                artifact(publishArtifact);
            }
        }
        Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext.getUsage());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, dependencies);
                } else {
                    addModuleDependency(dependency, dependencies);
                }
            }
        }
    }
}
Also used : 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) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal)

Example 2 with UsageContext

use of org.gradle.api.internal.component.UsageContext 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();
    for (UsageContext usageContext : this.component.getUsages()) {
        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()) {
            // 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 {
                addModuleDependency(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

InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)2 UsageContext (org.gradle.api.internal.component.UsageContext)2 Usage (org.gradle.api.attributes.Usage)1 MavenDependencyInternal (org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal)1