From a805c07a3156db7bf8ce3908b2c12426f2ce4f4b Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Tue, 27 Oct 2020 16:03:30 +0100 Subject: [PATCH] ProjectBuildLogAppender not found when starting the daemon #165 --- .../fuse/mvnd/client/DaemonConnector.java | 26 +++------------ .../jboss/fuse/mvnd/common/Environment.java | 33 +++++++++++++++++-- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java index 621c69217..f05b3d354 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java @@ -16,12 +16,10 @@ package org.jboss.fuse.mvnd.client; import java.io.File; -import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.channels.SocketChannel; -import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -33,9 +31,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -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,11 +248,8 @@ private String startDaemon() { final Path workingDir = layout.userDir(); String command = ""; try { - 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 classpath = mavenHome.resolve("mvn/lib/ext/mvnd-common-" + buildProperties.getVersion() + ".jar") + .toString(); final String java = Os.current().isUnixLike() ? "bin/java" : "bin\\java.exe"; List args = new ArrayList<>(); args.add(layout.javaHome().resolve(java).toString()); @@ -269,6 +262,9 @@ private String startDaemon() { args.add("-Dmvnd.java.home=" + layout.javaHome().toString()); args.add("-Dlogback.configurationFile=" + layout.getLogbackConfigurationPath()); args.add("-Ddaemon.uid=" + uid); + if (Boolean.getBoolean(Environment.DEBUG_ENVIRONMENT_PROP)) { + args.add("-D" + Environment.DEBUG_ENVIRONMENT_PROP + "=true"); + } args.add("-Xmx4g"); args.add(Environment.DAEMON_IDLE_TIMEOUT_MS.asCommandLineProperty(Integer.toString(layout.getIdleTimeoutMs()))); args.add(Environment.DAEMON_KEEP_ALIVE_MS.asCommandLineProperty(Integer.toString(layout.getKeepAliveMs()))); @@ -292,18 +288,6 @@ private String startDaemon() { } } - private String findJars(Path mavenHome, Predicate... filters) { - final Path libExtDir = mavenHome.resolve("mvn/lib/ext"); - try (Stream 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); - } - } - private DaemonClientConnection connectToDaemonWithId(String daemon, boolean newDaemon) throws DaemonException.ConnectException { // Look for 'our' daemon among the busy daemons - a daemon will start in busy state so that nobody else will diff --git a/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java b/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java index e6d39ce1a..a4df3654f 100644 --- a/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java +++ b/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java @@ -24,6 +24,7 @@ import java.util.Optional; import java.util.Properties; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.slf4j.Logger; @@ -54,7 +55,33 @@ public enum Environment { public static final int DEFAULT_MIN_THREADS = 1; - private static final Logger LOG = LoggerFactory.getLogger(Environment.class); + private static final Consumer LOG; + private static final boolean DEBUG_ENABLED; + public static final String DEBUG_ENVIRONMENT_PROP = "mvnd.environment.debug"; + + static { + Consumer log = null; + boolean debugEnabled = false; + try { + Logger logger = LoggerFactory.getLogger(Environment.class); + log = logger::debug; + debugEnabled = logger.isDebugEnabled(); + } catch (java.lang.NoClassDefFoundError e) { + if (e.getMessage().contains("org/slf4j/LoggerFactory")) { + /* This is when we are in the daemon's boot class path where slf4j is not available */ + if (Boolean.getBoolean(DEBUG_ENVIRONMENT_PROP)) { + log = s -> System.out.println("mvnd.environment: " + s); + debugEnabled = true; + } + } else { + throw e; + } + } + LOG = log != null ? log : s -> { + }; + DEBUG_ENABLED = debugEnabled; + } + static Properties properties = System.getProperties(); static Map env = System.getenv(); @@ -276,7 +303,7 @@ String get() { } } final String result = valueSource.valueSupplier.get(); - if (result != null && LOG.isDebugEnabled()) { + if (result != null && DEBUG_ENABLED) { StringBuilder sb = new StringBuilder("Loaded environment value for key [") .append(envKey.name()) .append("] from "); @@ -284,7 +311,7 @@ String get() { sb.append(": [") .append(result) .append(']'); - LOG.debug(sb.toString()); + LOG.accept(sb.toString()); } return result; }