22
22
import biz .gabrys .lesscss .compiler2 .util .StringUtils ;
23
23
24
24
/**
25
- * Options that control the <a href="http://lesscss.org/">Less</a> compilation process.
25
+ * Responsible for creating options that control the {@link NativeLessCompiler} compilation process.
26
26
* @since 2.0.0
27
27
* @see <a href="http://lesscss.org/usage/index.html#command-line-usage-options">Less options</a>
28
28
*/
29
29
public class NativeLessCompilerOptionsBuilder {
30
30
31
- /**
32
- * The operating system software checker responsible for verifing system distriubution.
33
- * @since 2.0.0
34
- */
35
- protected OperatingSystemChecker systemChecker ;
36
-
37
31
private File input ;
38
32
private File output ;
39
33
private boolean silent ;
@@ -43,6 +37,9 @@ public class NativeLessCompilerOptionsBuilder {
43
37
private boolean javaScriptEnabled = true ;
44
38
private List <String > includePaths = Collections .emptyList ();
45
39
private LineNumbersValue lineNumbers = LineNumbersValue .DISABLED ;
40
+ private boolean sourceMapDefault ;
41
+ private File sourceMapFile ;
42
+ private boolean sourceMapInline ;
46
43
private String rootPath ;
47
44
private boolean relativeUrls ;
48
45
private boolean strictMath ;
@@ -53,22 +50,7 @@ public class NativeLessCompilerOptionsBuilder {
53
50
* @since 2.0.0
54
51
*/
55
52
public NativeLessCompilerOptionsBuilder () {
56
- systemChecker = new OperatingSystemChecker () {
57
-
58
- @ Override
59
- public boolean isWindows () {
60
- return System .getProperty ("os.name" ).startsWith ("Windows" );
61
- }
62
- };
63
- }
64
-
65
- /**
66
- * Constructs a new instance.
67
- * @param systemChecker the operating system software checker.
68
- * @since 2.0.0
69
- */
70
- public NativeLessCompilerOptionsBuilder (final OperatingSystemChecker systemChecker ) {
71
- this .systemChecker = systemChecker ;
53
+ // do nothing
72
54
}
73
55
74
56
/**
@@ -252,10 +234,9 @@ protected String getJavaScriptEnabledCompilerOption() {
252
234
}
253
235
254
236
/**
255
- * Sets available include paths (default: empty collection). Separated by ':' or ';' on Windows. If the file in an
256
- * @import rule does not exist at that exact location, less will look for it at the location(s) passed to this
257
- * option. You might use this for instance to specify a path to a library which you want to be referenced simply and
258
- * relatively in the less files.
237
+ * Sets available include paths (default: empty collection). If the file in an @import rule does not exist at
238
+ * that exact location, less will look for it at the location(s) passed to this option. You might use this for
239
+ * instance to specify a path to a library which you want to be referenced simply and relatively in the less files.
259
240
* @param includePaths the available include paths.
260
241
* @return {@code this} builder.
261
242
* @since 2.0.0
@@ -284,7 +265,7 @@ protected String getIncludePathsCompilerOption() {
284
265
if (StringUtils .isNotBlank (path )) {
285
266
final boolean separatorRequired = paths .length () != 0 ;
286
267
if (separatorRequired ) {
287
- paths .append (systemChecker . isWindows () ? ';' : ':' );
268
+ paths .append (NativeLessCompiler . INCLUDE_PATHS_SEPARATOR );
288
269
}
289
270
paths .append (path .trim ());
290
271
}
@@ -318,6 +299,110 @@ protected String getLineNumbersCompilerOption() {
318
299
}
319
300
}
320
301
302
+ /**
303
+ * Sets whether a compiler should generate a Source Map file with a default name equal to
304
+ * {@link #withOutputFile(File) output file name} plus {@code .map} suffix. It does not matter whether you call this
305
+ * method before or after the {@link #withOutputFile(File)} method.
306
+ * <p>
307
+ * This method clears bulider's data set by the {@link #withSourceMapFile(File)} and the
308
+ * {@link #withSourceMapInline(boolean)} methods.
309
+ * </p>
310
+ * @param enabled {@code true} whether the compiler should generate the Source Map file, otherwise {@code false}.
311
+ * @return {@code this} builder.
312
+ * @since 2.0.0
313
+ * @see #withOutputFile(File)
314
+ * @see #withSourceMapFile(File)
315
+ * @see #withSourceMapInline(boolean)
316
+ */
317
+ public NativeLessCompilerOptionsBuilder withSourceMapDefault (final boolean enabled ) {
318
+ sourceMapDefault = enabled ;
319
+ sourceMapFile = null ;
320
+ sourceMapInline = false ;
321
+ return this ;
322
+ }
323
+
324
+ /**
325
+ * Returns a command line option which enables/disables generating a Source Map file with default name.
326
+ * @return the command line option (never {@code null}).
327
+ * @since 2.0.0
328
+ * @see #withSourceMapDefault(boolean)
329
+ */
330
+ protected String getSourceMapDefaultCompilerOption () {
331
+ if (sourceMapDefault ) {
332
+ return "--source-map" ;
333
+ } else {
334
+ return "" ;
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Sets whether a compiler should generate a Source Map file.
340
+ * <p>
341
+ * This method clears bulider's data set by the {@link #withSourceMapDefault(boolean)} and the
342
+ * {@link #withSourceMapInline(boolean)} methods.
343
+ * </p>
344
+ * @param sourceMap the Source Map file.
345
+ * @return {@code this} builder.
346
+ * @since 2.0.0
347
+ * @see #withSourceMapDefault(boolean)
348
+ * @see #withSourceMapInline(boolean)
349
+ */
350
+ public NativeLessCompilerOptionsBuilder withSourceMapFile (final File sourceMap ) {
351
+ sourceMapDefault = false ;
352
+ sourceMapFile = sourceMap ;
353
+ sourceMapInline = false ;
354
+ return this ;
355
+ }
356
+
357
+ /**
358
+ * Returns a command line option which enables/disables generating a Source Map file.
359
+ * @return the command line option (never {@code null}).
360
+ * @since 2.0.0
361
+ * @see #withSourceMapFile(File)
362
+ */
363
+ protected String getSourceMapFileCompilerOption () {
364
+ if (sourceMapFile != null ) {
365
+ return "--source-map=" + sourceMapFile .getAbsolutePath ();
366
+ } else {
367
+ return "" ;
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Sets whether a compiler should generate a Source Map and put it to CSS code. This is not recommended for
373
+ * production, but for development it allows the compiler to produce a single output file which in browsers that
374
+ * support it, use the compiled CSS but show you the non-compiled Less source.
375
+ * <p>
376
+ * This method clears bulider's data set by the {@link #withSourceMapDefault(boolean)} and the
377
+ * {@link #withSourceMapFile(File)} methods.
378
+ * </p>
379
+ * @param inline {@code true} whether the compiler should generate a Source Map, otherwise {@code false}.
380
+ * @return {@code this} builder.
381
+ * @since 2.0.0
382
+ * @see #withSourceMapDefault(boolean)
383
+ * @see #withSourceMapFile(File)
384
+ */
385
+ public NativeLessCompilerOptionsBuilder withSourceMapInline (final boolean inline ) {
386
+ sourceMapDefault = false ;
387
+ sourceMapFile = null ;
388
+ sourceMapInline = inline ;
389
+ return this ;
390
+ }
391
+
392
+ /**
393
+ * Returns a command line options which enables/disables generating a Source Map which will be put to CSS code.
394
+ * @return the command line options (never {@code null}).
395
+ * @since 2.0.0
396
+ * @see #withSourceMapInline(boolean)
397
+ */
398
+ protected String [] getSourceMapInlineCompilerOptions () {
399
+ if (sourceMapInline ) {
400
+ return new String [] { "--source-map" , "--source-map-map-inline" };
401
+ } else {
402
+ return new String [0 ];
403
+ }
404
+ }
405
+
321
406
///////
322
407
// TODO source maps
323
408
///////
@@ -522,6 +607,11 @@ public Collection<Object> create() {
522
607
options .add (getJavaScriptEnabledCompilerOption ());
523
608
options .add (getIncludePathsCompilerOption ());
524
609
options .add (getLineNumbersCompilerOption ());
610
+
611
+ options .add (getSourceMapDefaultCompilerOption ());
612
+ options .add (getSourceMapFileCompilerOption ());
613
+ options .add (getSourceMapInlineCompilerOptions ());
614
+
525
615
options .add (getRootPathCompilerOption ());
526
616
options .add (getRelativeUrlsCompilerOption ());
527
617
options .add (getStrictMathCompilerOption ());
@@ -539,20 +629,6 @@ public Collection<Object> create() {
539
629
return options .create ();
540
630
}
541
631
542
- /**
543
- * Responsible for checking operating system family.
544
- * @since 2.0.0
545
- */
546
- public interface OperatingSystemChecker {
547
-
548
- /**
549
- * Tests whether operating system is <a href="http://www.microsoft.com/">Windows</a>.
550
- * @return {@code true} whether operating system is Windows, otherwise {@code false}.
551
- * @since 2.0.0
552
- */
553
- boolean isWindows ();
554
- }
555
-
556
632
/**
557
633
* Available values for {@link NativeLessCompilerOptionsBuilder#withLineNumbers(LineNumbersValue) line numbers}
558
634
* option.
0 commit comments