Search in sources :

Example 1 with ScalaOptionInvocationWrapper

use of org.gradle.scala.internal.reflect.ScalaOptionInvocationWrapper in project gradle by gradle.

the class TwirlCompiler method execute.

@Override
public WorkResult execute(TwirlCompileSpec spec) {
    List<File> outputFiles = Lists.newArrayList();
    ClassLoader cl = getClass().getClassLoader();
    ScalaMethod compile = getCompileMethod(cl);
    Iterable<RelativeFile> sources = spec.getSources();
    for (RelativeFile sourceFile : sources) {
        TwirlTemplateFormat format = findTemplateFormat(spec, sourceFile.getFile());
        try {
            Object result = compile.invoke(buildCompileArguments(spec, cl, sourceFile, format));
            ScalaOptionInvocationWrapper<File> maybeFile = new ScalaOptionInvocationWrapper<File>(result);
            if (maybeFile.isDefined()) {
                File outputFile = maybeFile.get();
                outputFiles.add(outputFile);
            }
        } catch (Exception e) {
            throw new RuntimeException("Error invoking Play Twirl template compiler.", e);
        }
    }
    return WorkResults.didWork(!outputFiles.isEmpty());
}
Also used : RelativeFile(org.gradle.api.internal.file.RelativeFile) ScalaMethod(org.gradle.scala.internal.reflect.ScalaMethod) ScalaOptionInvocationWrapper(org.gradle.scala.internal.reflect.ScalaOptionInvocationWrapper) RelativeFile(org.gradle.api.internal.file.RelativeFile) File(java.io.File) TwirlTemplateFormat(org.gradle.language.twirl.TwirlTemplateFormat)

Aggregations

File (java.io.File)1 RelativeFile (org.gradle.api.internal.file.RelativeFile)1 TwirlTemplateFormat (org.gradle.language.twirl.TwirlTemplateFormat)1 ScalaMethod (org.gradle.scala.internal.reflect.ScalaMethod)1 ScalaOptionInvocationWrapper (org.gradle.scala.internal.reflect.ScalaOptionInvocationWrapper)1