Skip to content

Commit

Permalink
[Gradle] Use real Twirl compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage committed Aug 30, 2023
1 parent 6841817 commit ce8646d
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,50 @@
*/
package play.twirl.gradle.internal;

import java.io.File;
import java.util.Collection;
import java.util.List;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.workers.WorkAction;
import play.japi.twirl.compiler.TwirlCompiler;
import scala.io.Codec;

public abstract class TwirlCompileAction implements WorkAction<TwirlCompileParams> {

private static final Logger LOGGER = Logging.getLogger(TwirlCompileAction.class);

@Override
public void execute() {
try {
System.out.println(
"Compile Twirl template "
+ getParameters().getSourceFile().getAsFile().get().getName()
+ " into "
+ getParameters().getDestinationDirectory().getAsFile().get().getCanonicalPath());
File sourceFile = getParameters().getSourceFile().getAsFile().get();
File sourceDirectory = getParameters().getSourceDirectory().getAsFile().get();
File destinationDirectory = getParameters().getDestinationDirectory().getAsFile().get();
String formatterType = getParameters().getFormatterType().get();
getParameters().getTemplateImports().addAll(TwirlCompiler.DEFAULT_IMPORTS);
Collection<String> imports = getParameters().getTemplateImports().get();
List<String> constructorAnnotations = getParameters().getConstructorAnnotations().get();
String sourceEncoding = getParameters().getSourceEncoding().get();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Compile Twirl template [{}/{}] {} from {} into {}",
formatterType,
sourceEncoding,
sourceFile.getName(),
sourceDirectory.getCanonicalPath(),
destinationDirectory.getCanonicalPath());
}
TwirlCompiler.compile(
sourceFile,
sourceDirectory,
destinationDirectory,
formatterType,
imports,
constructorAnnotations,
Codec.string2codec(sourceEncoding),
false);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit ce8646d

Please sign in to comment.