git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270864 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -8,11 +8,9 @@ | |||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.Pattern; | import org.apache.myrmidon.framework.Pattern; | ||||
| import org.apache.myrmidon.framework.PatternSet; | import org.apache.myrmidon.framework.PatternSet; | ||||
| import org.apache.tools.ant.ProjectComponent; | |||||
| /** | /** | ||||
| * Moved out of MatchingTask to make it a standalone object that could be | * Moved out of MatchingTask to make it a standalone object that could be | ||||
| @@ -27,14 +25,11 @@ import org.apache.tools.ant.ProjectComponent; | |||||
| * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | ||||
| */ | */ | ||||
| public class FileSet | public class FileSet | ||||
| extends ProjectComponent | |||||
| implements Cloneable | |||||
| { | { | ||||
| private PatternSet m_defaultPatterns = new PatternSet(); | |||||
| private ArrayList m_additionalPatterns = new ArrayList(); | |||||
| private File m_dir; | |||||
| private PatternSet m_patternSet = new PatternSet(); | |||||
| private boolean m_useDefaultExcludes = true; | private boolean m_useDefaultExcludes = true; | ||||
| private boolean m_isCaseSensitive = true; | private boolean m_isCaseSensitive = true; | ||||
| private File m_dir; | |||||
| /** | /** | ||||
| * Sets case sensitivity of the file system | * Sets case sensitivity of the file system | ||||
| @@ -66,102 +61,58 @@ public class FileSet | |||||
| */ | */ | ||||
| public void setExcludes( final String excludes ) | public void setExcludes( final String excludes ) | ||||
| { | { | ||||
| m_defaultPatterns.setExcludes( excludes ); | |||||
| m_patternSet.setExcludes( excludes ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Sets the set of include patterns. Patterns may be separated by a comma or | |||||
| * a space. | |||||
| * | |||||
| * @param includes the string containing the include patterns | |||||
| * add a name entry on the exclude list | |||||
| */ | */ | ||||
| public void setIncludes( final String includes ) | |||||
| public void addExclude( final Pattern pattern ) | |||||
| { | { | ||||
| m_defaultPatterns.setIncludes( includes ); | |||||
| m_patternSet.addExclude( pattern ); | |||||
| } | } | ||||
| public void setupDirectoryScanner( final FileScanner ds ) | |||||
| throws TaskException | |||||
| /** | |||||
| * add a name entry on the include list | |||||
| */ | |||||
| public void addInclude( final Pattern pattern ) | |||||
| { | { | ||||
| if( null == ds ) | |||||
| { | |||||
| final String message = "ds cannot be null"; | |||||
| throw new IllegalArgumentException( message ); | |||||
| } | |||||
| ds.setBasedir( m_dir ); | |||||
| final int size = m_additionalPatterns.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | |||||
| final Object o = m_additionalPatterns.get( i ); | |||||
| m_defaultPatterns.append( (PatternSet)o ); | |||||
| } | |||||
| final String message = "FileSet: Setup file scanner in dir " + | |||||
| m_dir + " with " + m_defaultPatterns; | |||||
| getLogger().debug( message ); | |||||
| ds.setIncludes( m_defaultPatterns.getIncludePatterns( getContext() ) ); | |||||
| ds.setExcludes( m_defaultPatterns.getExcludePatterns( getContext() ) ); | |||||
| if( m_useDefaultExcludes ) | |||||
| { | |||||
| ds.addDefaultExcludes(); | |||||
| } | |||||
| ds.setCaseSensitive( m_isCaseSensitive ); | |||||
| m_patternSet.addInclude( pattern ); | |||||
| } | } | ||||
| public File getDir() | |||||
| public void addPatternSet( final PatternSet set ) | |||||
| { | { | ||||
| return m_dir; | |||||
| m_patternSet.append( set ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Returns the directory scanner needed to access the files to process. | |||||
| * Sets the set of include patterns. Patterns may be separated by a comma or | |||||
| * a space. | |||||
| * | |||||
| * @param includes the string containing the include patterns | |||||
| */ | */ | ||||
| public DirectoryScanner getDirectoryScanner() | |||||
| throws TaskException | |||||
| public void setIncludes( final String includes ) | |||||
| { | { | ||||
| if( m_dir == null ) | |||||
| { | |||||
| throw new TaskException( "No directory specified for fileset." ); | |||||
| } | |||||
| if( !m_dir.exists() ) | |||||
| { | |||||
| throw new TaskException( m_dir.getAbsolutePath() + " not found." ); | |||||
| } | |||||
| if( !m_dir.isDirectory() ) | |||||
| { | |||||
| throw new TaskException( m_dir.getAbsolutePath() + " is not a directory." ); | |||||
| } | |||||
| m_patternSet.setIncludes( includes ); | |||||
| } | |||||
| final DirectoryScanner scanner = new DirectoryScanner(); | |||||
| setupDirectoryScanner( scanner ); | |||||
| scanner.scan(); | |||||
| return scanner; | |||||
| public final PatternSet getPatternSet() | |||||
| { | |||||
| return m_patternSet; | |||||
| } | } | ||||
| /** | |||||
| * add a name entry on the exclude list | |||||
| */ | |||||
| public void addExclude( final Pattern pattern ) | |||||
| public boolean isCaseSensitive() | |||||
| { | { | ||||
| m_defaultPatterns.addExclude( pattern ); | |||||
| return m_isCaseSensitive; | |||||
| } | } | ||||
| /** | |||||
| * add a name entry on the include list | |||||
| */ | |||||
| public void addInclude( final Pattern pattern ) | |||||
| public boolean useDefaultExcludes() | |||||
| { | { | ||||
| m_defaultPatterns.addInclude( pattern ); | |||||
| return m_useDefaultExcludes; | |||||
| } | } | ||||
| public PatternSet createPatternSet() | |||||
| public File getDir() | |||||
| { | { | ||||
| final PatternSet patterns = new PatternSet(); | |||||
| m_additionalPatterns.add( patterns ); | |||||
| return patterns; | |||||
| return m_dir; | |||||
| } | } | ||||
| } | } | ||||
| @@ -205,7 +205,7 @@ public class Path | |||||
| else if( o instanceof FileSet ) | else if( o instanceof FileSet ) | ||||
| { | { | ||||
| final FileSet fs = (FileSet)o; | final FileSet fs = (FileSet)o; | ||||
| final DirectoryScanner ds = fs.getDirectoryScanner(); | |||||
| final DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs ); | |||||
| final String[] s = ds.getIncludedFiles(); | final String[] s = ds.getIncludedFiles(); | ||||
| final File dir = fs.getDir(); | final File dir = fs.getDir(); | ||||
| for( int j = 0; j < s.length; j++ ) | for( int j = 0; j < s.length; j++ ) | ||||
| @@ -10,6 +10,9 @@ package org.apache.tools.ant.types; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.framework.PatternUtil; | |||||
| /** | /** | ||||
| * | * | ||||
| @@ -524,4 +527,57 @@ public class ScannerUtil | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| public static void setupDirectoryScanner( final FileSet set, | |||||
| final FileScanner scanner, | |||||
| final TaskContext context ) | |||||
| throws TaskException | |||||
| { | |||||
| if( null == scanner ) | |||||
| { | |||||
| final String message = "ds cannot be null"; | |||||
| throw new IllegalArgumentException( message ); | |||||
| } | |||||
| scanner.setBasedir( set.getDir() ); | |||||
| final String message = "FileSet: Setup file scanner in dir " + | |||||
| set.getDir() + " with " + set.getPatternSet(); | |||||
| //getLogger().debug( message ); | |||||
| scanner.setIncludes( PatternUtil.getIncludePatterns( set.getPatternSet(), context ) ); | |||||
| scanner.setExcludes( PatternUtil.getExcludePatterns( set.getPatternSet(), context ) ); | |||||
| if( set.useDefaultExcludes() ) | |||||
| { | |||||
| scanner.addDefaultExcludes(); | |||||
| } | |||||
| scanner.setCaseSensitive( set.isCaseSensitive() ); | |||||
| } | |||||
| public static DirectoryScanner getDirectoryScanner( final FileSet set ) | |||||
| throws TaskException | |||||
| { | |||||
| final File dir = set.getDir(); | |||||
| if( null == dir ) | |||||
| { | |||||
| final String message = "No directory specified for fileset."; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| if( !dir.exists() ) | |||||
| { | |||||
| final String message = dir.getAbsolutePath() + " not found."; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| if( !dir.isDirectory() ) | |||||
| { | |||||
| final String message = dir.getAbsolutePath() + " is not a directory."; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| final DirectoryScanner scanner = new DirectoryScanner(); | |||||
| setupDirectoryScanner( set, scanner, null ); | |||||
| scanner.scan(); | |||||
| return scanner; | |||||
| } | |||||
| } | } | ||||
| @@ -9,6 +9,7 @@ package org.apache.tools.ant.types; | |||||
| import java.io.File; | import java.io.File; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| /** | /** | ||||
| @@ -103,16 +104,16 @@ public class ZipFileSet | |||||
| { | { | ||||
| if( srcFile != null ) | if( srcFile != null ) | ||||
| { | { | ||||
| ZipScanner zs = new ZipScanner(); | |||||
| final ZipScanner zs = new ZipScanner(); | |||||
| zs.setSrc( srcFile ); | zs.setSrc( srcFile ); | ||||
| super.setDir( p.getBaseDir() ); | super.setDir( p.getBaseDir() ); | ||||
| setupDirectoryScanner( zs ); | |||||
| ScannerUtil.setupDirectoryScanner( this, zs, null ); | |||||
| zs.init(); | zs.init(); | ||||
| return zs; | return zs; | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| return super.getDirectoryScanner(); | |||||
| return ScannerUtil.getDirectoryScanner( this ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -8,11 +8,9 @@ | |||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.Pattern; | import org.apache.myrmidon.framework.Pattern; | ||||
| import org.apache.myrmidon.framework.PatternSet; | import org.apache.myrmidon.framework.PatternSet; | ||||
| import org.apache.tools.ant.ProjectComponent; | |||||
| /** | /** | ||||
| * Moved out of MatchingTask to make it a standalone object that could be | * Moved out of MatchingTask to make it a standalone object that could be | ||||
| @@ -27,14 +25,11 @@ import org.apache.tools.ant.ProjectComponent; | |||||
| * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | ||||
| */ | */ | ||||
| public class FileSet | public class FileSet | ||||
| extends ProjectComponent | |||||
| implements Cloneable | |||||
| { | { | ||||
| private PatternSet m_defaultPatterns = new PatternSet(); | |||||
| private ArrayList m_additionalPatterns = new ArrayList(); | |||||
| private File m_dir; | |||||
| private PatternSet m_patternSet = new PatternSet(); | |||||
| private boolean m_useDefaultExcludes = true; | private boolean m_useDefaultExcludes = true; | ||||
| private boolean m_isCaseSensitive = true; | private boolean m_isCaseSensitive = true; | ||||
| private File m_dir; | |||||
| /** | /** | ||||
| * Sets case sensitivity of the file system | * Sets case sensitivity of the file system | ||||
| @@ -66,102 +61,58 @@ public class FileSet | |||||
| */ | */ | ||||
| public void setExcludes( final String excludes ) | public void setExcludes( final String excludes ) | ||||
| { | { | ||||
| m_defaultPatterns.setExcludes( excludes ); | |||||
| m_patternSet.setExcludes( excludes ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Sets the set of include patterns. Patterns may be separated by a comma or | |||||
| * a space. | |||||
| * | |||||
| * @param includes the string containing the include patterns | |||||
| * add a name entry on the exclude list | |||||
| */ | */ | ||||
| public void setIncludes( final String includes ) | |||||
| public void addExclude( final Pattern pattern ) | |||||
| { | { | ||||
| m_defaultPatterns.setIncludes( includes ); | |||||
| m_patternSet.addExclude( pattern ); | |||||
| } | } | ||||
| public void setupDirectoryScanner( final FileScanner ds ) | |||||
| throws TaskException | |||||
| /** | |||||
| * add a name entry on the include list | |||||
| */ | |||||
| public void addInclude( final Pattern pattern ) | |||||
| { | { | ||||
| if( null == ds ) | |||||
| { | |||||
| final String message = "ds cannot be null"; | |||||
| throw new IllegalArgumentException( message ); | |||||
| } | |||||
| ds.setBasedir( m_dir ); | |||||
| final int size = m_additionalPatterns.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | |||||
| final Object o = m_additionalPatterns.get( i ); | |||||
| m_defaultPatterns.append( (PatternSet)o ); | |||||
| } | |||||
| final String message = "FileSet: Setup file scanner in dir " + | |||||
| m_dir + " with " + m_defaultPatterns; | |||||
| getLogger().debug( message ); | |||||
| ds.setIncludes( m_defaultPatterns.getIncludePatterns( getContext() ) ); | |||||
| ds.setExcludes( m_defaultPatterns.getExcludePatterns( getContext() ) ); | |||||
| if( m_useDefaultExcludes ) | |||||
| { | |||||
| ds.addDefaultExcludes(); | |||||
| } | |||||
| ds.setCaseSensitive( m_isCaseSensitive ); | |||||
| m_patternSet.addInclude( pattern ); | |||||
| } | } | ||||
| public File getDir() | |||||
| public void addPatternSet( final PatternSet set ) | |||||
| { | { | ||||
| return m_dir; | |||||
| m_patternSet.append( set ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Returns the directory scanner needed to access the files to process. | |||||
| * Sets the set of include patterns. Patterns may be separated by a comma or | |||||
| * a space. | |||||
| * | |||||
| * @param includes the string containing the include patterns | |||||
| */ | */ | ||||
| public DirectoryScanner getDirectoryScanner() | |||||
| throws TaskException | |||||
| public void setIncludes( final String includes ) | |||||
| { | { | ||||
| if( m_dir == null ) | |||||
| { | |||||
| throw new TaskException( "No directory specified for fileset." ); | |||||
| } | |||||
| if( !m_dir.exists() ) | |||||
| { | |||||
| throw new TaskException( m_dir.getAbsolutePath() + " not found." ); | |||||
| } | |||||
| if( !m_dir.isDirectory() ) | |||||
| { | |||||
| throw new TaskException( m_dir.getAbsolutePath() + " is not a directory." ); | |||||
| } | |||||
| m_patternSet.setIncludes( includes ); | |||||
| } | |||||
| final DirectoryScanner scanner = new DirectoryScanner(); | |||||
| setupDirectoryScanner( scanner ); | |||||
| scanner.scan(); | |||||
| return scanner; | |||||
| public final PatternSet getPatternSet() | |||||
| { | |||||
| return m_patternSet; | |||||
| } | } | ||||
| /** | |||||
| * add a name entry on the exclude list | |||||
| */ | |||||
| public void addExclude( final Pattern pattern ) | |||||
| public boolean isCaseSensitive() | |||||
| { | { | ||||
| m_defaultPatterns.addExclude( pattern ); | |||||
| return m_isCaseSensitive; | |||||
| } | } | ||||
| /** | |||||
| * add a name entry on the include list | |||||
| */ | |||||
| public void addInclude( final Pattern pattern ) | |||||
| public boolean useDefaultExcludes() | |||||
| { | { | ||||
| m_defaultPatterns.addInclude( pattern ); | |||||
| return m_useDefaultExcludes; | |||||
| } | } | ||||
| public PatternSet createPatternSet() | |||||
| public File getDir() | |||||
| { | { | ||||
| final PatternSet patterns = new PatternSet(); | |||||
| m_additionalPatterns.add( patterns ); | |||||
| return patterns; | |||||
| return m_dir; | |||||
| } | } | ||||
| } | } | ||||
| @@ -205,7 +205,7 @@ public class Path | |||||
| else if( o instanceof FileSet ) | else if( o instanceof FileSet ) | ||||
| { | { | ||||
| final FileSet fs = (FileSet)o; | final FileSet fs = (FileSet)o; | ||||
| final DirectoryScanner ds = fs.getDirectoryScanner(); | |||||
| final DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs ); | |||||
| final String[] s = ds.getIncludedFiles(); | final String[] s = ds.getIncludedFiles(); | ||||
| final File dir = fs.getDir(); | final File dir = fs.getDir(); | ||||
| for( int j = 0; j < s.length; j++ ) | for( int j = 0; j < s.length; j++ ) | ||||
| @@ -10,6 +10,9 @@ package org.apache.tools.ant.types; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.framework.PatternUtil; | |||||
| /** | /** | ||||
| * | * | ||||
| @@ -524,4 +527,57 @@ public class ScannerUtil | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| public static void setupDirectoryScanner( final FileSet set, | |||||
| final FileScanner scanner, | |||||
| final TaskContext context ) | |||||
| throws TaskException | |||||
| { | |||||
| if( null == scanner ) | |||||
| { | |||||
| final String message = "ds cannot be null"; | |||||
| throw new IllegalArgumentException( message ); | |||||
| } | |||||
| scanner.setBasedir( set.getDir() ); | |||||
| final String message = "FileSet: Setup file scanner in dir " + | |||||
| set.getDir() + " with " + set.getPatternSet(); | |||||
| //getLogger().debug( message ); | |||||
| scanner.setIncludes( PatternUtil.getIncludePatterns( set.getPatternSet(), context ) ); | |||||
| scanner.setExcludes( PatternUtil.getExcludePatterns( set.getPatternSet(), context ) ); | |||||
| if( set.useDefaultExcludes() ) | |||||
| { | |||||
| scanner.addDefaultExcludes(); | |||||
| } | |||||
| scanner.setCaseSensitive( set.isCaseSensitive() ); | |||||
| } | |||||
| public static DirectoryScanner getDirectoryScanner( final FileSet set ) | |||||
| throws TaskException | |||||
| { | |||||
| final File dir = set.getDir(); | |||||
| if( null == dir ) | |||||
| { | |||||
| final String message = "No directory specified for fileset."; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| if( !dir.exists() ) | |||||
| { | |||||
| final String message = dir.getAbsolutePath() + " not found."; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| if( !dir.isDirectory() ) | |||||
| { | |||||
| final String message = dir.getAbsolutePath() + " is not a directory."; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| final DirectoryScanner scanner = new DirectoryScanner(); | |||||
| setupDirectoryScanner( set, scanner, null ); | |||||
| scanner.scan(); | |||||
| return scanner; | |||||
| } | |||||
| } | } | ||||
| @@ -9,6 +9,7 @@ package org.apache.tools.ant.types; | |||||
| import java.io.File; | import java.io.File; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| /** | /** | ||||
| @@ -103,16 +104,16 @@ public class ZipFileSet | |||||
| { | { | ||||
| if( srcFile != null ) | if( srcFile != null ) | ||||
| { | { | ||||
| ZipScanner zs = new ZipScanner(); | |||||
| final ZipScanner zs = new ZipScanner(); | |||||
| zs.setSrc( srcFile ); | zs.setSrc( srcFile ); | ||||
| super.setDir( p.getBaseDir() ); | super.setDir( p.getBaseDir() ); | ||||
| setupDirectoryScanner( zs ); | |||||
| ScannerUtil.setupDirectoryScanner( this, zs, null ); | |||||
| zs.init(); | zs.init(); | ||||
| return zs; | return zs; | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| return super.getDirectoryScanner(); | |||||
| return ScannerUtil.getDirectoryScanner( this ); | |||||
| } | } | ||||
| } | } | ||||