File tree Expand file tree Collapse file tree 4 files changed +32
-7
lines changed
qulice-checkstyle/src/main/java/com/qulice/checkstyle
main/java/com/qulice/maven
test/java/com/qulice/maven Expand file tree Collapse file tree 4 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ private static DetailAST secondChild(final DetailAST node) {
189189 * @return True if node contains angle brackets only
190190 */
191191 private static boolean isDiamondOperatorUsed (final DetailAST node ) {
192- return node .getChildCount () == 2
192+ return node != null && node .getChildCount () == 2
193193 && node .getFirstChild ().getType () == TokenTypes .GENERIC_START
194194 && node .getLastChild ().getType () == TokenTypes .GENERIC_END ;
195195 }
Original file line number Diff line number Diff line change @@ -106,6 +106,13 @@ public abstract class AbstractQuliceMojo extends AbstractMojo
106106 )
107107 private final Collection <String > asserts = new LinkedList <>();
108108
109+ /**
110+ * The source encoding.
111+ *
112+ * @parameter expression="${project.build.sourceEncoding}" required="true"
113+ */
114+ private String charset ;
115+
109116 /**
110117 * Set Maven Project (used mostly for unit testing).
111118 * @param proj The project to set
@@ -148,6 +155,14 @@ public final void setExcludes(final Collection<String> exprs) {
148155 this .excludes .addAll (exprs );
149156 }
150157
158+ /**
159+ * Set source code encoding.
160+ * @param encoding Source code encoding
161+ */
162+ public void setEncoding (final String encoding ) {
163+ this .charset = encoding ;
164+ }
165+
151166 @ Override
152167 public final void contextualize (final Context ctx ) {
153168 this .environment .setContext (ctx );
@@ -167,6 +182,7 @@ public final void execute() throws MojoFailureException {
167182 );
168183 this .environment .setExcludes (this .excludes );
169184 this .environment .setAsser (this .asserts );
185+ this .environment .setEncoding (this .charset );
170186 final long start = System .nanoTime ();
171187 this .doExecute ();
172188 Logger .info (
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ public final class DefaultMavenEnvironment implements MavenEnvironment {
9797 */
9898 private final Collection <String > asser = new LinkedList <>();
9999
100+ /**
101+ * Source code encoding charset.
102+ */
103+ private String charset = "UTF-8" ;
104+
100105 @ Override
101106 public String param (final String name , final String value ) {
102107 String ret = this .iproperties .getProperty (name );
@@ -293,16 +298,19 @@ public void setAsser(final Collection<String> ass) {
293298 this .asser .addAll (ass );
294299 }
295300
301+ public void setEncoding (final String encoding ) {
302+ this .charset = encoding ;
303+ }
304+
296305 /**
297306 * Get source files encoding.
298307 * @return Charset of the source files
299308 */
300309 public Charset encoding () {
301- String charset = this .iproject .getProperties ().getProperty ("project.build.sourceEncoding" );
302- if (charset == null ) {
303- charset = "UTF-8" ;
310+ if (this .charset == null || this .charset .isEmpty ()) {
311+ this .charset = "UTF-8" ;
304312 }
305- return Charset .forName (charset );
313+ return Charset .forName (this . charset );
306314 }
307315
308316 /**
Original file line number Diff line number Diff line change 3131package com .qulice .maven ;
3232
3333import com .google .common .collect .ImmutableList ;
34+ import java .nio .charset .StandardCharsets ;
3435import java .util .Collections ;
3536import org .apache .maven .project .MavenProject ;
3637import org .hamcrest .MatcherAssert ;
@@ -152,12 +153,12 @@ void producesEmptyExcludesWhenNoMatches() {
152153 * Default source files encoding should be UFT-8.
153154 */
154155 @ Test
155- void defaultEncodingIsUTF8 () {
156+ void defaultEncodingIsUtf () {
156157 final DefaultMavenEnvironment env = new DefaultMavenEnvironment ();
157158 MatcherAssert .assertThat (
158159 "Default encoding should be UTF-8" ,
159160 env .encoding (),
160- Matchers .is ("UTF-8" )
161+ Matchers .is (StandardCharsets . UTF_8 )
161162 );
162163 }
163164}
You can’t perform that action at this time.
0 commit comments