public void execute()

in maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java [343:508]


    public void execute() throws MojoExecutionException
    {
        try
        {
            // Tell Maven to add this directory to its "resources" path. 
            // The maven-resources-plugin will then copy all the files
            // from this directory to its own target directory, which is
            // where the final jar artifact is built from.
            addResourceRoot(project, targetDirectory.getCanonicalPath());
        }
        catch(IOException e)
        {
            throw new MojoExecutionException("Error during generation", e);
        }
        
        //1. Set up parameters
        ModelParams parameters = new ModelParams();
        
        List sourceDirs = new ArrayList();
        if (sourceDirectories == null)
        {
            sourceDirs.addAll(project.getCompileSourceRoots());
        }
        else
        {
            sourceDirs.addAll(sourceDirectories);
        }
        
        if (generatedSourceDirectory != null)
        {
            for (Iterator it = sourceDirs.iterator(); it.hasNext();)
            {
                File f = new File((String) it.next());
                if (generatedSourceDirectory.equals(f))
                {
                    it.remove();
                }
            }
        }
        
        parameters.setSourceDirs(sourceDirs);
        
        List compositeComponentDirs = new ArrayList();
        compositeComponentDirs.add(compositeComponentDirectory);
        parameters.setCompositeComponentDirectories(compositeComponentDirs);
        
        parameters.setCompositeComponentLibraries(compositeComponentLibraries);
        
        parameters.setCompositeComponentFileExtensions(compositeComponentFileExtensions);
        
        //Trinidad maven faces plugin integration
        if (isReadMavenFacesPluginMetadata())
        {
            processIndex(project);
            
            if (_facesConfig != null)
            {
                parameters.setFacesConfigBean(_facesConfig);
            }
        }
        
        //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);
        
        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);
            }
        }
    }