You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2004/01/31 17:29:28 UTC
cvs commit: maven-plugins/javacc/src/main/org/apache/maven/javacc JJTreeBean.java JavaccBean.java BaseBean.java
michal 2004/01/31 08:29:28
Added: javacc/src/test/org/apache/maven/javacc BaseBeanTest.java
JavaccBeanTest.java JJTreeBeanTest.java
javacc/src/test-data JavaCCSample.jj.header JavaCCSample.jj
JJTreeSample.jjt.header JJTreeSample.jjt
javacc/xdocs index.xml navigation.xml properties.xml
changes.xml .cvsignore goals.xml
javacc .cvsignore plugin.properties project.xml
plugin.jelly project.properties
javacc/src/main/org/apache/maven/javacc JJTreeBean.java
JavaccBean.java BaseBean.java
Log:
Initial version of maven plugin for javacc
Revision Changes Path
1.1 maven-plugins/javacc/src/test/org/apache/maven/javacc/BaseBeanTest.java
Index: BaseBeanTest.java
===================================================================
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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import java.io.File;
import junit.framework.TestCase;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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() );
}}
1.1 maven-plugins/javacc/src/test/org/apache/maven/javacc/JavaccBeanTest.java
Index: JavaccBeanTest.java
===================================================================
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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import junit.framework.TestCase;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import org.codehaus.plexus.util.FileUtils;
/**
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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" ));
}
}
1.1 maven-plugins/javacc/src/test/org/apache/maven/javacc/JJTreeBeanTest.java
Index: JJTreeBeanTest.java
===================================================================
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 <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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" ) );
}
}
1.1 maven-plugins/javacc/src/test-data/JavaCCSample.jj.header
Index: JavaCCSample.jj.header
===================================================================
/** javacc BLAH */
1.1 maven-plugins/javacc/src/test-data/JavaCCSample.jj
Index: JavaCCSample.jj
===================================================================
/*
* 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")* <EOF>
}
void MatchedBraces() :
{}
{
"{" [ MatchedBraces() ] "}"
}
1.1 maven-plugins/javacc/src/test-data/JJTreeSample.jjt.header
Index: JJTreeSample.jjt.header
===================================================================
/** jjtree BLAH */
1.1 maven-plugins/javacc/src/test-data/JJTreeSample.jjt
Index: JJTreeSample.jjt
===================================================================
/*
* 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:
<DECIMAL_LITERAL> (["l","L"])?
| <HEX_LITERAL> (["l","L"])?
| <OCTAL_LITERAL> (["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> (<LETTER>|<DIGIT>)* >
|
< #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() : {}
{
<IDENTIFIER>
}
void Integer() : {}
{
<INTEGER_LITERAL>
}
1.1 maven-plugins/javacc/xdocs/index.xml
Index: index.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Maven Javacc Plug-in</title>
<author email="michal.maczka@dimatics.com">Michal Maczka</author>
</properties>
<body>
<section name="Maven Javacc Plug-in">
<p>
This plugin generates code based on user-supplied Javcc/JJtree grammars.
</p>
<p>
For more information on the functionality provided by this plugin,
please see the <a href="goals.html">Goals</a> document.
</p>
<p>
For more information on how to customise the functionality provided
by this plugin, please see the <a href="properties.html">properties</a>
document.
</p>
</section>
</body>
</document>
1.1 maven-plugins/javacc/xdocs/navigation.xml
Index: navigation.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Maven Javacc Plugin">
<title>Maven Javacc Plugin</title>
<body>
<links>
<item name="Maven" href="http://maven.apache.org/"/>
<item name="Javacc" href="https://javacc.dev.java.net/"/>
</links>
<menu name="Overview">
<item name="Goals" href="/goals.html" />
<item name="Properties" href="/properties.html" />
</menu>
<menu name="Downloads">
<item name="Javacc plugin 1.0" href="http://www.ibiblio.org/maven/maven/plugins/maven-javacc-plugin-1.0.jar"/>
</menu>
</body>
</project>
1.1 maven-plugins/javacc/xdocs/properties.xml
Index: properties.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<properties>
<title>Maven Javacc Plugin Properties</title>
<author email="michal.maczka@dimatics.com">Michal Maczka</author>
</properties>
<body>
<section name="Maven Javacc Plugin Settings">
<table>
<tr>
<th>Property name</th>
<th>Optional?</th>
<th>Description</th>
</tr>
<tr>
<td>maven.javacc.javacc.grammar</td>
<td>No</td>
<td>
The javacc grammar file for which code will be generated.
</td>
</tr>
<tr>
<td>maven.javacc.jjtree.grammar</td>
<td>No</td>
<td>
The jtree grammar file for which code will be generated.
</td>
</tr>
<tr>
<td>maven.javacc.javacc.target.dir</td>
<td>No</td>
<td>
Defines where javacc will process .jj files to.
</td>
</tr>
<tr>
<td>maven.javacc.jtree.target.dir</td>
<td>No</td>
<td>
Defines where jtree will process .jjt files to.
</td>
</tr>
</table>
</section>
<section name="Other properties used">
<table>
<tr>
<th>Property name</th>
<th>Optional?</th>
<th>Description</th>
</tr>
<tr>
<td>maven.compile.src.set</td>
<td>Yes</td>
<td>
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
</td>
</tr>
</table>
</section>
</body>
</document>
1.1 maven-plugins/javacc/xdocs/changes.xml
Index: changes.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Changes</title>
<author email="michal.maczka@dinatics.com">Michal Maczka</author>
</properties>
<body>
<release version="1.0" date="IN CVS">
<action dev="michal" type="add">
Initial release
</action>
</release>
</body>
</document>
1.1 maven-plugins/javacc/xdocs/.cvsignore
Index: .cvsignore
===================================================================
stylesheets
1.1 maven-plugins/javacc/xdocs/goals.xml
Index: goals.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Maven Antlr Plug-in Goals</title>
<author email="dion@multitask.com.au">dIon Gillard</author>
</properties>
<body>
<section name="Goals">
<table>
<tr><th>Goal</th><th>Description</th></tr>
<tr>
<td>javacc:javacc-generate</td>
<td>
<p>
Generates code using <b>javaccc</b> tool for the grammar defined in the
<a href="properties.html">${maven.javacc.javacc.grammar}</a>
property.
</p>
<p>
This goal should be called before the <code>java:compile</code>
goal so that code is generated before compilation.
</p>
</td>
</tr>
<tr>
<td>javacc:jjtree-generate</td>
<td>
<p>
Generates code using first <b>jtree</b> then <b>javacc</b> tool for the grammar defined in the
<a href="properties.html">${maven.javacc.jtree.grammar}</a>
property.
</p>
<p>
This goal should be called before the <code>java:compile</code>
goal so that code is generated before compilation.
</p>
</td>
</tr>
</table>
</section>
</body>
</document>
1.1 maven-plugins/javacc/.cvsignore
Index: .cvsignore
===================================================================
target
velocity.log
maven.log
build.properties
*.iml
1.1 maven-plugins/javacc/plugin.properties
Index: plugin.properties
===================================================================
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
1.1 maven-plugins/javacc/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<extend>../project.xml</extend>
<pomVersion>3</pomVersion>
<id>maven-javacc-plugin</id>
<name>Maven Javacc Plugin</name>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<description/>
<shortDescription>Process javacc/jtree grammars</shortDescription>
<url>http://maven.apache.org/reference/plugins/javacc/</url>
<issueTrackingUrl>http://jira.codehaus.org/BrowseProject.jspa?id=10318</issueTrackingUrl>
<siteDirectory>/www/maven.apache.org/reference/plugins/javacc/</siteDirectory>
<repository>
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-plugins/javacc/</connection>
<url>http://cvs.apache.org/viewcvs/maven-plugins/javacc/</url>
</repository>
<developers>
<developer>
<name>Michal Maczka</name>
<id>mmaczka</id>
<email>michal.maczka@dimatics.com</email>
<organization>Dimatics</organization>
<roles>
<role>Creator</role>
<role>Release Manager</role>
<role>Java Developer</role>
</roles>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>javacc</groupId>
<artifactId>javacc</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.0-beta-1</version>
</dependency>
</dependencies>
</project>
1.1 maven-plugins/javacc/plugin.jelly
Index: plugin.jelly
===================================================================
<?xml version="1.0"?>
<project xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
xmlns:maven="jelly:maven"
>
<goal name="javacc:javacc-generate"
description="Generate source from javacc grammar">
<j:set var="packageName" value="${maven.javacc.javacc.package}"/>
<j:if test="${packageName == null or packageName.length() eq 0}">
<j:set var="packageName" value="${pom.package}"/>
</j:if>
<j:useBean var="javacc"
generatedSourceDirectory="${basedir}/target/generated-java"
class="org.apache.maven.javacc.JavaccBean"
javaccPackageName="${packageName}"
grammar="${maven.javacc.javacc.grammar}"
header="${maven.javacc.javacc.header}"
/>
<j:set var="dummy" value="${javacc.generate()}"/>
</goal>
<goal name="javacc:jjtree-generate">
<j:set var="jjtreePackageName" value="${maven.javacc.jjtree.package}"/>
<j:if test="${jjtreePackageName == null or jjtreePackageName.length() eq 0}">
<j:set var="jjtreePackageName" value="${pom.package}"/>
</j:if>
<j:set var="javaccPackageName" value="${maven.javacc.javacc.package}"/>
<j:if test="${javaccPackageName == null or jtreePackageName.length() eq 0}">
<j:set var="javaccPackageName" value="${pom.package}"/>
</j:if>
<echo>javaccPackageName:${javaccPackageName}</echo>
<echo>jjtreePackageName:${jjtreePackageName}</echo>
<j:useBean var="jjtree"
generatedSourceDirectory="${basedir}/target/generated-java"
class="org.apache.maven.javacc.JJTreeBean"
javaccPackageName="${javaccPackageName}"
jjtreePackageName="${jjtreePackageName}"
grammar="${maven.javacc.jjtree.grammar}"
header="${maven.javacc.jjtree.header}"
/>
<j:set var="dummy" value="${jjtree.generate()}"/>
<j:set var="maven.javacc.javacc.grammar" value="${jjtree.javaccGrammar}"/>
<echo>${maven.javacc.javacc.grammar}</echo>
</goal>
<goal name="javacc">
<j:set var="jjtreeGrammar" value="${maven.javacc.jjtree.grammar}"/>
<echo>jjtree grammar: ${jjtreeGrammar}</echo>
<j:if test="${jjtreeGrammar != null and jjtreeGrammar.length() gt 0}">
<attainGoal name="javacc:jjtree-generate"/>
</j:if>
<attainGoal name="javacc:javacc-generate"/>
<ant:path id="maven.javacc.compile.src.set"
location="target/generated/java"/>
<maven:addPath id="maven.compile.src.set"
refid="maven.javacc.compile.src.set"/>
</goal>
</project>
1.1 maven-plugins/javacc/project.properties
Index: project.properties
===================================================================
# -------------------------------------------------------------------
# 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
1.1 maven-plugins/javacc/src/main/org/apache/maven/javacc/JJTreeBean.java
Index: JJTreeBean.java
===================================================================
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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.javacc.jjtree.JJTree;
import java.io.File;
import java.util.ArrayList;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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;
}
}
1.1 maven-plugins/javacc/src/main/org/apache/maven/javacc/JavaccBean.java
Index: JavaccBean.java
===================================================================
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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.javacc.parser.Main;
import java.io.File;
import java.util.ArrayList;
/**
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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;
}
}
1.1 maven-plugins/javacc/src/main/org/apache/maven/javacc/BaseBean.java
Index: BaseBean.java
===================================================================
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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org