/* forked from https://github.com/gli/closure-compiler-maven-plugin/blob/34c2d4395db1b88e606e06bb19e9a6e6cdf9d9f0/src/main/java/glisoft/ClosureCompilerMojo.java */

package org.spiffyui.maven.plugins;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.javascript.jscomp.CompilationLevel;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.JSError;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.Result;

/**
 * Goal which executes the Google closure compiler against .js codee
 * 
 * @goal closure
 * 
 * @phase compile
 */
public class ClosureMojo extends AbstractMojo
{
    /**
     * @parameter expression="SIMPLE_OPTIMIZATIONS"
     * @required
     */
    private String compilationLevel;

    /**
     * @parameter expression="src/main/js"
     * @required
     */
    private File sourceDirectory;

    /**
     * @parameter expression=
     *            "${project.build.directory}/${project.build.finalName}/${project.artifactId}-min.js"
     * @required
     */
    private File outputFile;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        CompilationLevel compilationLevel = null;
        try {
            compilationLevel = CompilationLevel.valueOf(this.compilationLevel);
        } catch (IllegalArgumentException e) {
            throw new MojoFailureException("Compilation level invalid" + e.getMessage());
        }

        CompilerOptions compilerOptions = new CompilerOptions();
        compilationLevel.setOptionsForCompilationLevel(compilerOptions);

        Compiler compiler = new Compiler();
        Result result = compiler.compile(new ArrayList<JSSourceFile>(), listJSSourceFiles(sourceDirectory), compilerOptions);

        for (JSError warning : result.warnings) {
            getLog().warn(warning.toString());
        }

        for (JSError error : result.errors) {
            getLog().error(error.toString());
        }

        if (!result.success) {
            throw new MojoFailureException("Compilation failure");
        }

        try {
            Files.createParentDirs(outputFile);
            Files.touch(outputFile);
            Files.write(compiler.toSource(), outputFile, Charsets.UTF_8);
        } catch (IOException e) {
            throw new MojoFailureException(outputFile != null ? outputFile.toString() : e.getMessage());
        }
    }

    private List<JSSourceFile> listJSSourceFiles(File directory) {
        return listJSSourceFiles(new ArrayList<JSSourceFile>(), directory);
    }

    private List<JSSourceFile> listJSSourceFiles(List<JSSourceFile> jsSourceFiles, File directory) {
        if (directory != null) {
            File[] files = directory.listFiles();
            if (files != null) {
                for (File file : directory.listFiles()) {
                    if (file.isFile()) {
                        if (file.getName().endsWith(".js")) {
                            jsSourceFiles.add(JSSourceFile.fromFile(file));
                        }
                    } else {
                        listJSSourceFiles(jsSourceFiles, file);
                    }
                }
            }
        }
        return jsSourceFiles;
    }

}

@@ -294,16 +294,45 @@
 il.List;
+%0Aimport java.util.Properties;
 %0A%0Aimport
@@ -477,16 +477,62 @@
 ception;
+%0Aimport org.apache.maven.project.MavenProject;
 %0A%0Aimport
@@ -1061,32 +1061,211 @@
 tMojo%0A%7B%0A    /**%0A
+     * %7B@link MavenProject%7D to process.%0A     * %0A     * @parameter expression=%22$%7Bproject%7D%22%0A     * @required%0A     * @readonly%0A     */%0A    private MavenProject project;%0A    %0A    /**%0A
      * @paramete
@@ -2187,32 +2187,429 @@
 mpilerOptions);%0A
+        %0A        Properties p = project.getProperties();%0A        File module = new File(p.getProperty(%22spiffyui.gwt.module.path%22));%0A        List%3CJSSourceFile%3E sources = new ArrayList%3CJSSourceFile%3E();%0A     %0A        /* spiffyui.min.js _must_ be first */%0A        sources.add(JSSourceFile.fromFile(new File(module, %22spiffyui.min.js%22)));   %0A        listJSSourceFiles(sources, sourceDirectory);%0A        
 %0A        Compile
@@ -2713,42 +2713,15 @@
 (), 
-listJSSourceFiles(sourceDirectory)
+sources
 , co

Make sure to properly include spiffyui.min.js in the closure output