Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport reachability-metadata.json parser #23

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ class TypeMethodsWithFlagsTest {
final Map<ConfigurationMethod, ConfigurationMemberDeclaration> methodsThatMustExist = new HashMap<>();
final Map<ConfigurationMethod, ConfigurationMemberDeclaration> methodsThatMustNotExist = new HashMap<>();

final TypeConfiguration previousConfig = new TypeConfiguration();
final TypeConfiguration currentConfig = new TypeConfiguration();
final TypeConfiguration previousConfig = new TypeConfiguration("");
final TypeConfiguration currentConfig = new TypeConfiguration("");

TypeMethodsWithFlagsTest(ConfigurationMemberDeclaration methodKind) {
this.methodKind = methodKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import org.junit.Test;

import com.oracle.svm.configure.config.ResourceConfiguration;
import com.oracle.svm.core.util.json.JsonWriter;
import com.oracle.svm.core.configure.ResourceConfigurationParser;
import com.oracle.svm.core.configure.ResourcesRegistry;
import com.oracle.svm.core.util.json.JsonWriter;

public class ResourceConfigurationTest {

Expand Down Expand Up @@ -117,7 +117,7 @@ public void addClassBasedResourceBundle(ConfigurationCondition condition, String
}
};

ResourceConfigurationParser rcp = new ResourceConfigurationParser(registry, true);
ResourceConfigurationParser rcp = ResourceConfigurationParser.create(false, registry, true);
writerThread.start();
rcp.parseAndRegister(pr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

import java.util.function.Consumer;

import com.oracle.svm.core.util.json.JsonPrintable;
import com.oracle.svm.core.configure.ConfigurationParser;
import org.graalvm.nativeimage.impl.ConfigurationCondition;

import com.oracle.svm.core.configure.ConfigurationParser;
import com.oracle.svm.core.util.json.JsonPrintable;

public abstract class ConfigurationBase<T extends ConfigurationBase<T, P>, P> implements JsonPrintable {

public abstract boolean isEmpty();
Expand Down Expand Up @@ -68,5 +69,5 @@ public T copyAndFilter(P predicate) {
return copyAnd(copy -> copy.removeIf(predicate));
}

public abstract ConfigurationParser createParser();
public abstract ConfigurationParser createParser(boolean strictMetadata);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,31 @@
*/
package com.oracle.svm.configure.config;

import static com.oracle.svm.core.configure.ConfigurationParser.JNI_KEY;
import static com.oracle.svm.core.configure.ConfigurationParser.REFLECTION_KEY;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import com.oracle.svm.core.configure.ConfigurationFile;
import com.oracle.svm.core.configure.ConfigurationParser;
import com.oracle.svm.core.util.VMError;

public class ConfigurationFileCollection {
public static final Function<IOException, Exception> FAIL_ON_EXCEPTION = e -> e;

private final Set<URI> reachabilityMetadataPaths = new LinkedHashSet<>();
private final Set<URI> jniConfigPaths = new LinkedHashSet<>();
private final Set<URI> reflectConfigPaths = new LinkedHashSet<>();
private final Set<URI> proxyConfigPaths = new LinkedHashSet<>();
Expand All @@ -51,6 +58,7 @@ public class ConfigurationFileCollection {
private Set<URI> lockFilePaths;

public void addDirectory(Path path) {
reachabilityMetadataPaths.add(path.resolve(ConfigurationFile.REACHABILITY_METADATA.getFileName()).toUri());
jniConfigPaths.add(path.resolve(ConfigurationFile.JNI.getFileName()).toUri());
reflectConfigPaths.add(path.resolve(ConfigurationFile.REFLECTION.getFileName()).toUri());
proxyConfigPaths.add(path.resolve(ConfigurationFile.DYNAMIC_PROXY.getFileName()).toUri());
Expand All @@ -70,24 +78,51 @@ private <T> void detectAgentLock(T location, Predicate<T> exists, Function<T, UR
}

public void addDirectory(Function<String, URI> fileResolver) {
jniConfigPaths.add(fileResolver.apply(ConfigurationFile.JNI.getFileName()));
reflectConfigPaths.add(fileResolver.apply(ConfigurationFile.REFLECTION.getFileName()));
proxyConfigPaths.add(fileResolver.apply(ConfigurationFile.DYNAMIC_PROXY.getFileName()));
resourceConfigPaths.add(fileResolver.apply(ConfigurationFile.RESOURCES.getFileName()));
serializationConfigPaths.add(fileResolver.apply(ConfigurationFile.SERIALIZATION.getFileName()));
predefinedClassesConfigPaths.add(fileResolver.apply(ConfigurationFile.PREDEFINED_CLASSES_NAME.getFileName()));
addFile(reachabilityMetadataPaths, fileResolver, ConfigurationFile.REACHABILITY_METADATA);
addFile(jniConfigPaths, fileResolver, ConfigurationFile.JNI);
addFile(reflectConfigPaths, fileResolver, ConfigurationFile.REFLECTION);
addFile(proxyConfigPaths, fileResolver, ConfigurationFile.DYNAMIC_PROXY);
addFile(resourceConfigPaths, fileResolver, ConfigurationFile.RESOURCES);
addFile(serializationConfigPaths, fileResolver, ConfigurationFile.SERIALIZATION);
addFile(predefinedClassesConfigPaths, fileResolver, ConfigurationFile.PREDEFINED_CLASSES_NAME);
detectAgentLock(fileResolver.apply(ConfigurationFile.LOCK_FILE_NAME), Objects::nonNull, Function.identity());
}

private static void addFile(Set<URI> metadataPaths, Function<String, URI> fileResolver, ConfigurationFile configurationFile) {
URI uri = fileResolver.apply(configurationFile.getFileName());
if (uri != null) {
metadataPaths.add(uri);
}
}

public Set<URI> getDetectedAgentLockPaths() {
return (lockFilePaths != null) ? lockFilePaths : Collections.emptySet();
}

public boolean isEmpty() {
return jniConfigPaths.isEmpty() && reflectConfigPaths.isEmpty() && proxyConfigPaths.isEmpty() &&
return reachabilityMetadataPaths.isEmpty() && jniConfigPaths.isEmpty() && reflectConfigPaths.isEmpty() && proxyConfigPaths.isEmpty() &&
resourceConfigPaths.isEmpty() && serializationConfigPaths.isEmpty() && predefinedClassesConfigPaths.isEmpty();
}

public Set<Path> getPaths(ConfigurationFile configurationFile) {
Set<URI> uris;
switch (configurationFile) {
case REACHABILITY_METADATA -> uris = getReachabilityMetadataPaths();
case DYNAMIC_PROXY -> uris = getProxyConfigPaths();
case RESOURCES -> uris = getResourceConfigPaths();
case JNI -> uris = getJniConfigPaths();
case REFLECTION -> uris = getReflectConfigPaths();
case SERIALIZATION -> uris = getSerializationConfigPaths();
case PREDEFINED_CLASSES_NAME -> uris = getPredefinedClassesConfigPaths();
default -> throw VMError.shouldNotReachHere("Cannot get paths for configuration file " + configurationFile);
}
return uris.stream().map(Paths::get).collect(Collectors.toSet());
}

public Set<URI> getReachabilityMetadataPaths() {
return reachabilityMetadataPaths;
}

public Set<URI> getJniConfigPaths() {
return jniConfigPaths;
}
Expand All @@ -113,35 +148,37 @@ public Set<URI> getPredefinedClassesConfigPaths() {
}

public TypeConfiguration loadJniConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
return loadTypeConfig(jniConfigPaths, exceptionHandler);
return loadTypeConfig(JNI_KEY, jniConfigPaths, exceptionHandler);
}

public TypeConfiguration loadReflectConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
return loadTypeConfig(reflectConfigPaths, exceptionHandler);
return loadTypeConfig(REFLECTION_KEY, reflectConfigPaths, exceptionHandler);
}

public ProxyConfiguration loadProxyConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
loadConfig(proxyConfigPaths, proxyConfiguration.createParser(), exceptionHandler);
loadConfig(proxyConfigPaths, proxyConfiguration.createParser(false), exceptionHandler);
return proxyConfiguration;
}

public PredefinedClassesConfiguration loadPredefinedClassesConfig(Path[] classDestinationDirs, Predicate<String> shouldExcludeClassesWithHash,
Function<IOException, Exception> exceptionHandler) throws Exception {
PredefinedClassesConfiguration predefinedClassesConfiguration = new PredefinedClassesConfiguration(classDestinationDirs, shouldExcludeClassesWithHash);
loadConfig(predefinedClassesConfigPaths, predefinedClassesConfiguration.createParser(), exceptionHandler);
loadConfig(predefinedClassesConfigPaths, predefinedClassesConfiguration.createParser(false), exceptionHandler);
return predefinedClassesConfiguration;
}

public ResourceConfiguration loadResourceConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
ResourceConfiguration resourceConfiguration = new ResourceConfiguration();
loadConfig(resourceConfigPaths, resourceConfiguration.createParser(), exceptionHandler);
loadConfig(reachabilityMetadataPaths, resourceConfiguration.createParser(true), exceptionHandler);
loadConfig(resourceConfigPaths, resourceConfiguration.createParser(false), exceptionHandler);
return resourceConfiguration;
}

public SerializationConfiguration loadSerializationConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
SerializationConfiguration serializationConfiguration = new SerializationConfiguration();
loadConfig(serializationConfigPaths, serializationConfiguration.createParser(), exceptionHandler);
loadConfig(reachabilityMetadataPaths, serializationConfiguration.createParser(true), exceptionHandler);
loadConfig(serializationConfigPaths, serializationConfiguration.createParser(false), exceptionHandler);
return serializationConfiguration;
}

Expand All @@ -152,9 +189,10 @@ public ConfigurationSet loadConfigurationSet(Function<IOException, Exception> ex
loadPredefinedClassesConfig(predefinedConfigClassDestinationDirs, predefinedConfigClassWithHashExclusionPredicate, exceptionHandler));
}

private static TypeConfiguration loadTypeConfig(Collection<URI> uris, Function<IOException, Exception> exceptionHandler) throws Exception {
TypeConfiguration configuration = new TypeConfiguration();
loadConfig(uris, configuration.createParser(), exceptionHandler);
private TypeConfiguration loadTypeConfig(String combinedFileKey, Collection<URI> uris, Function<IOException, Exception> exceptionHandler) throws Exception {
TypeConfiguration configuration = new TypeConfiguration(combinedFileKey);
loadConfig(reachabilityMetadataPaths, configuration.createParser(true), exceptionHandler);
loadConfig(uris, configuration.createParser(false), exceptionHandler);
return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
package com.oracle.svm.configure.config;

import static com.oracle.svm.core.configure.ConfigurationParser.JNI_KEY;
import static com.oracle.svm.core.configure.ConfigurationParser.REFLECTION_KEY;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -32,10 +35,10 @@

import com.oracle.svm.configure.ConfigurationBase;
import com.oracle.svm.configure.config.conditional.ConditionalConfigurationPredicate;
import com.oracle.svm.core.util.json.JsonPrintable;
import com.oracle.svm.core.util.json.JsonWriter;
import com.oracle.svm.core.configure.ConfigurationFile;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.core.util.json.JsonPrintable;
import com.oracle.svm.core.util.json.JsonWriter;

public class ConfigurationSet {
@FunctionalInterface
Expand Down Expand Up @@ -66,7 +69,7 @@ public ConfigurationSet(ConfigurationSet other) {
}

public ConfigurationSet() {
this(new TypeConfiguration(), new TypeConfiguration(), new ResourceConfiguration(), new ProxyConfiguration(), new SerializationConfiguration(),
this(new TypeConfiguration(REFLECTION_KEY), new TypeConfiguration(JNI_KEY), new ResourceConfiguration(), new ProxyConfiguration(), new SerializationConfiguration(),
new PredefinedClassesConfiguration(new Path[0], hash -> false));
}

Expand Down
Loading