Do not instantiate allFiles 29/104629/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Feb 2023 18:07:09 +0000 (19:07 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Feb 2023 18:07:09 +0000 (19:07 +0100)
We are just performing a simple check -- we can do that via
concatenating two streams instead.

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

index 26770b164f228758dcbc87aca0634b1646111123..1ebae81a276c9ad6eb47d6d33c7e1cd9cb6b01da 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Optional;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
@@ -150,17 +151,11 @@ class YangToSourcesProcessor {
 
         // All files which affect YANG context. This minimally includes all files in the current project, but optionally
         // may include any YANG files in the dependencies.
-        final Collection<File> allFiles = new ArrayList<>(yangFilesInProject);
-        final Collection<ScannedDependency> dependencies;
+        final List<ScannedDependency> dependencies;
         if (inspectDependencies) {
-            dependencies = new ArrayList<>();
             final Stopwatch watch = Stopwatch.createStarted();
-
             try {
-                ScannedDependency.scanDependencies(project).forEach(dep -> {
-                    allFiles.add(dep.file());
-                    dependencies.add(dep);
-                });
+                dependencies = ScannedDependency.scanDependencies(project);
             } catch (IOException e) {
                 LOG.error("{} Failed to scan dependencies", LOG_PREFIX, e);
                 throw new MojoExecutionException(LOG_PREFIX + " Failed to scan dependencies ", e);
@@ -174,8 +169,9 @@ class YangToSourcesProcessor {
          * Check if any of the listed files changed. If no changes occurred, simply return empty, which indicates
          * end of execution.
          */
-        if (!allFiles.stream().anyMatch(buildContext::hasDelta)) {
-            LOG.info("{} None of {} input files changed", LOG_PREFIX, allFiles.size());
+        if (!Stream.concat(yangFilesInProject.stream(), dependencies.stream().map(ScannedDependency::file))
+                .anyMatch(buildContext::hasDelta)) {
+            LOG.info("{} None of {} input files changed", LOG_PREFIX, yangFilesInProject.size() + dependencies.size());
             return;
         }