1616
1717package com .google .copybara .util ;
1818
19+ import static com .google .common .collect .ImmutableList .toImmutableList ;
20+
1921import com .google .common .collect .ImmutableList ;
20- import com .google .common .collect .ImmutableSet ;
2122import com .google .copybara .util .GlobAtom .AtomType ;
22- import java .nio .file .FileSystem ;
2323import java .nio .file .Path ;
2424import java .nio .file .PathMatcher ;
2525import net .starlark .java .eval .EvalException ;
@@ -38,40 +38,13 @@ String toStringWithParentheses(boolean isRootGlob) {
3838 }
3939
4040 @ Override
41- public PathMatcher relativeTo (Path root ) {
42- ImmutableSet .Builder <Path > paths = ImmutableSet .builder ();
43- for (GlobAtom atom : include ) {
44- paths .add (resolvePath (root , atom .pattern ()));
45- }
46- final ImmutableSet <Path > matchPaths = paths .build ();
41+ public PathMatcher relativeTo (Path path ) {
4742 return new ReadablePathMatcher (
48- new PathMatcher () {
49- @ Override
50- public boolean matches (Path path ) {
51- return matchPaths .contains (path .normalize ());
52- }
53-
54- @ Override
55- public String toString () {
56- return SequenceGlob .this .toString ();
57- }
58- },
43+ FileUtil .anyPathMatcher (
44+ include .stream ().map (g -> g .matcher (path )).collect (toImmutableList ())),
5945 this .toString ());
6046 }
6147
62- private Path resolvePath (Path root , String pattern ) {
63- // Logic from GlobAtom.SINGLE_FILE.matcher
64- FileSystem fs = root .getFileSystem ();
65- String rootStr = root .normalize ().toString ();
66- String separator = fs .getSeparator ();
67-
68- if (!rootStr .endsWith (separator )) {
69- rootStr += separator ;
70- }
71-
72- return fs .getPath (rootStr + pattern );
73- }
74-
7548 public static SequenceGlob ofStarlarkList (StarlarkList <?> patterns ) throws EvalException {
7649 ImmutableList .Builder <GlobAtom > atoms = ImmutableList .builder ();
7750 for (Object pattern : patterns ) {
0 commit comments