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

Commit 06c7a80

Browse files
author
Sandro Boehme
committed
Merge branch 'master' of git://github.com/learningobjectsinc/lesscss-maven-plugin into learningobjectsinc-master
Conflicts: README.md src/main/java/org/lesscss/mojo/CompileMojo.java
2 parents 8c91e85 + dbb7310 commit 06c7a80

File tree

5 files changed

+54
-57
lines changed

5 files changed

+54
-57
lines changed

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,26 @@ Example configuration for web project
5151
All configuration options
5252
-------------------------
5353

54-
+ outputDirectory (File) - The directory for compiled CSS stylesheets. Default value is: ${project.build.directory}.
55-
+ sourceDirectory (File) - The source directory containing the LESS sources. Default value is: ${project.basedir}/src/main/less.
56-
+ compress (boolean) - When true the LESS compiler will compress the CSS stylesheets. Default value is: false.
57-
+ encoding (String) The character encoding the LESS compiler will use for writing the CSS stylesheets. Default value is: ${project.build.sourceEncoding}.
58-
+ excludes (String[]) - List of files to exclude. Specified as fileset patterns which are relative to the source directory.
59-
+ force (boolean) - When true 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. Default value is: false.
60-
+ includes (String[]) - List of files to include. Specified as fileset patterns which are relative to the source directory. Default value is: { "**\/*.less" }
61-
+ lessJs (String) - The location of the LESS JavasSript file.
62-
+ watch (boolean) - When true the plugin watches the sourceDirectory and recompiles the included files after they changed. Instead of configuring it in the pom you can use that option at the command line like this "mvn lesscss:compile -Dlesscss.watch=true". Then it doesn't interfere with other maven lifecycle phases and you can just kill the watch process e.g. with crtl-c. Default value is: false.
63-
+ watchInterval (int) - The interval in milliseconds the plugin waits between the check for file changes. Default value is: 1000 ms.
64-
+ skip (boolean) - Whether to skip plugin execution. Default value is: false.
54+
+ **outputDirectory** `File` - The directory for compiled CSS stylesheets. Default value is: ${project.build.directory}.
55+
56+
+ **sourceDirectory** `File` - The source directory containing the LESS sources. Default value is: ${project.basedir}/src/main/less.
57+
58+
+ **compress** `boolean` - When true the LESS compiler will compress the CSS stylesheets. Default value is: false.
59+
+ **encoding** `String` The character encoding the LESS compiler will use for writing the CSS stylesheets. Default value is: ${project.build.sourceEncoding}.
60+
61+
+ **excludes** `String[]` - List of files to exclude. Specified as fileset patterns which are relative to the source directory.
62+
63+
+ **force** `boolean` - When true 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. Default value is: false.
64+
65+
+ **includes** `String[]` - List of files to include. Specified as fileset patterns which are relative to the source directory. Default value is: { "**\/*.less" }
66+
67+
+ **lessJs** `String` - The location of the LESS JavaScript file.
68+
69+
+ **watch** `boolean` - When true the plugin watches the sourceDirectory and recompiles the included files after they changed. Instead of configuring it in the pom you can use that option at the command line like this "mvn lesscss:compile -Dlesscss.watch=true". Then it doesn't interfere with other maven lifecycle phases and you can just kill the watch process e.g. with crtl-c. Default value is: false.
70+
71+
+ **watchInterval** `int` - The interval in milliseconds the plugin waits between the check for file changes. Default value is: 1000 ms.
72+
73+
+ **outputFileFormat** `String` - The format of the output files. Default is: '{fileName}.css'. examples: '{fileName}.min.css', 'min-{fileName}.css', '{fileName}.anything'.
6574

6675
List sources
6776
------------

src/it/filename-suffix/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.lesscss.it</groupId>
5-
<artifactId>filena-emsuffix</artifactId>
5+
<artifactId>filename-suffix</artifactId>
66
<version>testing</version>
77

88
<build>
@@ -12,7 +12,7 @@
1212
<artifactId>lesscss-maven-plugin</artifactId>
1313
<version>@project.version@</version>
1414
<configuration>
15-
<outputFileSuffix>-1.33.7</outputFileSuffix>
15+
<outputFileFormat>min-{fileName}-1.33.7.css</outputFileFormat>
1616
</configuration>
1717
<executions>
1818
<execution>

src/it/filename-suffix/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ h2 {
77
88
"""
99

10-
css = new File(basedir, "target/test-1.33.7.css")
10+
css = new File(basedir, "target/min-test-1.33.7.css")
1111
assert css.exists()
1212
assert css.getText().equals(expected)

src/main/java/org/lesscss/mojo/CompileMojo.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ public class CompileMojo extends AbstractLessCssMojo {
4343
*/
4444
protected File outputDirectory;
4545

46-
/**
47-
* An optional suffix to append to each output filename, before the .less extension
48-
*
49-
* @parameter expression="${lesscss.outputFileSuffix}"
50-
*/
51-
private String outputFileSuffix = "";
52-
5346
/**
5447
* When <code>true</code> the LESS compiler will compress the CSS stylesheets.
5548
*
@@ -98,6 +91,15 @@ public class CompileMojo extends AbstractLessCssMojo {
9891
* @parameter
9992
*/
10093
private String nodeExecutable;
94+
95+
/**
96+
* The format of the output file names.
97+
*
98+
* @parameter
99+
*/
100+
private String outputFileFormat;
101+
102+
private static final String FILE_NAME_FORMAT_PARAMETER_REGEX = "\\{fileName\\}";
101103

102104
/**
103105
* Execute the MOJO.
@@ -109,7 +111,6 @@ public void execute() throws MojoExecutionException {
109111
if (getLog().isDebugEnabled()) {
110112
getLog().debug("sourceDirectory = " + sourceDirectory);
111113
getLog().debug("outputDirectory = " + outputDirectory);
112-
getLog().debug("outputFileSuffix = " + outputFileSuffix);
113114
getLog().debug("includes = " + Arrays.toString(includes));
114115
getLog().debug("excludes = " + Arrays.toString(excludes));
115116
getLog().debug("force = " + force);
@@ -167,10 +168,11 @@ private void compileIfChanged(String[] files, Object lessCompiler) throws MojoEx
167168

168169
buildContext.removeMessages(input);
169170

170-
String filename = file.replace(".less", "%s.css");
171-
filename = String.format(filename, outputFileSuffix);
171+
if(outputFileFormat != null){
172+
file = outputFileFormat.replaceAll(FILE_NAME_FORMAT_PARAMETER_REGEX, file.replace(".less", ""));
173+
}
172174

173-
File output = new File(outputDirectory, filename);
175+
File output = new File(outputDirectory, file.replace(".less", ".css"));
174176

175177
if (!output.getParentFile().exists() && !output.getParentFile().mkdirs()) {
176178
throw new MojoExecutionException("Cannot create output directory " + output.getParentFile());

src/test/java/org/lesscss/mojo/CompileMojoTest.java

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,8 @@ public void testExecutionMakeDirsWhenOutputDirectoryDoesNotExists() throws Excep
442442
verify(lessCompiler).compile(lessSource, output, false);
443443
}
444444

445-
@Test
446-
public void testExecutionAddsSuffixToFilenameIfSpecified() throws Exception {
447-
448-
setVariableValueToObject(mojo, "outputFileSuffix", "-1.33.7");
449-
445+
@Test(expected = MojoExecutionException.class)
446+
public void testExecutionMakeDirsFailsWhenOutputDirectoryDoesNotExists() throws Exception {
450447
files = new String[] { "less.less" };
451448

452449
when(buildContext.newScanner(sourceDirectory, true)).thenReturn(scanner);
@@ -455,18 +452,11 @@ public void testExecutionAddsSuffixToFilenameIfSpecified() throws Exception {
455452
whenNew(LessCompiler.class).withNoArguments().thenReturn(lessCompiler);
456453

457454
whenNew(File.class).withArguments(sourceDirectory, "less.less").thenReturn(input);
458-
whenNew(File.class).withArguments(outputDirectory, "less-1.33.7.css").thenReturn(output);
455+
whenNew(File.class).withArguments(outputDirectory, "less.css").thenReturn(output);
459456

460-
when(output.exists()).thenReturn(true);
461457
when(output.getParentFile()).thenReturn(parent);
462458
when(parent.exists()).thenReturn(false);
463-
when(parent.mkdirs()).thenReturn(true);
464-
465-
whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
466-
467-
when(output.lastModified()).thenReturn(1l);
468-
when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l);
469-
459+
when(parent.mkdirs()).thenReturn(false);
470460

471461
mojo.execute();
472462

@@ -480,23 +470,17 @@ public void testExecutionAddsSuffixToFilenameIfSpecified() throws Exception {
480470
verify(lessCompiler).setEncoding(null);
481471

482472
verifyNew(File.class).withArguments(sourceDirectory, "less.less");
483-
verifyNew(File.class).withArguments(outputDirectory, "less-1.33.7.css");
473+
verifyNew(File.class).withArguments(outputDirectory, "less.css");
484474

485475
verify(output, times(2)).getParentFile();
486476
verify(parent).exists();
487477
verify(parent).mkdirs();
488-
489-
verifyNew(LessSource.class).withArguments(input);
490-
491-
verify(output).lastModified();
492-
verify(lessSource).getLastModifiedIncludingImports();
493-
494-
verify(log).info("Compiling LESS source: less.less...");
495-
verify(lessCompiler).compile(lessSource, output, false);
496478
}
497-
498-
@Test(expected = MojoExecutionException.class)
499-
public void testExecutionMakeDirsFailsWhenOutputDirectoryDoesNotExists() throws Exception {
479+
480+
@Test
481+
public void testExecutionOutputFilesNamedFromOutputFileFormat() throws Exception {
482+
483+
setVariableValueToObject(mojo, "outputFileFormat", "{fileName}-min.css");
500484
files = new String[] { "less.less" };
501485

502486
when(buildContext.newScanner(sourceDirectory, true)).thenReturn(scanner);
@@ -505,11 +489,14 @@ public void testExecutionMakeDirsFailsWhenOutputDirectoryDoesNotExists() throws
505489
whenNew(LessCompiler.class).withNoArguments().thenReturn(lessCompiler);
506490

507491
whenNew(File.class).withArguments(sourceDirectory, "less.less").thenReturn(input);
508-
whenNew(File.class).withArguments(outputDirectory, "less.css").thenReturn(output);
492+
whenNew(File.class).withArguments(outputDirectory, "less-min.css").thenReturn(output);
509493

510494
when(output.getParentFile()).thenReturn(parent);
511-
when(parent.exists()).thenReturn(false);
512-
when(parent.mkdirs()).thenReturn(false);
495+
when(parent.exists()).thenReturn(true);
496+
when(parent.mkdirs()).thenReturn(true);
497+
498+
whenNew(LessSource.class).withArguments(input).thenReturn(lessSource);
499+
513500

514501
mojo.execute();
515502

@@ -523,11 +510,10 @@ public void testExecutionMakeDirsFailsWhenOutputDirectoryDoesNotExists() throws
523510
verify(lessCompiler).setEncoding(null);
524511

525512
verifyNew(File.class).withArguments(sourceDirectory, "less.less");
526-
verifyNew(File.class).withArguments(outputDirectory, "less.css");
513+
verifyNew(File.class).withArguments(outputDirectory, "less-min.css");
527514

528-
verify(output, times(2)).getParentFile();
515+
verify(output, times(1)).getParentFile();
529516
verify(parent).exists();
530-
verify(parent).mkdirs();
531517
}
532518

533519
@After

0 commit comments

Comments
 (0)