Added 'excludeFiles' option to yang-maven-plugin configuration. 43/943/1
authorMartin Vitez <mvitez@cisco.com>
Wed, 21 Aug 2013 15:51:44 +0000 (17:51 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 21 Aug 2013 15:51:44 +0000 (17:51 +0200)
Signed-off-by: Martin Vitez <mvitez@cisco.com>
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java
yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java

index e40be9789335527a7a2379160bb9e95483bd53d7..0621cb4ab6518b2e886b665b910fb30e12b797fb 100644 (file)
@@ -43,8 +43,7 @@ final class Util {
     // phase Second: yang files are copied as resources during
     // generate-resources phase. This cache ensures that yang files are listed
     // only once.
-    private static Map<File, Collection<File>> cache = Maps
-            .newHashMapWithExpectedSize(10);
+    private static Map<File, Collection<File>> cache = Maps.newHashMapWithExpectedSize(10);
 
     /**
      * List files recursively and return as array of String paths. Use cache of
@@ -58,18 +57,44 @@ final class Util {
             throw new FileNotFoundException(root.toString());
         }
 
-        Collection<File> yangFiles = FileUtils.listFiles(root,
-                new String[] { YANG_SUFFIX }, true);
+        Collection<File> yangFiles = FileUtils.listFiles(root, new String[] { YANG_SUFFIX }, true);
 
         toCache(root, yangFiles);
         return yangFiles;
     }
 
-    static List<InputStream> listFilesAsStream(File rootDir)
+    static Collection<File> listFiles(File root, File[] excludedFiles, Log log) throws FileNotFoundException {
+        if (!root.exists()) {
+            throw new FileNotFoundException(root.toString());
+        }
+        Collection<File> result = new ArrayList<>();
+        Collection<File> yangFiles = FileUtils.listFiles(root, new String[] { YANG_SUFFIX }, true);
+        for (File f : yangFiles) {
+            boolean excluded = false;
+            for (File ex : excludedFiles) {
+                if (ex.equals(f)) {
+                    excluded = true;
+                    break;
+                }
+            }
+            if (excluded) {
+                if(log != null) {
+                    log.info(Util.message("%s file excluded %s", YangToSourcesProcessor.LOG_PREFIX,
+                            Util.YANG_SUFFIX.toUpperCase(), f));
+                }
+            } else {
+                result.add(f);
+            }
+        }
+
+        return result;
+    }
+
+    static List<InputStream> listFilesAsStream(File rootDir, File[] excludedFiles, Log log)
             throws FileNotFoundException {
         List<InputStream> is = new ArrayList<InputStream>();
 
-        Collection<File> files = listFiles(rootDir);
+        Collection<File> files = listFiles(rootDir, excludedFiles, log);
         for (File f : files) {
             is.add(new NamedFileInputStream(f));
         }
@@ -91,33 +116,27 @@ final class Util {
         }
     }
 
-    private static void toCache(final File rootDir,
-            final Collection<File> yangFiles) {
+    private static void toCache(final File rootDir, final Collection<File> yangFiles) {
         cache.put(rootDir, yangFiles);
     }
 
     /**
      * Instantiate object from fully qualified class name
      */
-    static <T> T getInstance(String codeGeneratorClass, Class<T> baseType)
-            throws ClassNotFoundException, InstantiationException,
-            IllegalAccessException {
-        return baseType.cast(resolveClass(codeGeneratorClass, baseType)
-                .newInstance());
+    static <T> T getInstance(String codeGeneratorClass, Class<T> baseType) throws ClassNotFoundException,
+            InstantiationException, IllegalAccessException {
+        return baseType.cast(resolveClass(codeGeneratorClass, baseType).newInstance());
     }
 
-    private static Class<?> resolveClass(String codeGeneratorClass,
-            Class<?> baseType) throws ClassNotFoundException {
+    private static Class<?> resolveClass(String codeGeneratorClass, Class<?> baseType) throws ClassNotFoundException {
         Class<?> clazz = Class.forName(codeGeneratorClass);
 
         if (!isImplemented(baseType, clazz))
-            throw new IllegalArgumentException("Code generator " + clazz
-                    + " has to implement " + baseType);
+            throw new IllegalArgumentException("Code generator " + clazz + " has to implement " + baseType);
         return clazz;
     }
 
-    private static boolean isImplemented(Class<?> expectedIface,
-            Class<?> byClazz) {
+    private static boolean isImplemented(Class<?> expectedIface, Class<?> byClazz) {
         for (Class<?> iface : byClazz.getInterfaces()) {
             if (iface.equals(expectedIface))
                 return true;
@@ -144,21 +163,18 @@ final class Util {
     private static final String JAR_SUFFIX = ".jar";
 
     private static boolean isJar(File element) {
-        return (element.isFile() && element.getName().endsWith(JAR_SUFFIX)) ? true
-                : false;
+        return (element.isFile() && element.getName().endsWith(JAR_SUFFIX)) ? true : false;
     }
 
     static <T> T checkNotNull(T obj, String paramName) {
-        return Preconditions.checkNotNull(obj, "Parameter " + paramName
-                + " is null");
+        return Preconditions.checkNotNull(obj, "Parameter " + paramName + " is null");
     }
 
     final static class YangsInZipsResult implements Closeable {
         final List<InputStream> yangStreams;
         private final List<Closeable> zipInputStreams;
 
-        private YangsInZipsResult(List<InputStream> yangStreams,
-                List<Closeable> zipInputStreams) {
+        private YangsInZipsResult(List<InputStream> yangStreams, List<Closeable> zipInputStreams) {
             this.yangStreams = yangStreams;
             this.zipInputStreams = zipInputStreams;
         }
@@ -174,35 +190,29 @@ final class Util {
         }
     }
 
-    static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log,
-            MavenProject project)
+    static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log, MavenProject project)
             throws MojoFailureException {
         List<InputStream> yangsFromDependencies = new ArrayList<>();
         List<Closeable> zips = new ArrayList<>();
         try {
             List<File> filesOnCp = Util.getClassPath(project);
-            log.info(Util.message(
-                    "Searching for yang files in following dependencies: %s",
+            log.info(Util.message("Searching for yang files in following dependencies: %s",
                     YangToSourcesProcessor.LOG_PREFIX, filesOnCp));
 
             for (File file : filesOnCp) {
                 List<String> foundFilesForReporting = new ArrayList<>();
                 // is it jar file or directory?
                 if (file.isDirectory()) {
-                    File yangDir = new File(file,
-                            YangToSourcesProcessor.META_INF_YANG_STRING);
+                    File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING);
                     if (yangDir.exists() && yangDir.isDirectory()) {
-                        File[] yangFiles = yangDir
-                                .listFiles(new FilenameFilter() {
-                                    @Override
-                                    public boolean accept(File dir, String name) {
-                                        return name.endsWith(".yang")
-                                                && new File(dir, name).isFile();
-                                    }
-                                });
+                        File[] yangFiles = yangDir.listFiles(new FilenameFilter() {
+                            @Override
+                            public boolean accept(File dir, String name) {
+                                return name.endsWith(".yang") && new File(dir, name).isFile();
+                            }
+                        });
                         for (File yangFile : yangFiles) {
-                            yangsFromDependencies.add(new NamedFileInputStream(
-                                    yangFile));
+                            yangsFromDependencies.add(new NamedFileInputStream(yangFile));
                         }
                     }
 
@@ -215,25 +225,20 @@ final class Util {
                         ZipEntry entry = entries.nextElement();
                         String entryName = entry.getName();
 
-                        if (entryName
-                                .startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)) {
-                            if (entry.isDirectory() == false
-                                    && entryName.endsWith(".yang")) {
+                        if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)) {
+                            if (entry.isDirectory() == false && entryName.endsWith(".yang")) {
                                 foundFilesForReporting.add(entryName);
                                 // This will be closed after all strams are
                                 // parsed.
-                                InputStream entryStream = zip
-                                        .getInputStream(entry);
+                                InputStream entryStream = zip.getInputStream(entry);
                                 yangsFromDependencies.add(entryStream);
                             }
                         }
                     }
                 }
                 if (foundFilesForReporting.size() > 0) {
-                    log.info(Util.message("Found %d yang files in %s: %s",
-                            YangToSourcesProcessor.LOG_PREFIX,
-                            foundFilesForReporting.size(), file,
-                            foundFilesForReporting));
+                    log.info(Util.message("Found %d yang files in %s: %s", YangToSourcesProcessor.LOG_PREFIX,
+                            foundFilesForReporting.size(), file, foundFilesForReporting));
                 }
 
             }
index 07c3edcffe432b8348adb57e97adee8b0a407bdb..cebef8c69c97f224e5578ad2724732e7f8a0db9f 100644 (file)
@@ -58,6 +58,9 @@ public final class YangToSourcesMojo extends AbstractMojo {
     @Parameter(required = false)
     private String yangFilesRootDir; // defaults to ${basedir}/src/main/yang
 
+    @Parameter(required = false)
+    private String[] excludeFiles;
+
     @Parameter(property = "project", required = true, readonly = true)
     protected MavenProject project;
 
@@ -82,18 +85,16 @@ public final class YangToSourcesMojo extends AbstractMojo {
             List<CodeGeneratorArg> codeGeneratorArgs = processCodeGenerators(codeGenerators);
 
             // defaults to ${basedir}/src/main/yang
-            File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir,
-                    project.getBasedir());
+            File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir, project.getBasedir());
+            File[] excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
 
-            yangToSourcesProcessor = new YangToSourcesProcessor(getLog(),
-                    yangFilesRootFile, codeGeneratorArgs, project,
-                    inspectDependencies);
+            yangToSourcesProcessor = new YangToSourcesProcessor(getLog(), yangFilesRootFile, excludedFiles,
+                    codeGeneratorArgs, project, inspectDependencies);
         }
         yangToSourcesProcessor.execute();
     }
 
-    private static List<CodeGeneratorArg> processCodeGenerators(
-            CodeGeneratorArg[] codeGenerators) {
+    private static List<CodeGeneratorArg> processCodeGenerators(CodeGeneratorArg[] codeGenerators) {
         List<CodeGeneratorArg> codeGeneratorArgs;
         if (codeGenerators == null) {
             codeGeneratorArgs = Collections.emptyList();
@@ -103,12 +104,10 @@ public final class YangToSourcesMojo extends AbstractMojo {
         return codeGeneratorArgs;
     }
 
-    private static File processYangFilesRootDir(String yangFilesRootDir,
-            File baseDir) {
+    private static File processYangFilesRootDir(String yangFilesRootDir, File baseDir) {
         File yangFilesRootFile;
         if (yangFilesRootDir == null) {
-            yangFilesRootFile = new File(baseDir, "src" + File.separator
-                    + "main" + File.separator + "yang");
+            yangFilesRootFile = new File(baseDir, "src" + File.separator + "main" + File.separator + "yang");
         } else {
             File file = new File(yangFilesRootDir);
             if (file.isAbsolute()) {
@@ -119,4 +118,17 @@ public final class YangToSourcesMojo extends AbstractMojo {
         }
         return yangFilesRootFile;
     }
+
+    private static File[] processExcludeFiles(String[] excludeFiles, File baseDir) {
+        if (excludeFiles == null) {
+            return new File[] {};
+        }
+        File[] result = new File[excludeFiles.length];
+        for (int i = 0; i < excludeFiles.length; i++) {
+            result[i] = new File(baseDir, excludeFiles[i]);
+        }
+
+        return result;
+    }
+
 }
index ca972bf993035dca8c73d7023cb10eb11ffe6727..eb7269d818fc181c82e4abb3840302716025e436 100644 (file)
@@ -24,7 +24,6 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.FileUtils;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
@@ -38,43 +37,39 @@ import com.google.common.collect.Maps;
 
 class YangToSourcesProcessor {
     static final String LOG_PREFIX = "yang-to-sources:";
-    static final String META_INF_YANG_STRING = "META-INF" + File.separator
-            + "yang";
+    static final String META_INF_YANG_STRING = "META-INF" + File.separator + "yang";
     static final String META_INF_YANG_STRING_JAR = "META-INF" + "/" + "yang";
     static final File META_INF_YANG_DIR = new File(META_INF_YANG_STRING);
 
     private final Log log;
     private final File yangFilesRootDir;
+    private final File[] excludedFiles;
     private final List<CodeGeneratorArg> codeGenerators;
     private final MavenProject project;
     private final boolean inspectDependencies;
     private YangProvider yangProvider;
 
     @VisibleForTesting
-    YangToSourcesProcessor(Log log, File yangFilesRootDir,
-                           List<CodeGeneratorArg> codeGenerators, MavenProject project,
-                           boolean inspectDependencies, YangProvider yangProvider) {
+    YangToSourcesProcessor(Log log, File yangFilesRootDir, File[] excludedFiles, List<CodeGeneratorArg> codeGenerators,
+            MavenProject project, boolean inspectDependencies, YangProvider yangProvider) {
         this.log = Util.checkNotNull(log, "log");
-        this.yangFilesRootDir = Util.checkNotNull(yangFilesRootDir,
-                "yangFilesRootDir");
-        this.codeGenerators = Collections.unmodifiableList(Util.checkNotNull(
-                codeGenerators, "codeGenerators"));
+        this.yangFilesRootDir = Util.checkNotNull(yangFilesRootDir, "yangFilesRootDir");
+        this.excludedFiles = excludedFiles;
+        this.codeGenerators = Collections.unmodifiableList(Util.checkNotNull(codeGenerators, "codeGenerators"));
         this.project = Util.checkNotNull(project, "project");
         this.inspectDependencies = inspectDependencies;
         this.yangProvider = yangProvider;
     }
 
-    YangToSourcesProcessor(Log log, File yangFilesRootDir,
-                           List<CodeGeneratorArg> codeGenerators, MavenProject project,
-                           boolean inspectDependencies) {
-        this(log, yangFilesRootDir, codeGenerators, project,
-                inspectDependencies, new YangProvider());
+    YangToSourcesProcessor(Log log, File yangFilesRootDir, File[] excludedFiles, List<CodeGeneratorArg> codeGenerators,
+            MavenProject project, boolean inspectDependencies) {
+        this(log, yangFilesRootDir, excludedFiles, codeGenerators, project, inspectDependencies, new YangProvider());
     }
 
     public void execute() throws MojoExecutionException, MojoFailureException {
         ContextHolder context = processYang();
         generateSources(context);
-        yangProvider.addYangsToMETA_INF(log, project, yangFilesRootDir);
+        yangProvider.addYangsToMETA_INF(log, project, yangFilesRootDir, excludedFiles);
     }
 
     private ContextHolder processYang() throws MojoExecutionException {
@@ -82,16 +77,14 @@ class YangToSourcesProcessor {
         List<Closeable> closeables = new ArrayList<>();
         log.info(Util.message("Inspecting %s", LOG_PREFIX, yangFilesRootDir));
         try {
-            List<InputStream> yangsInProject = Util
-                    .listFilesAsStream(yangFilesRootDir);
+            List<InputStream> yangsInProject = Util.listFilesAsStream(yangFilesRootDir, excludedFiles, log);
             List<InputStream> all = new ArrayList<>(yangsInProject);
             closeables.addAll(yangsInProject);
             Map<InputStream, Module> allYangModules;
             Set<Module> projectYangModules;
             try {
                 if (inspectDependencies) {
-                    YangsInZipsResult dependentYangResult = Util
-                            .findYangFilesInDependenciesAsStream(log, project);
+                    YangsInZipsResult dependentYangResult = Util.findYangFilesInDependenciesAsStream(log, project);
                     Closeable dependentYangResult1 = dependentYangResult;
                     closeables.add(dependentYangResult1);
                     all.addAll(dependentYangResult.yangStreams);
@@ -110,18 +103,15 @@ class YangToSourcesProcessor {
                 }
             }
 
-            Set<Module> parsedAllYangModules = new HashSet<>(
-                    allYangModules.values());
-            SchemaContext resolveSchemaContext = parser
-                    .resolveSchemaContext(parsedAllYangModules);
-            log.info(Util.message("%s files parsed from %s", LOG_PREFIX,
-                    Util.YANG_SUFFIX.toUpperCase(), yangsInProject));
+            Set<Module> parsedAllYangModules = new HashSet<>(allYangModules.values());
+            SchemaContext resolveSchemaContext = parser.resolveSchemaContext(parsedAllYangModules);
+            log.info(Util.message("%s files parsed from %s", LOG_PREFIX, Util.YANG_SUFFIX.toUpperCase(), yangsInProject));
             return new ContextHolder(resolveSchemaContext, projectYangModules);
 
             // MojoExecutionException is thrown since execution cannot continue
         } catch (Exception e) {
-            String message = Util.message("Unable to parse %s files from %s",
-                    LOG_PREFIX, Util.YANG_SUFFIX, yangFilesRootDir);
+            String message = Util.message("Unable to parse %s files from %s", LOG_PREFIX, Util.YANG_SUFFIX,
+                    yangFilesRootDir);
             log.error(message, e);
             throw new MojoExecutionException(message, e);
         }
@@ -129,30 +119,30 @@ class YangToSourcesProcessor {
 
     static class YangProvider {
 
-        private static final String yangResourceDir = "target" + File.separator
-                + "yang";
+        private static final String yangResourceDir = "target" + File.separator + "yang";
 
-        void addYangsToMETA_INF(Log log, MavenProject project,
-                                File yangFilesRootDir) throws MojoFailureException {
+        void addYangsToMETA_INF(Log log, MavenProject project, File yangFilesRootDir, File[] excludedFiles)
+                throws MojoFailureException {
             File targetYangDir = new File(project.getBasedir(), yangResourceDir);
 
             try {
-                FileUtils.copyDirectory(yangFilesRootDir, targetYangDir);
+                Collection<File> files = Util.listFiles(yangFilesRootDir, excludedFiles, null);
+                for (File file : files) {
+                    org.apache.commons.io.FileUtils.copyFile(file, new File(targetYangDir, file.getName()));
+                }
             } catch (IOException e) {
-                String message = "Unable to copy yang files into resource folder";
+                String message = "Unable to list yang files into resource folder";
                 log.warn(message, e);
                 throw new MojoFailureException(message, e);
             }
 
             setResource(targetYangDir, META_INF_YANG_STRING_JAR, project);
 
-            log.debug(Util.message(
-                    "Yang files from: %s marked as resources: %s", LOG_PREFIX,
-                    yangFilesRootDir, META_INF_YANG_STRING_JAR));
+            log.debug(Util.message("Yang files from: %s marked as resources: %s", LOG_PREFIX, yangFilesRootDir,
+                    META_INF_YANG_STRING_JAR));
         }
 
-        private static void setResource(File targetYangDir, String targetPath,
-                                        MavenProject project) {
+        private static void setResource(File targetYangDir, String targetPath, MavenProject project) {
             Resource res = new Resource();
             res.setDirectory(targetYangDir.getPath());
             if (targetPath != null)
@@ -164,8 +154,7 @@ class YangToSourcesProcessor {
     /**
      * Call generate on every generator from plugin configuration
      */
-    private void generateSources(ContextHolder context)
-            throws MojoFailureException {
+    private void generateSources(ContextHolder context) throws MojoFailureException {
         if (codeGenerators.size() == 0) {
             log.warn(Util.message("No code generators provided", LOG_PREFIX));
             return;
@@ -177,19 +166,17 @@ class YangToSourcesProcessor {
                 generateSourcesWithOneGenerator(context, codeGenerator);
             } catch (Exception e) {
                 // try other generators, exception will be thrown after
-                log.error(Util.message(
-                        "Unable to generate sources with %s generator",
-                        LOG_PREFIX, codeGenerator.getCodeGeneratorClass()), e);
-                thrown.put(codeGenerator.getCodeGeneratorClass(), e.getClass()
-                        .getCanonicalName());
+                log.error(
+                        Util.message("Unable to generate sources with %s generator", LOG_PREFIX,
+                                codeGenerator.getCodeGeneratorClass()), e);
+                thrown.put(codeGenerator.getCodeGeneratorClass(), e.getClass().getCanonicalName());
             }
         }
 
         if (!thrown.isEmpty()) {
-            String message = Util
-                    .message(
-                            "One or more code generators failed, including failed list(generatorClass=exception) %s",
-                            LOG_PREFIX, thrown.toString());
+            String message = Util.message(
+                    "One or more code generators failed, including failed list(generatorClass=exception) %s",
+                    LOG_PREFIX, thrown.toString());
             log.error(message);
             throw new MojoFailureException(message);
         }
@@ -198,29 +185,23 @@ class YangToSourcesProcessor {
     /**
      * Instantiate generator from class and call required method
      */
-    private void generateSourcesWithOneGenerator(ContextHolder context,
-                                                 CodeGeneratorArg codeGeneratorCfg) throws ClassNotFoundException,
-            InstantiationException, IllegalAccessException, IOException {
+    private void generateSourcesWithOneGenerator(ContextHolder context, CodeGeneratorArg codeGeneratorCfg)
+            throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
 
         codeGeneratorCfg.check();
 
-        CodeGenerator g = Util.getInstance(
-                codeGeneratorCfg.getCodeGeneratorClass(), CodeGenerator.class);
-        log.info(Util.message("Code generator instantiated from %s",
-                LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass()));
+        CodeGenerator g = Util.getInstance(codeGeneratorCfg.getCodeGeneratorClass(), CodeGenerator.class);
+        log.info(Util.message("Code generator instantiated from %s", LOG_PREFIX,
+                codeGeneratorCfg.getCodeGeneratorClass()));
 
         File outputDir = codeGeneratorCfg.getOutputBaseDir(project);
 
-        log.info(Util.message("Sources will be generated to %s", LOG_PREFIX,
-                outputDir));
-        log.debug(Util.message("Project root dir is %s", LOG_PREFIX,
-                project.getBasedir()));
-        log.debug(Util.message(
-                "Additional configuration picked up for : %s: %s", LOG_PREFIX,
-                codeGeneratorCfg.getCodeGeneratorClass(),
-                codeGeneratorCfg.getAdditionalConfiguration()));
+        log.info(Util.message("Sources will be generated to %s", LOG_PREFIX, outputDir));
+        log.debug(Util.message("Project root dir is %s", LOG_PREFIX, project.getBasedir()));
+        log.debug(Util.message("Additional configuration picked up for : %s: %s", LOG_PREFIX,
+                codeGeneratorCfg.getCodeGeneratorClass(), codeGeneratorCfg.getAdditionalConfiguration()));
 
-        if(outputDir != null) {
+        if (outputDir != null) {
             project.addCompileSourceRoot(outputDir.getAbsolutePath());
         }
         g.setLog(log);
@@ -230,15 +211,13 @@ class YangToSourcesProcessor {
 
         YangProvider.setResource(resourceBaseDir, null, project);
         g.setResourceBaseDir(resourceBaseDir);
-        log.debug(Util.message(
-                "Folder: %s marked as resources for generator: %s", LOG_PREFIX,
-                resourceBaseDir, codeGeneratorCfg.getCodeGeneratorClass()));
+        log.debug(Util.message("Folder: %s marked as resources for generator: %s", LOG_PREFIX, resourceBaseDir,
+                codeGeneratorCfg.getCodeGeneratorClass()));
 
-        Collection<File> generated = g.generateSources(context.getContext(),
-                outputDir, context.getYangModules());
+        Collection<File> generated = g.generateSources(context.getContext(), outputDir, context.getYangModules());
 
-        log.info(Util.message("Sources generated by %s: %s", LOG_PREFIX,
-                codeGeneratorCfg.getCodeGeneratorClass(), generated));
+        log.info(Util.message("Sources generated by %s: %s", LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass(),
+                generated));
     }
 
 }
index ef20864fa3447660678e1d3621480222e16d889f..2f7a050cb02e2f5dc1ca03412220efd514432b1c 100644 (file)
@@ -46,17 +46,14 @@ public class GenerateSourcesTest {
     public void setUp() throws MojoFailureException {
         MockitoAnnotations.initMocks(this);
 
-        yang = new File(getClass().getResource("/yang/mock.yang").getFile())
-                .getParent();
+        yang = new File(getClass().getResource("/yang/mock.yang").getFile()).getParent();
         outDir = new File("/outputDir");
         YangProvider mock = mock(YangProvider.class);
-        doNothing().when(mock).addYangsToMETA_INF(any(Log.class),
-                any(MavenProject.class), any(File.class));
+        doNothing().when(mock).addYangsToMETA_INF(any(Log.class), any(MavenProject.class), any(File.class),
+                any(File[].class));
 
-        YangToSourcesProcessor processor = new YangToSourcesProcessor(
-                mock(Log.class), new File(yang),
-                Lists.newArrayList(new CodeGeneratorArg(GeneratorMock.class
-                        .getName(), "outputDir")), project, false,
+        YangToSourcesProcessor processor = new YangToSourcesProcessor(mock(Log.class), new File(yang), new File[] {},
+                Lists.newArrayList(new CodeGeneratorArg(GeneratorMock.class.getName(), "outputDir")), project, false,
                 mock);
         mojo = new YangToSourcesMojo(processor);
         doReturn(new File("")).when(project).getBasedir();
@@ -71,9 +68,8 @@ public class GenerateSourcesTest {
         assertThat(GeneratorMock.project, is(project));
         assertNotNull(GeneratorMock.log);
         assertTrue(GeneratorMock.additionalCfg.isEmpty());
-        assertThat(GeneratorMock.resourceBaseDir.toString(),
-                containsString("target" + File.separator
-                        + "generated-resources"));
+        assertThat(GeneratorMock.resourceBaseDir.toString(), containsString("target" + File.separator
+                + "generated-resources"));
     }
 
     public static class GeneratorMock implements CodeGenerator {
@@ -86,8 +82,7 @@ public class GenerateSourcesTest {
         private static MavenProject project;
 
         @Override
-        public Collection<File> generateSources(SchemaContext context,
-                File outputBaseDir, Set<Module> currentModules)
+        public Collection<File> generateSources(SchemaContext context, File outputBaseDir, Set<Module> currentModules)
                 throws IOException {
             called++;
             outputDir = outputBaseDir;
@@ -100,8 +95,7 @@ public class GenerateSourcesTest {
         }
 
         @Override
-        public void setAdditionalConfig(
-                Map<String, String> additionalConfiguration) {
+        public void setAdditionalConfig(Map<String, String> additionalConfiguration) {
             GeneratorMock.additionalCfg = additionalConfiguration;
         }