Skip to content

Commit

Permalink
Add encoding to environment
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed May 11, 2024
1 parent ebf4355 commit 8a9dda4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
name: mvn
env:
JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF8"
JAVA_OPTS: "%JAVA_OPTS% -Dfile.encoding=UTF-8"
on:
push:
branches:
Expand All @@ -29,4 +26,4 @@ jobs:
key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-jdk-${{ matrix.java }}-maven-
- run: mvn -B install -Pqulice
- run: mvn -B install -Pqulice
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.LinkedList;
Expand Down Expand Up @@ -292,6 +293,18 @@ public void setAsser(final Collection<String> ass) {
this.asser.addAll(ass);
}

/**
* Get source files encoding.
* @return Charset of the source files
*/
public Charset encoding() {
String charset = this.iproperties.getProperty("project.build.sourceEncoding");
if (charset == null) {
charset = "UTF-8";
}
return Charset.forName(charset);
}

/**
* Creates URL ClassLoader in privileged block.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.qulice.spi.Environment;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Properties;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -182,5 +183,10 @@ public boolean exclude(final String check, final String name) {
public Collection<String> excludes(final String checker) {
return this.env.excludes(checker);
}

@Override
public Charset encoding() {
return this.env.encoding();
}
}
}
8 changes: 8 additions & 0 deletions qulice-pmd/src/main/java/com/qulice/pmd/SourceValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.jcabi.log.Logger;
import com.qulice.spi.Environment;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
Expand Down Expand Up @@ -70,6 +71,11 @@ final class SourceValidator {
*/
private final PMDConfiguration config;

/**
* Source files encoding.
*/
private final Charset encoding;

/**
* Creates new instance of <code>SourceValidator</code>.
* @param env Environment
Expand All @@ -79,6 +85,7 @@ final class SourceValidator {
this.listener = new PmdListener(env);
this.renderer = new PmdRenderer();
this.config = new PMDConfiguration();
this.encoding = env.encoding();
}

/**
Expand All @@ -95,6 +102,7 @@ public Collection<PmdError> validate(
this.config.setMinimumPriority(RulePriority.LOW);
this.config.setIgnoreIncrementalAnalysis(true);
this.config.setShowSuppressedViolations(true);
this.config.setSourceEncoding(this.encoding.name());
final Report report = new Report();
report.addListener(this.listener);
this.context.setReport(report);
Expand Down
12 changes: 12 additions & 0 deletions qulice-spi/src/main/java/com/qulice/spi/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -122,6 +123,12 @@ public interface Environment {
*/
Collection<String> excludes(String checker);

/**
* Encoding for the files.
* @return Source files charset
*/
Charset encoding();

/**
* Mock of {@link Environment}.
*
Expand Down Expand Up @@ -323,5 +330,10 @@ public Collection<String> excludes(final String checker) {
}
return exc;
}

@Override
public Charset encoding() {
return StandardCharsets.UTF_8;
}
}
}

0 comments on commit 8a9dda4

Please sign in to comment.