mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-26 23:45:47 +00:00
Isolate the integration tests from the local environment #97
This commit is contained in:
@@ -44,9 +44,8 @@ public class ClientLayout extends Layout {
|
||||
final Path mvndPropertiesPath = Environment.findMvndPropertiesPath();
|
||||
final Supplier<Properties> mvndProperties = lazyMvndProperties(mvndPropertiesPath);
|
||||
final Path pwd = Paths.get(".").toAbsolutePath().normalize();
|
||||
final Path mvndHome = Environment.findBasicMavenHome()
|
||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
||||
.or(new ValueSource(
|
||||
final Path mvndHome = Environment.MVND_HOME
|
||||
.fromValueSource(new ValueSource(
|
||||
description -> description.append("path relative to the mvnd executable"),
|
||||
() -> {
|
||||
Optional<String> cmd = ProcessHandle.current().info().command();
|
||||
@@ -63,6 +62,9 @@ public class ClientLayout extends Layout {
|
||||
}
|
||||
return null;
|
||||
}))
|
||||
.orSystemProperty()
|
||||
.orEnvironmentVariable()
|
||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
||||
.orFail()
|
||||
.asPath()
|
||||
.toAbsolutePath().normalize();
|
||||
|
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.nio.channels.SocketChannel;
|
||||
@@ -30,7 +32,9 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.jboss.fuse.mvnd.common.BuildProperties;
|
||||
import org.jboss.fuse.mvnd.common.DaemonCompatibilitySpec;
|
||||
import org.jboss.fuse.mvnd.common.DaemonCompatibilitySpec.Result;
|
||||
@@ -252,7 +256,11 @@ public class DaemonConnector {
|
||||
final Path workingDir = layout.userDir();
|
||||
String command = "";
|
||||
try {
|
||||
String classpath = findCommonJar(mavenHome).toString();
|
||||
String classpath = findJars(
|
||||
mavenHome,
|
||||
p -> p.getFileName().toString().equals("mvnd-common-" + buildProperties.getVersion() + ".jar"),
|
||||
p -> p.getFileName().toString().startsWith("slf4j-api-"),
|
||||
p -> p.getFileName().toString().startsWith("logback-"));
|
||||
final String java = IS_WINDOWS ? "bin\\java.exe" : "bin/java";
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add(layout.javaHome().resolve(java).toString());
|
||||
@@ -275,7 +283,7 @@ public class DaemonConnector {
|
||||
command = String.join(" ", args);
|
||||
|
||||
LOGGER.debug("Starting daemon process: uid = {}, workingDir = {}, daemonArgs: {}", uid, workingDir, command);
|
||||
ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.appendTo(layout.daemonLog("output").toFile());
|
||||
ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.appendTo(layout.daemonLog(uid + ".out").toFile());
|
||||
new ProcessBuilder()
|
||||
.directory(workingDir.toFile())
|
||||
.command(args)
|
||||
@@ -291,16 +299,21 @@ public class DaemonConnector {
|
||||
}
|
||||
}
|
||||
|
||||
private Path findCommonJar(Path mavenHome) {
|
||||
final Path result = mavenHome.resolve("mvn/lib/ext/mvnd-common-" + buildProperties.getVersion() + ".jar");
|
||||
if (!Files.isRegularFile(result)) {
|
||||
throw new RuntimeException("File must exist and must be a regular file: " + result);
|
||||
private String findJars(Path mavenHome, Predicate<Path>... filters) {
|
||||
final Path libExtDir = mavenHome.resolve("mvn/lib/ext");
|
||||
try (Stream<Path> jars = Files.list(libExtDir)) {
|
||||
return jars
|
||||
.filter(Stream.of(filters).reduce((previous, current) -> previous.or(current)).get())
|
||||
.map(Path::toString)
|
||||
.collect(Collectors.joining(File.pathSeparator));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not list " + libExtDir);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DaemonClientConnection connectToDaemonWithId(String daemon) throws DaemonException.ConnectException {
|
||||
// Look for 'our' daemon among the busy daemons - a daemon will start in busy state so that nobody else will grab it.
|
||||
// Look for 'our' daemon among the busy daemons - a daemon will start in busy state so that nobody else will
|
||||
// grab it.
|
||||
DaemonInfo daemonInfo = registry.get(daemon);
|
||||
if (daemonInfo != null) {
|
||||
try {
|
||||
|
@@ -25,6 +25,8 @@ import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Collects system properties and environment variables used by mvnd client or server.
|
||||
@@ -41,6 +43,7 @@ public enum Environment {
|
||||
DAEMON_IDLE_TIMEOUT("daemon.idleTimeout", null),
|
||||
DAEMON_UID("daemon.uid", null);
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Environment.class);
|
||||
static Properties properties = System.getProperties();
|
||||
static Map<String, String> env = System.getenv();
|
||||
|
||||
@@ -66,6 +69,10 @@ public enum Environment {
|
||||
return new EnvValue(this, environmentVariableSource());
|
||||
}
|
||||
|
||||
public EnvValue fromValueSource(ValueSource valueSource) {
|
||||
return new EnvValue(this, valueSource);
|
||||
}
|
||||
|
||||
public String asCommandLineProperty(String value) {
|
||||
return "-D" + property + "=" + value;
|
||||
}
|
||||
@@ -99,14 +106,6 @@ public enum Environment {
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
public static Path findMavenHome(Supplier<Properties> mvndProperties, Path mvndPropertiesPath) {
|
||||
return findBasicMavenHome()
|
||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
||||
.orFail()
|
||||
.asPath()
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
public static EnvValue findBasicMavenHome() {
|
||||
return MVND_HOME
|
||||
.environmentVariable()
|
||||
@@ -231,7 +230,7 @@ public enum Environment {
|
||||
|
||||
public Environment.EnvValue orDefault(Supplier<String> defaultSupplier) {
|
||||
return new EnvValue(this, envKey,
|
||||
new ValueSource(sb -> sb.append("default").append(defaultSupplier.get()), defaultSupplier));
|
||||
new ValueSource(sb -> sb.append("default: ").append(defaultSupplier.get()), defaultSupplier));
|
||||
}
|
||||
|
||||
public Environment.EnvValue orFail() {
|
||||
@@ -265,7 +264,18 @@ public enum Environment {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return valueSource.valueSupplier.get();
|
||||
final String result = valueSource.valueSupplier.get();
|
||||
if (result != null && LOG.isDebugEnabled()) {
|
||||
StringBuilder sb = new StringBuilder("Loaded environment value for key [")
|
||||
.append(envKey.name())
|
||||
.append("] from ");
|
||||
valueSource.descriptionFunction.apply(sb);
|
||||
sb.append(": [")
|
||||
.append(result)
|
||||
.append(']');
|
||||
LOG.debug(sb.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
@@ -290,4 +300,5 @@ public enum Environment {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -72,8 +72,8 @@ public class Layout {
|
||||
|
||||
ENV_INSTANCE = new Layout(
|
||||
mvndPropertiesPath,
|
||||
Environment.findBasicMavenHome()
|
||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
||||
Environment.MVND_HOME
|
||||
.systemProperty()
|
||||
.orFail()
|
||||
.asPath()
|
||||
.toAbsolutePath().normalize(),
|
||||
|
@@ -71,7 +71,6 @@ public class ServerMain {
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
Class<?> clazz = loader.loadClass("org.jboss.fuse.mvnd.daemon.Server");
|
||||
try (AutoCloseable server = (AutoCloseable) clazz.getConstructor(String.class).newInstance(uidStr)) {
|
||||
System.out.println("server = " + server);
|
||||
((Runnable) server).run();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user