@@ -10,13 +10,13 @@ package org.apache.tools.ant.taskdefs;
import java.io.File;
import java.io.File;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Iterator;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.FileNameMapper;
import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.ScannerUtil;
import org.apache.tools.ant.types.ScannerUtil;
import org.apache.tools.ant.types.SourceFileScanner;
import org.apache.tools.ant.types.SourceFileScanner;
import org.apache.tools.ant.util.mappers.FileNameMapper;
import org.apache.tools.ant.util.mappers.Mapper;
import org.apache.tools.ant.util.mappers.MergingMapper;
import org.apache.tools.ant.util.mappers.MergingMapper;
/**
/**
@@ -29,16 +29,15 @@ import org.apache.tools.ant.util.mappers.MergingMapper;
* hnakamur@mc.neweb.ne.jp</a>
* hnakamur@mc.neweb.ne.jp</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
*/
public class UpToDate extends Matching Task
public class UpToDate
extends Abstract Task
{
{
private ArrayList sourceFileSets = new ArrayList();
protected Mapper mapperElement = null;
private final ArrayList m_fileSets = new ArrayList();
private FileNameMapper m_mapper;
private String _property;
private File _targetFile;
private String _value;
private String m _property;
private File m _targetFile;
private String m _value;
/**
/**
* The property to set if the target file is more up to date than each of
* The property to set if the target file is more up to date than each of
@@ -46,9 +45,9 @@ public class UpToDate extends MatchingTask
*
*
* @param property the name of the property to set if Target is up to date.
* @param property the name of the property to set if Target is up to date.
*/
*/
public void setProperty( String property )
public void setProperty( final String property )
{
{
_property = property;
m _property = property;
}
}
/**
/**
@@ -57,9 +56,9 @@ public class UpToDate extends MatchingTask
*
*
* @param file the file which we are checking against.
* @param file the file which we are checking against.
*/
*/
public void setTargetFile( File file )
public void setTargetFile( final File file )
{
{
_targetFile = file;
m _targetFile = file;
}
}
/**
/**
@@ -68,9 +67,9 @@ public class UpToDate extends MatchingTask
*
*
* @param value the value to set the property to if Target is up to date
* @param value the value to set the property to if Target is up to date
*/
*/
public void setValue( String value )
public void setValue( final String value )
{
{
_value = value;
m _value = value;
}
}
/**
/**
@@ -78,26 +77,22 @@ public class UpToDate extends MatchingTask
*
*
* @param fs The feature to be added to the Srcfiles attribute
* @param fs The feature to be added to the Srcfiles attribute
*/
*/
public void addSrcfiles( FileSet fs )
public void addSrcfiles( final FileSet fs )
{
{
sourceF ileSets.add( fs );
m_f ileSets.add( fs );
}
}
/**
/**
* Defines the FileNameMapper to use (nested mapper element).
* Defines the FileNameMapper to use (nested mapper element).
*
* @return Description of the Returned Value
* @exception TaskException Description of Exception
*/
*/
public Mapper createMapper( )
public void addMapper( final FileNameMapper mapper )
throws TaskException
throws TaskException
{
{
if( mapperElement != null )
if( m_m apper != null )
{
{
throw new TaskException( "Cannot define more than one mapper" );
throw new TaskException( "Cannot define more than one mapper" );
}
}
mapperElement = new Mapper();
return mapperElement;
m_mapper = mapper;
}
}
/**
/**
@@ -108,23 +103,23 @@ public class UpToDate extends MatchingTask
public boolean eval()
public boolean eval()
throws TaskException
throws TaskException
{
{
if( sourceF ileSets.size() == 0 )
if( m_f ileSets.size() == 0 )
{
{
throw new TaskException( "At least one <srcfiles> element must be set" );
throw new TaskException( "At least one <srcfiles> element must be set" );
}
}
if( _targetFile == null && mapperElement == null )
if( m _targetFile == null && m_m apper == null )
{
{
throw new TaskException( "The targetfile attribute or a nested mapper element must be set" );
throw new TaskException( "The targetfile attribute or a nested mapper element must be set" );
}
}
// if not there then it can't be up to date
// if not there then it can't be up to date
if( _targetFile != null && !_targetFile.exists() )
if( m _targetFile != null && !m _targetFile.exists() )
{
{
return false;
return false;
}
}
Iterator enum = sourceF ileSets.iterator();
Iterator enum = m_f ileSets.iterator();
boolean upToDate = true;
boolean upToDate = true;
while( upToDate && enum.hasNext() )
while( upToDate && enum.hasNext() )
{
{
@@ -148,12 +143,12 @@ public class UpToDate extends MatchingTask
boolean upToDate = eval();
boolean upToDate = eval();
if( upToDate )
if( upToDate )
{
{
final String name = _property;
final String name = m _property;
final Object value = this.getValue();
final Object value = this.getValue();
getContext().setProperty( name, value );
getContext().setProperty( name, value );
if( mapperElement == null )
if( m_m apper == null )
{
{
getLogger().debug( "File \"" + _targetFile.getAbsolutePath() + "\" is up to date." );
getLogger().debug( "File \"" + m _targetFile.getAbsolutePath() + "\" is up to date." );
}
}
else
else
{
{
@@ -169,18 +164,18 @@ public class UpToDate extends MatchingTask
setupLogger( scanner );
setupLogger( scanner );
FileNameMapper mapper = null;
FileNameMapper mapper = null;
File dir = srcDir;
File dir = srcDir;
if( mapperElement == null )
if( m_m apper == null )
{
{
MergingMapper mm = new MergingMapper();
MergingMapper mm = new MergingMapper();
mm.setTo( _targetFile.getAbsolutePath() );
mm.setTo( m _targetFile.getAbsolutePath() );
mapper = mm;
mapper = mm;
dir = null;
dir = null;
}
}
else
else
{
{
mapper = mapperElement.getImplementation() ;
mapper = m_m apper;
}
}
return scanner.restrict( files, srcDir, dir, mapper ).length == 0;
return scanner.restrict( files, srcDir, dir, mapper, getContext() ).length == 0;
}
}
/**
/**
@@ -190,6 +185,6 @@ public class UpToDate extends MatchingTask
*/
*/
private String getValue()
private String getValue()
{
{
return ( _value != null ) ? _value : "true";
return ( m _value != null ) ? m _value : "true";
}
}
}
}