use of org.gradle.api.component.SoftwareComponent in project gradle by gradle.
the class MavenPluginPublishingRules method addMainPublication.
@Mutate
public void addMainPublication(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment, ServiceRegistry services) {
if (!pluginDevelopment.isAutomatedPublishing()) {
return;
}
SoftwareComponentContainer componentContainer = services.get(SoftwareComponentContainer.class);
SoftwareComponent component = componentContainer.getByName("java");
PublicationContainer publications = publishing.getPublications();
createMavenPluginPublication(component, publications);
}
use of org.gradle.api.component.SoftwareComponent in project gradle by gradle.
the class ModuleMetadataFileGenerator method writeIdentity.
private void writeIdentity(ModuleVersionIdentifier coordinates, ImmutableAttributes attributes, SoftwareComponent component, Map<SoftwareComponent, ComponentData> componentCoordinates, Map<SoftwareComponent, SoftwareComponent> owners, JsonWriter jsonWriter) throws IOException {
SoftwareComponent owner = owners.get(component);
if (owner == null) {
jsonWriter.name("component");
jsonWriter.beginObject();
jsonWriter.name("group");
jsonWriter.value(coordinates.getGroup());
jsonWriter.name("module");
jsonWriter.value(coordinates.getName());
jsonWriter.name("version");
jsonWriter.value(coordinates.getVersion());
writeAttributes(attributes, jsonWriter);
jsonWriter.endObject();
} else {
ComponentData componentData = componentCoordinates.get(owner);
ModuleVersionIdentifier ownerCoordinates = componentData.coordinates;
jsonWriter.name("component");
jsonWriter.beginObject();
jsonWriter.name("url");
jsonWriter.value(relativeUrlTo(coordinates, ownerCoordinates));
jsonWriter.name("group");
jsonWriter.value(ownerCoordinates.getGroup());
jsonWriter.name("module");
jsonWriter.value(ownerCoordinates.getName());
jsonWriter.name("version");
jsonWriter.value(ownerCoordinates.getVersion());
writeAttributes(componentData.attributes, jsonWriter);
jsonWriter.endObject();
}
}
use of org.gradle.api.component.SoftwareComponent in project gradle by gradle.
the class ModuleMetadataFileGenerator method generateTo.
public void generateTo(PublicationInternal publication, Collection<? extends PublicationInternal> publications, Writer writer) throws IOException {
// Collect a map from component to coordinates. This might be better to move to the component or some publications model
Map<SoftwareComponent, ComponentData> coordinates = new HashMap<SoftwareComponent, ComponentData>();
collectCoordinates(publications, coordinates);
// Collect a map from component to its owning component. This might be better to move to the component or some publications model
Map<SoftwareComponent, SoftwareComponent> owners = new HashMap<SoftwareComponent, SoftwareComponent>();
collectOwners(publications, owners);
// Write the output
JsonWriter jsonWriter = new JsonWriter(writer);
jsonWriter.setHtmlSafe(false);
jsonWriter.setIndent(" ");
writeComponentWithVariants(publication, publication.getComponent(), coordinates, owners, jsonWriter);
jsonWriter.flush();
writer.append('\n');
}
use of org.gradle.api.component.SoftwareComponent in project gradle by gradle.
the class ModuleMetadataFileGenerator method writeVariants.
private void writeVariants(PublicationInternal publication, SoftwareComponent component, Map<SoftwareComponent, ComponentData> componentCoordinates, JsonWriter jsonWriter) throws IOException {
boolean started = false;
for (UsageContext usageContext : ((SoftwareComponentInternal) component).getUsages()) {
if (!started) {
jsonWriter.name("variants");
jsonWriter.beginArray();
started = true;
}
writeVariantHostedInThisModule(publication, usageContext, jsonWriter);
}
if (component instanceof ComponentWithVariants) {
for (SoftwareComponent childComponent : ((ComponentWithVariants) component).getVariants()) {
ModuleVersionIdentifier childCoordinates;
if (childComponent instanceof ComponentWithCoordinates) {
childCoordinates = ((ComponentWithCoordinates) childComponent).getCoordinates();
} else {
ComponentData componentData = componentCoordinates.get(childComponent);
childCoordinates = componentData == null ? null : componentData.coordinates;
}
assert childCoordinates != null;
if (childComponent instanceof SoftwareComponentInternal) {
for (UsageContext usageContext : ((SoftwareComponentInternal) childComponent).getUsages()) {
if (!started) {
jsonWriter.name("variants");
jsonWriter.beginArray();
started = true;
}
writeVariantHostedInAnotherModule(publication.getCoordinates(), childCoordinates, usageContext, jsonWriter);
}
}
}
}
if (started) {
jsonWriter.endArray();
}
}
use of org.gradle.api.component.SoftwareComponent in project gradle by gradle.
the class ModuleMetadataSpecBuilder method identity.
private ModuleMetadataSpec.Identity identity() {
// Collect a map from component to its owning component. This might be better to move to the component or some publications model
Map<SoftwareComponent, SoftwareComponent> owners = new HashMap<>();
collectOwners(publications, owners);
SoftwareComponent owner = owners.get(component);
ComponentData ownerData = owner == null ? null : componentCoordinates.get(owner);
ComponentData componentData = new ComponentData(publication.getCoordinates(), publication.getAttributes());
return ownerData != null ? identityFor(ownerData, relativeUrlTo(componentData.coordinates, ownerData.coordinates)) : identityFor(componentData, null);
}
Aggregations