1 /*
2 * Copyright 2014-2015 Mark Prins, GeoDienstenCentrum.
3 * Copyright 2010-2014 Jasig.
4 *
5 * See the NOTICE file distributed with this work for additional information
6 * regarding copyright ownership.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package nl.geodienstencentrum.maven.plugin.sass.compiler;
21
22 import org.apache.maven.plugin.logging.Log;
23
24 /**
25 * Callback to bind <a
26 * href="http://sass-lang.com/docs/yardoc/Sass/Plugin/Compiler.html">Sass::Plugin::Compiler</a>.
27 */
28 public class CompilerCallback {
29 /** compiler error indicator. */
30 private boolean compileError;
31 /** maven logging instance. */
32 private final Log log;
33
34 /**
35 * Instantiates a new compiler callback.
36 *
37 * @param log
38 * the maven logging instance to use for messages
39 */
40 public CompilerCallback(final Log log) {
41 this.log = log;
42 }
43
44 /**
45 * Handle {@code on_compilation_error} event.
46 *
47 * @param error
48 * the error
49 * @param template
50 * the template
51 * @param css
52 * the css
53 * @see <a
54 * href="http://sass-lang.com/docs/yardoc/Sass/Plugin/Compiler.html#on_compilation_error-instance_method">
55 * on_compilation_error</a>
56 */
57 public void compilationError(final String error, final String template, final String css) {
58 this.log.error("Compilation of template " + template + " failed: "
59 + error);
60 this.compileError = true;
61 }
62
63 /**
64 * Handle {@code on_updated_stylesheet} event.
65 *
66 * @param template
67 * the template
68 * @param css
69 * the css
70 * @see <a
71 * href="http://sass-lang.com/docs/yardoc/Sass/Plugin/Compiler.html#on_updated_stylesheet-instance_method">
72 * on_updated_stylesheet</a>
73 */
74 public void updatedStylesheeet(final String template, final String css) {
75 this.log.info(" >> " + template + " => " + css);
76 }
77
78 /**
79 * Handle {@code on_template_modified} event.
80 *
81 * @param template
82 * the template
83 * @see <a
84 * href="http://sass-lang.com/docs/yardoc/Sass/Plugin/Compiler.html#on_template_modified-instance_method">
85 * on_template_modified</a>
86 */
87 public void templateModified(final String template) {
88 this.log.info("File Change detected " + template);
89 }
90
91 /**
92 * Handle {@code on_template_created} event.
93 *
94 * @param template
95 * the template
96 * @see <a
97 * href="http://sass-lang.com/docs/yardoc/Sass/Plugin/Compiler.html#on_template_created-instance_method">
98 * on_template_created</a>
99 */
100 public void templateCreated(final String template) {
101 this.log.info("New File detected " + template);
102 }
103
104 /**
105 * Handle {@code on_template_deleted} event.
106 *
107 * @param template
108 * the template
109 * @see <a
110 * href="http://sass-lang.com/docs/yardoc/Sass/Plugin/Compiler.html#on_template_deleted-instance_method">
111 * on_template_deleted</a>
112 */
113 public void templateDeleted(final String template) {
114 this.log.info("File Delete detected " + template);
115 }
116
117 /**
118 * Had error.
119 *
120 * @return {@code true} when there was an error
121 */
122 public boolean hadError() {
123 return this.compileError;
124 }
125 }