mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-28 00:22:03 +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 Path mvndPropertiesPath = Environment.findMvndPropertiesPath();
|
||||||
final Supplier<Properties> mvndProperties = lazyMvndProperties(mvndPropertiesPath);
|
final Supplier<Properties> mvndProperties = lazyMvndProperties(mvndPropertiesPath);
|
||||||
final Path pwd = Paths.get(".").toAbsolutePath().normalize();
|
final Path pwd = Paths.get(".").toAbsolutePath().normalize();
|
||||||
final Path mvndHome = Environment.findBasicMavenHome()
|
final Path mvndHome = Environment.MVND_HOME
|
||||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
.fromValueSource(new ValueSource(
|
||||||
.or(new ValueSource(
|
|
||||||
description -> description.append("path relative to the mvnd executable"),
|
description -> description.append("path relative to the mvnd executable"),
|
||||||
() -> {
|
() -> {
|
||||||
Optional<String> cmd = ProcessHandle.current().info().command();
|
Optional<String> cmd = ProcessHandle.current().info().command();
|
||||||
@@ -63,6 +62,9 @@ public class ClientLayout extends Layout {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}))
|
}))
|
||||||
|
.orSystemProperty()
|
||||||
|
.orEnvironmentVariable()
|
||||||
|
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
||||||
.orFail()
|
.orFail()
|
||||||
.asPath()
|
.asPath()
|
||||||
.toAbsolutePath().normalize();
|
.toAbsolutePath().normalize();
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jboss.fuse.mvnd.client;
|
package org.jboss.fuse.mvnd.client;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
@@ -30,7 +32,9 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import org.jboss.fuse.mvnd.common.BuildProperties;
|
import org.jboss.fuse.mvnd.common.BuildProperties;
|
||||||
import org.jboss.fuse.mvnd.common.DaemonCompatibilitySpec;
|
import org.jboss.fuse.mvnd.common.DaemonCompatibilitySpec;
|
||||||
import org.jboss.fuse.mvnd.common.DaemonCompatibilitySpec.Result;
|
import org.jboss.fuse.mvnd.common.DaemonCompatibilitySpec.Result;
|
||||||
@@ -252,7 +256,11 @@ public class DaemonConnector {
|
|||||||
final Path workingDir = layout.userDir();
|
final Path workingDir = layout.userDir();
|
||||||
String command = "";
|
String command = "";
|
||||||
try {
|
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";
|
final String java = IS_WINDOWS ? "bin\\java.exe" : "bin/java";
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add(layout.javaHome().resolve(java).toString());
|
args.add(layout.javaHome().resolve(java).toString());
|
||||||
@@ -275,7 +283,7 @@ public class DaemonConnector {
|
|||||||
command = String.join(" ", args);
|
command = String.join(" ", args);
|
||||||
|
|
||||||
LOGGER.debug("Starting daemon process: uid = {}, workingDir = {}, daemonArgs: {}", uid, workingDir, command);
|
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()
|
new ProcessBuilder()
|
||||||
.directory(workingDir.toFile())
|
.directory(workingDir.toFile())
|
||||||
.command(args)
|
.command(args)
|
||||||
@@ -291,16 +299,21 @@ public class DaemonConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path findCommonJar(Path mavenHome) {
|
private String findJars(Path mavenHome, Predicate<Path>... filters) {
|
||||||
final Path result = mavenHome.resolve("mvn/lib/ext/mvnd-common-" + buildProperties.getVersion() + ".jar");
|
final Path libExtDir = mavenHome.resolve("mvn/lib/ext");
|
||||||
if (!Files.isRegularFile(result)) {
|
try (Stream<Path> jars = Files.list(libExtDir)) {
|
||||||
throw new RuntimeException("File must exist and must be a regular file: " + result);
|
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 {
|
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);
|
DaemonInfo daemonInfo = registry.get(daemon);
|
||||||
if (daemonInfo != null) {
|
if (daemonInfo != null) {
|
||||||
try {
|
try {
|
||||||
|
@@ -25,6 +25,8 @@ import java.util.Optional;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
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.
|
* 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_IDLE_TIMEOUT("daemon.idleTimeout", null),
|
||||||
DAEMON_UID("daemon.uid", null);
|
DAEMON_UID("daemon.uid", null);
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(Environment.class);
|
||||||
static Properties properties = System.getProperties();
|
static Properties properties = System.getProperties();
|
||||||
static Map<String, String> env = System.getenv();
|
static Map<String, String> env = System.getenv();
|
||||||
|
|
||||||
@@ -66,6 +69,10 @@ public enum Environment {
|
|||||||
return new EnvValue(this, environmentVariableSource());
|
return new EnvValue(this, environmentVariableSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EnvValue fromValueSource(ValueSource valueSource) {
|
||||||
|
return new EnvValue(this, valueSource);
|
||||||
|
}
|
||||||
|
|
||||||
public String asCommandLineProperty(String value) {
|
public String asCommandLineProperty(String value) {
|
||||||
return "-D" + property + "=" + value;
|
return "-D" + property + "=" + value;
|
||||||
}
|
}
|
||||||
@@ -99,14 +106,6 @@ public enum Environment {
|
|||||||
.toAbsolutePath().normalize();
|
.toAbsolutePath().normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path findMavenHome(Supplier<Properties> mvndProperties, Path mvndPropertiesPath) {
|
|
||||||
return findBasicMavenHome()
|
|
||||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
|
||||||
.orFail()
|
|
||||||
.asPath()
|
|
||||||
.toAbsolutePath().normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnvValue findBasicMavenHome() {
|
public static EnvValue findBasicMavenHome() {
|
||||||
return MVND_HOME
|
return MVND_HOME
|
||||||
.environmentVariable()
|
.environmentVariable()
|
||||||
@@ -231,7 +230,7 @@ public enum Environment {
|
|||||||
|
|
||||||
public Environment.EnvValue orDefault(Supplier<String> defaultSupplier) {
|
public Environment.EnvValue orDefault(Supplier<String> defaultSupplier) {
|
||||||
return new EnvValue(this, envKey,
|
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() {
|
public Environment.EnvValue orFail() {
|
||||||
@@ -265,7 +264,18 @@ public enum Environment {
|
|||||||
return result;
|
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() {
|
public String asString() {
|
||||||
@@ -290,4 +300,5 @@ public enum Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -72,8 +72,8 @@ public class Layout {
|
|||||||
|
|
||||||
ENV_INSTANCE = new Layout(
|
ENV_INSTANCE = new Layout(
|
||||||
mvndPropertiesPath,
|
mvndPropertiesPath,
|
||||||
Environment.findBasicMavenHome()
|
Environment.MVND_HOME
|
||||||
.orLocalProperty(mvndProperties, mvndPropertiesPath)
|
.systemProperty()
|
||||||
.orFail()
|
.orFail()
|
||||||
.asPath()
|
.asPath()
|
||||||
.toAbsolutePath().normalize(),
|
.toAbsolutePath().normalize(),
|
||||||
|
@@ -71,7 +71,6 @@ public class ServerMain {
|
|||||||
Thread.currentThread().setContextClassLoader(loader);
|
Thread.currentThread().setContextClassLoader(loader);
|
||||||
Class<?> clazz = loader.loadClass("org.jboss.fuse.mvnd.daemon.Server");
|
Class<?> clazz = loader.loadClass("org.jboss.fuse.mvnd.daemon.Server");
|
||||||
try (AutoCloseable server = (AutoCloseable) clazz.getConstructor(String.class).newInstance(uidStr)) {
|
try (AutoCloseable server = (AutoCloseable) clazz.getConstructor(String.class).newInstance(uidStr)) {
|
||||||
System.out.println("server = " + server);
|
|
||||||
((Runnable) server).run();
|
((Runnable) server).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user