Move model addition out of the loop 08/104808/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Mar 2023 14:32:27 +0000 (15:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Mar 2023 15:28:08 +0000 (16:28 +0100)
Normalized names for YANG files in the project should be output outside
of the per-generator task.

JIRA: YANGTOOLS-745
Change-Id: Id15d9ba6a5786eb54fb39d0c9f50c62672df82f0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java

index 29dfb8f9a3e68d1b32ca53d60d945c7f3bac66db..ea4401d9c439017e35795197c72d85f73ae44e84 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang2sources.plugin;
 import com.google.common.annotations.VisibleForTesting;
 import java.io.IOException;
 import java.util.Collection;
+import java.util.List;
 import org.apache.maven.project.MavenProject;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
@@ -17,6 +18,6 @@ import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 @VisibleForTesting
 interface YangProvider {
 
-    Collection<FileState> addYangsToMetaInf(MavenProject project,
+    List<FileState> addYangsToMetaInf(MavenProject project,
             Collection<YangTextSchemaSource> modelsInProject) throws IOException;
 }
index 86f536b16263eaa077cee238903bb38b2c2179ad..5262a53002393d53f3ea1aa279a3de071506966b 100644 (file)
@@ -241,7 +241,7 @@ class YangToSourcesProcessor {
             .collect(ImmutableMap.toImmutableMap(FileState::path, Function.identity())));
 
         final var outputFiles = ImmutableList.<FileState>builder();
-        boolean sourcesPersisted = false;
+        Collection<YangTextSchemaSource> modelsInProject = null;
 
         for (YangParserConfiguration parserConfig : parserConfigs) {
             final var moduleReactor = createReactor(yangFilesInProject, parserConfig, dependencies, parsed);
@@ -255,7 +255,6 @@ class YangToSourcesProcessor {
             } catch (IOException e) {
                 throw new MojoExecutionException("Failed to read reactor " + moduleReactor, e);
             }
-
             LOG.info("{} {} YANG models processed in {}", LOG_PREFIX, holder.getContext().getModules().size(), yangSw);
 
             for (var factory : codeGenerators) {
@@ -276,21 +275,19 @@ class YangToSourcesProcessor {
                     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);
-                }
-
-                sourcesPersisted = true;
-                outputFiles.addAll(sourceFileStates);
+            if (modelsInProject == null) {
+                // FIXME: this is an invariant, we should prepare these separately
+                modelsInProject = moduleReactor.getModelsInProject();
             }
         }
 
+        // add META_INF/yang once
+        try {
+            outputFiles.addAll(yangProvider.addYangsToMetaInf(project, modelsInProject));
+        } catch (IOException e) {
+            throw new MojoExecutionException("Failed write model files for " + modelsInProject, e);
+        }
+
         // add META_INF/services
         File generatedServicesDir = new File(new File(project.getBuild().getDirectory(), "generated-sources"), "spi");
         ProjectFileAccess.addResourceDir(project, generatedServicesDir);