Encapsulate GeneratorTask 94/104794/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Mar 2023 21:33:13 +0000 (22:33 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Mar 2023 21:49:47 +0000 (22:49 +0100)
The distinction between GeneratorTask and GeneratorTaskFactory is very
moot. Simplify the interface to YangToSourcesProcessor, which enables us
to merge the two classes.

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

index d9318dcf59937237b238ba99bb4964b94aaf8cd0..c876629ab938909f77f92974f4f476aed70cc809 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.yangtools.yang2sources.plugin;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
+import java.io.IOException;
+import java.util.List;
 import org.apache.maven.project.MavenProject;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.concepts.Identifiable;
@@ -64,9 +66,13 @@ final class GeneratorTaskFactory implements Identifiable<String> {
      *
      * @param project current Maven Project
      * @param context model generation context
+     * @return {@link FileState} for every generated file
+     * @throws FileGeneratorException if the underlying {@link #generator()} fails
+     * @throws IOException when a generated file cannot be written
      */
-    GeneratorTask createTask(final MavenProject project, final ContextHolder context) {
-        return new GeneratorTask(this, context, new ProjectFileAccess(project, getIdentifier()));
+    List<FileState> execute(final MavenProject project, final ContextHolder context)
+            throws FileGeneratorException, IOException {
+        return new GeneratorTask(this, context, new ProjectFileAccess(project, getIdentifier())).execute();
     }
 
     @Override
index 84c7c9d775f5940159fd44ee92952eaa039f82aa..1eaed68577f81fc4fcff594cfb8ff8c462648c7b 100644 (file)
@@ -239,12 +239,9 @@ class YangToSourcesProcessor {
                 }
 
                 final var genSw = Stopwatch.createStarted();
-                final var generatorTask = factory.createTask(project, holder);
-                LOG.debug("{} Task {} initialized in {}", LOG_PREFIX, generatorTask, genSw);
-
                 final List<FileState> files;
                 try {
-                    files = generatorTask.execute();
+                    files = factory.execute(project, holder);
                 } catch (FileGeneratorException | IOException e) {
                     throw new MojoFailureException(LOG_PREFIX + " Generator " + factory + " failed", e);
                 }