EurostagDDB { EurostagDDB(List<Path> ddbDirs) throws IOException { for (Path ddbDir : ddbDirs) { ddbDir = readSymbolicLink(ddbDir); if (!Files.exists(ddbDir) && !Files.isDirectory(ddbDir)) { throw new IllegalArgumentException(ddbDir + " must exist and be a dir"); } Files.walkFileTree(ddbDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fileName = file.getFileName().toString(); Path tmpfile = readSymbolicLink(file); if (Files.isDirectory(tmpfile)) { Files.walkFileTree(tmpfile, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, this); } else if (Files.isRegularFile(tmpfile) && fileName.endsWith(".tg")) { String key = fileName.substring(0, fileName.length() - 3); if (generators.containsKey(key)) { LOGGER.warn("the processing has detected that the file {} is present in {} and {}", fileName, tmpfile, generators.get(key)); } generators.put(key, tmpfile); } return super.visitFile(file, attrs); } }); } } EurostagDDB(List<Path> ddbDirs);   }
@Test public void testEurostagDDB() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path folder1 = Files.createDirectory(fs.getPath("/folder1")); Path folder2 = Files.createDirectory(fs.getPath("/folder2")); Path folder3 = Files.createDirectory(fs.getPath("/folder3")); Path generator1 = Files.createFile(folder1.resolve("generator1.tg")); Path generator2 = Files.createFile(folder1.resolve("generator2.tg")); Files.createFile(folder2.resolve("generator3.tg.bck")); Path link = Files.createSymbolicLink(folder2.resolve("folder3"), folder3); Path generator4 = Files.createFile(link.resolve("generator4.tg")); Path dataFile = Files.createFile(folder3.resolve("generator.data")); Files.createSymbolicLink(folder3.resolve("generator5.tg"), dataFile); EurostagDDB eurostagDDB = new EurostagDDB(Arrays.asList(folder1, folder2)); assertEquals(generator1, eurostagDDB.findGenerator("generator1")); assertEquals(generator2, eurostagDDB.findGenerator("generator2")); assertNull(eurostagDDB.findGenerator("generator3")); assertEquals(generator4, eurostagDDB.findGenerator("generator4")); assertEquals(dataFile, eurostagDDB.findGenerator("generator5")); } }