Search in sources :

Example 61 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class UnionGlob method relativeTo.

@Override
public PathMatcher relativeTo(Path base) {
    PathMatcher leftMatcher = lval.relativeTo(base);
    PathMatcher rightMatcher = rval.relativeTo(base);
    return path -> leftMatcher.matches(path) || rightMatcher.matches(path);
}
Also used : Objects(java.util.Objects) Iterables(com.google.common.collect.Iterables) ImmutableSet(com.google.common.collect.ImmutableSet) PathMatcher(java.nio.file.PathMatcher) Preconditions(com.google.common.base.Preconditions) Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher)

Example 62 with PathMatcher

use of java.nio.file.PathMatcher in project archiva by apache.

the class AbstractArchivaRepositoryScanningTaskExecutorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    Path sourceRepoDir = Paths.get("src/test/repositories/default-repository");
    repoDir = Paths.get("target/default-repository");
    org.apache.archiva.common.utils.FileUtils.deleteDirectory(repoDir);
    assertFalse("Default Test Repository should not exist.", Files.exists(repoDir));
    Files.createDirectories(repoDir);
    FileUtils.copyDirectoryStructure(sourceRepoDir.toFile(), repoDir.toFile());
    // set the timestamps to a time well in the past
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -1);
    try (Stream<Path> stream = Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS)) {
        stream.forEach(path -> {
            try {
                Files.setLastModifiedTime(path, FileTime.fromMillis(cal.getTimeInMillis()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }
    PathMatcher m = FileSystems.getDefault().getPathMatcher("glob:**/.svn");
    Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS).filter(Files::isDirectory).sorted(Comparator.reverseOrder()).filter(path -> m.matches(path)).forEach(path -> org.apache.archiva.common.utils.FileUtils.deleteQuietly(path));
    assertTrue("Default Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir));
    assertNotNull(archivaConfig);
    // Create it
    ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
    repositoryConfiguration.setId(TEST_REPO_ID);
    repositoryConfiguration.setName("Test Repository");
    repositoryConfiguration.setLocation(repoDir.toAbsolutePath().toString());
    for (ManagedRepository repo : repositoryRegistry.getManagedRepositories()) {
        repositoryRegistry.removeRepository(repo);
    }
    repositoryRegistry.putRepository(repositoryConfiguration);
    metadataRepository = mock(MetadataRepository.class);
    factory.setRepository(metadataRepository);
}
Also used : Path(java.nio.file.Path) DirtiesContext(org.springframework.test.annotation.DirtiesContext) MockRepositorySessionFactory(org.apache.archiva.mock.MockRepositorySessionFactory) RunWith(org.junit.runner.RunWith) FileTime(java.nio.file.attribute.FileTime) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Inject(javax.inject.Inject) Calendar(java.util.Calendar) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) After(org.junit.After) PathMatcher(java.nio.file.PathMatcher) TestCase(junit.framework.TestCase) Named(javax.inject.Named) Path(java.nio.file.Path) Before(org.junit.Before) Files(java.nio.file.Files) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaSpringJUnit4ClassRunner(org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner) IOException(java.io.IOException) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) ManagedRepository(org.apache.archiva.repository.ManagedRepository) TaskExecutor(org.apache.archiva.redback.components.taskqueue.execution.TaskExecutor) FileUtils(org.codehaus.plexus.util.FileUtils) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Comparator(java.util.Comparator) FileSystems(java.nio.file.FileSystems) RepositoryStatisticsManager(org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager) Mockito.mock(org.mockito.Mockito.mock) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) PathMatcher(java.nio.file.PathMatcher) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Calendar(java.util.Calendar) IOException(java.io.IOException) Before(org.junit.Before)

Example 63 with PathMatcher

use of java.nio.file.PathMatcher in project statecharts by Yakindu.

the class PomXMLGetVersionVisitor method visitFile.

@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes arg1) throws IOException {
    FileSystem fileSystem = FileSystems.getDefault();
    PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern);
    if (pathMatcher.matches(path.getFileName())) {
        System.out.println("File: " + path.toAbsolutePath());
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(path.toFile());
            XPathFactory xpathfactory = XPathFactory.newInstance();
            XPath xpath = xpathfactory.newXPath();
            XPathExpression expr = xpath.compile("//project[1]/version/text()");
            Object result = expr.evaluate(doc, XPathConstants.STRING);
            if (result instanceof String && !((String) result).isEmpty()) {
                this.version = result.toString();
            } else {
                // try in parent tag
                expr = xpath.compile("//project[1]/parent/version/text()");
                result = expr.evaluate(doc, XPathConstants.STRING);
                if (result instanceof String && !((String) result).isEmpty()) {
                    this.version = result.toString();
                } else {
                    System.out.println("Error: Unable to find version within pom.xmls.");
                    version = null;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return FileVisitResult.TERMINATE;
    }
    return FileVisitResult.CONTINUE;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) PathMatcher(java.nio.file.PathMatcher) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileSystem(java.nio.file.FileSystem) Document(org.w3c.dom.Document) IOException(java.io.IOException)

Example 64 with PathMatcher

use of java.nio.file.PathMatcher in project statecharts by Yakindu.

the class VersionUpdateVisitor method visitFile.

@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes arg1) throws IOException {
    FileSystem fileSystem = FileSystems.getDefault();
    PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern);
    if (pathMatcher.matches(path.getFileName())) {
        searchList.add(path);
        String charset = Charset.defaultCharset().name();
        // System.out.println(charset);
        String content = new String(Files.readAllBytes(path), charset);
        content = content.replaceAll(this.searchPattern, this.replacePattern);
        Files.write(path, content.getBytes(charset));
        fileCount++;
    }
    return FileVisitResult.CONTINUE;
}
Also used : PathMatcher(java.nio.file.PathMatcher) FileSystem(java.nio.file.FileSystem)

Example 65 with PathMatcher

use of java.nio.file.PathMatcher in project candlepin by candlepin.

the class SchemaCompatibilityTest method gatherChangesets.

private List<File> gatherChangesets() throws Exception {
    final PathMatcher xmlMatcher = FileSystems.getDefault().getPathMatcher("glob:*.xml");
    Path resources = Paths.get("src", "main", "resources", "db", "changelog");
    final List<File> matches = new ArrayList<>();
    Files.walkFileTree(resources, new FileVisitor<Path>() {

        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (xmlMatcher.matches(file.getFileName())) {
                matches.add(file.toFile());
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            throw new IOException("Could not visit" + file);
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });
    return matches;
}
Also used : XPath(javax.xml.xpath.XPath) Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)5 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)5 ProjectImporterRegistry (org.eclipse.che.api.project.server.importer.ProjectImporterRegistry)5 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)5 DefaultFileWatcherNotificationHandler (org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler)5 FileTreeWatcher (org.eclipse.che.api.vfs.impl.file.FileTreeWatcher)5 LocalVirtualFileSystemProvider (org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider)5 FSLuceneSearcherProvider (org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider)5