Skip to content

Instantly share code, notes, and snippets.

@ajoberstar
Last active December 11, 2015 06:38
Show Gist options
  • Save ajoberstar/4560342 to your computer and use it in GitHub Desktop.
Save ajoberstar/4560342 to your computer and use it in GitHub Desktop.
Gradle init script adding a task that creates a Sublime Text 2 project file.
import groovy.json.JsonBuilder
rootProject {
task sublimeProject {
group = 'IDE'
description = 'Generate a project file for Sublime Text 2.'
doLast {
def json = new JsonBuilder()
def projectPaths = allprojects.collectEntries { project ->
[(project.name):project.projectDir.canonicalPath.replaceAll($/\\/$, '/')]
}
new File(project.projectDir, 'buildSrc').with {
if (it.exists()) {
projectPaths['buildSrc'] = it.canonicalPath.replaceAll($/\\/$, '/')
}
}
def folders = projectPaths.collect { name, path ->
def lastFolder = (path =~ /.*[\\\/](.+)$/)[0][1]
def excludes = ["$lastFolder/build", "$lastFolder/.gradle", "$lastFolder/bin", "$lastFolder/.codestation"]
def nestedProjects = projectPaths.values().collect {
it.replaceAll("^$path", lastFolder)
}.findAll {
it != lastFolder && it.startsWith("$lastFolder/")
}
[path: path, name: name, folder_exclude_patterns:(excludes + nestedProjects)]
}
json(folders:folders)
file("${project.name}.sublime-project").withWriter { writer ->
writer.println json.toPrettyString()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment