User: vharcq
Date: 02/03/30 02:11:38
Added: core/src/xdoclet/util GenerationManager.java
Log:
Externalize the isGenerationNeeded in its own class.
More clear.
Revision Changes Path
1.1 xdoclet/core/src/xdoclet/util/GenerationManager.java
Index: GenerationManager.java
===================================================================
/*
* Created by IntelliJ IDEA.
* User: Vincent
* Date: Mar 30, 2002
* Time: 10:59:13 AM
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package xdoclet.util;
import xdoclet.TemplateSubTask;
import xdoclet.XDocletException;
import xdoclet.tags.AbstractProgramElementTagsHandler;
import xdoclet.template.TemplateException;
import xdoclet.template.TemplateParser;
import java.io.File;
import java.net.URL;
import xjavadoc.XClass;
import org.apache.log4j.Category;
public class GenerationManager {
private static File xdocletJar = getXdocletJar();
private boolean guessGenerationNeeded = true;
private URL templateUrl;
private TemplateParser parser;
private boolean isForce;
public GenerationManager( URL templateUrl, TemplateParser parser, boolean
isForce){
this.templateUrl = templateUrl;
this.parser = parser;
this.isForce = isForce;
}
public boolean isGuessGenerationNeeded()
{
return guessGenerationNeeded;
}
public void setGuessGenerationNeeded(boolean guessGenerationNeeded )
{
this.guessGenerationNeeded = guessGenerationNeeded;
}
public URL getTemplateURL(){
return templateUrl;
}
public TemplateParser getParser(){
return parser;
}
/**
* 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
*/
public boolean isGenerationNeeded( XClass clazz, File file, boolean
withTemplate )
throws XDocletException
{
Category cat = Log.getCategory( TemplateSubTask.class, "generation" );
if( 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
*/
public 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( 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