diff --git a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPluginFuncTest.groovy b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPluginFuncTest.groovy index 424b9297a1b..e67e0d59f88 100644 --- a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPluginFuncTest.groovy +++ b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPluginFuncTest.groovy @@ -99,11 +99,14 @@ class InternalDistributionArchiveSetupPluginFuncTest extends AbstractGradleFuncT import org.gradle.api.artifacts.type.ArtifactTypeDefinition; import org.gradle.api.internal.artifacts.ArtifactAttributes; + def snapshotFile = file("snapshot-\${version}.txt") + snapshotFile << 'some snapshot content' distribution_archives { producerTar { content { project.copySpec { from 'someFile.txt' + from snapshotFile } } } @@ -134,19 +137,27 @@ class InternalDistributionArchiveSetupPluginFuncTest extends AbstractGradleFuncT when: def result = gradleRunner("copyArchive").build() - then:"tar task executed and target folder contains plain tar" + then: "tar task executed and target folder contains plain tar" result.task(':buildProducerTar').outcome == TaskOutcome.SUCCESS result.task(':consumer:copyArchive').outcome == TaskOutcome.SUCCESS file("producer-tar/build/distributions/elasticsearch.tar.gz").exists() file("consumer/build/archives/elasticsearch.tar.gz").exists() when: - result = gradleRunner("copyDir").build() - then:"plain copy task executed and target folder contains plain content" + result = gradleRunner("copyDir", "-Pversion=1.0").build() + then: "plain copy task executed and target folder contains plain content" result.task(':buildProducer').outcome == TaskOutcome.SUCCESS result.task(':consumer:copyDir').outcome == TaskOutcome.SUCCESS file("producer-tar/build/install/someFile.txt").exists() + file("producer-tar/build/install/snapshot-1.0.txt").exists() file("consumer/build/dir/someFile.txt").exists() + + when: + gradleRunner("copyDir", "-Pversion=2.0").build() + then: "old content is cleared out" + file("producer-tar/build/install/someFile.txt").exists() + !file("producer-tar/build/install/snapshot-1.0.txt").exists() + file("producer-tar/build/install/snapshot-2.0.txt").exists() } private static boolean assertTarPermissionDefaults(File tarArchive) { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/internal/DistributionArchive.java b/buildSrc/src/main/java/org/elasticsearch/gradle/internal/DistributionArchive.java index cad21e74289..bd8b68f9646 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/internal/DistributionArchive.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/internal/DistributionArchive.java @@ -21,7 +21,7 @@ package org.elasticsearch.gradle.internal; import org.gradle.api.Named; import org.gradle.api.file.CopySpec; -import org.gradle.api.tasks.Copy; +import org.gradle.api.tasks.Sync; import org.gradle.api.tasks.TaskProvider; import org.gradle.api.tasks.bundling.AbstractArchiveTask; @@ -30,10 +30,10 @@ import java.util.function.Supplier; public class DistributionArchive implements Named { private TaskProvider archiveTask; - private TaskProvider expandedDistTask; + private TaskProvider expandedDistTask; private final String name; - public DistributionArchive(TaskProvider archiveTask, TaskProvider expandedDistTask, String name) { + public DistributionArchive(TaskProvider archiveTask, TaskProvider expandedDistTask, String name) { this.archiveTask = archiveTask; this.expandedDistTask = expandedDistTask; this.name = name; @@ -57,7 +57,7 @@ public class DistributionArchive implements Named { return archiveTask; } - public TaskProvider getExpandedDistTask() { + public TaskProvider getExpandedDistTask() { return expandedDistTask; } } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java index 54c23bc5770..8a4d61c2653 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java @@ -27,7 +27,7 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.type.ArtifactTypeDefinition; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.tasks.AbstractCopyTask; -import org.gradle.api.tasks.Copy; +import org.gradle.api.tasks.Sync; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.bundling.AbstractArchiveTask; import org.gradle.api.tasks.bundling.Compression; @@ -72,7 +72,7 @@ public class InternalDistributionArchiveSetupPlugin implements Plugin { var subProjectDir = archiveToSubprojectName(name); var copyDistributionTaskName = "build" + capitalize(name.substring(0, name.length() - 3)); TaskContainer tasks = project.getTasks(); - var explodedDist = tasks.register(copyDistributionTaskName, Copy.class, copy -> copy.into(subProjectDir + "/build/install/")); + var explodedDist = tasks.register(copyDistributionTaskName, Sync.class, sync -> sync.into(subProjectDir + "/build/install/")); var archiveTaskName = "build" + capitalize(name); return name.endsWith("Tar") ? new DistributionArchive(tasks.register(archiveTaskName, SymbolicLinkPreservingTar.class), explodedDist, name)