|
22 | 22 | import com.google.common.base.Function; |
23 | 23 | import com.google.common.base.Predicate; |
24 | 24 | import com.google.common.base.Predicates; |
| 25 | +import com.google.common.base.Strings; |
25 | 26 | import com.google.common.collect.Lists; |
26 | 27 | import com.google.common.io.Closeables; |
27 | 28 | import com.google.common.io.Files; |
|
34 | 35 | import pl.project13.maven.git.log.MavenLoggerBridge; |
35 | 36 | import pl.project13.maven.git.util.PropertyManager; |
36 | 37 |
|
37 | | -import java.io.File; |
38 | | -import java.io.FileWriter; |
39 | | -import java.io.IOException; |
| 38 | +import java.io.*; |
| 39 | +import java.nio.charset.Charset; |
40 | 40 | import java.text.SimpleDateFormat; |
41 | 41 | import java.util.Collections; |
42 | 42 | import java.util.Date; |
@@ -272,6 +272,13 @@ public class GitCommitIdMojo extends AbstractMojo { |
272 | 272 | @SuppressWarnings("UnusedDeclaration") |
273 | 273 | private List<String> excludeProperties = Collections.emptyList(); |
274 | 274 |
|
| 275 | + /** |
| 276 | + * Specifies the character encoding for the properties file that is generated by this plugin |
| 277 | + * |
| 278 | + * @parameter expression="${encoding}" default-value="${project.reporting.outputEncoding} |
| 279 | + * @since 2.1.11 |
| 280 | + */ |
| 281 | + private String encoding; |
275 | 282 |
|
276 | 283 | /** |
277 | 284 | * The properties we store our data in and then expose them |
@@ -487,25 +494,39 @@ void loadGitDataWithJGit(@NotNull Properties properties) throws IOException, Moj |
487 | 494 | } |
488 | 495 |
|
489 | 496 | void generatePropertiesFile(@NotNull Properties properties, File base, String propertiesFilename) throws IOException { |
490 | | - FileWriter fileWriter = null; |
| 497 | + Writer outputWriter = null; |
491 | 498 | File gitPropsFile = craftPropertiesOutputFile(base, propertiesFilename); |
492 | 499 | try { |
493 | 500 | Files.createParentDirs(gitPropsFile); |
494 | 501 |
|
495 | | - fileWriter = new FileWriter(gitPropsFile); |
| 502 | + outputWriter = new OutputStreamWriter(new FileOutputStream(gitPropsFile), determineEncoding()); |
496 | 503 | if ("json".equalsIgnoreCase(format)) { |
497 | 504 | log("Writing json file to [", gitPropsFile.getAbsolutePath(), "] (for module ", project.getName(), ")..."); |
498 | 505 | ObjectMapper mapper = new ObjectMapper(); |
499 | | - mapper.writeValue(fileWriter, properties); |
| 506 | + mapper.writeValue(outputWriter, properties); |
500 | 507 | } else { |
501 | 508 | log("Writing properties file to [", gitPropsFile.getAbsolutePath(), "] (for module ", project.getName(), ")..."); |
502 | | - properties.store(fileWriter, "Generated by Git-Commit-Id-Plugin"); |
| 509 | + properties.store(outputWriter, "Generated by Git-Commit-Id-Plugin"); |
503 | 510 | } |
504 | 511 |
|
505 | 512 | } catch (IOException ex) { |
506 | 513 | throw new RuntimeException("Cannot create custom git properties file: " + gitPropsFile, ex); |
507 | 514 | } finally { |
508 | | - Closeables.closeQuietly(fileWriter); |
| 515 | + Closeables.closeQuietly(outputWriter); |
| 516 | + } |
| 517 | + } |
| 518 | + |
| 519 | + private String determineEncoding() { |
| 520 | + if (Strings.isNullOrEmpty(this.encoding) ) |
| 521 | + { |
| 522 | + getLog().warn( |
| 523 | + "File encoding has not been set, using platform encoding " + Charset.defaultCharset().name() |
| 524 | + + ", i.e. build is platform dependent!" ); |
| 525 | + return Charset.defaultCharset().name(); |
| 526 | + } |
| 527 | + else |
| 528 | + { |
| 529 | + return this.encoding; |
509 | 530 | } |
510 | 531 | } |
511 | 532 |
|
|
0 commit comments