use of java.nio.file.FileVisitOption in project raml-module-builder by folio-org.
the class RamlDirCopier method copy.
/**
* Copy a RAML directory tree to a target directory tree and
* dereference all $ref references of all .json and .schema files.
* It does not delete any existing files or directories at target,
* but a file may get overwritten.
*
* @param sourceDir directory tree to copy
* @param targetDir target directory
* @throws IOException on read or write error
*/
public static void copy(Path sourceDir, Path targetDir) throws IOException {
File targetFile = targetDir.toFile();
if (!targetFile.isDirectory()) {
targetFile.mkdirs();
}
Set<FileVisitOption> options = Collections.emptySet();
RamlDirCopier ramlDirCopier = new RamlDirCopier(sourceDir, targetDir);
Files.walkFileTree(sourceDir, options, Integer.MAX_VALUE, ramlDirCopier.ramlTypeCollectorVisitor);
Files.walkFileTree(sourceDir, options, Integer.MAX_VALUE, ramlDirCopier.fileVisitor);
}
use of java.nio.file.FileVisitOption in project elasticsearch by elastic.
the class LogConfigurator method configure.
private static void configure(final Settings settings, final Path configsPath, final Path logsPath) throws IOException, UserException {
Objects.requireNonNull(settings);
Objects.requireNonNull(configsPath);
Objects.requireNonNull(logsPath);
setLogConfigurationSystemProperty(logsPath, settings);
// we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
configureStatusLogger();
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final List<AbstractConfiguration> configurations = new ArrayList<>();
final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
final Set<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(configsPath, options, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().equals("log4j2.properties")) {
configurations.add((PropertiesConfiguration) factory.getConfiguration(context, file.toString(), file.toUri()));
}
return FileVisitResult.CONTINUE;
}
});
if (configurations.isEmpty()) {
throw new UserException(ExitCodes.CONFIG, "no log4j2.properties found; tried [" + configsPath + "] and its subdirectories");
}
context.start(new CompositeConfiguration(configurations));
configureLoggerLevels(settings);
}
use of java.nio.file.FileVisitOption in project jetty.project by eclipse.
the class CorrectMavenCentralRefs method fix.
public void fix(Path buildRoot) throws IOException {
// Find all of the *.mod files
PathFinder finder = new PathFinder();
finder.setFileMatcher("glob:**/*.mod");
finder.setBase(buildRoot);
// Matcher for target directories
PathMatcher targetMatcher = PathMatchers.getMatcher("glob:**/target/**");
PathMatcher testMatcher = PathMatchers.getMatcher("glob:**/test/**");
System.out.printf("Walking path: %s%n", buildRoot);
Set<FileVisitOption> options = Collections.emptySet();
Files.walkFileTree(buildRoot, options, 30, finder);
System.out.printf("Found: %d hits%n", finder.getHits().size());
int count = 0;
for (Path path : finder.getHits()) {
if (Files.isDirectory(path)) {
// skip
continue;
}
if (targetMatcher.matches(path)) {
// skip
continue;
}
if (testMatcher.matches(path)) {
// skip
continue;
}
if (processModFile(path)) {
count++;
}
}
System.out.printf("Processed %,d modules", count);
}
use of java.nio.file.FileVisitOption in project vcell by virtualcell.
the class CopySimFiles method execute.
@Override
public int execute() {
try {
// append to log, if it exists already
pw = new PrintWriter(new FileWriter(logName, true));
try {
fs = FileSystems.getDefault();
Path from = fs.getPath(fromDirectory);
File toDir = new File(toDirectory);
if (!toDir.exists()) {
toDir.mkdir();
if (lg.isDebugEnabled()) {
lg.debug("copying " + from + " to " + toDir + " (created)");
}
} else if (lg.isDebugEnabled()) {
lg.debug("copying " + from + " to " + toDir + " (exists)");
}
Set<FileVisitOption> empty = Collections.emptySet();
Files.walkFileTree(from, empty, 1, this);
return 0;
} finally {
pw.close();
pw = null;
}
} catch (IOException e) {
exc = e;
return 1;
}
}
use of java.nio.file.FileVisitOption in project liferay-ide by liferay.
the class IOUtil method copyDirToDir.
public static void copyDirToDir(File src, File dest) {
Path targetPath = Paths.get(dest.getPath().toString());
Path sourcePath = Paths.get(src.getPath().toString());
EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
TreeCopier tc = new TreeCopier(sourcePath, targetPath);
try {
Files.walkFileTree(sourcePath, opts, Integer.MAX_VALUE, tc);
} catch (IOException ioe) {
LiferayCore.logError("copy folder " + src.getName() + " error", ioe);
}
}
Aggregations