gradle / gradle-completion

Gradle tab completion for bash and zsh
MIT License
1.02k stars 133 forks source link

Better tasks cache generating - gradle task proposal #88

Open mwos-sl opened 4 years ago

mwos-sl commented 4 years ago

Curent behaviour:

Currently generating cache uses gradle tasks --all, which: 1) does not return unqualified tasks (tasks that are in subprojects but available without typing subproject name) 2) includes hidden tasks 3) does not allow to configure visibility of tasks other than setting group to null (but even this one is not supported by gradle-completion, because --all does not care..)

After the command returns a list, additional parsing is done on the script side.

Proposal:

Replace generating cache with configurable gradle task, that creates cache in the final format. Parameters:

    protected Set<String> rootGroupsBlacklist = new HashSet<>();
    protected Set<String> rootTasksBlacklist = new HashSet<>();
    protected Set<String> subprojectsGroupsBlacklist = new HashSet<>();
    protected Set<String> subprojectsTasksBlacklist = new HashSet<>();
    protected Map<String, String> arbitraryCommands = new HashMap<>();

    protected boolean includeUnqualified = true;
    protected boolean includeHidden = false;
    protected boolean duplicateWithoutLeadingColon = true;

...and also list of Clousures with post processors, to modify the final result easily with project specific stuff (e.g. rules).

It gives a total freedom what should be supported in gradle-completion and what should not. It would store directly to pointed cache file set a parameter too. Example configuration in build.gradle:

tasks.register("initCompletionCache", com.sumologic.gradle.completion.InitCacheTask.class) {
  doFirst {
    setRootGroupsBlacklist(groupsToExcludeForRootConsoleCompletion)
    setRootTasksBlacklist(tasksToExcludeForRootTaskReport)
    setSubprojectsGroupsBlacklist(groupsToExcludeForSubProjectTaskReport)
    setSubprojectsTasksBlacklist(tasksToExcludeForSubProjectTaskReport)
  }
}

and invoking:

./gradlew initCompletionCache --shell=bash --completionCachePath="$cache_dir/$cached_checksum" --no-scan

I already implemented it. My plan is, to change gradle-completion scripts in a way, that if they discover .gradle-completion dir in a given project, it would source some files, that would override default behaviour. In particular default command, so that it's possible to replace with my custom task for generating report.

What do you think about it? Would you be interested in: a) such gradle task / plugin to be added to this repository b) eventually replacing gradle tasks --all with it c) more generic scripts that allow overriding default behavious. In particular gradle cmd.

Proposed generating cache is faster comparing to the original one.

mwos-sl commented 4 years ago

As mentioned - I already implemented it and using with luck, using also this PR: https://github.com/gradle/gradle-completion/pull/89

orafaaraujo commented 4 years ago

Hi, everyone :)

Any news about this? It really would help me :)

To "fix" the issue, I edit the Gradle script oh-my-zsh/plugins/gradle/_gradle to run ./gradlew tasks instead ./gradlew tasks --all, so this way I could get only the project tasks and not each module task. But would be good to get all of them.

I also need to delete the cache of my project, deleting the content of .gradle/completion/

Let me know if I could help with something else. :)