*/
package org.opendaylight.yangtools.yang2sources.plugin;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
-import org.apache.maven.repository.RepositorySystem;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
final class Util {
}
static final class YangsInZipsResult implements Closeable {
- private final List<InputStream> yangStreams;
+ private final List<YangSourceFromDependency> yangStreams;
private final List<Closeable> zipInputStreams;
- private YangsInZipsResult(List<InputStream> yangStreams, List<Closeable> zipInputStreams) {
+ private YangsInZipsResult(List<YangSourceFromDependency> yangStreams, List<Closeable> zipInputStreams) {
this.yangStreams = yangStreams;
this.zipInputStreams = zipInputStreams;
}
@Override
public void close() throws IOException {
- for (InputStream is : yangStreams) {
- is.close();
- }
for (Closeable is : zipInputStreams) {
is.close();
}
}
- public List<InputStream> getYangStreams() {
+ public List<YangSourceFromDependency> getYangStreams() {
return this.yangStreams;
}
}
static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log, MavenProject project)
throws MojoFailureException {
- List<InputStream> yangsFromDependencies = new ArrayList<>();
+ List<YangSourceFromDependency> yangsFromDependencies = new ArrayList<>();
List<Closeable> zips = new ArrayList<>();
try {
List<File> filesOnCp = Util.getClassPath(project);
return name.endsWith(".yang") && new File(dir, name).isFile();
}
});
- for (File yangFile : yangFiles) {
- yangsFromDependencies.add(new NamedFileInputStream(yangFile, YangToSourcesProcessor.META_INF_YANG_STRING + File.separator + yangFile.getName()));
+ for (final File yangFile : yangFiles) {
+ yangsFromDependencies.add(new YangSourceFromFile(file));
}
}
if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)
&& !entry.isDirectory() && entryName.endsWith(".yang")) {
foundFilesForReporting.add(entryName);
- // This will be closed after all streams are
- // parsed.
- InputStream entryStream = zip.getInputStream(entry);
- yangsFromDependencies.add(entryStream);
+ yangsFromDependencies.add(new YangSourceInZipFile(zip, entry));
}
}
}
return new YangsInZipsResult(yangsFromDependencies, zips);
}
+ /**
+ * Find all dependencies which contains yang sources
+ *
+ * Returns collection of YANG files and Zip files which contains YANG files.
+ *
+ * FIXME: Rename to what class is actually doing.
+ *
+ * @param log
+ * @param project
+ * @return
+ * @throws MojoFailureException
+ */
static Collection<File> findYangFilesInDependencies(Log log, MavenProject project) throws MojoFailureException {
final List<File> yangsFilesFromDependencies = new ArrayList<>();