Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify "embulkHome" instead of "into" in InstallEmbulkRunSet #5

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 47 additions & 2 deletions src/main/java/org/embulk/gradle/runset/InstallEmbulkRunSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<? super CopySpec> 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();
Expand Down Expand Up @@ -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<String, String> notationMap = validateMap(dependencyNotation);
this.logger.info("Artifact: {}", notationMap);
this.logger.info("Supplied artifact: {}", notationMap);
return this.project.getDependencies().create(notationMap);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading