summaryrefslogtreecommitdiff
path: root/java/com/google/devtools/build/android/desugar/Desugar.java
diff options
context:
space:
mode:
authorkmb <kmb@google.com>2018-03-12 21:37:51 -0700
committerIvan Gavrilovic <gavra@google.com>2018-05-04 10:40:06 +0100
commit44b53edaa9c5611c75e08da2fdc5d91c7b0ac6ae (patch)
tree6040dd4b8305db93501afa19e1c23c6f0dba7fe2 /java/com/google/devtools/build/android/desugar/Desugar.java
parent46d8182c5c6cb6616586a7ba8466f88ef2fee16a (diff)
downloaddesugar-44b53edaa9c5611c75e08da2fdc5d91c7b0ac6ae.tar.gz
Make KeepScanner tool search classpath for nearest definition of each member reference, instead of potentially referring to a subtype.
Refactor desugar's class loading machinery and related code into a separate package for easier reuse in this tool. RELNOTES: None. PiperOrigin-RevId: 188825305 GitOrigin-RevId: 2cbeb24a9c41c6b14ecbb26e2e198fbaf79aea64 Change-Id: Ie2969cb1e1c86aa68c5a6dc0be6b42b09dfaee70
Diffstat (limited to 'java/com/google/devtools/build/android/desugar/Desugar.java')
-rw-r--r--java/com/google/devtools/build/android/desugar/Desugar.java48
1 files changed, 10 insertions, 38 deletions
diff --git a/java/com/google/devtools/build/android/desugar/Desugar.java b/java/com/google/devtools/build/android/desugar/Desugar.java
index 506a380..c176f9c 100644
--- a/java/com/google/devtools/build/android/desugar/Desugar.java
+++ b/java/com/google/devtools/build/android/desugar/Desugar.java
@@ -27,14 +27,19 @@ import com.google.common.io.ByteStreams;
import com.google.common.io.Closer;
import com.google.devtools.build.android.Converters.ExistingPathConverter;
import com.google.devtools.build.android.Converters.PathConverter;
-import com.google.devtools.build.android.desugar.CoreLibraryRewriter.UnprefixingClassWriter;
+import com.google.devtools.build.android.desugar.io.CoreLibraryRewriter;
+import com.google.devtools.build.android.desugar.io.CoreLibraryRewriter.UnprefixingClassWriter;
+import com.google.devtools.build.android.desugar.io.HeaderClassLoader;
+import com.google.devtools.build.android.desugar.io.IndexedInputs;
+import com.google.devtools.build.android.desugar.io.InputFileProvider;
+import com.google.devtools.build.android.desugar.io.OutputFileProvider;
+import com.google.devtools.build.android.desugar.io.ThrowingClassLoader;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.ShellQuotedParamsFilePreProcessor;
-import com.google.errorprone.annotations.MustBeClosed;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
@@ -386,8 +391,8 @@ class Desugar {
Files.isDirectory(inputPath) || !Files.isDirectory(outputPath),
"Input jar file requires an output jar file");
- try (OutputFileProvider outputFileProvider = toOutputFileProvider(outputPath);
- InputFileProvider inputFiles = toInputFileProvider(inputPath)) {
+ try (OutputFileProvider outputFileProvider = OutputFileProvider.create(outputPath);
+ InputFileProvider inputFiles = InputFileProvider.open(inputPath)) {
DependencyCollector depsCollector = createDepsCollector();
IndexedInputs indexedInputFiles = new IndexedInputs(ImmutableList.of(inputFiles));
// Prepend classpath with input file itself so LambdaDesugaring can load classes with
@@ -942,19 +947,6 @@ class Desugar {
return ioPairListbuilder.build();
}
- @VisibleForTesting
- static class ThrowingClassLoader extends ClassLoader {
- @Override
- protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
- if (name.startsWith("java.")) {
- // Use system class loader for java. classes, since ClassLoader.defineClass gets
- // grumpy when those don't come from the standard place.
- return super.loadClass(name, resolve);
- }
- throw new ClassNotFoundException();
- }
- }
-
private static void deleteTreeOnExit(final Path directory) {
Thread shutdownHook =
new Thread() {
@@ -993,26 +985,6 @@ class Desugar {
}
}
- /** Transform a Path to an {@link OutputFileProvider} */
- @MustBeClosed
- private static OutputFileProvider toOutputFileProvider(Path path) throws IOException {
- if (Files.isDirectory(path)) {
- return new DirectoryOutputFileProvider(path);
- } else {
- return new ZipOutputFileProvider(path);
- }
- }
-
- /** Transform a Path to an InputFileProvider that needs to be closed by the caller. */
- @MustBeClosed
- private static InputFileProvider toInputFileProvider(Path path) throws IOException {
- if (Files.isDirectory(path)) {
- return new DirectoryInputFileProvider(path);
- } else {
- return new ZipInputFileProvider(path);
- }
- }
-
/**
* Transform a list of Path to a list of InputFileProvider and register them with the given
* closer.
@@ -1023,7 +995,7 @@ class Desugar {
Closer closer, List<Path> paths) throws IOException {
ImmutableList.Builder<InputFileProvider> builder = new ImmutableList.Builder<>();
for (Path path : paths) {
- builder.add(closer.register(toInputFileProvider(path)));
+ builder.add(closer.register(InputFileProvider.open(path)));
}
return builder.build();
}