diff --git a/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojo.java b/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojo.java index 7acc4280b..9dce1eefe 100644 --- a/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojo.java +++ b/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojo.java @@ -51,6 +51,7 @@ public class CoffeeScriptCompilerMojo extends AbstractWisdomWatcherMojo implemen public static final String COFFEE_SCRIPT_NPM_NAME = "coffee-script"; public static final String COFFEE_SCRIPT_COMMAND = "coffee"; public static final String ERROR_TITLE = "CoffeeScript Compilation Error"; + public static final String COFFEESCRIPT_VERSION = "1.9.2"; private NPM coffee; @@ -60,7 +61,7 @@ public class CoffeeScriptCompilerMojo extends AbstractWisdomWatcherMojo implemen * * @see NPM Web Site. */ - @Parameter(defaultValue = "1.8.0") + @Parameter(defaultValue = COFFEESCRIPT_VERSION) String coffeeScriptVersion; /** diff --git a/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/LessCompilerMojo.java b/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/LessCompilerMojo.java index 19e8e3db3..33662071c 100644 --- a/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/LessCompilerMojo.java +++ b/core/wisdom-maven-plugin/src/main/java/org/wisdom/maven/mojos/LessCompilerMojo.java @@ -52,6 +52,7 @@ public class LessCompilerMojo extends AbstractWisdomWatcherMojo implements Const public static final String LESS_NPM_NAME = "less"; public static final String ERROR_TITLE = "Less Compilation Error"; + public static final String LESS_VERSION = "1.7.5"; private NPM less; @@ -64,7 +65,7 @@ public class LessCompilerMojo extends AbstractWisdomWatcherMojo implements Const * * @see NPM Web Site. */ - @Parameter(defaultValue = "1.7.3") + @Parameter(defaultValue = LESS_VERSION) String lessVersion; /** diff --git a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CSSMinifierMojoTest.java b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CSSMinifierMojoTest.java index a0c210326..935afa589 100644 --- a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CSSMinifierMojoTest.java +++ b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CSSMinifierMojoTest.java @@ -72,7 +72,7 @@ public void setUp() throws IOException { less.project = project; less.basedir = new File(FAKE_PROJECT); less.buildDirectory = new File(FAKE_PROJECT_TARGET); - less.lessVersion = "1.7.3"; + less.lessVersion = LessCompilerMojo.LESS_VERSION; cleanup(); } diff --git a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojoTest.java b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojoTest.java index 539c21800..71d041d31 100644 --- a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojoTest.java +++ b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/CoffeeScriptCompilerMojoTest.java @@ -33,6 +33,7 @@ import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Check the behavior of the CoffeeScript mojo. @@ -56,7 +57,7 @@ public void setUp() throws IOException { mojo.basedir = new File(FAKE_PROJECT); mojo.buildDirectory = new File(FAKE_PROJECT_TARGET); mojo.buildDirectory.mkdirs(); - mojo.coffeeScriptVersion = "1.8.0"; + mojo.coffeeScriptVersion = CoffeeScriptCompilerMojo.COFFEESCRIPT_VERSION; cleanup(); } @@ -133,6 +134,29 @@ public void testWatching() throws MojoFailureException, MojoExecutionException, assertThat(ext.lastModified()).isGreaterThanOrEqualTo(originalLastModified); } + @Test + public void testErrorDetection() throws IOException, MojoExecutionException { + cleanup(); + // Execute also initialize the mojo + mojo.execute(); + + // Copy the broken file + File broken = new File("src/test/resources/coffee/invalid.coffee"); + final File copy = new File(mojo.basedir, "src/main/resources/assets/invalid.coffee"); + FileUtils.copyFile(broken, copy); + try { + mojo.fileCreated(copy); + fail("Watching Exception expected when compiling a broken CoffeeScript file"); + } catch (WatchingException e) { + assertThat(e.getLine()).isEqualTo(3); + assertThat(e.getFile().getAbsolutePath()).isEqualTo(copy.getAbsolutePath()); + assertThat(e.getCharacter()).isEqualTo(25); + assertThat(e.getMessage()).contains("unexpected end of input"); + } finally { + FileUtils.deleteQuietly(copy); + } + } + private void cleanup() { FileUtils.deleteQuietly(mojo.buildDirectory); } diff --git a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/LessCompilerMojoTest.java b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/LessCompilerMojoTest.java index b1038a355..f737032ee 100644 --- a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/LessCompilerMojoTest.java +++ b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/mojos/LessCompilerMojoTest.java @@ -33,6 +33,7 @@ import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Checks the Less Compiler Mojo. @@ -56,7 +57,7 @@ public void setUp() throws IOException { mojo.basedir = new File(FAKE_PROJECT); mojo.buildDirectory = new File(FAKE_PROJECT_TARGET); mojo.buildDirectory.mkdirs(); - mojo.lessVersion = "1.7.3"; + mojo.lessVersion = LessCompilerMojo.LESS_VERSION; cleanup(); } @@ -155,6 +156,29 @@ public void testUsingParameters() throws MojoFailureException, MojoExecutionExce .contains("-webkit-box-shadow:0 0 5px rgba(0,0,0,0.3);"); } + @Test + public void testErrorDetection() throws IOException, MojoExecutionException { + cleanup(); + // Execute also initialize the mojo + mojo.execute(); + + // Copy the broken file + File broken = new File("src/test/resources/less/invalid.less"); + final File copy = new File(mojo.basedir, "src/main/resources/assets/invalid.less"); + FileUtils.copyFile(broken, copy); + try { + mojo.fileCreated(copy); + fail("Watching Exception expected when compiling a broken Less file"); + } catch (WatchingException e) { + assertThat(e.getLine()).isEqualTo(3); + assertThat(e.getFile().getAbsolutePath()).isEqualTo(copy.getAbsolutePath()); + assertThat(e.getCharacter()).isEqualTo(3); + assertThat(e.getMessage()).contains("Unrecognised input"); + } finally { + FileUtils.deleteQuietly(copy); + } + } + private void cleanup() { FileUtils.deleteQuietly(mojo.buildDirectory); } diff --git a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/node/NodeManagerTest.java b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/node/NodeManagerTest.java index daa3fbf19..2635eab88 100644 --- a/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/node/NodeManagerTest.java +++ b/core/wisdom-maven-plugin/src/test/java/org/wisdom/maven/node/NodeManagerTest.java @@ -29,6 +29,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.wisdom.maven.mojos.AbstractWisdomMojo; +import org.wisdom.maven.mojos.CoffeeScriptCompilerMojo; import java.io.File; import java.io.IOException; @@ -83,7 +84,7 @@ public void testInstallationOfCoffeeScript() throws IOException, ParseException when(mojo.getLog()).thenReturn(log); when(mojo.getNodeManager()).thenReturn(manager); - NPM npm = NPM.npm(mojo, "coffee-script", "1.8.0"); + NPM npm = NPM.npm(mojo, "coffee-script", CoffeeScriptCompilerMojo.COFFEESCRIPT_VERSION); assertThat(npm).isNotNull(); assertThat(npm.findExecutable("coffee")).isFile(); @@ -97,11 +98,11 @@ public void testReinstallation() throws IOException, ParseException { when(mojo.getLog()).thenReturn(log); when(mojo.getNodeManager()).thenReturn(manager); - NPM npm = NPM.npm(mojo, "coffee-script", "1.8.0"); + NPM npm = NPM.npm(mojo, "coffee-script", CoffeeScriptCompilerMojo.COFFEESCRIPT_VERSION); assertThat(npm).isNotNull(); assertThat(npm.findExecutable("coffee")).isFile(); - NPM npm2 = NPM.npm(mojo, "coffee-script", "1.8.0"); + NPM npm2 = NPM.npm(mojo, "coffee-script", CoffeeScriptCompilerMojo.COFFEESCRIPT_VERSION); assertThat(npm).isEqualTo(npm2); assertThat(npm.hashCode()).isEqualTo(npm2.hashCode()); } @@ -114,9 +115,9 @@ public void testExecution() throws IOException, ParseException, MojoExecutionExc when(mojo.getLog()).thenReturn(log); when(mojo.getNodeManager()).thenReturn(manager); - NPM npm = NPM.npm(mojo, "coffee-script", "1.8.0"); + NPM npm = NPM.npm(mojo, "coffee-script", CoffeeScriptCompilerMojo.COFFEESCRIPT_VERSION); - File input = new File("target/test-classes/coffee"); + File input = new File("target/test-classes/coffee/test.coffee"); File output = new File("target/test/coffee"); output.mkdirs(); int exit = npm.execute("coffee", "--compile", "--map", "--output", output.getAbsolutePath(), diff --git a/core/wisdom-maven-plugin/src/test/resources/coffee/invalid.coffee b/core/wisdom-maven-plugin/src/test/resources/coffee/invalid.coffee new file mode 100644 index 000000000..e3f359a58 --- /dev/null +++ b/core/wisdom-maven-plugin/src/test/resources/coffee/invalid.coffee @@ -0,0 +1,3 @@ +number = 42 +opposite = true +Not a valid coffee file. \ No newline at end of file diff --git a/core/wisdom-maven-plugin/src/test/resources/less/invalid.less b/core/wisdom-maven-plugin/src/test/resources/less/invalid.less new file mode 100644 index 000000000..905c4aaab --- /dev/null +++ b/core/wisdom-maven-plugin/src/test/resources/less/invalid.less @@ -0,0 +1,5 @@ +// This file is not valid for testing purpose. +h1 { + font: this is not a valid less file. + color: red +} \ No newline at end of file