From 2da99a2cac7451d2f7c11dc704395575b8b1e922 Mon Sep 17 00:00:00 2001 From: Juergen Bruester Date: Thu, 13 Oct 2011 12:47:12 +0200 Subject: [PATCH 1/3] Adds encoding property and default fallback because less engine uses FileWriter in formerly used method which uses default encoding. When using before- or after-elements in css this can result in encoding problems on a website. --- pom.xml | 19 ++- .../maven/plugins/lesscss/CompileMojo.java | 127 +++++++++++------- 2 files changed, 88 insertions(+), 58 deletions(-) diff --git a/pom.xml b/pom.xml index c24627c..dc49d0d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - eu.numberfour.maven.plugins + de.dumontnet.maven.plugins lesscss-maven-plugin - 1.0.41-SNAPSHOT + 1.0.42-SNAPSHOT maven-plugin LessCSS plugin @@ -19,6 +19,11 @@ Leonard Ehrenfried leonard.ehrenfried@web.de + + crushcoder + Jürgen Brüster + jb@devilscab.de + @@ -27,12 +32,12 @@ - https://github.com/NumberFour/file-list-maven-plugin#readme + https://github.com/crushcoder/lesscss-maven-pluginn#readme - scm:git:git://github.com/NumberFour/file-list-maven-plugin.git - scm:git:git@github.com:NumberFour/file-list-maven-plugin.git - https://github.com/NumberFour/file-list-maven-plugin#readme + scm:git:git://github.com/crushcoder/lesscss-maven-plugin.git + scm:git:git@github.com:crushcoder/lesscss-maven-plugin.git + https://github.com/crushcoder/lesscss-maven-plugin#readme @@ -47,7 +52,7 @@ com.asual.lesscss lesscss-engine - 1.0.41 + 1.2.11 diff --git a/src/main/java/eu/numberfour/maven/plugins/lesscss/CompileMojo.java b/src/main/java/eu/numberfour/maven/plugins/lesscss/CompileMojo.java index f3c94e4..f567f38 100644 --- a/src/main/java/eu/numberfour/maven/plugins/lesscss/CompileMojo.java +++ b/src/main/java/eu/numberfour/maven/plugins/lesscss/CompileMojo.java @@ -2,9 +2,6 @@ import com.asual.lesscss.LessEngine; import com.asual.lesscss.LessException; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -12,6 +9,10 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.DirectoryScanner; +import java.io.*; +import java.nio.charset.Charset; +import java.util.Arrays; + /** *

* Compiles LessCSS files as part of the standard Maven build process. @@ -69,59 +70,83 @@ public class CompileMojo extends AbstractMojo { */ public boolean caseSensitive; + /** + * Encoding to use for output file. + * Defaults to "project.build.sourceEncoding" or platform encoding if not specified. + * + * @parameter default-value="${project.build.sourceEncoding}" + */ + private String encoding; + public void execute() throws MojoExecutionException, MojoFailureException { - try { - - if(includes == null){ - includes = new String[1]; - includes[0]="**/*.less"; + if(includes == null){ + includes = new String[1]; + includes[0]="**/*.less"; + } + + Charset charset = Charset.defaultCharset(); + if(encoding != null) { + charset = Charset.forName(encoding); + } + + Log log = getLog(); + log.info(""); + log.info("Creating file list"); + log.info("Source dir: " + sourceDir); + log.info("Output dir: " + outputDir); + log.info("Includes: " + Arrays.toString(includes)); + log.info("Excludes: " + Arrays.toString(excludes)); + log.info("Using '" + charset.displayName() + "' encoding for output file(s)"); + + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(sourceDir); + scanner.setIncludes(includes); + scanner.setExcludes(excludes); + scanner.setCaseSensitive(caseSensitive); + scanner.scan(); + + String[] includedFiles = scanner.getIncludedFiles(); + + log.info("Found " + includedFiles.length + " less files."); + log.info(""); + + LessEngine engine = new LessEngine(); + + for (String i:includedFiles){ + File inputFile = new File(sourceDir+i); + File outputFile = new File(outputDir+'/'+i.replaceAll(".less$", ".css")); + + File outputDir_ = new File(outputFile.getParent()); + if(!outputDir_.exists()){ + outputDir_.mkdirs(); } - - Log log = getLog(); - log.info(""); - log.info("Creating file list"); - log.info("Source dir: " + sourceDir); - log.info("Output dir: " + outputDir); - log.info("Includes: " + Arrays.toString(includes)); - log.info("Excludes: " + Arrays.toString(excludes)); - - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir(sourceDir); - scanner.setIncludes(includes); - scanner.setExcludes(excludes); - scanner.setCaseSensitive(caseSensitive); - scanner.scan(); - - String[] includedFiles = scanner.getIncludedFiles(); - - log.info("Found " + includedFiles.length + " less files."); - log.info(""); - - LessEngine engine = new LessEngine(); - - for (String i:includedFiles){ - File inputFile = new File(sourceDir+i); - File outputFile = new File(outputDir+'/'+i.replaceAll(".less$", ".css")); - - File outputDir_ = new File(outputFile.getParent()); - if(!outputDir_.exists()){ - outputDir_.mkdirs(); - } - - if(log.isDebugEnabled()){ - log.debug("Compiling "+inputFile.toString() +" to "+outputFile.toString()); + + if(log.isDebugEnabled()){ + log.debug("Compiling "+inputFile.toString() +" to "+outputFile.toString()); + } + else{ + log.info("Compiling "+i); + } + + BufferedWriter bw = null; + try { + String output = engine.compile(inputFile); + if (!outputFile.exists()) { + outputFile.createNewFile(); } - else{ - log.info("Compiling "+i); + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), charset)); + bw.write(output); + } catch (IOException ex) { + throw new MojoFailureException(ex, "IO Exception", "IO Exception while compiling less files."); + } catch (LessException ex) { + throw new MojoFailureException(ex, ex.getMessage(), ex.getMessage()); + } finally { + try { + bw.close(); + } catch (IOException ex2) { + throw new MojoFailureException(ex2, "IO Exception", "IO Exception while closing output stream."); } - - engine.compile(inputFile, outputFile); } - - } catch (IOException ex) { - throw new MojoFailureException(ex, "IO Exception", "IO Exception while compiling less files."); - } catch (LessException ex) { - throw new MojoFailureException(ex, ex.getMessage(), ex.getMessage()); } } } From 79fdf5b4174259b93c6c35b77ded64252c7f7704 Mon Sep 17 00:00:00 2001 From: Juergen Bruester Date: Mon, 17 Oct 2011 08:56:34 +0200 Subject: [PATCH 2/3] [maven-release-plugin] prepare release lesscss-maven-plugin-1.0.42 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dc49d0d..e3c6dc2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.dumontnet.maven.plugins lesscss-maven-plugin - 1.0.42-SNAPSHOT + 1.0.42 maven-plugin LessCSS plugin From 6236b8783c749221cc5ced1e1a01f8ce740274ed Mon Sep 17 00:00:00 2001 From: Juergen Bruester Date: Mon, 17 Oct 2011 08:56:40 +0200 Subject: [PATCH 3/3] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e3c6dc2..bc9b87e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.dumontnet.maven.plugins lesscss-maven-plugin - 1.0.42 + 1.0.43-SNAPSHOT maven-plugin LessCSS plugin