*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import groovy.text.GStringTemplateEngine
/**
* This class is used to construct a ProjectTemplate. A project template consists of files and directories. This builder
* can be used to set up the necessary files and directories needed for new projects.
*
* Eg.
*
* ProjectTemplate.fromUserDir {
* directory('src') { // creates new directory named 'src'
* dir('main') { // creates a new directory named 'main'
* d('java') { // creates a new directory named 'java'
* file('Class1.java') // creates a new file named 'Class1.java'
* f('Class2.java') // creates a new file named 'Class2.java'
* }
* }
* }
* }
*
*
* Can also be used without method calls for directory and file.
* Eg.
*
* ProjectTemplate.fromUserDir {
* 'src/main' { // creates the directories 'src', and 'main'.
* 'java' {
* 'Class1.java' 'public class Class1 {}' // creates the file 'Class1.java' with some initial content.
* }
* 'resources' {}
* }
* }
*
*
* @author: elberry
* Date: 4/9/11 6:04 PM
*/
class ProjectTemplate {
private File parent
/**
* Private so that it can't be accessed. Use one of the static 'fromUserDir' methods to start building a template.
*/
private ProjectTemplate() {}
/**
* Same as the directory method.
* @param name
* @param closure
* @see #directory(String, Closure)
*/
void d(String name, Closure closure = {}) {
directory(name, closure)
}
/**
* Same as the directory method.
* @param name
* @param closure
* @see #directory(String, Closure)
*/
void dir(String name, Closure closure = {}) {
directory(name, closure)
}
/**
* Creates a directory, and it's parents if they don't already exist.
* @param name
* @param closure
* @see #directory(String, Closure)
*/
void directory(String name, Closure closure = {}) {
File oldParent = parent
if (parent) {
parent = new File(parent, name)
} else {
parent = new File(name)
}
parent.mkdirs()
closure.delegate = this
closure()
parent = oldParent
}
/**
* Same as file method
* @param args
* @param name
* @see #file(Map, String)
*/
void f(Map args = [:], String name) {
file(args, name)
}
/**
* Same as file method
* @param args
* @param name
* @see #file(String, String)
*/
void f(String name, String content) {
file(name, content)
}
/**
* Creates a new file with the given name. If a 'content' argument is provided it will be appended, or replace the
* content of the current file (if it exists) based on the value of the 'append' argument.
* @param args Arguments to be used when creating the new file: [content: String, append: boolean]
* @param name Name of the new file to be created.
*/
void file(Map args = [:], String name) {
File file
if (parent) {
file = new File(parent, name)
} else {
file = new File(name)
}
file.exists() ?: file.parentFile.mkdirs() && file.createNewFile()
def content
if (args.content) {
content = args.content.stripIndent()
} else if (args.template) {
content = renderTemplate(args, args.template)
}
if (content) {
if (args.append) {
file.append(content)
} else {
file.text = content
}
}
}
/**
* Render the template at the given path with the provided parameters. An attempt will be made to load the template path
* as an absolute path, then as a relative path, then lastly from the classpath.
*
* @param params
* @param template the template path
* @return the rendered template
*/
String renderTemplate(Map params = [:], String template) {
def tLoc = new File(template)
if (!tLoc.exists()) { // check given path
// Couldn't find file at given path, trying relative path.
def rTemplate = template
if (rTemplate.startsWith('/')) {
rTemplate = rTemplate - '/'
}
tLoc = new File(System.getProperty('user.dir'), rTemplate)
if (!tLoc.exists()) { // check relative path from current working dir.
tLoc = getClass().getResource(template) // last ditch, use classpath.
}
}
def tReader = tLoc?.newReader()
if (tReader) {
return new GStringTemplateEngine().createTemplate(tReader)?.make(params)?.toString()
}
throw new RuntimeException("Could not locate template: ${template}")
}
/**
* Calls file([content: content], name)
* @param name
* @param content
* @see #file(Map, String)
*/
void file(String name, String content) {
file([content: content], name)
}
/**
* Starts the ProjectTemplate in the "user.dir" directory, unless the init.dir system property is specified.
* @param closure
*/
static void fromUserDir(Closure closure = {}) {
new ProjectTemplate().directory(System.getProperty( 'init.dir', System.getProperty('user.dir') ), closure)
}
/**
* Starts the ProjectTemplate in the given path.
* @param path String path to the root of the new project.
* @param closure
*/
static void fromRoot(String path, Closure closure = {}) {
new ProjectTemplate().directory(path, closure)
}
/**
* Starts the ProjectTemplate in the given file path.
* @param pathFile File path to the root of the new project.
* @param closure
*/
static void fromRoot(File pathFile, Closure closure = {}) {
new ProjectTemplate().directory(pathFile.path, closure)
}
/**
* Handles creation of files or directories without the need to specify directly.
* @param name
* @param args
* @return
*/
def methodMissing(String name, def args) {
if (args) {
def arg = args[0]
if (arg instanceof Closure) {
directory(name, arg)
} else if (arg instanceof Map) {
file(arg, name)
} else if (arg instanceof String || arg instanceof GString) {
file([content: arg], name)
} else {
println "Couldn't figure out what to do. name: ${name}, arg: ${arg}, type: ${arg.getClass()}"
}
}
}
}
================================================
FILE: src/main/groovy/templates/ScalaTemplatesPlugin.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Plugin
import org.gradle.api.Project
import templates.tasks.scala.CreateScalaClassTask
import templates.tasks.scala.CreateScalaObjectTask
import templates.tasks.scala.CreateScalaProjectTask
import templates.tasks.scala.ExportScalaTemplatesTask
import templates.tasks.scala.InitScalaProjectTask
/**
* Adds basic tasks for bootstrapping Scala projects.
*
* Adds createScalaClass, createScalaObject, createScalaProject, exportScalaTemplates, and initScalaProject tasks.
*/
class ScalaTemplatesPlugin implements Plugin {
// TODO: is this plugin really needed or just roll into main?
void apply(Project project) {
project.task 'createScalaClass', type:CreateScalaClassTask
project.task 'createScalaObject', type:CreateScalaObjectTask
project.task 'createScalaProject', type:CreateScalaProjectTask
project.task 'exportScalaTemplates', type:ExportScalaTemplatesTask
project.task 'initScalaProject', type:InitScalaProjectTask
}
}
================================================
FILE: src/main/groovy/templates/TemplatesPlugin.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* The core of the templates plugin.
*/
class TemplatesPlugin implements Plugin {
static final String group = 'Template'
static final String lineSep = System.getProperty( 'line.separator' )
static final String inputPrompt = "${lineSep}templates>"
static void prependPlugin(String plugin, File gradleFile) {
def oldText = gradleFile.text
gradleFile.text = ''
gradleFile.withPrintWriter { pw ->
pw.println "apply plugin: '${plugin}'"
pw.print oldText
}
}
static String prompt(String message, String defaultValue = null) {
readLine(message, defaultValue)
}
static int promptOptions(String message, List options = []) {
promptOptions(message, 0, options)
}
static int promptOptions(String message, int defaultValue, List options = []) {
String consoleMessage = "${message}"
consoleMessage += "${lineSep} Pick an option ${1..options.size()}"
options.eachWithIndex { option, index ->
consoleMessage += "${lineSep} (${index + 1}): ${option}"
}
try {
def range = 0..options.size() - 1
int choice = Integer.parseInt(readLine(consoleMessage, defaultValue))
if (choice == 0) {
throw new GradleException('No option provided')
}
choice--
if (range.containsWithinBounds(choice)) {
return choice
} else {
throw new IllegalArgumentException('Option is not valid.')
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException('Option is not valid.', e)
}
}
static boolean promptYesOrNo( final String message, final boolean defaultValue = false) {
String consoleVal = readLine("$message (Y|n)", defaultValue ? 'Y' : 'n')
return consoleVal?.toLowerCase()?.startsWith('y') ?: defaultValue
}
private static String readLine(String message, def defaultValue = null) {
String _message = "$inputPrompt $message " + (defaultValue ? "$lineSep [$defaultValue] " : "")
if (System.console()) {
return System.console().readLine(_message) ?: String.valueOf(defaultValue)
}
println "$_message (WAITING FOR INPUT BELOW)"
return System.in.newReader().readLine() ?: String.valueOf(defaultValue)
}
def void apply(Project project) {
project.convention.plugins.templatePlugin = new TemplatesPluginConvention()
// FIXME: would be better to allow user to configure the desired template set rather than get them all
project.apply(plugin: GroovyTemplatesPlugin)
project.apply(plugin: GradlePluginTemplatesPlugin)
project.apply(plugin: JavaTemplatesPlugin)
project.apply(plugin: ScalaTemplatesPlugin)
project.apply(plugin: WebappTemplatesPlugin)
project.task(
'exportAllTemplates',
dependsOn: [
'exportJavaTemplates', 'exportGroovyTemplates', 'exportScalaTemplates', 'exportWebappTemplates', 'exportPluginTemplates'
],
group: TemplatesPlugin.group,
description: 'Exports all the default template files into the current directory.'
) {}
}
}
================================================
FILE: src/main/groovy/templates/TemplatesPluginConvention.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
/**
* @author: elberry
* Date: 4/12/11 12:27 AM
*/
class TemplatesPluginConvention {
String gradlePluginApplyLabel
String gradlePluginClassName
String sourceBasePackage
def templates(Closure closure) {
closure.delegate = this
closure()
}
}
================================================
FILE: src/main/groovy/templates/WebappTemplatesPlugin.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Plugin
import org.gradle.api.Project
import templates.tasks.webapp.CreateWebappProjectTask
import templates.tasks.webapp.ExportWebappTemplatesTask
import templates.tasks.webapp.InitWebappProjectTask
/**
* Adds basic tasks for bootstrapping Webapp projects. Adds createWebappProject, exportWebappTemplates, and
* initWebappProject tasks. Also applies the java-templates plugin.
*/
class WebappTemplatesPlugin extends JavaTemplatesPlugin implements Plugin {
void apply(Project project) {
// Check to make sure JavaTemplatesPlugin isn't already added.
if (!project.plugins.findPlugin(JavaTemplatesPlugin)) {
project.apply(plugin: JavaTemplatesPlugin)
}
project.task 'createWebappProject', type:CreateWebappProjectTask
project.task 'exportWebappTemplates', type:ExportWebappTemplatesTask
project.task 'initWebappProject', type:InitWebappProjectTask
}
}
================================================
FILE: src/main/groovy/templates/tasks/AbstractProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks
import org.gradle.api.DefaultTask
import templates.TemplatesPlugin
/**
* Abstract base class for project tasks.
*/
abstract class AbstractProjectTask extends DefaultTask {
static final String NEW_PROJECT_NAME = 'newProjectName'
static final String PROJECT_GROUP = 'projectGroup'
static final String PROJECT_VERSION = 'projectVersion'
static final String PROJECT_PARENT_DIR = 'projectParentDir'
AbstractProjectTask( final String name, final String description ){
this.name = name
this.group = TemplatesPlugin.group
this.description = description
}
/**
* A solution to allow external generation directory config which also allows unit testing for init.
* It will try a system property named 'init.dir' and then fallback to the 'user.dir' property value.
*/
protected String defaultDir(){
System.getProperty( 'init.dir', System.getProperty('user.dir') )
}
/**
* Determine the project path directory based on the specified project name.
*
* If the "projectParentDir" is not specified as a property, the user will be prompted for it.
*
* @param projectName the project name
* @return the project directory path
*/
protected String projectPath( final String projectName ){
String parentDir = project.properties[PROJECT_PARENT_DIR]
if( parentDir ){
return "$parentDir/$projectName"
} else {
String dir = TemplatesPlugin.prompt( 'Project Parent Directory:', defaultDir() )
return "$dir/$projectName"
}
}
/**
* Determine the project name to be used. If the 'newProjectName' is not specified as a property, the user will
* be prompted for it.
*
* @return the project name to be used
*/
protected String projectName(){
project.properties[NEW_PROJECT_NAME] ?: TemplatesPlugin.prompt('Project Name:')
}
/**
* Determine the project group to be used based on the project name. If the 'projectGroup' is not specified as a
* property, the user will be prompted for it.
*
* @param projectName the project name
* @return the project group
*/
protected String projectGroup( final String projectName ){
project.properties[PROJECT_GROUP] ?: TemplatesPlugin.prompt('Group:', projectName.toLowerCase())
}
/**
* Determine the project version to be used. If the 'projectVersion' is not specified as a property the user will
* be prompted for it.
*
* @return the project version
*/
protected String projectVersion(){
project.properties[PROJECT_VERSION] ?: TemplatesPlugin.prompt('Version:', '0.1')
}
/**
* Ensures that the specified file exists under the current default directory. The file reference is returned.
*
* @param file the file suffix to ensure
* @return the existing file
*/
protected File ensureFileExists( final String file ){
File buildFile = new File(defaultDir(), file)
if( !buildFile.exists() ){
buildFile.createNewFile()
}
return buildFile
}
}
================================================
FILE: src/main/groovy/templates/tasks/AbstractTemplateExportTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import templates.TemplatesPlugin
/**
* Abstract base task for template exporters.
*/
abstract class AbstractTemplateExportTask extends DefaultTask {
private final templatePaths = []
/**
* Creates a new template export task with the given properties and templates.
*
* @param name the task name
* @param description the task description
* @param paths the template paths
*/
protected AbstractTemplateExportTask( final String name, final String description, final paths = []){
this.name = name
this.group = TemplatesPlugin.group
this.description = description
this.templatePaths = paths
}
/**
* Exports the configured templates.
*/
@TaskAction void export(){
exportTemplates templatePaths
}
private void exportTemplates(def templates = []) {
templates.ProjectTemplate.fromUserDir {
templates.each { template ->
def tStream = getClass().getResourceAsStream(template)
"$template" tStream.text
}
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/gradle/AbstractGradleProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import templates.JavaTemplatesPlugin
import templates.ProjectTemplate
import templates.TemplatesPlugin
import templates.tasks.AbstractProjectTask
/**
*
*/
abstract class AbstractGradleProjectTask extends AbstractProjectTask {
static final String PLUGIN_APPLY_LABEL = 'pluginApplyLabel'
static final String PLUGIN_CLASS_NAME = 'pluginClassName'
AbstractGradleProjectTask( final String name, final String description ){
super( name, description )
}
/**
* Creates the default project structure for a new gradle plugin.
* @param path The root path of the project. optional, defaults to user.dir.
* @param project A project object.
*/
protected void createBase(String path = defaultDir(), def project) {
def props = project.properties
String lProjectName = project.name.toLowerCase()
String cProjectName = project.name.capitalize()
String projectGroup = props[ PROJECT_GROUP ] ?: TemplatesPlugin.prompt('Group:', lProjectName)
String projectVersion = props[ PROJECT_VERSION ] ?: TemplatesPlugin.prompt('Version:', '1.0')
String pluginApplyLabel = props[ PLUGIN_APPLY_LABEL ] ?: TemplatesPlugin.prompt('Plugin \'apply\' label:', lProjectName)
String pluginClassName = props[ PLUGIN_CLASS_NAME ] ?: TemplatesPlugin.prompt('Plugin class name:', "${projectGroup}.${cProjectName}Plugin")
createGroovyBase( path )
ProjectTemplate.fromRoot(path){
'src/main/' {
'resources/META-INF/gradle-plugins' {
"${pluginApplyLabel}.properties" "implementation-class=${pluginClassName}"
}
'groovy' {
if (pluginClassName) {
def classParts = JavaTemplatesPlugin.getClassParts(pluginClassName)
"${classParts.classPackagePath}" {
"${classParts.className}.groovy" template: '/templates/plugin/plugin-class.tmpl',
className: classParts.className,
classPackage: classParts.classPackage
"${classParts.className}Convention.groovy" template: '/templates/plugin/convention-class.tmpl',
className: classParts.className,
classPackage: classParts.classPackage
}
}
}
}
'build.gradle' template: '/templates/plugin/build.gradle.tmpl', projectGroup: projectGroup
'gradle.properties' content: "version=${projectVersion}", append: true
}
}
// FIXME: a bit of duplicated code to start with, need to refactor away
private void createGroovyBase( path ){
ProjectTemplate.fromRoot(path) {
'src' {
'main' {
'groovy' {}
'resources' {}
}
'test' {
"groovy" {}
"resources" {}
}
}
'LICENSE.txt' '// Your License Goes here'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/gradle/CreateGradlePluginTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import org.gradle.api.tasks.TaskAction
/**
* Task to create a gradle project in a new directory.
*/
class CreateGradlePluginTask extends AbstractGradleProjectTask {
CreateGradlePluginTask(){
super(
'createGradlePlugin',
'Creates a new Gradle Plugin project in a new directory named after your project.'
)
}
@TaskAction void create(){
def projectName = projectName()
if (projectName) {
createBase(
projectPath( projectName ),
[
name:projectName,
properties:project.properties
]
)
} else {
// FIXME: error
println 'No project name provided.'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/gradle/ExportPluginTemplatesTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import templates.tasks.AbstractTemplateExportTask
/**
* Task to export the default gradle project templates.
*/
class ExportPluginTemplatesTask extends AbstractTemplateExportTask {
ExportPluginTemplatesTask(){
super(
'exportPluginTemplates',
'Exports the default plugin template files into the current directory.',
[
'/templates/plugin/build.gradle.tmpl',
'/templates/plugin/convention-class.tmpl',
'/templates/plugin/plugin-class.tmpl'
]
)
}
}
================================================
FILE: src/main/groovy/templates/tasks/gradle/InitGradlePluginTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import org.gradle.api.tasks.TaskAction
/**
* Task to initialize a new gradle plugin project in the current directory.
*/
class InitGradlePluginTask extends AbstractGradleProjectTask {
InitGradlePluginTask(){
super(
'initGradlePlugin',
'Initializes a new Gradle Plugin project in the current directory.'
)
}
@TaskAction def init(){
createBase project
}
}
================================================
FILE: src/main/groovy/templates/tasks/groovy/AbstractGroovyProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import templates.ProjectTemplate
import templates.tasks.AbstractProjectTask
/**
*
*/
abstract class AbstractGroovyProjectTask extends AbstractProjectTask {
AbstractGroovyProjectTask( final String name, final String description ){
super( name, description )
}
/**
* Creates the basic Groovy project directory structure.
* @param path the root of the project. Optional,defaults to user.dir.
*/
protected void createBase(String path = defaultDir() ) {
ProjectTemplate.fromRoot(path) {
'src' {
'main' {
'groovy' {}
'resources' {}
}
'test' {
"groovy" {}
"resources" {}
}
}
'LICENSE.txt' '// Your License Goes here'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/groovy/CreateGroovyClassTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction
import templates.JavaTemplatesPlugin
import templates.ProjectTemplate
import templates.TemplatesPlugin
/**
* Task to create a new Groovy class in the current project.
*/
class CreateGroovyClassTask extends AbstractGroovyProjectTask {
public static final String NEW_CLASS_NAME = 'newClassName'
CreateGroovyClassTask(){
super(
'createGroovyClass',
'Creates a new Groovy class in the current project.'
)
}
@TaskAction def create(){
def mainSrcDir = null
try {
// get main groovy dir, and check to see if Groovy plugin is installed.
mainSrcDir = findMainGroovyDir(project)
} catch (Exception e) {
throw new IllegalStateException('It seems that the Groovy plugin is not installed, I cannot determine the main groovy source directory.', e)
}
def fullClassName = project.properties[NEW_CLASS_NAME] ?: TemplatesPlugin.prompt('Class name (com.example.MyClass)')
if (fullClassName) {
def classParts = JavaTemplatesPlugin.getClassParts(fullClassName)
ProjectTemplate.fromUserDir {
"${mainSrcDir}" {
"${classParts.classPackagePath}" {
"${classParts.className}.groovy" template: '/templates/groovy/groovy-class.tmpl',
className: classParts.className,
classPackage: classParts.classPackage
}
}
}
} else {
println 'No class name provided.'
}
}
// FIXME: these finders are all very similar, refactor
/**
* Finds the path to the main java source directory.
* @param project The project.
* @return The path to the main groovy source directory.
*/
private static String findMainGroovyDir(Project project) {
def mainSrcDir = project.sourceSets?.main?.groovy?.srcDirs*.path
mainSrcDir = mainSrcDir?.first()
mainSrcDir = mainSrcDir?.minus(project.projectDir.path)
return mainSrcDir
}
}
================================================
FILE: src/main/groovy/templates/tasks/groovy/CreateGroovyProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.gradle.api.tasks.TaskAction
import templates.ProjectTemplate
/**
* Task to create a Groovy Gradle project in a new directory.
*/
class CreateGroovyProjectTask extends AbstractGroovyProjectTask {
CreateGroovyProjectTask(){
super(
'createGroovyProject',
'Creates a new Gradle Groovy project in a new directory named after your project.'
)
}
@TaskAction def create(){
String projectName = projectName()
if (projectName) {
String projectPath = projectPath( projectName )
createBase projectPath
ProjectTemplate.fromRoot(projectPath) {
'build.gradle' template:'/templates/groovy/build.gradle.tmpl', projectGroup:projectGroup(projectName)
'gradle.properties' content:"version=${projectVersion()}", append:true
}
} else {
// FIXME: should be an error
println 'No project name provided.'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/groovy/ExportGroovyTemplatesTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import templates.tasks.AbstractTemplateExportTask
/**
* Task to export the default groovy templates.
*/
class ExportGroovyTemplatesTask extends AbstractTemplateExportTask {
ExportGroovyTemplatesTask(){
super(
'exportGroovyTemplates',
'Exports the default groovy template files into the current directory.',
[
'/templates/groovy/build.gradle.tmpl',
'/templates/groovy/groovy-class.tmpl'
]
)
}
}
================================================
FILE: src/main/groovy/templates/tasks/groovy/InitGroovyProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.gradle.api.tasks.TaskAction
import templates.TemplatesPlugin
/**
* Task to initialize a groovy project.
*/
class InitGroovyProjectTask extends AbstractGroovyProjectTask {
InitGroovyProjectTask(){
super(
'initGroovyProject',
'Initializes a new Gradle Groovy project in the current directory.'
)
}
@TaskAction def init(){
createBase()
File buildFile = ensureFileExists('build.gradle')
TemplatesPlugin.prependPlugin 'groovy', buildFile
}
}
================================================
FILE: src/main/groovy/templates/tasks/java/AbstractJavaProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import templates.ProjectTemplate
import templates.tasks.AbstractProjectTask
/**
* Base class for Java project tasks.
*/
abstract class AbstractJavaProjectTask extends AbstractProjectTask {
AbstractJavaProjectTask( final String name, final String description ){
super( name, description )
}
/**
* Creates the basic Java project directory structure.
*
* @param path the root of the project. Optional,defaults to user.dir.
*/
protected void createBase(String path = defaultDir() ){
ProjectTemplate.fromRoot(path) {
'src' {
'main' {
'java' {}
'resources' {}
}
'test' {
'java' {}
'resources' {}
}
}
'LICENSE.txt' '// Your License Goes here'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/java/CreateJavaClassTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction
import templates.JavaTemplatesPlugin
import templates.ProjectTemplate
import templates.TemplatesPlugin
/**
* Task to create a new Java class in the current project.
*/
class CreateJavaClassTask extends AbstractJavaProjectTask {
// TODO: the property names should be standardized and in a shared location
public static final String NEW_CLASS_NAME = 'newClassName'
CreateJavaClassTask(){
super(
'createJavaClass',
'Creates a new Java class in the current project.'
)
}
@TaskAction def create(){
def mainSrcDir = null
try {
// get main java dir, and check to see if Java plugin is installed.
mainSrcDir = findMainJavaDir(project)
} catch (Exception e) {
throw new IllegalStateException('It seems that the Java plugin is not installed, I cannot determine the main java source directory.', e)
}
def fullClassName = project.properties[NEW_CLASS_NAME] ?: TemplatesPlugin.prompt('Class name (com.example.MyClass)')
if (fullClassName) {
def classParts = JavaTemplatesPlugin.getClassParts(fullClassName)
ProjectTemplate.fromUserDir {
"${mainSrcDir}" {
"${classParts.classPackagePath}" {
"${classParts.className}.java" template: '/templates/java/java-class.tmpl',
classPackage: classParts.classPackage,
className: classParts.className
}
}
}
} else {
// TODO: should be an error
println 'No class name provided.'
}
}
/**
* Finds the path to the main java source directory.
*
* @param project The project.
* @return The path to the main java source directory.
*/
private static String findMainJavaDir( final Project project ){
def mainSrcDir = project.sourceSets?.main?.java?.srcDirs*.path
mainSrcDir = mainSrcDir?.first()
mainSrcDir = mainSrcDir?.minus(project.projectDir.path)
return mainSrcDir
}
}
================================================
FILE: src/main/groovy/templates/tasks/java/CreateJavaProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.gradle.api.tasks.TaskAction
import templates.ProjectTemplate
/**
* Task that creates a new java project in a specified directory.
*/
class CreateJavaProjectTask extends AbstractJavaProjectTask {
CreateJavaProjectTask(){
super(
'createJavaProject',
'Creates a new Gradle Java project in a new directory named after your project.'
)
}
@TaskAction void create(){
String projectName = projectName()
if (projectName) {
String projectPath = projectPath( projectName )
createBase projectPath
ProjectTemplate.fromRoot(projectPath) {
'build.gradle' template:'/templates/java/build.gradle.tmpl', projectGroup:projectGroup(projectName)
'gradle.properties' content:"version=${projectVersion()}", append:true
}
} else {
// FIXME: should be an error
println 'No project name provided.'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/java/ExportJavaTemplatesTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import templates.tasks.AbstractTemplateExportTask
/**
* Task to export the default java templates into the current directory.
*/
class ExportJavaTemplatesTask extends AbstractTemplateExportTask {
ExportJavaTemplatesTask(){
super(
'exportJavaTemplates',
'Exports the default java template files into the current directory.',
[
'/templates/java/build.gradle.tmpl',
'/templates/java/java-class.tmpl'
]
)
}
}
================================================
FILE: src/main/groovy/templates/tasks/java/InitJavaProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.gradle.api.tasks.TaskAction
import templates.TemplatesPlugin
/**
* Task to initialize a gradle Java project in the current directory.
*/
class InitJavaProjectTask extends AbstractJavaProjectTask {
InitJavaProjectTask(){
super(
'initJavaProject',
'Initializes a new Gradle Java project in the current directory.'
)
}
@TaskAction def init(){
createBase()
File buildFile = ensureFileExists( 'build.gradle')
TemplatesPlugin.prependPlugin 'java', buildFile
}
}
================================================
FILE: src/main/groovy/templates/tasks/scala/AbstractScalaProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.gradle.api.Project
import templates.ProjectTemplate
import templates.TemplatesPlugin
import templates.tasks.AbstractProjectTask
/**
* Base class for Scala tasks.
*/
abstract class AbstractScalaProjectTask extends AbstractProjectTask {
static final String SCALA_VERSION = 'scalaVersion'
static final String USE_FAST_SCALA_COMPILER = 'useFastScalaCompiler'
AbstractScalaProjectTask( final String name, final String description ){
super( name, description )
}
/**
* Creates the basic Scala project directory structure.
*
* @param path the root of the project. Optional,defaults to user.dir.
*/
protected void createBase(String path = defaultDir() ){
ProjectTemplate.fromRoot(path) {
'src' {
'main' {
'scala' {}
'resources' {}
}
'test' {
'scala' {}
'resources' {}
}
}
'LICENSE.txt' '// Your License Goes here'
}
}
/**
* Initializes or creates the project's build.gradle file.
*
* @param project The project
* @param path The path to the root of the project. optional, defaults to user.dir.
*/
protected void setupBuildFile(Project project, String path = defaultDir() ) {
def props = project.properties
String scalaVersion = props[SCALA_VERSION] ?: TemplatesPlugin.prompt('Scala Version:', '2.9.0')
boolean useFastCompiler = props[USE_FAST_SCALA_COMPILER] ?: TemplatesPlugin.promptYesOrNo('Use fast compiler?', false)
ProjectTemplate.fromRoot(path) {
'build.gradle' template: '/templates/scala/build.gradle.tmpl', append: true,
scalaVersion: scalaVersion,
useFastCompiler: useFastCompiler,
projectGroup: props[AbstractProjectTask.PROJECT_GROUP]
'gradle.properties' content: "version=${props[AbstractProjectTask.PROJECT_VERSION] ?: '0.1'}", append: true
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/scala/CreateScalaClassTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction
import templates.JavaTemplatesPlugin
import templates.ProjectTemplate
import templates.TemplatesPlugin
/**
* Task for creating a new scala class in the current project.
*/
class CreateScalaClassTask extends AbstractScalaProjectTask {
protected static final String NEW_CLASS_NAME = 'newClassName'
protected static final String NEW_OBJECT_NAME = 'newObjectName'
CreateScalaClassTask(){
super(
'createScalaClass',
'Creates a new Scala class in the current project.'
)
}
@TaskAction
def create(){
createScalaClass project, false
}
/**
* Creates a Scala class, or object in the current working directory.
*
* @param project The project.
* @param object Is this a Scala class, or object.
*/
protected void createScalaClass(Project project, boolean object) {
def mainSrcDir = null
try {
// get main Scala dir, and check to see if Scala plugin is installed.
mainSrcDir = findMainScalaDir(project)
} catch (Exception e) {
throw new IllegalStateException('It seems that the Scala plugin is not installed, I cannot determine the main scala source directory.', e)
}
def props = project.properties
def type = object ? 'Object' : 'Class'
// TODO: seems like we'd only need one name that works for either case
def fullClassName = props[NEW_CLASS_NAME] ?: props[NEW_OBJECT_NAME] ?: TemplatesPlugin.prompt("${type} name (com.example.My${type})")
if (fullClassName) {
def classParts = JavaTemplatesPlugin.getClassParts(fullClassName)
ProjectTemplate.fromUserDir {
"${mainSrcDir}" {
"${classParts.classPackagePath}" {
"${classParts.className}.scala" template: '/templates/scala/scala-class.tmpl',
className: classParts.className,
classPackage: classParts.classPackage,
object: object
}
}
}
} else {
// TODO: should be an error of some sort
println 'No class name provided.'
}
}
/**
* Finds the path to the main java source directory.
*
* @param project The project.
* @return The path to the main groovy source directory.
*/
protected static String findMainScalaDir( final Project project ){
def mainSrcDir = project.sourceSets?.main?.scala?.srcDirs*.path
mainSrcDir = mainSrcDir?.first()
mainSrcDir = mainSrcDir?.minus(project.projectDir.path)
return mainSrcDir
}
}
================================================
FILE: src/main/groovy/templates/tasks/scala/CreateScalaObjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.gradle.api.tasks.TaskAction
/**
* Task for creating a new scala object in the current project.
*/
class CreateScalaObjectTask extends CreateScalaClassTask {
// TODO: seems like there should be a better way to do this since its just a different property
CreateScalaObjectTask(){
super()
name = 'createScalaObject'
description = 'Creates a new Scala object in the current project.'
}
@Override @TaskAction
def create(){
createScalaClass project, true
}
}
================================================
FILE: src/main/groovy/templates/tasks/scala/CreateScalaProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.gradle.api.tasks.TaskAction
/**
* Task for creating a new Gradle Scala project in a specified directory.
*/
class CreateScalaProjectTask extends AbstractScalaProjectTask {
CreateScalaProjectTask(){
super(
'createScalaProject',
'Creates a new Gradle Scala project in a new directory named after your project.'
)
}
@TaskAction void create(){
String projectName = projectName()
if (projectName) {
project.ext[PROJECT_GROUP] = projectGroup( projectName )
project.ext[PROJECT_VERSION] = projectVersion()
String projectPath = projectPath( projectName )
createBase projectPath
setupBuildFile project, projectPath
} else {
// FIXME: error
println 'No project name provided.'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/scala/ExportScalaTemplatesTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import templates.tasks.AbstractTemplateExportTask
/**
* Task to export the scala templates.
*/
class ExportScalaTemplatesTask extends AbstractTemplateExportTask {
ExportScalaTemplatesTask(){
super(
'exportScalaTemplates',
'Exports the default scala template files into the current directory.',
[
'/templates/scala/build.gradle.tmpl',
'/templates/scala/scala-class.tmpl'
]
)
}
}
================================================
FILE: src/main/groovy/templates/tasks/scala/InitScalaProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.gradle.api.tasks.TaskAction
/**
* Task for initializing a new Gradle Scala project in the current directory.
*/
class InitScalaProjectTask extends AbstractScalaProjectTask {
InitScalaProjectTask(){
super(
'initScalaProject',
'Initializes a new Gradle Scala project in the current directory.'
)
}
@TaskAction
def init(){
createBase()
setupBuildFile(project)
}
}
================================================
FILE: src/main/groovy/templates/tasks/webapp/AbstractWebappProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import templates.ProjectTemplate
import templates.TemplatesPlugin
import templates.tasks.AbstractProjectTask
/**
*
*/
abstract class AbstractWebappProjectTask extends AbstractProjectTask {
static final String USE_JETTY_PLUGIN = 'useJettyPlugin'
AbstractWebappProjectTask( final String name, final String description ){
super( name, description )
}
/**
* Creates the basic Groovy project directory structure.
* @param path the root of the project. Optional,defaults to user.dir.
*/
protected void createBase(String path = defaultDir(), String projectName) {
createJavaBase path
ProjectTemplate.fromRoot(path) {
'src/main/webapp/WEB-INF' {
'web.xml' template: '/templates/webapp/web-xml.tmpl', project: [name: projectName]
}
}
}
protected boolean useJetty(){
if( project.properties[USE_JETTY_PLUGIN] ){
return project.properties[USE_JETTY_PLUGIN]?.toLowerCase() == 'y'
} else {
return TemplatesPlugin.promptYesOrNo('Use Jetty Plugin?')
}
}
// FIXME: copied from AbstractJavaProjectTask
private void createJavaBase(String path = defaultDir() ){
ProjectTemplate.fromRoot(path) {
'src' {
'main' {
'java' {}
'resources' {}
}
'test' {
'java' {}
'resources' {}
}
}
'LICENSE.txt' '// Your License Goes here'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/webapp/CreateWebappProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import org.gradle.api.tasks.TaskAction
import templates.ProjectTemplate
/**
* Task to create a new gradle web app project in a directory.
*/
class CreateWebappProjectTask extends AbstractWebappProjectTask {
CreateWebappProjectTask(){
super(
'createWebappProject',
'Creates a new Gradle Webapp project in a new directory named after your project.'
)
}
@TaskAction def create(){
String projectName = projectName()
if (projectName) {
String projectPath = projectPath( projectName )
createBase projectPath, projectName
ProjectTemplate.fromRoot(projectPath) {
'build.gradle' template:'/templates/webapp/build.gradle.tmpl', useJetty:useJetty(), projectGroup:projectGroup(projectName)
'gradle.properties' content:"version=${projectVersion()}", append:true
}
} else {
// FIXME: error here
println 'No project name provided.'
}
}
}
================================================
FILE: src/main/groovy/templates/tasks/webapp/ExportWebappTemplatesTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import templates.tasks.AbstractTemplateExportTask
/**
* Task to export the default webapp templates.
*/
class ExportWebappTemplatesTask extends AbstractTemplateExportTask {
ExportWebappTemplatesTask(){
super(
'exportWebappTemplates',
'Exports the default webapp template files into the current directory.',
[
'/templates/webapp/build.gradle.tmpl',
'/templates/webapp/web-xml.tmpl'
]
)
}
}
================================================
FILE: src/main/groovy/templates/tasks/webapp/InitWebappProjectTask.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import org.gradle.api.tasks.TaskAction
import templates.TemplatesPlugin
/**
* Task to initialize a webapp project.
*/
class InitWebappProjectTask extends AbstractWebappProjectTask {
InitWebappProjectTask(){
super(
'initWebappProject',
'Initializes a new Gradle Webapp project in the current directory.'
)
}
@TaskAction def init(){
createBase project.name
File buildFile = ensureFileExists( 'build.gradle' )
TemplatesPlugin.prependPlugin useJetty() ? 'jetty' : 'war', buildFile
}
}
================================================
FILE: src/main/resources/META-INF/gradle-plugins/gradle-plugin-templates.properties
================================================
implementation-class=templates.GradlePluginTemplatesPlugin
================================================
FILE: src/main/resources/META-INF/gradle-plugins/groovy-templates.properties
================================================
implementation-class=templates.GroovyTemplatesPlugin
================================================
FILE: src/main/resources/META-INF/gradle-plugins/java-templates.properties
================================================
implementation-class=templates.JavaTemplatesPlugin
================================================
FILE: src/main/resources/META-INF/gradle-plugins/scala-templates.properties
================================================
implementation-class=templates.ScalaTemplatesPlugin
================================================
FILE: src/main/resources/META-INF/gradle-plugins/templates.properties
================================================
implementation-class=templates.TemplatesPlugin
================================================
FILE: src/main/resources/META-INF/gradle-plugins/webapp-templates.properties
================================================
implementation-class=templates.WebappTemplatesPlugin
================================================
FILE: src/main/resources/templates/groovy/build.gradle.tmpl
================================================
apply plugin: 'groovy'
group = '${projectGroup}'
dependencies {
groovy localGroovy()
}
================================================
FILE: src/main/resources/templates/groovy/groovy-class.tmpl
================================================
package ${classPackage}
/**
* @author ${System.getProperty('user.name')}
* Created: ${new Date()}
*/
class ${className} {
}
================================================
FILE: src/main/resources/templates/java/build.gradle.tmpl
================================================
apply plugin: 'java'
group = '${projectGroup}'
================================================
FILE: src/main/resources/templates/java/java-class.tmpl
================================================
package ${classPackage};
/**
* @author ${System.getProperty('user.name')}
* Created: ${new Date()}
*/
public class ${className} {
public ${className}() {
}
}
================================================
FILE: src/main/resources/templates/plugin/build.gradle.tmpl
================================================
apply plugin: 'groovy'
group = '${projectGroup}'
dependencies {
compile gradleApi()
groovy localGroovy()
}
================================================
FILE: src/main/resources/templates/plugin/convention-class.tmpl
================================================
package ${classPackage}
/**
* @author ${System.getProperty('user.name')}
* Created: ${new Date()}
*/
class ${className}Convention {
}
================================================
FILE: src/main/resources/templates/plugin/plugin-class.tmpl
================================================
package ${classPackage}
import org.gradle.api.Project
import org.gradle.api.Plugin
/**
* @author ${System.getProperty('user.name')}
* Created: ${new Date()}
*/
class ${className} implements Plugin {
void apply (Project project) {
project.convention.plugins.${className} = new ${className}Convention()
// add your plugin tasks here.
}
}
================================================
FILE: src/main/resources/templates/scala/build.gradle.tmpl
================================================
apply plugin: 'scala'
<% if(projectGroup){ %>
group = '${projectGroup}'
<% } %>
repositories {
mavenCentral()
}
scalaVersion = '${scalaVersion}'
dependencies {
// Libraries needed to run the scala tools
scalaTools "org.scala-lang:scala-compiler:\${scalaVersion}",
"org.scala-lang:scala-library:\${scalaVersion}"
// Libraries needed for scala api
compile "org.scala-lang:scala-library:\${scalaVersion}"
}
<% if (useFastCompiler) { %>
compileScala {
scalaCompileOptions.useCompileDaemon = true
// optionally specify host and port of the daemon:
scalaCompileOptions.daemonServer = 'localhost:4243'
}
<% } %>
================================================
FILE: src/main/resources/templates/scala/scala-class.tmpl
================================================
package ${classPackage}
/**
* @author ${System.getProperty('user.name')}
* Created: ${new Date()}
*/
${object ? 'object' : 'class'} ${className} {
}
================================================
FILE: src/main/resources/templates/webapp/build.gradle.tmpl
================================================
${useJetty ? 'apply plugin: \'jetty\'' : 'apply plugin: \'war\''}
group = '${projectGroup}'
================================================
FILE: src/main/resources/templates/webapp/web-xml.tmpl
================================================
${project.name} - Webapp
Describe the ${project.name} Webapp here.
${System.getProperty('user.name')}@example.com
See http://tomcat.apache.org/tomcat-6.0-doc/appdev/web.xml.txt for more information
regarding this Web Descriptor File.
================================================
FILE: src/test/groovy/templates/AbstractTaskTester.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.testfixtures.ProjectBuilder
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.rules.TemporaryFolder
/**
* Base class for template-based task testers.
*/
abstract class AbstractTaskTester {
@Rule
public TemporaryFolder folder = new TemporaryFolder()
protected Project project
protected Task task
private final Class taskClass
AbstractTaskTester( final Class taskClass ){
this.taskClass = taskClass
}
@Before
void before(){
System.setProperty( 'init.dir', folder.root as String )
project = ProjectBuilder.builder().build()
task = project.task( 'targetTask', type:taskClass )
}
@After void after(){
System.setProperty( 'init.dir', '' )
}
/**
* Asserts that the specified file exists.
*
* @param root the root directory
* @param path the path to the file
*/
protected void assertFileExists( File root, String path ){
assert new File( root, path ).exists()
}
/**
* Asserts that the file at the given path (root+path) exists and that it contains the specified
* content strings.
*
* @param root the root directory
* @param path the path to the file
* @param contents the content string to be tested
*/
protected void assertFileContains( File root, String path, String... contents ){
assertFileExists root, path
String text = new File( root, path ).text
contents.each { String str ->
assert text.contains( str )
}
}
}
================================================
FILE: src/test/groovy/templates/GradlePluginTemplatesPluginTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
class GradlePluginTemplatesPluginTest {
@Rule public TemporaryFolder rootFolder = new TemporaryFolder()
@Test void 'apply'(){
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'templates'
assert project.tasks.createGradlePlugin
assert project.tasks.exportPluginTemplates
assert project.tasks.initGradlePlugin
}
}
================================================
FILE: src/test/groovy/templates/GroovyTemplatesPluginTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
class GroovyTemplatesPluginTest {
@Test void 'apply'(){
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'templates'
assert project.tasks.createGroovyClass
assert project.tasks.createGroovyProject
assert project.tasks.exportGroovyTemplates
assert project.tasks.initGroovyProject
}
}
================================================
FILE: src/test/groovy/templates/JavaTemplatesPluginTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
class JavaTemplatesPluginTest {
@Test void 'apply'(){
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'templates'
assert project.tasks.createJavaClass
assert project.tasks.createJavaProject
assert project.tasks.exportJavaTemplates
assert project.tasks.initJavaProject
}
}
================================================
FILE: src/test/groovy/templates/ProjectTemplateTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
class ProjectTemplateTest {
private static final String PROJECT_NAME = 'some_project'
@Rule public TemporaryFolder rootFolder = new TemporaryFolder()
@Test void 'fromRoot(String): empty'(){
assert !(new File( rootFolder.root, PROJECT_NAME ).exists())
ProjectTemplate.fromRoot( "${rootFolder.root}/$PROJECT_NAME" )
assert new File( rootFolder.root, PROJECT_NAME ).exists()
}
@Test void 'fromRoot(String): with content'(){
assert !(new File( rootFolder.root, PROJECT_NAME ).exists())
File templateFile = rootFolder.newFile( 'template.tmpl' )
templateFile.text = 'The answer is ${bar}'
ProjectTemplate.fromRoot( "${rootFolder.root}/$PROJECT_NAME" ){
'stuff' {
'README.txt' '''
This is a generated README file.
'''
'deeper' {}
'foo' template:templateFile.toString(), bar:42
}
}
assert new File( rootFolder.root, PROJECT_NAME ).exists()
assert new File( rootFolder.root, "$PROJECT_NAME/stuff" ).exists()
assert new File( rootFolder.root, "$PROJECT_NAME/stuff/deeper" ).exists()
assertFileText rootFolder.root, "$PROJECT_NAME/stuff/README.txt", 'This is a generated README file.'
assertFileText rootFolder.root, "$PROJECT_NAME/stuff/foo", 'The answer is 42'
}
private void assertFileText( File dir, String path, String expectedText ){
def targetFile = new File( dir, path )
assert targetFile.exists()
assert targetFile.text.trim() == expectedText
}
@Test void 'fromRoot(File): empty'(){
assert !(new File( rootFolder.root, PROJECT_NAME ).exists())
ProjectTemplate.fromRoot( new File( rootFolder.root, PROJECT_NAME ) )
assert new File( rootFolder.root, PROJECT_NAME ).exists()
}
}
================================================
FILE: src/test/groovy/templates/ScalaTemplatesPluginTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
class ScalaTemplatesPluginTest {
@Test void 'apply'(){
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'templates'
assert project.tasks.createScalaClass
assert project.tasks.createScalaObject
assert project.tasks.createScalaProject
assert project.tasks.exportScalaTemplates
assert project.tasks.initScalaProject
}
}
================================================
FILE: src/test/groovy/templates/TemplatesPluginTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
class TemplatesPluginTest {
@Test void 'apply'(){
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'templates'
assert project.tasks.exportAllTemplates
assert project.tasks.createGradlePlugin
assert project.tasks.exportPluginTemplates
assert project.tasks.initGradlePlugin
assert project.tasks.createGroovyClass
assert project.tasks.createGroovyProject
assert project.tasks.exportGroovyTemplates
assert project.tasks.initGroovyProject
assert project.tasks.createJavaClass
assert project.tasks.createJavaProject
assert project.tasks.exportJavaTemplates
assert project.tasks.initJavaProject
assert project.tasks.createScalaClass
assert project.tasks.createScalaObject
assert project.tasks.createScalaProject
assert project.tasks.exportScalaTemplates
assert project.tasks.initScalaProject
assert project.tasks.createWebappProject
assert project.tasks.exportWebappTemplates
assert project.tasks.initWebappProject
}
}
================================================
FILE: src/test/groovy/templates/WebappTemplatesPluginTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
class WebappTemplatesPluginTest {
@Test void 'apply'(){
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'templates'
assert project.tasks.createWebappProject
assert project.tasks.exportWebappTemplates
assert project.tasks.initWebappProject
}
}
================================================
FILE: src/test/groovy/templates/tasks/gradle/CreateGradlePluginTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import org.junit.Test
import templates.AbstractTaskTester
import static AbstractGradleProjectTask.NEW_PROJECT_NAME
import static AbstractGradleProjectTask.PROJECT_PARENT_DIR
import static AbstractGradleProjectTask.PROJECT_GROUP
import static AbstractGradleProjectTask.PROJECT_VERSION
import static AbstractGradleProjectTask.PLUGIN_CLASS_NAME
import static AbstractGradleProjectTask.PLUGIN_APPLY_LABEL
class CreateGradlePluginTaskTest extends AbstractTaskTester {
CreateGradlePluginTaskTest(){
super( CreateGradlePluginTask )
}
@Test void create(){
project.ext[PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[NEW_PROJECT_NAME] = 'tester'
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[PROJECT_VERSION] = '1.1.1'
project.ext[PLUGIN_APPLY_LABEL] = 'test-foo'
project.ext[PLUGIN_CLASS_NAME] = 'com.test'
task.create()
assertFileExists folder.root, 'tester/src/main/groovy'
assertFileExists folder.root, 'tester/src/main/resources'
assertFileExists folder.root, 'tester/src/test/groovy'
assertFileExists folder.root, 'tester/src/test/resources'
assertFileExists folder.root, 'tester/LICENSE.txt'
assertFileContains folder.root, 'tester/build.gradle', 'group = \'test-group\''
assertFileContains folder.root, 'tester/gradle.properties', 'version=1.1.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/gradle/ExportPluginTemplatesTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import org.junit.Test
import templates.AbstractTaskTester
class ExportPluginTemplatesTaskTest extends AbstractTaskTester {
ExportPluginTemplatesTaskTest(){
super( ExportPluginTemplatesTask )
}
@Test void export(){
task.export()
assertFileExists folder.root, 'templates/plugin/build.gradle.tmpl'
assertFileExists folder.root, 'templates/plugin/convention-class.tmpl'
assertFileExists folder.root, 'templates/plugin/plugin-class.tmpl'
}
}
================================================
FILE: src/test/groovy/templates/tasks/gradle/InitGradlePluginTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.gradle
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.gradle.AbstractGradleProjectTask.*
class InitGradlePluginTaskTest extends AbstractTaskTester{
InitGradlePluginTaskTest(){
super( InitGradlePluginTask )
}
@Test void init(){
project.ext[PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[PROJECT_VERSION] = '1.1.1'
project.ext[PLUGIN_APPLY_LABEL] = 'test-foo'
project.ext[PLUGIN_CLASS_NAME] = 'com.test'
task.init()
assertFileExists folder.root, 'src/main/groovy'
assertFileExists folder.root, 'src/main/resources'
assertFileExists folder.root, 'src/test/groovy'
assertFileExists folder.root, 'src/test/resources'
assertFileExists folder.root, 'LICENSE.txt'
assertFileContains folder.root, 'build.gradle', 'group = \'test-group\''
assertFileContains folder.root, 'gradle.properties', 'version=1.1.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/groovy/CreateGroovyClassTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.groovy.CreateGroovyClassTask.NEW_CLASS_NAME
/**
* Created by cjstehno on 12/23/13.
*/
class CreateGroovyClassTaskTest extends AbstractTaskTester {
CreateGroovyClassTaskTest(){
super( CreateGroovyClassTask )
}
@Test void create(){
project.apply plugin:'groovy'
project.ext[NEW_CLASS_NAME] = 'foo.Something'
task.create()
assertFileContains folder.root, 'src/main/groovy/foo/Something.groovy', 'class Something'
}
}
================================================
FILE: src/test/groovy/templates/tasks/groovy/CreateGroovyProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.junit.Test
import templates.AbstractTaskTester
class CreateGroovyProjectTaskTest extends AbstractTaskTester {
CreateGroovyProjectTaskTest(){
super( CreateGroovyProjectTask )
}
@Test void create(){
project.ext[ CreateGroovyProjectTask.PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[ CreateGroovyProjectTask.NEW_PROJECT_NAME] = 'tester'
project.ext[ CreateGroovyProjectTask.PROJECT_GROUP] = 'test-group'
project.ext[ CreateGroovyProjectTask.PROJECT_VERSION] = '1.1.1'
task.create()
assertFileExists folder.root, 'tester/src/main/groovy'
assertFileExists folder.root, 'tester/src/main/resources'
assertFileExists folder.root, 'tester/src/test/groovy'
assertFileExists folder.root, 'tester/src/test/resources'
assertFileExists folder.root, 'tester/LICENSE.txt'
assertFileContains folder.root, 'tester/build.gradle', 'group = \'test-group\''
assertFileContains folder.root, 'tester/gradle.properties', 'version=1.1.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/groovy/ExportGroovyTemplatesTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.junit.Test
import templates.AbstractTaskTester
class ExportGroovyTemplatesTaskTest extends AbstractTaskTester {
ExportGroovyTemplatesTaskTest(){
super( ExportGroovyTemplatesTask )
}
@Test void export(){
task.export()
assertFileExists folder.root, 'templates/groovy/build.gradle.tmpl'
assertFileExists folder.root, 'templates/groovy/groovy-class.tmpl'
}
}
================================================
FILE: src/test/groovy/templates/tasks/groovy/InitGroovyProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.groovy
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.scala.AbstractScalaProjectTask.PROJECT_GROUP
class InitGroovyProjectTaskTest extends AbstractTaskTester {
InitGroovyProjectTaskTest(){
super( InitGroovyProjectTask )
}
@Test void init(){
project.ext[PROJECT_GROUP] = 'test-group'
task.init()
assertFileExists folder.root, 'src/main/groovy'
assertFileExists folder.root, 'src/main/resources'
assertFileExists folder.root, 'src/test/groovy'
assertFileExists folder.root, 'src/test/resources'
assertFileExists folder.root, 'LICENSE.txt'
assertFileContains folder.root, 'build.gradle', 'apply plugin: \'groovy\''
}
}
================================================
FILE: src/test/groovy/templates/tasks/java/CreateJavaClassTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.java.CreateJavaClassTask.NEW_CLASS_NAME
class CreateJavaClassTaskTest extends AbstractTaskTester {
CreateJavaClassTaskTest(){
super( CreateJavaClassTask )
}
@Test void create(){
project.apply plugin:'java'
project.ext[NEW_CLASS_NAME] = 'foo.Something'
task.create()
assertFileContains folder.root, 'src/main/java/foo/Something.java', 'class Something'
}
}
================================================
FILE: src/test/groovy/templates/tasks/java/CreateJavaProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.junit.Test
import templates.AbstractTaskTester
class CreateJavaProjectTaskTest extends AbstractTaskTester {
CreateJavaProjectTaskTest(){
super( CreateJavaProjectTask )
}
@Test void create(){
project.ext[CreateJavaProjectTask.PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[CreateJavaProjectTask.NEW_PROJECT_NAME] = 'tester'
project.ext[CreateJavaProjectTask.PROJECT_GROUP] = 'test-group'
project.ext[CreateJavaProjectTask.PROJECT_VERSION] = '1.1.1'
task.create()
assertFileExists folder.root, 'tester/src/main/java'
assertFileExists folder.root, 'tester/src/main/resources'
assertFileExists folder.root, 'tester/src/test/java'
assertFileExists folder.root, 'tester/src/test/resources'
assertFileExists folder.root, 'tester/LICENSE.txt'
assertFileContains folder.root, 'tester/build.gradle', 'group = \'test-group\''
assertFileContains folder.root, 'tester/gradle.properties', 'version=1.1.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/java/ExportJavaTemplatesTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.junit.Test
import templates.AbstractTaskTester
class ExportJavaTemplatesTaskTest extends AbstractTaskTester {
ExportJavaTemplatesTaskTest(){
super( ExportJavaTemplatesTask )
}
@Test void export(){
task.export()
assertFileExists folder.root, 'templates/java/build.gradle.tmpl'
assertFileExists folder.root, 'templates/java/java-class.tmpl'
}
}
================================================
FILE: src/test/groovy/templates/tasks/java/InitJavaProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.java
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.java.AbstractJavaProjectTask.PROJECT_GROUP
class InitJavaProjectTaskTest extends AbstractTaskTester {
InitJavaProjectTaskTest(){
super( InitJavaProjectTask )
}
@Test void init(){
project.ext[PROJECT_GROUP] = 'test-group'
task.init()
assertFileExists folder.root, 'src/main/java'
assertFileExists folder.root, 'src/main/resources'
assertFileExists folder.root, 'src/test/java'
assertFileExists folder.root, 'src/test/resources'
assertFileExists folder.root, 'LICENSE.txt'
assertFileContains folder.root, 'build.gradle', 'apply plugin: \'java\''
}
}
================================================
FILE: src/test/groovy/templates/tasks/scala/CreateScalaClassTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.scala.CreateScalaClassTask.NEW_CLASS_NAME
class CreateScalaClassTaskTest extends AbstractTaskTester {
CreateScalaClassTaskTest(){
super( CreateScalaClassTask )
}
@Test void create(){
project.apply plugin:'scala'
project.ext[NEW_CLASS_NAME] = 'foo.Something'
task.create()
assertFileContains folder.root, 'src/main/scala/foo/Something.scala', 'class Something'
}
}
================================================
FILE: src/test/groovy/templates/tasks/scala/CreateScalaObjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.scala.CreateScalaClassTask.NEW_CLASS_NAME
class CreateScalaObjectTaskTest extends AbstractTaskTester {
CreateScalaObjectTaskTest(){
super( CreateScalaObjectTask )
}
@Test void create(){
project.apply plugin:'scala'
project.ext[NEW_CLASS_NAME] = 'foo.Something'
task.create()
assertFileContains folder.root, 'src/main/scala/foo/Something.scala', 'object Something'
}
}
================================================
FILE: src/test/groovy/templates/tasks/scala/CreateScalaProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.scala.AbstractScalaProjectTask.NEW_PROJECT_NAME
import static templates.tasks.scala.AbstractScalaProjectTask.PROJECT_GROUP
import static templates.tasks.scala.AbstractScalaProjectTask.PROJECT_PARENT_DIR
import static templates.tasks.scala.AbstractScalaProjectTask.PROJECT_VERSION
import static templates.tasks.scala.AbstractScalaProjectTask.SCALA_VERSION
import static templates.tasks.scala.AbstractScalaProjectTask.USE_FAST_SCALA_COMPILER
class CreateScalaProjectTaskTest extends AbstractTaskTester {
CreateScalaProjectTaskTest(){
super( CreateScalaProjectTask )
}
@Test
void create(){
project.ext[PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[NEW_PROJECT_NAME] = 'tester'
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[PROJECT_VERSION] = '1.1.1'
project.ext[SCALA_VERSION] = '2.9.0'
project.ext[USE_FAST_SCALA_COMPILER] = true
task.create()
assertFileExists folder.root, 'tester/src/main/scala'
assertFileExists folder.root, 'tester/src/main/resources'
assertFileExists folder.root, 'tester/src/test/scala'
assertFileExists folder.root, 'tester/src/test/resources'
assertFileExists folder.root, 'tester/LICENSE.txt'
assertFileContains folder.root, 'tester/build.gradle', 'scalaVersion = \'2.9.0\'', 'scalaCompileOptions.useCompileDaemon = true', 'group = \'test-group\''
assertFileContains folder.root, 'tester/gradle.properties', 'version=1.1.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/scala/ExportScalaTemplatesTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.junit.Test
import templates.AbstractTaskTester
import templates.tasks.scala.ExportScalaTemplatesTask
class ExportScalaTemplatesTaskTest extends AbstractTaskTester {
ExportScalaTemplatesTaskTest(){
super( ExportScalaTemplatesTask )
}
@Test void export(){
task.export()
assertFileExists folder.root, 'templates/scala/build.gradle.tmpl'
assertFileExists folder.root, 'templates/scala/scala-class.tmpl'
}
}
================================================
FILE: src/test/groovy/templates/tasks/scala/InitScalaProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.scala
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.scala.AbstractScalaProjectTask.PROJECT_GROUP
import static templates.tasks.scala.AbstractScalaProjectTask.SCALA_VERSION
import static templates.tasks.scala.AbstractScalaProjectTask.USE_FAST_SCALA_COMPILER
class InitScalaProjectTaskTest extends AbstractTaskTester {
InitScalaProjectTaskTest(){
super( InitScalaProjectTask )
}
@Test void init(){
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[SCALA_VERSION] = '2.9.0'
project.ext[USE_FAST_SCALA_COMPILER] = true
task.init()
assertFileExists folder.root, 'src/main/scala'
assertFileExists folder.root, 'src/main/resources'
assertFileExists folder.root, 'src/test/scala'
assertFileExists folder.root, 'src/test/resources'
assertFileExists folder.root, 'LICENSE.txt'
assertFileContains folder.root, 'build.gradle', 'scalaVersion = \'2.9.0\'', 'scalaCompileOptions.useCompileDaemon = true', 'group = \'test-group\''
assertFileContains folder.root, 'gradle.properties', 'version=0.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/webapp/CreateWebappProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.webapp.AbstractWebappProjectTask.NEW_PROJECT_NAME
import static templates.tasks.webapp.AbstractWebappProjectTask.PROJECT_GROUP
import static templates.tasks.webapp.AbstractWebappProjectTask.PROJECT_PARENT_DIR
import static templates.tasks.webapp.AbstractWebappProjectTask.PROJECT_VERSION
import static templates.tasks.webapp.AbstractWebappProjectTask.USE_JETTY_PLUGIN
class CreateWebappProjectTaskTest extends AbstractTaskTester {
CreateWebappProjectTaskTest(){
super( CreateWebappProjectTask )
}
@Test void 'create: jetty'(){
project.ext[PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[NEW_PROJECT_NAME] = 'tester'
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[PROJECT_VERSION] = '1.1.1'
project.ext[USE_JETTY_PLUGIN] = 'y'
task.create()
assertFileExists folder.root, 'tester/src/main/java'
assertFileExists folder.root, 'tester/src/main/resources'
assertFileExists folder.root, 'tester/src/test/java'
assertFileExists folder.root, 'tester/src/test/resources'
assertFileExists folder.root, 'tester/LICENSE.txt'
assertFileContains folder.root, 'tester/build.gradle', 'group = \'test-group\'', 'apply plugin: \'jetty\''
assertFileContains folder.root, 'tester/gradle.properties', 'version=1.1.1'
}
@Test void 'create: war'(){
project.ext[PROJECT_PARENT_DIR] = folder.getRoot() as String
project.ext[NEW_PROJECT_NAME] = 'tester'
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[PROJECT_VERSION] = '1.1.1'
project.ext[USE_JETTY_PLUGIN] = 'n'
task.create()
assertFileExists folder.root, 'tester/src/main/java'
assertFileExists folder.root, 'tester/src/main/resources'
assertFileExists folder.root, 'tester/src/test/java'
assertFileExists folder.root, 'tester/src/test/resources'
assertFileExists folder.root, 'tester/LICENSE.txt'
assertFileContains folder.root, 'tester/build.gradle', 'group = \'test-group\'', 'apply plugin: \'war\''
assertFileContains folder.root, 'tester/gradle.properties', 'version=1.1.1'
}
}
================================================
FILE: src/test/groovy/templates/tasks/webapp/ExportWebappTemplatesTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import org.junit.Test
import templates.AbstractTaskTester
class ExportWebappTemplatesTaskTest extends AbstractTaskTester {
ExportWebappTemplatesTaskTest(){
super( ExportWebappTemplatesTask )
}
@Test void export(){
task.export()
assertFileExists folder.root, 'templates/webapp/build.gradle.tmpl'
assertFileExists folder.root, 'templates/webapp/web-xml.tmpl'
}
}
================================================
FILE: src/test/groovy/templates/tasks/webapp/InitWebappProjectTaskTest.groovy
================================================
/*
* Copyright (c) 2011,2012 Eric Berry
* Copyright (c) 2013 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package templates.tasks.webapp
import org.junit.Test
import templates.AbstractTaskTester
import static templates.tasks.webapp.AbstractWebappProjectTask.PROJECT_GROUP
import static templates.tasks.webapp.AbstractWebappProjectTask.USE_JETTY_PLUGIN
class InitWebappProjectTaskTest extends AbstractTaskTester {
InitWebappProjectTaskTest(){
super( InitWebappProjectTask )
}
@Test void 'init: jetty'(){
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[USE_JETTY_PLUGIN] = 'y'
task.init()
assertFileExists folder.root, 'src/main/java'
assertFileExists folder.root, 'src/main/resources'
assertFileExists folder.root, 'src/test/java'
assertFileExists folder.root, 'src/test/resources'
assertFileExists folder.root, 'LICENSE.txt'
assertFileContains folder.root, 'build.gradle', 'apply plugin: \'jetty\''
}
@Test void 'init: war'(){
project.ext[PROJECT_GROUP] = 'test-group'
project.ext[USE_JETTY_PLUGIN] = 'n'
task.init()
assertFileExists folder.root, 'src/main/java'
assertFileExists folder.root, 'src/main/resources'
assertFileExists folder.root, 'src/test/java'
assertFileExists folder.root, 'src/test/resources'
assertFileExists folder.root, 'LICENSE.txt'
assertFileContains folder.root, 'build.gradle', 'apply plugin: \'war\''
}
}