~gradle-plugins/gradle-templates/trunk

« back to all changes in this revision

Viewing changes to src/main/groovy/templates/WebappTemplatesPlugin.groovy

  • Committer: Eric Berry
  • Date: 2011-08-04 00:49:30 UTC
  • Revision ID: elberry@gmail.com-20110804004930-hi55con4e6tt6c8f
renaming scala templates to match the others. Also implementing blueprints for groupId and version, as well as -P properties.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package templates
2
2
 
 
3
import org.gradle.api.Plugin
3
4
import org.gradle.api.Project
4
 
import org.gradle.api.Plugin
5
5
 
6
6
class WebappTemplatesPlugin extends JavaTemplatesPlugin implements Plugin<Project> {
7
 
   void createBase(String path = System.getProperty("user.dir"), String projectName) {
8
 
      super.createBase(path)
9
 
      ProjectTemplate.fromRoot(path) {
10
 
         "src/main/webapp/WEB-INF" {
11
 
            "web.xml" template: "/templates/webapp/web-xml.tmpl", project: [name: projectName]
12
 
         }
13
 
      }
14
 
   }
15
 
 
16
 
   void apply(Project project) {
17
 
      project.apply(plugin: "java-templates")
18
 
      
19
 
      project.task("createWebappProject", group: TemplatesPlugin.group, description: "Creates a new Gradle Webapp project in a new directory named after your project.") << {
20
 
         def projectName = TemplatesPlugin.prompt("Project Name:")
21
 
         def useJetty = TemplatesPlugin.promptYesOrNo("Use Jetty Plugin?")
22
 
         if (projectName) {
23
 
            createBase(projectName, projectName)
24
 
            ProjectTemplate.fromRoot(projectName) {
25
 
               "build.gradle" template: "/templates/webapp/build.gradle.tmpl", useJetty: useJetty
26
 
            }
27
 
         } else {
28
 
            println "No project name provided."
29
 
         }
30
 
      }
31
 
      project.task("initWebappProject", group: TemplatesPlugin.group, description: "Initializes a new Gradle Webapp project in the current directory.") << {
32
 
         createBase(project.name)
33
 
         def useJetty = TemplatesPlugin.promptYesOrNo("Use Jetty Plugin?")
34
 
         if(useJetty) {
35
 
            TemplatesPlugin.prependPlugin "jetty", new File("build.gradle")
36
 
         }
37
 
         TemplatesPlugin.prependPlugin "war", new File("build.gradle")
38
 
      }
39
 
 
40
 
   }
 
7
        void createBase(String path = System.getProperty('user.dir'), String projectName) {
 
8
                super.createBase(path)
 
9
                ProjectTemplate.fromRoot(path) {
 
10
                        'src/main/webapp/WEB-INF' {
 
11
                                'web.xml' template: '/templates/webapp/web-xml.tmpl', project: [name: projectName]
 
12
                        }
 
13
                }
 
14
        }
 
15
 
 
16
        void apply(Project project) {
 
17
                project.apply(plugin: 'java-templates')
 
18
 
 
19
                def props = project.properties
 
20
 
 
21
                project.task('createWebappProject', group: TemplatesPlugin.group, description: 'Creates a new Gradle Webapp project in a new directory named after your project.') << {
 
22
                        def projectName = props['newProjectName'] ?: TemplatesPlugin.prompt('Project Name:')
 
23
                        def useJetty = props['useJettyPlugin'] ?: TemplatesPlugin.promptYesOrNo('Use Jetty Plugin?')
 
24
                        if (projectName) {
 
25
                                String projectGroup = props['projectGroup'] ?: TemplatesPlugin.prompt('Group:', projectName.toLowerCase())
 
26
                                String projectVersion = props['projectVersion'] ?: TemplatesPlugin.prompt('Version:', '1.0')
 
27
                                createBase(projectName, projectName)
 
28
                                ProjectTemplate.fromRoot(projectName) {
 
29
                                        'build.gradle' template: '/templates/webapp/build.gradle.tmpl', useJetty: useJetty, projectGroup: projectGroup
 
30
                                        'gradle.properties' content: "version=${projectVersion}", append: true
 
31
                                }
 
32
                        } else {
 
33
                                println 'No project name provided.'
 
34
                        }
 
35
                }
 
36
                project.task('initWebappProject', group: TemplatesPlugin.group, description: 'Initializes a new Gradle Webapp project in the current directory.') << {
 
37
                        createBase(project.name)
 
38
                        def useJetty = props['useJettyPlugin'] ?: TemplatesPlugin.promptYesOrNo('Use Jetty Plugin?')
 
39
                        File buildFile = new File('build.gradle')
 
40
                        buildFile.exists() ?: buildFile.createNewFile()
 
41
                        if (useJetty) {
 
42
                                TemplatesPlugin.prependPlugin 'jetty', buildFile
 
43
                        } else {
 
44
                                TemplatesPlugin.prependPlugin 'war', buildFile
 
45
                        }
 
46
                }
 
47
 
 
48
        }
41
49
}
 
 
b'\\ No newline at end of file'