diff --git a/substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/conditionalconfig/ConfigurationVerifier.java b/substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/conditionalconfig/ConfigurationVerifier.java index d6ba5520fc0e..1b9f168eb16f 100644 --- a/substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/conditionalconfig/ConfigurationVerifier.java +++ b/substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/conditionalconfig/ConfigurationVerifier.java @@ -32,6 +32,7 @@ import org.junit.Assert; import org.junit.Test; +import com.oracle.svm.configure.ConfigurationBase; import com.oracle.svm.configure.config.ConfigurationFileCollection; import com.oracle.svm.configure.config.ConfigurationSet; import com.oracle.svm.core.configure.ConfigurationFile; @@ -70,9 +71,14 @@ private static String getConfigurationJSON(ConfigurationSet config) throws IOExc StringWriter sw = new StringWriter(); try (JsonWriter writer = new JsonWriter(sw)) { for (ConfigurationFile file : ConfigurationFile.agentGeneratedFiles()) { - if (!config.getConfiguration(file).isEmpty()) { + ConfigurationBase configuration = config.getConfiguration(file); + if (!configuration.isEmpty()) { sw.append("\n").append(file.getName()).append("\n"); - config.getConfiguration(file).printJson(writer); + if (configuration.supportsCombinedFile()) { + configuration.printJson(writer); + } else { + configuration.printLegacyJson(writer); + } } } return sw.toString(); diff --git a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/ConfigurationSet.java b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/ConfigurationSet.java index 5e3211f488b7..5a58c16b2eed 100644 --- a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/ConfigurationSet.java +++ b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/ConfigurationSet.java @@ -189,14 +189,7 @@ public static List writeConfigurationToAllPaths(Function writeConfigurationToAllPaths(Function writeConfiguration(Function configFilePathResolver) throws IOException { return writeConfiguration(configFilePathResolver, this::getConfiguration); } diff --git a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/HumanReadableConfigurationWithOrigins.java b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/HumanReadableConfigurationWithOrigins.java index 9ae0f1c7505b..08523fde5570 100644 --- a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/HumanReadableConfigurationWithOrigins.java +++ b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/HumanReadableConfigurationWithOrigins.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Set; +import com.oracle.svm.configure.ConfigurationBase; import com.oracle.svm.core.configure.ConfigurationFile; import jdk.graal.compiler.util.json.JsonPrintable; @@ -65,8 +66,14 @@ private void printNode(JsonWriter writer, String prefix, MethodCallNode node) th writer.append(prefix).append(node.methodInfo.toString()); if (node.hasConfig(configFile)) { writer.append(" - "); + ConfigurationBase config = node.configuration.getConfiguration(configFile); StringWriter sw = new StringWriter(); - node.configuration.getConfiguration(configFile).printJson(new JsonWriter(sw)); + JsonWriter jw = new JsonWriter(sw); + if (config.supportsCombinedFile()) { + config.printJson(jw); + } else { + config.printLegacyJson(jw); + } writer.append(sw.toString().replace("\n", " ")); } writer.newline(); diff --git a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/PartialConfigurationWithOrigins.java b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/PartialConfigurationWithOrigins.java index 9158b6143a87..3bca5a3463fc 100644 --- a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/PartialConfigurationWithOrigins.java +++ b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/conditional/PartialConfigurationWithOrigins.java @@ -31,6 +31,7 @@ import org.graalvm.collections.EconomicMap; import org.graalvm.collections.MapCursor; +import com.oracle.svm.configure.ConfigurationBase; import com.oracle.svm.configure.config.ConfigurationSet; import com.oracle.svm.core.configure.ConfigurationFile; import com.oracle.svm.core.configure.ConfigurationParser; @@ -143,22 +144,34 @@ private void parseMethodEntry(MethodCallNode parent, EconomicMap meth private static void printConfigurationSet(JsonWriter writer, ConfigurationSet configurationSet) throws IOException { if (!configurationSet.isEmpty()) { - writer.quote("config").append(": {").indent().newline(); + writer.quote("config").appendFieldSeparator().appendObjectStart(); + + /* Print combined file */ + writer.quote(ConfigurationFile.REACHABILITY_METADATA.getName()).appendFieldSeparator().appendObjectStart(); boolean first = true; for (ConfigurationFile file : ConfigurationFile.agentGeneratedFiles()) { - if (!configurationSet.getConfiguration(file).isEmpty()) { + ConfigurationBase config = configurationSet.getConfiguration(file); + if (!config.isEmpty() && config.supportsCombinedFile()) { if (first) { first = false; } else { - writer.append(",").newline(); + writer.appendSeparator(); } + ConfigurationSet.printConfigurationToCombinedFile(config, file, writer); + } + } + writer.appendObjectEnd(); - writer.quote(file.getName()).append(": "); - configurationSet.getConfiguration(file).printJson(writer); + /* Print legacy files */ + for (ConfigurationFile file : ConfigurationFile.agentGeneratedFiles()) { + ConfigurationBase config = configurationSet.getConfiguration(file); + if (!config.isEmpty() && !config.supportsCombinedFile()) { + writer.appendSeparator(); + writer.quote(file.getName()).appendFieldSeparator(); + config.printLegacyJson(writer); } } - writer.unindent().newline() - .append("}"); + writer.appendObjectEnd(); } } @@ -170,7 +183,13 @@ private static void parseConfigurationSet(EconomicMap configJson, Con if (configType == null) { throw new JsonParserException("Invalid configuration type: " + configName); } - configurationSet.getConfiguration(configType).createParser(false).parseAndRegister(cursor.getValue(), origin); + if (configType == ConfigurationFile.REACHABILITY_METADATA) { + for (ConfigurationFile file : ConfigurationFile.combinedFileConfigurations()) { + configurationSet.getConfiguration(file).createParser(true).parseAndRegister(cursor.getValue(), origin); + } + } else { + configurationSet.getConfiguration(configType).createParser(false).parseAndRegister(cursor.getValue(), origin); + } } } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationFile.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationFile.java index 8ec71e14ba5a..d3ae09ce0a20 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationFile.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationFile.java @@ -33,12 +33,12 @@ public enum ConfigurationFile { /* Combined file */ - REACHABILITY_METADATA("reachability-metadata", null, true, true), + REACHABILITY_METADATA("reachability-metadata", null, true, false), /* Main metadata categories (order matters) */ - REFLECTION("reflect", REFLECTION_KEY, true, false), - RESOURCES("resource", RESOURCES_KEY, true, false), - SERIALIZATION("serialization", SERIALIZATION_KEY, true, false), - JNI("jni", JNI_KEY, true, false), + REFLECTION("reflect", REFLECTION_KEY, true, true), + RESOURCES("resource", RESOURCES_KEY, true, true), + SERIALIZATION("serialization", SERIALIZATION_KEY, true, true), + JNI("jni", JNI_KEY, true, true), /* Deprecated metadata categories */ DYNAMIC_PROXY("proxy", null, true, false), PREDEFINED_CLASSES_NAME("predefined-classes", null, true, false), @@ -51,7 +51,7 @@ public enum ConfigurationFile { private final String name; private final String fieldName; private final boolean canAgentGenerate; - private final boolean combinedFile; + private final boolean inCombinedFile; public static final String LOCK_FILE_NAME = ".lock"; public static final String PREDEFINED_CLASSES_AGENT_EXTRACTED_SUBDIR = "agent-extracted-predefined-classes"; @@ -59,12 +59,13 @@ public enum ConfigurationFile { public static final String PARTIAL_CONFIGURATION_WITH_ORIGINS = "partial-config-with-origins.json"; private static final ConfigurationFile[] agentGeneratedFiles = computeAgentGeneratedFiles(); + private static final ConfigurationFile[] combinedFileConfigurations = computeCombinedFileConfigurations(); - ConfigurationFile(String name, String fieldName, boolean canAgentGenerate, boolean combinedFile) { + ConfigurationFile(String name, String fieldName, boolean canAgentGenerate, boolean inCombinedFile) { this.name = name; this.fieldName = fieldName; this.canAgentGenerate = canAgentGenerate; - this.combinedFile = combinedFile; + this.inCombinedFile = inCombinedFile; } public String getName() { @@ -76,7 +77,7 @@ public String getFieldName() { } public String getFileName() { - return name + (combinedFile ? COMBINED_FILE_NAME_SUFFIX : LEGACY_FILE_NAME_SUFFIX); + return name + (this == REACHABILITY_METADATA ? COMBINED_FILE_NAME_SUFFIX : LEGACY_FILE_NAME_SUFFIX); } public String getFileName(String suffix) { @@ -84,7 +85,7 @@ public String getFileName(String suffix) { } public boolean canBeGeneratedByAgent() { - return canAgentGenerate && !combinedFile; + return canAgentGenerate && this != REACHABILITY_METADATA; } public static ConfigurationFile getByName(String name) { @@ -103,4 +104,12 @@ public static ConfigurationFile[] agentGeneratedFiles() { private static ConfigurationFile[] computeAgentGeneratedFiles() { return Arrays.stream(values()).filter(f -> f.canBeGeneratedByAgent()).toArray(ConfigurationFile[]::new); } + + public static ConfigurationFile[] combinedFileConfigurations() { + return combinedFileConfigurations; + } + + private static ConfigurationFile[] computeCombinedFileConfigurations() { + return Arrays.stream(values()).filter(f -> f.inCombinedFile).toArray(ConfigurationFile[]::new); + } }