gnodet commented on code in PR #79: URL: https://github.com/apache/maven-archiver/pull/79#discussion_r1860283250
########## src/main/java/org/apache/maven/shared/archiver/PomPropertiesUtil.java: ########## @@ -52,92 +48,53 @@ private Properties loadPropertiesFile(Path file) throws IOException { } } - private boolean sameContents(Properties props, Path file) throws IOException { - if (!Files.isRegularFile(file)) { - return false; - } - - Properties fileProps = loadPropertiesFile(file); - return fileProps.equals(props); - } - - private void createPropertiesFile(Properties properties, Path outputFile, boolean forceCreation) - throws IOException { + private void createPropertiesFile(Properties properties, Path outputFile) throws IOException { Path outputDir = outputFile.getParent(); - if (outputDir != null && !Files.isDirectory(outputDir)) { + if (outputDir != null) { Files.createDirectories(outputDir); } - if (!forceCreation && sameContents(properties, outputFile)) { - return; - } - - try (PrintWriter pw = new PrintWriter(outputFile.toFile(), StandardCharsets.ISO_8859_1.name()); - StringWriter sw = new StringWriter()) { - - properties.store(sw, null); - - List<String> lines = new ArrayList<>(); - try (BufferedReader r = new BufferedReader(new StringReader(sw.toString()))) { - String line; - while ((line = r.readLine()) != null) { - if (!line.startsWith("#")) { - lines.add(line); - } - } - } - - Collections.sort(lines); - for (String l : lines) { - pw.println(l); - } + // For reproducible builds, sort the properties and drop comments. + // The java.util.Properties class doesn't guarantee order so we have + // to write the file using a Writer. + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + properties.store(baos, null); + String nl = System.lineSeparator(); + String output = baos.toString(StandardCharsets.ISO_8859_1) Review Comment: It's been this way since JDK 1.2, so 26 years. And for the encoding, the Properties class has been opened to other encodings in JDK 1.5. The default encoding for reading properties [has already been changed in JDK 9](https://docs.oracle.com/javase/9/intl/internationalization-enhancements-jdk-9.htm#GUID-974CF488-23E8-4963-A322-82006A7A14C7). The encoding used here is kinda irrelevant (whether ISO-8859-1 or UTF-8) because all non-ascii chars have been transformed into `\uxxxx` sequences, thereby removing everything that is encoding specific. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org