Expose URLYangTextSource
[yangtools.git] / plugin / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / YangToSourcesProcessor.java
index 1ed6f6888f8bb95879c87b7ea933d9755b35bfef..8297a392e2e04fe863f52773ff3fa0daf20b3703 100644 (file)
@@ -39,8 +39,9 @@ import org.eclipse.jdt.annotation.NonNull;
 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;
@@ -87,10 +88,10 @@ class YangToSourcesProcessor {
 
         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);
@@ -244,9 +245,9 @@ class YangToSourcesProcessor {
 
         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) {
@@ -258,7 +259,7 @@ class YangToSourcesProcessor {
         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();
@@ -347,17 +348,17 @@ class YangToSourcesProcessor {
         }
     }
 
-    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);
@@ -369,7 +370,7 @@ class YangToSourcesProcessor {
             } 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);
         }
 
@@ -382,26 +383,25 @@ class YangToSourcesProcessor {
             }
         );
 
-        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);
                 }