Search in sources :

Example 1 with ArtifactTransformRegistration

use of org.gradle.api.internal.artifacts.ArtifactTransformRegistration in project gradle by gradle.

the class DefaultVariantTransformRegistry method registerTransform.

@Override
@SuppressWarnings("deprecation")
public void registerTransform(Action<? super org.gradle.api.artifacts.transform.VariantTransform> registrationAction) {
    try {
        UntypedRegistration registration = instantiatorFactory.decorateLenient().newInstance(UntypedRegistration.class, immutableAttributesFactory, instantiatorFactory);
        registrationAction.execute(registration);
        validateActionType(registration.actionType);
        try {
            validateAttributes(registration);
            Object[] parameters = registration.getTransformParameters();
            ArtifactTransformRegistration finalizedRegistration = registrationFactory.create(registration.from.asImmutable(), registration.to.asImmutable(), registration.actionType, parameters);
            transforms.add(finalizedRegistration);
        } catch (Exception e) {
            TreeFormatter formatter = new TreeFormatter();
            formatter.node("Could not register artifact transform ");
            formatter.appendType(registration.actionType);
            formatter.append(" (from ");
            formatter.appendValue(registration.from);
            formatter.append(" to ");
            formatter.appendValue(registration.to);
            formatter.append(").");
            throw new VariantTransformConfigurationException(formatter.toString(), e);
        }
    } catch (VariantTransformConfigurationException e) {
        throw e;
    } catch (Exception e) {
        throw new VariantTransformConfigurationException("Could not register artifact transform.", e);
    }
}
Also used : ArtifactTransformRegistration(org.gradle.api.internal.artifacts.ArtifactTransformRegistration) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) VariantTransformConfigurationException(org.gradle.api.artifacts.transform.VariantTransformConfigurationException) VariantTransformConfigurationException(org.gradle.api.artifacts.transform.VariantTransformConfigurationException)

Example 2 with ArtifactTransformRegistration

use of org.gradle.api.internal.artifacts.ArtifactTransformRegistration in project gradle by gradle.

the class DefaultVariantTransformRegistry method register.

private <T extends TransformParameters> void register(RecordingRegistration registration, Class<? extends TransformAction<?>> actionType, @Nullable T parameterObject) {
    validateActionType(actionType);
    try {
        validateAttributes(registration);
        ArtifactTransformRegistration finalizedRegistration = registrationFactory.create(registration.from.asImmutable(), registration.to.asImmutable(), actionType, parameterObject);
        transforms.add(finalizedRegistration);
    } catch (Exception e) {
        TreeFormatter formatter = new TreeFormatter();
        formatter.node("Could not register artifact transform ");
        formatter.appendType(actionType);
        formatter.append(" (from ");
        formatter.appendValue(registration.from);
        formatter.append(" to ");
        formatter.appendValue(registration.to);
        formatter.append(").");
        throw new VariantTransformConfigurationException(formatter.toString(), e);
    }
}
Also used : ArtifactTransformRegistration(org.gradle.api.internal.artifacts.ArtifactTransformRegistration) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) VariantTransformConfigurationException(org.gradle.api.artifacts.transform.VariantTransformConfigurationException) VariantTransformConfigurationException(org.gradle.api.artifacts.transform.VariantTransformConfigurationException)

Example 3 with ArtifactTransformRegistration

use of org.gradle.api.internal.artifacts.ArtifactTransformRegistration in project gradle by gradle.

the class ConsumerProvidedVariantFinder method findProducersFor.

private MutableConsumerVariantMatchResult findProducersFor(AttributeContainerInternal actual, AttributeContainerInternal requested) {
    // Prefer direct transformation over indirect transformation
    List<ArtifactTransformRegistration> candidates = new ArrayList<>();
    List<ArtifactTransformRegistration> transforms = variantTransforms.getTransforms();
    int nbOfTransforms = transforms.size();
    MutableConsumerVariantMatchResult result = new MutableConsumerVariantMatchResult(nbOfTransforms * nbOfTransforms);
    for (ArtifactTransformRegistration registration : transforms) {
        if (matchAttributes(registration.getTo(), requested)) {
            if (matchAttributes(actual, registration.getFrom())) {
                ImmutableAttributes variantAttributes = attributesFactory.concat(actual.asImmutable(), registration.getTo().asImmutable());
                if (matchAttributes(variantAttributes, requested)) {
                    result.matched(variantAttributes, registration.getTransformationStep(), null, 1);
                }
            }
            candidates.add(registration);
        }
    }
    if (result.hasMatches()) {
        return result;
    }
    for (ArtifactTransformRegistration candidate : candidates) {
        AttributeContainerInternal requestedPrevious = computeRequestedAttributes(requested, candidate);
        ConsumerVariantMatchResult inputVariants = collectConsumerVariants(actual, requestedPrevious);
        if (!inputVariants.hasMatches()) {
            continue;
        }
        for (MutableConsumerVariantMatchResult.ConsumerVariant inputVariant : inputVariants.getMatches()) {
            ImmutableAttributes variantAttributes = attributesFactory.concat(inputVariant.attributes.asImmutable(), candidate.getTo().asImmutable());
            result.matched(variantAttributes, candidate.getTransformationStep(), inputVariant, inputVariant.depth + 1);
        }
    }
    return result;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ArtifactTransformRegistration(org.gradle.api.internal.artifacts.ArtifactTransformRegistration) ArrayList(java.util.ArrayList) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 4 with ArtifactTransformRegistration

use of org.gradle.api.internal.artifacts.ArtifactTransformRegistration in project gradle by gradle.

the class DefaultArtifactTypeRegistry method visitArtifactTypes.

@Override
public void visitArtifactTypes(Consumer<? super ImmutableAttributes> action) {
    Set<ImmutableAttributes> seen = new HashSet<>();
    if (artifactTypeDefinitions != null) {
        for (ArtifactTypeDefinition artifactTypeDefinition : artifactTypeDefinitions) {
            ImmutableAttributes attributes = ((AttributeContainerInternal) artifactTypeDefinition.getAttributes()).asImmutable();
            attributes = attributesFactory.concat(attributesFactory.of(ARTIFACT_TYPE_ATTRIBUTE, artifactTypeDefinition.getName()), attributes);
            if (seen.add(attributes)) {
                action.accept(attributes);
            }
        }
    }
    for (ArtifactTransformRegistration transform : transformRegistry.getTransforms()) {
        AttributeContainerInternal sourceAttributes = transform.getFrom();
        String format = sourceAttributes.getAttribute(ARTIFACT_TYPE_ATTRIBUTE);
        // Some format that is not already registered
        if (format != null) {
            ImmutableAttributes attributes = sourceAttributes.asImmutable();
            if (seen.add(attributes)) {
                action.accept(attributes);
            }
        }
    }
}
Also used : ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ArtifactTransformRegistration(org.gradle.api.internal.artifacts.ArtifactTransformRegistration) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) HashSet(java.util.HashSet)

Aggregations

ArtifactTransformRegistration (org.gradle.api.internal.artifacts.ArtifactTransformRegistration)4 VariantTransformConfigurationException (org.gradle.api.artifacts.transform.VariantTransformConfigurationException)2 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ArtifactTypeDefinition (org.gradle.api.artifacts.type.ArtifactTypeDefinition)1