Skip to content
This repository was archived by the owner on Jan 9, 2019. It is now read-only.

Add configuration property that allows you to specify the encoding of LESS files #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>org.lesscss</groupId>
<artifactId>lesscss</artifactId>
<version>1.3.3</version>
<version>1.3.3.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/org/lesscss/mojo/CompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.MalformedURLException;
import java.util.Arrays;

import org.apache.commons.io.Charsets;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.StringUtils;
import org.lesscss.LessCompiler;
Expand Down Expand Up @@ -53,9 +54,16 @@ public class CompileMojo extends AbstractLessCssMojo {
/**
* The character encoding the LESS compiler will use for writing the CSS stylesheets.
*
* @parameter expression="${lesscss.encoding}" default-value="${project.build.sourceEncoding}"
* @parameter expression="${lesscss.outputEncoding}" default-value="${project.build.sourceEncoding}"
*/
private String encoding;
private String outputEncoding;

/**
* The character encoding the LESS compiler will use for writing the CSS stylesheets.
*
* @parameter expression="${lesscss.inputEncoding}" default-value="${project.build.sourceEncoding}"
*/
private String inputEncoding;

/**
* When <code>true</code> forces the LESS compiler to always compile the LESS sources. By default LESS sources are only compiled when modified (including imports) or the CSS stylesheet does not exists.
Expand Down Expand Up @@ -101,7 +109,8 @@ public void execute() throws MojoExecutionException {

LessCompiler lessCompiler = new LessCompiler();
lessCompiler.setCompress(compress);
lessCompiler.setEncoding(encoding);
lessCompiler.setInputEncoding(inputEncoding);
lessCompiler.setOutputEncoding(outputEncoding);

if (lessJs != null) {
try {
Expand All @@ -124,7 +133,7 @@ public void execute() throws MojoExecutionException {
}

try {
LessSource lessSource = new LessSource(input);
LessSource lessSource = new LessSource(input, Charsets.toCharset(inputEncoding));

if (output.lastModified() < lessSource.getLastModifiedIncludingImports()) {
getLog().info("Compiling LESS source: " + file + "...");
Expand Down
44 changes: 23 additions & 21 deletions src/test/java/org/lesscss/mojo/CompileMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.commons.io.Charsets;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void testExecution() throws Exception {
when(output.getParentFile()).thenReturn(parent);
when(parent.exists()).thenReturn(true);

whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
whenNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null)).thenReturn(lessSource);

when(output.lastModified()).thenReturn(1l);
when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l);
Expand All @@ -138,15 +139,15 @@ public void testExecution() throws Exception {

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
verifyNew(File.class).withArguments(outputDirectory, "less.css");

verify(output).getParentFile();
verify(parent).exists();

verifyNew(LessSource.class).withArguments(input);
verifyNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null));

verify(output).lastModified();
verify(lessSource).getLastModifiedIncludingImports();
Expand All @@ -170,7 +171,7 @@ public void testExecutionNotModified() throws Exception {
when(output.getParentFile()).thenReturn(parent);
when(parent.exists()).thenReturn(true);

whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
whenNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null)).thenReturn(lessSource);

when(output.lastModified()).thenReturn(2l);
when(lessSource.getLastModifiedIncludingImports()).thenReturn(1l);
Expand All @@ -184,17 +185,18 @@ public void testExecutionNotModified() throws Exception {

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);
verify(lessCompiler).setInputEncoding(null);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
verifyNew(File.class).withArguments(outputDirectory, "less.css");

verify(output).getParentFile();
verify(parent).exists();

verifyNew(LessSource.class).withArguments(input);
verifyNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null));
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);

verify(output).lastModified();
verify(lessSource).getLastModifiedIncludingImports();
Expand Down Expand Up @@ -242,7 +244,7 @@ public void testExecutionIOExceptionWhenCreatingLessSource() throws Exception {
when(output.getParentFile()).thenReturn(parent);
when(parent.exists()).thenReturn(true);

whenNew(LessSource.class).withArguments(input).thenThrow(new IOException());
whenNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null)).thenThrow(new IOException());

mojo.execute();

Expand All @@ -253,15 +255,15 @@ public void testExecutionIOExceptionWhenCreatingLessSource() throws Exception {

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
verifyNew(File.class).withArguments(outputDirectory, "less.css");

verify(output).getParentFile();
verify(parent).exists();

verifyNew(LessSource.class).withArguments(input);
verifyNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null));
}

@Test(expected = MojoExecutionException.class)
Expand All @@ -279,7 +281,7 @@ public void testExecutionLessExceptionWhenCompilingLessSource() throws Exception
when(output.getParentFile()).thenReturn(parent);
when(parent.exists()).thenReturn(true);

whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
whenNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null)).thenReturn(lessSource);

when(output.lastModified()).thenReturn(1l);
when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l);
Expand All @@ -295,15 +297,15 @@ public void testExecutionLessExceptionWhenCompilingLessSource() throws Exception

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
verifyNew(File.class).withArguments(outputDirectory, "less.css");

verify(output).getParentFile();
verify(parent).exists();

verifyNew(LessSource.class).withArguments(input);
verifyNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null));

verify(output).lastModified();
verify(lessSource).getLastModifiedIncludingImports();
Expand Down Expand Up @@ -332,7 +334,7 @@ public void testExecutionWithCustomLessJs() throws Exception {
when(output.getParentFile()).thenReturn(parent);
when(parent.exists()).thenReturn(true);

whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
whenNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null)).thenReturn(lessSource);

when(output.lastModified()).thenReturn(1l);
when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l);
Expand All @@ -346,7 +348,7 @@ public void testExecutionWithCustomLessJs() throws Exception {

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);
verify(lessCompiler).setLessJs(lessJsURL);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
Expand All @@ -355,7 +357,7 @@ public void testExecutionWithCustomLessJs() throws Exception {
verify(output).getParentFile();
verify(parent).exists();

verifyNew(LessSource.class).withArguments(input);
verifyNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null));

verify(output).lastModified();
verify(lessSource).getLastModifiedIncludingImports();
Expand Down Expand Up @@ -387,7 +389,7 @@ public void testExecutionMalformedURLExceptionWhenCustomLessJs() throws Exceptio

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);
}

@Test
Expand All @@ -406,7 +408,7 @@ public void testExecutionMakeDirsWhenOutputDirectoryDoesNotExists() throws Excep
when(parent.exists()).thenReturn(false);
when(parent.mkdirs()).thenReturn(true);

whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
whenNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null)).thenReturn(lessSource);

when(output.lastModified()).thenReturn(1l);
when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l);
Expand All @@ -420,7 +422,7 @@ public void testExecutionMakeDirsWhenOutputDirectoryDoesNotExists() throws Excep

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
verifyNew(File.class).withArguments(outputDirectory, "less.css");
Expand All @@ -429,7 +431,7 @@ public void testExecutionMakeDirsWhenOutputDirectoryDoesNotExists() throws Excep
verify(parent).exists();
verify(parent).mkdirs();

verifyNew(LessSource.class).withArguments(input);
verifyNew(LessSource.class).withArguments(input, Charsets.toCharset((String)null));

verify(output).lastModified();
verify(lessSource).getLastModifiedIncludingImports();
Expand Down Expand Up @@ -463,7 +465,7 @@ public void testExecutionMakeDirsFailsWhenOutputDirectoryDoesNotExists() throws

verifyNew(LessCompiler.class).withNoArguments();
verify(lessCompiler).setCompress(false);
verify(lessCompiler).setEncoding(null);
verify(lessCompiler).setOutputEncoding(null);

verifyNew(File.class).withArguments(sourceDirectory, "less.less");
verifyNew(File.class).withArguments(outputDirectory, "less.css");
Expand Down