You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/11/03 21:02:31 UTC

svn commit: r1197294 [1/2] - in /myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder: ./ qdox/

Author: lu4242
Date: Thu Nov  3 20:02:30 2011
New Revision: 1197294

URL: http://svn.apache.org/viewvc?rev=1197294&view=rev
Log:
MYFACES-3384 Cache lastModified info in myfaces-builder-plugin to prevent unnecessary executions

Added:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/AbstractBuilderMojo.java   (with props)
Modified:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeClientBehaviorsMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeComponentsMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConverterTagsMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConvertersMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorTagsMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxHelper.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java

Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/AbstractBuilderMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/AbstractBuilderMojo.java?rev=1197294&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/AbstractBuilderMojo.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/AbstractBuilderMojo.java Thu Nov  3 20:02:30 2011
@@ -0,0 +1,120 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.builder;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public abstract class AbstractBuilderMojo extends AbstractMojo
+{
+    /**
+     * 
+     * @parameter expression="${project.build.directory}/myfaces-builder-plugin-cachefile"
+     */
+    private File cacheFile;
+
+    /**
+     * Does not check if the model is up to date and always build the model when it is executed
+     * 
+     * @parameter
+     */
+    private String noCache;
+
+    protected boolean isCachingEnabled()
+    {
+        return (!Boolean.valueOf(noCache)) && cacheFile != null;
+    }
+    
+    protected void loadCache(Properties cacheInfo) throws MojoExecutionException
+    {
+        try
+        {
+            if (isCachingEnabled() && cacheFile != null && cacheFile.exists())
+            {
+                cacheInfo.load(new BufferedInputStream(new FileInputStream(cacheFile)));
+            }
+        }
+        catch (IOException e)
+        {
+            throw new MojoExecutionException("Error during saving cache information", e);
+        }
+    }
+    
+    protected void storeCache(Properties cacheInfo) throws MojoExecutionException
+    {
+        if (isCachingEnabled())
+        {
+            //save info
+            try
+            {
+                cacheInfo.store(new BufferedOutputStream(new FileOutputStream(cacheFile)), 
+                        "Created: "+ Long.toString(System.currentTimeMillis()));
+            }
+            catch (IOException e)
+            {
+                throw new MojoExecutionException("Error during saving cache information", e);
+            }
+        }
+    }
+    
+    protected boolean isFileUpToDate(Properties cachedInfo, File outFile)
+    {
+        return isFileUpToDate(cachedInfo, outFile.lastModified(), outFile);
+    }
+    
+    protected boolean isFileUpToDate(Properties cachedInfo, long lastModifiedMetadata, File outFile)
+    {
+        boolean upToDate = true;
+        if (!outFile.exists())
+        {
+            return false;
+        }
+        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+        if (lastModifiedString == null)
+        {
+            upToDate = false;
+        }
+        else if (!outFile.exists())
+        {
+            upToDate = false;
+        }
+        else
+        {
+            Long lastModified = Long.valueOf(lastModifiedString);
+            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+            {
+                upToDate = false;
+            }
+        }
+        return upToDate;
+    }
+}

Propchange: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/AbstractBuilderMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java Thu Nov  3 20:02:30 2011
@@ -18,7 +18,12 @@
  */
 package org.apache.myfaces.buildtools.maven2.plugin.builder;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -31,6 +36,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
@@ -41,6 +47,7 @@ import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.IOUtils.SourceVisitor;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.QdoxModelBuilder;
@@ -312,6 +319,19 @@ public class BuildMetaDataMojo extends A
      */
     private String readMavenFacesPluginMetadata;
     
+    /**
+     * 
+     * @parameter expression="${project.build.directory}/myfaces-builder-plugin-cachefile"
+     */
+    private File cacheFile;
+    
+    /**
+     * Does not check if the model is up to date and always build the model when it is executed
+     * 
+     * @parameter
+     */
+    private String noCache;
+    
     private File localResource;
     
     private FacesConfigBean _facesConfig;
@@ -335,29 +355,7 @@ public class BuildMetaDataMojo extends A
             throw new MojoExecutionException("Error during generation", e);
         }
         
-        List models = IOUtils.getModelsFromArtifacts(project); 
-        models = sortModels(models);
-
-        Model model = new Model();
-
-        if (inputFile != null)
-        {
-            // An explicitly-specified input model takes precedence
-            Model fileModel = IOUtils.loadModel(inputFile);
-            model.merge(fileModel);
-        }
-        
-        
-        for (Iterator it = models.iterator(); it.hasNext();)
-        {
-            Model artifactModel = (Model) it.next();
-            
-            if ((dependencyModelIds == null) || dependencyModelIds.contains(artifactModel.getModelId()))
-            {
-                model.merge(artifactModel);
-            }
-        }
-
+        //1. Set up parameters
         ModelParams parameters = new ModelParams();
         
         List sourceDirs = new ArrayList();
@@ -403,15 +401,155 @@ public class BuildMetaDataMojo extends A
             }
         }
         
+        //2. Check if is required to refresh model
+        
+        if (!isReadMavenFacesPluginMetadata() && isCachingEnabled() && cacheFile != null)
+        {
+            final Properties p = new Properties();
+            try
+            {
+                if (cacheFile.exists())
+                {
+                    p.load(new BufferedInputStream(new FileInputStream(cacheFile)));
+                }
+
+                SourceVisitorChecker jsvc = new SourceVisitorChecker(p);
+                if (inputFile != null && inputFile.exists())
+                {
+                    jsvc.processSource(inputFile);
+                }
+                
+                IOUtils.visitSources(parameters,  jsvc);
+                
+                if (jsvc.isUpToDate())
+                {
+                    //Model is up to date, no need to create it again.
+                    getLog().info("model is up to date");
+                    return;
+                }
+            }
+            catch (FileNotFoundException e)
+            {
+                throw new MojoExecutionException("cannot read cacheFile:"+cacheFile.getAbsolutePath());
+            }
+            catch (IOException e)
+            {
+                throw new MojoExecutionException("cannot read cacheFile:"+cacheFile.getAbsolutePath());
+            }
+        }
+        
+        List models = IOUtils.getModelsFromArtifacts(project); 
+        models = sortModels(models);
+
+        Model model = new Model();
+
+        if (inputFile != null)
+        {
+            // An explicitly-specified input model takes precedence
+            Model fileModel = IOUtils.loadModel(inputFile);
+            model.merge(fileModel);
+        }
+        
+        
+        for (Iterator it = models.iterator(); it.hasNext();)
+        {
+            Model artifactModel = (Model) it.next();
+            
+            if ((dependencyModelIds == null) || dependencyModelIds.contains(artifactModel.getModelId()))
+            {
+                model.merge(artifactModel);
+            }
+        }
+        
         buildModel(model, project, parameters);
         
         resolveReplacePackage(model);
         
-        IOUtils.saveModel(model, new File(targetDirectory, outputFile));
+        File metadataFile = new File(targetDirectory, outputFile);
+        
+        IOUtils.saveModel(model, metadataFile);
         
         validateComponents(model);
+        
+        final Properties p = new Properties();
+        
+        if (!isReadMavenFacesPluginMetadata() && isCachingEnabled() && cacheFile != null)
+        {
+            p.put(outputFile, Long.toString(metadataFile.lastModified()));
+            if (inputFile != null && inputFile.exists())
+            {
+                p.put(outputFile, Long.toString(inputFile.lastModified()));
+            }
+        }
+        
+        IOUtils.visitSources(parameters, new IOUtils.SourceVisitor()
+        {
+            public void processSource(File file) throws IOException
+            {
+                p.put(file.getAbsolutePath(), Long.toString(file.lastModified()));                 
+            }
+        });
+        
+        if (cacheFile.exists())
+        {
+            cacheFile.delete();
+        }
+        if (!isReadMavenFacesPluginMetadata() && isCachingEnabled() && cacheFile != null)
+        {
+            try
+            {
+                p.store(new BufferedOutputStream(new FileOutputStream(cacheFile)), "Created: "+ Long.toString(System.currentTimeMillis()));
+            }
+            catch (IOException e)
+            {
+                throw new MojoExecutionException("Error during saving cache information", e);
+            }
+        }
+    }
+    
+    protected boolean isCachingEnabled()
+    {
+        return (!Boolean.valueOf(noCache)) && cacheFile != null;
     }
     
+    private class SourceVisitorChecker implements SourceVisitor
+    {
+        private Properties cachedInfo;
+        
+        private boolean upToDate;
+        
+        public SourceVisitorChecker(Properties p)
+        {
+            cachedInfo = p;
+            upToDate = true;
+        }
+
+        public void processSource(File file) throws IOException
+        {
+            if (!upToDate)
+            {
+                return;
+            }
+            String lastModifiedString = cachedInfo.getProperty(file.getAbsolutePath());
+            if (lastModifiedString != null)
+            {
+                Long lastModified = Long.valueOf(lastModifiedString);
+                if (lastModified != null && file.lastModified() > lastModified.longValue())
+                {
+                    upToDate = false;
+                }
+            }
+            else
+            {
+                upToDate = false;
+            }
+        }
+        
+        public boolean isUpToDate()
+        {
+            return upToDate;
+        }
+    }
     /**
      * Order the models as specified by the modelIdOrder property.
      * <p>

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java Thu Nov  3 20:02:30 2011
@@ -19,6 +19,7 @@
 package org.apache.myfaces.buildtools.maven2.plugin.builder;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.FileWriter;
@@ -38,13 +39,23 @@ import javax.xml.parsers.ParserConfigura
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.digester.Digester;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.io.XmlWriter;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
+import org.codehaus.plexus.components.io.fileselectors.FileInfo;
+import org.codehaus.plexus.components.io.fileselectors.FileSelector;
+import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
 import org.xml.sax.SAXException;
 
+import com.thoughtworks.qdox.directorywalker.DirectoryScanner;
+import com.thoughtworks.qdox.directorywalker.FileVisitor;
+import com.thoughtworks.qdox.directorywalker.SuffixFilter;
+
 /**
  * Utilities to write a Model as xml, and read a Model in from xml.
  */
@@ -381,4 +392,236 @@ public class IOUtils
             throw new MojoExecutionException("Unable to load parser", e);
         }
     }
+    
+    public interface SourceVisitor
+    {
+        public void processSource(File file) throws IOException;
+    }
+
+    public static void visitSources(ModelParams parameters, SourceVisitor visitor)
+    {
+        getSourceClasses(visitor, parameters.getSourceDirs(),
+                parameters.getIncludes(), parameters.getExcludes());
+    }
+
+    private static void getSourceClasses(SourceVisitor visitor,
+            List sourceDirs, String includes, String excludes)
+    {
+        if (StringUtils.isNotEmpty(includes)
+                || StringUtils.isNotEmpty(excludes))
+        {
+            getInnerSourceClasses(visitor, sourceDirs, includes, excludes);
+        }
+        else
+        {
+            getInnerSourceClasses(visitor, sourceDirs);
+        }
+    }
+
+    private static void getInnerSourceClasses(SourceVisitor visitor,
+            List sourceDirs, String includes, String excludes)
+    {
+        IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector();
+        if (StringUtils.isNotEmpty(excludes))
+        {
+            selector.setExcludes(excludes.split(","));
+        }
+        if (StringUtils.isNotEmpty(includes))
+        {
+            selector.setIncludes(includes.split(","));
+        }
+        for (Iterator i = sourceDirs.iterator(); i.hasNext();)
+        {
+            Object dir = i.next();
+            File srcDir = null;
+            if (dir instanceof File)
+            {
+                srcDir = (File) dir;
+            }
+            else
+            {
+                new File((String) i.next());
+            }
+            //Scan all files on directory and add to builder
+            addFileToJavaDocBuilder(visitor, selector, srcDir);
+        }
+    }
+
+    private static void getInnerSourceClasses(SourceVisitor visitor,
+            List sourceDirs)
+    {
+        for (Iterator i = sourceDirs.iterator(); i.hasNext();)
+        {
+            String srcDir = (String) i.next();
+            addSourceTree(visitor, new File(srcDir));
+        }
+    }
+
+    /**
+     * Add all files in a directory (and subdirs, recursively).
+     *
+     * If a file cannot be read, a RuntimeException shall be thrown.
+     */
+    private static void addSourceTree(SourceVisitor visitor, File file)
+    {
+        FileVisitor errorHandler = new FileVisitor()
+        {
+            public void visitFile(File badFile)
+            {
+                throw new RuntimeException("Cannot read file : "
+                        + badFile.getName());
+            }
+        };
+        addSourceTree(visitor, file, errorHandler);
+    }
+
+    /**
+     * Add all files in a directory (and subdirs, recursively).
+     *
+     * If a file cannot be read, errorHandler will be notified.
+     */
+    private static void addSourceTree(final SourceVisitor visitor,
+            File file, final FileVisitor errorHandler)
+    {
+        DirectoryScanner scanner = new DirectoryScanner(file);
+        scanner.addFilter(new SuffixFilter(".java"));
+        scanner.scan(new FileVisitor()
+        {
+            public void visitFile(File currentFile)
+            {
+                try
+                {
+                    visitor.processSource(currentFile);
+                }
+                catch (IOException e)
+                {
+                    errorHandler.visitFile(currentFile);
+                }
+            }
+        });
+    }
+
+    private static void addFileToJavaDocBuilder(SourceVisitor visitor,
+            FileSelector selector, File path)
+    {
+        addFileToJavaDocBuilder(visitor, selector, path, path.getPath());
+    }
+
+    private static void addFileToJavaDocBuilder(SourceVisitor visitor,
+            FileSelector selector, File path, String basePath)
+    {
+        if (path.isDirectory())
+        {
+            File[] files = path.listFiles();
+
+            //Scan all files in directory
+            for (int i = 0; i < files.length; i++)
+            {
+                addFileToJavaDocBuilder(visitor, selector, files[i], basePath);
+            }
+        }
+        else
+        {
+            File file = path;
+
+            try
+            {
+                String name = file.getPath();
+                while (name.startsWith("/"))
+                {
+                    name = name.substring(1);
+                }
+                while (name.startsWith("\\"))
+                {
+                    name = name.substring(1);
+                }
+                SourceFileInfo fileInfo = new SourceFileInfo(file, name);
+                if (selector.isSelected(fileInfo))
+                {
+                    //builder.addSource(file);
+                    visitor.processSource(file);
+                }
+            }
+            catch (FileNotFoundException e)
+            {
+                Log log = LogFactory.getLog(IOUtils.class);
+                log.error("Error reading file: " + file.getName() + " "
+                        + e.getMessage());
+            }
+            catch (IOException e)
+            {
+                Log log = LogFactory.getLog(IOUtils.class);
+                log.error("Error reading file: " + file.getName() + " "
+                        + e.getMessage());
+            }
+        }
+    }
+
+    private static class SourceFileInfo implements FileInfo
+    {
+        private File file;
+
+        private String name;
+
+        /**
+         * Creates a new instance.
+         */
+        public SourceFileInfo(File file)
+        {
+            this(file, file.getPath().replace('\\', '/'));
+        }
+
+        /**
+         * Creates a new instance.
+         */
+        public SourceFileInfo(File file, String name)
+        {
+            this.file = file;
+            this.name = name;
+        }
+
+        /**
+         * Sets the resources file.
+         */
+        public void setFile(File file)
+        {
+            this.file = file;
+        }
+
+        /**
+         * Returns the resources file.
+         */
+        public File getFile()
+        {
+            return file;
+        }
+
+        /**
+         * Sets the resources name.
+         */
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public InputStream getContents() throws IOException
+        {
+            return new FileInputStream(getFile());
+        }
+
+        public boolean isDirectory()
+        {
+            return file.isDirectory();
+        }
+
+        public boolean isFile()
+        {
+            return file.isFile();
+        }
+    }
 }

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeClientBehaviorsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeClientBehaviorsMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeClientBehaviorsMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeClientBehaviorsMojo.java Thu Nov  3 20:02:30 2011
@@ -26,8 +26,8 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.BehaviorMeta;
@@ -63,7 +63,7 @@ import com.thoughtworks.qdox.JavaDocBuil
  * @goal make-client-behaviors
  * @phase generate-sources
  */
-public class MakeClientBehaviorsMojo extends AbstractMojo
+public class MakeClientBehaviorsMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -186,10 +186,14 @@ public class MakeClientBehaviorsMojo ext
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateBehaviors(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateBehaviors(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -201,7 +205,6 @@ public class MakeClientBehaviorsMojo ext
         }
     }
     
-    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
         File template = new File(templateSourceDirectory, _getTemplateName());
@@ -250,12 +253,76 @@ public class MakeClientBehaviorsMojo ext
     /**
      * Generates parsed behaviors.
      */
-    private void generateBehaviors(Model model) throws IOException,
+    private void generateBehaviors(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
         // Make sure generated source directory 
         // is added to compilation source path 
         //project.addCompileSourceRoot(generatedSourceDirectory.getCanonicalPath());
+        File tf = new File(templateSourceDirectory, _getTemplateName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getBehaviors().iterator(); it.hasNext();)
+            {
+                BehaviorMeta behavior = (BehaviorMeta) it.next();
+                
+                if (behavior.getClassName() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                        behavior.getClassName(), ".", "/")+".java");
+                                    
+                    if (!f.exists() && canGenerateBehavior(behavior))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    behavior.getClassName(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                behavior.getClassName(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated converter files are up to date");
+                return;
+            }
+        }
+
         
         //Init Qdox for extract code 
         JavaDocBuilder builder = new JavaDocBuilder();
@@ -299,7 +366,8 @@ public class MakeClientBehaviorsMojo ext
                     getLog().info("Generating client behavior class:"+behavior.getClassName());
                     try
                     {
-                        _generateBehavior(velocityEngine, builder,behavior,baseContext);
+                        _generateBehavior(velocityEngine, builder,behavior,baseContext,
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -315,7 +383,14 @@ public class MakeClientBehaviorsMojo ext
                     }
                 }
             }
-        }        
+        }
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateBehavior(BehaviorMeta behavior)
@@ -366,7 +441,8 @@ public class MakeClientBehaviorsMojo ext
      */
     private void _generateBehavior(VelocityEngine velocityEngine,
             JavaDocBuilder builder,
-            BehaviorMeta behavior, VelocityContext baseContext)
+            BehaviorMeta behavior, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
         Context context = new VelocityContext(baseContext);
@@ -392,6 +468,11 @@ public class MakeClientBehaviorsMojo ext
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeComponentsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeComponentsMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeComponentsMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeComponentsMojo.java Thu Nov  3 20:02:30 2011
@@ -27,8 +27,8 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
@@ -72,7 +72,7 @@ import com.thoughtworks.qdox.model.JavaM
  * @goal make-components
  * @phase generate-sources
  */
-public class MakeComponentsMojo extends AbstractMojo
+public class MakeComponentsMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -214,10 +214,14 @@ public class MakeComponentsMojo extends 
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateComponents(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateComponents(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -229,7 +233,6 @@ public class MakeComponentsMojo extends 
         }
     }
     
-    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
         File template = new File(templateSourceDirectory, _getTemplateName());
@@ -277,12 +280,76 @@ public class MakeComponentsMojo extends 
     /**
      * Generates parsed components.
      */
-    private void generateComponents(Model model) throws IOException,
+    private void generateComponents(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
         // Make sure generated source directory 
         // is added to compilation source path 
         //project.addCompileSourceRoot(generatedSourceDirectory.getCanonicalPath());
+        File tf = new File(templateSourceDirectory, _getTemplateName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getComponents().iterator(); it.hasNext();)
+            {
+                ComponentMeta component = (ComponentMeta) it.next();
+                
+                if (component.getClassName() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                            component.getClassName(), ".", "/")+".java");
+                                        
+                    if (!f.exists() && canGenerateComponent(component))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    component.getClassName(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                component.getClassName(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated component files are up to date");
+                return;
+            }
+        }
+
         
         //Init Qdox for extract code 
         JavaDocBuilder builder = new JavaDocBuilder();
@@ -327,7 +394,8 @@ public class MakeComponentsMojo extends 
                     
                     try 
                     {
-                        _generateComponent(velocityEngine, builder,component,baseContext);
+                        _generateComponent(velocityEngine, builder,component,baseContext,
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -343,7 +411,14 @@ public class MakeComponentsMojo extends 
                     }
                 }
             }
-        }        
+        }
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateComponent(ComponentMeta component)
@@ -407,7 +482,8 @@ public class MakeComponentsMojo extends 
      */
     private void _generateComponent(VelocityEngine velocityEngine,
             JavaDocBuilder builder,
-            ComponentMeta component, VelocityContext baseContext)
+            ComponentMeta component, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
         Context context = new VelocityContext(baseContext);
@@ -443,6 +519,11 @@ public class MakeComponentsMojo extends 
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java Thu Nov  3 20:02:30 2011
@@ -30,8 +30,8 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
@@ -83,7 +83,7 @@ import org.codehaus.plexus.util.xml.pull
  * @goal make-config
  * @phase generate-sources
  */
-public class MakeConfigMojo extends AbstractMojo
+public class MakeConfigMojo extends AbstractBuilderMojo
 {
     /**
      * The current maven project (auto-injected by Maven).
@@ -212,15 +212,18 @@ public class MakeConfigMojo extends Abst
 
             // Load the metadata file from an xml file (presumably generated
             // by an earlier execution of the build-metadata goal.
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
 
             // Flatten the model so that the template can access every property
             // of each model item directly, even when the property is actually
             // defined on an ancestor class or interface.
             new Flattener(model).flatten();
-
-            generateConfigFromVelocity(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateConfigFromVelocity(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -232,78 +235,100 @@ public class MakeConfigMojo extends Abst
         }
     }
     
-    private void generateConfigFromVelocity(Model model) throws IOException,
+    private void generateConfigFromVelocity(Model model,
+		Properties cachedInfo, long lastModifiedMetadata) throws IOException,
         MojoExecutionException
     {    
-        VelocityEngine velocityEngine = initVelocity();
-
-        VelocityContext baseContext = new VelocityContext();
-        baseContext.put("utils", new MyfacesUtils());
-        
-        String baseContent = "";
+        Writer writer = null;
+        File outFile = null;
+        File tf = new File(templateSourceDirectory, templateFile);
         
-        if (xmlBaseFile != null && xmlBaseFile.exists())
+        try
         {
-            getLog().info("using base content file: "+xmlBaseFile.getPath());
+            outFile = new File(outputDirectory, xmlFile);
+
+            if ( !outFile.getParentFile().exists() )
+            {
+                outFile.getParentFile().mkdirs();
+            }
             
-            Reader reader = null;
-            try
+            if (isCachingEnabled() && outFile.exists())
             {
-                reader = new FileReader(xmlBaseFile);
-                Xpp3Dom root = Xpp3DomBuilder.build(reader);
-                
-                StringWriter writer = new StringWriter();
+                boolean upToDate = isFileUpToDate(cachedInfo, lastModifiedMetadata, outFile); 
                 
-                Xpp3Dom [] children = root.getChildren();
+                if (upToDate && xmlBaseFile != null && xmlBaseFile.exists())
+                {
+                    upToDate = isFileUpToDate(cachedInfo, xmlBaseFile);
+                }
+                if (upToDate && tf != null && tf.exists())
+                {
+                    upToDate = isFileUpToDate(cachedInfo, tf);
+                }
                 
-                for (int i = 0; i< children.length; i++)
+                if (upToDate)
                 {
-                    Xpp3Dom dom = children[i];
-                    Xpp3DomWriter.write(writer, dom);
-                    writer.write('\n');
+                    getLog().info("generated file " +outFile.getName()+ " is up to date");
+                    return;
                 }
-                baseContent = writer.toString();
-                writer.close();
-            }
-            catch (XmlPullParserException e)
-            {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
             }
-            finally
-            {
-                reader.close();
-            }
-        }
-        
-        baseContext.put("baseContent", baseContent);
-        
-        baseContext.put("model", model);
-        
-        baseContext.put("modelIds", modelIds);
-        
-        if (params != null)
-        {
-            //Load all parameters to the context, so the template can
-            //load it. This allow to generate any config file we want
-            //(faces-config, tld, facelet,....)
-            for (Iterator it = params.keySet().iterator(); it.hasNext();)
+            
+            VelocityEngine velocityEngine = initVelocity();
+
+            VelocityContext baseContext = new VelocityContext();
+            baseContext.put("utils", new MyfacesUtils());
+            
+            String baseContent = "";
+            
+            if (xmlBaseFile != null && xmlBaseFile.exists())
             {
-                String key = (String) it.next();
-                baseContext.put(key,params.get(key));
+                getLog().info("using base content file: "+xmlBaseFile.getPath());
+                
+                Reader reader = null;
+                try
+                {
+                    reader = new FileReader(xmlBaseFile);
+                    Xpp3Dom root = Xpp3DomBuilder.build(reader);
+                    
+                    StringWriter swriter = new StringWriter();
+                    
+                    Xpp3Dom [] children = root.getChildren();
+                    
+                    for (int i = 0; i< children.length; i++)
+                    {
+                        Xpp3Dom dom = children[i];
+                        Xpp3DomWriter.write(swriter, dom);
+                        swriter.write('\n');
+                    }
+                    baseContent = swriter.toString();
+                    swriter.close();
+                }
+                catch (XmlPullParserException e)
+                {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                finally
+                {
+                    reader.close();
+                }
             }
-        }
-        
-        Writer writer = null;
-        File outFile = null;
-        
-        try
-        {
-            outFile = new File(outputDirectory, xmlFile);
             
-            if ( !outFile.getParentFile().exists() )
+            baseContext.put("baseContent", baseContent);
+            
+            baseContext.put("model", model);
+            
+            baseContext.put("modelIds", modelIds);
+            
+            if (params != null)
             {
-                outFile.getParentFile().mkdirs();
+                //Load all parameters to the context, so the template can
+                //load it. This allow to generate any config file we want
+                //(faces-config, tld, facelet,....)
+                for (Iterator it = params.keySet().iterator(); it.hasNext();)
+                {
+                    String key = (String) it.next();
+                    baseContext.put(key,params.get(key));
+                }
             }
             
             writer = new OutputStreamWriter(new FileOutputStream(outFile));
@@ -313,6 +338,19 @@ public class MakeConfigMojo extends Abst
             template.merge(baseContext, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+                if (xmlBaseFile != null && xmlBaseFile.exists())
+                {
+                    cachedInfo.put(xmlBaseFile.getAbsolutePath(), Long.toString(xmlBaseFile.lastModified()));
+                }
+                if (tf != null && tf.exists())
+                {
+                    cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+                }
+            }
         }
         catch (ResourceNotFoundException e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConverterTagsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConverterTagsMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConverterTagsMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConverterTagsMojo.java Thu Nov  3 20:02:30 2011
@@ -18,7 +18,10 @@
  */
 package org.apache.myfaces.buildtools.maven2.plugin.builder;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -26,6 +29,7 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -61,7 +65,7 @@ import org.codehaus.plexus.util.StringUt
  * @goal make-converter-tags
  * @phase generate-sources
  */
-public class MakeConverterTagsMojo extends AbstractMojo
+public class MakeConverterTagsMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -202,10 +206,14 @@ public class MakeConverterTagsMojo exten
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateConverters(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateConverters(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -216,7 +224,7 @@ public class MakeConverterTagsMojo exten
             throw new MojoExecutionException("Error generating components", e);
         }
     }
-        
+    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
 
@@ -265,9 +273,73 @@ public class MakeConverterTagsMojo exten
     /**
      * Generates parsed components.
      */
-    private void generateConverters(Model model) throws IOException,
+    private void generateConverters(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
+        File tf = new File(templateSourceDirectory, _getTemplateTagName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getConverters().iterator(); it.hasNext();)
+            {
+                ConverterMeta converter = (ConverterMeta) it.next();
+                
+                if (converter.getTagClass() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                        converter.getTagClass(), ".", "/")+".java");
+                    
+                    if (!f.exists() && canGenerateConverterTag(converter))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    converter.getTagClass(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                converter.getTagClass(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated component tag files are up to date");
+                return;
+            }
+        }
+
         VelocityEngine velocityEngine = initVelocity();
 
         VelocityContext baseContext = new VelocityContext();
@@ -297,7 +369,8 @@ public class MakeConverterTagsMojo exten
                     getLog().info("Generating tag class:"+converter.getTagClass());
                     try
                     {
-                        _generateConverter(velocityEngine, converter,baseContext);
+                        _generateConverter(velocityEngine, converter,baseContext, 
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -314,7 +387,13 @@ public class MakeConverterTagsMojo exten
                 }
             }
         }
-        //throw new MojoExecutionException("stopping..");
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateConverterTag(ConverterMeta component)
@@ -376,7 +455,8 @@ public class MakeConverterTagsMojo exten
      * @param converter
      *            the parsed component metadata
      */
-    private void _generateConverter(VelocityEngine velocityEngine, ConverterMeta converter, VelocityContext baseContext)
+    private void _generateConverter(VelocityEngine velocityEngine, ConverterMeta converter, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
 
@@ -403,6 +483,11 @@ public class MakeConverterTagsMojo exten
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConvertersMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConvertersMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConvertersMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConvertersMojo.java Thu Nov  3 20:02:30 2011
@@ -26,12 +26,12 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ConverterMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.BuildException;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.MavenPluginConsoleLogSystem;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.MyfacesUtils;
@@ -65,7 +65,7 @@ import com.thoughtworks.qdox.JavaDocBuil
  * @goal make-converters
  * @phase generate-sources
  */
-public class MakeConvertersMojo extends AbstractMojo
+public class MakeConvertersMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -200,10 +200,14 @@ public class MakeConvertersMojo extends 
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateConverters(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateConverters(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -215,7 +219,6 @@ public class MakeConvertersMojo extends 
         }
     }
     
-    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
         File template = new File(templateSourceDirectory, _getTemplateName());
@@ -264,12 +267,76 @@ public class MakeConvertersMojo extends 
     /**
      * Generates parsed converters.
      */
-    private void generateConverters(Model model) throws IOException,
+    private void generateConverters(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
         // Make sure generated source directory 
         // is added to compilation source path 
         //project.addCompileSourceRoot(generatedSourceDirectory.getCanonicalPath());
+        File tf = new File(templateSourceDirectory, _getTemplateName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getConverters().iterator(); it.hasNext();)
+            {
+                ConverterMeta converter = (ConverterMeta) it.next();
+                
+                if (converter.getClassName() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                        converter.getClassName(), ".", "/")+".java");
+                                  
+                    if (!f.exists() && canGenerateConverter(converter))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    converter.getClassName(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                converter.getClassName(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated converter files are up to date");
+                return;
+            }
+        }
+
         
         //Init Qdox for extract code 
         JavaDocBuilder builder = new JavaDocBuilder();
@@ -313,7 +380,8 @@ public class MakeConvertersMojo extends 
                     getLog().info("Generating converter class:"+converter.getClassName());
                     try
                     {
-                        _generateConverter(velocityEngine, builder,converter,baseContext);
+                        _generateConverter(velocityEngine, builder,converter,baseContext,
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -329,7 +397,14 @@ public class MakeConvertersMojo extends 
                     }
                 }
             }
-        }        
+        }
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateConverter(ConverterMeta converter)
@@ -373,7 +448,8 @@ public class MakeConvertersMojo extends 
      */
     private void _generateConverter(VelocityEngine velocityEngine,
             JavaDocBuilder builder,
-            ConverterMeta converter, VelocityContext baseContext)
+            ConverterMeta converter, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
         Context context = new VelocityContext(baseContext);
@@ -399,6 +475,11 @@ public class MakeConvertersMojo extends 
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java Thu Nov  3 20:02:30 2011
@@ -26,8 +26,8 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
@@ -61,7 +61,7 @@ import org.codehaus.plexus.util.StringUt
  * @goal make-tags
  * @phase generate-sources
  */
-public class MakeTagsMojo extends AbstractMojo
+public class MakeTagsMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -202,10 +202,14 @@ public class MakeTagsMojo extends Abstra
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateComponents(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateComponents(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -216,7 +220,7 @@ public class MakeTagsMojo extends Abstra
             throw new MojoExecutionException("Error generating components", e);
         }
     }
-        
+    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
         File template = new File(templateSourceDirectory, _getTemplateTagName());
@@ -264,9 +268,73 @@ public class MakeTagsMojo extends Abstra
     /**
      * Generates parsed components.
      */
-    private void generateComponents(Model model) throws IOException,
+    private void generateComponents(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
+        File tf = new File(templateSourceDirectory, _getTemplateTagName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getComponents().iterator(); it.hasNext();)
+            {
+                ComponentMeta component = (ComponentMeta) it.next();
+                
+                if (component.getTagClass() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                        component.getTagClass(), ".", "/")+".java");
+                    
+                    if (!f.exists() && canGenerateComponentTag(component))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    component.getTagClass(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                component.getTagClass(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated component tag files are up to date");
+                return;
+            }
+        }
+
         VelocityEngine velocityEngine = initVelocity();
 
         VelocityContext baseContext = new VelocityContext();
@@ -296,7 +364,8 @@ public class MakeTagsMojo extends Abstra
                     getLog().info("Generating tag class:"+component.getTagClass());
                     try 
                     {
-                        _generateComponent(velocityEngine, component,baseContext);
+                        _generateComponent(velocityEngine, component,baseContext, 
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -313,7 +382,13 @@ public class MakeTagsMojo extends Abstra
                 }
             }
         }
-        //throw new MojoExecutionException("stopping..");
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateComponentTag(ComponentMeta component)
@@ -375,7 +450,8 @@ public class MakeTagsMojo extends Abstra
      * @param component
      *            the parsed component metadata
      */
-    private void _generateComponent(VelocityEngine velocityEngine, ComponentMeta component, VelocityContext baseContext)
+    private void _generateComponent(VelocityEngine velocityEngine, ComponentMeta component, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
 
@@ -402,6 +478,11 @@ public class MakeTagsMojo extends Abstra
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorTagsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorTagsMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorTagsMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorTagsMojo.java Thu Nov  3 20:02:30 2011
@@ -26,8 +26,8 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
@@ -61,7 +61,7 @@ import org.codehaus.plexus.util.StringUt
  * @goal make-validator-tags
  * @phase generate-sources
  */
-public class MakeValidatorTagsMojo extends AbstractMojo
+public class MakeValidatorTagsMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -202,10 +202,14 @@ public class MakeValidatorTagsMojo exten
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateValidators(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateValidators(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -216,7 +220,7 @@ public class MakeValidatorTagsMojo exten
             throw new MojoExecutionException("Error generating components", e);
         }
     }
-        
+
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
         File template = new File(templateSourceDirectory, _getTemplateTagName());
@@ -265,9 +269,73 @@ public class MakeValidatorTagsMojo exten
     /**
      * Generates parsed components.
      */
-    private void generateValidators(Model model) throws IOException,
+    private void generateValidators(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
+        File tf = new File(templateSourceDirectory, _getTemplateTagName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getValidators().iterator(); it.hasNext();)
+            {
+                ValidatorMeta validator = (ValidatorMeta) it.next();
+                
+                if (validator.getTagClass() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                        validator.getTagClass(), ".", "/")+".java");
+                    
+                    if (!f.exists() && canGenerateValidatorTag(validator))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    validator.getTagClass(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                validator.getTagClass(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated component tag files are up to date");
+                return;
+            }
+        }
+
         VelocityEngine velocityEngine = initVelocity();
 
         VelocityContext baseContext = new VelocityContext();
@@ -297,7 +365,8 @@ public class MakeValidatorTagsMojo exten
                     getLog().info("Generating tag class:"+validator.getTagClass());
                     try
                     {
-                        _generateValidator(velocityEngine, validator,baseContext);
+                        _generateValidator(velocityEngine, validator,baseContext, 
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -314,7 +383,13 @@ public class MakeValidatorTagsMojo exten
                 }
             }
         }
-        //throw new MojoExecutionException("stopping..");
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateValidatorTag(ValidatorMeta component)
@@ -376,7 +451,8 @@ public class MakeValidatorTagsMojo exten
      * @param validator
      *            the parsed component metadata
      */
-    private void _generateValidator(VelocityEngine velocityEngine, ValidatorMeta validator, VelocityContext baseContext)
+    private void _generateValidator(VelocityEngine velocityEngine, ValidatorMeta validator, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
 
@@ -403,6 +479,11 @@ public class MakeValidatorTagsMojo exten
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java?rev=1197294&r1=1197293&r2=1197294&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java Thu Nov  3 20:02:30 2011
@@ -26,8 +26,8 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
@@ -63,7 +63,7 @@ import com.thoughtworks.qdox.JavaDocBuil
  * @goal make-validators
  * @phase generate-sources
  */
-public class MakeValidatorsMojo extends AbstractMojo
+public class MakeValidatorsMojo extends AbstractBuilderMojo
 {
     /**
      * Injected Maven project.
@@ -197,10 +197,14 @@ public class MakeValidatorsMojo extends 
                 modelIds = new ArrayList();
                 modelIds.add(project.getArtifactId());
             }
-            Model model = IOUtils.loadModel(new File(buildDirectory,
-                    metadataFile));
+            File mdFile = new File(buildDirectory, metadataFile);
+            Model model = IOUtils.loadModel(mdFile);
             new Flattener(model).flatten();
-            generateValidators(model);
+            
+            Properties cacheInfo = new Properties();
+            loadCache(cacheInfo);
+            generateValidators(model, cacheInfo, mdFile.lastModified() );
+            storeCache(cacheInfo);
         }
         catch (IOException e)
         {
@@ -212,7 +216,6 @@ public class MakeValidatorsMojo extends 
         }
     }
     
-    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
         File template = new File(templateSourceDirectory, _getTemplateName());
@@ -261,12 +264,76 @@ public class MakeValidatorsMojo extends 
     /**
      * Generates parsed validators.
      */
-    private void generateValidators(Model model) throws IOException,
+    private void generateValidators(Model model, Properties cachedInfo, long lastModifiedMetadata) throws IOException,
             MojoExecutionException
     {
         // Make sure generated source directory 
         // is added to compilation source path 
         //project.addCompileSourceRoot(generatedSourceDirectory.getCanonicalPath());
+        File tf = new File(templateSourceDirectory, _getTemplateName());
+        
+        if (isCachingEnabled())
+        {
+            boolean upToDate = true;
+            for (Iterator it = model.getValidators().iterator(); it.hasNext();)
+            {
+                ValidatorMeta validator = (ValidatorMeta) it.next();
+                
+                if (validator.getClassName() != null)
+                {
+                    File f = new File(mainSourceDirectory, StringUtils.replace(
+                        validator.getClassName(), ".", "/")+".java");
+                                    
+                    if (!f.exists() && canGenerateValidator(validator))
+                    {
+                        if (mainSourceDirectory2 != null)
+                        {
+                            File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                    validator.getClassName(), ".", "/")+".java");
+                            if (f2.exists())
+                            {
+                                //Skip
+                                continue;
+                            }
+                        }
+    
+                        File outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                                validator.getClassName(), ".", "/")+".java");
+    
+                        String lastModifiedString = cachedInfo.getProperty(outFile.getAbsolutePath());
+                        if (lastModifiedString == null)
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else if (!outFile.exists())
+                        {
+                            upToDate = false;
+                            break;
+                        }
+                        else
+                        {
+                            Long lastModified = Long.valueOf(lastModifiedString);
+                            if (lastModified != null && lastModifiedMetadata > lastModified.longValue())
+                            {
+                                upToDate = false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            if (upToDate && tf != null && tf.exists())
+            {
+                upToDate = isFileUpToDate(cachedInfo, tf);
+            }
+            if (upToDate)
+            {
+                getLog().info("generated converter files are up to date");
+                return;
+            }
+        }
+
         
         //Init Qdox for extract code 
         JavaDocBuilder builder = new JavaDocBuilder();
@@ -310,7 +377,8 @@ public class MakeValidatorsMojo extends 
                     getLog().info("Generating validator class:"+validator.getClassName());
                     try
                     {
-                        _generateValidator(velocityEngine, builder,validator,baseContext);
+                        _generateValidator(velocityEngine, builder,validator,baseContext,
+                                cachedInfo, lastModifiedMetadata);
                     }
                     catch(MojoExecutionException e)
                     {
@@ -326,7 +394,14 @@ public class MakeValidatorsMojo extends 
                     }
                 }
             }
-        }        
+        }
+        if (isCachingEnabled())
+        {
+            if (tf != null && tf.exists())
+            {
+                cachedInfo.put(tf.getAbsolutePath(), Long.toString(tf.lastModified()));
+            }
+        }
     }
     
     public boolean canGenerateValidator(ValidatorMeta validator)
@@ -370,7 +445,8 @@ public class MakeValidatorsMojo extends 
      */
     private void _generateValidator(VelocityEngine velocityEngine,
             JavaDocBuilder builder,
-            ValidatorMeta validator, VelocityContext baseContext)
+            ValidatorMeta validator, VelocityContext baseContext,
+            Properties cachedInfo, long lastModifiedMetadata)
             throws MojoExecutionException
     {
         Context context = new VelocityContext(baseContext);
@@ -396,6 +472,11 @@ public class MakeValidatorsMojo extends 
             template.merge(context, writer);
 
             writer.flush();
+            
+            if (isCachingEnabled())
+            {
+                cachedInfo.put(outFile.getAbsolutePath(), Long.toString(lastModifiedMetadata));
+            }
         }
         catch (Exception e)
         {
@@ -432,7 +513,7 @@ public class MakeValidatorsMojo extends 
     {
         return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
     }
-    
+
 
     private boolean _is20()
     {