Search in sources :

Example 1 with JsonGeneratorFactory

use of net.morimekta.providence.generator.format.json.JsonGeneratorFactory in project providence by morimekta.

the class GeneratorOptions method getFactories.

public Map<String, GeneratorFactory> getFactories() {
    try {
        FactoryLoader<GeneratorFactory> loader = new FactoryLoader<>(GeneratorFactory.MANIFEST_PROPERTY);
        Map<String, GeneratorFactory> factories = new TreeMap<>();
        factories.put("json", new JsonGeneratorFactory());
        File currentDir = currentJarDirectory();
        if (currentDir != null) {
            File generators = new File(currentDir, "generator");
            if (generators.isDirectory()) {
                addToMap(factories, loader.getFactories(generators));
            }
        }
        {
            ProvidenceTools config = getConfig();
            if (config.hasGeneratorPaths()) {
                for (String path : config.getGeneratorPaths()) {
                    addToMap(factories, loader.getFactories(new File(path)));
                }
            }
        }
        for (File extra : extraGenerators) {
            GeneratorFactory factory = loader.getFactory(extra);
            factories.put(factory.generatorName(), factory);
        }
        return factories;
    } catch (ProvidenceConfigException e) {
        throw new UncheckedProvidenceConfigException(e);
    }
}
Also used : GeneratorFactory(net.morimekta.providence.generator.GeneratorFactory) JsonGeneratorFactory(net.morimekta.providence.generator.format.json.JsonGeneratorFactory) FactoryLoader(net.morimekta.providence.generator.util.FactoryLoader) ProvidenceTools(net.morimekta.providence.tools.common.ProvidenceTools) JsonGeneratorFactory(net.morimekta.providence.generator.format.json.JsonGeneratorFactory) TreeMap(java.util.TreeMap) UncheckedProvidenceConfigException(net.morimekta.providence.config.UncheckedProvidenceConfigException) File(java.io.File) ProvidenceConfigException(net.morimekta.providence.config.ProvidenceConfigException) UncheckedProvidenceConfigException(net.morimekta.providence.config.UncheckedProvidenceConfigException)

Aggregations

File (java.io.File)1 TreeMap (java.util.TreeMap)1 ProvidenceConfigException (net.morimekta.providence.config.ProvidenceConfigException)1 UncheckedProvidenceConfigException (net.morimekta.providence.config.UncheckedProvidenceConfigException)1 GeneratorFactory (net.morimekta.providence.generator.GeneratorFactory)1 JsonGeneratorFactory (net.morimekta.providence.generator.format.json.JsonGeneratorFactory)1 FactoryLoader (net.morimekta.providence.generator.util.FactoryLoader)1 ProvidenceTools (net.morimekta.providence.tools.common.ProvidenceTools)1