Skip to content

Commit

Permalink
Merge branch 'feature/issue90' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Dec 18, 2020
2 parents 652fa4a + 34f8050 commit e5a9fe9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<packaging>pom</packaging>
<version>4.4</version>
<version>4.5-SNAPSHOT</version>
<name>MAVEN PROCESSOR PLUGIN PARENT</name>
<description>A maven plugin to process annotation for jdk6 at compile time

Expand Down
2 changes: 1 addition & 1 deletion processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.4</version>
<version>4.5-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -565,6 +585,11 @@ private List<String> 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));
Expand Down Expand Up @@ -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() ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));

}

Expand All @@ -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() );
}


}
2 changes: 1 addition & 1 deletion test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.4</version>
<version>4.5-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.4</version>
<version>4.5-SNAPSHOT</version>
</parent>

<properties>
Expand Down

0 comments on commit e5a9fe9

Please sign in to comment.