Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gradle] Add javadoc comments #674

Merged
merged 1 commit into from
Sep 8, 2023
Merged
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 @@ -26,6 +26,7 @@
import org.gradle.workers.WorkerExecutor;
import play.twirl.gradle.internal.TwirlCompileAction;

/** Gradle task for compiling Twirl templates into Scala code. */
public abstract class TwirlCompile extends SourceTask {

@InputFiles
Expand Down
13 changes: 13 additions & 0 deletions gradle-twirl/src/main/java/play/twirl/gradle/TwirlExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@

import org.gradle.api.provider.Property;

/**
* The extension of the plugin allowing for configuring the target Scala version used for the
* application.
*/
public abstract class TwirlExtension {

/**
* Scala version used for compilation Twirl templates.
*
* <pre>{@code
* twirl {
* scalaVersion.set("3")
* }
* }</pre>
*/
public abstract Property<String> getScalaVersion();
}
27 changes: 13 additions & 14 deletions gradle-twirl/src/main/java/play/twirl/gradle/TwirlPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import play.twirl.gradle.internal.DefaultTwirlSourceDirectorySet;
import play.twirl.gradle.internal.Gradle7TwirlSourceDirectorySet;

/** A simple 'hello world' plugin. */
/** A Gradle plugin to compile Twirl templates. */
public class TwirlPlugin implements Plugin<Project> {

static final String DEFAULT_SCALA_VERSION = "2.13";
Expand Down Expand Up @@ -58,7 +58,7 @@ public void apply(final Project project) {
configureSourceSetDefaults(project, twirlConfiguration);
}

/** Get Twirl version from Gradle Plugin MANIFEST.MF */
/** Get Twirl compiler version from Gradle Plugin MANIFEST.MF */
private String getDefaultTwirlVersion() {
return System.getProperty("twirl.version", getClass().getPackage().getImplementationVersion());
}
Expand Down Expand Up @@ -140,25 +140,24 @@ private TaskProvider<TwirlCompile> createTwirlCompileTask(
});
}

@SuppressWarnings("deprecation")
private TwirlSourceDirectorySet getTwirlSourceDirectorySet(SourceSet sourceSet) {
String displayName = ((DefaultSourceSet) sourceSet).getDisplayName();
TwirlSourceDirectorySet twirlSourceDirectorySet;
if (GradleVersion.current().compareTo(GradleVersion.version("8.0")) < 0) { // Gradle < 8.0
twirlSourceDirectorySet =
objectFactory.newInstance(
Gradle7TwirlSourceDirectorySet.class,
objectFactory.sourceDirectorySet("twirl", displayName + " Twirl source"));
} else { // Gradle 8+
twirlSourceDirectorySet =
objectFactory.newInstance(
DefaultTwirlSourceDirectorySet.class,
objectFactory.sourceDirectorySet("twirl", displayName + " Twirl source"));
}
TwirlSourceDirectorySet twirlSourceDirectorySet =
objectFactory.newInstance(
isGradleVersionLessThan("8.0")
? Gradle7TwirlSourceDirectorySet.class
: DefaultTwirlSourceDirectorySet.class,
objectFactory.sourceDirectorySet("twirl", displayName + " Twirl source"));
twirlSourceDirectorySet.getFilter().include("**/*.scala.*");
twirlSourceDirectorySet.getTemplateFormats().convention(DEFAULT_TEMPLATE_FORMATS);
return twirlSourceDirectorySet;
}

static boolean isGradleVersionLessThan(String gradleVersion) {
return GradleVersion.current().compareTo(GradleVersion.version(gradleVersion)) < 0;
}

static JavaPluginExtension javaPluginExtension(Project project) {
return extensionOf(project, JavaPluginExtension.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,63 @@
*/
public interface TwirlSourceDirectorySet extends SourceDirectorySet {

/**
* Custom template formats configured for this source directory set.
*
* <pre>{@code
* sourceSets {
* main {
* twirl {
* templateFormats.put("csv", "play.twirl.api.TxtFormat")
* }
* }
* }
* }</pre>
*/
MapProperty<String, String> getTemplateFormats();

/**
* Imports that should be added to generated source files.
*
* <pre>{@code
* sourceSets {
* main {
* twirl {
* templateImports.add("org.example._")
* }
* }
* }
* }</pre>
*/
SetProperty<String> getTemplateImports();

/**
* Annotations added to constructors in injectable templates.
*
* <pre>{@code
* sourceSets {
* main {
* twirl {
* constructorAnnotations.add("@org.example.MyAnnotation()")
* }
* }
* }
* }</pre>
*/
ListProperty<String> getConstructorAnnotations();

/**
* Source encoding for template files and generated scala files.
*
* <pre>{@code
* sourceSets {
* main {
* twirl {
* sourceEncoding.set("<enc>")
* }
* }
* }
* }</pre>
*/
Property<String> getSourceEncoding();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.gradle.api.provider.SetProperty;
import play.twirl.gradle.TwirlSourceDirectorySet;

/** Default implementation of {@link TwirlSourceDirectorySet}. */
public class DefaultTwirlSourceDirectorySet extends DefaultSourceDirectorySet
implements TwirlSourceDirectorySet {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
import javax.inject.Inject;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.model.ObjectFactory;
import play.twirl.gradle.TwirlSourceDirectorySet;

/**
* Implementation of {@link TwirlSourceDirectorySet} is needed to support Gradle 7.
*
* @deprecated
*/
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public class Gradle7TwirlSourceDirectorySet extends DefaultTwirlSourceDirectorySet {

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import play.japi.twirl.compiler.TwirlCompiler;
import scala.io.Codec;

/** Gradle work action that compile one Twirl template. */
public abstract class TwirlCompileAction implements WorkAction<TwirlCompileParams> {

private static final Logger LOGGER = Logging.getLogger(TwirlCompileAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.gradle.api.provider.SetProperty;
import org.gradle.workers.WorkParameters;

/** Parameters of compilation work action. */
public interface TwirlCompileParams extends WorkParameters {

RegularFileProperty getSourceFile();
Expand Down
Loading