Search in sources :

Example 1 with RelativeFile

use of org.gradle.api.internal.file.RelativeFile in project gradle by gradle.

the class SerializableCoffeeScriptCompileSpec method toRelativeFiles.

public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
    FileTree fileTree = source.getAsFileTree();
    fileTree.visit(new FileVisitor() {

        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
        }
    });
}
Also used : FileVisitDetails(org.gradle.api.file.FileVisitDetails) RelativeFile(org.gradle.api.internal.file.RelativeFile) FileTree(org.gradle.api.file.FileTree) FileVisitor(org.gradle.api.file.FileVisitor)

Example 2 with RelativeFile

use of org.gradle.api.internal.file.RelativeFile in project gradle by gradle.

the class GoogleClosureCompiler method execute.

@Override
public WorkResult execute(JavaScriptCompileSpec spec) {
    JavaScriptCompileDestinationCalculator destinationCalculator = new JavaScriptCompileDestinationCalculator(spec.getDestinationDir());
    List<String> allErrors = Lists.newArrayList();
    for (RelativeFile sourceFile : spec.getSources()) {
        allErrors.addAll(compile(sourceFile, spec, destinationCalculator));
    }
    if (allErrors.isEmpty()) {
        return WorkResults.didWork(true);
    } else {
        throw new SourceTransformationException(String.format("Minification failed with the following errors:\n\t%s", StringUtils.join(allErrors, "\n\t")), null);
    }
}
Also used : RelativeFile(org.gradle.api.internal.file.RelativeFile) SourceTransformationException(org.gradle.plugins.javascript.base.SourceTransformationException)

Example 3 with RelativeFile

use of org.gradle.api.internal.file.RelativeFile in project gradle by gradle.

the class CoffeeScriptCompilerWorker method process.

public void process(SerializableCoffeeScriptCompileSpec spec) {
    Scriptable coffeeScriptScope = parse(spec.getCoffeeScriptJs(), "UTF-8", new Action<Context>() {

        public void execute(Context context) {
            context.setOptimizationLevel(-1);
        }
    });
    String encoding = spec.getOptions().getEncoding();
    CoffeeScriptCompileDestinationCalculator destinationCalculator = new CoffeeScriptCompileDestinationCalculator(spec.getDestinationDir());
    for (RelativeFile target : spec.getSource()) {
        String source = readFile(target.getFile(), encoding);
        String output = compile(coffeeScriptScope, source, target.getRelativePath().getPathString());
        writeFile(output, destinationCalculator.transform(target.getRelativePath()), encoding);
    }
}
Also used : Context(org.mozilla.javascript.Context) CoffeeScriptCompileDestinationCalculator(org.gradle.plugins.javascript.coffeescript.compile.internal.CoffeeScriptCompileDestinationCalculator) RelativeFile(org.gradle.api.internal.file.RelativeFile) Scriptable(org.mozilla.javascript.Scriptable)

Example 4 with RelativeFile

use of org.gradle.api.internal.file.RelativeFile 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

RelativeFile (org.gradle.api.internal.file.RelativeFile)4 File (java.io.File)1 FileTree (org.gradle.api.file.FileTree)1 FileVisitDetails (org.gradle.api.file.FileVisitDetails)1 FileVisitor (org.gradle.api.file.FileVisitor)1 TwirlTemplateFormat (org.gradle.language.twirl.TwirlTemplateFormat)1 SourceTransformationException (org.gradle.plugins.javascript.base.SourceTransformationException)1 CoffeeScriptCompileDestinationCalculator (org.gradle.plugins.javascript.coffeescript.compile.internal.CoffeeScriptCompileDestinationCalculator)1 ScalaMethod (org.gradle.scala.internal.reflect.ScalaMethod)1 ScalaOptionInvocationWrapper (org.gradle.scala.internal.reflect.ScalaOptionInvocationWrapper)1 Context (org.mozilla.javascript.Context)1 Scriptable (org.mozilla.javascript.Scriptable)1