from the interface, as these are no longer needed. * Changed tasks to accept a FileNameMapper directly, rather than using Mapper. * Removed the 'flatten' attribute from the <copy> task. * Removed the 'ext' attribute from the <native2ascii> task. * Removed Mapper and MapperType. * Moved <flatten> mapper to antlib. * Made ExtMapper available as <map-extension> and moved to antlib. * Added <prefix> mapper, to apply a fixed prefix to names. * Added <chain> mapper, to apply a chain of mappers to names. * Added <mapped-fileset>, a fileset that transforms nested filesets using a mapper. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271715 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -0,0 +1,43 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.antlib.core; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Maps file extensions. | |||
| * | |||
| * @ant:type type="mapper" name="map-extension" | |||
| */ | |||
| public class ExtFileNameMapper | |||
| implements FileNameMapper | |||
| { | |||
| private String m_extension; | |||
| public void setExtension( final String extension ) | |||
| { | |||
| m_extension = extension; | |||
| } | |||
| public String[] mapFileName( final String filename, TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| final String name = FileUtil.removeExtension( filename ); | |||
| if( m_extension != null ) | |||
| { | |||
| return new String[]{ name + '.' + m_extension }; | |||
| } | |||
| else | |||
| { | |||
| return new String[]{ name }; | |||
| } | |||
| } | |||
| } | |||
| @@ -5,35 +5,25 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| package org.apache.antlib.core; | |||
| import java.io.File; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that always returns the source file name | |||
| * without any leading directory information. <p> | |||
| * | |||
| * This is the default FileNameMapper for the copy and move tasks if the flatten | |||
| * attribute has been set.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="flatten" | |||
| */ | |||
| public class FlatFileNameMapper | |||
| extends PrefixFileNameMapper | |||
| implements FileNameMapper | |||
| { | |||
| /** | |||
| * Ignored. | |||
| */ | |||
| public void setFrom( final String from ) | |||
| { | |||
| } | |||
| /** | |||
| * Ignored. | |||
| */ | |||
| public void setTo( final String to ) | |||
| { | |||
| } | |||
| /** | |||
| * Returns an one-element array containing the source file name without any | |||
| @@ -42,8 +32,10 @@ public class FlatFileNameMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| return new String[]{new File( sourceFileName ).getName()}; | |||
| final String baseName = FileUtil.removePath( sourceFileName, '/' ); | |||
| return super.mapFileName( baseName, context ); | |||
| } | |||
| } | |||
| @@ -0,0 +1,56 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.antlib.core; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * A filename mapper that applies a prefix to each file. | |||
| * | |||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
| * @version $Revision$ $Date$ | |||
| * | |||
| * @ant:type type="mapper" name="prefix" | |||
| */ | |||
| public class PrefixFileNameMapper | |||
| implements FileNameMapper | |||
| { | |||
| private String m_prefix; | |||
| /** | |||
| * Sets the prefix. | |||
| */ | |||
| public void setPrefix( final String prefix ) | |||
| { | |||
| m_prefix = prefix; | |||
| if( ! m_prefix.endsWith( "/" ) ) | |||
| { | |||
| m_prefix = m_prefix + '/'; | |||
| } | |||
| } | |||
| /** | |||
| * Returns an array containing the target filename(s) for the given source | |||
| * file. | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| if( m_prefix == null ) | |||
| { | |||
| return new String[]{ sourceFileName }; | |||
| } | |||
| else | |||
| { | |||
| return new String[] { m_prefix + sourceFileName }; | |||
| } | |||
| } | |||
| } | |||
| @@ -18,14 +18,12 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| 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.FileSet; | |||
| import org.apache.tools.ant.types.ScannerUtil; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.tools.ant.util.mappers.FlatFileNameMapper; | |||
| import org.apache.tools.ant.util.mappers.IdentityMapper; | |||
| import org.apache.tools.ant.util.mappers.Mapper; | |||
| /** | |||
| * This is a task used to copy files. | |||
| @@ -50,9 +48,8 @@ public class CopyTask | |||
| private File m_destDir; | |||
| private boolean m_preserveLastModified; | |||
| private boolean m_overwrite; | |||
| private boolean m_flatten; | |||
| private boolean m_includeEmpty = true; | |||
| private Mapper m_mapper; | |||
| private FileNameMapper m_mapper; | |||
| private HashMap m_fileMap = new HashMap(); | |||
| private HashMap m_dirMap = new HashMap(); | |||
| @@ -93,23 +90,10 @@ public class CopyTask | |||
| m_overwrite = overwrite; | |||
| } | |||
| /** | |||
| * When copying directory trees, the files can be "flattened" into a single | |||
| * directory. If there are multiple files with the same name in the source | |||
| * directory tree, only the first file will be copied into the "flattened" | |||
| * directory, unless the forceoverwrite attribute is true. | |||
| * | |||
| * @param flatten The new Flatten value | |||
| */ | |||
| public void setFlatten( final boolean flatten ) | |||
| { | |||
| m_flatten = flatten; | |||
| } | |||
| /** | |||
| * Defines the FileNameMapper to use (nested mapper element). | |||
| */ | |||
| public void addMapper( final Mapper mapper ) | |||
| public void addMapper( final FileNameMapper mapper ) | |||
| throws TaskException | |||
| { | |||
| if( null != m_mapper ) | |||
| @@ -269,7 +253,7 @@ public class CopyTask | |||
| final String[] toCopy = buildFilenameList( files, mapper, sourceDir, destDir ); | |||
| for( int i = 0; i < toCopy.length; i++ ) | |||
| { | |||
| final String destFilename = mapper.mapFileName( toCopy[ i ] )[ 0 ]; | |||
| final String destFilename = mapper.mapFileName( toCopy[ i ], getContext() )[ 0 ]; | |||
| final File source = new File( sourceDir, toCopy[ i ] ); | |||
| final File destination = new File( destDir, destFilename ); | |||
| map.put( source.getAbsolutePath(), destination.getAbsolutePath() ); | |||
| @@ -292,7 +276,7 @@ public class CopyTask | |||
| for( int i = 0; i < names.length; i++ ) | |||
| { | |||
| final String name = names[ i ]; | |||
| if( null != mapper.mapFileName( name ) ) | |||
| if( null != mapper.mapFileName( name, getContext() ) ) | |||
| { | |||
| list.add( name ); | |||
| } | |||
| @@ -304,7 +288,7 @@ public class CopyTask | |||
| { | |||
| final SourceFileScanner scanner = new SourceFileScanner(); | |||
| setupLogger( scanner ); | |||
| return scanner.restrict( names, fromDir, toDir, mapper ); | |||
| return scanner.restrict( names, fromDir, toDir, mapper, getContext() ); | |||
| } | |||
| } | |||
| @@ -406,11 +390,7 @@ public class CopyTask | |||
| { | |||
| if( null != m_mapper ) | |||
| { | |||
| return m_mapper.getImplementation(); | |||
| } | |||
| else if( m_flatten ) | |||
| { | |||
| return new FlatFileNameMapper(); | |||
| return m_mapper; | |||
| } | |||
| else | |||
| { | |||
| @@ -0,0 +1,95 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.antlib.vfile; | |||
| import java.util.ArrayList; | |||
| import org.apache.aut.vfs.FileObject; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.ChainFileNameMapper; | |||
| /** | |||
| * A fileset that maps another fileset. | |||
| * | |||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
| * @version $Revision$ $Date$ | |||
| * | |||
| * @ant:data-type name="mapped-fileset" | |||
| */ | |||
| public class MappedFileSet | |||
| implements FileSet | |||
| { | |||
| private final ArrayList m_filesets = new ArrayList(); | |||
| private ChainFileNameMapper m_mapper = new ChainFileNameMapper(); | |||
| /** | |||
| * Sets the mapper to use. | |||
| */ | |||
| public void setMapper( final ChainFileNameMapper mapper ) | |||
| { | |||
| m_mapper.add( mapper ); | |||
| } | |||
| /** | |||
| * Sets the fileset to map. | |||
| */ | |||
| public void add( final FileSet fileset ) | |||
| { | |||
| m_filesets.add( fileset ); | |||
| } | |||
| /** | |||
| * Returns the contents of the set. | |||
| */ | |||
| public FileSetResult getResult( final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| final DefaultFileSetResult result = new DefaultFileSetResult(); | |||
| // Map each source fileset. | |||
| final int count = m_filesets.size(); | |||
| for( int i = 0; i < count; i++ ) | |||
| { | |||
| final FileSet fileSet = (FileSet)m_filesets.get(i ); | |||
| mapFileSet( fileSet, result, context ); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * Maps the contents of a fileset. | |||
| */ | |||
| private void mapFileSet( final FileSet fileset, | |||
| final DefaultFileSetResult result, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| // Build the result from the nested fileset | |||
| FileSetResult origResult = fileset.getResult( context ); | |||
| final FileObject[] files = origResult.getFiles(); | |||
| final String[] paths = origResult.getPaths(); | |||
| // Map each element of the result | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| final FileObject file = files[ i ]; | |||
| final String path = paths[ i ]; | |||
| String[] newPaths = m_mapper.mapFileName( path, context ); | |||
| if( newPaths == null ) | |||
| { | |||
| continue; | |||
| } | |||
| for( int j = 0; j < newPaths.length; j++ ) | |||
| { | |||
| String newPath = newPaths[j ]; | |||
| result.addElement( file, newPath ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,85 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.myrmidon.framework; | |||
| import java.util.ArrayList; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| /** | |||
| * A mapper that applies a chain of mappers. | |||
| * | |||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
| * @version $Revision$ $Date$ | |||
| * | |||
| * @ant:type type="mapper" name="chain" | |||
| */ | |||
| public class ChainFileNameMapper | |||
| implements FileNameMapper | |||
| { | |||
| private final ArrayList m_mappers = new ArrayList(); | |||
| /** | |||
| * Adds a nested mapper. | |||
| */ | |||
| public void add( final FileNameMapper mapper ) | |||
| { | |||
| m_mappers.add( mapper ); | |||
| } | |||
| /** | |||
| * Returns an array containing the target filename(s) for the given source | |||
| * file. | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| ArrayList names = new ArrayList(); | |||
| names.add( sourceFileName ); | |||
| final int count = m_mappers.size(); | |||
| for( int i = 0; i < count; i++ ) | |||
| { | |||
| final FileNameMapper mapper = (FileNameMapper)m_mappers.get( i ); | |||
| names = mapNames( mapper, names, context ); | |||
| } | |||
| return (String[])names.toArray( new String[ names.size() ] ); | |||
| } | |||
| /** | |||
| * Maps a set of names. | |||
| */ | |||
| private ArrayList mapNames( final FileNameMapper mapper, | |||
| final ArrayList names, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| final ArrayList retval = new ArrayList(); | |||
| // Map each of the supplied names | |||
| final int count = names.size(); | |||
| for( int i = 0; i < count; i++ ) | |||
| { | |||
| final String name = (String)names.get( i ); | |||
| final String[] newNames = mapper.mapFileName( name, context ); | |||
| if( newNames == null ) | |||
| { | |||
| continue; | |||
| } | |||
| for( int j = 0; j < newNames.length; j++ ) | |||
| { | |||
| final String newName = newNames[ j ]; | |||
| retval.add( newName ); | |||
| } | |||
| } | |||
| return retval; | |||
| } | |||
| } | |||
| @@ -5,8 +5,9 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| package org.apache.myrmidon.framework; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| /** | |||
| @@ -20,36 +21,24 @@ import org.apache.myrmidon.api.TaskException; | |||
| * </p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:role shorthand="mapper" | |||
| */ | |||
| public interface FileNameMapper | |||
| { | |||
| /** | |||
| * Sets the from part of the transformation rule. | |||
| * | |||
| * @param from The new From value | |||
| */ | |||
| void setFrom( String from ) | |||
| throws TaskException; | |||
| /** | |||
| * Sets the to part of the transformation rule. | |||
| * | |||
| * @param to The new To value | |||
| */ | |||
| void setTo( String to ); | |||
| /** | |||
| * Returns an array containing the target filename(s) for the given source | |||
| * file. <p> | |||
| * file. | |||
| * | |||
| * if the given rule doesn't apply to the source file, implementation must | |||
| * return null. SourceFileScanner will then omit the source file in | |||
| * <p>if the given rule doesn't apply to the source file, implementation | |||
| * must return null. SourceFileScanner will then omit the source file in | |||
| * question.</p> | |||
| * | |||
| * @param sourceFileName the name of the source file relative to some given | |||
| * basedirectory. | |||
| * @param context the context to perform the mapping in. | |||
| * @return Description of the Returned Value | |||
| */ | |||
| String[] mapFileName( String sourceFileName ) | |||
| String[] mapFileName( String sourceFileName, TaskContext context ) | |||
| throws TaskException; | |||
| } | |||
| @@ -116,7 +116,7 @@ public final class Main | |||
| final String name = file.getName(); | |||
| if( !name.endsWith( ".jar" ) && !name.endsWith( ".zip" ) ) | |||
| { | |||
| //Ifnore files in lib dir that are not jars or zips | |||
| //Ignore files in lib dir that are not jars or zips | |||
| continue; | |||
| } | |||
| @@ -10,13 +10,13 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| 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.FileSet; | |||
| import org.apache.tools.ant.types.ScannerUtil; | |||
| 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; | |||
| /** | |||
| @@ -29,16 +29,15 @@ import org.apache.tools.ant.util.mappers.MergingMapper; | |||
| * hnakamur@mc.neweb.ne.jp</a> | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public class UpToDate extends MatchingTask | |||
| public class UpToDate | |||
| extends AbstractTask | |||
| { | |||
| 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 | |||
| @@ -46,9 +45,9 @@ public class UpToDate extends MatchingTask | |||
| * | |||
| * @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. | |||
| */ | |||
| 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 | |||
| */ | |||
| 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 | |||
| */ | |||
| public void addSrcfiles( FileSet fs ) | |||
| public void addSrcfiles( final FileSet fs ) | |||
| { | |||
| sourceFileSets.add( fs ); | |||
| m_fileSets.add( fs ); | |||
| } | |||
| /** | |||
| * 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 | |||
| { | |||
| if( mapperElement != null ) | |||
| if( m_mapper != null ) | |||
| { | |||
| 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() | |||
| throws TaskException | |||
| { | |||
| if( sourceFileSets.size() == 0 ) | |||
| if( m_fileSets.size() == 0 ) | |||
| { | |||
| throw new TaskException( "At least one <srcfiles> element must be set" ); | |||
| } | |||
| if( _targetFile == null && mapperElement == null ) | |||
| if( m_targetFile == null && m_mapper == null ) | |||
| { | |||
| 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( _targetFile != null && !_targetFile.exists() ) | |||
| if( m_targetFile != null && !m_targetFile.exists() ) | |||
| { | |||
| return false; | |||
| } | |||
| Iterator enum = sourceFileSets.iterator(); | |||
| Iterator enum = m_fileSets.iterator(); | |||
| boolean upToDate = true; | |||
| while( upToDate && enum.hasNext() ) | |||
| { | |||
| @@ -148,12 +143,12 @@ public class UpToDate extends MatchingTask | |||
| boolean upToDate = eval(); | |||
| if( upToDate ) | |||
| { | |||
| final String name = _property; | |||
| final String name = m_property; | |||
| final Object value = this.getValue(); | |||
| getContext().setProperty( name, value ); | |||
| if( mapperElement == null ) | |||
| if( m_mapper == null ) | |||
| { | |||
| getLogger().debug( "File \"" + _targetFile.getAbsolutePath() + "\" is up to date." ); | |||
| getLogger().debug( "File \"" + m_targetFile.getAbsolutePath() + "\" is up to date." ); | |||
| } | |||
| else | |||
| { | |||
| @@ -169,18 +164,18 @@ public class UpToDate extends MatchingTask | |||
| setupLogger( scanner ); | |||
| FileNameMapper mapper = null; | |||
| File dir = srcDir; | |||
| if( mapperElement == null ) | |||
| if( m_mapper == null ) | |||
| { | |||
| MergingMapper mm = new MergingMapper(); | |||
| mm.setTo( _targetFile.getAbsolutePath() ); | |||
| mm.setTo( m_targetFile.getAbsolutePath() ); | |||
| mapper = mm; | |||
| dir = null; | |||
| } | |||
| else | |||
| { | |||
| mapper = mapperElement.getImplementation(); | |||
| mapper = m_mapper; | |||
| } | |||
| 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() | |||
| { | |||
| return ( _value != null ) ? _value : "true"; | |||
| return ( m_value != null ) ? m_value : "true"; | |||
| } | |||
| } | |||
| @@ -227,7 +227,7 @@ public class Tar | |||
| setupLogger( scanner ); | |||
| final MergingMapper mapper = new MergingMapper(); | |||
| mapper.setTo( tarFile.getAbsolutePath() ); | |||
| return scanner.restrict( files, baseDir, null, mapper ).length == 0; | |||
| return scanner.restrict( files, baseDir, null, mapper, getContext() ).length == 0; | |||
| } | |||
| private void tarFile( final File file, | |||
| @@ -483,7 +483,7 @@ public class Zip | |||
| for( int i = 0; i < scanners.length; i++ ) | |||
| { | |||
| if( scanner.restrict( fileNames[ i ], scanners[ i ].getBasedir(), null, | |||
| mm ).length > 0 ) | |||
| mm, getContext() ).length > 0 ) | |||
| { | |||
| return false; | |||
| } | |||
| @@ -13,11 +13,11 @@ import java.util.Iterator; | |||
| import org.apache.aut.nativelib.Os; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.JavaVersion; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.DirectoryScanner; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.GlobPatternMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| /** | |||
| * Task to compile Java source files. This task can take the following | |||
| @@ -713,7 +713,7 @@ public class Javac | |||
| m.setTo( "*.class" ); | |||
| SourceFileScanner sfs = new SourceFileScanner(); | |||
| setupLogger( sfs ); | |||
| File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m ); | |||
| File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m, getContext() ); | |||
| if( newFiles.length > 0 ) | |||
| { | |||
| @@ -11,11 +11,12 @@ import java.io.File; | |||
| import java.util.ArrayList; | |||
| import java.util.Random; | |||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| /** | |||
| * This is the default implementation for the RmicAdapter interface. Currently, | |||
| @@ -268,7 +269,7 @@ public abstract class DefaultRmicAdapter | |||
| { | |||
| } | |||
| public String[] mapFileName( String name ) | |||
| public String[] mapFileName( String name, TaskContext context ) | |||
| { | |||
| if( name == null | |||
| || !name.endsWith( ".class" ) | |||
| @@ -15,13 +15,12 @@ import java.rmi.Remote; | |||
| import java.util.ArrayList; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.DirectoryScanner; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.PathUtil; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| /** | |||
| * Task to compile RMI stubs and skeletons. This task can take the following | |||
| @@ -569,7 +568,7 @@ public class Rmic extends MatchingTask | |||
| { | |||
| final SourceFileScanner scanner = new SourceFileScanner(); | |||
| setupLogger( scanner ); | |||
| newFiles = scanner.restrict( files, baseDir, baseDir, mapper ); | |||
| newFiles = scanner.restrict( files, baseDir, baseDir, mapper, getContext() ); | |||
| } | |||
| for( int i = 0; i < newFiles.length; i++ ) | |||
| @@ -603,7 +602,7 @@ public class Rmic extends MatchingTask | |||
| String classFileName = | |||
| classname.replace( '.', File.separatorChar ) + ".class"; | |||
| String[] generatedFiles = | |||
| adapter.getMapper().mapFileName( classFileName ); | |||
| adapter.getMapper().mapFileName( classFileName, getContext() ); | |||
| for( int i = 0; i < generatedFiles.length; i++ ) | |||
| { | |||
| @@ -8,8 +8,8 @@ | |||
| package org.apache.tools.ant.taskdefs.rmic; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| /** | |||
| * The interface that all rmic adapters must adher to. <p> | |||
| @@ -1,43 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.text; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| class ExtMapper | |||
| implements FileNameMapper | |||
| { | |||
| private final String m_extension; | |||
| public ExtMapper( final String extension ) | |||
| { | |||
| m_extension = extension; | |||
| } | |||
| public void setFrom( final String from ) | |||
| { | |||
| } | |||
| public void setTo( final String to ) | |||
| { | |||
| } | |||
| public String[] mapFileName( final String filename ) | |||
| { | |||
| final int index = filename.lastIndexOf( '.' ); | |||
| if( index >= 0 ) | |||
| { | |||
| final String reult = filename.substring( 0, index ) + m_extension; | |||
| return new String[]{reult}; | |||
| } | |||
| else | |||
| { | |||
| return new String[]{filename + m_extension}; | |||
| } | |||
| } | |||
| } | |||
| @@ -9,13 +9,12 @@ package org.apache.tools.ant.taskdefs.text; | |||
| import java.io.File; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.types.DirectoryScanner; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.tools.ant.util.mappers.IdentityMapper; | |||
| import org.apache.tools.ant.util.mappers.Mapper; | |||
| /** | |||
| * Convert files from native encodings to ascii. | |||
| @@ -30,8 +29,7 @@ public class Native2Ascii | |||
| private String m_encoding;// encoding to convert to/from | |||
| private File m_srcDir;// Where to find input files | |||
| private File m_destDir;// Where to put output files | |||
| private String m_ext;// Extension of output files if different | |||
| private Mapper m_mapper; | |||
| private FileNameMapper m_mapper; | |||
| /** | |||
| * Set the destination dirctory to place converted files into. | |||
| @@ -55,17 +53,6 @@ public class Native2Ascii | |||
| m_encoding = encoding; | |||
| } | |||
| /** | |||
| * Set the extension which converted files should have. If unset, files will | |||
| * not be renamed. | |||
| * | |||
| * @param ext File extension to use for converted files. | |||
| */ | |||
| public void setExt( final String ext ) | |||
| { | |||
| m_ext = ext; | |||
| } | |||
| /** | |||
| * Flag the conversion to run in the reverse sense, that is Ascii to Native | |||
| * encoding. | |||
| @@ -89,19 +76,15 @@ public class Native2Ascii | |||
| /** | |||
| * Defines the FileNameMapper to use (nested mapper element). | |||
| * | |||
| * @return Description of the Returned Value | |||
| * @exception TaskException Description of Exception | |||
| */ | |||
| public Mapper createMapper() | |||
| public void createMapper( final FileNameMapper mapper ) | |||
| throws TaskException | |||
| { | |||
| if( m_mapper != null ) | |||
| { | |||
| throw new TaskException( "Cannot define more than one mapper" ); | |||
| } | |||
| m_mapper = new Mapper(); | |||
| return m_mapper; | |||
| m_mapper = mapper; | |||
| } | |||
| public void execute() | |||
| @@ -115,7 +98,7 @@ public class Native2Ascii | |||
| final SourceFileScanner sfs = new SourceFileScanner(); | |||
| setupLogger( sfs ); | |||
| final FileNameMapper mapper = buildMapper(); | |||
| files = sfs.restrict( files, m_srcDir, m_destDir, mapper ); | |||
| files = sfs.restrict( files, m_srcDir, m_destDir, mapper, getContext() ); | |||
| int count = files.length; | |||
| if( count == 0 ) | |||
| { | |||
| @@ -129,7 +112,7 @@ public class Native2Ascii | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| final String name = mapper.mapFileName( files[ i ] )[ 0 ]; | |||
| final String name = mapper.mapFileName( files[ i ], getContext() )[ 0 ]; | |||
| convert( files[ i ], name ); | |||
| } | |||
| } | |||
| @@ -140,18 +123,11 @@ public class Native2Ascii | |||
| FileNameMapper mapper = null; | |||
| if( m_mapper == null ) | |||
| { | |||
| if( m_ext == null ) | |||
| { | |||
| mapper = new IdentityMapper(); | |||
| } | |||
| else | |||
| { | |||
| mapper = new ExtMapper( m_ext ); | |||
| } | |||
| mapper = new IdentityMapper(); | |||
| } | |||
| else | |||
| { | |||
| mapper = m_mapper.getImplementation(); | |||
| mapper = m_mapper; | |||
| } | |||
| return mapper; | |||
| @@ -169,9 +145,9 @@ public class Native2Ascii | |||
| // if src and dest dirs are the same, require the extension | |||
| // to be set, so we don't stomp every file. One could still | |||
| // include a file with the same extension, but .... | |||
| if( m_srcDir.equals( m_destDir ) && m_ext == null && m_mapper == null ) | |||
| if( m_srcDir.equals( m_destDir ) && m_mapper == null ) | |||
| { | |||
| throw new TaskException( "The ext attribute or a mapper must be set if" + | |||
| throw new TaskException( "A mapper must be specified if" + | |||
| " src and dest dirs are the same." ); | |||
| } | |||
| @@ -13,8 +13,9 @@ import java.util.Date; | |||
| import org.apache.aut.nativelib.Os; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Utility class that collects the functionality of the various scanDir methods | |||
| @@ -40,8 +41,11 @@ public class SourceFileScanner | |||
| * @param mapper knows how to construct a target file names from source file | |||
| * names. | |||
| */ | |||
| public String[] restrict( String[] files, File srcDir, File destDir, | |||
| FileNameMapper mapper ) | |||
| public String[] restrict( final String[] files, | |||
| final File srcDir, | |||
| final File destDir, | |||
| final FileNameMapper mapper, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| @@ -64,7 +68,7 @@ public class SourceFileScanner | |||
| final ArrayList v = new ArrayList(); | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| final String[] targets = mapper.mapFileName( files[ i ] ); | |||
| final String[] targets = mapper.mapFileName( files[ i ], context ); | |||
| if( targets == null || targets.length == 0 ) | |||
| { | |||
| final String message = files[ i ] + " skipped - don\'t know how to handle it"; | |||
| @@ -130,10 +134,11 @@ public class SourceFileScanner | |||
| public File[] restrictAsFiles( final String[] files, | |||
| final File srcDir, | |||
| final File destDir, | |||
| final FileNameMapper mapper ) | |||
| final FileNameMapper mapper, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| final String[] res = restrict( files, srcDir, destDir, mapper ); | |||
| final String[] res = restrict( files, srcDir, destDir, mapper, context ); | |||
| final File[] result = new File[ res.length ]; | |||
| for( int i = 0; i < res.length; i++ ) | |||
| { | |||
| @@ -1,55 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| /** | |||
| * Interface to be used by SourceFileScanner. <p> | |||
| * | |||
| * Used to find the name of the target file(s) corresponding to a source file. | |||
| * </p> <p> | |||
| * | |||
| * The rule by which the file names are transformed is specified via the setFrom | |||
| * and setTo methods. The exact meaning of these is implementation dependent. | |||
| * </p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public interface FileNameMapper | |||
| { | |||
| /** | |||
| * Sets the from part of the transformation rule. | |||
| * | |||
| * @param from The new From value | |||
| */ | |||
| void setFrom( String from ) | |||
| throws TaskException; | |||
| /** | |||
| * Sets the to part of the transformation rule. | |||
| * | |||
| * @param to The new To value | |||
| */ | |||
| void setTo( String to ); | |||
| /** | |||
| * Returns an array containing the target filename(s) for the given source | |||
| * file. <p> | |||
| * | |||
| * if the given rule doesn't apply to the source file, implementation must | |||
| * return null. SourceFileScanner will then omit the source file in | |||
| * question.</p> | |||
| * | |||
| * @param sourceFileName the name of the source file relative to some given | |||
| * basedirectory. | |||
| * @return Description of the Returned Value | |||
| */ | |||
| String[] mapFileName( String sourceFileName ) | |||
| throws TaskException; | |||
| } | |||
| @@ -7,6 +7,9 @@ | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that does simple wildcard pattern | |||
| * replacements. <p> | |||
| @@ -18,6 +21,8 @@ package org.apache.tools.ant.util.mappers; | |||
| * This is one of the more useful Mappers, it is used by javac for example.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="glob" | |||
| */ | |||
| public class GlobPatternMapper | |||
| implements FileNameMapper | |||
| @@ -101,7 +106,7 @@ public class GlobPatternMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| { | |||
| if( m_fromPrefix == null || | |||
| !sourceFileName.startsWith( m_fromPrefix ) || | |||
| @@ -124,7 +129,7 @@ public class GlobPatternMapper | |||
| * @param name Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| protected String extractVariablePart( final String name ) | |||
| private String extractVariablePart( final String name ) | |||
| { | |||
| return name.substring( m_prefixLength, | |||
| name.length() - m_postfixLength ); | |||
| @@ -7,43 +7,28 @@ | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that always returns the source file name. | |||
| * <p> | |||
| * | |||
| * This is the default FileNameMapper for the copy and move tasks.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="identity" | |||
| */ | |||
| public class IdentityMapper | |||
| implements FileNameMapper | |||
| { | |||
| /** | |||
| * Ignored. | |||
| * | |||
| * @param from The new From value | |||
| */ | |||
| public void setFrom( final String from ) | |||
| { | |||
| } | |||
| /** | |||
| * Ignored. | |||
| * | |||
| * @param to The new To value | |||
| */ | |||
| public void setTo( final String to ) | |||
| { | |||
| } | |||
| /** | |||
| * Returns an one-element array containing the source file name. | |||
| * | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| { | |||
| return new String[]{sourceFileName}; | |||
| return new String[]{ sourceFileName }; | |||
| } | |||
| } | |||
| @@ -1,158 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.PathUtil; | |||
| /** | |||
| * Element to define a FileNameMapper. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public class Mapper | |||
| { | |||
| private MapperType m_type; | |||
| private String m_classname; | |||
| private Path m_classpath; | |||
| private String m_from; | |||
| private String m_to; | |||
| /** | |||
| * Set the class name of the FileNameMapper to use. | |||
| * | |||
| * @param classname The new Classname value | |||
| */ | |||
| public void setClassname( final String classname ) | |||
| { | |||
| m_classname = classname; | |||
| } | |||
| /** | |||
| * Set the classpath to load the FileNameMapper through (attribute). | |||
| * | |||
| * @param classpath The new Classpath value | |||
| */ | |||
| public void setClasspath( Path classpath ) | |||
| throws TaskException | |||
| { | |||
| if( m_classpath == null ) | |||
| { | |||
| m_classpath = classpath; | |||
| } | |||
| else | |||
| { | |||
| m_classpath.append( classpath ); | |||
| } | |||
| } | |||
| /** | |||
| * Set the argument to FileNameMapper.setFrom | |||
| */ | |||
| public void setFrom( final String from ) | |||
| { | |||
| m_from = from; | |||
| } | |||
| /** | |||
| * Set the argument to FileNameMapper.setTo | |||
| */ | |||
| public void setTo( final String to ) | |||
| { | |||
| m_to = to; | |||
| } | |||
| /** | |||
| * Set the type of FileNameMapper to use. | |||
| */ | |||
| public void setType( MapperType type ) | |||
| { | |||
| m_type = type; | |||
| } | |||
| /** | |||
| * Returns a fully configured FileNameMapper implementation. | |||
| * | |||
| * @return The Implementation value | |||
| * @exception TaskException Description of Exception | |||
| */ | |||
| public FileNameMapper getImplementation() | |||
| throws TaskException | |||
| { | |||
| if( m_type == null && m_classname == null ) | |||
| { | |||
| throw new TaskException( "one of the attributes type or classname is required" ); | |||
| } | |||
| if( m_type != null && m_classname != null ) | |||
| { | |||
| throw new TaskException( "must not specify both type and classname attribute" ); | |||
| } | |||
| try | |||
| { | |||
| if( m_type != null ) | |||
| { | |||
| m_classname = m_type.getImplementation(); | |||
| } | |||
| Class c = null; | |||
| if( m_classpath == null ) | |||
| { | |||
| c = Class.forName( m_classname ); | |||
| } | |||
| else | |||
| { | |||
| final URL[] urls = PathUtil.toURLs( m_classpath ); | |||
| final URLClassLoader classLoader = new URLClassLoader( urls ); | |||
| c = classLoader.loadClass( m_classname ); | |||
| } | |||
| FileNameMapper m = (FileNameMapper)c.newInstance(); | |||
| m.setFrom( m_from ); | |||
| m.setTo( m_to ); | |||
| return m; | |||
| } | |||
| catch( TaskException be ) | |||
| { | |||
| throw be; | |||
| } | |||
| catch( Throwable t ) | |||
| { | |||
| throw new TaskException( "Error", t ); | |||
| } | |||
| finally | |||
| { | |||
| if( m_type != null ) | |||
| { | |||
| m_classname = null; | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * Set the classpath to load the FileNameMapper through (nested element). | |||
| * | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public Path createClasspath() | |||
| throws TaskException | |||
| { | |||
| if( m_classpath == null ) | |||
| { | |||
| m_classpath = new Path(); | |||
| } | |||
| Path path1 = m_classpath; | |||
| final Path path = new Path(); | |||
| path1.addPath( path ); | |||
| return path; | |||
| } | |||
| } | |||
| @@ -1,45 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.util.Properties; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| /** | |||
| * Class as Argument to FileNameMapper.setType. | |||
| */ | |||
| public class MapperType | |||
| extends EnumeratedAttribute | |||
| { | |||
| private final Properties c_implementations; | |||
| public MapperType() | |||
| { | |||
| c_implementations = new Properties(); | |||
| c_implementations.put( "identity", | |||
| "org.apache.tools.ant.util.IdentityMapper" ); | |||
| c_implementations.put( "flatten", | |||
| "org.apache.tools.ant.util.FlatFileNameMapper" ); | |||
| c_implementations.put( "glob", | |||
| "org.apache.tools.ant.util.GlobPatternMapper" ); | |||
| c_implementations.put( "merge", | |||
| "org.apache.tools.ant.util.MergingMapper" ); | |||
| c_implementations.put( "regexp", | |||
| "org.apache.tools.ant.util.RegexpPatternMapper" ); | |||
| } | |||
| public String getImplementation() | |||
| { | |||
| return c_implementations.getProperty( getValue() ); | |||
| } | |||
| public String[] getValues() | |||
| { | |||
| return new String[]{"identity", "flatten", "glob", "merge", "regexp"}; | |||
| } | |||
| } | |||
| @@ -7,36 +7,31 @@ | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that always returns the same target file | |||
| * name. <p> | |||
| * | |||
| * This is the default FileNameMapper for the archiving tasks and uptodate.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="merge" | |||
| */ | |||
| public class MergingMapper | |||
| implements FileNameMapper | |||
| { | |||
| private String[] m_mergedFile; | |||
| /** | |||
| * Ignored. | |||
| * | |||
| * @param from The new From value | |||
| */ | |||
| public void setFrom( String from ) | |||
| { | |||
| } | |||
| /** | |||
| * Sets the name of the merged file. | |||
| * | |||
| * @param to The new To value | |||
| */ | |||
| public void setTo( String to ) | |||
| public void setTo( final String to ) | |||
| { | |||
| m_mergedFile = new String[]{to}; | |||
| m_mergedFile = new String[]{ to }; | |||
| } | |||
| /** | |||
| @@ -45,8 +40,13 @@ public class MergingMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| if( m_mergedFile == null ) | |||
| { | |||
| throw new TaskException( "Destination file was not specified." ); | |||
| } | |||
| return m_mergedFile; | |||
| } | |||
| } | |||
| @@ -8,7 +8,9 @@ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.util.ArrayList; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcher; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
| @@ -16,6 +18,8 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
| * Implementation of FileNameMapper that does regular expression replacements. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="regexp" | |||
| */ | |||
| public class RegexpPatternMapper | |||
| implements FileNameMapper | |||
| @@ -65,7 +69,7 @@ public class RegexpPatternMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| if( m_matcher == null || m_to == null || | |||
| @@ -10,13 +10,13 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| 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.FileSet; | |||
| import org.apache.tools.ant.types.ScannerUtil; | |||
| 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; | |||
| /** | |||
| @@ -29,16 +29,15 @@ import org.apache.tools.ant.util.mappers.MergingMapper; | |||
| * hnakamur@mc.neweb.ne.jp</a> | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public class UpToDate extends MatchingTask | |||
| public class UpToDate | |||
| extends AbstractTask | |||
| { | |||
| 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 | |||
| @@ -46,9 +45,9 @@ public class UpToDate extends MatchingTask | |||
| * | |||
| * @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. | |||
| */ | |||
| 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 | |||
| */ | |||
| 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 | |||
| */ | |||
| public void addSrcfiles( FileSet fs ) | |||
| public void addSrcfiles( final FileSet fs ) | |||
| { | |||
| sourceFileSets.add( fs ); | |||
| m_fileSets.add( fs ); | |||
| } | |||
| /** | |||
| * 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 | |||
| { | |||
| if( mapperElement != null ) | |||
| if( m_mapper != null ) | |||
| { | |||
| 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() | |||
| throws TaskException | |||
| { | |||
| if( sourceFileSets.size() == 0 ) | |||
| if( m_fileSets.size() == 0 ) | |||
| { | |||
| throw new TaskException( "At least one <srcfiles> element must be set" ); | |||
| } | |||
| if( _targetFile == null && mapperElement == null ) | |||
| if( m_targetFile == null && m_mapper == null ) | |||
| { | |||
| 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( _targetFile != null && !_targetFile.exists() ) | |||
| if( m_targetFile != null && !m_targetFile.exists() ) | |||
| { | |||
| return false; | |||
| } | |||
| Iterator enum = sourceFileSets.iterator(); | |||
| Iterator enum = m_fileSets.iterator(); | |||
| boolean upToDate = true; | |||
| while( upToDate && enum.hasNext() ) | |||
| { | |||
| @@ -148,12 +143,12 @@ public class UpToDate extends MatchingTask | |||
| boolean upToDate = eval(); | |||
| if( upToDate ) | |||
| { | |||
| final String name = _property; | |||
| final String name = m_property; | |||
| final Object value = this.getValue(); | |||
| getContext().setProperty( name, value ); | |||
| if( mapperElement == null ) | |||
| if( m_mapper == null ) | |||
| { | |||
| getLogger().debug( "File \"" + _targetFile.getAbsolutePath() + "\" is up to date." ); | |||
| getLogger().debug( "File \"" + m_targetFile.getAbsolutePath() + "\" is up to date." ); | |||
| } | |||
| else | |||
| { | |||
| @@ -169,18 +164,18 @@ public class UpToDate extends MatchingTask | |||
| setupLogger( scanner ); | |||
| FileNameMapper mapper = null; | |||
| File dir = srcDir; | |||
| if( mapperElement == null ) | |||
| if( m_mapper == null ) | |||
| { | |||
| MergingMapper mm = new MergingMapper(); | |||
| mm.setTo( _targetFile.getAbsolutePath() ); | |||
| mm.setTo( m_targetFile.getAbsolutePath() ); | |||
| mapper = mm; | |||
| dir = null; | |||
| } | |||
| else | |||
| { | |||
| mapper = mapperElement.getImplementation(); | |||
| mapper = m_mapper; | |||
| } | |||
| 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() | |||
| { | |||
| return ( _value != null ) ? _value : "true"; | |||
| return ( m_value != null ) ? m_value : "true"; | |||
| } | |||
| } | |||
| @@ -227,7 +227,7 @@ public class Tar | |||
| setupLogger( scanner ); | |||
| final MergingMapper mapper = new MergingMapper(); | |||
| mapper.setTo( tarFile.getAbsolutePath() ); | |||
| return scanner.restrict( files, baseDir, null, mapper ).length == 0; | |||
| return scanner.restrict( files, baseDir, null, mapper, getContext() ).length == 0; | |||
| } | |||
| private void tarFile( final File file, | |||
| @@ -483,7 +483,7 @@ public class Zip | |||
| for( int i = 0; i < scanners.length; i++ ) | |||
| { | |||
| if( scanner.restrict( fileNames[ i ], scanners[ i ].getBasedir(), null, | |||
| mm ).length > 0 ) | |||
| mm, getContext() ).length > 0 ) | |||
| { | |||
| return false; | |||
| } | |||
| @@ -13,11 +13,11 @@ import java.util.Iterator; | |||
| import org.apache.aut.nativelib.Os; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.JavaVersion; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.DirectoryScanner; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.GlobPatternMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| /** | |||
| * Task to compile Java source files. This task can take the following | |||
| @@ -713,7 +713,7 @@ public class Javac | |||
| m.setTo( "*.class" ); | |||
| SourceFileScanner sfs = new SourceFileScanner(); | |||
| setupLogger( sfs ); | |||
| File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m ); | |||
| File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m, getContext() ); | |||
| if( newFiles.length > 0 ) | |||
| { | |||
| @@ -11,11 +11,12 @@ import java.io.File; | |||
| import java.util.ArrayList; | |||
| import java.util.Random; | |||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| /** | |||
| * This is the default implementation for the RmicAdapter interface. Currently, | |||
| @@ -268,7 +269,7 @@ public abstract class DefaultRmicAdapter | |||
| { | |||
| } | |||
| public String[] mapFileName( String name ) | |||
| public String[] mapFileName( String name, TaskContext context ) | |||
| { | |||
| if( name == null | |||
| || !name.endsWith( ".class" ) | |||
| @@ -15,13 +15,12 @@ import java.rmi.Remote; | |||
| import java.util.ArrayList; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.DirectoryScanner; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.PathUtil; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| /** | |||
| * Task to compile RMI stubs and skeletons. This task can take the following | |||
| @@ -569,7 +568,7 @@ public class Rmic extends MatchingTask | |||
| { | |||
| final SourceFileScanner scanner = new SourceFileScanner(); | |||
| setupLogger( scanner ); | |||
| newFiles = scanner.restrict( files, baseDir, baseDir, mapper ); | |||
| newFiles = scanner.restrict( files, baseDir, baseDir, mapper, getContext() ); | |||
| } | |||
| for( int i = 0; i < newFiles.length; i++ ) | |||
| @@ -603,7 +602,7 @@ public class Rmic extends MatchingTask | |||
| String classFileName = | |||
| classname.replace( '.', File.separatorChar ) + ".class"; | |||
| String[] generatedFiles = | |||
| adapter.getMapper().mapFileName( classFileName ); | |||
| adapter.getMapper().mapFileName( classFileName, getContext() ); | |||
| for( int i = 0; i < generatedFiles.length; i++ ) | |||
| { | |||
| @@ -8,8 +8,8 @@ | |||
| package org.apache.tools.ant.taskdefs.rmic; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| /** | |||
| * The interface that all rmic adapters must adher to. <p> | |||
| @@ -1,43 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.text; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| class ExtMapper | |||
| implements FileNameMapper | |||
| { | |||
| private final String m_extension; | |||
| public ExtMapper( final String extension ) | |||
| { | |||
| m_extension = extension; | |||
| } | |||
| public void setFrom( final String from ) | |||
| { | |||
| } | |||
| public void setTo( final String to ) | |||
| { | |||
| } | |||
| public String[] mapFileName( final String filename ) | |||
| { | |||
| final int index = filename.lastIndexOf( '.' ); | |||
| if( index >= 0 ) | |||
| { | |||
| final String reult = filename.substring( 0, index ) + m_extension; | |||
| return new String[]{reult}; | |||
| } | |||
| else | |||
| { | |||
| return new String[]{filename + m_extension}; | |||
| } | |||
| } | |||
| } | |||
| @@ -9,13 +9,12 @@ package org.apache.tools.ant.taskdefs.text; | |||
| import java.io.File; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.types.DirectoryScanner; | |||
| import org.apache.tools.ant.types.SourceFileScanner; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.tools.ant.util.mappers.IdentityMapper; | |||
| import org.apache.tools.ant.util.mappers.Mapper; | |||
| /** | |||
| * Convert files from native encodings to ascii. | |||
| @@ -30,8 +29,7 @@ public class Native2Ascii | |||
| private String m_encoding;// encoding to convert to/from | |||
| private File m_srcDir;// Where to find input files | |||
| private File m_destDir;// Where to put output files | |||
| private String m_ext;// Extension of output files if different | |||
| private Mapper m_mapper; | |||
| private FileNameMapper m_mapper; | |||
| /** | |||
| * Set the destination dirctory to place converted files into. | |||
| @@ -55,17 +53,6 @@ public class Native2Ascii | |||
| m_encoding = encoding; | |||
| } | |||
| /** | |||
| * Set the extension which converted files should have. If unset, files will | |||
| * not be renamed. | |||
| * | |||
| * @param ext File extension to use for converted files. | |||
| */ | |||
| public void setExt( final String ext ) | |||
| { | |||
| m_ext = ext; | |||
| } | |||
| /** | |||
| * Flag the conversion to run in the reverse sense, that is Ascii to Native | |||
| * encoding. | |||
| @@ -89,19 +76,15 @@ public class Native2Ascii | |||
| /** | |||
| * Defines the FileNameMapper to use (nested mapper element). | |||
| * | |||
| * @return Description of the Returned Value | |||
| * @exception TaskException Description of Exception | |||
| */ | |||
| public Mapper createMapper() | |||
| public void createMapper( final FileNameMapper mapper ) | |||
| throws TaskException | |||
| { | |||
| if( m_mapper != null ) | |||
| { | |||
| throw new TaskException( "Cannot define more than one mapper" ); | |||
| } | |||
| m_mapper = new Mapper(); | |||
| return m_mapper; | |||
| m_mapper = mapper; | |||
| } | |||
| public void execute() | |||
| @@ -115,7 +98,7 @@ public class Native2Ascii | |||
| final SourceFileScanner sfs = new SourceFileScanner(); | |||
| setupLogger( sfs ); | |||
| final FileNameMapper mapper = buildMapper(); | |||
| files = sfs.restrict( files, m_srcDir, m_destDir, mapper ); | |||
| files = sfs.restrict( files, m_srcDir, m_destDir, mapper, getContext() ); | |||
| int count = files.length; | |||
| if( count == 0 ) | |||
| { | |||
| @@ -129,7 +112,7 @@ public class Native2Ascii | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| final String name = mapper.mapFileName( files[ i ] )[ 0 ]; | |||
| final String name = mapper.mapFileName( files[ i ], getContext() )[ 0 ]; | |||
| convert( files[ i ], name ); | |||
| } | |||
| } | |||
| @@ -140,18 +123,11 @@ public class Native2Ascii | |||
| FileNameMapper mapper = null; | |||
| if( m_mapper == null ) | |||
| { | |||
| if( m_ext == null ) | |||
| { | |||
| mapper = new IdentityMapper(); | |||
| } | |||
| else | |||
| { | |||
| mapper = new ExtMapper( m_ext ); | |||
| } | |||
| mapper = new IdentityMapper(); | |||
| } | |||
| else | |||
| { | |||
| mapper = m_mapper.getImplementation(); | |||
| mapper = m_mapper; | |||
| } | |||
| return mapper; | |||
| @@ -169,9 +145,9 @@ public class Native2Ascii | |||
| // if src and dest dirs are the same, require the extension | |||
| // to be set, so we don't stomp every file. One could still | |||
| // include a file with the same extension, but .... | |||
| if( m_srcDir.equals( m_destDir ) && m_ext == null && m_mapper == null ) | |||
| if( m_srcDir.equals( m_destDir ) && m_mapper == null ) | |||
| { | |||
| throw new TaskException( "The ext attribute or a mapper must be set if" + | |||
| throw new TaskException( "A mapper must be specified if" + | |||
| " src and dest dirs are the same." ); | |||
| } | |||
| @@ -13,8 +13,9 @@ import java.util.Date; | |||
| import org.apache.aut.nativelib.Os; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.util.mappers.FileNameMapper; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Utility class that collects the functionality of the various scanDir methods | |||
| @@ -40,8 +41,11 @@ public class SourceFileScanner | |||
| * @param mapper knows how to construct a target file names from source file | |||
| * names. | |||
| */ | |||
| public String[] restrict( String[] files, File srcDir, File destDir, | |||
| FileNameMapper mapper ) | |||
| public String[] restrict( final String[] files, | |||
| final File srcDir, | |||
| final File destDir, | |||
| final FileNameMapper mapper, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| @@ -64,7 +68,7 @@ public class SourceFileScanner | |||
| final ArrayList v = new ArrayList(); | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| final String[] targets = mapper.mapFileName( files[ i ] ); | |||
| final String[] targets = mapper.mapFileName( files[ i ], context ); | |||
| if( targets == null || targets.length == 0 ) | |||
| { | |||
| final String message = files[ i ] + " skipped - don\'t know how to handle it"; | |||
| @@ -130,10 +134,11 @@ public class SourceFileScanner | |||
| public File[] restrictAsFiles( final String[] files, | |||
| final File srcDir, | |||
| final File destDir, | |||
| final FileNameMapper mapper ) | |||
| final FileNameMapper mapper, | |||
| final TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| final String[] res = restrict( files, srcDir, destDir, mapper ); | |||
| final String[] res = restrict( files, srcDir, destDir, mapper, context ); | |||
| final File[] result = new File[ res.length ]; | |||
| for( int i = 0; i < res.length; i++ ) | |||
| { | |||
| @@ -1,49 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.io.File; | |||
| /** | |||
| * Implementation of FileNameMapper that always returns the source file name | |||
| * without any leading directory information. <p> | |||
| * | |||
| * This is the default FileNameMapper for the copy and move tasks if the flatten | |||
| * attribute has been set.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public class FlatFileNameMapper | |||
| implements FileNameMapper | |||
| { | |||
| /** | |||
| * Ignored. | |||
| */ | |||
| public void setFrom( final String from ) | |||
| { | |||
| } | |||
| /** | |||
| * Ignored. | |||
| */ | |||
| public void setTo( final String to ) | |||
| { | |||
| } | |||
| /** | |||
| * Returns an one-element array containing the source file name without any | |||
| * leading directory information. | |||
| * | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| { | |||
| return new String[]{new File( sourceFileName ).getName()}; | |||
| } | |||
| } | |||
| @@ -7,6 +7,9 @@ | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that does simple wildcard pattern | |||
| * replacements. <p> | |||
| @@ -18,6 +21,8 @@ package org.apache.tools.ant.util.mappers; | |||
| * This is one of the more useful Mappers, it is used by javac for example.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="glob" | |||
| */ | |||
| public class GlobPatternMapper | |||
| implements FileNameMapper | |||
| @@ -101,7 +106,7 @@ public class GlobPatternMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| { | |||
| if( m_fromPrefix == null || | |||
| !sourceFileName.startsWith( m_fromPrefix ) || | |||
| @@ -124,7 +129,7 @@ public class GlobPatternMapper | |||
| * @param name Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| protected String extractVariablePart( final String name ) | |||
| private String extractVariablePart( final String name ) | |||
| { | |||
| return name.substring( m_prefixLength, | |||
| name.length() - m_postfixLength ); | |||
| @@ -7,43 +7,28 @@ | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that always returns the source file name. | |||
| * <p> | |||
| * | |||
| * This is the default FileNameMapper for the copy and move tasks.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="identity" | |||
| */ | |||
| public class IdentityMapper | |||
| implements FileNameMapper | |||
| { | |||
| /** | |||
| * Ignored. | |||
| * | |||
| * @param from The new From value | |||
| */ | |||
| public void setFrom( final String from ) | |||
| { | |||
| } | |||
| /** | |||
| * Ignored. | |||
| * | |||
| * @param to The new To value | |||
| */ | |||
| public void setTo( final String to ) | |||
| { | |||
| } | |||
| /** | |||
| * Returns an one-element array containing the source file name. | |||
| * | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| { | |||
| return new String[]{sourceFileName}; | |||
| return new String[]{ sourceFileName }; | |||
| } | |||
| } | |||
| @@ -1,158 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.PathUtil; | |||
| /** | |||
| * Element to define a FileNameMapper. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public class Mapper | |||
| { | |||
| private MapperType m_type; | |||
| private String m_classname; | |||
| private Path m_classpath; | |||
| private String m_from; | |||
| private String m_to; | |||
| /** | |||
| * Set the class name of the FileNameMapper to use. | |||
| * | |||
| * @param classname The new Classname value | |||
| */ | |||
| public void setClassname( final String classname ) | |||
| { | |||
| m_classname = classname; | |||
| } | |||
| /** | |||
| * Set the classpath to load the FileNameMapper through (attribute). | |||
| * | |||
| * @param classpath The new Classpath value | |||
| */ | |||
| public void setClasspath( Path classpath ) | |||
| throws TaskException | |||
| { | |||
| if( m_classpath == null ) | |||
| { | |||
| m_classpath = classpath; | |||
| } | |||
| else | |||
| { | |||
| m_classpath.append( classpath ); | |||
| } | |||
| } | |||
| /** | |||
| * Set the argument to FileNameMapper.setFrom | |||
| */ | |||
| public void setFrom( final String from ) | |||
| { | |||
| m_from = from; | |||
| } | |||
| /** | |||
| * Set the argument to FileNameMapper.setTo | |||
| */ | |||
| public void setTo( final String to ) | |||
| { | |||
| m_to = to; | |||
| } | |||
| /** | |||
| * Set the type of FileNameMapper to use. | |||
| */ | |||
| public void setType( MapperType type ) | |||
| { | |||
| m_type = type; | |||
| } | |||
| /** | |||
| * Returns a fully configured FileNameMapper implementation. | |||
| * | |||
| * @return The Implementation value | |||
| * @exception TaskException Description of Exception | |||
| */ | |||
| public FileNameMapper getImplementation() | |||
| throws TaskException | |||
| { | |||
| if( m_type == null && m_classname == null ) | |||
| { | |||
| throw new TaskException( "one of the attributes type or classname is required" ); | |||
| } | |||
| if( m_type != null && m_classname != null ) | |||
| { | |||
| throw new TaskException( "must not specify both type and classname attribute" ); | |||
| } | |||
| try | |||
| { | |||
| if( m_type != null ) | |||
| { | |||
| m_classname = m_type.getImplementation(); | |||
| } | |||
| Class c = null; | |||
| if( m_classpath == null ) | |||
| { | |||
| c = Class.forName( m_classname ); | |||
| } | |||
| else | |||
| { | |||
| final URL[] urls = PathUtil.toURLs( m_classpath ); | |||
| final URLClassLoader classLoader = new URLClassLoader( urls ); | |||
| c = classLoader.loadClass( m_classname ); | |||
| } | |||
| FileNameMapper m = (FileNameMapper)c.newInstance(); | |||
| m.setFrom( m_from ); | |||
| m.setTo( m_to ); | |||
| return m; | |||
| } | |||
| catch( TaskException be ) | |||
| { | |||
| throw be; | |||
| } | |||
| catch( Throwable t ) | |||
| { | |||
| throw new TaskException( "Error", t ); | |||
| } | |||
| finally | |||
| { | |||
| if( m_type != null ) | |||
| { | |||
| m_classname = null; | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * Set the classpath to load the FileNameMapper through (nested element). | |||
| * | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public Path createClasspath() | |||
| throws TaskException | |||
| { | |||
| if( m_classpath == null ) | |||
| { | |||
| m_classpath = new Path(); | |||
| } | |||
| Path path1 = m_classpath; | |||
| final Path path = new Path(); | |||
| path1.addPath( path ); | |||
| return path; | |||
| } | |||
| } | |||
| @@ -1,45 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE.txt file. | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.util.Properties; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| /** | |||
| * Class as Argument to FileNameMapper.setType. | |||
| */ | |||
| public class MapperType | |||
| extends EnumeratedAttribute | |||
| { | |||
| private final Properties c_implementations; | |||
| public MapperType() | |||
| { | |||
| c_implementations = new Properties(); | |||
| c_implementations.put( "identity", | |||
| "org.apache.tools.ant.util.IdentityMapper" ); | |||
| c_implementations.put( "flatten", | |||
| "org.apache.tools.ant.util.FlatFileNameMapper" ); | |||
| c_implementations.put( "glob", | |||
| "org.apache.tools.ant.util.GlobPatternMapper" ); | |||
| c_implementations.put( "merge", | |||
| "org.apache.tools.ant.util.MergingMapper" ); | |||
| c_implementations.put( "regexp", | |||
| "org.apache.tools.ant.util.RegexpPatternMapper" ); | |||
| } | |||
| public String getImplementation() | |||
| { | |||
| return c_implementations.getProperty( getValue() ); | |||
| } | |||
| public String[] getValues() | |||
| { | |||
| return new String[]{"identity", "flatten", "glob", "merge", "regexp"}; | |||
| } | |||
| } | |||
| @@ -7,36 +7,31 @@ | |||
| */ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| /** | |||
| * Implementation of FileNameMapper that always returns the same target file | |||
| * name. <p> | |||
| * | |||
| * This is the default FileNameMapper for the archiving tasks and uptodate.</p> | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="merge" | |||
| */ | |||
| public class MergingMapper | |||
| implements FileNameMapper | |||
| { | |||
| private String[] m_mergedFile; | |||
| /** | |||
| * Ignored. | |||
| * | |||
| * @param from The new From value | |||
| */ | |||
| public void setFrom( String from ) | |||
| { | |||
| } | |||
| /** | |||
| * Sets the name of the merged file. | |||
| * | |||
| * @param to The new To value | |||
| */ | |||
| public void setTo( String to ) | |||
| public void setTo( final String to ) | |||
| { | |||
| m_mergedFile = new String[]{to}; | |||
| m_mergedFile = new String[]{ to }; | |||
| } | |||
| /** | |||
| @@ -45,8 +40,13 @@ public class MergingMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| if( m_mergedFile == null ) | |||
| { | |||
| throw new TaskException( "Destination file was not specified." ); | |||
| } | |||
| return m_mergedFile; | |||
| } | |||
| } | |||
| @@ -8,7 +8,9 @@ | |||
| package org.apache.tools.ant.util.mappers; | |||
| import java.util.ArrayList; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.FileNameMapper; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcher; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
| @@ -16,6 +18,8 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
| * Implementation of FileNameMapper that does regular expression replacements. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @ant:type type="mapper" name="regexp" | |||
| */ | |||
| public class RegexpPatternMapper | |||
| implements FileNameMapper | |||
| @@ -65,7 +69,7 @@ public class RegexpPatternMapper | |||
| * @param sourceFileName Description of Parameter | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public String[] mapFileName( final String sourceFileName ) | |||
| public String[] mapFileName( final String sourceFileName, TaskContext context ) | |||
| throws TaskException | |||
| { | |||
| if( m_matcher == null || m_to == null || | |||