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

Install Maven artifacts under "m2_repo" #22

Merged
merged 2 commits into from
Jun 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -65,6 +66,7 @@ public InstallEmbulkRunSet() {
this.logger = this.project.getLogger();
this.embulkSystemProperties = new Properties();
this.embulkSystemPropertiesSource = null;
this.m2RepoRelative = DEFAULT_M2_REPO_RELATIVE;

final ObjectFactory objectFactory = this.project.getObjects();
}
Expand Down Expand Up @@ -142,6 +144,26 @@ public InstallEmbulkRunSet embulkHome(final File dir) {
return this;
}

public InstallEmbulkRunSet m2RepoRelative(final String dir) {
if (dir == null) {
throw new InvalidUserDataException("Supplied m2RepoRelative is null.");
}

try {
this.m2RepoRelative = Paths.get(dir);
} catch (final InvalidPathException ex) {
throw new InvalidUserDataException("Supplied m2RepoRelative \"" + dir + "\"is invalid.", ex);
}

if (this.m2RepoRelative.isAbsolute()) {
throw new InvalidUserDataException(
"Supplied m2RepoRelative \"" + dir + "\" is absolute."
+ " Supply a relative path from embulkHome.");
}

return this.embulkSystemProperty("m2_repo", this.m2RepoRelative.toString());
}

public InstallEmbulkRunSet embulkSystemProperty(final String key, final String value) {
this.createPropertiesSourceAndSetToCopy();
this.embulkSystemProperties.setProperty(key, value);
Expand Down Expand Up @@ -172,7 +194,7 @@ private void fromArtifact(final ResolvedArtifactResult resolvedArtifactResult, f
this.logger.lifecycle("Setting to copy {}:{} into {}", id, artifactType, modulePath);
this.logger.info("Cached file: {}", file);
this.from(file, copy -> {
copy.into(modulePath.toFile());
copy.into(this.m2RepoRelative.resolve(modulePath).toFile());
copy.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
});
} else if (id instanceof ProjectComponentIdentifier) {
Expand Down Expand Up @@ -280,6 +302,8 @@ private synchronized void createPropertiesSourceAndSetToCopy() {
}
}

private static final Path DEFAULT_M2_REPO_RELATIVE = Paths.get("lib").resolve("m2").resolve("repository");

// https://github.com/gradle/gradle/blob/v8.7.0/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/notations/DependencyMapNotationConverter.java#L42-L58
private static List<String> ACCEPTABLE_MAP_KEYS =
Arrays.asList("group", "name", "version", "configuration", "ext", "classifier");
Expand All @@ -291,4 +315,6 @@ private synchronized void createPropertiesSourceAndSetToCopy() {
private final Properties embulkSystemProperties;

private Path embulkSystemPropertiesSource;

private Path m2RepoRelative;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Properties;
Expand Down Expand Up @@ -52,7 +53,8 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr
try (final InputStream in = Files.newInputStream(propertiesPath)) {
properties.load(in);
}
assertEquals(1, properties.size());
assertEquals(2, properties.size());
assertEquals("value", properties.getProperty("key"));
assertEquals(Paths.get("lib").resolve("m2").resolve("repository").toString(), properties.getProperty("m2_repo"));
}
}
1 change: 1 addition & 0 deletions src/test/resources/simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {

installEmbulkRunSet {
embulkHome file("${project.buildDir}/simple")
m2RepoRelative "lib/m2/repository"
embulkSystemProperty "key", "value"
artifact "org.embulk:embulk-input-postgresql:0.13.2"
artifact group: "org.embulk", name: "embulk-input-s3", version: "0.6.0"
Expand Down
Loading