From d2a54cdf6b31559f0e9928f00f72d0ca4573a766 Mon Sep 17 00:00:00 2001 From: gfouquet Date: Mon, 21 Oct 2013 17:01:10 +0200 Subject: [PATCH] [Issue #29] Added an optional "runner" parameter with which one can specify if he wants to use rhino or node. It defaults to nodejs --- README.md | 6 +++++ pom.xml | 2 +- .../mcheely/maven/requirejs/OptimizeMojo.java | 25 ++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7583f92..2e83b53 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,12 @@ http://requirejs.org/docs/optimization.html#wholeproject ### Plugin Options +**runner** + +Specifies which Javascript engine is used to execute the r.js optimizer. Can be either *rhino* or *nodejs*, defaults to *nodejs*. +When using *nodejs*, the plugin will try and detect the node executable. To customize the node executable's location, supply a path +to the executable using nodeJsFile + **nodeExecutable** An optional path to a nodejs executable. This should not be needed if node is in the system path as 'node' or 'nodejs'; diff --git a/pom.xml b/pom.xml index aa877cc..f698fe4 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.github.mcheely requirejs-maven-plugin RequireJS Maven Plugin - 2.0.1-noquotes-SNAPSHOT + 2.0.1-SNAPSHOT maven-plugin http://github.com/mcheely/requirejs-maven-plugin diff --git a/src/main/java/com/github/mcheely/maven/requirejs/OptimizeMojo.java b/src/main/java/com/github/mcheely/maven/requirejs/OptimizeMojo.java index 0a6891f..b6c3e06 100644 --- a/src/main/java/com/github/mcheely/maven/requirejs/OptimizeMojo.java +++ b/src/main/java/com/github/mcheely/maven/requirejs/OptimizeMojo.java @@ -81,6 +81,13 @@ public class OptimizeMojo extends AbstractMojo { */ private boolean skip; + /** + * Defines which javascript engine to use. Possible values: rhino or nodejs. + * + * @parameter expression="${requirejs.optimize.runner}" default-value=nodejs + */ + private String runner = "nodejs"; + /** * Defines the location of the NodeJS executable to use. * @@ -100,7 +107,8 @@ public void execute() throws MojoExecutionException { } Runner runner; - String nodeCommand = getNodeJsPath(); + String nodeCommand = getNodeCommand(); + if (nodeCommand != null) { getLog().info("Running with Node @ " + nodeCommand); runner = new NodeJsRunner(nodeCommand); @@ -109,7 +117,6 @@ public void execute() throws MojoExecutionException { runner = new RhinoRunner(); } - try { Optimizer builder = new Optimizer(); ErrorReporter reporter = new MojoErrorReporter(getLog(), true); @@ -127,8 +134,20 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("r.js exited with an error."); } } + /** + * Returns the node command if node is available and it is the runner which should be used. + * + * @return the command or null + */ + private String getNodeCommand() { + if ("nodejs".equalsIgnoreCase(runner)) { + return getNodeJsPath(); + } + + return null; + } - @SuppressWarnings("rawtypes") + @SuppressWarnings("rawtypes") public Map getPluginContext() { return super.getPluginContext(); }