import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Stopwatch;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import com.google.common.io.CharStreams;
import java.io.File;
import java.io.IOException;
-import java.io.Reader;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.AbstractMap.SimpleImmutableEntry;
final ProcessorModuleReactor reactor = optReactor.get();
if (!skip) {
+ final Stopwatch watch = Stopwatch.createStarted();
final ContextHolder holder;
try {
- holder = createContextHolder(reactor);
+ 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, watch);
generateSources(holder, codeGenerators);
} else {
- LOG.info("Skipping YANG code generation because property yang.skip is true");
+ LOG.info("{} Skipping YANG code generation because property yang.skip is true", LOG_PREFIX);
}
// add META_INF/yang
private Optional<ProcessorModuleReactor> createReactor(final StatementParserMode parserMode,
final List<File> yangFilesInProject) throws MojoExecutionException {
LOG.info("{} Inspecting {}", LOG_PREFIX, yangFilesRootDir);
- try {
+ try {
final Collection<File> allFiles = new ArrayList<>(yangFilesInProject);
+ final Collection<ScannedDependency> dependencies;
if (inspectDependencies) {
- allFiles.addAll(Util.findYangFilesInDependencies(project));
+ dependencies = new ArrayList<>();
+ final Stopwatch watch = Stopwatch.createStarted();
+ ScannedDependency.scanDependencies(project).forEach(dep -> {
+ allFiles.add(dep.file());
+ dependencies.add(dep);
+ });
+ LOG.info("{} Found {} dependencies in {}", LOG_PREFIX, dependencies.size(), watch);
+ } else {
+ dependencies = ImmutableList.of();
}
/*
}
}
- LOG.debug("Processed project files: {}", yangFilesInProject);
- LOG.info("{} Project model files parsed: {}", LOG_PREFIX, yangFilesInProject.size());
+ LOG.debug("Found project files: {}", yangFilesInProject);
+ LOG.info("{} Project model files found: {}", LOG_PREFIX, yangFilesInProject.size());
- final ProcessorModuleReactor reactor = new ProcessorModuleReactor(parser, sourcesInProject);
+ final ProcessorModuleReactor reactor = new ProcessorModuleReactor(parser, sourcesInProject, dependencies);
LOG.debug("Initialized reactor {}", reactor, yangFilesInProject);
return Optional.of(reactor);
} catch (Exception e) {
}
}
- private ContextHolder createContextHolder(final ProcessorModuleReactor reactor) throws MojoFailureException,
- IOException, YangParserException {
- /**
- * Set contains all modules generated from input sources. Number of
- * modules may differ from number of sources due to submodules
- * (parsed submodule's data are added to its parent module). Set
- * cannot contains null values.
- */
- if (inspectDependencies) {
- final List<YangTextSchemaSource> sourcesInDependencies = Util.findYangFilesInDependenciesAsStream(
- project);
- for (YangTextSchemaSource s : toUniqueSources(sourcesInDependencies)) {
- reactor.registerSourceFromDependency(s);
- }
- }
-
- return reactor.toContext();
- }
-
private static List<File> listFiles(final File root, final Collection<File> excludedFiles)
throws IOException {
if (!root.isDirectory()) {
}).filter(f -> f.getName().endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION)).collect(Collectors.toList());
}
- private static Collection<YangTextSchemaSource> toUniqueSources(final Collection<YangTextSchemaSource> sources)
- throws IOException {
- final Map<String, YangTextSchemaSource> byContent = new HashMap<>();
- for (YangTextSchemaSource s : sources) {
- try (Reader reader = s.asCharSource(StandardCharsets.UTF_8).openStream()) {
- final String contents = CharStreams.toString(reader);
- byContent.putIfAbsent(contents, s);
- }
- }
- return byContent.values();
- }
-
/**
* Call generate on every generator from plugin configuration.
*/
Collection<File> generated = codeGenerator.generateSources(context.getContext(), outputDir,
context.getYangModules(), context::moduleToResourcePath);
- LOG.info("{} Sources generated by {}: {}", LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass(), generated);
+ LOG.debug("{} Sources generated by {}: {}", LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass(), generated);
+ LOG.info("{} Sources generated by {}: {}", LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass(),
+ generated == null ? 0 : generated.size());
}
/**