private void copyFolders(final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot, final org.uberfire.java.nio.file.Path originRepositoryRoot) { final RecursiveCopier copier = new RecursiveCopier(originRepositoryRoot, nioTargetRepositoryRoot); Files.walkFileTree(originRepositoryRoot, copier); }
private void removeRegistry(final Path path) { walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (file.getFileName().toString().endsWith(".registry.js") && attrs.isRegularFile()) { final org.uberfire.backend.vfs.Path path = convert(file); getIoService().delete(file); } } catch (final Exception ex) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); }
/** * @throws IllegalArgumentException * @throws IOException * @throws SecurityException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path, java.nio.file.FileVisitor)">Original JavaDoc</a> */ public static Path walkFileTree(final Path start, final FileVisitor<Path> visitor) throws IllegalArgumentException, IOException, SecurityException { checkNotNull("start", start); checkNotNull("visitor", visitor); final Set<FileVisitOption> options = emptySet(); return walkFileTree(start, options, Integer.MAX_VALUE, visitor); }
/** * @throws IllegalArgumentException * @throws IOException * @throws SecurityException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path, java.nio.file.FileVisitor)">Original JavaDoc</a> */ public static Path walkFileTree(final Path start, final FileVisitor<Path> visitor) throws IllegalArgumentException, IOException, SecurityException { checkNotNull("start", start); checkNotNull("visitor", visitor); final Set<FileVisitOption> options = emptySet(); return walkFileTree(start, options, Integer.MAX_VALUE, visitor); }
/** * @throws IllegalArgumentException * @throws IOException * @throws SecurityException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path, java.nio.file.FileVisitor)">Original JavaDoc</a> */ public static Path walkFileTree(final Path start, final FileVisitor<Path> visitor) throws IllegalArgumentException, IOException, SecurityException { checkNotNull("start", start); checkNotNull("visitor", visitor); final Set<FileVisitOption> options = emptySet(); return walkFileTree(start, options, Integer.MAX_VALUE, visitor); }
if (ioService.exists(perspectivesPath)) { walkFileTree(perspectivesPath, new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(final Path file,
public Collection<DataSetDef> listDataSetDefs() { final Collection<DataSetDef> result = new ArrayList<>(); if (ioService.exists(root)) { walkFileTree(checkNotNull("root", root), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (file.getFileName().toString().endsWith(DATASET_EXT) && attrs.isRegularFile()) { String json = ioService.readAllString(file); DataSetDef def = getDataSetDefJsonMarshaller().fromJson(json); result.add(def); } } catch (final Exception e) { log.error("Data set definition read error: " + file.getFileName(), e); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); } return result; }
@Override public Collection<String> listPerspectives() { final Collection<String> result = new ArrayList<String>(); final Path perspectivesDir = fileSystem.getPath( PERSPECTIVE_EDITOR ); if ( ioService.exists( perspectivesDir ) ) { walkFileTree( checkNotNull( "root", perspectivesDir ), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { try { checkNotNull( "file", file ); checkNotNull( "attrs", attrs ); if ( attrs.isRegularFile() ) { final org.uberfire.backend.vfs.Path path = convert( file ); result.add( file.getFileName().toString() ); } } catch ( final Exception ex ) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } } ); } return result; }
@Override public Collection<Plugin> listPlugins() { final Collection<Plugin> result = new ArrayList<Plugin>(); final Path plugins = fileSystem.getPath( "plugins", "/" ); if ( ioService.exists( plugins ) ) { walkFileTree( checkNotNull( "root", plugins ), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { try { checkNotNull( "file", file ); checkNotNull( "attrs", attrs ); if ( file.getFileName().toString().endsWith( ".plugin" ) && attrs.isRegularFile() ) { final org.uberfire.backend.vfs.Path path = convert( file ); result.add( new Plugin( file.getParent().getFileName().toString(), TypeConverterUtil.fromPath( path ), path ) ); } } catch ( final Exception ex ) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } } ); } return result; }
private Collection<RuntimePlugin> listRuntimePlugins(Path path) { final Collection<RuntimePlugin> result = new ArrayList<RuntimePlugin>(); if (getIoService().exists(path)) { walkFileTree(checkNotNull("path", path), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (attrs.isRegularFile()) { result.addAll(buildPluginRuntimePlugins(file)); } } catch (final Exception ex) { logger.error("An unexpected exception was thrown: ", ex); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); } return result; }
@Override public Collection<LayoutEditorModel> listLayoutEditor(final PluginType pluginType) { final Collection<LayoutEditorModel> result = new ArrayList<LayoutEditorModel>(); if (getIoService().exists(root)) { walkFileTree(checkNotNull("root", root), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (file.getFileName().toString().equalsIgnoreCase(pluginType.toString().toLowerCase()) && attrs.isRegularFile()) { final LayoutEditorModel layoutEditorModel = getLayoutEditor(convert(file), pluginType); result.add(layoutEditorModel); } } catch (final Exception ex) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); } return result; }
@Override public Collection<Plugin> listPlugins() { final Collection<Plugin> result = new ArrayList<>(); if (getIoService().exists(root)) { walkFileTree(checkNotNull("root", root), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (file.getFileName().toString().endsWith(".plugin") && attrs.isRegularFile()) { final org.uberfire.backend.vfs.Path path = convert(file); result.add(new Plugin(file.getParent().getFileName().toString(), TypeConverterUtil.fromPath(path), path)); } } catch (final Exception ex) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); } return result; }
@Override public Collection<DynamicMenu> listDynamicMenus() { final Collection<DynamicMenu> result = new ArrayList<DynamicMenu>(); final Path plugins = fileSystem.getPath( "plugins", "/" ); if ( ioService.exists( plugins ) ) { walkFileTree( checkNotNull( "root", plugins ), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { try { checkNotNull( "file", file ); checkNotNull( "attrs", attrs ); if ( file.getFileName().toString().equalsIgnoreCase( "info.dynamic" ) && attrs.isRegularFile() ) { final String pluginName = file.getParent().getFileName().toString(); result.add( new DynamicMenu( pluginName, PluginType.DYNAMIC_MENU, convert( file.getParent() ), loadMenuItems( pluginName ) ) ); } } catch ( final Exception ex ) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } } ); } return result; }
@Test public void testWalkerDeep2() { final Path dir = newTempDir(null); final Path subDir = newTempDir(dir); final Path subSubDir = newTempDir(subDir); newTempDir(subSubDir); cleanupVisitor(); Files.walkFileTree(dir, simple); assertThat(preDir.get()).isEqualTo(4); assertThat(postDir.get()).isEqualTo(4); assertThat(fileC.get()).isEqualTo(0); assertThat(failFile.get()).isEqualTo(0); }
Files.walkFileTree(Paths.convert(workspaceProject.getRootPath()), new SimpleFileVisitor<org.uberfire.java.nio.file.Path>() { @Override public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException {
@Test public void testWalker() { final Path dir = newTempDir(null); final Path file1 = Files.createTempFile(dir, "foo", "bar"); Files.createTempFile(dir, "foo", "bar"); cleanupVisitor(); Files.walkFileTree(dir, simple); assertThat(preDir.get()).isEqualTo(1); assertThat(postDir.get()).isEqualTo(1); assertThat(fileC.get()).isEqualTo(2); assertThat(failFile.get()).isEqualTo(0); cleanupVisitor(); Files.walkFileTree(file1, simple); assertThat(preDir.get()).isEqualTo(0); assertThat(postDir.get()).isEqualTo(0); assertThat(fileC.get()).isEqualTo(1); assertThat(failFile.get()).isEqualTo(0); }
protected void readWorkspaceBPMNModels() { BPMNAnalyzer analyzer = new BPMNAnalyzer(); Files.walkFileTree(Paths.convert(migrationContext.getWorkspaceProject().getRootPath()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException { org.uberfire.backend.vfs.Path visitedVFSPath = Paths.convert(visitedPath); String fileName = visitedVFSPath.getFileName(); File file = visitedPath.toFile(); if (file.isFile()) { if (fileName.endsWith("." + FormsMigrationConstants.BPMN_EXTENSION) || fileName.endsWith("." + FormsMigrationConstants.BPMN2_EXTENSION)) { try { BPMNProcess process = analyzer.read(migrationContext.getMigrationServicesCDIWrapper().getIOService().newInputStream(visitedPath)); if (process != null) { workspaceBPMNFormModels.addAll(process.getFormModels()); } else { migrationContext.getSystem().console().format(FormsMigrationConstants.BPMN_PARSING_ERROR, FormsMigrationConstants.WARNING, fileName); } } catch (Exception ex) { migrationContext.getSystem().console().format(FormsMigrationConstants.BPMN_PARSING_ERROR, FormsMigrationConstants.WARNING, fileName); } } } return FileVisitResult.CONTINUE; } }); }
@Test public void testWalkerDeep1() { final Path dir = newTempDir(null); final Path subDir = newTempDir(dir); final Path subSubDir = newTempDir(subDir); final Path subSubSubDir = newTempDir(subSubDir); Files.createTempFile(dir, "foo", "bar"); Files.createTempFile(dir, "foo", "bar"); cleanupVisitor(); Files.walkFileTree(dir, simple); assertThat(preDir.get()).isEqualTo(4); assertThat(postDir.get()).isEqualTo(4); assertThat(fileC.get()).isEqualTo(2); assertThat(failFile.get()).isEqualTo(0); }
public void deleteTempFiles() { Path tempPath = getTempPath(); if (ioService.exists(tempPath)) { ioService.startBatch(fileSystem, new CommentedOption("system", "Delete temporal files")); try { walkFileTree(tempPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } }); } finally { ioService.endBatch(); } } }
public void deleteTempFiles() { Path tempPath = getTempPath(); if (ioService.exists(tempPath)) { ioService.startBatch(fileSystem, new CommentedOption("system", "Delete temporal files")); try { walkFileTree(tempPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } }); } finally { ioService.endBatch(); } } }