Skip to content

Commit

Permalink
[maven] when downloading dependencies, tolerate the maven.repo.local …
Browse files Browse the repository at this point in the history
…system property
  • Loading branch information
rmannibucau committed May 13, 2024
1 parent f602010 commit 25f80c4
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Semaphore;
import java.util.function.BiFunction;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static io.yupiik.bundlebee.core.command.Executable.UNSET;
Expand All @@ -82,15 +81,17 @@
@ApplicationScoped
public class Maven implements ConfigHolder {
private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
private static final Pattern ENCRYPTED_PATTERN = Pattern.compile(".*?[^\\\\]?\\{(.*?[^\\\\])\\}.*");

@Inject
@Description("When fetching a dependency using HTTP, the connection timeout for this dependency.")
@ConfigProperty(name = "bundlebee.maven.http.connectTimeout", defaultValue = "30000")
private int connectTimeout;

@Inject
@Description("Where to cache maven dependencies. If set to `auto`, `$HOME/.m2/repository` is used.")
@Description("Where to cache maven dependencies. " +
"If set to `auto`, tries to read the system property `maven.repo.local`" +
" then the `settings.xml` `localRepository`" +
" and finally it would fallback on `$HOME/.m2/repository`.")
@ConfigProperty(name = "bundlebee.maven.cache", defaultValue = "auto")
private String m2CacheConfig;

Expand Down Expand Up @@ -479,6 +480,11 @@ private Path m2Home() {
.filter(it -> !"auto".equals(it))
.map(Paths::get)
.orElseGet(() -> {
final var sp = System.getProperty("maven.repo.local");
if (sp != null) {
return Path.of(sp);
}

final var m2 = Paths.get(System.getProperty("user.home")).resolve(".m2/repository");
final var settingsXml = m2.resolve("settings.xml");
if (Files.exists(settingsXml)) {
Expand Down

0 comments on commit 25f80c4

Please sign in to comment.