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.util.Set;
 

Author(s):
jruiz@exist.com
jesse <jesse.mcconnell@gmail.com>
Version:
$Id: JavaCCMojo.java 5340 2007-10-12 19:26:31Z jesse $
Goal:
javacc
Phase:
generate-sources
Description:
Goal which parse a JJ file and transform it to Java Source Files.
 
 public class JavaCCMojo extends AbstractMojo
 {
    

Parameter:
expression=${lookAhead}"
 
     private Integer lookAhead;

    

Parameter:
expression="${choiceAmbiguityCheck}"
 
     private Integer choiceAmbiguityCheck;

    

Parameter:
expression=${otherAmbiguityCheck}"
 
     private Integer otherAmbiguityCheck;

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    

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

    
Package into which the generated classes will be put. Note that this will also be used to create the directory structure where shources will be generated.

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

    
Directory where the JJ file(s) are located.

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

    
Directory where the output Java Files will be located.

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

    
The directory to store the processed .jj files

Parameter:
expression="${project.build.directory}/generated-sources/javacc-timestamp"
    private String 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;
    
    

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

    

Parameter:
expression="${basedir}"
Required:
Readonly:
    private File baseDir;
    
    
Execute the JavaCC compiler

    public void execute() throws MojoExecutionException
    {
        File sourceDir = new File();
        if (!sourceDir.exists()) 
        {
            getLog().warn("Source directory '" +  + "' does not exist. Skipping...");
            return;
        }
        
        // check packageName for . vs /
        if (  != null )
        {
             = StringUtils.replace'.'. );
        }
        if ( !FileUtils.fileExists ) )
        {
            if (  != null )
            {
                FileUtils.mkdir + . +  );
            }
            else
            {
                FileUtils.mkdir );
            }
        }
        
        if ( ! .startsWith(.) )
        {
        }
        if ( !FileUtils.fileExists ) )
        {
            FileUtils.mkdir );
        }
        if (  == null )
        {
             = Collections.singleton"**/*" );
        }
        
        if (  == null )
        {
             = .;
        }
        
        Set staleGrammars = computeStaleGrammars();
        if ( staleGrammars.isEmpty() )
        {
            getLog().info("Nothing to process - all grammars in " +  + " are up to date.");            
        }
        else
        {
            // Copy all .java file from sourceDirectory to outputDirectory, in
            // order to override Token.java
            try
            {
                if (  != null )
                {
                    FileUtils.copyDirectorynew File ), new File + .
                            +  ), "*.java""*.jj,*.JJ" );
                }
                else
                {
                    FileUtils.copyDirectorynew File ), new File ), "*.java",
                            "*.jj,*.JJ" );
                }
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException"Unable to copy overriden java files."e );
            }
            for ( Iterator i = staleGrammars.iterator(); i.hasNext(); )
            {
                File javaccFile = (Filei.next();
                try
                {
                    org.javacc.parser.Main.mainProgramgenerateJavaCCArgumentListjavaccFile.getAbsolutePath() ) );
                    String timestampFilePath = javaccFile.getAbsolutePath().replace("");
                    FileUtils.copyFile(javaccFilenew File( + . + timestampFilePath));
                }
                catch ( Exception e )
                {
                    throw new MojoExecutionException"JavaCC execution failed"e );
                }
            }
        }
        if (  != null )
        {
            .addCompileSourceRoot );
        }
    }
    
    

Parameters:
javaccInput a String which rappresent the path of the file to compile
Returns:
a String[] that represent the argument to use for JavaCC
    private String[] generateJavaCCArgumentListString javaccInput )
        throws MojoExecutionException
    {
        ArrayList argsList = new ArrayList();
        if (  != null )
        {
            argsList.add"-LOOKAHEAD=" +  );
        }
        if (  != null )
        {
            argsList.add"-CHOICE_AMBIGUITY_CHECK=" +  );
        }
        if (  != null )
        {
            argsList.add"-OTHER_AMBIGUITY_CHECK=" +  );
        }
        if (  != null )
        {
            argsList.add"-STATIC=" +  );
        }
        if (  != null )
        {
            argsList.add"-DEBUG_PARSER=" +  );
        }
        if (  != null )
        {
            argsList.add"-DEBUG_LOOKAHEAD=" +  );
        }
        if (  != null )
        {
            argsList.add"-DEBUG_TOKEN_MANAGER=" +  );
        }
        if (  != null )
        {
            argsList.add"-OPTIMIZE_TOKEN_MANAGER=" +  );
        }
        if (  != null )
        {
            argsList.add"-ERROR_REPORTING=" +  );
        }
        if (  != null )
        {
            argsList.add"-JAVA_UNICODE_ESCAPE=" +  );
        }
        if (  != null )
        {
            argsList.add"-UNICODE_INPUT=" +  );
        }
        if (  != null )
        {
            argsList.add"-IGNORE_CASE=" +  );
        }
        if (  != null )
        {
            argsList.add"-COMMON_TOKEN_ACTION=" +  );
        }
        if (  != null )
        {
            argsList.add"-USER_TOKEN_MANAGER=" +  );
        }
        if (  != null )
        {
            argsList.add"-USER_CHAR_STREAM=" +  );
        }
        if (  != null )
        {
            argsList.add"-BUILD_PARSER=" +  );
        }
        if (  != null )
        {
            argsList.add"-BUILD_TOKEN_MANAGER=" +  );
        }
        if (  != null )
        {
            argsList.add"-SANITY_CHECK=" +  );
        }
        if (  != null )
        {
            argsList.add"-FORCE_LA_CHECK=" +  );
        }
        if (  != null )
        {
            argsList.add"-CACHE_TOKENS=" +  );
        }
        if (  != null )
        {
            argsList.add"-KEEP_LINE_COLUMN=" +  );
        }
        if (  != null )
        {
            argsList.add"-OUTPUT_DIRECTORY:" +  + . +  );
        }
        else
        {
            String declaredPackage = JavaCCUtil.getDeclaredPackagejavaccInput );
            
            if (declaredPackage != null)
            {
                argsList.add("-OUTPUT_DIRECTORY:" +  + . + declaredPackage);
            }
            else
            {
                argsList.add("-OUTPUT_DIRECTORY:" + );
            }            
        }
        argsList.addjavaccInput );
        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
    
    {
        SuffixMapping mapping = new SuffixMapping".jj"".jj" );
        SuffixMapping mappingCAP = new SuffixMapping".JJ"".JJ" );
        SourceInclusionScanner scanner = new StaleSourceScanner );
        scanner.addSourceMappingmapping );
        scanner.addSourceMappingmappingCAP );
        File outDir = new File );
        Set staleSources = new HashSet();
        File sourceDir = new File );
        try
        {
            staleSources.addAllscanner.getIncludedSourcessourceDiroutDir ) );
        }
        catch ( InclusionScanException e )
        {
            throw new MojoExecutionException"Error scanning source root: \'" + sourceDir
                    + "\' for stale grammars to reprocess."e );
        }
        return staleSources;
    }
New to GrepCode? Check out our FAQ X