From 2008df8a4c16e2ca66ef368a95ced172c2c2dd2e Mon Sep 17 00:00:00 2001 From: Dai MIKURUBE Date: Wed, 29 May 2024 17:48:18 +0900 Subject: [PATCH] Specify "embulkHome" instead of "into" in InstallEmbulkRunSet --- README.md | 2 +- .../gradle/runset/InstallEmbulkRunSet.java | 49 ++++++++++++++++++- src/test/resources/simple/build.gradle | 2 +- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3791780..bbb4b63 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ repositories { } installEmbulkRunSet { - into "path/to/embulk-home" // Set your Embulk home directory to install the Embulk plugins. + embulkHome file("path/to/embulk-home") // Set your Embulk home directory (absolute path) to install the Embulk plugins. artifact "org.embulk:embulk-input-postgresql:0.13.2" artifact group: "org.embulk", name: "embulk-input-s3", version: "0.6.0" diff --git a/src/main/java/org/embulk/gradle/runset/InstallEmbulkRunSet.java b/src/main/java/org/embulk/gradle/runset/InstallEmbulkRunSet.java index f247c26..166efb7 100644 --- a/src/main/java/org/embulk/gradle/runset/InstallEmbulkRunSet.java +++ b/src/main/java/org/embulk/gradle/runset/InstallEmbulkRunSet.java @@ -25,7 +25,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.gradle.api.Action; import org.gradle.api.IllegalDependencyNotation; +import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; import org.gradle.api.artifacts.ArtifactCollection; import org.gradle.api.artifacts.Configuration; @@ -38,6 +40,7 @@ import org.gradle.api.artifacts.result.ArtifactResult; import org.gradle.api.artifacts.result.ComponentArtifactsResult; import org.gradle.api.artifacts.result.ResolvedArtifactResult; +import org.gradle.api.file.CopySpec; import org.gradle.api.file.DuplicatesStrategy; import org.gradle.api.logging.Logger; import org.gradle.api.model.ObjectFactory; @@ -104,6 +107,48 @@ public void artifact(final Object dependencyNotation) { } } + public InstallEmbulkRunSet embulkHome(final File dir) { + if (dir == null) { + throw new InvalidUserDataException("Supplied embulkHome is null."); + } + + if (!dir.isAbsolute()) { + throw new InvalidUserDataException( + "Supplied embulkHome \"" + dir.toString() + "\" is not absolute." + + " Get an absolute path by: File#getAbsoluteFile()"); + } + + if (dir.exists()) { + if (dir.isDirectory()) { + this.logger.lifecycle("Supplied embulkHome \"{}\" already exists.", dir); + } else { + throw new InvalidUserDataException( + "Supplied embulkHome \"" + dir.toString() + "\" already exists, but is not a directory."); + } + } else { + // TODO: Check parents recursively? + this.logger.lifecycle("Supplied embulkHome \"{}\" does not exist, then will be created.", dir); + } + + super.into(dir); + return this; + } + + @Override + public final Copy into​(final Object destDir) { + throw new InvalidUserDataException("\"into\" is not permitted in InstallEmbulkRunSet. Use \"embulkHome\" instead."); + } + + @Override + public final Copy into​(final Object destDir, final groovy.lang.Closure configureClosure) { + throw new InvalidUserDataException("\"into\" is not permitted in InstallEmbulkRunSet. Use \"embulkHome\" instead."); + } + + @Override + public final Copy into(final Object destPath, final Action copySpec) { + throw new InvalidUserDataException("\"into\" is not permitted in InstallEmbulkRunSet. Use \"embulkHome\" instead."); + } + private void fromArtifact(final ResolvedArtifactResult resolvedArtifactResult, final String artifactType) { final ComponentIdentifier id = resolvedArtifactResult.getId().getComponentIdentifier(); final File file = resolvedArtifactResult.getFile(); @@ -148,14 +193,14 @@ private static Path moduleToPath(final ModuleComponentIdentifier id) { // https://github.com/gradle/gradle/blob/v8.4.0/subprojects/dependency-management/src/main/java/org/gradle/api/internal/notations/DependencyStringNotationConverter.java private Dependency dependencyFromCharSequence(final CharSequence dependencyNotation) { final String notationString = dependencyNotation.toString(); - this.logger.info("Artifact: {}", notationString); + this.logger.info("Supplied artifact: {}", notationString); return this.project.getDependencies().create(notationString); } // https://github.com/gradle/gradle/blob/v8.4.0/subprojects/core/src/main/java/org/gradle/internal/typeconversion/MapNotationConverter.java private Dependency dependencyFromMap(final Map dependencyNotation) { final Map notationMap = validateMap(dependencyNotation); - this.logger.info("Artifact: {}", notationMap); + this.logger.info("Supplied artifact: {}", notationMap); return this.project.getDependencies().create(notationMap); } diff --git a/src/test/resources/simple/build.gradle b/src/test/resources/simple/build.gradle index b4fca2d..84dc86b 100644 --- a/src/test/resources/simple/build.gradle +++ b/src/test/resources/simple/build.gradle @@ -7,7 +7,7 @@ repositories { } installEmbulkRunSet { - into "${project.buildDir}/simple" + embulkHome file("${project.buildDir}/simple") artifact "org.embulk:embulk-input-postgresql:0.13.2" artifact group: "org.embulk", name: "embulk-input-s3", version: "0.6.0" }