import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Function;
boolean sourcesPersisted = false;
for (YangParserConfiguration parserConfig : parserConfigs) {
- final Optional<ProcessorModuleReactor> optReactor = createReactor(yangFilesInProject,
- parserConfig, dependencies, parsed);
- if (optReactor.isPresent()) {
- final ProcessorModuleReactor reactor = optReactor.orElseThrow();
+ final var moduleReactor = createReactor(yangFilesInProject, parserConfig, dependencies, parsed);
+ final var yangSw = Stopwatch.createStarted();
- final Stopwatch sw = Stopwatch.createStarted();
- final ContextHolder holder;
+ final ContextHolder holder;
+ try {
+ holder = moduleReactor.toContext();
+ } catch (YangParserException e) {
+ throw new MojoFailureException("Failed to process reactor " + moduleReactor, e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to read reactor " + moduleReactor, e);
+ }
- try {
- holder = reactor.toContext();
- } catch (YangParserException e) {
- throw new MojoFailureException("Failed to process reactor " + reactor, e);
- } catch (IOException e) {
- throw new MojoExecutionException("Failed to read reactor " + reactor, e);
- }
+ LOG.info("{} {} YANG models processed in {}", LOG_PREFIX, holder.getContext().getModules().size(), yangSw);
- LOG.info("{} {} YANG models processed in {}", LOG_PREFIX, holder.getContext().getModules().size(), sw);
+ for (var factory : codeGenerators) {
+ if (!parserConfig.equals(factory.parserConfig())) {
+ continue;
+ }
- for (GeneratorTaskFactory factory : codeGenerators) {
- if (!parserConfig.equals(factory.parserConfig())) {
- continue;
- }
+ final var genSw = Stopwatch.createStarted();
+ final var generatorTask = factory.createTask(project, holder);
+ LOG.debug("{} Task {} initialized in {}", LOG_PREFIX, generatorTask, genSw);
- final Stopwatch genSw = Stopwatch.createStarted();
- final GeneratorTask task = factory.createTask(project, holder);
- LOG.debug("{} Task {} initialized in {}", LOG_PREFIX, task, genSw);
+ final List<FileState> files;
+ try {
+ files = generatorTask.execute();
+ } catch (FileGeneratorException | IOException e) {
+ throw new MojoFailureException(LOG_PREFIX + " Generator " + factory + " failed", e);
+ }
- final List<FileState> files;
- try {
- files = task.execute();
- } catch (FileGeneratorException | IOException e) {
- throw new MojoFailureException(LOG_PREFIX + " Generator " + factory + " failed", e);
- }
+ files.forEach(state -> buildContext.refresh(new File(state.path())));
+ outputFiles.addAll(files);
- files.forEach(state -> buildContext.refresh(new File(state.path())));
- outputFiles.addAll(files);
+ LOG.info("{} Sources generated by {}: {} in {}", LOG_PREFIX, factory.generatorName(), files.size(),
+ genSw);
+ }
- LOG.info("{} Sources generated by {}: {} in {}", LOG_PREFIX, factory.generatorName(), files.size(),
- genSw);
+ if (!sourcesPersisted) {
+ // add META_INF/yang once
+ final var models = moduleReactor.getModelsInProject();
+ final Collection<FileState> sourceFileStates;
+ try {
+ sourceFileStates = yangProvider.addYangsToMetaInf(project, models);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed write model files for " + models, e);
}
- if (!sourcesPersisted) {
- // add META_INF/yang once
- final var models = reactor.getModelsInProject();
- final Collection<FileState> sourceFileStates;
- try {
- sourceFileStates = yangProvider.addYangsToMetaInf(project, models);
- } catch (IOException e) {
- throw new MojoExecutionException("Failed write model files for " + models, e);
- }
-
- sourcesPersisted = true;
- outputFiles.addAll(sourceFileStates);
- }
+ sourcesPersisted = true;
+ outputFiles.addAll(sourceFileStates);
}
}
}
@SuppressWarnings("checkstyle:illegalCatch")
- private Optional<ProcessorModuleReactor> createReactor(final List<File> yangFilesInProject,
+ private @NonNull ProcessorModuleReactor createReactor(final List<File> yangFilesInProject,
final YangParserConfiguration parserConfig, final Collection<ScannedDependency> dependencies,
final List<Entry<YangTextSchemaSource, YangIRSchemaSource>> parsed) throws MojoExecutionException {
final ProcessorModuleReactor reactor = new ProcessorModuleReactor(parser, sourcesInProject, dependencies);
LOG.debug("Initialized reactor {} with {}", reactor, yangFilesInProject);
- return Optional.of(reactor);
+ return reactor;
} catch (IOException | YangSyntaxErrorException | RuntimeException e) {
// MojoExecutionException is thrown since execution cannot continue
LOG.error("{} Unable to parse YANG files from {}", LOG_PREFIX, yangFilesRootDir, e);