Search in sources :

Example 6 with IOException

use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.

the class VFSRegistryHelperTest method testReadEntriesWithError.

@Test
public void testReadEntriesWithError() throws Exception {
    prepareReadEntries();
    // make an arbitrary path reading to fail.
    int failingIndex = 5;
    when(marshaller.unmarshal(entries.get(failingIndex).getContent())).thenThrow(new IOException(ERROR_MESSAGE));
    expectedException.expectMessage(ERROR_MESSAGE);
    registryHelper.readEntries(rootPath, filter);
    for (int i = 0; i < failingIndex; i++) {
        verify(registryHelper, times(1));
    }
}
Also used : IOException(org.uberfire.java.nio.IOException) Test(org.junit.Test)

Example 7 with IOException

use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.

the class FileUtils method scan.

private Collection<ScanResult> scan(IOService ioService, Path rootPath, final Collection<String> fileTypes, 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);
            final DirectoryStream<Path> foundFiles = ioService.newDirectoryStream(rootPath, new DirectoryStream.Filter<Path>() {

                @Override
                public boolean accept(final Path entry) throws IOException {
                    boolean include = false;
                    if (Files.isDirectory(entry) && recursiveScan) {
                        // use this check iteration to additionally remember child directories
                        childDirectories.add(entry);
                    } else {
                        if (fileTypes == null) {
                            include = true;
                        } else {
                            include = isFromType(entry, fileTypes);
                        }
                    }
                    return include;
                }
            });
            if (foundFiles != null) {
                for (Path acceptedFile : foundFiles) {
                    results.add(new ScanResult(acceptedFile));
                }
            }
            // finally
            if (recursiveScan) {
                for (Path child : childDirectories) {
                    results.addAll(scan(ioService, child, fileTypes, recursiveScan, scannedCache));
                }
            }
        }
    }
    return results;
}
Also used : Path(org.uberfire.java.nio.file.Path) DirectoryStream(org.uberfire.java.nio.file.DirectoryStream) IOException(org.uberfire.java.nio.IOException)

Aggregations

IOException (org.uberfire.java.nio.IOException)7 Path (org.uberfire.java.nio.file.Path)4 DirectoryStream (org.uberfire.java.nio.file.DirectoryStream)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 FileVisitResult (org.uberfire.java.nio.file.FileVisitResult)2 BasicFileAttributes (org.uberfire.java.nio.file.attribute.BasicFileAttributes)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)1 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)1 Repository (org.guvnor.structure.repositories.Repository)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 Test (org.junit.Test)1 KieContainerResource (org.kie.server.api.model.KieContainerResource)1 KieServerInstance (org.kie.server.controller.api.model.KieServerInstance)1 KieServerInstanceInfo (org.kie.server.controller.api.model.KieServerInstanceInfo)1 KieServerSetup (org.kie.server.controller.api.model.KieServerSetup)1