package org.spiffyui.maven.plugins;

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

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.spiffyui.build.HTMLPropertiesUtil;

/**
 * Goal which compiles various HTML files into something consumable by GWT
 * 
 * @goal htmlprops
 * @phase generate-resources
 */
public class HTMLPropsMojo extends AbstractMojo
{
    /**
     * The maven project.
     * 
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    protected MavenProject project;
        
    /**
     * Location of the file.
     * 
     * @parameter expression="${project.build.outputDirectory}/htmlprops.properties"
     * @required
     */
    private File outputFile;

    /**
     * The name to give to the generated package
     * 
     * @parameter expression="${project.groupId}.${project.artifactId}.htmlprops"
     * @required
     */
    private String packageName;
    
    /**
     * @parameter expression="src/main/html"
     * @required
     */
    private File sourceDirectory;
    
    @Override
    public void execute()
        throws MojoExecutionException,
            MojoFailureException
    {
        Log log = getLog();
        
        if (!sourceDirectory.exists()) {
            log.debug("HTMLPROPS: " +
                  sourceDirectory.getAbsolutePath() + " does not exist.  Skipping");
            return;
        }
        
        log.info("HTMLPROPS: Generating " + packageName);
        
        String[] exts = new String[] { "html" };
        List<File> files = new ArrayList<File>(FileUtils.listFiles(sourceDirectory, exts, true));
        
        project.getProperties().put("spiffyui.htmlprops.path", outputFile.getAbsolutePath());
        
        try {
            HTMLPropertiesUtil.generatePropertiesFiles(files, outputFile, packageName);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage());
        }

    }

}

@@ -912,15 +912,9 @@
 ild.
-outputD
+d
 irec
@@ -932,19 +932,8 @@
 rops
-.properties
 %22%0A  
@@ -978,20 +978,25 @@
 e output
-File
+Directory
 ;%0A%0A    /
@@ -1666,32 +1666,118 @@
      %7D%0A        %0A
+        File outputFile = new File(outputDirectory, %22htmlprops.properties%22);%0A        %0A
         log.info
@@ -1995,93 +1995,59 @@
     
-project.getProperties().put(%22spiffyui.htmlprops.path%22, outputFile.getAbsolutePath
+ try %7B%0A %0A            if (!outputDirectory.exists
 ())
-;
 %0A   
@@ -2051,25 +2051,24 @@
         
-%0A
         
 try %7B%0A  
@@ -2059,21 +2059,60 @@
         
-try %7B
+FileUtils.forceMkdir(outputDirectory);%0A     
 %0A       
@@ -2297,16 +2297,124 @@
        %7D
+%0A        %0A        project.getProperties().put(%22spiffyui.htmlprops.path%22, outputDirectory.getAbsolutePath());
 %0A%0A    %7D%0A

Put the htmlprops in a directory outside of the static artifacts