Skip to content
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

Improve gradle plugin task parsing #5230

Merged
merged 3 commits into from
Sep 15, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve gradle task parsing by writing .gradletasknamecache atomically
Previously the .gradletasknamecache file was written line by line inside a parsing loop,
which could cause errors such as half-written cache files if the process was aborted.

This also removes the need of deleting the .gradletasknamecache file before parsing.
  • Loading branch information
bes committed Sep 14, 2016
commit ff862f84a75ef37eea6986c019d590095412dea7
20 changes: 4 additions & 16 deletions plugins/gradle/gradle.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ _gradle_does_task_list_need_generating () {
# are considered to be tasks. If and when gradle adds support for listing tasks
# for programmatic parsing, this method can be deprecated.
##############
_gradle_parse_tasks_to_gradletasknamecache () {
_gradle_parse_tasks () {
lines_might_be_tasks=false
task_name_buffer=""
while read -r line; do
Expand All @@ -78,7 +78,7 @@ _gradle_parse_tasks_to_gradletasknamecache () {
if [[ "$lines_might_be_tasks" = true ]]; then
# If a newline is found, send the buffer to .gradletasknamecache
while read -r task; do
echo $task | awk '/[a-zA-Z0-9:-]+/ {print $1}' >> .gradletasknamecache
echo $task | awk '/[a-zA-Z0-9:-]+/ {print $1}'
done <<< "$task_name_buffer"
# Empty buffer, because we are done with the tasks
task_name_buffer=""
Expand All @@ -97,13 +97,7 @@ _gradle_tasks () {
if [[ -f build.gradle ]]; then
_gradle_arguments
if _gradle_does_task_list_need_generating; then
# First empty the old cache file
if [ -f .gradletasknamecache ]; then
rm .gradletasknamecache
fi
# Then append the rest of the lines to that file
output=$(gradle tasks --all)
_gradle_parse_tasks_to_gradletasknamecache $output
_gradle_parse_tasks "$(gradle tasks --all)" > .gradletasknamecache
fi
compadd -X "==== Gradle Tasks ====" $(cat .gradletasknamecache)
fi
Expand All @@ -113,13 +107,7 @@ _gradlew_tasks () {
if [[ -f build.gradle ]]; then
_gradle_arguments
if _gradle_does_task_list_need_generating; then
# First empty the old cache file
if [ -f .gradletasknamecache ]; then
rm .gradletasknamecache
fi
# Then append the rest of the lines to that file
output=$(./gradlew tasks --all)
_gradle_parse_tasks_to_gradletasknamecache $output
_gradle_parse_tasks "$(./gradlew tasks --all)" > .gradletasknamecache
fi
compadd -X "==== Gradlew Tasks ====" $(cat .gradletasknamecache)
fi
Expand Down