Permalink
Browse files

fixed some bugs

  • Loading branch information...
1 parent 0362270 commit 8b0ba1333b896888a44ec470954d4438930664a3 @sirrapa committed Dec 19, 2012
View
@@ -6,13 +6,15 @@ A maven plugin that executes nodejs commands
##How to install:
### Repository
+#### Use your own repository
Upload nodejs artifacts to your own repository or use Sirrapa's repositories.
-##### Configure Sirrapa repositories
+##### Use the Sirrapa repositories
+Add the following repositories to your pom.xml or settings.xml
<repositories>
<repository>
<id>sirrapa-central</id>
- <url>https://scm.sirrapa.com/nexus/content/groups/public/</url>
+ <url>https://repo.sirrapa.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
@@ -22,7 +24,7 @@ Upload nodejs artifacts to your own repository or use Sirrapa's repositories.
</repository>
<repository>
<id>sirrapa-central-snapshot</id>
- <url>https://scm.sirrapa.com/nexus/content/groups/public-snapshots/</url>
+ <url>https://repo.sirrapa.com/nexus/content/groups/public-snapshots/</url>
<layout>default</layout>
<releases>
<enabled>false</enabled>
@@ -35,7 +37,7 @@ Upload nodejs artifacts to your own repository or use Sirrapa's repositories.
<pluginRepositories>
<pluginRepository>
<id>central</id>
- <url>https://scm.sirrapa.com/nexus/content/groups/public/</url>
+ <url>https://repo.sirrapa.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
@@ -58,8 +60,18 @@ Upload nodejs artifacts to your own repository or use Sirrapa's repositories.
<plugin>
<groupId>com.sirrapa.maven.plugins</groupId>
<artifactId>nodejs-maven-plugin</artifactId>
+ <!-- Optional, if you want the js to compile when mvn:compile... -->
+ <executions>
+ <execution>
+ <id>compile-js</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <!-- Optional end -->
<configuration>
- <goal>compile</goal>
<!-- Optional, the values are default -->
<nodejsGroupId>org.nodejs</nodejsGroupId>
<nodejsArtifactId>nodejs</nodejsArtifactId>
@@ -68,8 +80,12 @@ Upload nodejs artifacts to your own repository or use Sirrapa's repositories.
<nodejsType>tar</nodejsType>
<!-- Optional end -->
<modules>
- <module>jshint.js --node foo bar</module>
- <module>r.js --o out.js</module>
+ <module>
+ <name>--version</name>
+ <arguments>
+ <argument>-o buildconfig.js</argument>
+ </arguments>
+ </module>
</modules>
</configuration>
</plugin>
@@ -81,3 +97,24 @@ Upload nodejs artifacts to your own repository or use Sirrapa's repositories.
<pre>
mvn nodejs:compile
</pre>
+
+##Example
+An example project is located at ://nodejs-maven-plugin/tree/master/src/test/resources/projects/project-001
+
+If you want to the nodejs-maven-plugin always to run when for instance compiling, just add the following section to the plugin configuration:
+ <plugin>
+ <groupId>com.sirrapa.maven.plugins</groupId>
+ <artifactId>nodejs-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>compile-js</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ ...
+ </configuration>
+ </plugin>
View
@@ -61,6 +61,11 @@
<type>tar</type>
</dependency>
<dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.9</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
@@ -106,12 +111,6 @@
<version>1.9</version>
<scope>test</scope>
</dependency>
- <!--<dependency>-->
- <!--<groupId>org.codehaus.plexus</groupId>-->
- <!--<artifactId>plexus-utils</artifactId>-->
- <!--<version>3.0.9</version>-->
- <!--<scope>test</scope>-->
- <!--</dependency>-->
</dependencies>
<build>
<pluginManagement>
@@ -14,6 +14,7 @@
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.Arg;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
@@ -31,7 +32,7 @@
* The nodejs file to run
*/
@Parameter
- private NodeJsModule[] modules;
+ protected NodeJsModule[] modules;
/**
* The nodejs nodejsGroupId
@@ -147,24 +148,30 @@ protected void executeCommandLine(Commandline commandLine)
* Create an CommandLine for the given executable
* @param workDir
* @param executable
+ * @param moduleName
* @param args
* @return
*/
- protected Commandline getCommandLine(File workDir, String executable, String... args) {
+ protected Commandline getCommandLine(File workDir, String executable, String moduleName, String... args) {
Commandline commandLine = new Commandline();
+ commandLine.getShell().setQuotedExecutableEnabled(false);
+ commandLine.getShell().setQuotedArgumentsEnabled(false);
+
if (workDir != null) {
if (!workDir.exists()) {
workDir.mkdirs();
}
commandLine.setWorkingDirectory(workDir);
}
- commandLine.getShell().setQuotedExecutableEnabled(false);
commandLine.setExecutable(executable);
-
+ if (moduleName != null) {
+ Arg arg = commandLine.createArg();
+ arg.setValue(moduleName);
+ }
if (args != null) {
- commandLine.getShell().setQuotedArgumentsEnabled(false);
commandLine.addArguments(args);
+
}
getLog().debug("commandLine = " + commandLine);
@@ -181,7 +188,7 @@ protected void executeNodeJs() throws MojoExecutionException, CommandLineExcepti
String executable = getNodeJsExecutable(nodejsClassifier) + " %s";
for (NodeJsModule module : modules) {
// get a commandline with the nodejs executable
- Commandline commandLine = getCommandLine(workingDirectory, String.format(executable, module.getName()), module.getArguments());
+ Commandline commandLine = getCommandLine(workingDirectory, executable, module.getName(), module.getArguments());
executeCommandLine(commandLine);
}
}
View
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<project name="${project.name}">
- <skin>
- <groupId>com.sirrapa.commons.maven.skins</groupId>
- <artifactId>maven-kl-default-skin</artifactId>
- <version>1</version>
- </skin>
- <bannerLeft>
- <src>images/leftklm.jpg</src>
- <href>http://www.klm.com</href>
- </bannerLeft>
- <bannerRight>
- <src>images/rightklm.jpg</src>
- </bannerRight>
- <publishDate format="dd MMMM yyyy HH:mm:ss" position="left"/>
- <body>
- <links>
- <item name="KL QA Monitor" href="${kl.Internal.M2.QAM.Url}"/>
- <item name="Jira" href="${kl.Internal.Jira.Url}"/>
- <item name="Confluence" href="${kl.Internal.Confluence.Url}"/>
- <item name="Bamboo" href="${kl.Internal.Bamboo.Url}"/>
- <item name="Crowd" href="${kl.Internal.Crowd.Url}"/>
- <item name="Maven Repo" href="${kl.Maven.Repo.Url}"/>
- <item name="Archiva" href="${kl.Internal.Archiva.Url}"/>
- <item name="Maven 2 (Apache)" href="http://maven.apache.org/"/>
- </links>
-
- <menu name="Overview">
- <item name="Introduction" href="index.html"/>
- </menu>
-
- <menu ref="parent"/>
- <menu ref="modules"/>
- <menu ref="reports"/>
-
- <!-- temp remove clover history report generaiton
-<menu name="Other Reports">
- <item name="Clover History" href="clover/historical.html"/>
- </menu> -->
- </body>
-</project>
@@ -5,24 +5,23 @@
import java.util.Map;
import java.util.Set;
+import com.sirrapa.maven.plugins.nodejs.config.NodeJsModule;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.DefaultArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.monitor.logging.DefaultLog;
-import org.apache.maven.plugin.Mojo;
-import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.ArtifactStubFactory;
import org.apache.maven.plugin.testing.stubs.StubArtifactResolver;
-import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.shell.CmdShell;
+import org.codehaus.plexus.util.cli.shell.CommandShell;
public class NodeJsMojoTest extends AbstractMojoTestCase {
NodeJsMojo mojo;
@@ -57,7 +56,7 @@ private void loadMojo(String pomFileName) throws Exception {
assertNotNull("Mojo is null after lookupMojo call", mojo);
final DefaultArtifactRepository repository = new DefaultArtifactRepository("local",
- new File(getBasedir(), localRepoDir).toURI().toURL().toString(), new DefaultRepositoryLayout());
+ new File(getBasedir(), localRepoDir).toURI().toURL().toString(), new DefaultRepositoryLayout());
repository.setBasedir(getBasedir() + localRepoDir);
mojo.setLocal(repository);
@@ -79,17 +78,15 @@ private void loadMojo(String pomFileName) throws Exception {
if (handlerDescriptors.isEmpty()) {
log.debug("All ArtifactHandlers are registered. Continuing...");
- }
- else {
+ } else {
Map<String, ArtifactHandler> unregisteredHandlers = new HashMap<String, ArtifactHandler>(handlerDescriptors.size());
for (String hint : handlerDescriptors.keySet()) {
try {
unregisteredHandlers.put(hint, (ArtifactHandler) lookup(ArtifactHandler.ROLE, hint));
log.debug("Adding ArtifactHandler for: " + hint);
- }
- catch (ComponentLookupException e) {
- log.warn("Failed to lookup ArtifactHandler with hint: " + hint + ". Reason: " + e.getMessage(), e);
+ } catch (ComponentLookupException e) {
+ mojo.getLog().warn("Failed to lookup ArtifactHandler with hint: " + hint + ". Reason: " + e.getMessage(), e);
}
}
@@ -109,8 +106,7 @@ public void testMissingModules() throws Exception {
try {
mojo.initializeModulesConfiguration();
fail("An NodeJsPluginException was expected");
- }
- catch (NodeJsPluginException e) {
+ } catch (NodeJsPluginException e) {
//this is expected
//e.printStackTrace();
assertEquals("The exception is invalid", "No NodeJs modules configured.", e.getMessage());
@@ -123,8 +119,7 @@ public void testMissingModule() throws Exception {
setVariableValueToObject(mojo, "modules", null);
mojo.initializeModulesConfiguration();
fail("An NodeJsPluginException was expected");
- }
- catch (NodeJsPluginException t) {
+ } catch (NodeJsPluginException t) {
//this is expected
//t.printStackTrace();
assertEquals("The exception message is invalid", "No NodeJs modules configured.", t.getMessage());
@@ -135,9 +130,8 @@ public void testMissingModuleName() throws Exception {
loadMojo("plugin-config-no-module-name.xml");
try {
mojo.initializeModulesConfiguration();
- // fail("An NodeJsPluginException was expected");
- }
- catch (NodeJsPluginException t) {
+// fail("An NodeJsPluginException was expected");
+ } catch (NodeJsPluginException t) {
//this is expected
//t.printStackTrace();
assertNotNull("Expected an exception cause.", t.getCause());
@@ -166,8 +160,7 @@ public void testUnpackNodeJs() throws Exception {
assertTrue(String.format("Extract of nodejs to '%s' failed", tmpDir.getAbsolutePath()), tmpDir.exists());
- }
- finally {
+ } finally {
tmpDir.delete();
}
}
@@ -186,46 +179,42 @@ public void testGetNodeJsExecutable() throws Exception {
if (Os.FAMILY_WINDOWS.equals(family) || Os.FAMILY_DOS.equals(family)) {
assertTrue(String.format("The nodejs executable for %s family is invalid", family), nodejsEx.endsWith(File.separator + "nodejs" + File.separator + "node.exe"));
- }
- else {
+ } else {
assertTrue(String.format("The nodejs executable for %s family is invalid", family), nodejsEx.endsWith(File.separator + "nodejs" + File.separator + "bin" + File.separator + "node"));
}
}
}
public void testGetCommandLine() throws Exception {
- loadMojo("plugin-config.xml");
+ loadMojo("projects/project-001/pom.xml");
mojo.initializeModulesConfiguration();
String nodejsDir = "/tmp/nodejs";
String workDir = "/work";
setVariableValueToObject(mojo, "nodejsDirectory", new File(nodejsDir + "/"));
+
+ assertNotNull("Mojo modules is null", mojo.modules);
+ assertTrue("Mojo modules should contain at least one module", mojo.modules.length == 1);
+ NodeJsModule module = mojo.modules[0];
String executable = mojo.getNodeJsExecutable("win");
assertNotNull("executable is null", executable);
- Commandline cmd = mojo.getCommandLine(new File(workDir + "/"), executable + " -o foobar", null);
+ Commandline cmd = mojo.getCommandLine(new File(workDir + "/"), executable, module.getName(), module.getArguments());
assertNotNull("commandline is null", cmd);
/** the expected string differs per OS... */
- String expected;
- if (Os.FAMILY_WINDOWS.equals(Os.OS_FAMILY) || Os.FAMILY_DOS.equals(Os.OS_FAMILY)) {
- expected = "cmd.exe /X /C \"%s -o foobar\"";
- assertEquals("The windows commandline string is invalid", String.format(expected, executable), cmd.toString());
- }
- else {
- expected = "/bin/sh -c cd %s && \"%s -o foobar\"";
- assertEquals("The commandline string is invalid", String.format(expected, workDir, executable), cmd.toString());
- }
-
- cmd = mojo.getCommandLine(new File(workDir), executable, "-o foobar", null);
- assertNotNull("commandline is null", cmd);
- /** the expected string differs per OS... */
- if (Os.isFamily(mojo.nodejsClassifier)) {
- expected = "cmd.exe /X /C \"%s -o foobar\"";
- assertEquals("The windows commandline with argument string is invalid", String.format(expected, executable), cmd.toString());
- }
- else {
- expected = "/bin/sh -c cd %s && %s -o foobar";
- assertEquals("The commandline with argument string is invalid", String.format(expected, workDir, executable), cmd.toString());
- }
- }
+ String expected= "/bin/sh -c cd %s && %s %s -o buildconfig.js";
+ assertEquals("The commandline string is invalid", String.format(expected, workDir, executable, module.getName()), cmd.toString());
+ //windows...
+ cmd.setShell(new CmdShell());
+ cmd.getShell().setQuotedExecutableEnabled(false);
+ cmd.getShell().setQuotedArgumentsEnabled(false);
+ expected = "cmd.exe /X /C \"%s %s -o buildconfig.js\"";
+ assertEquals("The windows commandline string is invalid", String.format(expected, executable, module.getName()), cmd.toString());
+ }
+
+// public void testCmdLine() throws Exception {
+// mojo = new NodeJsMojo();
+// Commandline cmd = mojo.getCommandLine(new File("/opt/node-plugin/work/"),"/opt/node-plugin/nodejs/bin/node","--version");
+// mojo.executeCommandLine(cmd);
+// }
}
Oops, something went wrong.

0 comments on commit 8b0ba13

Please sign in to comment.