diff --git a/javacc/.cvsignore b/javacc/.cvsignore new file mode 100644 index 00000000..9098b4bc --- /dev/null +++ b/javacc/.cvsignore @@ -0,0 +1,5 @@ +target +velocity.log +maven.log +build.properties +*.iml diff --git a/javacc/plugin.jelly b/javacc/plugin.jelly new file mode 100644 index 00000000..cc27f8d3 --- /dev/null +++ b/javacc/plugin.jelly @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + javaccPackageName:${javaccPackageName} + jjtreePackageName:${jjtreePackageName} + + + + + + ${maven.javacc.javacc.grammar} + + + + + + jjtree grammar: ${jjtreeGrammar} + + + + + + + + + + + diff --git a/javacc/plugin.properties b/javacc/plugin.properties new file mode 100644 index 00000000..b70d6576 --- /dev/null +++ b/javacc/plugin.properties @@ -0,0 +1,6 @@ +maven.javacc.javacc.grammar= +maven.javacc.javacc.packageName= +maven.javacc.jjtree.grammar= +maven.javacc.jjtree.packageName= +maven.javacc.jjtree.header=src/main/javacc/jjtree_header +maven.javacc.javacc.header=src/main/javacc/javacc_header diff --git a/javacc/project.properties b/javacc/project.properties new file mode 100644 index 00000000..b9da0814 --- /dev/null +++ b/javacc/project.properties @@ -0,0 +1,7 @@ +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} +maven.license.licenseFile=${basedir}/../LICENSE.txt + diff --git a/javacc/project.xml b/javacc/project.xml new file mode 100644 index 00000000..f553e014 --- /dev/null +++ b/javacc/project.xml @@ -0,0 +1,43 @@ + + + + ../project.xml + 3 + maven-javacc-plugin + Maven Javacc Plugin + 1.0-SNAPSHOT + + Process javacc/jtree grammars + http://maven.apache.org/reference/plugins/javacc/ + http://jira.codehaus.org/BrowseProject.jspa?id=10318 + /www/maven.apache.org/reference/plugins/javacc/ + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-plugins/javacc/ + http://cvs.apache.org/viewcvs/maven-plugins/javacc/ + + + + Michal Maczka + mmaczka + michal.maczka@dimatics.com + Dimatics + + Creator + Release Manager + Java Developer + + + + + + javacc + javacc + 3.2 + + + plexus + plexus-utils + 1.0-beta-1 + + + diff --git a/javacc/src/main/org/apache/maven/javacc/BaseBean.java b/javacc/src/main/org/apache/maven/javacc/BaseBean.java new file mode 100644 index 00000000..1aae3cb4 --- /dev/null +++ b/javacc/src/main/org/apache/maven/javacc/BaseBean.java @@ -0,0 +1,223 @@ +package org.apache.maven.javacc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; + + +/** + * @author Michal Maczka + * @version $Id: BaseBean.java,v 1.1 2004/01/31 16:29:28 michal Exp $ + */ +public class BaseBean +{ + /** + * jjtree or javacc grammar file + */ + private String grammar; + + /** + * the name of the java package which will contain generated files + */ + private String javaccPackageName; + + private String jjtreePackageName; + + private String header; + + + private String generatedSourceDirectory; + + public void setGeneratedSourceDirectory( String generatedSourceDirectory ) + { + this.generatedSourceDirectory = generatedSourceDirectory; + } + + /** + * Returns grammar file (javacc of jjtree grammar) + * + * @return grammar file + */ + public String getGrammar() + { + return grammar; + } + + /** + * Sets grammar file + * + * @param grammar + */ + public void setGrammar( final String grammar ) + { + this.grammar = grammar; + } + + /** + * Sets the name of the java package which will contain generated files + * + * @param javaccPackageName the name of java package e.g com.wombat.parser.ast + */ + public void setJavaccPackageName( final String javaccPackageName ) + { + this.javaccPackageName = javaccPackageName; + } + + /** + * @return Returns the header. + */ + public String getHeader() + { + return header; + } + + /** + * @param header The header to set. + */ + public void setHeader( final String header ) + { + this.header = header; + } + + /** + * @return + */ + public File getJavaccOutputDir() + { + final String packagePath = javaccPackageName + .replace( '.', File.separatorChar ); + + final File retValue = new File( getGeneratedSourceDirectory(), packagePath ); + return retValue; + + } + + public String getGeneratedSourceDirectory() + { + return generatedSourceDirectory; + } + + /** + * @return + */ + public File getJJTreeOutputDir() + { + final String packagePath = jjtreePackageName + .replace( '.', File.separatorChar ); + return new File( getGeneratedSourceDirectory(), packagePath ); + } + + + + /** + * + * @param timestamp + * @param directory + * @throws Exception + */ + public void createTimestampFile( final long timestamp, final File directory ) throws Exception + { + final File timestampFile = new File( directory, ".timestamp" ); + FileUtils.fileWrite( timestampFile.getAbsolutePath(), "" + timestamp ); + } + + public long readTimestampFile( final File directory ) + { + return 0; + } + + + /** + * Returns the flag indicating if generator should run + * @return + * @throws Exception + */ + public boolean checkTimestamp() throws Exception + { +// final File outputDir = getOutputDir(); +// final File grammarFile = new File ( getGrammar() ).getCanonicalFile(); +// final File timestampFile = new File( outputDir, ".timestamp" ); +// if ( timestampFile.exists() ) +// { +// long oldTimestamp = readTimestampFile( outputDir ); +// if ( oldTimestamp < grammarFile.lastModified() ) +// { +// return false; +// } +// } + return true; + } + + + /** + * @return Returns the jjtreePackageName. + */ + public String getJjtreePackageName() + { + return jjtreePackageName; + } + + /** + * @param jjtreePackageName The jjtreePackageName to set. + */ + public void setJjtreePackageName( String jjtreePackageName ) + { + this.jjtreePackageName = jjtreePackageName; + } +} diff --git a/javacc/src/main/org/apache/maven/javacc/JJTreeBean.java b/javacc/src/main/org/apache/maven/javacc/JJTreeBean.java new file mode 100644 index 00000000..44cb01f5 --- /dev/null +++ b/javacc/src/main/org/apache/maven/javacc/JJTreeBean.java @@ -0,0 +1,142 @@ +package org.apache.maven.javacc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.javacc.jjtree.JJTree; + +import java.io.File; +import java.util.ArrayList; + +/** + * @author Michal Maczka + * @version $Id: JJTreeBean.java,v 1.1 2004/01/31 16:29:28 michal Exp $ + */ +public class JJTreeBean extends BaseBean +{ + + /** + * Generates AST and javacc grammar + * + * @return + * + * @throws Exception + */ + public int generate() throws Exception + { + final ArrayList params = new ArrayList(); + final File outputDir = getJJTreeOutputDir(); + System.out.println( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() ); + + final long timestamp = System.currentTimeMillis(); + + if ( !outputDir.exists() ) + { + outputDir.mkdirs(); + } + else + { + if ( !checkTimestamp() ) + { + return 0; + } + } + params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() ); + params.add( getGrammar() ); + String[] args = ( String[] ) params.toArray( new String[params.size()] ); + final JJTree jjtree = new JJTree(); + final int retValue = jjtree.main( args ); + + moveJJTJavaParserState(); + //addHeader( outputDir ); + createTimestampFile( timestamp, outputDir ); + return retValue; + } + + /** + * + */ + private void moveJJTJavaParserState() + { + final File jjtJavaParserStateFileOrg = new File( getJJTreeOutputDir(), "JJTJavaParserState.java" ); + final File jjtJavaParserStateFileNew = new File( getJavaccOutputDir(), "JJTJavaParserState.java" ); + if ( !jjtJavaParserStateFileOrg.equals( jjtJavaParserStateFileNew ) ) + { + final File dir = jjtJavaParserStateFileNew.getParentFile(); + if ( !dir.exists() ) + { + dir.mkdirs(); + } + System.out.println( "Moving: " + jjtJavaParserStateFileOrg + " to: " + jjtJavaParserStateFileNew ); + jjtJavaParserStateFileOrg.renameTo( jjtJavaParserStateFileNew ); + } + } + + /** + * Returns the path to generated javacc grammar + * + * @return the path to generated javacc grammar + */ + public String getJavaccGrammar() + { + final File grammarFile = new File( getGrammar() ); + String grammarName = grammarFile.getName(); + grammarName = grammarName.substring( 0, grammarName.length() - 1 ); + final String retValue = getJJTreeOutputDir() + File.separator + grammarName; + return retValue; + } + +} diff --git a/javacc/src/main/org/apache/maven/javacc/JavaccBean.java b/javacc/src/main/org/apache/maven/javacc/JavaccBean.java new file mode 100644 index 00000000..4bc20f1c --- /dev/null +++ b/javacc/src/main/org/apache/maven/javacc/JavaccBean.java @@ -0,0 +1,90 @@ +package org.apache.maven.javacc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.javacc.parser.Main; + +import java.io.File; +import java.util.ArrayList; + +/** + * + * @author Michal Maczka + * @version $Id: JavaccBean.java,v 1.1 2004/01/31 16:29:28 michal Exp $ + */ +public class JavaccBean extends BaseBean +{ + + + public int generate() throws Exception + { + final ArrayList params = new ArrayList(); + final File outputDir = getJavaccOutputDir(); + if ( !outputDir.exists() ) + { + outputDir.mkdirs(); + } + params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() ); + params.add( getGrammar() ); + String[] args = ( String[] ) params.toArray( new String[ params.size() ] ); + final int retValue = Main.mainProgram( args ); + //addHeader( outputDir ); + return retValue; + } + + +} diff --git a/javacc/src/test-data/JJTreeSample.jjt b/javacc/src/test-data/JJTreeSample.jjt new file mode 100644 index 00000000..5adbf207 --- /dev/null +++ b/javacc/src/test-data/JJTreeSample.jjt @@ -0,0 +1,115 @@ + +/* + * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has + * intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, + * these intellectual property rights may include one or more of the U.S. + * patents listed at http://www.sun.com/patents and one or more additional + * patents or pending patent applications in the U.S. and in other countries. + * U.S. Government Rights - Commercial software. Government users are subject + * to the Sun Microsystems, Inc. standard license agreement and applicable + * provisions of the FAR and its supplements. Use is subject to license terms. + * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered + * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This + * product is covered and controlled by U.S. Export Control laws and may be + * subject to the export or import laws in other countries. Nuclear, missile, + * chemical biological weapons or nuclear maritime end uses or end users, + * whether direct or indirect, are strictly prohibited. Export or reexport + * to countries subject to U.S. embargo or to entities identified on U.S. + * export exclusion lists, including, but not limited to, the denied persons + * and specially designated nationals lists is strictly prohibited. + */ + + +PARSER_BEGIN(eg1) + +class eg1 { + public static void main(String args[]) { + System.out.println("Reading from standard input..."); + eg1 t = new eg1(System.in); + try { + SimpleNode n = t.Start(); + n.dump(""); + System.out.println("Thank you."); + } catch (Exception e) { + System.out.println("Oops."); + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } +} + +PARSER_END(eg1) + + +SKIP : +{ + " " +| "\t" +| "\n" +| "\r" +| <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> +| <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/"> +} + +TOKEN : /* LITERALS */ +{ + < INTEGER_LITERAL: + (["l","L"])? + | (["l","L"])? + | (["l","L"])? + > +| + < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > +| + < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > +| + < #OCTAL_LITERAL: "0" (["0"-"7"])* > +} + +TOKEN : /* IDENTIFIERS */ +{ + < IDENTIFIER: (|)* > +| + < #LETTER: ["_","a"-"z","A"-"Z"] > +| + < #DIGIT: ["0"-"9"] > +} + +SimpleNode Start() : {} +{ + Expression() ";" + { return jjtThis; } +} + + +void Expression() : {} +{ + AdditiveExpression() +} + +void AdditiveExpression() : {} +{ + MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* +} + +void MultiplicativeExpression() : {} +{ + UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )* +} + +void UnaryExpression() : {} +{ + "(" Expression() ")" | Identifier() | Integer() +} + +void Identifier() : {} +{ + +} + +void Integer() : {} +{ + +} diff --git a/javacc/src/test-data/JJTreeSample.jjt.header b/javacc/src/test-data/JJTreeSample.jjt.header new file mode 100644 index 00000000..5f4cde35 --- /dev/null +++ b/javacc/src/test-data/JJTreeSample.jjt.header @@ -0,0 +1 @@ +/** jjtree BLAH */ diff --git a/javacc/src/test-data/JavaCCSample.jj b/javacc/src/test-data/JavaCCSample.jj new file mode 100644 index 00000000..274305ef --- /dev/null +++ b/javacc/src/test-data/JavaCCSample.jj @@ -0,0 +1,68 @@ + +/* + * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has + * intellectual property rights relating to technology embodied in the product + * that is described in this document. In particular, and without limitation, + * these intellectual property rights may include one or more of the U.S. + * patents listed at http://www.sun.com/patents and one or more additional + * patents or pending patent applications in the U.S. and in other countries. + * U.S. Government Rights - Commercial software. Government users are subject + * to the Sun Microsystems, Inc. standard license agreement and applicable + * provisions of the FAR and its supplements. Use is subject to license terms. + * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered + * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This + * product is covered and controlled by U.S. Export Control laws and may be + * subject to the export or import laws in other countries. Nuclear, missile, + * chemical biological weapons or nuclear maritime end uses or end users, + * whether direct or indirect, are strictly prohibited. Export or reexport + * to countries subject to U.S. embargo or to entities identified on U.S. + * export exclusion lists, including, but not limited to, the denied persons + * and specially designated nationals lists is strictly prohibited. + */ + + +options { + LOOKAHEAD = 1; + CHOICE_AMBIGUITY_CHECK = 2; + OTHER_AMBIGUITY_CHECK = 1; + STATIC = true; + DEBUG_PARSER = false; + DEBUG_LOOKAHEAD = false; + DEBUG_TOKEN_MANAGER = false; + ERROR_REPORTING = true; + JAVA_UNICODE_ESCAPE = false; + UNICODE_INPUT = false; + IGNORE_CASE = false; + USER_TOKEN_MANAGER = false; + USER_CHAR_STREAM = false; + BUILD_PARSER = true; + BUILD_TOKEN_MANAGER = true; + SANITY_CHECK = true; + FORCE_LA_CHECK = false; +} + +PARSER_BEGIN(Simple1) + +public class Simple1 { + + public static void main(String args[]) throws ParseException { + Simple1 parser = new Simple1(System.in); + parser.Input(); + } + +} + +PARSER_END(Simple1) + +void Input() : +{} +{ + MatchedBraces() ("\n"|"\r")* +} + +void MatchedBraces() : +{} +{ + "{" [ MatchedBraces() ] "}" +} diff --git a/javacc/src/test-data/JavaCCSample.jj.header b/javacc/src/test-data/JavaCCSample.jj.header new file mode 100644 index 00000000..1fa9d92c --- /dev/null +++ b/javacc/src/test-data/JavaCCSample.jj.header @@ -0,0 +1 @@ +/** javacc BLAH */ diff --git a/javacc/src/test/org/apache/maven/javacc/BaseBeanTest.java b/javacc/src/test/org/apache/maven/javacc/BaseBeanTest.java new file mode 100644 index 00000000..c66f1e75 --- /dev/null +++ b/javacc/src/test/org/apache/maven/javacc/BaseBeanTest.java @@ -0,0 +1,88 @@ +package org.apache.maven.javacc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.File; +import junit.framework.TestCase; + +/** + * @author Michal Maczka + * @version $Id: BaseBeanTest.java,v 1.1 2004/01/31 16:29:27 michal Exp $ + */ +public class BaseBeanTest extends TestCase +{ +public void testBaseBean() + + { + final BaseBean bean = new BaseBean(); + final String grammar = "foo/baa/grammar.txt"; + bean.setGrammar( grammar); + assertEquals( "Grammar file was not set correctly ", grammar, bean + .getGrammar()); + bean.setJavaccPackageName( "com.wombat.javacc"); + bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" ); + final String javaccPath = "target" + File.separator + "generated-java" + + File.separator + "com" + File.separator + "wombat" + + File.separator + "javacc"; + assertEquals( "Output dir not was set correctly", javaccPath, bean.getJavaccOutputDir().getPath() ); + bean.setJjtreePackageName( "com.wombat.jjtree"); + final String jjtreePath = "target" + File.separator + "generated-java" + + File.separator + "com" + File.separator + "wombat" + + File.separator + "jjtree"; + assertEquals( "Output dir not was set correctly", jjtreePath, bean.getJJTreeOutputDir().getPath() ); + + }} diff --git a/javacc/src/test/org/apache/maven/javacc/JJTreeBeanTest.java b/javacc/src/test/org/apache/maven/javacc/JJTreeBeanTest.java new file mode 100644 index 00000000..e484de54 --- /dev/null +++ b/javacc/src/test/org/apache/maven/javacc/JJTreeBeanTest.java @@ -0,0 +1,44 @@ +package org.apache.maven.javacc; + +import junit.framework.TestCase; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import org.codehaus.plexus.util.FileUtils; + +/** + * + * @author Michal Maczka + * @version $Id: JJTreeBeanTest.java,v 1.1 2004/01/31 16:29:27 michal Exp $ + */ +public class JJTreeBeanTest extends TestCase +{ + public void testGenerate() + { + final File grammarFile = new File( System.getProperty( "basedir" ), "src/test-data/JJTreeSample.jjt" ); + final File headerFile = new File( System.getProperty( "basedir" ), "src/test-data/JJTreeSample.jjt.header" ); + final JJTreeBean bean = new JJTreeBean(); + bean.setGrammar( grammarFile.getAbsolutePath() ); + bean.setHeader( headerFile.getAbsolutePath() ); + final String packageName = "org.apache.maven.javacc.jtree"; + bean.setJjtreePackageName( packageName ); + bean.setJavaccPackageName( packageName ); + try + { + FileUtils.deleteDirectory( bean.getJJTreeOutputDir() ); + bean.generate(); + } + catch ( Exception e ) + { + e.printStackTrace(); + fail( "Generation failed" ); + + } + final String[] fileNames = bean.getJJTreeOutputDir().list(); + final List list = Arrays.asList( fileNames ); + assertTrue( list.contains( "JJTreeSample.jj" ) ); + } + +} diff --git a/javacc/src/test/org/apache/maven/javacc/JavaccBeanTest.java b/javacc/src/test/org/apache/maven/javacc/JavaccBeanTest.java new file mode 100644 index 00000000..cdcff17e --- /dev/null +++ b/javacc/src/test/org/apache/maven/javacc/JavaccBeanTest.java @@ -0,0 +1,102 @@ +package org.apache.maven.javacc; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import junit.framework.TestCase; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import org.codehaus.plexus.util.FileUtils; + +/** + * + * @author Michal Maczka + * @version $Id: JavaccBeanTest.java,v 1.1 2004/01/31 16:29:27 michal Exp $ + */ +public class JavaccBeanTest extends TestCase +{ + public void testGenerate() + { + final File grammarFile = new File( System.getProperty( "basedir" ), "src/test-data/JavaCCSample.jj" ); + final File headerFile = new File( System.getProperty( "basedir" ), "src/test-data/JavaCCSample.jj.header" ); + final JavaccBean bean = new JavaccBean(); + bean.setGrammar( grammarFile.getAbsolutePath() ); + bean.setHeader( headerFile.getAbsolutePath() ); + final String packageName = "org.apache.maven.javacc.javacc"; + bean.setJavaccPackageName( packageName ); + try + { + FileUtils.deleteDirectory( bean.getJavaccOutputDir() ); + bean.generate(); + } catch ( Exception e ) + { + e.printStackTrace(); + fail( "Generation failed" ); + + } + final String[] fileNames = bean.getJavaccOutputDir().list(); + final List list = Arrays.asList( fileNames ); + assertTrue( list.contains( "Simple1.java" )); + assertTrue( list.contains( "Token.java" )); + + + } + + +} diff --git a/javacc/xdocs/.cvsignore b/javacc/xdocs/.cvsignore new file mode 100644 index 00000000..cb6131bb --- /dev/null +++ b/javacc/xdocs/.cvsignore @@ -0,0 +1 @@ +stylesheets diff --git a/javacc/xdocs/changes.xml b/javacc/xdocs/changes.xml new file mode 100644 index 00000000..861264c1 --- /dev/null +++ b/javacc/xdocs/changes.xml @@ -0,0 +1,16 @@ + + + + Changes + Michal Maczka + + + + + + Initial release + + + + + diff --git a/javacc/xdocs/goals.xml b/javacc/xdocs/goals.xml new file mode 100644 index 00000000..5c6bedfb --- /dev/null +++ b/javacc/xdocs/goals.xml @@ -0,0 +1,44 @@ + + + + + Maven Antlr Plug-in Goals + dIon Gillard + + + +
+ + + + + + + + + + +
GoalDescription
javacc:javacc-generate +

+ Generates code using javaccc tool for the grammar defined in the + ${maven.javacc.javacc.grammar} + property. +

+

+ This goal should be called before the java:compile + goal so that code is generated before compilation. +

+
javacc:jjtree-generate +

+ Generates code using first jtree then javacc tool for the grammar defined in the + ${maven.javacc.jtree.grammar} + property. +

+

+ This goal should be called before the java:compile + goal so that code is generated before compilation. +

+
+
+ +
diff --git a/javacc/xdocs/index.xml b/javacc/xdocs/index.xml new file mode 100644 index 00000000..f4c31fbc --- /dev/null +++ b/javacc/xdocs/index.xml @@ -0,0 +1,25 @@ + + + + + Maven Javacc Plug-in + Michal Maczka + + + +
+

+ This plugin generates code based on user-supplied Javcc/JJtree grammars. +

+

+ For more information on the functionality provided by this plugin, + please see the Goals document. +

+

+ For more information on how to customise the functionality provided + by this plugin, please see the properties + document. +

+
+ +
diff --git a/javacc/xdocs/navigation.xml b/javacc/xdocs/navigation.xml new file mode 100644 index 00000000..b401a4b2 --- /dev/null +++ b/javacc/xdocs/navigation.xml @@ -0,0 +1,19 @@ + + + + Maven Javacc Plugin + + + + + + + + + + + + + + + diff --git a/javacc/xdocs/properties.xml b/javacc/xdocs/properties.xml new file mode 100644 index 00000000..7860fe0a --- /dev/null +++ b/javacc/xdocs/properties.xml @@ -0,0 +1,66 @@ + + + + + Maven Javacc Plugin Properties + Michal Maczka + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Property nameOptional?Description
maven.javacc.javacc.grammarNo + The javacc grammar file for which code will be generated. +
maven.javacc.jjtree.grammarNo + The jtree grammar file for which code will be generated. +
maven.javacc.javacc.target.dirNo + Defines where javacc will process .jj files to. +
maven.javacc.jtree.target.dirNo + Defines where jtree will process .jjt files to. +
+
+
+ + + + + + + + + + + +
Property nameOptional?Description
maven.compile.src.setYes + The source directories maven uses to compile java code. + The javacc plugin adds the directory it generates code to + this path, so that generated code is compiled seamlessly +
+
+ +
\ No newline at end of file