@PostConstruct public void init() { fileUtils = FileUtils.getInstance(); }
public Collection<ScanResult> scan(IOService ioService, Collection<Path> rootPaths, String fileType, boolean recursiveScan) throws IOException { ArrayList<String> fileTypes = new ArrayList<String>(); fileTypes.add(fileType); return scan(ioService, rootPaths, fileTypes, recursiveScan); }
public static FileUtils getInstance() { return new FileUtils(); }
public Collection<ScanResult> scan(IOService ioService, Collection<Path> rootPaths, Collection<String> fileTypes, boolean recursiveScan) throws IOException { List<ScanResult> results = new ArrayList<ScanResult>(); final Map<Path, Path> scannedCache = new HashMap<Path, Path>(); if (rootPaths != null) { for (Path root : rootPaths) { if (Files.isDirectory(root) && !scannedCache.containsKey(root)) { results.addAll(scan(ioService, root, fileTypes, recursiveScan, scannedCache)); } else if ( (fileTypes == null || isFromType( root, fileTypes )) && !scannedCache.containsKey( root ) ) { results.add( new ScanResult( root ) ); scannedCache.put( root, root ); } } } return results; }
private List<FormDefinition> findForms(final Path path, final FormSearchConstraint constraint) { List<FormDefinition> result = new ArrayList<>(); Module module = moduleService.resolveModule(path); FileUtils utils = FileUtils.getInstance(); List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<>(); nioPaths.add(Paths.convert(module.getRootPath())); Collection<FileUtils.ScanResult> forms = utils.scan(ioService, nioPaths, FormResourceTypeDefinition.EXTENSION, true); for (FileUtils.ScanResult form : forms) { org.uberfire.java.nio.file.Path formPath = form.getFile(); try { FormDefinition formDefinition = serializer.deserialize(ioService.readAllString(formPath).trim()); if (constraint == null || constraint.accepts(formDefinition)) { result.add(formDefinition); } } catch (Exception ex) { logger.warn("Unable to generate FormDefinition for {}", path, ex); } } return result; }
public boolean cleanEmptyDirectories(final IOService ioService, Path rootPath, boolean deleteRoot, List<String> deleteableFiles) throws IOException { DirDescriptor dirDescriptor; if (rootPath != null && Files.exists(rootPath) && Files.isDirectory(rootPath)) { final DirectoryStream<Path> children = ioService.newDirectoryStream(rootPath); if (children != null) { for (Path child : children) { if (Files.isDirectory(child)) { cleanEmptyDirectories(ioService, child, true, deleteableFiles); } } } dirDescriptor = isDeleteableDir(ioService, rootPath, deleteableFiles); if (dirDescriptor.isDeleteable()) { for (Path child : dirDescriptor.getChildren()) { ioService.delete(child); } if (deleteRoot) { //Invoke deleteIfExists because when the the last child is removede and JGit filesystem //is installed the directory is removed automatically ioService.deleteIfExists(rootPath); return true; } } } return false; }
public Collection<ScanResult> scanDirectories(IOService ioService, Path rootPath, final boolean includeRoot, final boolean recursiveScan/*, final Map<Path, Path> scannedCache*/) throws IOException { final Collection<ScanResult> results = new ArrayList<ScanResult>(); final List<Path> childDirectories = new ArrayList<Path>(); if (rootPath != null) { if (Files.isDirectory(rootPath) /* && !scannedCache.containsKey(rootPath)*/) { //scannedCache.put(rootPath, rootPath); if (includeRoot) results.add(new ScanResult(rootPath)); final DirectoryStream<Path> children = ioService.newDirectoryStream(rootPath); //finally if (recursiveScan) { for (Path child : children) { results.addAll( scanDirectories(ioService, child, true, recursiveScan/*, scannedCache*/) ); } } } } return results; }
FileUtils utils = FileUtils.getInstance(); Collection<FileUtils.ScanResult> forms = utils.scan( ioService, nioPaths, "form", true );
@Override public Form getFormById( String ctxUID, long formId ) { FormEditorContext editorContext = formEditorContextManager.getRootEditorContext( ctxUID ); if ( editorContext != null ) { try { if ( editorContext.getForm().getId().equals( new Long( formId ) ) ) { return editorContext.getForm(); } Path currentForm = Paths.convert( ioService.get( new URI( editorContext.getPath() ) ) ); Project project = projectService.resolveProject( currentForm ); FileUtils utils = FileUtils.getInstance(); List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<org.uberfire.java.nio.file.Path>(); nioPaths.add( Paths.convert( project.getRootPath() ) ); Collection<FileUtils.ScanResult> forms = utils.scan( ioService, nioPaths, "form", true ); String header = formSerializationManager.generateHeaderFormFormId( formId ); for ( FileUtils.ScanResult form : forms ) { org.uberfire.java.nio.file.Path formPath = form.getFile(); org.uberfire.java.nio.file.Path path = Paths.convert( project.getRootPath() ).resolve( MAIN_RESOURCES_PATH ).resolve( formPath ); String xml = ioService.readAllString( path ).trim(); if ( xml.startsWith( header ) ) { return formSerializationManager.loadFormFromXML( xml ); } } } catch ( Exception e ) { log.warn( "Error getting form {} from context {}: {}", formId, ctxUID, e ); } } return null; }
public Collection<ScanResult> scan(IOService ioService, Path root, Collection<String> fileTypes, boolean recursiveScan) throws IOException { Collection<Path> roots = new ArrayList<Path>(); roots.add(root); return scan(ioService, roots, fileTypes, recursiveScan); }
rootPaths.add(javaRootPath); Collection<FileUtils.ScanResult> scanResults = FileUtils.getInstance().scan(ioService, rootPaths, ".java",
protected void scannProcessesForType(final Path path, final String extension, final GenerationConfig generationConfig) { List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<>(); nioPaths.add(Paths.convert(path)); Collection<FileUtils.ScanResult> processes = fileUtils.scan(ioService, nioPaths, extension, true); processes.stream().map(scanResult -> parse(scanResult)).filter(definitions -> definitions != null && generationConfig.getPredicate().test(definitions)).forEach(definitions -> { BusinessProcessFormModel processFormModel = bpmnFormModelGenerator.generateProcessFormModel(definitions.get(), path); List<TaskFormModel> taskModels = bpmnFormModelGenerator.generateTaskFormModels(definitions.get(), path); generationConfig.getConsumer().accept(new JBPMProcessModel(processFormModel, taskModels)); }); }
results.addAll( scan(ioService, child, fileTypes, recursiveScan, scannedCache) );