Search in sources :

Example 1 with ResourceConfigurationParser

use of com.oracle.svm.core.configure.ResourceConfigurationParser in project graal by oracle.

the class ConfigurationSet method loadResourceConfig.

public ResourceConfiguration loadResourceConfig(Function<IOException, Exception> exceptionHandler) throws Exception {
    ResourceConfiguration resourceConfiguration = new ResourceConfiguration();
    loadConfig(resourceConfigPaths, new ResourceConfigurationParser(new ResourceConfiguration.ParserAdapter(resourceConfiguration), true), exceptionHandler);
    return resourceConfiguration;
}
Also used : ResourceConfigurationParser(com.oracle.svm.core.configure.ResourceConfigurationParser)

Example 2 with ResourceConfigurationParser

use of com.oracle.svm.core.configure.ResourceConfigurationParser 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 3 with ResourceConfigurationParser

use of com.oracle.svm.core.configure.ResourceConfigurationParser in project graal by oracle.

the class ResourcesFeature method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
    ResourceConfigurationParser parser = new ResourceConfigurationParser(ImageSingletons.lookup(ResourcesRegistry.class), ConfigurationFiles.Options.StrictConfiguration.getValue());
    loadedConfigurations = ConfigurationParserUtils.parseAndRegisterConfigurations(parser, imageClassLoader, "resource", ConfigurationFiles.Options.ResourceConfigurationFiles, ConfigurationFiles.Options.ResourceConfigurationResources, ConfigurationFile.RESOURCES.getFileName());
    resourcePatternWorkSet.addAll(Options.IncludeResources.getValue().values());
    excludedResourcePatterns.addAll(Options.ExcludeResources.getValue().values());
    resourceRegistryImpl().flushConditionalConfiguration(access);
}
Also used : ResourceConfigurationParser(com.oracle.svm.core.configure.ResourceConfigurationParser) ResourcesRegistry(com.oracle.svm.core.configure.ResourcesRegistry)

Aggregations

ResourceConfigurationParser (com.oracle.svm.core.configure.ResourceConfigurationParser)3 ResourcesRegistry (com.oracle.svm.core.configure.ResourcesRegistry)2 ResourceConfiguration (com.oracle.svm.configure.config.ResourceConfiguration)1 JsonWriter (com.oracle.svm.configure.json.JsonWriter)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 ConfigurationCondition (org.graalvm.nativeimage.impl.ConfigurationCondition)1 Test (org.junit.Test)1