1 package org.apache.maven.javacc;
2
3 /* ====================================================================
4 * Copyright 2001-2004 The Apache Software Foundation.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19
20 import java.io.File;
21
22 import java.util.ArrayList;
23
24 import org.javacc.parser.Main;
25
26 /**
27 *
28 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
29 * @version $Id: JavaccBean.java 373246 2006-01-28 21:11:33Z ltheussl $
30 */
31 public class JavaccBean extends BaseBean
32 {
33 /**
34 * Generates javacc grammar
35 * @return The value returned by org.javacc.parser.Main.mainProgram( String[] )
36 * @throws Exception Exception
37 */
38 public int generate() throws Exception
39 {
40 final ArrayList params = new ArrayList();
41
42 final File outputDir = getJavaccOutputDir();
43
44 if ( !outputDir.exists() )
45 {
46 outputDir.mkdirs();
47 }
48
49 params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
50
51 params.add( getGrammar() );
52
53 String[] args =
54 (String[]) params.toArray( new String[params.size()] );
55
56 final int retValue = Main.mainProgram( args );
57
58 //addHeader( outputDir );
59 return retValue;
60 }
61 }