diff options
author | Googler <noreply@google.com> | 2017-03-09 09:47:17 +0000 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-03-13 17:20:46 -0700 |
commit | e0eaafddc031c3a942c03db65854eb534b0ab3db (patch) | |
tree | d1a9d40c34c36e02ca871d6c8d5c66e335ba6691 /java/com/google/devtools/build/android/desugar/Desugar.java | |
parent | b40221e4f50007ca4c1b59e6300ce6c7c1f5a1fb (diff) | |
download | desugar-e0eaafddc031c3a942c03db65854eb534b0ab3db.tar.gz |
Add an --copy_bridges_from_classpath argument
This argument allows to copy bridges from interfaces that are on the classpath to the desugared classes.
RELNOTES: Add an --copy_bridges_from_classpath argument to android desugaring tool
--
PiperOrigin-RevId: 149631699
MOS_MIGRATED_REVID=149631699
GitOrigin-RevId: 4369f79c0e1667ab517f7570aaa448184daf4e66
Change-Id: I20e23995cf6dbee54045b5020ae47a26350759b3
Diffstat (limited to 'java/com/google/devtools/build/android/desugar/Desugar.java')
-rw-r--r-- | java/com/google/devtools/build/android/desugar/Desugar.java | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/java/com/google/devtools/build/android/desugar/Desugar.java b/java/com/google/devtools/build/android/desugar/Desugar.java index 36d9f55..116b2b5 100644 --- a/java/com/google/devtools/build/android/desugar/Desugar.java +++ b/java/com/google/devtools/build/android/desugar/Desugar.java @@ -121,6 +121,14 @@ class Desugar { public int minSdkVersion; @Option( + name = "copy_bridges_from_classpath", + defaultValue = "false", + category = "misc", + help = "Copy bridges from classpath to desugared classes." + ) + public boolean copyBridgesFromClasspath; + + @Option( name = "core_library", defaultValue = "false", category = "undocumented", @@ -168,16 +176,22 @@ class Desugar { CoreLibraryRewriter rewriter = new CoreLibraryRewriter(options.coreLibrary ? "__desugar__/" : ""); + IndexedJars appIndexedJar = new IndexedJars(ImmutableList.of(options.inputJar)); + IndexedJars appAndClasspathIndexedJars = new IndexedJars(options.classpath, appIndexedJar); ClassLoader loader = - createClassLoader( - rewriter, options.bootclasspath, options.inputJar, options.classpath, parent); + createClassLoader(rewriter, options.bootclasspath, appAndClasspathIndexedJars, parent); boolean allowCallsToObjectsNonNull = options.minSdkVersion >= 19; try (ZipFile in = new ZipFile(options.inputJar.toFile()); ZipOutputStream out = new ZipOutputStream( new BufferedOutputStream(Files.newOutputStream(options.outputJar)))) { LambdaClassMaker lambdas = new LambdaClassMaker(dumpDirectory); - ClassReaderFactory readerFactory = new ClassReaderFactory(in, rewriter); + ClassReaderFactory readerFactory = + new ClassReaderFactory( + (options.copyBridgesFromClasspath && !allowDefaultMethods) + ? appAndClasspathIndexedJars + : appIndexedJar, + rewriter); ImmutableSet.Builder<String> interfaceLambdaMethodCollector = ImmutableSet.builder(); @@ -288,21 +302,19 @@ class Desugar { private static ClassLoader createClassLoader( CoreLibraryRewriter rewriter, List<Path> bootclasspath, - Path inputJar, - List<Path> classpath, + IndexedJars appAndClasspathIndexedJars, ClassLoader parent) throws IOException { - // Prepend classpath with input jar itself so LambdaDesugaring can load classes with lambdas. - // Note that inputJar and classpath need to be in the same classloader because we typically get - // the header Jar for inputJar on the classpath and having the header Jar in a parent loader - // means the header version is preferred over the real thing. - classpath = ImmutableList.<Path>builder().add(inputJar).addAll(classpath).build(); // Use a classloader that as much as possible uses the provided bootclasspath instead of // the tool's system classloader. Unfortunately we can't do that for java. classes. if (!bootclasspath.isEmpty()) { - parent = HeaderClassLoader.fromClassPath(bootclasspath, rewriter, parent); + parent = new HeaderClassLoader(new IndexedJars(bootclasspath), rewriter, parent); } - return HeaderClassLoader.fromClassPath(classpath, rewriter, parent); + // Prepend classpath with input jar itself so LambdaDesugaring can load classes with lambdas. + // Note that inputJar and classpath need to be in the same classloader because we typically get + // the header Jar for inputJar on the classpath and having the header Jar in a parent loader + // means the header version is preferred over the real thing. + return new HeaderClassLoader(appAndClasspathIndexedJars, rewriter, parent); } private static class ThrowingClassLoader extends ClassLoader { |