Search in sources :

Example 1 with ArtifactTypeDefinition

use of org.gradle.api.artifacts.type.ArtifactTypeDefinition 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)

Example 2 with ArtifactTypeDefinition

use of org.gradle.api.artifacts.type.ArtifactTypeDefinition in project crate by crate.

the class JdkDownloadPlugin method apply.

@Override
public void apply(Project project) {
    project.getDependencies().getArtifactTypes().maybeCreate(ArtifactTypeDefinition.ZIP_TYPE);
    project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
        transformSpec.getFrom().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE);
        transformSpec.getTo().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
    });
    ArtifactTypeDefinition tarArtifactTypeDefinition = project.getDependencies().getArtifactTypes().maybeCreate("tar.gz");
    project.getDependencies().registerTransform(SymbolicLinkPreservingUntarTransform.class, transformSpec -> {
        transformSpec.getFrom().attribute(ArtifactAttributes.ARTIFACT_FORMAT, tarArtifactTypeDefinition.getName());
        transformSpec.getTo().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
    });
    NamedDomainObjectContainer<Jdk> jdksContainer = project.container(Jdk.class, name -> {
        Configuration configuration = project.getConfigurations().create("jdk_" + name);
        configuration.setCanBeConsumed(false);
        configuration.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
        Jdk jdk = new Jdk(name, configuration, project.getObjects());
        configuration.defaultDependencies(dependencies -> {
            jdk.finalizeValues();
            setupRepository(project, jdk);
            dependencies.add(project.getDependencies().create(dependencyNotation(jdk)));
        });
        return jdk;
    });
    project.getExtensions().add(EXTENSION_NAME, jdksContainer);
}
Also used : ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) Configuration(org.gradle.api.artifacts.Configuration)

Aggregations

ArtifactTypeDefinition (org.gradle.api.artifacts.type.ArtifactTypeDefinition)2 HashSet (java.util.HashSet)1 Configuration (org.gradle.api.artifacts.Configuration)1 ArtifactTransformRegistration (org.gradle.api.internal.artifacts.ArtifactTransformRegistration)1 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)1 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)1