Skip to content

Commit ac58393

Browse files
committed
Merge branch '__rultor'
2 parents 9b3606d + 0bd5241 commit ac58393

File tree

10 files changed

+102
-3
lines changed

10 files changed

+102
-3
lines changed

qulice-checkstyle/src/main/java/com/qulice/checkstyle/DiamondOperatorCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

qulice-maven-plugin/src/main/java/com/qulice/maven/AbstractQuliceMojo.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ 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+
@Parameter(property = "encoding", defaultValue = "${project.build.sourceEncoding}")
115+
private String charset;
116+
109117
/**
110118
* Set Maven Project (used mostly for unit testing).
111119
* @param proj The project to set
@@ -148,6 +156,14 @@ public final void setExcludes(final Collection<String> exprs) {
148156
this.excludes.addAll(exprs);
149157
}
150158

159+
/**
160+
* Set source code encoding.
161+
* @param encoding Source code encoding
162+
*/
163+
public void setEncoding(final String encoding) {
164+
this.charset = encoding;
165+
}
166+
151167
@Override
152168
public final void contextualize(final Context ctx) {
153169
this.environment.setContext(ctx);
@@ -167,6 +183,7 @@ public final void execute() throws MojoFailureException {
167183
);
168184
this.environment.setExcludes(this.excludes);
169185
this.environment.setAsser(this.asserts);
186+
this.environment.setEncoding(this.charset);
170187
final long start = System.nanoTime();
171188
this.doExecute();
172189
Logger.info(

qulice-maven-plugin/src/main/java/com/qulice/maven/DefaultMavenEnvironment.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.net.URI;
4242
import java.net.URL;
4343
import java.net.URLClassLoader;
44+
import java.nio.charset.Charset;
4445
import java.security.PrivilegedAction;
4546
import java.util.Collection;
4647
import java.util.LinkedList;
@@ -96,6 +97,11 @@ public final class DefaultMavenEnvironment implements MavenEnvironment {
9697
*/
9798
private final Collection<String> asser = new LinkedList<>();
9899

100+
/**
101+
* Source code encoding charset.
102+
*/
103+
private String charset = "UTF-8";
104+
99105
@Override
100106
public String param(final String name, final String value) {
101107
String ret = this.iproperties.getProperty(name);
@@ -292,6 +298,21 @@ public void setAsser(final Collection<String> ass) {
292298
this.asser.addAll(ass);
293299
}
294300

301+
public void setEncoding(final String encoding) {
302+
this.charset = encoding;
303+
}
304+
305+
/**
306+
* Get source files encoding.
307+
* @return Charset of the source files
308+
*/
309+
public Charset encoding() {
310+
if (this.charset == null || this.charset.isEmpty()) {
311+
this.charset = "UTF-8";
312+
}
313+
return Charset.forName(this.charset);
314+
}
315+
295316
/**
296317
* Creates URL ClassLoader in privileged block.
297318
*

qulice-maven-plugin/src/main/java/com/qulice/maven/MavenEnvironment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import com.qulice.spi.Environment;
3434
import java.io.File;
35+
import java.nio.charset.Charset;
3536
import java.util.Collection;
3637
import java.util.Properties;
3738
import org.apache.maven.project.MavenProject;
@@ -182,5 +183,10 @@ public boolean exclude(final String check, final String name) {
182183
public Collection<String> excludes(final String checker) {
183184
return this.env.excludes(checker);
184185
}
186+
187+
@Override
188+
public Charset encoding() {
189+
return this.env.encoding();
190+
}
185191
}
186192
}

qulice-maven-plugin/src/test/java/com/qulice/maven/DefaultMavenEnvironmentTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
package com.qulice.maven;
3232

3333
import com.google.common.collect.ImmutableList;
34+
import java.nio.charset.StandardCharsets;
3435
import java.util.Collections;
3536
import org.apache.maven.project.MavenProject;
3637
import org.hamcrest.MatcherAssert;
@@ -147,4 +148,17 @@ void producesEmptyExcludesWhenNoMatches() {
147148
Matchers.empty()
148149
);
149150
}
151+
152+
/**
153+
* Default source files encoding should be UFT-8.
154+
*/
155+
@Test
156+
void defaultEncodingIsUtf() {
157+
final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
158+
MatcherAssert.assertThat(
159+
"Default encoding should be UTF-8",
160+
env.encoding(),
161+
Matchers.is(StandardCharsets.UTF_8)
162+
);
163+
}
150164
}

qulice-maven-plugin/src/test/java/com/qulice/maven/MavenProjectMocker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public final class MavenProjectMocker {
5252
* In this basedir.
5353
* @param dir The directory
5454
* @return This object
55-
* @throws Exception If something wrong happens inside
5655
*/
57-
public MavenProjectMocker inBasedir(final File dir) throws Exception {
56+
public MavenProjectMocker inBasedir(final File dir) {
5857
Mockito.doReturn(dir).when(this.project).getBasedir();
5958
final Build build = Mockito.mock(Build.class);
6059
Mockito.doReturn(build).when(this.project).getBuild();

qulice-pmd/src/main/java/com/qulice/pmd/SourceValidator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.jcabi.log.Logger;
3434
import com.qulice.spi.Environment;
3535
import java.io.File;
36+
import java.nio.charset.Charset;
3637
import java.util.Collection;
3738
import java.util.Collections;
3839
import java.util.LinkedList;
@@ -70,6 +71,11 @@ final class SourceValidator {
7071
*/
7172
private final PMDConfiguration config;
7273

74+
/**
75+
* Source files encoding.
76+
*/
77+
private final Charset encoding;
78+
7379
/**
7480
* Creates new instance of <code>SourceValidator</code>.
7581
* @param env Environment
@@ -79,6 +85,7 @@ final class SourceValidator {
7985
this.listener = new PmdListener(env);
8086
this.renderer = new PmdRenderer();
8187
this.config = new PMDConfiguration();
88+
this.encoding = env.encoding();
8289
}
8390

8491
/**
@@ -95,6 +102,7 @@ public Collection<PmdError> validate(
95102
this.config.setMinimumPriority(RulePriority.LOW);
96103
this.config.setIgnoreIncrementalAnalysis(true);
97104
this.config.setShowSuppressedViolations(true);
105+
this.config.setSourceEncoding(this.encoding.name());
98106
final Report report = new Report();
99107
report.addListener(this.listener);
100108
this.context.setReport(report);

qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,17 @@ void allowsSwaggerAnnotations() throws Exception {
751751
)
752752
).validate();
753753
}
754+
755+
/**
756+
* PmdValidator can prohibit unicode characters in method names.
757+
* @throws Exception If something wrong happens inside.
758+
*/
759+
@Test
760+
void prohibitsUnicodeCharactersInMethodNames() throws Exception {
761+
new PmdAssert(
762+
"UnicodeCharactersInMethodNames.java",
763+
Matchers.is(false),
764+
Matchers.containsString("MethodNamingConventions")
765+
).validate();
766+
}
754767
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package foo;
2+
3+
public final class UnderstandsMethodReferences {
4+
private static final String SOME_STRING = "φ";
5+
6+
public String φTestMethod() {
7+
return UnderstandsMethodReferences.SOME_STRING;
8+
}
9+
}

qulice-spi/src/main/java/com/qulice/spi/Environment.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import java.io.File;
3434
import java.io.IOException;
35+
import java.nio.charset.Charset;
3536
import java.nio.charset.StandardCharsets;
3637
import java.util.Arrays;
3738
import java.util.Collection;
@@ -122,6 +123,12 @@ public interface Environment {
122123
*/
123124
Collection<String> excludes(String checker);
124125

126+
/**
127+
* Encoding for the files.
128+
* @return Source files charset
129+
*/
130+
Charset encoding();
131+
125132
/**
126133
* Mock of {@link Environment}.
127134
*
@@ -323,5 +330,10 @@ public Collection<String> excludes(final String checker) {
323330
}
324331
return exc;
325332
}
333+
334+
@Override
335+
public Charset encoding() {
336+
return StandardCharsets.UTF_8;
337+
}
326338
}
327339
}

0 commit comments

Comments
 (0)