User: vharcq
Date: 02/03/30 02:11:39
Modified: core/src/xdoclet TemplateSubTask.java
Log:
Externalize the isGenerationNeeded in its own class.
More clear.
Revision Changes Path
1.32 +10 -239 xdoclet/core/src/xdoclet/TemplateSubTask.java
Index: TemplateSubTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/TemplateSubTask.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -r1.31 -r1.32
--- TemplateSubTask.java 30 Mar 2002 09:34:45 -0000 1.31
+++ TemplateSubTask.java 30 Mar 2002 10:11:38 -0000 1.32
@@ -15,6 +15,7 @@
import xdoclet.util.Log;
import xdoclet.util.Translator;
+import xdoclet.util.GenerationManager;
import xdoclet.ejb.UtilObjectSubTask;
import java.io.File;
@@ -29,7 +30,7 @@
*
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created Sep 25, 2001
- * @version $Revision: 1.31 $
+ * @version $Revision: 1.32 $
*/
public class TemplateSubTask extends SubTask
{
@@ -95,11 +96,7 @@
private ArrayList packageSubstitutions = new ArrayList();
private boolean packageSubstitutionInheritanceSupported = true;
- private boolean guessGenerationNeeded = true;
-
- private static File xdocletJar = getXdocletJar();
-
-
+ private GenerationManager generationManager;
/**
* Converts the full qualified class name to a valid path with File.separator
@@ -118,11 +115,6 @@
return packageSubstitutions;
}
- public boolean isGuessGenerationNeeded()
- {
- return guessGenerationNeeded;
- }
-
/**
* By default supports, but some subtasks may not support because global
* packageSubstitution is for public interfaces/classes, not good for impl
@@ -185,11 +177,6 @@
return prefixWithPackageStructure;
}
- public void setGuessGenerationNeeded( boolean guessGenerationNeeded )
- {
- this.guessGenerationNeeded = guessGenerationNeeded;
- }
-
public void setPackageSubstitutions( ArrayList packageSubstitutions )
{
this.packageSubstitutions = packageSubstitutions;
@@ -296,6 +283,10 @@
setHavingClassTag( src.getHavingClassTag() );
}
+ public void setGenerationManager(GenerationManager gM){
+ this.generationManager = gM;
+ }
+
public void init() throws XDocletException
{
super.init();
@@ -304,6 +295,7 @@
{
setEngine( new TemplateEngine( ) );
setParser( new TemplateParser( ) );
+ setGenerationManager(new GenerationManager(getTemplateURL() ,
getParser(), getContext().isForce()));
}
catch( TemplateException te )
{
@@ -417,7 +409,7 @@
try
{
- if( isGenerationNeeded( output_file ) )
+ if( generationManager.isGenerationNeeded( output_file
) )
{
startEngine( getTemplateURL(), output_file );
}
@@ -505,7 +497,7 @@
cat.debug( "File exists." );
// Check modification timestamps
- if( !isGenerationNeeded( clazz, file, true ) )
+ if( ! generationManager.isGenerationNeeded( clazz, file, true
) )
return;
}
@@ -568,227 +560,6 @@
private boolean isGenerationPerClass()
{
return getDestinationFile().indexOf( "{0}" ) != -1;
- }
-
- /**
- * Test if a Java source mmust be generated or not depending of timestamp of
- * elements involved.
- *
- * @param clazz the Class from wich we generate
- * @param file the File that will be generated
- * @param withTemplate
- * @return true if generation is needed
- * @exception XDocletException
- */
- private boolean isGenerationNeeded( XClass clazz, File file, boolean
withTemplate )
- throws XDocletException
- {
- Category cat = Log.getCategory( TemplateSubTask.class, "generation" );
-
- if( getContext().isForce() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Force generation enabled" );
- return true;
- }
-
- if( isGuessGenerationNeeded() == false )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "guessGenerationNeeded enabled" );
- return true;
- }
-
- // 1. Check the classpath for timestamp on XDOCLET JAR
- File xdocletJar = getXdocletJar();
-
- if( file.lastModified() < xdocletJar.lastModified() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Generation needed for '" + file.getName()
+ "' because of timestamp of " + xdocletJar.getName() );
- return true;
- }
- if( cat.isDebugEnabled() )
- cat.debug( "Reject file '" + file.getName() + "' because of
timestamp of " + xdocletJar.getName() );
-
- // 2. Check the bean timestamp
- if( file.lastModified() < clazz.lastModified() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Generation needed for '" + file.getName()
+ "' because of timestamp of " + clazz.qualifiedName() );
- return true;
- }
- if( cat.isDebugEnabled() )
- cat.debug( "Reject file '" + clazz.qualifiedName() + "'
because of timestamp of " + clazz.qualifiedName() );
-
- // 3. Check the superclasses timestamp
- XClass supers = clazz.superclass();
-
- while( supers != null )
- {
- if( supers.qualifiedName().equals("java.lang.Object") ) {
- return false;
- }
- if( file.lastModified() < supers.lastModified() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Generation needed for '" +
file.getName() + "' because of timestamp of " + supers.qualifiedName() );
- return true;
- }
- if( cat.isDebugEnabled() )
- cat.debug( "Reject file '" +clazz.qualifiedName() + "'
because of timestamp of " + supers.qualifiedName() );
- supers = supers.superclass();
- }
-
- // 4. Check the timestamp of template file and merge files
- if( withTemplate )
- {
- if( isGenerationNeeded( file, getTemplateURL() ) )
- return true;
- }
-
- return false;
- }
-
- /**
- * Verify if the generation of a file to generate is needed because either the
- * Template used to generate the file have a later timestamp, or because ALL
- * the Java sources imported in this task have a sooner timestamp. This is used
- * to test if xml files generation is needed.
- *
- * @param file The file to check
- * @return true if the generation is needed
- * @exception XDocletException
- */
- private boolean isGenerationNeeded( File file )
- throws XDocletException
- {
- Category cat = Log.getCategory( TemplateSubTask.class, "generation" );
-
- if( cat.isDebugEnabled() )
- cat.debug( "Generation need check for " + file.getName() );
-
- if( getContext().isForce() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Force generation enabled" );
- return true;
- }
-
- if( isGuessGenerationNeeded() == false )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "guessGenerationNeeded enabled" );
- return true;
- }
-
- // 1. Check the classpath for timestamp on XDOCLET JAR
- if( file.lastModified() < xdocletJar.lastModified() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Generation needed for '" + file.getName()
+ "' because of timestamp of " + xdocletJar.getName() );
- return true;
- }
- if( cat.isDebugEnabled() )
- cat.debug( "Reject file '"+file.getName()+"' because of
timestamp of " + xdocletJar.getName() );
-
- if( cat.isDebugEnabled() )
- cat.debug( "Generation need check for " + file.getName() );
-
- // 2. Check the timestamp of template file and merge files
- if( isGenerationNeeded( file, getTemplateURL() ) )
- return true;
-
- if( cat.isDebugEnabled() )
- cat.debug( "Generation need check for " + file.getName() );
-
- // 3. Check Timestamp of all java sources in sourcepath
- XClass[] classes = AbstractProgramElementTagsHandler.getAllClasses();
-
- for( int i = 0; i < classes.length; i++ )
- {
- if( isGenerationNeeded( classes[i], file, false ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Verify if the generation of a file is needed because either the template
- * file has a sooner timestamp, or because one of the merge files have a sooner
- * timestamp
- *
- * @param file The file to generate
- * @param templateURL the Template file to use
- * @return true if generation is needed.
- * @exception XDocletException
- */
- private boolean isGenerationNeeded( File file, URL templateURL )
- throws XDocletException
- {
- Category cat = Log.getCategory( TemplateSubTask.class, "generation" );
-
- if( cat.isDebugEnabled() )
- cat.debug( "Generation need check for " + file.getName() );
-
- // 1. Check Timestamp of Template file
- if( cat.isDebugEnabled() )
- cat.debug( file.getName() + " " + getTemplateURL() );
- if( file.lastModified() < new File( getTemplateURL().getFile()
).lastModified() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Generation needed for '" + file.getName()
+ "' because of timestamp of " + getTemplateURL() );
- return true;
- }
- if( cat.isDebugEnabled() )
- cat.debug( "Reject file '"+file.getName()+ "' because of
timestamp of " + getTemplateURL() );
-
- // 2. Check timestamp of Merge files found inside Template
- getParser().setOutput( file );
- getParser().setTemplateURL( templateURL );
-
- try
- {
- getParser().start();
- }
- catch( TemplateException e )
- {
- throw new XDocletException( e.toString() );
- }
-
- File[] files = getParser().getMergeFiles();
-
- if( cat.isDebugEnabled() )
- cat.debug( "Number of Merge files involved = " + files.length
);
- for( int i = 0; i < files.length; i++ )
- {
- if( files[i].exists() )
- {
- if( file.lastModified() < files[i].lastModified() )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "Generation needed for '" +
file.getName() + "' because of timestamp of " + files[i].getName() );
- return true;
- }
- if( cat.isDebugEnabled() )
- cat.debug( "Reject file '"+file.getName()+"'
because of timestamp of " + files[i].getName() );
- }
- }
- return false;
- }
-
- private static File getXdocletJar()
- {
- String path_str =
TemplateSubTask.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
-
- if( path_str != null && path_str.startsWith( "/" ) )
- {
- path_str = path_str.substring( 1 );
- }
- return new File( path_str );
}
/**
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel