X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fmaven-yang-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang2sources%2Fplugin%2FUtil.java;h=3739a1d6599184898a6b64548e86208c634f572d;hp=98a5d8531b79e0d8d78da9ffb2ee7461928d6773;hb=2a77046c0d95cb07a6c79881886a23f50252c207;hpb=78718ca2980d6289703f239abb6b7928ea08c8e4 diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/Util.java b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/Util.java index 98a5d8531b..3739a1d659 100644 --- a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/Util.java +++ b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/Util.java @@ -8,17 +8,29 @@ package org.opendaylight.controller.yang2sources.plugin; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.Enumeration; +import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; import org.apache.commons.io.FileUtils; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.project.MavenProject; import com.google.common.base.Function; import com.google.common.collect.Collections2; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; final class Util { - static final String YANG_SUFFIX = "yang"; // Cache for listed directories and found yang files. Typically yang files @@ -34,7 +46,6 @@ final class Util { * size 1. */ static Collection listFiles(String rootDir) { - if (cache.get(rootDir) != null) return cache.get(rootDir); @@ -45,6 +56,17 @@ final class Util { return yangFiles; } + static Collection listFilesAsStream(String rootDir) throws FileNotFoundException { + Collection is = new ArrayList(); + + Collection files = listFiles(rootDir); + for(File f : files) { + is.add(new FileInputStream(f)); + } + + return is; + } + static String[] listFilesAsArrayOfPaths(String rootDir) { String[] filesArray = new String[] {}; Collection yangFiles = listFiles(rootDir); @@ -99,4 +121,56 @@ final class Util { String innerMessage = String.format(message, args); return String.format("%s %s", logPrefix, innerMessage); } + + public static List getClassPath(MavenProject project) + throws DependencyResolutionRequiredException { + List dependencies = Lists.newArrayList(); + try { + for (Object element : project.getCompileClasspathElements()) { + File asFile = new File((String) element); + if (isJar(asFile)) { + dependencies.add(asFile); + } + } + } catch (DependencyResolutionRequiredException e) { + throw e; + } + return dependencies; + } + + private static final String JAR_SUFFIX = ".jar"; + + private static boolean isJar(File element) { + return (element.isFile() && element.getName().endsWith(JAR_SUFFIX)) ? true + : false; + } + + public static Collection getFilesFromClasspath( + List jarsOnClasspath, List classPathFilter) + throws ZipException, IOException { + List yangs = Lists.newArrayList(); + + for (File file : jarsOnClasspath) { + ZipFile zip = new ZipFile(file); + Enumeration entries = zip.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + if (entry.getName().endsWith(YANG_SUFFIX)) { + InputStream stream = zip.getInputStream(entry); + } + } + } + + return yangs; + } + + public static boolean acceptedFilter(String name, List filter) { + for(String f : filter) { + if(name.endsWith(f)) { + return true; + } + } + return false; + } + }