elharo commented on code in PR #79: URL: https://github.com/apache/maven-archiver/pull/79#discussion_r1860223895
########## 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(); Review Comment: We need system independent output. Use \n unconditionally. ########## 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: We're leaning pretty heavily on Hyrum's Law here. I'm not convinced we can rely on the description of current encoding in the Javadoc to apply to future encoding. In particular, I would not be at all surprised to see properties.store write in UTF-8 in a future JDK. -- 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