Skip to content

Commit

Permalink
Make sure generated quarkus-artifact.properties is stable
Browse files Browse the repository at this point in the history
At the moment, it contains a timestamp, which is going to be in the way
of the cache.
Also make sure the properties are sorted.

(cherry picked from commit 6981dab)
  • Loading branch information
gsmet committed Jul 2, 2024
1 parent 31f58dc commit 98aac98
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.runner.bootstrap;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -32,6 +31,7 @@
import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.classloading.ClassLoaderEventListener;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.bootstrap.util.PropertyUtils;
import io.quarkus.builder.BuildChainBuilder;
import io.quarkus.builder.BuildResult;
import io.quarkus.builder.item.BuildItem;
Expand Down Expand Up @@ -235,8 +235,8 @@ private void writeArtifactResultMetadataFile(BuildSystemTargetBuildItem outputTa
properties.put("metadata." + entry.getKey(), entry.getValue());
}
}
try (FileOutputStream fos = new FileOutputStream(quarkusArtifactMetadataPath.toFile())) {
properties.store(fos, "Generated by Quarkus - Do not edit manually");
try {
PropertyUtils.store(properties, quarkusArtifactMetadataPath, "Generated by Quarkus - Do not edit manually");
} catch (IOException e) {
log.debug("Unable to write artifact result metadata file", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public static final boolean getBoolean(String name, boolean notFoundValue) {
* {@link Properties#store(Writer, String)} format but skipping the timestamp and comments.
*
* @param properties properties to store
* @param leadingComment a leading comment, it will be prepended by an hash
* @param file target file
* @throws IOException in case of a failure
*/
public static void store(Properties properties, Path file) throws IOException {
public static void store(Properties properties, Path file, String leadingComment) throws IOException {
try (BufferedWriter writer = Files.newBufferedWriter(file)) {
store(properties, writer);
store(properties, writer, leadingComment);
}
}

Expand All @@ -75,11 +76,19 @@ public static void store(Properties properties, Path file) throws IOException {
* {@link Properties#store(Writer, String)} format but skipping the timestamp and comments.
*
* @param properties properties to store
* @param leadingComment a leading comment, it will be prepended by an hash
* @param writer target writer
* @throws IOException in case of a failure
*/
public static void store(Properties properties, Writer writer) throws IOException {
public static void store(Properties properties, Writer writer, String leadingComment) throws IOException {
final List<String> names = new ArrayList<>(properties.size());

if (leadingComment != null && !leadingComment.isBlank()) {
writer.write("# ");
writer.write(leadingComment);
writer.write(System.lineSeparator());
}

for (var name : properties.keySet()) {
names.add(name == null ? null : name.toString());
}
Expand All @@ -97,16 +106,58 @@ public static void store(Properties properties, Writer writer) throws IOExceptio
* @param file target file
* @throws IOException in case of a failure
*/
public static void store(Map<String, String> properties, Path file) throws IOException {
public static void store(Map<String, String> properties, Path file, String leadingComment) throws IOException {
final List<String> names = new ArrayList<>(properties.keySet());
Collections.sort(names);
try (BufferedWriter writer = Files.newBufferedWriter(file)) {
if (leadingComment != null && !leadingComment.isBlank()) {
writer.write("# ");
writer.write(leadingComment);
writer.write(System.lineSeparator());
}

for (String name : names) {
store(writer, name, properties.get(name));
}
}
}

/**
* Stores properties into a file sorting the keys alphabetically and following
* {@link Properties#store(Writer, String)} format but skipping the timestamp and comments.
*
* @param properties properties to store
* @param file target file
* @throws IOException in case of a failure
*/
public static void store(Properties properties, Path file) throws IOException {
store(properties, file, null);
}

/**
* Stores properties into a file sorting the keys alphabetically and following
* {@link Properties#store(Writer, String)} format but skipping the timestamp and comments.
*
* @param properties properties to store
* @param writer target writer
* @throws IOException in case of a failure
*/
public static void store(Properties properties, Writer writer) throws IOException {
store(properties, writer, null);
}

/**
* Stores a map of strings into a file sorting the keys alphabetically and following
* {@link Properties#store(Writer, String)} format but skipping the timestamp and comments.
*
* @param properties properties to store
* @param file target file
* @throws IOException in case of a failure
*/
public static void store(Map<String, String> properties, Path file) throws IOException {
store(properties, file, null);
}

/**
* Writes a config option with its value to the target writer,
* possibly applying some transformations, such as character escaping
Expand Down

0 comments on commit 98aac98

Please sign in to comment.