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/05/01 16:34:09 UTC
cvs commit: maven-plugins/javacc/src/main/org/apache/maven/javacc JJTreeBean.java JavaccBean.java BaseBean.java
michal 2004/05/01 07:34:09
Modified: javacc/src/test/org/apache/maven/javacc BaseBeanTest.java
JJTreeBeanTest.java JavaccBeanTest.java
javacc/src/main/org/apache/maven/javacc JJTreeBean.java
JavaccBean.java BaseBean.java
Log:
Code clean up. Generated source directory is everywhere set in consistent way now
Revision Changes Path
1.2 +37 -64 maven-plugins/javacc/src/test/org/apache/maven/javacc/BaseBeanTest.java
Index: BaseBeanTest.java
===================================================================
RCS file: /home/cvs/maven-plugins/javacc/src/test/org/apache/maven/javacc/BaseBeanTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseBeanTest.java 31 Jan 2004 16:29:27 -0000 1.1
+++ BaseBeanTest.java 1 May 2004 14:34:09 -0000 1.2
@@ -1,58 +1,19 @@
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/>.
+ * 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.
* ====================================================================
*/
@@ -65,24 +26,36 @@
*/
public class BaseBeanTest extends TestCase
{
-public void testBaseBean()
-
- {
+ 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());
+
+ 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";
+
+ final String fs = File.separator;
+
+ 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() );
+
bean.setJjtreePackageName( "com.wombat.jjtree");
- final String jjtreePath = "target" + File.separator + "generated-java"
- + File.separator + "com" + File.separator + "wombat"
- + File.separator + "jjtree";
+
+ final String jjtreePath = gsd + fs + "com" + fs + "wombat" + fs + "jjtree";
+
assertEquals( "Output dir not was set correctly", jjtreePath, bean.getJJTreeOutputDir().getPath() );
- }}
+ }
+
+}
1.3 +41 -4 maven-plugins/javacc/src/test/org/apache/maven/javacc/JJTreeBeanTest.java
Index: JJTreeBeanTest.java
===================================================================
RCS file: /home/cvs/maven-plugins/javacc/src/test/org/apache/maven/javacc/JJTreeBeanTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JJTreeBeanTest.java 20 Feb 2004 13:23:19 -0000 1.2
+++ JJTreeBeanTest.java 1 May 2004 14:34:09 -0000 1.3
@@ -1,5 +1,22 @@
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 java.io.File;
@@ -17,28 +34,48 @@
{
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();
- bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" );
+
bean.setGrammar( grammarFile.getAbsolutePath() );
+
bean.setHeader( headerFile.getAbsolutePath() );
+
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.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.3 +39 -56 maven-plugins/javacc/src/test/org/apache/maven/javacc/JavaccBeanTest.java
Index: JavaccBeanTest.java
===================================================================
RCS file: /home/cvs/maven-plugins/javacc/src/test/org/apache/maven/javacc/JavaccBeanTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaccBeanTest.java 20 Feb 2004 13:23:19 -0000 1.2
+++ JavaccBeanTest.java 1 May 2004 14:34:09 -0000 1.3
@@ -1,58 +1,19 @@
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/>.
+ * 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.
* ====================================================================
*/
@@ -73,27 +34,49 @@
{
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();
- bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" );
+
bean.setGrammar( grammarFile.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";
+
bean.setJavaccPackageName( packageName );
+
try
{
FileUtils.deleteDirectory( bean.getJavaccOutputDir() );
+
bean.generate();
- } catch ( Exception e )
+
+ }
+ 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.3 +68 -44 maven-plugins/javacc/src/main/org/apache/maven/javacc/JJTreeBean.java
Index: JJTreeBean.java
===================================================================
RCS file: /home/cvs/maven-plugins/javacc/src/main/org/apache/maven/javacc/JJTreeBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JJTreeBean.java 2 Mar 2004 15:05:55 -0000 1.2
+++ JJTreeBean.java 1 May 2004 14:34:09 -0000 1.3
@@ -17,87 +17,111 @@
* ====================================================================
*/
-import org.javacc.jjtree.JJTree;
-
import java.io.File;
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$
*/
public class JJTreeBean extends BaseBean
{
-
+
/**
* Generates AST and javacc grammar
- *
- * @return
- *
- * @throws Exception
+ * @return
+ * @throws Exception
*/
public int generate() throws Exception
- {
+ {
final ArrayList params = new ArrayList();
+
final File outputDir = getJJTreeOutputDir();
- System.out.println( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
-
+
+ System.err.println("-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath());
+
final long timestamp = System.currentTimeMillis();
-
+
+ System.err.println( "Creating directory: " + outputDir.getCanonicalPath() );
+
if ( !outputDir.exists() )
- {
- outputDir.mkdirs();
+ {
+
+ System.out.println( "Creating directorty: " + outputDir.getAbsolutePath() );
+
+ outputDir.mkdirs();
}
else
{
if ( !checkTimestamp() )
{
return 0;
- }
- }
- params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
+ }
+ }
+ params.add( "-OUTPUT_DIRECTORY=" + outputDir.getCanonicalPath() );
+
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 int retValue = jjtree.main( args );
-
- moveJJTJavaParserState();
+
+ 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 );
+ 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;
+ {
+ 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.3 +10 -1 maven-plugins/javacc/src/main/org/apache/maven/javacc/JavaccBean.java
Index: JavaccBean.java
===================================================================
RCS file: /home/cvs/maven-plugins/javacc/src/main/org/apache/maven/javacc/JavaccBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaccBean.java 2 Mar 2004 15:05:55 -0000 1.2
+++ JavaccBean.java 1 May 2004 14:34:09 -0000 1.3
@@ -34,16 +34,25 @@
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.3 +111 -64 maven-plugins/javacc/src/main/org/apache/maven/javacc/BaseBean.java
Index: BaseBean.java
===================================================================
RCS file: /home/cvs/maven-plugins/javacc/src/main/org/apache/maven/javacc/BaseBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseBean.java 2 Mar 2004 15:05:55 -0000 1.2
+++ BaseBean.java 1 May 2004 14:34:09 -0000 1.3
@@ -16,43 +16,32 @@
* limitations under the License.
* ====================================================================
*/
-
-import org.codehaus.plexus.util.FileUtils;
-
+
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$
*/
public class BaseBean
{
- /**
- * jjtree or javacc grammar file
- */
+ /** jjtree or javacc grammar file*/
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 jjtreePackageName;
-
- private String header;
-
-
+
+ private String header ;
+
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
*/
public String getGrammar()
@@ -62,8 +51,7 @@
/**
* Sets grammar file
- *
- * @param grammar
+ * @param grammar
*/
public void setGrammar( final String grammar )
{
@@ -73,13 +61,13 @@
/**
* 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 )
{
this.javaccPackageName = javaccPackageName;
}
-
+
/**
* @return Returns the header.
*/
@@ -87,7 +75,6 @@
{
return header;
}
-
/**
* @param header The header to set.
*/
@@ -95,68 +82,118 @@
{
this.header = header;
}
-
+
+
+
/**
- * @return
+ *
+ * @return
*/
public File getJavaccOutputDir()
{
- final String packagePath = javaccPackageName
- .replace( '.', File.separatorChar );
-
- final File retValue = new File( getGeneratedSourceDirectory(), packagePath );
- return retValue;
-
+ final String packagePath = javaccPackageName.replace( '.', File.separatorChar);
+
+ return new File( generatedSourceDirectory, packagePath );
}
-
- public String getGeneratedSourceDirectory()
+
+ /**
+ *
+ * @return
+ */
+ public File getJJTreeOutputDir()
{
- return generatedSourceDirectory;
+
+ final String packagePath = jjtreePackageName.replace( '.', File.separatorChar);
+
+ return new File( generatedSourceDirectory, packagePath );
}
-
+
+
/**
- * @return
+ *
+ * @throws Exception
*/
- public File getJJTreeOutputDir()
+ protected void addHeader( final File directory ) throws Exception
{
- final String packagePath = jjtreePackageName
- .replace( '.', File.separatorChar );
- return new File( getGeneratedSourceDirectory(), packagePath );
+
+ 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 timestamp
- * @param directory
+ *
+ * @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
{
- final File timestampFile = new File( directory, ".timestamp" );
+ 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;
@@ -164,8 +201,8 @@
// }
return true;
}
-
-
+
+
/**
* @return Returns the jjtreePackageName.
*/
@@ -173,12 +210,22 @@
{
return jjtreePackageName;
}
-
/**
* @param jjtreePackageName The jjtreePackageName to set.
*/
- public void setJjtreePackageName( String jjtreePackageName )
+ public void setJjtreePackageName( final String jjtreePackageName )
{
this.jjtreePackageName = jjtreePackageName;
+ }
+
+
+ public String getGeneratedSourceDirectory()
+ {
+ return generatedSourceDirectory;
+ }
+
+ public void setGeneratedSourceDirectory( final String generatedSourceDirectory )
+ {
+ this.generatedSourceDirectory = generatedSourceDirectory;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org