protected void executeCommand()

in src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java [145:186]


    protected void executeCommand(Commandline cmd, File outputDirectory) throws MojoExecutionException {
        if (getLog().isDebugEnabled()) {
            // no quoted arguments ???
            getLog().debug(CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
        }

        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
        try {
            int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);

            String output = (StringUtils.isEmpty(out.getOutput())
                    ? null
                    : '\n' + out.getOutput().trim());

            if (exitCode != 0) {
                if (StringUtils.isNotEmpty(output)) {
                    // Reconsider to use WARN / ERROR ?
                    getLog().info(output);
                }

                StringBuilder msg = new StringBuilder("\nExit code: ");
                msg.append(exitCode);
                if (StringUtils.isNotEmpty(err.getOutput())) {
                    msg.append(" - ").append(err.getOutput());
                }
                msg.append('\n');
                msg.append("Command line was: ").append(cmd).append('\n').append('\n');

                throw new MojoExecutionException(msg.toString());
            }

            if (StringUtils.isNotEmpty(output)) {
                String[] splitLines = StringUtils.split(output, "\n");
                for (String outputLine : splitLines) {
                    getLog().info(outputLine);
                }
            }
        } catch (CommandLineException e) {
            throw new MojoExecutionException("Unable to execute jmod command: " + e.getMessage(), e);
        }
    }