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;
}
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();
}
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());
}
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));
}
Aggregations