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);
}
}
}
}
}
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);
}
}
}
}
Aggregations