Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.gradle.playframework.sourcesets.TwirlSourceSet;
import org.gradle.playframework.sourcesets.internal.DefaultTwirlSourceSet;
import org.gradle.playframework.tasks.TwirlCompile;
import org.gradle.playframework.tasks.TwirlCompileExt;
import org.gradle.playframework.tools.internal.twirl.TwirlCompilerFactory;
import org.gradle.util.GradleVersion;

import java.util.List;

Expand Down Expand Up @@ -56,7 +58,13 @@ private void declareDefaultDependencies(Project project, Configuration configura
}

private TaskProvider<TwirlCompile> createDefaultTwirlCompileTask(Project project, TwirlSourceSet twirlSourceSet, Configuration compilerConfiguration, PlayExtension playExtension) {
return project.getTasks().register(TWIRL_COMPILE_TASK_NAME, TwirlCompile.class, twirlCompile -> {
Class<? extends TwirlCompile> type;
if (GradleVersion.current().compareTo(GradleVersion.version("6.7")) < 0) {
type = TwirlCompile.class;
} else {
type = TwirlCompileExt.class;
}
return project.getTasks().register(TWIRL_COMPILE_TASK_NAME, (Class<TwirlCompile>) type, twirlCompile -> {
twirlCompile.setDescription("Compiles Twirl templates for the '" + twirlSourceSet.getTwirl().getDisplayName() + "' source set.");
twirlCompile.getPlatform().set(project.provider(() -> playExtension.getPlatform()));
twirlCompile.setSource(twirlSourceSet.getTwirl());
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/org/gradle/playframework/tasks/TwirlCompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.gradle.api.Action;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.FileVisitDetails;
Expand Down Expand Up @@ -111,6 +110,10 @@ public ConfigurableFileCollection getTwirlCompilerClasspath() {
return twirlCompilerClasspath;
}

protected String executable() {
return null;
}

@TaskAction
@SuppressWarnings("Convert2Lambda")
void compile() {
Expand All @@ -121,7 +124,13 @@ void compile() {
if (GradleVersion.current().compareTo(GradleVersion.version("5.6")) < 0) {
workerExecutor.submit(TwirlCompileRunnable.class, workerConfiguration -> {
workerConfiguration.setIsolationMode(IsolationMode.PROCESS);
workerConfiguration.forkOptions(options -> options.jvmArgs("-XX:MaxMetaspaceSize=256m"));
workerConfiguration.forkOptions(options -> {
options.jvmArgs("-XX:MaxMetaspaceSize=256m");
String executable = executable();
if (executable != null) {
options.setExecutable(executable);
}
});
workerConfiguration.params(spec, getCompiler());
workerConfiguration.classpath(twirlCompilerClasspath);
workerConfiguration.setDisplayName("Generating Scala source from Twirl templates");
Expand All @@ -130,7 +139,13 @@ void compile() {
WorkQueue workQueue = workerExecutor.processIsolation(new Action<ProcessWorkerSpec>() {
@Override
public void execute(ProcessWorkerSpec workerSpec) {
workerSpec.forkOptions(options -> options.jvmArgs("-XX:MaxMetaspaceSize=256m"));
workerSpec.forkOptions(options -> {
options.jvmArgs("-XX:MaxMetaspaceSize=256m");
String executable = executable();
if (executable != null) {
options.setExecutable(executable);
}
});
workerSpec.getClasspath().from(twirlCompilerClasspath);
}
});
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/gradle/playframework/tasks/TwirlCompileExt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.gradle.playframework.tasks;

import org.gradle.api.Incubating;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Internal;
import org.gradle.jvm.toolchain.JavaLauncher;
import org.gradle.workers.WorkerExecutor;

import javax.inject.Inject;

public class TwirlCompileExt extends TwirlCompile {
@Inject
public TwirlCompileExt(WorkerExecutor workerExecutor) {
super(workerExecutor);
this.javaLauncher = getProject().getObjects().property(JavaLauncher.class);
}

private final Property<JavaLauncher> javaLauncher;

/**
* The toolchain {@link JavaLauncher} to use for executing the twirl template compiler.
*
* @return the java launcher property
*/
@Internal
@Incubating
public Property<JavaLauncher> getJavaLauncher() {
return this.javaLauncher;
}

@Override
protected String executable() {
return getJavaLauncher().map(launcher -> launcher.getExecutablePath().getAsFile().getAbsolutePath()).getOrNull();
}
}