Code clean up. Generated source directory is everywhere set in consistent way now

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115141 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
michal 2004-05-01 14:34:09 +00:00
parent eaa8e84536
commit 262803fb6d
6 changed files with 304 additions and 231 deletions

View File

@ -17,42 +17,31 @@ package org.apache.maven.javacc;
* ==================================================================== * ====================================================================
*/ */
import org.codehaus.plexus.util.FileUtils;
import java.io.File; import java.io.File;
import org.codehaus.plexus.util.FileUtils;
/** /**
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: BaseBean.java,v 1.2 2004/03/02 15:05:55 evenisse Exp $ * @version $Id: BaseBean.java,v 1.3 2004/05/01 14:34:09 michal Exp $
*/ */
public class BaseBean public class BaseBean
{ {
/** /** jjtree or javacc grammar file*/
* jjtree or javacc grammar file
*/
private String grammar; private String grammar;
/** /** the name of the java package which will contain generated files */
* the name of the java package which will contain generated files
*/
private String javaccPackageName; private String javaccPackageName;
private String jjtreePackageName; private String jjtreePackageName;
private String header; private String header ;
private String generatedSourceDirectory; private String generatedSourceDirectory;
public void setGeneratedSourceDirectory( String generatedSourceDirectory )
{
this.generatedSourceDirectory = generatedSourceDirectory;
}
/** /**
* Returns grammar file (javacc of jjtree grammar) * Returns grammar file (javacc of jjtree grammar)
*
* @return grammar file * @return grammar file
*/ */
public String getGrammar() public String getGrammar()
@ -62,7 +51,6 @@ public class BaseBean
/** /**
* Sets grammar file * Sets grammar file
*
* @param grammar * @param grammar
*/ */
public void setGrammar( final String grammar ) public void setGrammar( final String grammar )
@ -73,7 +61,7 @@ public class BaseBean
/** /**
* Sets the name of the java package which will contain generated files * 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 * @param packageName the name of java package e.g com.wombat.parser.ast
*/ */
public void setJavaccPackageName( final String javaccPackageName ) public void setJavaccPackageName( final String javaccPackageName )
{ {
@ -87,7 +75,6 @@ public class BaseBean
{ {
return header; return header;
} }
/** /**
* @param header The header to set. * @param header The header to set.
*/ */
@ -96,45 +83,96 @@ public class BaseBean
this.header = 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 * @return
* @param directory */
public File getJavaccOutputDir()
{
final String packagePath = javaccPackageName.replace( '.', File.separatorChar);
return new File( generatedSourceDirectory, packagePath );
}
/**
*
* @return
*/
public File getJJTreeOutputDir()
{
final String packagePath = jjtreePackageName.replace( '.', File.separatorChar);
return new File( generatedSourceDirectory, packagePath );
}
/**
*
* @throws Exception * @throws Exception
*/ */
protected void addHeader( final File directory ) throws Exception
{
final File headerFile = new File( getHeader() );
if ( headerFile.exists() )
{
final String headerContent = getHeaderContent( );
final File[] generatedFiles = directory.listFiles( );
for ( int i = 0; i < generatedFiles.length; i++ )
{
final File generatedFile = generatedFiles[i];
addHeader( generatedFile, headerContent );
}
}
}
/**
*
* @param headerFile
* @return
*/
protected String getHeaderContent( )
{
try
{
return FileUtils.fileRead( header );
}
catch ( Exception e )
{
return null;
}
}
/**
*
* @param file
* @param header
* @throws Exception
*/
protected void addHeader( final File file, final String headerContent )
throws Exception
{
if (! file.getName().endsWith(".java") )
{
return;
}
String content = FileUtils.fileRead( file.getCanonicalPath() );
content = headerContent + content;
FileUtils.fileWrite( file.getCanonicalPath(), content );
}
public void createTimestampFile( final long timestamp, final File directory ) throws Exception public void createTimestampFile( final long timestamp, final File directory ) throws Exception
{ {
final File timestampFile = new File( directory, ".timestamp" ); final File timestampFile = new File( directory, ".timestamp" );
FileUtils.fileWrite( timestampFile.getAbsolutePath(), "" + timestamp ); FileUtils.fileWrite( timestampFile.getAbsolutePath(), "" + timestamp );
} }
@ -143,20 +181,19 @@ public class BaseBean
return 0; return 0;
} }
/**
* Returns the flag indicating if generator should run
* @return
* @throws Exception
*/
public boolean checkTimestamp() throws Exception public boolean checkTimestamp() throws Exception
{ {
// final File outputDir = getOutputDir(); // final File outputDir = getOutputDir();
// final File grammarFile = new File ( getGrammar() ).getCanonicalFile(); // final File grammarFile = new File ( getGrammar() ).getCanonicalFile();
// final File timestampFile = new File( outputDir, ".timestamp" ); // final File timestampFile = new File( outputDir, ".timestamp" );
// if ( timestampFile.exists() ) // if ( timestampFile.exists() )
// { // {
// long oldTimestamp = readTimestampFile( outputDir ); // long oldTimestamp = readTimestampFile( outputDir );
// if ( oldTimestamp < grammarFile.lastModified() ) // if ( oldTimestamp < grammarFile.lastModified() )
// { // {
// return false; // return false;
@ -173,12 +210,22 @@ public class BaseBean
{ {
return jjtreePackageName; return jjtreePackageName;
} }
/** /**
* @param jjtreePackageName The jjtreePackageName to set. * @param jjtreePackageName The jjtreePackageName to set.
*/ */
public void setJjtreePackageName( String jjtreePackageName ) public void setJjtreePackageName( final String jjtreePackageName )
{ {
this.jjtreePackageName = jjtreePackageName; this.jjtreePackageName = jjtreePackageName;
} }
public String getGeneratedSourceDirectory()
{
return generatedSourceDirectory;
}
public void setGeneratedSourceDirectory( final String generatedSourceDirectory )
{
this.generatedSourceDirectory = generatedSourceDirectory;
}
} }

View File

@ -17,35 +17,41 @@ package org.apache.maven.javacc;
* ==================================================================== * ====================================================================
*/ */
import org.javacc.jjtree.JJTree;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import org.javacc.jjtree.JJTree;
/** /**
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: JJTreeBean.java,v 1.2 2004/03/02 15:05:55 evenisse Exp $ * @version $Id: JJTreeBean.java,v 1.3 2004/05/01 14:34:09 michal Exp $
*/ */
public class JJTreeBean extends BaseBean public class JJTreeBean extends BaseBean
{ {
/** /**
* Generates AST and javacc grammar * Generates AST and javacc grammar
*
* @return * @return
*
* @throws Exception * @throws Exception
*/ */
public int generate() throws Exception public int generate() throws Exception
{ {
final ArrayList params = new ArrayList(); final ArrayList params = new ArrayList();
final File outputDir = getJJTreeOutputDir(); final File outputDir = getJJTreeOutputDir();
System.out.println( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
System.err.println("-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath());
final long timestamp = System.currentTimeMillis(); final long timestamp = System.currentTimeMillis();
System.err.println( "Creating directory: " + outputDir.getCanonicalPath() );
if ( !outputDir.exists() ) if ( !outputDir.exists() )
{ {
System.out.println( "Creating directorty: " + outputDir.getAbsolutePath() );
outputDir.mkdirs(); outputDir.mkdirs();
} }
else else
@ -56,48 +62,66 @@ public class JJTreeBean extends BaseBean
} }
} }
params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() ); params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
params.add( getGrammar() ); params.add( getGrammar() );
String[] args = ( String[] ) params.toArray( new String[params.size()] );
String[] args = ( String[] ) params.toArray( new String[ params.size() ] );
final JJTree jjtree = new JJTree(); final JJTree jjtree = new JJTree();
final int retValue = jjtree.main( args ); final int retValue = jjtree.main( args );
moveJJTJavaParserState(); moveJJTJavaParserState( );
//addHeader( outputDir ); //addHeader( outputDir );
createTimestampFile( timestamp, outputDir ); createTimestampFile( timestamp, outputDir );
return retValue; return retValue;
} }
/** /**
* *
*/ */
private void moveJJTJavaParserState() private void moveJJTJavaParserState( )
{ {
final File jjtJavaParserStateFileOrg = new File( getJJTreeOutputDir(), "JJTJavaParserState.java" ); final File jjtJavaParserStateFileOrg = new File( getJJTreeOutputDir() , "JJTJavaParserState.java" );
final File jjtJavaParserStateFileNew = new File( getJavaccOutputDir(), "JJTJavaParserState.java" );
if ( !jjtJavaParserStateFileOrg.equals( jjtJavaParserStateFileNew ) ) final File jjtJavaParserStateFileNew = new File( getJavaccOutputDir() , "JJTJavaParserState.java" );
if ( ! jjtJavaParserStateFileOrg.equals( jjtJavaParserStateFileNew ) )
{ {
final File dir = jjtJavaParserStateFileNew.getParentFile(); final File dir = jjtJavaParserStateFileNew.getParentFile();
if ( !dir.exists() ) if ( !dir.exists() )
{ {
dir.mkdirs(); dir.mkdirs();
} }
System.out.println( "Moving: " + jjtJavaParserStateFileOrg + " to: " + jjtJavaParserStateFileNew );
System.out.println("Moving: " + jjtJavaParserStateFileOrg +" to: " + jjtJavaParserStateFileNew );
jjtJavaParserStateFileOrg.renameTo( jjtJavaParserStateFileNew ); jjtJavaParserStateFileOrg.renameTo( jjtJavaParserStateFileNew );
} }
} }
/** /**
* Returns the path to generated javacc grammar * Returns the path to generated javacc grammar
*
* @return the path to generated javacc grammar * @return the path to generated javacc grammar
*/ */
public String getJavaccGrammar() public String getJavaccGrammar()
{ {
final File grammarFile = new File( getGrammar() ); final File grammarFile = new File ( getGrammar() );
String grammarName = grammarFile.getName(); String grammarName = grammarFile.getName();
grammarName = grammarName.substring( 0, grammarName.length() - 1 );
final String retValue = getJJTreeOutputDir() + File.separator + grammarName; grammarName = grammarName.substring( 0, grammarName.length()-1 );
final String retValue = getJJTreeOutputDir() + File.separator + grammarName ;
return retValue; return retValue;
} }
} }

View File

@ -25,7 +25,7 @@ import java.util.ArrayList;
/** /**
* *
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: JavaccBean.java,v 1.2 2004/03/02 15:05:55 evenisse Exp $ * @version $Id: JavaccBean.java,v 1.3 2004/05/01 14:34:09 michal Exp $
*/ */
public class JavaccBean extends BaseBean public class JavaccBean extends BaseBean
{ {
@ -34,16 +34,25 @@ public class JavaccBean extends BaseBean
public int generate() throws Exception public int generate() throws Exception
{ {
final ArrayList params = new ArrayList(); final ArrayList params = new ArrayList();
final File outputDir = getJavaccOutputDir(); final File outputDir = getJavaccOutputDir();
if ( !outputDir.exists() ) if ( !outputDir.exists() )
{ {
outputDir.mkdirs(); outputDir.mkdirs();
} }
params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() ); params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
params.add( getGrammar() ); params.add( getGrammar() );
String[] args = ( String[] ) params.toArray( new String[ params.size() ] ); String[] args = ( String[] ) params.toArray( new String[ params.size() ] );
final int retValue = Main.mainProgram( args ); final int retValue = Main.mainProgram( args );
//addHeader( outputDir ); //addHeader( outputDir );
return retValue; return retValue;
} }

View File

@ -1,58 +1,19 @@
package org.apache.maven.javacc; package org.apache.maven.javacc;
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 * Copyright 2001-2004 The Apache Software Foundation.
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights * Licensed under the Apache License, Version 2.0 (the "License");
* reserved. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* *
* Redistribution and use in source and binary forms, with or without * http://www.apache.org/licenses/LICENSE-2.0
* 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/>.
* *
* 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.
* ==================================================================== * ====================================================================
*/ */
@ -61,28 +22,40 @@ import junit.framework.TestCase;
/** /**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @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 $ * @version $Id: BaseBeanTest.java,v 1.2 2004/05/01 14:34:09 michal Exp $
*/ */
public class BaseBeanTest extends TestCase public class BaseBeanTest extends TestCase
{ {
public void testBaseBean() public void testBaseBean()
{ {
final BaseBean bean = new BaseBean(); final BaseBean bean = new BaseBean();
final String grammar = "foo/baa/grammar.txt"; final String grammar = "foo/baa/grammar.txt";
bean.setGrammar( grammar); bean.setGrammar( grammar);
assertEquals( "Grammar file was not set correctly ", grammar, bean
.getGrammar()); assertEquals( "Grammar file was not set correctly ", grammar, bean.getGrammar());
bean.setJavaccPackageName( "com.wombat.javacc"); bean.setJavaccPackageName( "com.wombat.javacc");
bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" );
final String javaccPath = "target" + File.separator + "generated-java" final String fs = File.separator;
+ File.separator + "com" + File.separator + "wombat"
+ File.separator + "javacc"; final String basedir = System.getProperty( "basedir" );
final String gsd = basedir + fs + "target" + fs + "generated-src" + fs + "main" + fs + "java" ;
bean.setGeneratedSourceDirectory( gsd );
final String javaccPath = gsd + fs + "com" + fs + "wombat" + fs + "javacc";
assertEquals( "Output dir not was set correctly", javaccPath, bean.getJavaccOutputDir().getPath() ); assertEquals( "Output dir not was set correctly", javaccPath, bean.getJavaccOutputDir().getPath() );
bean.setJjtreePackageName( "com.wombat.jjtree"); bean.setJjtreePackageName( "com.wombat.jjtree");
final String jjtreePath = "target" + File.separator + "generated-java"
+ File.separator + "com" + File.separator + "wombat" final String jjtreePath = gsd + fs + "com" + fs + "wombat" + fs + "jjtree";
+ File.separator + "jjtree";
assertEquals( "Output dir not was set correctly", jjtreePath, bean.getJJTreeOutputDir().getPath() ); assertEquals( "Output dir not was set correctly", jjtreePath, bean.getJJTreeOutputDir().getPath() );
}} }
}

View File

@ -1,5 +1,22 @@
package org.apache.maven.javacc; package org.apache.maven.javacc;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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 junit.framework.TestCase; import junit.framework.TestCase;
import java.io.File; import java.io.File;
@ -11,34 +28,54 @@ import org.codehaus.plexus.util.FileUtils;
/** /**
* *
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: JJTreeBeanTest.java,v 1.2 2004/02/20 13:23:19 evenisse Exp $ * @version $Id: JJTreeBeanTest.java,v 1.3 2004/05/01 14:34:09 michal Exp $
*/ */
public class JJTreeBeanTest extends TestCase public class JJTreeBeanTest extends TestCase
{ {
public void testGenerate() 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 String basedir = System.getProperty( "basedir" );
final File grammarFile = new File( basedir, "src/test-data/JJTreeSample.jjt" );
final File headerFile = new File( basedir, "src/test-data/JJTreeSample.jjt.header" );
final JJTreeBean bean = new JJTreeBean(); final JJTreeBean bean = new JJTreeBean();
bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" );
bean.setGrammar( grammarFile.getAbsolutePath() ); bean.setGrammar( grammarFile.getAbsolutePath() );
bean.setHeader( headerFile.getAbsolutePath() ); bean.setHeader( headerFile.getAbsolutePath() );
final String packageName = "org.apache.maven.javacc.jtree"; final String packageName = "org.apache.maven.javacc.jtree";
final String fs = File.separator;
final String gsd = basedir + fs + "target" + fs + "generated-src" + fs + "main" + fs + "java" ;
bean.setGeneratedSourceDirectory( gsd );
bean.setJjtreePackageName( packageName ); bean.setJjtreePackageName( packageName );
bean.setJavaccPackageName( packageName ); bean.setJavaccPackageName( packageName );
try try
{ {
FileUtils.deleteDirectory( bean.getJJTreeOutputDir() ); FileUtils.deleteDirectory( bean.getJJTreeOutputDir() );
bean.generate(); bean.generate();
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace(); e.printStackTrace();
fail( "Generation failed" ); fail( "Generation failed" );
} }
final String[] fileNames = bean.getJJTreeOutputDir().list(); final String[] fileNames = bean.getJJTreeOutputDir().list();
final List list = Arrays.asList( fileNames ); final List list = Arrays.asList( fileNames );
assertTrue( list.contains( "JJTreeSample.jj" ) ); assertTrue( list.contains( "JJTreeSample.jj" ) );
} }

View File

@ -1,58 +1,19 @@
package org.apache.maven.javacc; package org.apache.maven.javacc;
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 * Copyright 2001-2004 The Apache Software Foundation.
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights * Licensed under the Apache License, Version 2.0 (the "License");
* reserved. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* *
* Redistribution and use in source and binary forms, with or without * http://www.apache.org/licenses/LICENSE-2.0
* 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/>.
* *
* 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.
* ==================================================================== * ====================================================================
*/ */
@ -67,33 +28,55 @@ import org.codehaus.plexus.util.FileUtils;
/** /**
* *
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: JavaccBeanTest.java,v 1.2 2004/02/20 13:23:19 evenisse Exp $ * @version $Id: JavaccBeanTest.java,v 1.3 2004/05/01 14:34:09 michal Exp $
*/ */
public class JavaccBeanTest extends TestCase public class JavaccBeanTest extends TestCase
{ {
public void testGenerate() 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 String basedir = System.getProperty( "basedir" );
final File grammarFile = new File( basedir, "src/test-data/JavaCCSample.jj" );
final File headerFile = new File( basedir, "src/test-data/JavaCCSample.jj.header" );
final JavaccBean bean = new JavaccBean(); final JavaccBean bean = new JavaccBean();
bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" );
bean.setGrammar( grammarFile.getAbsolutePath() ); bean.setGrammar( grammarFile.getAbsolutePath() );
bean.setHeader( headerFile.getAbsolutePath() ); bean.setHeader( headerFile.getAbsolutePath() );
final String fs = File.separator;
final String gsd = basedir + fs + "target" + fs + "generated-src" + fs + "main" + fs + "java" ;
bean.setGeneratedSourceDirectory( gsd );
final String packageName = "org.apache.maven.javacc.javacc"; final String packageName = "org.apache.maven.javacc.javacc";
bean.setJavaccPackageName( packageName ); bean.setJavaccPackageName( packageName );
try try
{ {
FileUtils.deleteDirectory( bean.getJavaccOutputDir() ); FileUtils.deleteDirectory( bean.getJavaccOutputDir() );
bean.generate(); bean.generate();
} catch ( Exception e )
}
catch ( Exception e )
{ {
e.printStackTrace(); e.printStackTrace();
fail( "Generation failed" ); fail( "Generation failed" );
} }
final String[] fileNames = bean.getJavaccOutputDir().list(); final String[] fileNames = bean.getJavaccOutputDir().list();
final List list = Arrays.asList( fileNames ); final List list = Arrays.asList( fileNames );
assertTrue( list.contains( "Simple1.java" )); assertTrue( list.contains( "Simple1.java" ));
assertTrue( list.contains( "Token.java" )); assertTrue( list.contains( "Token.java" ));