forked from grails/grails-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Forked GSP Compiler on Gradle to work similar to grails-v…
…iews (grails#11582) * Implemented Forked GSP Compiler on Gradle to work similar to grails-views * fixed versions and updated javadoc * whoops, reverting change to request mock
- Loading branch information
1 parent
c039fbc
commit c191ac6
Showing
3 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
src/main/groovy/org/grails/gradle/plugin/web/gsp/GroovyPageForkCompileTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.grails.gradle.plugin.web.gsp | ||
|
||
import grails.io.ResourceUtils | ||
import groovy.transform.CompileDynamic | ||
import groovy.transform.CompileStatic | ||
import org.codehaus.groovy.tools.shell.util.PackageHelper | ||
import org.gradle.api.Action | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.Nested | ||
import org.gradle.api.tasks.Optional | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.tasks.compile.AbstractCompile | ||
import org.gradle.api.tasks.incremental.IncrementalTaskInputs | ||
import org.gradle.process.ExecResult | ||
import org.gradle.process.JavaExecSpec | ||
|
||
/** | ||
* Abstract Gradle task for compiling templates, using GroovyPageCompilerForkTask | ||
* This Task is a Forked Java Task that is configurable with fork options provided | ||
* by {@link GspCompileOptions} | ||
* | ||
* @author David Estes | ||
* @since 4.0 | ||
*/ | ||
@CompileStatic | ||
class GroovyPageForkCompileTask extends AbstractCompile { | ||
|
||
@Input | ||
@Optional | ||
String packageName | ||
|
||
@InputDirectory | ||
File srcDir | ||
|
||
@Input | ||
File tmpDir | ||
|
||
@Input | ||
@Optional | ||
String serverpath | ||
|
||
@Nested | ||
GspCompileOptions compileOptions = new GspCompileOptions() | ||
|
||
@Override | ||
void setSource(Object source) { | ||
try { | ||
srcDir = project.file(source) | ||
if(srcDir.exists() && !srcDir.isDirectory()) { | ||
throw new IllegalArgumentException("The source for GSP compilation must be a single directory, but was $source") | ||
} | ||
super.setSource(source) | ||
} catch (e) { | ||
throw new IllegalArgumentException("The source for GSP compilation must be a single directory, but was $source") | ||
} | ||
} | ||
|
||
@TaskAction | ||
void execute(IncrementalTaskInputs inputs) { | ||
compile() | ||
} | ||
|
||
protected void compile() { | ||
|
||
if(packageName == null) { | ||
packageName = project.name | ||
if(!packageName) { | ||
packageName = project.projectDir.canonicalFile.name | ||
} | ||
} | ||
|
||
ExecResult result = project.javaexec( | ||
new Action<JavaExecSpec>() { | ||
@Override | ||
@CompileDynamic | ||
void execute(JavaExecSpec javaExecSpec) { | ||
javaExecSpec.setMain(getCompilerName()) | ||
javaExecSpec.setClasspath(getClasspath()) | ||
|
||
def jvmArgs = compileOptions.forkOptions.jvmArgs | ||
if(jvmArgs) { | ||
javaExecSpec.jvmArgs(jvmArgs) | ||
} | ||
javaExecSpec.setMaxHeapSize( compileOptions.forkOptions.memoryMaximumSize ) | ||
javaExecSpec.setMinHeapSize( compileOptions.forkOptions.memoryInitialSize ) | ||
|
||
|
||
def arguments = [ | ||
srcDir.canonicalPath, | ||
destinationDir.canonicalPath, | ||
tmpDir.canonicalPath, | ||
targetCompatibility, | ||
packageName, | ||
serverpath, | ||
project.file("grails-app/conf/application.yml").canonicalPath, | ||
compileOptions.encoding | ||
] | ||
|
||
prepareArguments(arguments) | ||
javaExecSpec.args(arguments) | ||
} | ||
|
||
} | ||
) | ||
result.assertNormalExitValue() | ||
|
||
} | ||
|
||
void prepareArguments(List<String> arguments) { | ||
// no-op | ||
} | ||
|
||
protected String getCompilerName() { | ||
"org.grails.web.pages.GroovyPageCompilerForkTask" | ||
} | ||
|
||
|
||
String getFileExtension() { | ||
"gsp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/groovy/org/grails/gradle/plugin/web/gsp/GspCompileOptions.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.grails.gradle.plugin.web.gsp | ||
|
||
import org.gradle.api.tasks.compile.GroovyForkOptions | ||
|
||
/** | ||
* Presents the Compile Options used by the {@llink GroovyPageForkCompileTask} | ||
* | ||
* @author David Estes | ||
* @since 4.0 | ||
*/ | ||
class GspCompileOptions { | ||
String encoding = "UTF-8" | ||
GroovyForkOptions forkOptions = new GroovyForkOptions() | ||
} |