Skip to content

Commit

Permalink
Fix #488
Browse files Browse the repository at this point in the history
Also update the less version to 1.7.5 (as #481 is postponed)

Signed-off-by: Clement Escoffier <[email protected]>
  • Loading branch information
cescoffier committed Apr 26, 2015
1 parent 619072d commit 4f716bd
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -60,7 +61,7 @@ public class CoffeeScriptCompilerMojo extends AbstractWisdomWatcherMojo implemen
*
* @see <a href="https://www.npmjs.org/">NPM Web Site</a>.
*/
@Parameter(defaultValue = "1.8.0")
@Parameter(defaultValue = COFFEESCRIPT_VERSION)
String coffeeScriptVersion;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -64,7 +65,7 @@ public class LessCompilerMojo extends AbstractWisdomWatcherMojo implements Const
*
* @see <a href="https://www.npmjs.org/">NPM Web Site</a>.
*/
@Parameter(defaultValue = "1.7.3")
@Parameter(defaultValue = LESS_VERSION)
String lessVersion;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
number = 42
opposite = true
Not a valid coffee file.
5 changes: 5 additions & 0 deletions core/wisdom-maven-plugin/src/test/resources/less/invalid.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file is not valid for testing purpose.
h1 {
font: this is not a valid less file.
color: red
}

0 comments on commit 4f716bd

Please sign in to comment.