private void executeRun()

in src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java [187:238]


    private void executeRun(
            final String scriptDescription, File scriptFile, final Map<String, ?> context, final ExecutionLogger logger)
            throws IOException, ScriptException {
        ScriptInterpreter interpreter = getInterpreter(scriptFile);
        if (LOG.isDebugEnabled()) {
            String name = interpreter.getClass().getName();
            name = name.substring(name.lastIndexOf('.') + 1);
            LOG.debug("Running script with {} :{}", name, scriptFile);
        }

        String script;
        try {
            byte[] bytes = Files.readAllBytes(scriptFile.toPath());
            if (encoding != null) {
                script = new String(bytes, encoding);
            } else {
                script = new String(bytes);
            }
        } catch (IOException e) {
            String errorMessage =
                    "error reading " + scriptDescription + " " + scriptFile.getPath() + ", " + e.getMessage();
            throw new IOException(errorMessage, e);
        }

        Object result;
        try {
            if (logger != null) {
                logger.consumeLine("Running " + scriptDescription + ": " + scriptFile);
            }

            PrintStream out = (logger != null) ? logger.getPrintStream() : null;

            Map<String, Object> scriptVariables = new HashMap<>(this.globalVariables);
            scriptVariables.put("basedir", scriptFile.getParentFile());
            scriptVariables.put("context", context);

            result = interpreter.evaluateScript(script, classPath, scriptVariables, out);
            if (logger != null) {
                logger.consumeLine("Finished " + scriptDescription + ": " + scriptFile);
            }
        } catch (ScriptEvaluationException e) {
            Throwable t = (e.getCause() != null) ? e.getCause() : e;
            if (logger != null) {
                t.printStackTrace(logger.getPrintStream());
            }
            throw e;
        }

        if (!(result == null || Boolean.parseBoolean(String.valueOf(result)))) {
            throw new ScriptReturnException("The " + scriptDescription + " returned " + result + ".", result);
        }
    }