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