Search in sources :

Example 1 with FileGeneratorFactory

use of org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory in project yangtools by opendaylight.

the class YangToSourcesProcessor method instantiateGenerators.

private List<GeneratorTaskFactory> instantiateGenerators() throws MojoExecutionException, MojoFailureException {
    final List<GeneratorTaskFactory> generators = new ArrayList<>(codeGeneratorArgs.size());
    for (CodeGeneratorArg arg : codeGeneratorArgs) {
        generators.add(CodeGeneratorTaskFactory.create(arg));
        LOG.info("{} Code generator instantiated from {}", LOG_PREFIX, arg.getCodeGeneratorClass());
    }
    // Search for available FileGenerator implementations
    final Map<String, FileGeneratorFactory> factories = Maps.uniqueIndex(ServiceLoader.load(FileGeneratorFactory.class), FileGeneratorFactory::getIdentifier);
    // Assign instantiate FileGenerators with appropriate configurate
    for (Entry<String, FileGeneratorFactory> entry : factories.entrySet()) {
        final String id = entry.getKey();
        FileGeneratorArg arg = fileGeneratorArgs.get(id);
        if (arg == null) {
            LOG.debug("{} No configuration for {}, using empty", LOG_PREFIX, id);
            arg = new FileGeneratorArg(id);
        }
        try {
            generators.add(FileGeneratorTaskFactory.of(entry.getValue(), arg));
        } catch (FileGeneratorException e) {
            throw new MojoExecutionException("File generator " + id + " failed", e);
        }
        LOG.info("{} Code generator {} instantiated", LOG_PREFIX, id);
    }
    return generators;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileGeneratorFactory(org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory) FileGeneratorException(org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException) CodeGeneratorArg(org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 FileGeneratorException (org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException)1 FileGeneratorFactory (org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory)1 CodeGeneratorArg (org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg)1