use of java.nio.file.FileVisitResult in project wildfly by wildfly.
the class EeLegacySubsystemTestCase method testLegacyConfigurations.
@Test
public void testLegacyConfigurations() throws Exception {
// Get a list of all the logging_x_x.xml files
final Pattern pattern = Pattern.compile("(subsystem)_\\d+_\\d+\\.xml");
// Using the CP as that's the standardSubsystemTest will use to find the config file
final String cp = WildFlySecurityManager.getPropertyPrivileged("java.class.path", ".");
final String[] entries = cp.split(Pattern.quote(File.pathSeparator));
final List<String> configs = new ArrayList<>();
for (String entry : entries) {
final Path path = Paths.get(entry);
if (Files.isDirectory(path)) {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
final String name = file.getFileName().toString();
if (pattern.matcher(name).matches()) {
configs.add(name);
}
return FileVisitResult.CONTINUE;
}
});
}
}
// The paths shouldn't be empty
Assert.assertFalse("No configs were found", configs.isEmpty());
for (String configId : configs) {
// Run the standard subsystem test, but don't compare the XML as it should never match
standardSubsystemTest(configId, false);
}
}
use of java.nio.file.FileVisitResult in project intellij-community by JetBrains.
the class LocalFileSystemTest method doTestInterruptedRefresh.
public static void doTestInterruptedRefresh(@NotNull File top) throws Exception {
for (int i = 1; i <= 3; i++) {
File sub = IoTestUtil.createTestDir(top, "sub_" + i);
for (int j = 1; j <= 3; j++) {
IoTestUtil.createTestDir(sub, "sub_" + j);
}
}
Files.walkFileTree(top.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
for (int k = 1; k <= 3; k++) {
IoTestUtil.createTestFile(dir.toFile(), "file_" + k, ".");
}
return FileVisitResult.CONTINUE;
}
});
VirtualFile topDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(top);
assertNotNull(topDir);
Set<VirtualFile> files = ContainerUtil.newHashSet();
VfsUtilCore.processFilesRecursively(topDir, file -> {
if (!file.isDirectory())
files.add(file);
return true;
});
// 13 dirs of 3 files
assertEquals(39, files.size());
topDir.refresh(false, true);
Set<VirtualFile> processed = ContainerUtil.newHashSet();
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
events.forEach(e -> processed.add(e.getFile()));
}
});
try {
files.forEach(f -> IoTestUtil.updateFile(new File(f.getPath()), "+++"));
((NewVirtualFile) topDir).markDirtyRecursively();
RefreshWorker.setCancellingCondition(file -> file.getPath().endsWith(top.getName() + "/sub_2/file_2"));
topDir.refresh(false, true);
assertThat(processed.size()).isGreaterThan(0).isLessThan(files.size());
RefreshWorker.setCancellingCondition(null);
topDir.refresh(false, true);
assertThat(processed).isEqualTo(files);
} finally {
connection.disconnect();
RefreshWorker.setCancellingCondition(null);
}
}
use of java.nio.file.FileVisitResult in project streamsx.topology by IBMStreams.
the class ZippedToolkitRemoteContext method addAllToZippedArchive.
private static void addAllToZippedArchive(Map<Path, String> starts, Path zipFilePath) throws IOException {
try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(zipFilePath.toFile())) {
for (Path start : starts.keySet()) {
final String rootEntryName = starts.get(start);
Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// Skip pyc files.
if (file.getFileName().toString().endsWith(".pyc"))
return FileVisitResult.CONTINUE;
String entryName = rootEntryName;
String relativePath = start.relativize(file).toString();
// If empty, file is the start file.
if (!relativePath.isEmpty()) {
entryName = entryName + "/" + relativePath;
}
// Zip uses forward slashes
entryName = entryName.replace(File.separatorChar, '/');
ZipArchiveEntry entry = new ZipArchiveEntry(file.toFile(), entryName);
if (Files.isExecutable(file))
entry.setUnixMode(0100770);
else
entry.setUnixMode(0100660);
zos.putArchiveEntry(entry);
Files.copy(file, zos);
zos.closeArchiveEntry();
return FileVisitResult.CONTINUE;
}
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
final String dirName = dir.getFileName().toString();
// Don't include pyc files or .toolkit
if (dirName.equals("__pycache__"))
return FileVisitResult.SKIP_SUBTREE;
ZipArchiveEntry dirEntry = new ZipArchiveEntry(dir.toFile(), rootEntryName + "/" + start.relativize(dir).toString().replace(File.separatorChar, '/') + "/");
zos.putArchiveEntry(dirEntry);
zos.closeArchiveEntry();
return FileVisitResult.CONTINUE;
}
});
}
}
}
use of java.nio.file.FileVisitResult in project JMRI by JMRI.
the class FileUtilSupport method copy.
/**
* Copy a file or directory. It is recommended to use
* {@link java.nio.file.Files#copy(java.nio.file.Path, java.io.OutputStream)}
* for files.
*
* @param source the file or directory to copy
* @param dest must be the file or directory, not the containing directory
* @throws java.io.IOException if file cannot be copied
*/
public void copy(File source, File dest) throws IOException {
if (!source.exists()) {
log.error("Attempting to copy non-existant file: {}", source);
return;
}
if (!dest.exists()) {
if (source.isDirectory()) {
boolean ok = dest.mkdirs();
if (!ok) {
throw new IOException("Could not use mkdirs to create destination directory");
}
} else {
boolean ok = dest.createNewFile();
if (!ok) {
throw new IOException("Could not create destination file");
}
}
}
Path srcPath = source.toPath();
Path dstPath = dest.toPath();
if (source.isDirectory()) {
Files.walkFileTree(srcPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
Files.createDirectories(dstPath.resolve(srcPath.relativize(dir)));
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
Files.copy(file, dstPath.resolve(srcPath.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
});
} else {
Files.copy(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
use of java.nio.file.FileVisitResult in project bnd by bndtools.
the class IO method copy.
public static Path copy(Path src, Path tgt) throws IOException {
final Path source = src.toAbsolutePath();
final Path target = tgt.toAbsolutePath();
if (Files.isRegularFile(source)) {
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
return tgt;
}
if (Files.isDirectory(source)) {
if (Files.notExists(target)) {
mkdirs(target);
}
if (!Files.isDirectory(target))
throw new IllegalArgumentException("target directory for a directory must be a directory: " + target);
if (target.startsWith(source))
throw new IllegalArgumentException("target directory can not be child of source directory.");
Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new FileVisitor<Path>() {
final FileTime now = FileTime.fromMillis(System.currentTimeMillis());
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Path targetdir = target.resolve(source.relativize(dir));
try {
Files.copy(dir, targetdir);
} catch (FileAlreadyExistsException e) {
if (!Files.isDirectory(targetdir))
throw e;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Path targetFile = target.resolve(source.relativize(file));
Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING);
Files.setLastModifiedTime(targetFile, now);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
if (exc != null) {
// directory iteration failed
throw exc;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc != null) {
throw exc;
}
return FileVisitResult.CONTINUE;
}
});
return tgt;
}
throw new FileNotFoundException("During copy: " + source.toString());
}
Aggregations