Skip to content

Commit

Permalink
ProjectBuildLogAppender not found when starting the daemon apache#165
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Oct 27, 2020
1 parent 6cbd5be commit 652bcb5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> args = new ArrayList<>();
args.add(layout.javaHome().resolve(java).toString());
Expand All @@ -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())));
Expand All @@ -292,18 +288,6 @@ private String startDaemon() {
}
}

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);
}
}

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
Expand Down
33 changes: 30 additions & 3 deletions common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> LOG;
private static final boolean DEBUG_ENABLED;
public static final String DEBUG_ENVIRONMENT_PROP = "mvnd.environment.debug";

static {
Consumer<String> 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<String, String> env = System.getenv();

Expand Down Expand Up @@ -276,15 +303,15 @@ 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 ");
valueSource.descriptionFunction.apply(sb);
sb.append(": [")
.append(result)
.append(']');
LOG.debug(sb.toString());
LOG.accept(sb.toString());
}
return result;
}
Expand Down

0 comments on commit 652bcb5

Please sign in to comment.