diff --git a/pom.xml b/pom.xml
index 474b321..abb44d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
org.bsc.maven
maven-processor-plugin-parent
pom
- 4.4
+ 4.5-SNAPSHOT
MAVEN PROCESSOR PLUGIN PARENT
A maven plugin to process annotation for jdk6 at compile time
diff --git a/processor/pom.xml b/processor/pom.xml
index 610734c..2167741 100644
--- a/processor/pom.xml
+++ b/processor/pom.xml
@@ -13,7 +13,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
org.bsc.maven
maven-processor-plugin-parent
- 4.4
+ 4.5-SNAPSHOT
diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java
index 0002bc7..b7b175c 100644
--- a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java
+++ b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java
@@ -341,6 +341,26 @@ public abstract class AbstractAnnotationProcessorMojo extends AbstractMojo
*/
public abstract File getDefaultOutputDirectory();
+ /**
+ *
+ * @return
+ */
+ private Charset getCharsetFromEncoding() {
+
+ return ofNullable(encoding).map( enc -> {
+ try {
+ return Charset.forName(encoding);
+ }
+ catch( IllegalCharsetNameException ex1 ) {
+ getLog().warn( format("the given charset name [%s] is illegal!. default is used", encoding ));
+ }
+ catch( UnsupportedCharsetException ex2 ) {
+ getLog().warn( format("the given charset name [%s] is unsupported!. default is used", encoding ));
+ }
+ return Charset.defaultCharset();
+ }).orElseGet( () -> Charset.defaultCharset() );
+
+ }
private String buildProcessor()
{
@@ -565,6 +585,11 @@ private List prepareOptions( JavaCompiler compiler ) {
});
});
+ ofNullable(encoding).ifPresent( enc -> {
+ options.add("-encoding");
+ options.add( getCharsetFromEncoding().name() );
+ });
+
if( getLog().isDebugEnabled() ) {
for (String option : options) {
getLog().debug(format("javac option: %s", option));
@@ -803,28 +828,10 @@ private void executeWithExceptionsHandled() throws Exception
return;
}
-
- Charset charset = null; ;
-
- if( encoding != null ) {
- try {
- charset = Charset.forName(encoding);
- }
- catch( IllegalCharsetNameException ex1 ) {
- getLog().warn( format("the given charset name [%s] is illegal!. default is used", encoding ));
- charset = null;
- }
- catch( UnsupportedCharsetException ex2 ) {
- getLog().warn( format("the given charset name [%s] is unsupported!. default is used", encoding ));
- charset = null;
- }
- }
-
- final StandardJavaFileManager fileManager =
- compiler.getStandardFileManager(null, null,
- (charset==null) ?
- Charset.defaultCharset() :
- charset);
+ final StandardJavaFileManager fileManager =
+ compiler.getStandardFileManager(null,
+ null,
+ getCharsetFromEncoding());
if( files!=null && !files.isEmpty() ) {
diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/AnnotationProcessorCompiler.java b/processor/src/main/java/org/bsc/maven/plugin/processor/AnnotationProcessorCompiler.java
index 55ef8f1..17dbac0 100644
--- a/processor/src/main/java/org/bsc/maven/plugin/processor/AnnotationProcessorCompiler.java
+++ b/processor/src/main/java/org/bsc/maven/plugin/processor/AnnotationProcessorCompiler.java
@@ -342,6 +342,9 @@ else if( "-s".equals(option) ) {
else if( "--release".equals(option) ) {
javacConf.setReleaseVersion(ii.next());
}
+ else if("-encoding".equals(option)) {
+ javacConf.setSourceEncoding(ii.next());
+ }
else /*if( option.startsWith("-A") ) */ { // view pull #70
// Just pass through any other arguments
javacConf.addCompilerCustomArgument(option, "");
diff --git a/processor/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java b/processor/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java
index 1191e0c..548272b 100644
--- a/processor/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java
+++ b/processor/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java
@@ -4,10 +4,12 @@
*/
package org.bsc.maven.plugin.processor;
-import java.io.File;
-import org.junit.Assert;
import org.junit.Test;
-import org.hamcrest.core.*;
+
+import java.nio.charset.Charset;
+
+import static org.junit.Assert.*;
+
/**
*
* @author softphone
@@ -20,11 +22,11 @@ public void compareFile() {
final java.io.File f = new java.io.File( "target/test-classes");
final java.io.File f2 = new java.io.File( "target/classes");
- Assert.assertThat( f.equals(f2), Is.is(false));
+ assertFalse( f.equals(f2));
final java.io.File f3 = new java.io.File( "target/classes");
- Assert.assertThat( f3.equals(f2), Is.is(true));
+ assertTrue( f3.equals(f2));
}
@@ -46,12 +48,25 @@ public void testDuplicatePath() {
fileSet.add( f2 );
- Assert.assertThat( fileSet.size(), IsEqual.equalTo(1) );
+ assertEquals( 1, fileSet.size() );
fileSet.add( f2 );
fileSet.add(f3);
- Assert.assertThat( fileSet.size(), IsEqual.equalTo(2) );
+ assertEquals( 2, fileSet.size() );
}
+
+ @Test
+ public void testEncoding() {
+
+ Charset.availableCharsets().entrySet().forEach( e -> {
+ System.out.printf( "encoding { key:%s, name:%s, aliases:%s }\n", e.getKey(), e.getValue().name(), e.getValue().aliases());
+ });
+
+ final Charset utf8 = Charset.forName("utf8");
+ assertEquals( "UTF-8", utf8.name() );
+ }
+
+
}
diff --git a/test/pom.xml b/test/pom.xml
index 89b26e6..25ac1ff 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -11,7 +11,7 @@
org.bsc.maven
maven-processor-plugin-parent
- 4.4
+ 4.5-SNAPSHOT
diff --git a/utils/pom.xml b/utils/pom.xml
index 56d14d4..05fb062 100644
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -31,7 +31,7 @@
org.bsc.maven
maven-processor-plugin-parent
- 4.4
+ 4.5-SNAPSHOT