Search in sources :

Example 1 with SoftwareComponentInternal

use of org.gradle.api.internal.component.SoftwareComponentInternal 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();
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ComponentWithCoordinates(org.gradle.api.component.ComponentWithCoordinates) UsageContext(org.gradle.api.internal.component.UsageContext) ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) SoftwareComponentInternal(org.gradle.api.internal.component.SoftwareComponentInternal) SoftwareComponent(org.gradle.api.component.SoftwareComponent)

Aggregations

ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ComponentWithCoordinates (org.gradle.api.component.ComponentWithCoordinates)1 ComponentWithVariants (org.gradle.api.component.ComponentWithVariants)1 SoftwareComponent (org.gradle.api.component.SoftwareComponent)1 SoftwareComponentInternal (org.gradle.api.internal.component.SoftwareComponentInternal)1 UsageContext (org.gradle.api.internal.component.UsageContext)1