Search in sources :

Example 1 with RhinoWorkerHandleFactory

use of org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory in project gradle by gradle.

the class EnvJsPlugin method apply.

public void apply(final Project project) {
    project.getPluginManager().apply(RhinoPlugin.class);
    project.getPluginManager().apply(ReportingBasePlugin.class);
    JavaScriptExtension jsExtension = project.getExtensions().getByType(JavaScriptExtension.class);
    final EnvJsExtension envJsExtension = ((ExtensionAware) jsExtension).getExtensions().create(EnvJsExtension.NAME, EnvJsExtension.class);
    final Configuration configuration = addConfiguration(project.getConfigurations(), project.getDependencies(), envJsExtension);
    final ConventionMapping conventionMapping = ((IConventionAware) envJsExtension).getConventionMapping();
    conventionMapping.map("js", new Callable<Configuration>() {

        public Configuration call() {
            return configuration;
        }
    });
    conventionMapping.map("version", new Callable<String>() {

        public String call() {
            return EnvJsExtension.DEFAULT_DEPENDENCY_VERSION;
        }
    });
    final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().getByType(RhinoExtension.class);
    project.getTasks().withType(BrowserEvaluate.class, new Action<BrowserEvaluate>() {

        public void execute(BrowserEvaluate task) {
            ((IConventionAware) task).getConventionMapping().map("evaluator", new Callable<EnvJsBrowserEvaluator>() {

                public EnvJsBrowserEvaluator call() {
                    RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(workerProcessBuilderFactory);
                    File workDir = project.getProjectDir();
                    Factory<File> envJsFactory = new Factory<File>() {

                        public File create() {
                            return envJsExtension.getJs().getSingleFile();
                        }
                    };
                    return new EnvJsBrowserEvaluator(handleFactory, rhinoExtension.getClasspath(), envJsFactory, project.getGradle().getStartParameter().getLogLevel(), workDir);
                }
            });
        }
    });
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) Configuration(org.gradle.api.artifacts.Configuration) RhinoExtension(org.gradle.plugins.javascript.rhino.RhinoExtension) BrowserEvaluate(org.gradle.plugins.javascript.envjs.browser.BrowserEvaluate) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) JavaScriptExtension(org.gradle.plugins.javascript.base.JavaScriptExtension) WorkerProcessFactory(org.gradle.process.internal.worker.WorkerProcessFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) Factory(org.gradle.internal.Factory) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) EnvJsBrowserEvaluator(org.gradle.plugins.javascript.envjs.internal.EnvJsBrowserEvaluator) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File)

Example 2 with RhinoWorkerHandleFactory

use of org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory in project gradle by gradle.

the class CoffeeScriptCompile method doCompile.

@TaskAction
public void doCompile() {
    RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
    CoffeeScriptCompileSpec spec = new DefaultCoffeeScriptCompileSpec();
    spec.setCoffeeScriptJs(getCoffeeScriptJs().getSingleFile());
    spec.setDestinationDir(getDestinationDir());
    spec.setSource(getSource());
    spec.setOptions(getOptions());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    CoffeeScriptCompiler compiler = new RhinoCoffeeScriptCompiler(handleFactory, getRhinoClasspath(), logLevel, getProject().getProjectDir());
    setDidWork(compiler.compile(spec).getDidWork());
}
Also used : RhinoCoffeeScriptCompiler(org.gradle.plugins.javascript.coffeescript.compile.internal.rhino.RhinoCoffeeScriptCompiler) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) DefaultCoffeeScriptCompileSpec(org.gradle.plugins.javascript.coffeescript.compile.internal.DefaultCoffeeScriptCompileSpec) RhinoCoffeeScriptCompiler(org.gradle.plugins.javascript.coffeescript.compile.internal.rhino.RhinoCoffeeScriptCompiler) DefaultCoffeeScriptCompileSpec(org.gradle.plugins.javascript.coffeescript.compile.internal.DefaultCoffeeScriptCompileSpec) LogLevel(org.gradle.api.logging.LogLevel) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with RhinoWorkerHandleFactory

use of org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory in project gradle by gradle.

the class JsHint method doJsHint.

@TaskAction
public void doJsHint() {
    RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    JsHintProtocol worker = handleFactory.create(getRhinoClasspath(), JsHintProtocol.class, JsHintWorker.class, logLevel, getProject().getProjectDir());
    JsHintSpec spec = new JsHintSpec();
    // flatten because we need to serialize
    spec.setSource(getSource().getFiles());
    spec.setEncoding(getEncoding());
    spec.setJsHint(getJsHint().getSingleFile());
    JsHintResult result = worker.process(spec);
    setDidWork(true);
    // TODO - this is all terribly lame. We need some proper reporting here (which means implementing Reporting).
    Logger logger = getLogger();
    boolean anyErrors = false;
    Map<String, Map<?, ?>> reportData = new LinkedHashMap<String, Map<?, ?>>(result.getResults().size());
    for (Map.Entry<File, Map<String, Object>> fileEntry : result.getResults().entrySet()) {
        File file = fileEntry.getKey();
        Map<String, Object> data = fileEntry.getValue();
        reportData.put(file.getAbsolutePath(), data);
        if (data.containsKey("errors")) {
            anyErrors = true;
            URI projectDirUri = getProject().getProjectDir().toURI();
            @SuppressWarnings("unchecked") Map<String, Object> errors = (Map<String, Object>) data.get("errors");
            if (!errors.isEmpty()) {
                URI relativePath = projectDirUri.relativize(file.toURI());
                logger.warn("JsHint errors for file: {}", relativePath.getPath());
                for (Map.Entry<String, Object> errorEntry : errors.entrySet()) {
                    @SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) errorEntry.getValue();
                    int line = Float.valueOf(error.get("line").toString()).intValue();
                    int character = Float.valueOf(error.get("character").toString()).intValue();
                    String reason = error.get("reason").toString();
                    logger.warn("  {}:{} > {}", new Object[] { line, character, reason });
                }
            }
        }
    }
    File jsonReportFile = getJsonReport();
    if (jsonReportFile != null) {
        try {
            FileWriter reportWriter = new FileWriter(jsonReportFile);
            new GsonBuilder().setPrettyPrinting().create().toJson(reportData, reportWriter);
            reportWriter.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    if (anyErrors) {
        throw new TaskExecutionException(this, new GradleException("JsHint detected errors"));
    }
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) FileWriter(java.io.FileWriter) UncheckedIOException(org.gradle.api.UncheckedIOException) Logger(org.gradle.api.logging.Logger) URI(java.net.URI) LogLevel(org.gradle.api.logging.LogLevel) LinkedHashMap(java.util.LinkedHashMap) JsHintSpec(org.gradle.plugins.javascript.jshint.internal.JsHintSpec) JsHintResult(org.gradle.plugins.javascript.jshint.internal.JsHintResult) GsonBuilder(com.google.gson.GsonBuilder) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) GradleException(org.gradle.api.GradleException) JsHintProtocol(org.gradle.plugins.javascript.jshint.internal.JsHintProtocol) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

DefaultRhinoWorkerHandleFactory (org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory)3 RhinoWorkerHandleFactory (org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory)3 File (java.io.File)2 LogLevel (org.gradle.api.logging.LogLevel)2 TaskAction (org.gradle.api.tasks.TaskAction)2 GsonBuilder (com.google.gson.GsonBuilder)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 GradleException (org.gradle.api.GradleException)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 Logger (org.gradle.api.logging.Logger)1 OutputFile (org.gradle.api.tasks.OutputFile)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1