3
import org.gradle.api.Plugin
3
4
import org.gradle.api.Project
4
import org.gradle.api.Plugin
6
6
class GroovyTemplatesPlugin implements Plugin<Project> {
7
void createBase(String path = System.getProperty("user.dir")) {
8
ProjectTemplate.fromRoot(path) {
19
"LICENSE.txt" "// Your License Goes here"
23
static String findMainGroovyDir(Project project) {
24
File rootDir = project.projectDir
25
def mainSrcDir = project.sourceSets?.main?.groovy?.srcDirs*.path
26
mainSrcDir = mainSrcDir?.first()
27
mainSrcDir = mainSrcDir?.minus(rootDir.path)
31
void apply(Project project) {
32
project.task("createGroovyClass", group: TemplatesPlugin.group, description: "Creates a new Groovy class in the current project.") << {
36
// get main groovy dir, and check to see if Groovy plugin is installed.
37
mainSrcDir = findMainGroovyDir(project)
38
} catch (Exception e) {
39
throw new IllegalStateException("It seems that the Groovy plugin is not installed, I cannot determine the main groovy source directory.", e)
42
def fullClassName = TemplatesPlugin.prompt("Class name (com.example.MyClass)")
44
def classParts = JavaTemplatesPlugin.getClassParts(fullClassName)
45
ProjectTemplate.fromUserDir {
47
"${classParts.classPackagePath}" {
48
"${classParts.className}.groovy" template: "/templates/groovy/groovy-class.tmpl",
49
className: classParts.className,
50
classPackage: classParts.classPackage
55
println "No class name provided."
58
project.task("createGroovyProject", group: TemplatesPlugin.group,
59
description: "Creates a new Gradle Groovy project in a new directory named after your project.") << {
60
def projectName = TemplatesPlugin.prompt("Project Name:")
62
createBase(projectName)
63
ProjectTemplate.fromRoot(projectName) {
64
"build.gradle" template: "/templates/groovy/build.gradle.tmpl"
67
println "No project name provided."
70
project.task("initGroovyProject", group: TemplatesPlugin.group,
71
description: "Initializes a new Gradle Groovy project in the current directory.") << {
73
TemplatesPlugin.prependPlugin "groovy", new File("build.gradle")
7
void createBase(String path = System.getProperty('user.dir')) {
8
ProjectTemplate.fromRoot(path) {
19
'LICENSE.txt' '// Your License Goes here'
23
static String findMainGroovyDir(Project project) {
24
File rootDir = project.projectDir
25
def mainSrcDir = project.sourceSets?.main?.groovy?.srcDirs*.path
26
mainSrcDir = mainSrcDir?.first()
27
mainSrcDir = mainSrcDir?.minus(rootDir.path)
31
void apply(Project project) {
32
def props = project.properties
34
project.task('createGroovyClass', group: TemplatesPlugin.group, description: 'Creates a new Groovy class in the current project.') << {
38
// get main groovy dir, and check to see if Groovy plugin is installed.
39
mainSrcDir = findMainGroovyDir(project)
40
} catch (Exception e) {
41
throw new IllegalStateException('It seems that the Groovy plugin is not installed, I cannot determine the main groovy source directory.', e)
44
def fullClassName = props['newClassName'] ?: TemplatesPlugin.prompt('Class name (com.example.MyClass)')
47
def classParts = JavaTemplatesPlugin.getClassParts(fullClassName)
48
ProjectTemplate.fromUserDir {
50
"${classParts.classPackagePath}" {
51
"${classParts.className}.groovy" template: '/templates/groovy/groovy-class.tmpl',
52
className: classParts.className,
53
classPackage: classParts.classPackage
58
println 'No class name provided.'
61
project.task('createGroovyProject', group: TemplatesPlugin.group,
62
description: 'Creates a new Gradle Groovy project in a new directory named after your project.') << {
64
def projectName = props['newProjectName'] ?: TemplatesPlugin.prompt('Project Name:')
66
String projectGroup = props['projectGroup'] ?: TemplatesPlugin.prompt('Group:', projectName.toLowerCase())
67
String projectVersion = props['projectVersion'] ?: TemplatesPlugin.prompt('Version:', '1.0')
68
createBase(projectName)
69
ProjectTemplate.fromRoot(projectName) {
70
'build.gradle' template: '/templates/groovy/build.gradle.tmpl', projectGroup: projectGroup
71
'gradle.properties' content: "version=$projectVersion", append: true
74
println 'No project name provided.'
77
project.task('initGroovyProject', group: TemplatesPlugin.group,
78
description: 'Initializes a new Gradle Groovy project in the current directory.') << {
80
def buildFile = new File('build.gradle')
81
buildFile.exists() ?: buildFile.createNewFile()
82
TemplatesPlugin.prependPlugin 'groovy', buildFile
b'\\ No newline at end of file'