use of org.gradle.language.twirl.TwirlTemplateFormat in project gradle by gradle.
the class TwirlCompiler method findTemplateFormat.
private TwirlTemplateFormat findTemplateFormat(TwirlCompileSpec spec, final File sourceFile) {
Spec<TwirlTemplateFormat> hasExtension = new Spec<TwirlTemplateFormat>() {
@Override
public boolean isSatisfiedBy(TwirlTemplateFormat format) {
return FileUtils.hasExtensionIgnoresCase(sourceFile.getName(), "." + format.getExtension());
}
};
TwirlTemplateFormat format = CollectionUtils.findFirst(adapter.getDefaultTemplateFormats(), hasExtension);
if (format == null) {
format = CollectionUtils.findFirst(spec.getUserTemplateFormats(), hasExtension);
}
Preconditions.checkNotNull(format, "Twirl compiler could not find a matching template for '%s'.", sourceFile.getName());
return format;
}
use of org.gradle.language.twirl.TwirlTemplateFormat 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());
}
Aggregations