-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8016d4b
add gradle tasks for metalava generation
VinayGuthal 48acad3
Address all comments and have the tasks running
VinayGuthal b68fd6b
Merge branch 'master' into add_metalava_api_txt
VinayGuthal a46fa94
fix merge conflict
VinayGuthal 1e291b6
add commands to ci
VinayGuthal 393cb67
add pygithub dependency
VinayGuthal 13279dd
update commit
VinayGuthal af8901c
update api txt
VinayGuthal 1e6c7ac
add fireci commands
VinayGuthal 9023cd7
remove the unwanted task
VinayGuthal c998f48
google java format
VinayGuthal 6be28ef
address all comments
VinayGuthal 6d334a9
update commands
VinayGuthal 82e2fe4
remove unneccasry baselines
VinayGuthal d8ed638
small updates
VinayGuthal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/ApiInformationTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.gradle.plugins.apiinfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collector; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.util.Arrays; | ||
|
||
/** | ||
Task generates the api diff of the current source code against the api.txt file stored | ||
alongside the project's src directory. | ||
*/ | ||
public abstract class ApiInformationTask extends DefaultTask { | ||
|
||
@Input | ||
VinayGuthal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
abstract String getMetalavaBinaryPath(); | ||
|
||
@InputFile | ||
abstract File getApiTxt(); | ||
|
||
@Input | ||
abstract String getSourcePath(); | ||
|
||
@OutputFile | ||
abstract File getBaselineFile(); | ||
|
||
@OutputFile | ||
abstract File getOutputApiFile(); | ||
|
||
@Input | ||
abstract boolean getUpdateBaseline(); | ||
|
||
@OutputFile | ||
abstract File getOutputFile(); | ||
|
||
public abstract void setSourcePath(String value); | ||
|
||
public abstract void setBaselineFile(File value); | ||
|
||
public abstract void setUpdateBaseline(boolean value); | ||
|
||
public abstract void setMetalavaBinaryPath(String value); | ||
|
||
public abstract void setApiTxt(File value); | ||
|
||
public abstract void setOutputApiFile(File value); | ||
|
||
public abstract void setOutputFile(File value); | ||
|
||
|
||
@TaskAction | ||
void execute() { | ||
File outputFileDir = getOutputFile().getParentFile(); | ||
if(!outputFileDir.exists()) { | ||
outputFileDir.mkdirs(); | ||
} | ||
|
||
// Generate api.txt file and store it in the build directory. | ||
getProject().exec(spec-> { | ||
spec.setCommandLine(Arrays.asList( | ||
getMetalavaBinaryPath(), | ||
"--source-path", getSourcePath(), | ||
"--api", getOutputApiFile().getAbsolutePath(), | ||
"--format=v2" | ||
)); | ||
spec.setIgnoreExitValue(true); | ||
}); | ||
getProject().exec(spec-> { | ||
List<String> cmd = new ArrayList<>(Arrays.asList( | ||
getMetalavaBinaryPath(), | ||
"--source-files", getOutputApiFile().getAbsolutePath(), | ||
"--check-compatibility:api:current", getApiTxt().getAbsolutePath(), | ||
"--format=v2", | ||
"--no-color", | ||
"--delete-empty-baselines" | ||
)); | ||
if(getUpdateBaseline()) { | ||
cmd.addAll(Arrays.asList("--update-baseline", getBaselineFile().getAbsolutePath())); | ||
} else if(getBaselineFile().exists()) { | ||
cmd.addAll(Arrays.asList("--baseline", getBaselineFile().getAbsolutePath())); | ||
} | ||
spec.setCommandLine(cmd); | ||
spec.setIgnoreExitValue(true); | ||
try { | ||
spec.setStandardOutput(new FileOutputStream(getOutputFile())); | ||
} catch (FileNotFoundException e) { | ||
throw new GradleException("Unable to run the command", e); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
...rc/src/main/groovy/com/google/firebase/gradle/plugins/apiinfo/GenerateApiTxtFileTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.gradle.plugins.apiinfo; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
import java.io.File; | ||
|
||
import java.util.Arrays; | ||
|
||
|
||
public abstract class GenerateApiTxtFileTask extends DefaultTask { | ||
|
||
@Input | ||
abstract String getMetalavaBinaryPath(); | ||
|
||
@OutputFile | ||
abstract File getApiTxt(); | ||
|
||
@Input | ||
abstract String getSourcePath(); | ||
|
||
|
||
@OutputFile | ||
abstract File getBaselineFile(); | ||
|
||
@Input | ||
abstract boolean getUpdateBaseline(); | ||
|
||
|
||
public abstract void setSourcePath(String value); | ||
|
||
public abstract void setBaselineFile(File value); | ||
|
||
VinayGuthal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public abstract void setUpdateBaseline(boolean value); | ||
|
||
public abstract void setMetalavaBinaryPath(String value); | ||
|
||
public abstract void setApiTxt(File value); | ||
|
||
@TaskAction | ||
void execute() { | ||
List<String> cmd = new ArrayList<String>(Arrays.asList( | ||
getMetalavaBinaryPath(), | ||
"--source-path", getSourcePath(), | ||
"--api", getApiTxt().getAbsolutePath(), | ||
"--format=v2", | ||
"--delete-empty-baselines" | ||
)); | ||
|
||
if(getUpdateBaseline()) { | ||
cmd.addAll(Arrays.asList("--update-baseline", getBaselineFile().getAbsolutePath())); | ||
} else if(getBaselineFile().exists()) { | ||
cmd.addAll(Arrays.asList("--baseline", getBaselineFile().getAbsolutePath())); | ||
} | ||
|
||
getProject().exec(spec -> { | ||
spec.setCommandLine(cmd); | ||
spec.setIgnoreExitValue(true); | ||
}); | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Signature format: 2.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.