Skip to content
This repository was archived by the owner on Jun 1, 2019. It is now read-only.

Commit 090d2e0

Browse files
committed
Remove dependencies on Java 7 std library.
1 parent fa8d632 commit 090d2e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+146
-140
lines changed

src/com/google/javascript/jscomp/AbstractCommandLineRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.US_ASCII;
20-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.US_ASCII;
20+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2121

2222
import com.google.common.annotations.GwtIncompatible;
2323
import com.google.common.annotations.VisibleForTesting;

src/com/google/javascript/jscomp/AliasStrings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;

src/com/google/javascript/jscomp/CallGraph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.LinkedHashMap;
3232
import java.util.LinkedList;
3333
import java.util.Map;
34-
import java.util.Objects;
34+
import java7compat.util.Objects;
3535

3636
/**
3737
* A pass the uses a {@link DefinitionProvider} to compute a call graph for an

src/com/google/javascript/jscomp/CommandLineRunner.java

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.common.base.Joiner;
@@ -45,22 +45,9 @@
4545
import org.kohsuke.args4j.spi.Setter;
4646
import org.kohsuke.args4j.spi.StringOptionHandler;
4747

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.*;
5549
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;
6451
import java.util.ArrayList;
6552
import java.util.Collection;
6653
import java.util.Collections;
@@ -1181,10 +1168,12 @@ private void reportError(String message) {
11811168

11821169
private void processFlagFile()
11831170
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);
11851176

1186-
BufferedReader buffer =
1187-
java.nio.file.Files.newBufferedReader(flagFile, UTF_8);
11881177
// Builds the tokens.
11891178
StringBuilder builder = new StringBuilder();
11901179
// Stores the built tokens.
@@ -1568,13 +1557,15 @@ protected CompilerOptions createOptions() {
15681557
Instrumentation.Builder builder = Instrumentation.newBuilder();
15691558
BufferedReader br = null;
15701559
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);
15721563
StringBuilder sb = new StringBuilder();
15731564
String line = br.readLine();
15741565

15751566
while (line != null) {
15761567
sb.append(line);
1577-
sb.append(System.lineSeparator());
1568+
sb.append(System.getProperty("line.separator"));
15781569
line = br.readLine();
15791570
}
15801571
instrumentationPb = sb.toString();
@@ -1685,8 +1676,8 @@ private static List<String> findJsFiles(Collection<String> patterns, boolean sor
16851676
if (matchedFile.isDirectory()) {
16861677
matchPaths(new File(matchedFile, "**.js").toString(), allJsInputs, excludes);
16871678
} 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();
16901681
if (!excludes.contains(pathStringAbsolute)) {
16911682
allJsInputs.put(pathStringAbsolute, original.toString());
16921683
}
@@ -1701,50 +1692,7 @@ private static List<String> findJsFiles(Collection<String> patterns, boolean sor
17011692

17021693
private static void matchPaths(String pattern, final Map<String, String> allJsInputs,
17031694
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("");
17481696
}
17491697

17501698
/**

src/com/google/javascript/jscomp/Compiler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import java.io.File;
5050
import java.io.IOException;
5151
import java.io.PrintStream;
52-
import java.nio.file.FileSystems;
5352
import java.util.ArrayList;
5453
import java.util.Collections;
5554
import java.util.HashMap;
@@ -562,8 +561,9 @@ private static List<CompilerInput> getAllInputsFromModules(
562561
* getRelativeTo("../foo/bar.js", "baz/bam/qux.js") --> "baz/foo/bar.js"
563562
*/
564563
private static String getRelativeTo(String relative, String base) {
565-
return FileSystems.getDefault().getPath(base)
566-
.resolveSibling(relative)
564+
return new File(base)
565+
.toURI()
566+
.resolve(relative)
567567
.normalize()
568568
.toString()
569569
.replace(File.separator, "/");

src/com/google/javascript/jscomp/DataFlowAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.Iterator;
3232
import java.util.LinkedHashSet;
3333
import java.util.List;
34-
import java.util.Objects;
34+
import java7compat.util.Objects;
3535
import java.util.Set;
3636
import java.util.TreeSet;
3737

src/com/google/javascript/jscomp/DefaultPassConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.javascript.jscomp;
1818

1919
import static com.google.javascript.jscomp.PassFactory.createEmptyPass;
20-
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2121

2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.base.Preconditions;

src/com/google/javascript/jscomp/FileInstrumentationData.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ String getInstrumentedLinesAsHexString() {
6161
StringBuilder builder = new StringBuilder();
6262

6363
// Build the hex string.
64-
for (byte byteEntry : instrumentedBits.toByteArray()) {
64+
for (byte byteEntry : toByteArray(instrumentedBits)) {
6565
// Java bytes are signed, but we want the value as if it were unsigned.
6666
int value = UnsignedBytes.toInt(byteEntry);
6767
String hexString = Integer.toHexString(value);
@@ -75,6 +75,15 @@ String getInstrumentedLinesAsHexString() {
7575
return builder.toString();
7676
}
7777

78+
private static byte[] toByteArray(BitSet bits) {
79+
byte[] bytes = new byte[(bits.length() + 7) / 8];
80+
for (int i = 0; i < bits.length(); i++) {
81+
if (bits.get(i)) {
82+
bytes[(bytes.length - i) / (8 - 1)] |= 1 << (i % 8);
83+
}
84+
}
85+
return bytes;
86+
}
7887

7988
/**
8089
* Mark given 1-based line number as instrumented. Zero, Negative numbers

src/com/google/javascript/jscomp/GlobalNamespace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import java.util.HashMap;
3838
import java.util.List;
3939
import java.util.Map;
40-
import java.util.Objects;
40+
import java7compat.util.Objects;
4141
import java.util.Set;
4242

4343
/**

src/com/google/javascript/jscomp/GoogleJsMessageIdGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.base.CaseFormat;
2222
import com.google.common.base.Preconditions;

0 commit comments

Comments
 (0)