* List files recursively and return as array of String paths. Use cache of
* size 1.
*/
- static Collection<File> listFiles(String rootDir) {
+ static Collection<File> listFiles(String rootDir) throws FileNotFoundException {
if (cache.get(rootDir) != null)
return cache.get(rootDir);
+ File file = new File(rootDir);
+ if(!file.exists()) {
+ throw new FileNotFoundException();
+ }
+
Collection<File> yangFiles = FileUtils.listFiles(new File(rootDir),
new String[] { YANG_SUFFIX }, true);
return is;
}
- static String[] listFilesAsArrayOfPaths(String rootDir) {
+ static String[] listFilesAsArrayOfPaths(String rootDir) throws FileNotFoundException {
String[] filesArray = new String[] {};
Collection<File> yangFiles = listFiles(rootDir);
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
}
private Collection<File> getFilesFromYangRoot() {
- Collection<File> yangFilesLoaded = Util.listFiles(yangFilesRootDir);
+ Collection<File> yangFilesLoaded = null;
+
+ File rootDir = new File(yangFilesRootDir);
+ try {
+ if(!rootDir.isAbsolute()) {
+ yangFilesLoaded = Util.listFiles(project.getBasedir().getAbsolutePath() + yangFilesRootDir);
+ } else {
+ yangFilesLoaded = Util.listFiles(yangFilesRootDir);
+ }
+
+ } catch(FileNotFoundException e) {
+ getLog().warn("Directory '" + yangFilesRootDir + "' does not exists.");
+ yangFilesLoaded = new ArrayList<File>();
+ }
Collection<File> yangFiles = new ArrayList<File>(yangFilesLoaded);
try {
*/
package org.opendaylight.controller.yang2sources.plugin;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.FileNotFoundException;
import java.util.Collection;
import org.junit.Test;
public class UtilTest {
@Test
- public void testCache() {
+ public void testCache() throws FileNotFoundException {
String yang = new File(getClass().getResource("/mock.yang").getFile())
.getParent();
Collection<File> files = Util.listFiles(yang);