|
20 | 20 | import org.openrewrite.Parser; |
21 | 21 | import org.openrewrite.SourceFile; |
22 | 22 | import org.openrewrite.internal.EncodingDetectingInputStream; |
| 23 | +import org.openrewrite.jgit.diff.RawText; |
23 | 24 | import org.openrewrite.tree.ParseError; |
24 | 25 | import org.openrewrite.tree.ParsingEventListener; |
25 | 26 | import org.openrewrite.tree.ParsingExecutionContextView; |
26 | 27 |
|
27 | 28 | import java.io.File; |
| 29 | +import java.io.IOException; |
| 30 | +import java.io.InputStream; |
| 31 | +import java.nio.file.Files; |
28 | 32 | import java.nio.file.Path; |
29 | 33 | import java.nio.file.PathMatcher; |
30 | 34 | import java.nio.file.Paths; |
@@ -89,7 +93,11 @@ public Stream<SourceFile> parseInputs(Iterable<Input> sources, @Nullable Path re |
89 | 93 |
|
90 | 94 | @Override |
91 | 95 | public boolean accept(Path path) { |
92 | | - return true; |
| 96 | + try (InputStream is = Files.newInputStream(path)) { |
| 97 | + return !RawText.isBinary(is); |
| 98 | + } catch (IOException ignored) { |
| 99 | + return false; |
| 100 | + } |
93 | 101 | } |
94 | 102 |
|
95 | 103 | @Override |
@@ -133,10 +141,11 @@ public boolean accept(Path path) { |
133 | 141 | } |
134 | 142 | // PathMather will not evaluate the path "README.md" to be matched by the pattern "**/README.md" |
135 | 143 | // This is counter-intuitive for most users and would otherwise require separate exclusions for files at the root and files in subdirectories |
136 | | - if(!path.isAbsolute() && !path.startsWith(File.separator)) { |
| 144 | + if (!path.isAbsolute() && !path.startsWith(File.separator)) { |
137 | 145 | return accept(Paths.get("/" + path)); |
138 | 146 | } |
139 | | - return false; |
| 147 | + |
| 148 | + return super.accept(path); |
140 | 149 | } |
141 | 150 | }; |
142 | 151 | } |
|
0 commit comments