Skip to content

Commit

Permalink
[8.0] Replace deprecated api in artifact transforms (#84015) (#84021)
Browse files Browse the repository at this point in the history
`ArtifactAttributes.ARTIFACT_FORMAT` has been deprecated in favor of
public available `ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE`
  • Loading branch information
breskeby authored Feb 21, 2022
1 parent e8c0a0e commit 88ebff7
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.File;

import static org.elasticsearch.gradle.internal.conventions.GUtils.capitalize;
import static org.gradle.api.internal.artifacts.ArtifactAttributes.ARTIFACT_FORMAT;

/**
* Provides a DSL and common configurations to define different types of
Expand Down Expand Up @@ -75,12 +74,14 @@ private void registerAndConfigureDistributionArchivesExtension(Project project)
sub.getArtifacts().add(DEFAULT_CONFIGURATION_NAME, distributionArchive.getArchiveTask());
var extractedConfiguration = sub.getConfigurations().create(EXTRACTED_CONFIGURATION_NAME);
extractedConfiguration.setCanBeResolved(false);
extractedConfiguration.getAttributes().attribute(ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
extractedConfiguration.getAttributes()
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
sub.getArtifacts().add(EXTRACTED_CONFIGURATION_NAME, distributionArchive.getExpandedDistTask());
// The "composite" configuration is specifically used for resolving transformed artifacts in an included build
var compositeConfiguration = sub.getConfigurations().create(COMPOSITE_CONFIGURATION_NAME);
compositeConfiguration.setCanBeResolved(false);
compositeConfiguration.getAttributes().attribute(ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
compositeConfiguration.getAttributes()
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
compositeConfiguration.getAttributes().attribute(Attribute.of("composite", Boolean.class), true);
sub.getArtifacts().add(COMPOSITE_CONFIGURATION_NAME, distributionArchive.getArchiveTask());
sub.getTasks().register("extractedAssemble", task ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.internal.artifacts.ArtifactAttributes;

import java.util.Arrays;

Expand All @@ -40,21 +39,21 @@ 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)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE)
.attribute(jdkAttribute, true);
transformSpec.getTo()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(jdkAttribute, true);
transformSpec.parameters(parameters -> parameters.setTrimmedPrefixPattern(JDK_TRIMMED_PREFIX));
});

ArtifactTypeDefinition tarArtifactTypeDefinition = project.getDependencies().getArtifactTypes().maybeCreate("tar.gz");
project.getDependencies().registerTransform(SymbolicLinkPreservingUntarTransform.class, transformSpec -> {
transformSpec.getFrom()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, tarArtifactTypeDefinition.getName())
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, tarArtifactTypeDefinition.getName())
.attribute(jdkAttribute, true);
transformSpec.getTo()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(jdkAttribute, true);
transformSpec.parameters(parameters -> {
parameters.setTrimmedPrefixPattern(JDK_TRIMMED_PREFIX);
Expand All @@ -65,7 +64,7 @@ public void apply(Project project) {
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);
configuration.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
configuration.getAttributes().attribute(jdkAttribute, true);
Jdk jdk = new Jdk(name, configuration, project.getObjects());
configuration.defaultDependencies(dependencies -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.specs.Specs;
Expand Down Expand Up @@ -313,7 +312,7 @@ private static Object convertPath(

private static Configuration configureExamplePlugin(Project project) {
Configuration examplePlugin = project.getConfigurations().create(EXAMPLE_PLUGIN_CONFIGURATION);
examplePlugin.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE);
examplePlugin.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE);
DependencyHandler deps = project.getDependencies();
deps.add(EXAMPLE_PLUGIN_CONFIGURATION, deps.project(Map.of("path", ":plugins:analysis-icu", "configuration", "zip")));
return examplePlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -61,14 +60,14 @@ public void setDockerAvailability(Provider<Boolean> dockerAvailability) {
@Override
public void apply(Project project) {
project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
transformSpec.getFrom().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE);
transformSpec.getTo().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
transformSpec.getFrom().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE);
transformSpec.getTo().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, 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);
transformSpec.getFrom().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, tarArtifactTypeDefinition.getName());
transformSpec.getTo().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
});

setupResolutionsContainer(project);
Expand All @@ -80,7 +79,8 @@ private void setupDistributionContainer(Project project, Property<Boolean> docke
distributionsContainer = project.container(ElasticsearchDistribution.class, name -> {
Configuration fileConfiguration = project.getConfigurations().create("es_distro_file_" + name);
Configuration extractedConfiguration = project.getConfigurations().create(DISTRO_EXTRACTED_CONFIG_PREFIX + name);
extractedConfiguration.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
extractedConfiguration.getAttributes()
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
return new ElasticsearchDistribution(
name,
project.getObjects(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.file.RegularFile;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
Expand Down Expand Up @@ -236,7 +235,7 @@ public Object doCall() {

// also make the zip available as a configuration (used when depending on this project)
Configuration configuration = project.getConfigurations().create("zip");
configuration.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE);
configuration.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE);
project.getArtifacts().add("zip", bundle);

return bundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.SourceSet;
Expand Down Expand Up @@ -53,16 +52,16 @@ public void apply(Project project) {
project.getDependencies().getArtifactTypes().maybeCreate(ArtifactTypeDefinition.JAR_TYPE);
project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
transformSpec.getFrom()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.JAR_TYPE)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE)
.attribute(restAttribute, true);
transformSpec.getTo()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(restAttribute, true);
});

ConfigurationContainer configurations = project.getConfigurations();
Configuration restTestSpecs = configurations.create(REST_TEST_SPECS_CONFIGURATION_NAME);
restTestSpecs.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
restTestSpecs.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
restTestSpecs.getAttributes().attribute(restAttribute, true);

TaskProvider<Copy> copyRestTestSpecs = project.getTasks().register("copyRestTestSpecs", Copy.class, t -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.RegularFile;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
Expand Down Expand Up @@ -343,7 +342,7 @@ public void module(Provider<RegularFile> module) {
private void registerExtractedConfig(Provider<RegularFile> pluginProvider) {
Dependency pluginDependency = this.project.getDependencies().create(project.files(pluginProvider));
Configuration extractedConfig = project.getConfigurations().detachedConfiguration(pluginDependency);
extractedConfig.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
extractedConfig.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
extractedConfig.getAttributes().attribute(bundleAttribute, true);
pluginAndModuleConfiguration.from(extractedConfig);
}
Expand All @@ -353,10 +352,10 @@ private void configureArtifactTransforms() {
project.getDependencies().getArtifactTypes().maybeCreate(ArtifactTypeDefinition.ZIP_TYPE);
project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
transformSpec.getFrom()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE)
.attribute(bundleAttribute, true);
transformSpec.getTo()
.attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(bundleAttribute, true);
transformSpec.getParameters().setAsFiletreeOutput(true);
});
Expand Down
35 changes: 17 additions & 18 deletions modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.OS
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.test.AntFixture
import org.elasticsearch.gradle.transform.UnzipTransform
import org.gradle.api.internal.artifacts.ArtifactAttributes

apply plugin: 'elasticsearch.test-with-dependencies'
apply plugin: 'elasticsearch.jdk-download'
Expand Down Expand Up @@ -102,30 +104,28 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
systemProperty "tests.fromOld", "false"
}
} else {
/* Set up tasks to unzip and run the old versions of ES before running the
* integration tests. */
/* Register a gradle artifact transformation to unpack resolved elasticsearch distributions. We only resolve
* zip files here. Using artifact transforms allow a better caching of the downloaded distros as the
* transformed (unpacked) distro will be cached by gradle resulting in less unpacking
*
* To avoid testing against too many old versions, always pick first and last version per major
*/
project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
transformSpec.getFrom().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.ZIP_TYPE);
transformSpec.getTo().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
});

def versions = ['2', '1', '090']
if (Os.isFamily(Os.FAMILY_MAC)) {
// 0.90 fails sometimes on mac, given that it is so old, let us disable it
// see: https://github.com/elastic/elasticsearch/issues/51202
versions = ['2', '1']
}
versions.each { version ->
// TODO Rene: we should be able to replace these unzip tasks with gradle artifact transforms
TaskProvider<Sync> unzip = tasks.register("unzipEs${version}", Sync) {
Configuration oldEsDependency = configurations['es' + version]
dependsOn oldEsDependency
/* Use a closure here to delay resolution of the dependency until we need
* it */
from {
oldEsDependency.collect { zipTree(it) }
}
into temporaryDir
}

def oldEsDependency = configurations['es' + version]
oldEsDependency.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
TaskProvider<AntFixture> fixture = tasks.register("oldEs${version}Fixture", AntFixture) {
dependsOn project.configurations.oldesFixture, jdks.legacy
dependsOn unzip
dependsOn project.configurations.oldesFixture, jdks.legacy, oldEsDependency
executable = "${BuildParams.runtimeJavaHome}/bin/java"
env 'CLASSPATH', "${-> project.configurations.oldesFixture.asPath}"
// old versions of Elasticsearch need JAVA_HOME
Expand All @@ -136,7 +136,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
}
args 'oldes.OldElasticsearch',
baseDir,
unzip.get().temporaryDir,
"${ -> oldEsDependency.singleFile.getPath()}",
version == '090'
waitCondition = { fixture, ant ->
// the fixture writes the ports file when Elasticsearch's HTTP service
Expand Down Expand Up @@ -173,4 +173,3 @@ tasks.named("yamlRestTestV7CompatTransform").configure { task ->

task.addAllowedWarningRegex("\\[types removal\\].*")
}

1 change: 0 additions & 1 deletion qa/repository-old-versions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,3 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
}
}
}

2 changes: 1 addition & 1 deletion rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ configurations {
// easy and efficient
basicRestSpecs {
attributes {
attribute(org.gradle.api.internal.artifacts.ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE)
attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
}
}
}
Expand Down

0 comments on commit 88ebff7

Please sign in to comment.