Examples of PathMatcher


Examples of java.nio.file.PathMatcher

    public static List<Path> listMatchingFiles(Path start, String glob)
            throws IOException
    {
        final ImmutableList.Builder<Path> list = ImmutableList.builder();
        final PathMatcher matcher = start.getFileSystem().getPathMatcher("glob:" + glob);
        walkFileTree(start, new SimpleFileVisitor<Path>()
        {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                    throws IOException
            {
                if (matcher.matches(file)) {
                    list.add(file);
                }
                return FileVisitResult.CONTINUE;
            }
        });
View Full Code Here

Examples of java.nio.file.PathMatcher

      matcher(pattern);
      fail();
    } catch (PatternSyntaxException expected) {}

    try {
      PathMatcher real = realMatcher(pattern);
      if (real != null) {
        fail();
      }
    } catch (PatternSyntaxException expected) {}
  }
View Full Code Here

Examples of java.nio.file.PathMatcher

  /**
   * Asserts that the path matches the given syntax and pattern.
   */
  public PathSubject matches(String syntaxAndPattern) {
    PathMatcher matcher = getSubject().getFileSystem().getPathMatcher(syntaxAndPattern);
    if (!matcher.matches(getSubject())) {
      fail("matches", syntaxAndPattern);
    }
    return this;
  }
View Full Code Here

Examples of java.nio.file.PathMatcher

  /**
   * Asserts that the path does not match the given syntax and pattern.
   */
  public PathSubject doesNotMatch(String syntaxAndPattern) {
    PathMatcher matcher = getSubject().getFileSystem().getPathMatcher(syntaxAndPattern);
    if (matcher.matches(getSubject())) {
      fail("does not match", syntaxAndPattern);
    }
    return this;
  }
View Full Code Here

Examples of java.nio.file.PathMatcher

        log(env);
        return env;
    }
   
    public Copy substituting(final String cwd, final String src, final String dst) {
        return substituting(cwd, new PathMatcher() {
            @Override
            public boolean matches(Path path) {
                return path.endsWith(src);
            }
        }, dst);
View Full Code Here

Examples of java.nio.file.PathMatcher

    List<Path> paths = JuCollectionUtils.asList(ds);
    Assert.assertEquals(1, paths.size()); // Note that search is not recursive
    Assert.assertEquals(pFile1Txt, paths.get(0));
   
    // Use PathMatcher
    PathMatcher pm1 = FileSystems.getDefault().getPathMatcher("glob:*"); // Note that we need the glob prefix here
    Assert.assertFalse(pm1.matches(pFile1Txt)); // Note that * doesn't cross directory boundaries
    Assert.assertTrue(pm1.matches(pFile1Txt.getFileName()));

    // ** crosses directory boundaries
    Assert.assertTrue(FileSystems.getDefault().getPathMatcher("glob:**").matches(pFile1Txt));
   
    // Multi Matches
    Assert.assertTrue(FileSystems.getDefault().getPathMatcher("glob:**.{txt,sql}").matches(pFile1Txt));
    Assert.assertFalse(FileSystems.getDefault().getPathMatcher("glob:**.{html,xml}").matches(pFile1Txt));
   
    // Complex Matches
    PathMatcher pm2 = FileSystems.getDefault().getPathMatcher("glob:**/sub/sub[A-F]ile?.{txt,bak}");
    Assert.assertFalse(pm2.matches(pFile1Txt));
    Assert.assertTrue(pm2.matches(pSubFile1Txt));
  }
 
View Full Code Here

Examples of java.nio.file.PathMatcher

    }

    private static List<File> findFiles(File incPath, String searchArgument, boolean findDirectory) {
        ArrayList<File> files = new ArrayList<>();

        final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**");
         DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
            @Override
            public boolean accept(Path entry)  {
                return matcher.matches(entry.getFileName());
            }
        };

        if(starPattern.matcher(searchArgument).matches()) {
            try (DirectoryStream<Path> stream = findDirectory ?
View Full Code Here

Examples of java.nio.file.PathMatcher

        for (int i = 0; i < token; i+=2) {
            if (expression.regionMatches(tokens[i], "or", 0, tokens[i+1] - tokens[i])) {
                if (i == 0 || i > token - 2) {
                    throw new IllegalArgumentException("Bad syntax: " + expression);
                }
                PathMatcher left = doParse(expression.substring(tokens[0], tokens[i-1]));
                PathMatcher right = doParse(expression.substring(tokens[i+2], tokens[token-1]));
                return new OrMatcher(left, right);
            }
        }
        for (int i = 0; i < token; i+=2) {
            if (expression.regionMatches(tokens[i], "and", 0, tokens[i+1] - tokens[i])) {
                if (i == 0 || i > token - 2) {
                    throw new IllegalArgumentException("Bad syntax: " + expression);
                }
                PathMatcher left = doParse(expression.substring(tokens[0], tokens[i-1]));
                PathMatcher right = doParse(expression.substring(tokens[i+2], tokens[token-1]));
                return new AndMatcher(left, right);
            }
        }
        if (token > 2 && expression.regionMatches(tokens[0], "not", 0, tokens[1] - tokens[0])) {
            PathMatcher right = doParse(expression.substring(tokens[2], tokens[token-1]));
            return new NotMatcher(right);
        }
        if (!expression.matches("[a-z]+:.*")) {
            expression = "glob:" + expression;
        }
View Full Code Here

Examples of java.nio.file.PathMatcher

public class MatchersTest {

    @Test
    public void testLogical() {
        PathMatcher matcher = Logical.parse("log:(org/{apache,foo}/** or **) and(not **example**)");

        assertTrue(matcher.matches(Paths.get("org/foo/foo.java")));
        assertFalse(matcher.matches(Paths.get("org/foo/example.java")));
    }
View Full Code Here

Examples of java.nio.file.PathMatcher

        assertFalse(matcher.matches(Paths.get("org/foo/example.java")));
    }

    @Test
    public void testMavenGroupId() {
        PathMatcher matcher = Maven.parse("mvn:groupId:org.apache,org.foo");

        assertTrue(matcher.matches(Paths.get("org")));
        assertTrue(matcher.matches(Paths.get("org/apache")));
        assertTrue(matcher.matches(Paths.get("org/apache/foo.jar")));
        assertTrue(matcher.matches(Paths.get("org/foo")));
        assertTrue(matcher.matches(Paths.get("org/foo/foo/bar.jar")));
        assertFalse(matcher.matches(Paths.get("org/jboss")));
        assertFalse(matcher.matches(Paths.get("org/jboss/foo.jar")));
        assertFalse(matcher.matches(Paths.get("com/jboss/foo.jar")));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.