All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eriwen.gradle.js.RhinoExec.groovy Maven / Gradle / Ivy

There is a newer version: 1.12.0
Show newest version
package com.eriwen.gradle.js

import org.gradle.api.Project
import org.gradle.process.ExecResult

/**
 * Utility for executing JS with Rhino.
 *
 * @author Eric Wendelin
 * @date 2/20/12
 */
class RhinoExec {
    private static final String RHINO_MAIN_CLASS = 'org.mozilla.javascript.tools.shell.Main'
    Project project

    void execute(final Iterable execargs, final Map options = [:]) {
        final String workingDirIn = options.get('workingDir', '.')
        final Boolean ignoreExitCode = options.get('ignoreExitCode', false).asBoolean()
        final OutputStream out = options.get('out', System.out) as OutputStream
        final String maxHeapSizeVal =  options.get('maxHeapSize', null)

        def execOptions = {
            main = RHINO_MAIN_CLASS
            classpath = project.configurations.rhino
            args = ["-opt", "9"] + execargs
            workingDir = workingDirIn
            ignoreExitValue = ignoreExitCode
            standardOutput = out
            if (maxHeapSizeVal) {
                maxHeapSize = maxHeapSizeVal
            }
        }

        ExecResult result = project.javaexec(execOptions)
        if (!ignoreExitCode) {
            result.assertNormalExitValue()
        }
    }

    public RhinoExec(final Project projectIn) {
        project = projectIn
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy