diff --git a/src/main/java/org/nqm/command/Wrapper.java b/src/main/java/org/nqm/command/Wrapper.java index 6682a32..325bef0 100644 --- a/src/main/java/org/nqm/command/Wrapper.java +++ b/src/main/java/org/nqm/command/Wrapper.java @@ -2,6 +2,7 @@ import static org.nqm.config.GisConfig.CURRENT_DIR; import static org.nqm.utils.StdOutUtils.errln; +import static org.nqm.utils.StdOutUtils.warnln; import java.io.File; import java.nio.file.Path; import java.util.function.Consumer; @@ -24,6 +25,10 @@ public static void deployVertx(Path path, String... args) { GisVertx.instance().deployVerticle(new CommandVerticle(path, args)); } + private static void deployEmptyVertx() { + GisVertx.instance().deployVerticle(new CommandVerticle()); + } + private static void forEachModuleWith(Predicate pred, Consumer consumeDir, boolean withRoot) { var gitModulesFilePath = Stream.of(Path.of(".", ".gis-modules"), Path.of(".", ".gitmodules")) .map(Path::toFile) @@ -47,7 +52,7 @@ private static void forEachModuleWith(Predicate pred, Consumer consu .forEach(dir -> shouldConsumeDirOrNot(pred, consumeDir, dir)); } else { - errln("failed to read file '.gitmodules'"); + errln("failed to read file '.gis-modules' or '.gitmodules'"); } }); } @@ -61,7 +66,8 @@ private static void shouldConsumeDirOrNot(Predicate pred, Consumer c consumeDir.accept(path); } else { - GisLog.debug("directory '%s' does not satisfy the predicate".formatted("" + path)); + warnln("module '%s' does not satisfy the predicate".formatted("" + path.getFileName())); + deployEmptyVertx(); } } diff --git a/src/main/java/org/nqm/config/GisConfig.java b/src/main/java/org/nqm/config/GisConfig.java index 4b297f1..8c9bfa5 100644 --- a/src/main/java/org/nqm/config/GisConfig.java +++ b/src/main/java/org/nqm/config/GisConfig.java @@ -15,7 +15,7 @@ private static VertxOptions vertxOptions() { options.setEventLoopPoolSize(1); options.setWorkerPoolSize(1); options.setInternalBlockingPoolSize(1); - options.setBlockedThreadCheckInterval(10000); + options.setBlockedThreadCheckInterval(1000000); return options; } diff --git a/src/main/java/org/nqm/utils/StdOutUtils.java b/src/main/java/org/nqm/utils/StdOutUtils.java index 3fc3074..d53a9dc 100644 --- a/src/main/java/org/nqm/utils/StdOutUtils.java +++ b/src/main/java/org/nqm/utils/StdOutUtils.java @@ -17,8 +17,6 @@ private StdOutUtils() {} public static final String CL_CYAN = "\u001B[36m"; public static final String CL_WHITE = "\u001B[37m"; - public static final String FONT_BOLD = "\u001B[1m"; - public static void errln(String msg) { err.println(" " + CL_RED + "ERROR: " + msg + CL_RESET); } diff --git a/src/main/java/org/nqm/vertx/CommandVerticle.java b/src/main/java/org/nqm/vertx/CommandVerticle.java index af876e0..f526d1e 100644 --- a/src/main/java/org/nqm/vertx/CommandVerticle.java +++ b/src/main/java/org/nqm/vertx/CommandVerticle.java @@ -35,12 +35,22 @@ public CommandVerticle(Path path, String... args) { for (int i = 0; i < args.length; i++) { this.commandWithArgs[i + 1] = args[i]; } - GisLog.debug("executing command '%s' under directory '%s'", commandWithArgs, path); + GisLog.debug("executing command '%s' under module '%s'", commandWithArgs, path.getFileName()); GisVertx.eventAddDir(path); } + public CommandVerticle() { + this.path = null; + this.commandWithArgs = null; + GisVertx.eventAddDir(Path.of(".")); + } + @Override public void start() { + if (path == null) { + GisVertx.eventRemoveDir(Path.of(".")); + return; + } vertx.executeBlocking( (Promise promise) -> { try { @@ -64,12 +74,7 @@ private void safelyPrint(Process pr) { var sb = new StringBuilder(infof("%s", "" + path.getFileName())); try { while (isNotBlank(line = input.readLine())) { - if (commandWithArgs[1].equals("status")) { - sb.append(gitStatus(line)); - } - else { - sb.append("\n ").append(line); - } + sb.append(commandWithArgs[1].equals("status") ? gitStatus(line) : "%n %s".formatted(line)); } out.println(sb.toString()); Optional.of(pr.waitFor()) diff --git a/src/main/java/org/nqm/vertx/GisVertx.java b/src/main/java/org/nqm/vertx/GisVertx.java index 3e4cb3d..0957c6e 100644 --- a/src/main/java/org/nqm/vertx/GisVertx.java +++ b/src/main/java/org/nqm/vertx/GisVertx.java @@ -2,8 +2,8 @@ import static org.nqm.config.GisConfig.VERTX_OPTIONS; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; import org.nqm.config.GisLog; import io.vertx.core.Vertx; import io.vertx.core.eventbus.EventBus; @@ -13,7 +13,7 @@ public class GisVertx { private static Vertx vertxInstance; private static EventBus eventBus; - private static List processedModules; + private static Map processedModules; public static final String ADDR_ADD_DIR = "add.dir"; public static final String ADDR_REM_DIR = "remove.dir"; @@ -27,9 +27,9 @@ public static Vertx instance() { return vertxInstance; } - private static List processedModules() { + private static Map processedModules() { if (processedModules == null) { - processedModules = new ArrayList<>(); + processedModules = new HashMap<>(); } return processedModules; } @@ -39,31 +39,31 @@ public static EventBus eventBus() { eventBus = instance().eventBus(); } - eventBus.consumer(ADDR_ADD_DIR).handler(GisVertx::handleAddProcessedDir); - eventBus.consumer(ADDR_REM_DIR).handler(GisVertx::handleRemoveProcessedDir); + eventBus.consumer(ADDR_ADD_DIR).handler(GisVertx::addNewModule); + eventBus.consumer(ADDR_REM_DIR).handler(GisVertx::processedModule); return eventBus; } - private static void handleAddProcessedDir(Message msg) { - processedModules().add("" + msg.body()); + private static void addNewModule(Message msg) { + processedModules().put("" + msg.body(), false); } - private static void handleRemoveProcessedDir(Message msg) { - processedModules().removeIf(d -> d.equals("" + msg.body())); - GisLog.debug("### queue size = '%s'".formatted(processedModules().size())); - if (processedModules().isEmpty()) { + private static void processedModule(Message msg) { + var modules = processedModules(); + modules.computeIfPresent("" + msg.body(), (k, v) -> true); + if (!modules.isEmpty() && modules.values().stream().allMatch(Boolean.TRUE::equals)) { System.exit(0); } } public static void eventAddDir(Path dir) { - GisLog.debug("+++ adding dir '%s' to queue".formatted("" + dir)); + GisLog.debug("+++ adding module '%s' to queue".formatted("" + dir.getFileName())); eventBus().send(GisVertx.ADDR_ADD_DIR, "" + dir); } public static void eventRemoveDir(Path dir) { - GisLog.debug("--- removing dir '%s' from queue".formatted("" + dir)); + GisLog.debug("--- removing module '%s' from queue".formatted("" + dir.getFileName())); eventBus().send(GisVertx.ADDR_REM_DIR, "" + dir); }