Search in sources :

Example 1 with ResourceConfiguration

use of com.oracle.svm.configure.config.ResourceConfiguration in project graal by oracle.

the class ResourceConfigurationTest method printJson.

@Test
public void printJson() {
    ResourceConfiguration rc = new ResourceConfiguration();
    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(() -> {
            try (JsonWriter w = jw) {
                rc.printJson(w);
            } catch (IOException e) {
                Assert.fail(e.getMessage());
            }
        });
        List<String> addedResources = new LinkedList<>();
        List<String> ignoredResources = new LinkedList<>();
        ResourcesRegistry registry = new ResourcesRegistry() {

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

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

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

            @Override
            public void addResourceBundles(ConfigurationCondition condition, String basename, Collection<Locale> locales) {
            }

            @Override
            public void addClassBasedResourceBundle(ConfigurationCondition condition, String basename, String className) {
            }
        };
        ResourceConfigurationParser rcp = new ResourceConfigurationParser(registry, true);
        writerThread.start();
        rcp.parseAndRegister(pr);
        writerThread.join();
        Assert.assertTrue(addedResources.contains(".*/Resource.*txt$"));
        Assert.assertTrue(ignoredResources.contains(".*/Resource2.txt$"));
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : ConfigurationCondition(org.graalvm.nativeimage.impl.ConfigurationCondition) IOException(java.io.IOException) JsonWriter(com.oracle.svm.configure.json.JsonWriter) PipedReader(java.io.PipedReader) LinkedList(java.util.LinkedList) ResourceConfiguration(com.oracle.svm.configure.config.ResourceConfiguration) ResourcesRegistry(com.oracle.svm.core.configure.ResourcesRegistry) PipedWriter(java.io.PipedWriter) Collection(java.util.Collection) ResourceConfigurationParser(com.oracle.svm.core.configure.ResourceConfigurationParser) Test(org.junit.Test)

Example 2 with ResourceConfiguration

use of com.oracle.svm.configure.config.ResourceConfiguration in project graal by oracle.

the class TraceProcessor method getResourceConfiguration.

public ResourceConfiguration getResourceConfiguration() {
    ResourceConfiguration result = reflectionProcessor.getResourceConfiguration();
    if (omittedConfigProcessor != null) {
        result = new ResourceConfiguration(result);
        result.removeAll(omittedConfigProcessor.reflectionProcessor.getResourceConfiguration());
    }
    return result;
}
Also used : ResourceConfiguration(com.oracle.svm.configure.config.ResourceConfiguration)

Example 3 with ResourceConfiguration

use of com.oracle.svm.configure.config.ResourceConfiguration in project graal by oracle.

the class ConfigurationWithOriginsResultWriter method createNewTraceProcessor.

private TraceProcessor createNewTraceProcessor() {
    TypeConfiguration jniConfig = new TypeConfiguration();
    TypeConfiguration reflectConfig = new TypeConfiguration();
    ProxyConfiguration proxyConfig = new ProxyConfiguration();
    ResourceConfiguration resourceConfig = new ResourceConfiguration();
    SerializationConfiguration serializationConfiguration = new SerializationConfiguration();
    PredefinedClassesConfiguration predefinedClassesConfiguration = new PredefinedClassesConfiguration(new Path[0], null);
    return new TraceProcessor(advisor, jniConfig, reflectConfig, proxyConfig, resourceConfig, serializationConfiguration, predefinedClassesConfiguration, null);
}
Also used : ProxyConfiguration(com.oracle.svm.configure.config.ProxyConfiguration) TraceProcessor(com.oracle.svm.configure.trace.TraceProcessor) TypeConfiguration(com.oracle.svm.configure.config.TypeConfiguration) SerializationConfiguration(com.oracle.svm.configure.config.SerializationConfiguration) PredefinedClassesConfiguration(com.oracle.svm.configure.config.PredefinedClassesConfiguration) ResourceConfiguration(com.oracle.svm.configure.config.ResourceConfiguration)

Example 4 with ResourceConfiguration

use of com.oracle.svm.configure.config.ResourceConfiguration in project graal by oracle.

the class ResourceConfigurationTest method anyResourceMatches.

@Test
public void anyResourceMatches() {
    ResourceConfiguration rc = new ResourceConfiguration();
    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(defaultCond, ".*/Resource2.txt$");
    Assert.assertTrue(rc.anyResourceMatches("com/my/app/Resource0.txt"));
    Assert.assertTrue(rc.anyResourceMatches("com/my/app/Resource1.txt"));
    Assert.assertFalse(rc.anyResourceMatches("/Resource2.txt"));
    Assert.assertTrue(rc.anyResourceMatches("/Resource3.txt"));
}
Also used : ConfigurationCondition(org.graalvm.nativeimage.impl.ConfigurationCondition) ResourceConfiguration(com.oracle.svm.configure.config.ResourceConfiguration) Test(org.junit.Test)

Aggregations

ResourceConfiguration (com.oracle.svm.configure.config.ResourceConfiguration)4 ConfigurationCondition (org.graalvm.nativeimage.impl.ConfigurationCondition)2 Test (org.junit.Test)2 PredefinedClassesConfiguration (com.oracle.svm.configure.config.PredefinedClassesConfiguration)1 ProxyConfiguration (com.oracle.svm.configure.config.ProxyConfiguration)1 SerializationConfiguration (com.oracle.svm.configure.config.SerializationConfiguration)1 TypeConfiguration (com.oracle.svm.configure.config.TypeConfiguration)1 JsonWriter (com.oracle.svm.configure.json.JsonWriter)1 TraceProcessor (com.oracle.svm.configure.trace.TraceProcessor)1 ResourceConfigurationParser (com.oracle.svm.core.configure.ResourceConfigurationParser)1 ResourcesRegistry (com.oracle.svm.core.configure.ResourcesRegistry)1 IOException (java.io.IOException)1 PipedReader (java.io.PipedReader)1 PipedWriter (java.io.PipedWriter)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1