Skip to content
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 @@ -69,7 +69,7 @@ public final class RuntimeReflection {
* @since 19.0
*/
public static void register(Class<?>... classes) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.objectReachable(), classes);
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), classes);
}

/**
Expand All @@ -80,7 +80,7 @@ public static void register(Class<?>... classes) {
* @since 19.0
*/
public static void register(Executable... methods) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.objectReachable(), methods);
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), methods);
}

/**
Expand All @@ -91,7 +91,7 @@ public static void register(Executable... methods) {
* @since 19.0
*/
public static void register(Field... fields) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.objectReachable(), false, fields);
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), false, fields);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class RuntimeSerialization {
* @since 21.3
*/
public static void register(Class<?>... classes) {
ImageSingletons.lookup(RuntimeSerializationSupport.class).register(ConfigurationCondition.objectReachable(), classes);
ImageSingletons.lookup(RuntimeSerializationSupport.class).register(ConfigurationCondition.alwaysTrue(), classes);
}

/**
Expand All @@ -76,7 +76,7 @@ public static void register(Class<?>... classes) {
* @since 21.3
*/
public static void registerWithTargetConstructorClass(Class<?> clazz, Class<?> customTargetConstructorClazz) {
ImageSingletons.lookup(RuntimeSerializationSupport.class).registerWithTargetConstructorClass(ConfigurationCondition.objectReachable(), clazz, customTargetConstructorClazz);
ImageSingletons.lookup(RuntimeSerializationSupport.class).registerWithTargetConstructorClass(ConfigurationCondition.alwaysTrue(), clazz, customTargetConstructorClazz);
}

private RuntimeSerialization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class ConfigurationCondition implements Comparable<ConfigurationCon
private final String typeName;
private static final ConfigurationCondition OBJECT_REACHABLE = new ConfigurationCondition(Object.class.getTypeName());

public static ConfigurationCondition objectReachable() {
public static ConfigurationCondition alwaysTrue() {
return OBJECT_REACHABLE;
}

Expand Down Expand Up @@ -87,4 +87,9 @@ public int hashCode() {
public int compareTo(ConfigurationCondition o) {
return this.typeName.compareTo(o.typeName);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe objectReachable() should really be named alwaysTrue() for easier comprehension of code that registers types, proxies, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like that, will change.


@Override
public String toString() {
return "[typeReachable: \"" + typeName + "\"" + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ private static void doTestTypeConfig(TypeConfiguration typeConfig) {
}

private static void doTestExpectedMissingTypes(TypeConfiguration typeConfig) {
Assert.assertNull(typeConfig.get(ConfigurationCondition.objectReachable(), "FlagTestA"));
Assert.assertNull(typeConfig.get(ConfigurationCondition.objectReachable(), "FlagTestB"));
Assert.assertNull(typeConfig.get(ConfigurationCondition.alwaysTrue(), "FlagTestA"));
Assert.assertNull(typeConfig.get(ConfigurationCondition.alwaysTrue(), "FlagTestB"));
}

private static void doTestTypeFlags(TypeConfiguration typeConfig) {
Expand Down Expand Up @@ -182,26 +182,28 @@ private static void doTestMethods(TypeConfiguration typeConfig) {
}

private static void doTestProxyConfig(ProxyConfiguration proxyConfig) {
Assert.assertFalse(proxyConfig.contains("testProxySeenA", "testProxySeenB", "testProxySeenC"));
Assert.assertTrue(proxyConfig.contains("testProxyUnseen"));
ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
Assert.assertFalse(proxyConfig.contains(condition, "testProxySeenA", "testProxySeenB", "testProxySeenC"));
Assert.assertTrue(proxyConfig.contains(condition, "testProxyUnseen"));
}

private static void doTestResourceConfig(ResourceConfiguration resourceConfig) {
Assert.assertFalse(resourceConfig.anyResourceMatches("seenResource.txt"));
Assert.assertTrue(resourceConfig.anyResourceMatches("unseenResource.txt"));

Assert.assertFalse(resourceConfig.anyBundleMatches("seenBundle"));
Assert.assertTrue(resourceConfig.anyBundleMatches("unseenBundle"));
ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
Assert.assertFalse(resourceConfig.anyBundleMatches(condition, "seenBundle"));
Assert.assertTrue(resourceConfig.anyBundleMatches(condition, "unseenBundle"));
}

private static void doTestSerializationConfig(SerializationConfiguration serializationConfig) {
ConfigurationCondition condition = ConfigurationCondition.objectReachable();
ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
Assert.assertFalse(serializationConfig.contains(condition, "seenType", null));
Assert.assertTrue(serializationConfig.contains(condition, "unseenType", null));
}

private static ConfigurationType getConfigTypeOrFail(TypeConfiguration typeConfig, String typeName) {
ConfigurationType type = typeConfig.get(ConfigurationCondition.objectReachable(), typeName);
ConfigurationType type = typeConfig.get(ConfigurationCondition.alwaysTrue(), typeName);
Assert.assertNotNull(type);
return type;
}
Expand Down Expand Up @@ -261,11 +263,11 @@ Map<ConfigurationMethod, ConfigurationMemberKind> getMethodsMap(ConfigurationMem
}

void populateConfig() {
ConfigurationType oldType = new ConfigurationType(ConfigurationCondition.objectReachable(), getTypeName());
ConfigurationType oldType = new ConfigurationType(ConfigurationCondition.alwaysTrue(), getTypeName());
setFlags(oldType);
previousConfig.add(oldType);

ConfigurationType newType = new ConfigurationType(ConfigurationCondition.objectReachable(), getTypeName());
ConfigurationType newType = new ConfigurationType(ConfigurationCondition.alwaysTrue(), getTypeName());
for (Map.Entry<ConfigurationMethod, ConfigurationMemberKind> methodEntry : methodsThatMustExist.entrySet()) {
newType.addMethod(methodEntry.getKey().getName(), methodEntry.getKey().getInternalSignature(), methodEntry.getValue());
}
Expand Down Expand Up @@ -296,7 +298,7 @@ String getTypeName() {

void doTest() {
String name = getTypeName();
ConfigurationType configurationType = currentConfig.get(ConfigurationCondition.objectReachable(), name);
ConfigurationType configurationType = currentConfig.get(ConfigurationCondition.alwaysTrue(), name);
if (methodsThatMustExist.size() == 0) {
Assert.assertNull("Generated configuration type " + name + " exists. Expected it to be cleared as it is empty.", configurationType);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.LinkedList;
import java.util.List;

import org.graalvm.nativeimage.impl.ConfigurationCondition;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -44,14 +45,15 @@ public class ResourceConfigurationTest {
@Test
public void anyResourceMatches() {
ResourceConfiguration rc = new ResourceConfiguration();
rc.addResourcePattern(".*/Resource.*txt$");
ConfigurationCondition defaultCond = ConfigurationCondition.alwaysTrue();
rc.addResourcePattern(defaultCond, ".*/Resource.*txt$");

Assert.assertTrue(rc.anyResourceMatches("com/my/app/Resource0.txt"));
Assert.assertTrue(rc.anyResourceMatches("com/my/app/Resource1.txt"));
Assert.assertTrue(rc.anyResourceMatches("/Resource2.txt"));
Assert.assertTrue(rc.anyResourceMatches("/Resource3.txt"));

rc.ignoreResourcePattern(".*/Resource2.txt$");
rc.ignoreResourcePattern(defaultCond, ".*/Resource2.txt$");

Assert.assertTrue(rc.anyResourceMatches("com/my/app/Resource0.txt"));
Assert.assertTrue(rc.anyResourceMatches("com/my/app/Resource1.txt"));
Expand All @@ -62,28 +64,20 @@ public void anyResourceMatches() {
@Test
public void printJson() {
ResourceConfiguration rc = new ResourceConfiguration();
rc.addResourcePattern(".*/Resource.*txt$");
rc.ignoreResourcePattern(".*/Resource2.txt$");
ConfigurationCondition defaultCond = ConfigurationCondition.alwaysTrue();
rc.addResourcePattern(defaultCond, ".*/Resource.*txt$");
rc.ignoreResourcePattern(defaultCond, ".*/Resource2.txt$");
PipedWriter pw = new PipedWriter();
JsonWriter jw = new JsonWriter(pw);

try (PipedReader pr = new PipedReader()) {
pr.connect(pw);

Thread writerThread = new Thread(new Runnable() {

@Override
public void run() {
try {
rc.printJson(jw);
} catch (IOException e) {
Assert.fail(e.getMessage());
} finally {
try {
jw.close();
} catch (IOException e) {
}
}
Thread writerThread = new Thread(() -> {
try (JsonWriter w = jw) {
rc.printJson(w);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
});

Expand All @@ -93,17 +87,17 @@ public void run() {
ResourcesRegistry registry = new ResourcesRegistry() {

@Override
public void addResources(String pattern) {
public void addResources(ConfigurationCondition condition, String pattern) {
addedResources.add(pattern);
}

@Override
public void ignoreResources(String pattern) {
public void ignoreResources(ConfigurationCondition condition, String pattern) {
ignoredResources.add(pattern);
}

@Override
public void addResourceBundles(String name) {
public void addResourceBundles(ConfigurationCondition condition, String name) {
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

final class ConfigurationConditionPrintable {
static void printConditionAttribute(ConfigurationCondition condition, JsonWriter writer) throws IOException {
if (!condition.equals(ConfigurationCondition.objectReachable())) {
if (!condition.equals(ConfigurationCondition.alwaysTrue())) {
writer.quote(CONDITIONAL_KEY).append(":{");
writer.quote(TYPE_REACHABLE_KEY).append(':').quote(condition.getTypeName());
writer.append("},").newline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
Expand Down Expand Up @@ -112,7 +112,7 @@ public TypeConfiguration loadReflectConfig(Function<IOException, Exception> exce

public ProxyConfiguration loadProxyConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
loadConfig(proxyConfigPaths, new ProxyConfigurationParser(types -> proxyConfiguration.add(Arrays.asList(types)), true), exceptionHandler);
loadConfig(proxyConfigPaths, new ProxyConfigurationParser(types -> proxyConfiguration.add(types.getCondition(), new ArrayList<>(types.getElement())), true), exceptionHandler);
return proxyConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,34 @@
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.graalvm.nativeimage.impl.ConfigurationCondition;

import com.oracle.svm.configure.ConfigurationBase;
import com.oracle.svm.configure.json.JsonWriter;
import com.oracle.svm.core.configure.ConditionalElement;

public class ProxyConfiguration implements ConfigurationBase {
private final ConcurrentHashMap.KeySetView<List<String>, Boolean> interfaceLists = ConcurrentHashMap.newKeySet();
private final ConcurrentHashMap.KeySetView<ConditionalElement<List<String>>, Boolean> interfaceLists = ConcurrentHashMap.newKeySet();

public ProxyConfiguration() {
}

public ProxyConfiguration(ProxyConfiguration other) {
for (List<String> interfaceList : other.interfaceLists) {
interfaceLists.add(new ArrayList<>(interfaceList));
for (ConditionalElement<List<String>> interfaceList : other.interfaceLists) {
interfaceLists.add(new ConditionalElement<>(interfaceList.getCondition(), new ArrayList<>(interfaceList.getElement())));
}
}

public void add(List<String> interfaceList) {
interfaceLists.add(interfaceList);
public void add(ConfigurationCondition condition, List<String> interfaceList) {
interfaceLists.add(new ConditionalElement<>(condition, interfaceList));
}

public boolean contains(List<String> interfaceList) {
return interfaceLists.contains(interfaceList);
public boolean contains(ConfigurationCondition condition, List<String> interfaceList) {
return interfaceLists.contains(new ConditionalElement<>(condition, interfaceList));
}

public boolean contains(String... interfaces) {
return contains(Arrays.asList(interfaces));
public boolean contains(ConfigurationCondition condition, String... interfaces) {
return contains(condition, Arrays.asList(interfaces));
}

public void removeAll(ProxyConfiguration other) {
Expand All @@ -63,29 +66,25 @@ public void removeAll(ProxyConfiguration other) {

@Override
public void printJson(JsonWriter writer) throws IOException {
List<String[]> lists = new ArrayList<>(interfaceLists.size());
for (List<String> list : interfaceLists) {
lists.add(list.toArray(new String[0]));
}
lists.sort((a, b) -> {
int c = 0;
for (int i = 0; c == 0 && i < a.length && i < b.length; i++) {
c = a[i].compareTo(b[i]);
}
return (c != 0) ? c : (a.length - b.length);
});
List<ConditionalElement<List<String>>> lists = new ArrayList<>(interfaceLists.size());
lists.addAll(interfaceLists);
lists.sort(ConditionalElement.comparator(ProxyConfiguration::compareList));

writer.append('[');
writer.indent();
String prefix = "";
for (String[] list : lists) {
writer.append(prefix).newline().append('[');
for (ConditionalElement<List<String>> list : lists) {
writer.append(prefix).newline();
writer.append('{').indent().newline();
ConfigurationConditionPrintable.printConditionAttribute(list.getCondition(), writer);
writer.quote("interfaces").append(":").append('[');
String typePrefix = "";
for (String type : list) {
for (String type : list.getElement()) {
writer.append(typePrefix).quote(type);
typePrefix = ",";
}
writer.append(']');
writer.append('}').unindent().newline();
prefix = ",";
}
writer.unindent().newline();
Expand All @@ -97,4 +96,14 @@ public boolean isEmpty() {
return interfaceLists.isEmpty();
}

private static <T extends Comparable<T>> int compareList(List<T> l1, List<T> l2) {
for (int i = 0; i < l1.size() && i < l2.size(); i++) {
int c = l1.get(i).compareTo(l2.get(i));
if (c != 0) {
return c;
}
}
return l1.size() - l2.size();
}

}
Loading