summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brazdil <dbrazdil@google.com>2018-04-24 15:38:25 +0100
committerDavid Brazdil <dbrazdil@google.com>2018-04-26 16:44:27 +0000
commit55c48ce3f2ac765949265b7c1ab8cf968b0495f0 (patch)
treecf2fe8bf7a76563d5d6c05c353351d1001a67332
parent3761ce56fa4f6aa13b57304988a523ac5dfd3364 (diff)
downloadplatform_external_doclava-55c48ce3f2ac765949265b7c1ab8cf968b0495f0.tar.gz
platform_external_doclava-55c48ce3f2ac765949265b7c1ab8cf968b0495f0.tar.bz2
platform_external_doclava-55c48ce3f2ac765949265b7c1ab8cf968b0495f0.zip
Add option to print @removed API as DEX signatures
We want to include all @removed API in the light greylist. To this end, we need to dump their list as DEX signatures. This patch adds a new command line option '-removedDexApi <file>' that will dump their list using the existing predicate for @removed API file. Bug: 78182899 Test: make Merged-In: I8fe27e8c03334f9c90204db1e69447de65a06a38 Change-Id: I8fe27e8c03334f9c90204db1e69447de65a06a38 (cherry picked from commit f526f816f214954574006e405dc2e3cdf8cb4842)
-rw-r--r--src/com/google/doclava/Doclava.java14
-rw-r--r--src/com/google/doclava/Stubs.java30
2 files changed, 37 insertions, 7 deletions
diff --git a/src/com/google/doclava/Doclava.java b/src/com/google/doclava/Doclava.java
index b059a64..8231471 100644
--- a/src/com/google/doclava/Doclava.java
+++ b/src/com/google/doclava/Doclava.java
@@ -184,6 +184,7 @@ public class Doclava {
boolean offlineMode = false;
String apiFile = null;
String removedApiFile = null;
+ String removedDexApiFile = null;
String exactApiFile = null;
String privateApiFile = null;
String privateDexApiFile = null;
@@ -305,6 +306,8 @@ public class Doclava {
apiFile = a[1];
} else if (a[0].equals("-removedApi")) {
removedApiFile = a[1];
+ } else if (a[0].equals("-removedDexApi")) {
+ removedDexApiFile = a[1];
} else if (a[0].equals("-exactApi")) {
exactApiFile = a[1];
} else if (a[0].equals("-privateApi")) {
@@ -556,9 +559,11 @@ public class Doclava {
// Stubs
if (stubsDir != null || apiFile != null || proguardFile != null || removedApiFile != null
- || exactApiFile != null || privateApiFile != null || privateDexApiFile != null) {
- Stubs.writeStubsAndApi(stubsDir, apiFile, proguardFile, removedApiFile, exactApiFile,
- privateApiFile, privateDexApiFile, stubPackages, stubImportPackages, stubSourceOnly);
+ || removedDexApiFile != null || exactApiFile != null || privateApiFile != null
+ || privateDexApiFile != null) {
+ Stubs.writeStubsAndApi(stubsDir, apiFile, proguardFile, removedApiFile, removedDexApiFile,
+ exactApiFile, privateApiFile, privateDexApiFile, stubPackages, stubImportPackages,
+ stubSourceOnly);
}
Errors.printErrors();
@@ -856,6 +861,9 @@ public class Doclava {
if (option.equals("-removedApi")) {
return 2;
}
+ if (option.equals("-removedDexApi")) {
+ return 2;
+ }
if (option.equals("-exactApi")) {
return 2;
}
diff --git a/src/com/google/doclava/Stubs.java b/src/com/google/doclava/Stubs.java
index 3d260ea..f5eaf4b 100644
--- a/src/com/google/doclava/Stubs.java
+++ b/src/com/google/doclava/Stubs.java
@@ -47,8 +47,9 @@ import java.util.stream.Collectors;
public class Stubs {
public static void writeStubsAndApi(String stubsDir, String apiFile, String keepListFile,
- String removedApiFile, String exactApiFile, String privateApiFile, String privateDexApiFile,
- HashSet<String> stubPackages, HashSet<String> stubImportPackages, boolean stubSourceOnly) {
+ String removedApiFile, String removedDexApiFile, String exactApiFile, String privateApiFile,
+ String privateDexApiFile, HashSet<String> stubPackages, HashSet<String> stubImportPackages,
+ boolean stubSourceOnly) {
// figure out which classes we need
final HashSet<ClassInfo> notStrippable = new HashSet<ClassInfo>();
Collection<ClassInfo> all = Converter.allClasses();
@@ -56,6 +57,7 @@ public class Stubs {
PrintStream apiWriter = null;
PrintStream keepListWriter = null;
PrintStream removedApiWriter = null;
+ PrintStream removedDexApiWriter = null;
PrintStream exactApiWriter = null;
PrintStream privateApiWriter = null;
PrintStream privateDexApiWriter = null;
@@ -91,6 +93,17 @@ public class Stubs {
"Cannot open file for write");
}
}
+ if (removedDexApiFile != null) {
+ try {
+ File removedDexApi = new File(removedDexApiFile);
+ removedDexApi.getParentFile().mkdirs();
+ removedDexApiWriter = new PrintStream(
+ new BufferedOutputStream(new FileOutputStream(removedDexApi)));
+ } catch (FileNotFoundException e) {
+ Errors.error(Errors.IO_ERROR, new SourcePositionInfo(removedDexApiFile, 0, 0),
+ "Cannot open file for write");
+ }
+ }
if (exactApiFile != null) {
try {
File exactApi = new File(exactApiFile);
@@ -239,7 +252,8 @@ public class Stubs {
}
}
- if (privateApiWriter != null || privateDexApiWriter != null || removedApiWriter != null) {
+ if (privateApiWriter != null || privateDexApiWriter != null || removedApiWriter != null
+ || removedDexApiWriter != null) {
allClassesByPackage = Converter.allClasses().stream()
// Make sure that the files only contains information from the required packages.
.filter(ci -> stubPackages == null
@@ -249,11 +263,12 @@ public class Stubs {
final boolean ignoreShown = Doclava.showUnannotated;
+ Predicate<MemberInfo> memberIsNotCloned = (x -> !x.isCloned());
+
FilterPredicate apiFilter = new FilterPredicate(new ApiPredicate().setIgnoreShown(ignoreShown));
ApiPredicate apiReference = new ApiPredicate().setIgnoreShown(true);
Predicate<MemberInfo> apiEmit = apiFilter.and(new ElidingPredicate(apiReference));
- Predicate<MemberInfo> memberIsNotCloned = (x -> !x.isCloned());
Predicate<MemberInfo> privateEmit = memberIsNotCloned.and(apiFilter.negate());
Predicate<MemberInfo> privateReference = (x -> true);
@@ -261,6 +276,7 @@ public class Stubs {
new FilterPredicate(new ApiPredicate().setIgnoreShown(ignoreShown).setMatchRemoved(true));
ApiPredicate removedReference = new ApiPredicate().setIgnoreShown(true).setIgnoreRemoved(true);
Predicate<MemberInfo> removedEmit = removedFilter.and(new ElidingPredicate(removedReference));
+ Predicate<MemberInfo> removedDexEmit = memberIsNotCloned.and(removedFilter);
// Write out the current API
if (apiWriter != null) {
@@ -291,6 +307,12 @@ public class Stubs {
writeApi(removedApiWriter, allClassesByPackage, removedEmit, removedReference);
removedApiWriter.close();
}
+
+ // Write out the removed DEX API
+ if (removedDexApiWriter != null) {
+ writeDexApi(removedDexApiWriter, allClassesByPackage, removedDexEmit);
+ removedDexApiWriter.close();
+ }
}
private static boolean shouldWriteStub(final String packageName,