16
16
17
17
package com .google .javascript .jscomp ;
18
18
19
- import static java .nio .charset .StandardCharsets .UTF_8 ;
19
+ import static java7compat .nio .charset .StandardCharsets .UTF_8 ;
20
20
21
21
import com .google .common .annotations .GwtIncompatible ;
22
22
import com .google .common .base .Joiner ;
45
45
import org .kohsuke .args4j .spi .Setter ;
46
46
import org .kohsuke .args4j .spi .StringOptionHandler ;
47
47
48
- import java .io .BufferedReader ;
49
- import java .io .File ;
50
- import java .io .FileInputStream ;
51
- import java .io .IOException ;
52
- import java .io .InputStream ;
53
- import java .io .OutputStreamWriter ;
54
- import java .io .PrintStream ;
48
+ import java .io .*;
55
49
import java .lang .reflect .AnnotatedElement ;
56
- import java .nio .file .FileSystem ;
57
- import java .nio .file .FileSystems ;
58
- import java .nio .file .FileVisitResult ;
59
- import java .nio .file .Path ;
60
- import java .nio .file .PathMatcher ;
61
- import java .nio .file .Paths ;
62
- import java .nio .file .SimpleFileVisitor ;
63
- import java .nio .file .attribute .BasicFileAttributes ;
50
+ import java .net .URI ;
64
51
import java .util .ArrayList ;
65
52
import java .util .Collection ;
66
53
import java .util .Collections ;
@@ -1181,10 +1168,12 @@ private void reportError(String message) {
1181
1168
1182
1169
private void processFlagFile ()
1183
1170
throws CmdLineException , IOException {
1184
- Path flagFile = Paths .get (flags .flagFile );
1171
+ File flagFile = new File (flags .flagFile );
1172
+
1173
+ InputStream newInputStream = new FileInputStream (flagFile );
1174
+ Reader reader = new InputStreamReader (newInputStream , UTF_8 .newDecoder ());
1175
+ BufferedReader buffer = new BufferedReader (reader );
1185
1176
1186
- BufferedReader buffer =
1187
- java .nio .file .Files .newBufferedReader (flagFile , UTF_8 );
1188
1177
// Builds the tokens.
1189
1178
StringBuilder builder = new StringBuilder ();
1190
1179
// Stores the built tokens.
@@ -1568,13 +1557,15 @@ protected CompilerOptions createOptions() {
1568
1557
Instrumentation .Builder builder = Instrumentation .newBuilder ();
1569
1558
BufferedReader br = null ;
1570
1559
try {
1571
- br = new BufferedReader (Files .newReader (new File (flags .instrumentationFile ), UTF_8 ));
1560
+ InputStream newInputStream = new FileInputStream (new File (flags .instrumentationFile ));
1561
+ Reader reader = new InputStreamReader (newInputStream , UTF_8 .newDecoder ());
1562
+ br = new BufferedReader (reader );
1572
1563
StringBuilder sb = new StringBuilder ();
1573
1564
String line = br .readLine ();
1574
1565
1575
1566
while (line != null ) {
1576
1567
sb .append (line );
1577
- sb .append (System .lineSeparator ( ));
1568
+ sb .append (System .getProperty ( "line.separator" ));
1578
1569
line = br .readLine ();
1579
1570
}
1580
1571
instrumentationPb = sb .toString ();
@@ -1685,8 +1676,8 @@ private static List<String> findJsFiles(Collection<String> patterns, boolean sor
1685
1676
if (matchedFile .isDirectory ()) {
1686
1677
matchPaths (new File (matchedFile , "**.js" ).toString (), allJsInputs , excludes );
1687
1678
} else {
1688
- Path original = Paths . get (pattern );
1689
- String pathStringAbsolute = original .normalize ().toAbsolutePath (). toString ();
1679
+ URI original = new File (pattern ). toURI ( );
1680
+ String pathStringAbsolute = new File ( original .normalize ().toString ()). getAbsolutePath ();
1690
1681
if (!excludes .contains (pathStringAbsolute )) {
1691
1682
allJsInputs .put (pathStringAbsolute , original .toString ());
1692
1683
}
@@ -1701,50 +1692,7 @@ private static List<String> findJsFiles(Collection<String> patterns, boolean sor
1701
1692
1702
1693
private static void matchPaths (String pattern , final Map <String , String > allJsInputs ,
1703
1694
final Set <String > excludes ) throws IOException {
1704
- FileSystem fs = FileSystems .getDefault ();
1705
- final boolean remove = pattern .indexOf ('!' ) == 0 ;
1706
- if (remove ) {
1707
- pattern = pattern .substring (1 );
1708
- }
1709
-
1710
- String separator = File .separator .equals ("\\ " ) ? "\\ \\ " : File .separator ;
1711
-
1712
- // Split the pattern into two pieces: the globbing part
1713
- // and the non-globbing prefix.
1714
- List <String > patternParts = Splitter .on (File .separator ).splitToList (pattern );
1715
- String prefix = "." ;
1716
- for (int i = 0 ; i < patternParts .size (); i ++) {
1717
- if (patternParts .get (i ).contains ("*" )) {
1718
- if (i > 0 ) {
1719
- prefix = Joiner .on (separator ).join (patternParts .subList (0 , i ));
1720
- pattern = Joiner .on (separator ).join (patternParts .subList (i , patternParts .size ()));
1721
- }
1722
- break ;
1723
- }
1724
- }
1725
-
1726
- final PathMatcher matcher = fs .getPathMatcher ("glob:" + prefix + separator + pattern );
1727
- java .nio .file .Files .walkFileTree (
1728
- fs .getPath (prefix ), new SimpleFileVisitor <Path >() {
1729
- @ Override
1730
- public FileVisitResult visitFile (Path p , BasicFileAttributes attrs ) {
1731
- if (matcher .matches (p ) || matcher .matches (p .normalize ())) {
1732
- String pathStringAbsolute = p .normalize ().toAbsolutePath ().toString ();
1733
- if (remove ) {
1734
- excludes .add (pathStringAbsolute );
1735
- allJsInputs .remove (pathStringAbsolute );
1736
- } else if (!excludes .contains (pathStringAbsolute )) {
1737
- allJsInputs .put (pathStringAbsolute , p .toString ());
1738
- }
1739
- }
1740
- return FileVisitResult .CONTINUE ;
1741
- }
1742
-
1743
- @ Override
1744
- public FileVisitResult visitFileFailed (Path file , IOException e ) {
1745
- return FileVisitResult .SKIP_SUBTREE ;
1746
- }
1747
- });
1695
+ throw new UnsupportedOperationException ("" );
1748
1696
}
1749
1697
1750
1698
/**
0 commit comments