diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy index 32e35f6c8..42fcefe66 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy @@ -38,11 +38,23 @@ abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile { @Nested final ViewCompileOptions compileOptions + @Input + final Property fileExtension + + @Input + final Property scriptBaseName + + @Input + final Property compilerName + @Inject AbstractGroovyTemplateCompileTask(ObjectFactory objectFactory) { - packageName = objectFactory.property(String) + packageName = objectFactory.property(String).convention(project.name ?: project.projectDir.canonicalFile.name) srcDir = objectFactory.directoryProperty() compileOptions = new ViewCompileOptions(objectFactory) + fileExtension = objectFactory.property(String) + scriptBaseName = objectFactory.property(String) + compilerName = objectFactory.property(String) } @Override @@ -62,16 +74,18 @@ abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile { protected void compile() { Iterable projectPackageNames = getProjectPackageNames(project.projectDir) +/* if (packageName.isPresent()) { packageName.set(project.name ?: project.projectDir.canonicalFile.name) } +*/ ExecResult result = project.javaexec( new Action() { @Override @CompileDynamic void execute(JavaExecSpec javaExecSpec) { - javaExecSpec.mainClass.set(getCompilerName()) - javaExecSpec.classpath = getClasspath() + javaExecSpec.mainClass.set(compilerName) + javaExecSpec.classpath = classpath List jvmArgs = compileOptions.forkOptions.jvmArgs if (jvmArgs) { @@ -88,7 +102,7 @@ abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile { packageImports, packageName.get(), project.file('grails-app/conf/application.yml').canonicalPath, - compileOptions.encoding + compileOptions.encoding.get() ] as List prepareArguments(arguments) @@ -103,17 +117,6 @@ abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile { // no-op } - @Input - protected String getCompilerName() { - 'grails.views.GenericGroovyTemplateCompiler' - } - - @Input - abstract String getFileExtension() - - @Input - abstract String getScriptBaseName() - Iterable getProjectPackageNames(File baseDir) { File rootDir = baseDir ? new File(baseDir, "grails-app${File.separator}domain") : null Set packageNames = [] diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy index 880b33477..911d622f6 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy @@ -7,8 +7,10 @@ import org.apache.tools.ant.taskdefs.condition.Os import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileCollection import org.gradle.api.tasks.SourceSetOutput +import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.bundling.Jar import org.grails.gradle.plugin.core.GrailsExtension import org.grails.gradle.plugin.core.IntegrationTestGradlePlugin @@ -32,7 +34,7 @@ class AbstractGroovyTemplatePlugin implements Plugin { AbstractGroovyTemplatePlugin(Class taskClass, String fileExtension) { this.taskClass = taskClass this.fileExtension = fileExtension - this.pathToSource = "grails-app/views" + this.pathToSource = 'grails-app/views' } AbstractGroovyTemplatePlugin(Class taskClass, String fileExtension, String pathToSource) { @@ -43,43 +45,58 @@ class AbstractGroovyTemplatePlugin implements Plugin { @Override void apply(Project project) { - def allTasks = project.tasks - def upperCaseName = GrailsNameUtils.getClassName(fileExtension) - AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask) allTasks.register("compile${upperCaseName}Views".toString(), (Class) taskClass).get() + TaskContainer tasks = project.tasks + String upperCaseName = GrailsNameUtils.getClassName(fileExtension) + AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask) tasks.register( + "compile${upperCaseName}Views".toString(), + (Class) taskClass + ).get() SourceSetOutput output = SourceSets.findMainSourceSet(project)?.output FileCollection classesDir = resolveClassesDirs(output, project) - File destDir = new File(project.buildDir, "${templateCompileTask.fileExtension}-classes/main") + File destDir = new File(project.layout.buildDirectory.get().asFile, "${templateCompileTask.fileExtension}-classes/main") output?.dir(destDir) project.afterEvaluate { GrailsExtension grailsExt = project.extensions.getByType(GrailsExtension) if (grailsExt.pathingJar && Os.isFamily(Os.FAMILY_WINDOWS)) { - Jar pathingJar = (Jar) allTasks.named('pathingJar').get() - def allClasspath = project.files("${project.buildDir}/classes/groovy/main", "${project.buildDir}/resources/main", "${project.projectDir}/gsp-classes", pathingJar.archiveFile.get().asFile) + Jar pathingJar = (Jar) tasks.named('pathingJar').get() + ConfigurableFileCollection allClasspath = project.files( + "${project.layout.buildDirectory.get().asFile}/classes/groovy/main", + "${project.layout.buildDirectory.get().asFile}/resources/main", + "${project.layout.projectDirectory.getAsFile()}/gsp-classes", + pathingJar.archiveFile.get().asFile + ) templateCompileTask.dependsOn(pathingJar) templateCompileTask.classpath = allClasspath } } def allClasspath = classesDir + project.configurations.named('compileClasspath').get() - templateCompileTask.getDestinationDirectory().set( destDir ) + templateCompileTask.destinationDirectory.set(destDir) templateCompileTask.classpath = allClasspath templateCompileTask.packageName.set(project.name) templateCompileTask.setSource(project.file("${project.projectDir}/$pathToSource")) - templateCompileTask.dependsOn( allTasks.named('classes').get() ) + templateCompileTask.dependsOn(tasks.named('classes').get()) project.plugins.withType(SpringBootPlugin).configureEach {plugin -> - allTasks.withType(Jar).configureEach { Task task -> - if (task.name in ['jar', 'bootJar', 'war', 'bootWar']) { task.dependsOn templateCompileTask } + tasks.withType(Jar).configureEach { Task task -> + if (task.name in ['jar', 'bootJar', 'war', 'bootWar']) { + task.dependsOn(templateCompileTask) + } + } + tasks.withType(ResolveMainClassName).configureEach { + it.dependsOn(templateCompileTask) } - allTasks.withType(ResolveMainClassName).configureEach { t -> t.dependsOn(templateCompileTask)} } - project.plugins.withType(IntegrationTestGradlePlugin).configureEach { plugin -> - allTasks.named("compileIntegrationTestGroovy") { t-> t.dependsOn(templateCompileTask)} - allTasks.named("integrationTest") {t -> t.dependsOn(templateCompileTask)} + project.plugins.withType(IntegrationTestGradlePlugin).configureEach { + tasks.named('compileIntegrationTestGroovy') { Task task -> + task.dependsOn(templateCompileTask) + } + tasks.named('integrationTest') { Task task -> + task.dependsOn(templateCompileTask) + } } } @CompileDynamic protected FileCollection resolveClassesDirs(SourceSetOutput output, Project project) { - return output.classesDirs ?: project.files(new File(project.buildDir, "classes/groovy/main")) + return output.classesDirs ?: project.files(new File(project.layout.buildDirectory.get().asFile, 'classes/groovy/main')) } - } diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/ViewCompileOptions.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/ViewCompileOptions.groovy index 8175bd1af..056840f7b 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/ViewCompileOptions.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/ViewCompileOptions.groovy @@ -5,7 +5,7 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.Nested import org.gradle.api.tasks.compile.GroovyForkOptions -import javax.inject.Inject; +import javax.inject.Inject /** * @author Graeme Rocher diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/json/GrailsJsonViewsPlugin.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/json/GrailsJsonViewsPlugin.groovy index d577f0869..7d0248b58 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/json/GrailsJsonViewsPlugin.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/json/GrailsJsonViewsPlugin.groovy @@ -13,7 +13,7 @@ import groovy.transform.CompileStatic class GrailsJsonViewsPlugin extends AbstractGroovyTemplatePlugin { GrailsJsonViewsPlugin() { - super(JsonViewCompilerTask, "gson") + super(JsonViewCompilerTask, 'gson') } } diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/json/JsonViewCompilerTask.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/json/JsonViewCompilerTask.groovy index 318159bc1..485d9ef2a 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/json/JsonViewCompilerTask.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/json/JsonViewCompilerTask.groovy @@ -2,8 +2,12 @@ package grails.views.gradle.json import grails.views.gradle.AbstractGroovyTemplateCompileTask import groovy.transform.CompileStatic +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property import org.gradle.api.tasks.Input +import javax.inject.Inject + /** * Concrete implementation that compiles JSON templates * @@ -12,22 +16,11 @@ import org.gradle.api.tasks.Input @CompileStatic class JsonViewCompilerTask extends AbstractGroovyTemplateCompileTask { - @Input - @Override - String getFileExtension() { - "gson" - } - - @Input - @Override - String getScriptBaseName() { - "grails.plugin.json.view.JsonViewTemplate" + @Inject + JsonViewCompilerTask(ObjectFactory objectFactory) { + super(objectFactory) + fileExtension.convention('gson') + scriptBaseName.convention('grails.plugin.json.view.JsonViewTemplate') + compilerName.convention('grails.plugin.json.view.JsonViewCompiler') } - - @Input - @Override - protected String getCompilerName() { - "grails.plugin.json.view.JsonViewCompiler" - } - } diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/markup/GrailsMarkupViewsPlugin.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/markup/GrailsMarkupViewsPlugin.groovy index baf6eede3..2d0a1f9a7 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/markup/GrailsMarkupViewsPlugin.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/markup/GrailsMarkupViewsPlugin.groovy @@ -13,6 +13,6 @@ import groovy.transform.CompileStatic class GrailsMarkupViewsPlugin extends AbstractGroovyTemplatePlugin { GrailsMarkupViewsPlugin() { - super(MarkupViewCompilerTask, "gml") + super(MarkupViewCompilerTask, 'gml') } } diff --git a/gradle-plugin/src/main/groovy/grails/views/gradle/markup/MarkupViewCompilerTask.groovy b/gradle-plugin/src/main/groovy/grails/views/gradle/markup/MarkupViewCompilerTask.groovy index 27bf8b598..fe379727f 100644 --- a/gradle-plugin/src/main/groovy/grails/views/gradle/markup/MarkupViewCompilerTask.groovy +++ b/gradle-plugin/src/main/groovy/grails/views/gradle/markup/MarkupViewCompilerTask.groovy @@ -2,6 +2,8 @@ package grails.views.gradle.markup import grails.views.gradle.AbstractGroovyTemplateCompileTask import groovy.transform.CompileStatic +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property import org.gradle.api.tasks.Input /** @@ -14,21 +16,18 @@ import org.gradle.api.tasks.Input class MarkupViewCompilerTask extends AbstractGroovyTemplateCompileTask { @Input - @Override - String getFileExtension() { - "gml" - } + final Property fileExtension @Input - @Override - String getScriptBaseName() { - "grails.plugin.markup.view.MarkupViewTemplate" - } + final Property scriptBaseName @Input - @Override - protected String getCompilerName() { - "grails.plugin.markup.view.MarkupViewCompiler" - } + final Property compilerName + MarkupViewCompilerTask(ObjectFactory objectFactory) { + super(objectFactory) + fileExtension.convention('gml') + scriptBaseName.convention('grails.plugin.markup.view.MarkupViewTemplate') + compilerName.convention('grails.plugin.markup.view.MarkupViewCompiler') + } }