Search in sources :

Example 1 with CodeGeneratorArg

use of org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg 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)

Example 2 with CodeGeneratorArg

use of org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg in project yangtools by opendaylight.

the class YangToSourcesProcessorTest method test.

@Test
public void test() throws Exception {
    final File file = new File(getClass().getResource("/yang").getFile());
    final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
    final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(), "target/YangToSourcesProcessorTest-outputBaseDir");
    final List<CodeGeneratorArg> codeGenerators = ImmutableList.of(codeGeneratorArg);
    final Build build = new Build();
    build.setDirectory("foo");
    doReturn(build).when(project).getBuild();
    final boolean dependencies = true;
    final YangToSourcesProcessor proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang), codeGenerators, project, dependencies, YangProvider.getInstance());
    assertNotNull(proc);
    proc.execute();
}
Also used : GeneratorMock(org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock) Build(org.apache.maven.model.Build) CodeGeneratorArg(org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg) File(java.io.File) Test(org.junit.Test)

Example 3 with CodeGeneratorArg

use of org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg in project yangtools by opendaylight.

the class YangToSourcesMojoTest method prepareProcessor.

private void prepareProcessor() {
    final File file = new File(getClass().getResource("/yang").getFile());
    final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
    final String path = file.getPath();
    final List<CodeGeneratorArg> codeGenerators = new ArrayList<>();
    final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(), "target/YangToSourcesMojoTest-outputBaseDir");
    codeGenerators.add(codeGeneratorArg);
    final Build build = new Build();
    build.setDirectory("testDir");
    doReturn(build).when(project).getBuild();
    final boolean dependencies = true;
    this.proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang), codeGenerators, project, dependencies, YangProvider.getInstance());
}
Also used : GeneratorMock(org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock) Build(org.apache.maven.model.Build) CodeGeneratorArg(org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with CodeGeneratorArg

use of org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg in project yangtools by opendaylight.

the class GenerateSourcesTest method setUp.

@Before
public void setUp() throws Exception {
    outDir = new File("/outputDir");
    this.mojo = setupMojo(new YangToSourcesProcessor(new File(Resources.getResource(GenerateSourcesTest.class, "/yang").toURI()), List.of(), List.of(new CodeGeneratorArg(GeneratorMock.class.getName(), "outputDir")), this.project, false, yangProvider));
}
Also used : CodeGeneratorArg(org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg) File(java.io.File) Before(org.junit.Before)

Aggregations

CodeGeneratorArg (org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Build (org.apache.maven.model.Build)2 GeneratorMock (org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 FileGeneratorException (org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException)1 FileGeneratorFactory (org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory)1