import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException;
import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory;
import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
final var stateListBuilder = ImmutableList.<FileState>builderWithExpectedSize(modelsInProject.size());
for (var source : modelsInProject) {
- final File file = new File(withMetaInf, source.getIdentifier().toYangFilename());
+ final File file = new File(withMetaInf, source.sourceId().toYangFilename());
stateListBuilder.add(FileState.ofWrittenFile(file,
out -> source.asByteSource(StandardCharsets.UTF_8).copyTo(out)));
- LOG.debug("Created file {} for {}", file, source.getIdentifier());
+ LOG.debug("Created file {} for {}", file, source.sourceId());
}
ProjectFileAccess.addResourceDir(project, generatedYangDir);
final Stopwatch watch = Stopwatch.createStarted();
- final List<Entry<YangTextSchemaSource, YangIRSchemaSource>> parsed = yangFilesInProject.parallelStream()
+ final List<Entry<YangTextSource, YangIRSchemaSource>> parsed = yangFilesInProject.parallelStream()
.map(file -> {
- final YangTextSchemaSource textSource = YangTextSchemaSource.forPath(file.toPath());
+ final var textSource = YangTextSource.forPath(file.toPath());
try {
return Map.entry(textSource, TextToIRTransformer.transformText(textSource));
} catch (YangSyntaxErrorException | IOException e) {
LOG.info("{} Project model files found: {} in {}", LOG_PREFIX, yangFilesInProject.size(), watch);
final var outputFiles = ImmutableList.<FileState>builder();
- Collection<YangTextSchemaSource> modelsInProject = null;
+ Collection<YangTextSource> modelsInProject = null;
for (var parserConfig : codeGenerators.stream().map(GeneratorTask::parserConfig).collect(Collectors.toSet())) {
final var moduleReactor = createReactor(yangFilesInProject, parserConfig, dependencies, parsed);
final var yangSw = Stopwatch.createStarted();
}
}
- private List<GeneratorTask> instantiateGenerators() throws MojoExecutionException {
+ private ImmutableList<@NonNull GeneratorTask> instantiateGenerators() throws MojoExecutionException {
// Search for available FileGenerator implementations
- final Map<String, FileGeneratorFactory> factories = Maps.uniqueIndex(
+ final var factories = Maps.uniqueIndex(
ServiceLoader.load(FileGeneratorFactory.class), FileGeneratorFactory::getIdentifier);
// FIXME: iterate over fileGeneratorArg instances (configuration), not factories (environment)
// Assign instantiate FileGenerators with appropriate configuration
- final var generators = new ArrayList<GeneratorTask>(factories.size());
- for (Entry<String, FileGeneratorFactory> entry : factories.entrySet()) {
- final String id = entry.getKey();
- FileGeneratorArg arg = fileGeneratorArgs.get(id);
+ final var builder = ImmutableList.<@NonNull GeneratorTask>builderWithExpectedSize(factories.size());
+ for (var entry : factories.entrySet()) {
+ final var id = entry.getKey();
+ var arg = fileGeneratorArgs.get(id);
if (arg == null) {
LOG.debug("{} No configuration for {}, using empty", LOG_PREFIX, id);
arg = new FileGeneratorArg(id);
} catch (FileGeneratorException e) {
throw new MojoExecutionException("File generator " + id + " failed", e);
}
- generators.add(task);
+ builder.add(task);
LOG.info("{} Code generator {} instantiated", LOG_PREFIX, id);
}
}
);
- return generators;
+ return builder.build();
}
@SuppressWarnings("checkstyle:illegalCatch")
private @NonNull ProcessorModuleReactor createReactor(final List<File> yangFilesInProject,
final YangParserConfiguration parserConfig, final Collection<ScannedDependency> dependencies,
- final List<Entry<YangTextSchemaSource, YangIRSchemaSource>> parsed) throws MojoExecutionException {
+ final List<Entry<YangTextSource, YangIRSchemaSource>> parsed) throws MojoExecutionException {
try {
- final var sourcesInProject = new ArrayList<YangTextSchemaSource>(yangFilesInProject.size());
+ final var sourcesInProject = new ArrayList<YangTextSource>(yangFilesInProject.size());
final var parser = parserFactory.createParser(parserConfig);
for (var entry : parsed) {
final var textSource = entry.getKey();
final var astSource = entry.getValue();
parser.addSource(astSource);
- if (!astSource.getIdentifier().equals(textSource.getIdentifier())) {
+ if (!astSource.sourceId().equals(textSource.sourceId())) {
// AST indicates a different source identifier, make sure we use that
- sourcesInProject.add(YangTextSchemaSource.delegateForCharSource(astSource.getIdentifier(),
- textSource));
+ sourcesInProject.add(new DelegatedYangTextSource(astSource.sourceId(), textSource));
} else {
sourcesInProject.add(textSource);
}