Fix syncing expanded distributions in gradle build (#63285) (#63328)

This commit is contained in:
Rene Groeschke 2020-10-06 16:51:12 +02:00 committed by GitHub
parent a3a373b67f
commit 09f7cff612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -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) {

View File

@ -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<? extends AbstractArchiveTask> archiveTask;
private TaskProvider<Copy> expandedDistTask;
private TaskProvider<Sync> expandedDistTask;
private final String name;
public DistributionArchive(TaskProvider<? extends AbstractArchiveTask> archiveTask, TaskProvider<Copy> expandedDistTask, String name) {
public DistributionArchive(TaskProvider<? extends AbstractArchiveTask> archiveTask, TaskProvider<Sync> 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<Copy> getExpandedDistTask() {
public TaskProvider<Sync> getExpandedDistTask() {
return expandedDistTask;
}
}

View File

@ -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<Project> {
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)