Last active
December 11, 2015 06:38
-
-
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.
This file contains 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
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