-
Notifications
You must be signed in to change notification settings - Fork 624
add gradle tasks for metalava generation #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can you guys have an initial look onto this pr |
@@ -64,6 +69,21 @@ public void apply(Project project) { | |||
} | |||
}); | |||
} | |||
if(System.getenv().containsKey("METALAVA_BINARY_PATH")) { | |||
String metalavaBinaryPath = System.getenv().get("METALAVA_BINARY_PATH"); | |||
String sourcePath = project.getProjectDir() + "/src/main/java"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably needs different paths if its a kotlin project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be replaced with the variant-specific sourceSets collection: see https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/buildSrc/src/main/kotlin/androidx/build/java/JavaCompileInputs.kt#43
Also note that they also setup classpath and bootClasspath, I think we need to do it too
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.groovy
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/GenerateApiTask.groovy
Outdated
Show resolved
Hide resolved
This is a test comment |
1 similar comment
This is a test comment |
This is a testing comment |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
9 similar comments
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
�[34m _ _ �[1m/usr/local/google/home/vguthal/firebase-android-sdk/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java:23: �[31merror: �[0mClass com.google.firebase.firestore.DocumentId no longer implements java.lang.annotation.Annotation [RemovedInterface] |
This is a test comment |
3 similar comments
This is a test comment |
This is a test comment |
This is a test comment |
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/GenerateApiTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java
Outdated
Show resolved
Hide resolved
No project's public api surface was changed due to this PR. |
The public api surface has changed for the subproject firebase-database: Please update the api.txt files for the subprojects being affected by this change with the files present in the artifacts directory. Also perform a major/minor bump accordingly. |
The public api surface has changed for the subproject firebase-firestore: Please update the api.txt files for the subprojects being affected by this change with the files present in the artifacts directory. Also perform a major/minor bump accordingly. |
/retest |
if (System.getenv().containsKey("METALAVA_BINARY_PATH")) { | ||
String metalavaBinaryPath = System.getenv("METALAVA_BINARY_PATH"); | ||
AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main"); | ||
File apiTxtFile = new File(project.getProjectDir() + "/api.txt"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace this with project.file("api.txt"), and maybe inline it?
String metalavaBinaryPath = System.getenv("METALAVA_BINARY_PATH"); | ||
AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main"); | ||
File apiTxtFile = new File(project.getProjectDir() + "/api.txt"); | ||
File baseLineFile = new File(project.getProjectDir() + "/baseline.txt"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of baseline.txt? it seems to be empty, also why is it's version declared as 1.0, while api.txt is declared as 2.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Baseline files are certain files which allows metalava to ignore the warnings present in these files. There is a system property updateBaseline which is added which allows us to control updation of the baseline file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are empty for some sdks whereas its not for firestore, common and other sdks
AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main"); | ||
File apiTxtFile = new File(project.getProjectDir() + "/api.txt"); | ||
File baseLineFile = new File(project.getProjectDir() + "/baseline.txt"); | ||
File outputFile = new File(project.getRootProject().getBuildDir() + "/apiinfo/" + project.getPath().substring(1).replace(":", "_")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project.getRootProject().file(Paths.get(
project.getRootProject().buildDir().getPath(),
"apiinfo",
project.getPath().substring(1).replace(":", "_")));
File baseLineFile = new File(project.getProjectDir() + "/baseline.txt"); | ||
File outputFile = new File(project.getRootProject().getBuildDir() + "/apiinfo/" + project.getPath().substring(1).replace(":", "_")); | ||
File outputFileDir = outputFile.getParentFile(); | ||
if(!outputFileDir.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move it into the task action so that this does not happen if the task is not executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
/retest |
File baseLineFile = new File(project.getProjectDir() + "/baseline.txt"); | ||
File outputFile = new File(project.getRootProject().getBuildDir() + "/apiinfo/" + project.getPath().substring(1).replace(":", "_")); | ||
File outputFileDir = outputFile.getParentFile(); | ||
if(!outputFileDir.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/GenerateApiTxtFileTask.java
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/GenerateApiTxtFileTask.java
Outdated
Show resolved
Hide resolved
The public api surface has changed for the subproject firebase-firestore: |
The public api surface has changed for the subproject firebase-database: Please update the api.txt files for the subprojects being affected by this change with the files present in the artifacts directory. Also perform a major/minor bump accordingly. |
} | ||
String cmdTemplate = "%s --source-path %s --check-compatibility:api:current %s --format=v2 --baseline %s --no-color"; | ||
if(getUpdateBaseline()) { | ||
cmdTemplate = "%s --source-path %s --check-compatibility:api:current %s --format=v2 --update-baseline %s --no-color"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, there is a lot of boilerplate here that comes down to 2 commands and their respective arguments.
%s --source-path %s --api %s --format=v2 --baseline %s
"%s --source-path %s --check-compatibility:api:current %s --format=v2 --update-baseline %s --no-color";
I think we can remove some cruft by modelling this as
// This task executes in 2 modes.
// 1. Generate api text mode
// 2. Compare api text mode
public abstract class MetalavaExecutionTask extends DefaultTask {
@Input
abstract String getMetalavaBinaryPath();
@InputFile
abstract File getApiTxt();
@Input
abstract String getSourcePath();
@InputFile
abstract File getBaselineFile();
@Input
abstract boolean getUpdateBaseline();
@Input
abstract enum getMode();
@OutputFile
abstract File getOutputFile();
abstract void setSourcePath(String value);
abstract void setBaselineFile(File value);
abstract void setUpdateBaseline(boolean value);
abstract void setMetalavaBinaryPath(String value);
abstract void setApiTxt(File value);
abstract void setOutputFile(File value);
abstract void setMode(Mode mode);
private static enum Mode {
GENERATE, COMPARE
}
@TaskAction
void execute() {
File outputFileDir = getOutputFile().getParentFile();
if(!outputFileDir.exists()) {
outputFileDir.mkdirs();
}
String cmd = mode == Mode.GENERATE ? "--check-compatibility:api:current %s" : "--api %s"
String baseline = "--baseline %s" : "--update-baseline %s"
String format = "--format=v2"
String sourcePath = "--source-path %s"
String cmdTemplate = ["%s", sourcePath, cmd, baselineArg, "--no-color"].join(" ")
String cmdToRun = String.format(cmdTemplate, getMetalavaBinaryPath(), getSourcePath(), getApiTxt().getAbsolutePath(), getBaselineFile().getAbsolutePath());
getProject().exec(spec-> {
spec.setCommandLine(Arrays.asList(cmdToRun.split(" ")));
try {
spec.setStandardOutput(new FileOutputStream(getOutputFile()));
} catch (FileNotFoundException e) {
getLogger().error(e.toString());
}
});
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the ci command we would need to run the task to getApiInformation
and then run the task to generateApiInformation in this order
so we would need two tasks. However we can merge the two task classes into one though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And there is no purpose of outputFile in the generateApiInformation Task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The structure of the second task has changed now. It involves producing the api.txt file and then comparing the already existing api.txt with that. I feel now the structure of the two tasks are fairly different
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java
Show resolved
Hide resolved
} | ||
if(doesSourcePathExist) { | ||
project.getTasks().register("apiInformation", ApiInformationTask.class, task -> { | ||
task.setProperty("apiTxt", project.file("api.txt")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer using setters directly instead of using this "reflective magic".(here and below)
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
Outdated
Show resolved
Hide resolved
outputFileDir.mkdirs(); | ||
} | ||
String cmdTemplate = getUpdateBaseline() ? | ||
"%s --source-path %s --check-compatibility:api:current %s --format=v2 --update-baseline %s --no-color" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned before you are still not populating the classpath
The public api surface has changed for the subproject firebase-common: The public api surface has changed for the subproject firebase-database: Please update the api.txt files for the subprojects being affected by this change with the files present in the artifacts directory. Also perform a major/minor bump accordingly. |
The public api surface has changed for the subproject firebase-database: Please update the api.txt files for the subprojects being affected by this change with the files present in the artifacts directory. Also perform a major/minor bump accordingly. |
/test device-check-changed |
boolean doesSourcePathExist = false; | ||
for(String sourcePath : sourcePathArgument.split(":")) { | ||
if(new File(sourcePath).exists()) { | ||
doesSourcePathExist = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can replace this for loop with mainSourceSet.getJava().getSrcDirs().stream().anyMatch(File::exists)
The public api surface has changed for the subproject firebase-firestore: The public api surface has changed for the subproject firebase-common: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
2 similar comments
The public api surface has changed for the subproject firebase-firestore: The public api surface has changed for the subproject firebase-common: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
The public api surface has changed for the subproject firebase-firestore: The public api surface has changed for the subproject firebase-common: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
This pr does the following things. it provides two tasks
This generates the api.txt file which can be used to generate api information in the future.
This provides information about the public apis.
Adds the ci command to invoke the github rest api to post the comments of the results.
Additional context:
Baseline files are certain files which allows metalava to ignore the warnings present in these files. There is a system property updateBaseline which is added which allows us to control updation of the baseline file.
The last comment is how the output would look like