Fix the ipc sync context when MVND_DAEMON_STORAGE is not set

This commit is contained in:
Guillaume Nodet
2021-07-22 17:09:39 +02:00
parent 07042e7a23
commit af832d55f5

View File

@@ -18,6 +18,7 @@ package org.mvndaemon.mvnd.sync;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PreDestroy;
import javax.inject.Named;
@@ -26,6 +27,7 @@ import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.SyncContext;
import org.eclipse.aether.impl.SyncContextFactory;
import org.eclipse.sisu.Priority;
import org.mvndaemon.mvnd.common.BuildProperties;
import org.mvndaemon.mvnd.common.Environment;
/**
@@ -41,8 +43,11 @@ public class IpcSyncContextFactory implements SyncContextFactory {
@Override
public SyncContext newInstance(RepositorySystemSession session, boolean shared) {
Path repository = session.getLocalRepository().getBasedir().toPath();
Path logPath = Environment.MVND_DAEMON_STORAGE.asPath();
String mvndHome = Environment.MVND_HOME.asOptional().orElse(null);
Path logPath = Optional.ofNullable(System.getProperty(Environment.MVND_DAEMON_STORAGE.getProperty()))
.map(Paths::get)
.orElseGet(() -> Environment.USER_HOME.asPath()
.resolve(".m2/mvnd/registry/" + BuildProperties.getInstance().getVersion()));
String mvndHome = Environment.MVND_HOME.asString();
Path syncPath = mvndHome != null ? Paths.get(mvndHome).resolve("bin") : null;
IpcClient client = clients.computeIfAbsent(repository, r -> new IpcClient(r, logPath, syncPath));
return new IpcSyncContext(client, shared);