public static void main()

in client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java [72:179]


    public static void main(String[] argv) throws Exception {
        final List<String> args = new ArrayList<>(Arrays.asList(argv));

        // Log file
        Path logFile = null;
        String sLogFile = Environment.MAVEN_LOG_FILE.removeCommandLineOption(args);
        if (sLogFile != null) {
            if (sLogFile.isEmpty()) {
                throw new IllegalArgumentException("-l and --log-file need to be followed by a path");
            } else {
                logFile = Paths.get(sLogFile);
            }
        }

        // Diag
        if (Environment.DIAG.removeCommandLineOption(args) != null) {
            org.jline.terminal.impl.Diag.diag(System.out);
            return;
        }

        // Serial
        if (Environment.SERIAL.removeCommandLineOption(args) != null) {
            System.setProperty(Environment.SERIAL.getProperty(), Boolean.toString(true));
        }

        // Batch mode
        final boolean batchMode = Environment.MAVEN_BATCH_MODE.hasCommandLineOption(args)
                || Environment.COMPLETION.hasCommandLineOption(args);

        String userJdkJavaOpts = System.getenv(Environment.JDK_JAVA_OPTIONS.getEnvironmentVariable());
        if (userJdkJavaOpts != null) {
            Environment.JDK_JAVA_OPTIONS.addCommandLineOption(args, userJdkJavaOpts);
        }

        // System properties
        setSystemPropertiesFromCommandLine(args);

        if (LoggerFactory.getILoggerFactory() instanceof MvndLoggerFactory) {
            ((MvndLoggerFactory) LoggerFactory.getILoggerFactory()).reconfigure();
        }

        DaemonParameters parameters = new DaemonParameters();
        if (parameters.serial()) {
            System.setProperty(Environment.MVND_THREADS.getProperty(), Integer.toString(1));
            System.setProperty(Environment.MVND_BUILDER.getProperty(), "singlethreaded");
            System.setProperty(Environment.MVND_NO_BUFERING.getProperty(), Boolean.toString(true));
        }

        System.setProperty(
                Environment.MVND_HOME.getProperty(), parameters.mvndHome().toString());

        Path dir;
        if (Environment.MAVEN_FILE.hasCommandLineOption(args)) {
            dir = parameters.userDir().resolve(Environment.MAVEN_FILE.getCommandLineOption(args));
            if (Files.isRegularFile(dir)) {
                dir = dir.getParent();
            }
            dir = dir.normalize();
        } else {
            dir = parameters.userDir();
        }
        Path multiModuleProjectDirectory = parameters.multiModuleProjectDirectory(dir);
        System.setProperty(
                Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.getProperty(), multiModuleProjectDirectory.toString());
        Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.addCommandLineOption(
                args, multiModuleProjectDirectory.toString());

        // .mvn/jvm.config
        if (Files.isRegularFile(parameters.jvmConfigPath())) {
            try (Stream<String> jvmArgs = Files.lines(parameters.jvmConfigPath())) {
                String jvmArgsStr = jvmArgs.collect(Collectors.joining(" "));
                parameters = parameters.withJvmArgs(jvmArgsStr, false);
            }
        }

        // Install JUL -> SLF4j bridge
        SLF4JBridgeHandler.install();

        int exitCode = 0;
        boolean noBuffering = batchMode || parameters.noBuffering();
        try (TerminalOutput output = new TerminalOutput(noBuffering, parameters.rollingWindowSize(), logFile)) {
            try {
                // Color
                // We need to defer this part until the terminal is created
                Color styleColor = Color.of(Environment.MAVEN_COLOR.removeCommandLineOption(args))
                        .orElse(Color.auto);
                if (styleColor == Color.auto) {
                    /* Translate from auto to either always or never */
                    /* stdout is not a terminal e.g. when stdout is redirected to a file */
                    final boolean stdoutIsTerminal =
                            ((TerminalExt) output.getTerminal()).getProvider().isSystemStream(SystemStream.Output);
                    styleColor = (batchMode || logFile != null || !stdoutIsTerminal) ? Color.never : Color.always;
                }
                /* We cannot use Environment.addCommandLineOption() because that one would pass --color to the daemon
                 * and --color is not supported there yet. */
                args.add("-D" + Environment.MAVEN_COLOR.getProperty() + "=" + styleColor.name());

                final ExecutionResult result = new DefaultClient(parameters).execute(output, args);
                exitCode = result.getExitCode();
            } catch (DaemonException.InterruptedException e) {
                final AttributedStyle s = new AttributedStyle().bold().foreground(AttributedStyle.RED);
                String str = new AttributedString(System.lineSeparator() + "Canceled by user", s).toAnsi();
                output.accept(Message.err(str));
                exitCode = 130;
            }
        }
        System.exit(exitCode);
    }