Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.javacc;
  
  /*
   * 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.
  */
 
 import java.io.File;
 import java.net.URI;
 import java.util.Set;
 
Parses a JJT grammar file and transforms it to Java source files.

Author(s):
jesse <jesse.mcconnell@gmail.com>
Version:
$Id: JJTreeMojo.java 6013 2008-01-24 02:38:57Z pgier $
Goal:
jjtree
Phase:
generate-sources
 
 public class JJTreeMojo
     extends AbstractMojo
 {

    

Parameter:
expression="${buildNodeFiles}"
 
     private Boolean buildNodeFiles;

    

Parameter:
expression="${multi}"
 
     private Boolean multi;

    

Parameter:
expression="${nodeDefaultVoid}"
 
     private Boolean nodeDefaultVoid;

    

Parameter:
expression="${nodeFactory}"
 
     private Boolean nodeFactory;

    

Parameter:
expression="${nodeScopeHook}"
 
     private Boolean nodeScopeHook;

    

Parameter:
expression="${nodeUsesParser}"
 
     private Boolean nodeUsesParser;

    

Parameter:
expression="${staticOption}"
 
     private Boolean staticOption;

    

Parameter:
expression="${visitor}"
 
     private Boolean visitor;

    

Parameter:
expression="${nodePackage}"
 
     private String nodePackage;

    

Parameter:
expression="${visitorException}"
    private String visitorException;

    

Parameter:
expression="${nodePrefix}"
    private String nodePrefix;

    
Directory where the JJT file(s) are located.

Parameter:
expression="${basedir}/src/main/jjtree"
Required:
    private File sourceDirectory;

    
Directory where the output Java Files will be located.

Parameter:
expression="${project.build.directory}/generated-sources/jjtree"
Required:
    private File outputDirectory;

    
the directory to store the processed .jjt files

Parameter:
expression="${project.build.directory}/generated-sources/jjtree-timestamp"
    private File timestampDirectory;

    
The granularity in milliseconds of the last modification date for testing whether a source needs recompilation

Parameter:
expression="${lastModGranularityMs}" default-value="0"
    private int staleMillis;

    
A list of inclusion filters for the compiler.

Parameter:
    private Set includes;

    
A list of exclusion filters for the compiler.

Parameter:
    private Set excludes;

    
Contains the package name to use for the generated code
    private String packageName;

    

Parameter:
expression="${project}"
Readonly:
Required:
    private MavenProject project;

    
Execute the JJTree

Throws:
org.apache.maven.plugin.MojoExecutionException if the compilation fails
    public void execute()
        throws MojoExecutionException
    {
        if (  != null )
        {
             = StringUtils.replace'.'. );
        }
        if ( !.exists() )
        {
            .mkdirs();
        }
        if ( !.exists() )
        {
            .mkdirs();
        }
        if (  == null )
        {
             = Collections.singleton"**/*" );
        }
        if (  == null )
        {
             = .;
        }
        Set staleGrammars = computeStaleGrammars();
        if ( staleGrammars.isEmpty() )
        {
            getLog().info"Nothing to process - all grammars in " +  + " are up to date." );
            return;
        }
        for ( Iterator i = staleGrammars.iterator(); i.hasNext(); )
        {
            File jjTreeFile = (Filei.next();
            try
            {
                JJTree jjtree = new JJTree();
                jjtree.maingenerateArgumentListjjTreeFile.getAbsolutePath() ) );
                URI relativeURI = .toURI().relativizejjTreeFile.toURI() );
                File timestampFile = new File.toURI().resolverelativeURI ) );
                FileUtils.copyFilejjTreeFiletimestampFile );
            }
            catch ( Exception e )
            {
                throw new MojoExecutionException"JJTree execution failed"e );
            }
        }
    }

    
Get the output directory for the javacc files.

Parameters:
jjtreeInput The jjtree file.
Returns:
the directory that will contain the generated code
Throws:
org.apache.maven.plugin.MojoExecutionException If there is a problem getting the package name.
    private File getOutputDirectoryString jjtreeInput )
        throws MojoExecutionException
    {
        if (  != null )
        {
            return new File );
        }
        else
        {
            String declaredPackage = JavaCCUtil.getDeclaredPackagenew FilejjtreeInput ) );
            if ( declaredPackage != null )
            {
                return new FiledeclaredPackage );
            }
        }
        return ;
    }

    
Create the argument list to be passed to jjtree on the command line.

Parameters:
jjTreeFilename a String which rappresent the path of the file to compile
Returns:
a String[] that represent the argument to use for JJTree
Throws:
org.apache.maven.plugin.MojoExecutionException if it fails.
    private String[] generateArgumentListString jjTreeFilename )
        throws MojoExecutionException
    {
        ArrayList argsList = new ArrayList();
        if (  != null )
        {
            argsList.add"-BUILD_NODE_FILES=" + .toString() );
        }
        if (  != null )
        {
            argsList.add"-MULTI=" +  );
        }
        if (  != null )
        {
            argsList.add"-NODE_DEFAULT_VOID=" +  );
        }
        if (  != null )
        {
            argsList.add"-NODE_FACTORY=" +  );
        }
        if (  != null )
        {
            argsList.add"-NODE_PACKAGE=" +  );
        }
        if (  != null )
        {
            argsList.add"-NODE_PREFIX=" +  );
        }
        if (  != null )
        {
            argsList.add"-NODE_SCOPE_HOOK=" +  );
        }
        if (  != null )
        {
            argsList.add"-NODE_USES_PARSER=" +  );
        }
        if (  != null )
        {
            argsList.add"-VISITOR=" +  );
        }
        if (  != null )
        {
            argsList.add"-STATIC=" +  );
        }
        if (  != null )
        {
            argsList.add"-VISITOR_EXCEPTION=\'" +  + "\'" );
        }
        argsList.add"-OUTPUT_DIRECTORY:" + getOutputDirectoryjjTreeFilename ) );
        argsList.addjjTreeFilename );
        getLog().debug"argslist: " + argsList.toString() );
        return (String[]) argsList.toArraynew String[argsList.size()] );
    }

    

Returns:
the Set contains a Stringtha rappresent the files to compile
Throws:
org.apache.maven.plugin.MojoExecutionException if it fails
    private Set computeStaleGrammars()
        throws MojoExecutionException
    {
        SuffixMapping mapping = new SuffixMapping".jjt"".jjt" );
        SuffixMapping mappingCAP = new SuffixMapping".JJT"".JJT" );
        SourceInclusionScanner scanner = new StaleSourceScanner );
        scanner.addSourceMappingmapping );
        scanner.addSourceMappingmappingCAP );
        Set staleSources = new HashSet();
        try
        {
            staleSources.addAllscanner.getIncludedSources ) );
        }
        catch ( InclusionScanException e )
        {
            throw new MojoExecutionException"Error scanning source root: \'" +  
                + "\' for stale grammars to reprocess."e );
        }
        return staleSources;
    }
New to GrepCode? Check out our FAQ X