Permalink
Browse files

updated README.md

  • Loading branch information...
2 parents ca0e75a + b068304 commit 7847e18a65d160ae161035e9f4d0253d1950500d @sirrapa committed Dec 20, 2012
Showing with 20 additions and 10 deletions.
  1. +20 −10 src/main/java/com/sirrapa/maven/plugins/nodejs/NodeJsMojo.java
@@ -12,6 +12,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.Arg;
@@ -79,14 +80,23 @@ public void execute() throws MojoExecutionException {
try {
initializeModulesConfiguration();
+ //get the nodejs executable path
+ String nodeJsExecutable = getNodeJsExecutable(nodejsClassifier);
- Artifact nodeJsArtifact = resolveNodeJsArtifact();
+ //only download and extract if it does not exists
+ if (!FileUtils.fileExists(nodeJsExecutable)) {
+ Artifact nodeJsArtifact = resolveNodeJsArtifact();
- if (nodeJsArtifact != null) {
- unpackNodeJs(nodeJsArtifact, nodejsDirectory);
+ if (nodeJsArtifact != null) {
+ unpackNodeJs(nodeJsArtifact, nodejsDirectory);
+ }
+ }
- executeNodeJs();
+ //scream if it does not exists now....
+ if (!FileUtils.fileExists(nodeJsExecutable)) {
+ throw new MojoExecutionException(String.format("Unable to locate nodejs executable at '%s'",nodeJsExecutable));
}
+ executeNodeJs(nodeJsExecutable);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Unable to locate artifact: '" + nodeJsArtifactString + "' in any repository.", e);
} catch (ArtifactNotFoundException e) {
@@ -105,17 +115,17 @@ public void execute() throws MojoExecutionException {
* @return
*/
protected String getNodeJsExecutable(String osFamily) {
- if(osFamily == null) {
+ if (osFamily == null) {
throw new IllegalArgumentException("osFamily is null");
}
- getLog().debug(String.format("Determing executable for osFamily = '%s'",osFamily));
+ getLog().debug(String.format("Determing executable for osFamily = '%s'", osFamily));
StringBuilder sb = new StringBuilder(nodejsDirectory.getAbsolutePath());
- if (osFamily.toLowerCase().startsWith("win")|| Os.FAMILY_DOS.equals(osFamily)) {
+ if (osFamily.toLowerCase().startsWith("win") || Os.FAMILY_DOS.equals(osFamily)) {
sb.append(File.separator).append("node.exe");
} else {
sb.append(File.separator).append("bin").append(File.separator).append("node");
}
- getLog().info(String.format("Determined executable for osFamily '%s' = '%s'",osFamily,sb.toString()));
+ getLog().info(String.format("Determined executable for osFamily '%s' = '%s'", osFamily, sb.toString()));
return sb.toString();
}
@@ -185,11 +195,11 @@ protected Commandline getCommandLine(File workDir, String executable, String mod
/**
* Execute nodejs for every module in #modules.
*
+ * @param executable
* @throws MojoExecutionException
* @throws CommandLineException
*/
- protected void executeNodeJs() throws MojoExecutionException, CommandLineException {
- String executable = getNodeJsExecutable(nodejsClassifier);
+ protected void executeNodeJs(String executable) throws MojoExecutionException, CommandLineException {
for (NodeJsModule module : modules) {
// get a commandline with the nodejs executable
Commandline commandLine = getCommandLine(workingDirectory, executable, module.getName(), module.getArguments());

0 comments on commit 7847e18

Please sign in to comment.