-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashCompletion.gradle
28 lines (24 loc) · 1.38 KB
/
bashCompletion.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
apply plugin: BashCompletionPlugin
import java.security.MessageDigest
class BashCompletionPlugin implements Plugin<Gradle> {
void apply(Gradle gradle) {
gradle.rootProject {
def rootDirEncodedHex = MessageDigest.getInstance("MD5").digest(projectDir.absolutePath.bytes).encodeHex().toString()
def bashCompletionFolder = new File(new File(gradle.getGradleUserHomeDir(), 'bash'), rootDirEncodedHex)
def autoCompleteSuggestionsFile = new File(bashCompletionFolder, 'gradle-autocomplete')
def projectMappingsFile = new File(bashCompletionFolder, 'gradle-projects')
tasks.create('bashCompletion') {
doLast {
// create file with all tasks
def allTaskNames = getAllTasks(true).collectMany { proj, taskSet -> taskSet.collect { it.path } }
autoCompleteSuggestionsFile.parentFile.mkdirs()
autoCompleteSuggestionsFile.text = allTaskNames.sort().unique().join('\n')
// create file that maps project path to relative directory
def projectMappings = allprojects.collect { "${it.path}=${it.rootProject.relativePath(it.projectDir.path)}" }
projectMappingsFile.parentFile.mkdirs()
projectMappingsFile.text = projectMappings.join('\n')
}
}
}
}
}