Remove ability to load patterns from files and so forth - do this in a separate task. cleaned up a bit of cruft aswell. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270835 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -7,17 +7,12 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import java.io.BufferedReader; | |||||
| import java.io.File; | |||||
| import java.io.FileReader; | |||||
| import java.io.IOException; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| 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.tools.ant.Project; | |||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| /** | /** | ||||
| @@ -38,13 +33,6 @@ public class PatternSet | |||||
| { | { | ||||
| private ArrayList m_includeList = new ArrayList(); | private ArrayList m_includeList = new ArrayList(); | ||||
| private ArrayList m_excludeList = new ArrayList(); | private ArrayList m_excludeList = new ArrayList(); | ||||
| private ArrayList m_includesFileList = new ArrayList(); | |||||
| private ArrayList m_excludesFileList = new ArrayList(); | |||||
| public PatternSet() | |||||
| { | |||||
| super(); | |||||
| } | |||||
| /** | /** | ||||
| * Sets the set of exclude patterns. Patterns may be separated by a comma or | * Sets the set of exclude patterns. Patterns may be separated by a comma or | ||||
| @@ -52,131 +40,68 @@ public class PatternSet | |||||
| * | * | ||||
| * @param excludes the string containing the exclude patterns | * @param excludes the string containing the exclude patterns | ||||
| */ | */ | ||||
| public void setExcludes( String excludes ) | |||||
| public void setExcludes( final String excludes ) | |||||
| { | { | ||||
| if( excludes != null && excludes.length() > 0 ) | |||||
| final Pattern[] patterns = parsePatterns( excludes ); | |||||
| for( int i = 0; i < patterns.length; i++ ) | |||||
| { | { | ||||
| StringTokenizer tok = new StringTokenizer( excludes, ", ", false ); | |||||
| while( tok.hasMoreTokens() ) | |||||
| { | |||||
| createExclude().setName( tok.nextToken() ); | |||||
| } | |||||
| addExclude( patterns[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Sets the name of the file containing the excludes patterns. | |||||
| * | |||||
| * @param excludesFile The file to fetch the exclude patterns from. | |||||
| * @exception TaskException Description of Exception | |||||
| */ | |||||
| public void setExcludesfile( File excludesFile ) | |||||
| { | |||||
| createExcludesFile().setName( excludesFile.getAbsolutePath() ); | |||||
| } | |||||
| /** | /** | ||||
| * Sets the set of include patterns. Patterns may be separated by a comma or | * Sets the set of include patterns. Patterns may be separated by a comma or | ||||
| * a space. | * a space. | ||||
| * | * | ||||
| * @param includes the string containing the include patterns | * @param includes the string containing the include patterns | ||||
| */ | */ | ||||
| public void setIncludes( String includes ) | |||||
| public void setIncludes( final String includes ) | |||||
| { | { | ||||
| if( includes != null && includes.length() > 0 ) | |||||
| final Pattern[] patterns = parsePatterns( includes ); | |||||
| for( int i = 0; i < patterns.length; i++ ) | |||||
| { | { | ||||
| StringTokenizer tok = new StringTokenizer( includes, ", ", false ); | |||||
| while( tok.hasMoreTokens() ) | |||||
| { | |||||
| createInclude().setName( tok.nextToken() ); | |||||
| } | |||||
| addInclude( patterns[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Sets the name of the file containing the includes patterns. | |||||
| * add a name entry on the exclude list | |||||
| */ | */ | ||||
| public void setIncludesfile( File includesFile ) | |||||
| { | |||||
| createIncludesFile().setName( includesFile.getAbsolutePath() ); | |||||
| } | |||||
| public String[] getExcludePatterns( final TaskContext context ) | |||||
| throws TaskException | |||||
| public void addExclude( final Pattern pattern ) | |||||
| { | { | ||||
| readFiles( context ); | |||||
| return makeArray( m_excludeList, context ); | |||||
| m_excludeList.add( pattern ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Returns the filtered include patterns. | |||||
| * add a name entry on the include list | |||||
| */ | */ | ||||
| public String[] getIncludePatterns( final TaskContext context ) | |||||
| throws TaskException | |||||
| public void addInclude( final Pattern pattern ) | |||||
| { | { | ||||
| readFiles( context ); | |||||
| return makeArray( m_includeList, context ); | |||||
| m_includeList.add( pattern ); | |||||
| } | } | ||||
| /** | |||||
| * Adds the patterns of the other instance to this set. | |||||
| */ | |||||
| protected void append( PatternSet other ) | |||||
| public String[] getExcludePatterns( final TaskContext context ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| String[] incl = other.getIncludePatterns( (TaskContext)null ); | |||||
| if( incl != null ) | |||||
| { | |||||
| for( int i = 0; i < incl.length; i++ ) | |||||
| { | |||||
| createInclude().setName( incl[ i ] ); | |||||
| } | |||||
| } | |||||
| String[] excl = other.getExcludePatterns( (TaskContext)null ); | |||||
| if( excl != null ) | |||||
| { | |||||
| for( int i = 0; i < excl.length; i++ ) | |||||
| { | |||||
| createExclude().setName( excl[ i ] ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * add a name entry on the exclude list | |||||
| * | |||||
| * @return Description of the Returned Value | |||||
| */ | |||||
| public Pattern createExclude() | |||||
| { | |||||
| return addPatternToList( m_excludeList ); | |||||
| } | |||||
| /** | |||||
| * add a name entry on the exclude files list | |||||
| * | |||||
| * @return Description of the Returned Value | |||||
| */ | |||||
| public Pattern createExcludesFile() | |||||
| { | |||||
| return addPatternToList( m_excludesFileList ); | |||||
| return toArray( m_excludeList, context ); | |||||
| } | } | ||||
| /** | /** | ||||
| * add a name entry on the include list | |||||
| * Returns the filtered include patterns. | |||||
| */ | */ | ||||
| public Pattern createInclude() | |||||
| public String[] getIncludePatterns( final TaskContext context ) | |||||
| throws TaskException | |||||
| { | { | ||||
| return addPatternToList( m_includeList ); | |||||
| return toArray( m_includeList, context ); | |||||
| } | } | ||||
| /** | /** | ||||
| * add a name entry on the include files list | |||||
| * Adds the patterns of the other instance to this set. | |||||
| */ | */ | ||||
| public Pattern createIncludesFile() | |||||
| protected void append( final PatternSet other ) | |||||
| { | { | ||||
| return addPatternToList( m_includesFileList ); | |||||
| m_includeList.addAll( other.m_includeList ); | |||||
| m_excludeList.addAll( other.m_excludeList ); | |||||
| } | } | ||||
| public String toString() | public String toString() | ||||
| @@ -185,154 +110,44 @@ public class PatternSet | |||||
| " excludes: " + m_excludeList + " }"; | " excludes: " + m_excludeList + " }"; | ||||
| } | } | ||||
| /** | |||||
| * helper for FileSet. | |||||
| */ | |||||
| boolean hasPatterns() | |||||
| { | |||||
| return m_includesFileList.size() > 0 || m_excludesFileList.size() > 0 || | |||||
| m_includeList.size() > 0 || m_excludeList.size() > 0; | |||||
| } | |||||
| /** | |||||
| * add a name entry to the given list | |||||
| */ | |||||
| private Pattern addPatternToList( final ArrayList list ) | |||||
| private Pattern[] parsePatterns( final String patternString ) | |||||
| { | { | ||||
| final Pattern result = new Pattern(); | |||||
| list.add( result ); | |||||
| return result; | |||||
| } | |||||
| /** | |||||
| * Convert a vector of Pattern elements into an array of Strings. | |||||
| */ | |||||
| private String[] makeArray( final ArrayList list, final TaskContext context ) | |||||
| { | |||||
| if( list.size() == 0 ) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| final ArrayList tmpNames = new ArrayList(); | |||||
| for( Iterator e = list.iterator(); e.hasNext(); ) | |||||
| final ArrayList patterns = new ArrayList(); | |||||
| if( patternString != null && patternString.length() > 0 ) | |||||
| { | { | ||||
| final Pattern ne = (Pattern)e.next(); | |||||
| final String pattern = ne.evaluateName( context ); | |||||
| if( pattern != null && pattern.length() > 0 ) | |||||
| StringTokenizer tok = new StringTokenizer( patternString, ", ", false ); | |||||
| while( tok.hasMoreTokens() ) | |||||
| { | { | ||||
| tmpNames.add( pattern ); | |||||
| final Pattern pattern = new Pattern( tok.nextToken() ); | |||||
| patterns.add( pattern ); | |||||
| } | } | ||||
| } | } | ||||
| final String[] result = new String[ tmpNames.size() ]; | |||||
| return (String[])tmpNames.toArray( result ); | |||||
| return (Pattern[])patterns.toArray( new Pattern[ patterns.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Read includesfile ot excludesfile if not already done so. | |||||
| * Convert a vector of Pattern elements into an array of Strings. | |||||
| */ | */ | ||||
| private void readFiles( final TaskContext context ) | |||||
| throws TaskException | |||||
| private String[] toArray( final ArrayList list, final TaskContext context ) | |||||
| { | { | ||||
| if( m_includesFileList.size() > 0 ) | |||||
| if( list.size() == 0 ) | |||||
| { | { | ||||
| Iterator e = m_includesFileList.iterator(); | |||||
| while( e.hasNext() ) | |||||
| { | |||||
| Pattern ne = (Pattern)e.next(); | |||||
| String fileName = ne.evaluateName( (TaskContext)null ); | |||||
| if( fileName != null ) | |||||
| { | |||||
| File inclFile = resolveFile( fileName ); | |||||
| if( !inclFile.exists() ) | |||||
| { | |||||
| throw new TaskException( "Includesfile " | |||||
| + inclFile.getAbsolutePath() | |||||
| + " not found." ); | |||||
| } | |||||
| readPatterns( inclFile, m_includeList, null ); | |||||
| } | |||||
| } | |||||
| m_includesFileList.clear(); | |||||
| return null; | |||||
| } | } | ||||
| if( m_excludesFileList.size() > 0 ) | |||||
| final ArrayList names = new ArrayList(); | |||||
| final Iterator e = list.iterator(); | |||||
| while( e.hasNext() ) | |||||
| { | { | ||||
| Iterator e = m_excludesFileList.iterator(); | |||||
| while( e.hasNext() ) | |||||
| final Pattern pattern = (Pattern)e.next(); | |||||
| final String result = pattern.evaluateName( context ); | |||||
| if( null != result && result.length() > 0 ) | |||||
| { | { | ||||
| Pattern ne = (Pattern)e.next(); | |||||
| String fileName = ne.evaluateName( null ); | |||||
| if( fileName != null ) | |||||
| { | |||||
| File exclFile = resolveFile( fileName ); | |||||
| if( !exclFile.exists() ) | |||||
| { | |||||
| throw new TaskException( "Excludesfile " | |||||
| + exclFile.getAbsolutePath() | |||||
| + " not found." ); | |||||
| } | |||||
| readPatterns( exclFile, m_excludeList, null ); | |||||
| } | |||||
| names.add( result ); | |||||
| } | } | ||||
| m_excludesFileList.clear(); | |||||
| } | } | ||||
| } | |||||
| /** | |||||
| * Reads path matching patterns from a file and adds them to the includes or | |||||
| * excludes list (as appropriate). | |||||
| * | |||||
| * @param patternfile Description of Parameter | |||||
| * @param patternlist Description of Parameter | |||||
| * @param p Description of Parameter | |||||
| * @exception TaskException Description of Exception | |||||
| */ | |||||
| private void readPatterns( File patternfile, ArrayList patternlist, Project p ) | |||||
| throws TaskException | |||||
| { | |||||
| BufferedReader patternReader = null; | |||||
| try | |||||
| { | |||||
| // Get a FileReader | |||||
| patternReader = | |||||
| new BufferedReader( new FileReader( patternfile ) ); | |||||
| // Create one Pattern in the appropriate pattern list for each | |||||
| // line in the file. | |||||
| String line = patternReader.readLine(); | |||||
| while( line != null ) | |||||
| { | |||||
| if( line.length() > 0 ) | |||||
| { | |||||
| line = p.replaceProperties( line ); | |||||
| addPatternToList( patternlist ).setName( line ); | |||||
| } | |||||
| line = patternReader.readLine(); | |||||
| } | |||||
| } | |||||
| catch( IOException ioe ) | |||||
| { | |||||
| String msg = "An error occured while reading from pattern file: " | |||||
| + patternfile; | |||||
| throw new TaskException( msg, ioe ); | |||||
| } | |||||
| finally | |||||
| { | |||||
| if( null != patternReader ) | |||||
| { | |||||
| try | |||||
| { | |||||
| patternReader.close(); | |||||
| } | |||||
| catch( IOException ioe ) | |||||
| { | |||||
| //Ignore exception | |||||
| } | |||||
| } | |||||
| } | |||||
| return (String[])names.toArray( new String[ names.size() ] ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -7,17 +7,12 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import java.io.BufferedReader; | |||||
| import java.io.File; | |||||
| import java.io.FileReader; | |||||
| import java.io.IOException; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| 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.tools.ant.Project; | |||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| /** | /** | ||||
| @@ -38,13 +33,6 @@ public class PatternSet | |||||
| { | { | ||||
| private ArrayList m_includeList = new ArrayList(); | private ArrayList m_includeList = new ArrayList(); | ||||
| private ArrayList m_excludeList = new ArrayList(); | private ArrayList m_excludeList = new ArrayList(); | ||||
| private ArrayList m_includesFileList = new ArrayList(); | |||||
| private ArrayList m_excludesFileList = new ArrayList(); | |||||
| public PatternSet() | |||||
| { | |||||
| super(); | |||||
| } | |||||
| /** | /** | ||||
| * Sets the set of exclude patterns. Patterns may be separated by a comma or | * Sets the set of exclude patterns. Patterns may be separated by a comma or | ||||
| @@ -52,131 +40,68 @@ public class PatternSet | |||||
| * | * | ||||
| * @param excludes the string containing the exclude patterns | * @param excludes the string containing the exclude patterns | ||||
| */ | */ | ||||
| public void setExcludes( String excludes ) | |||||
| public void setExcludes( final String excludes ) | |||||
| { | { | ||||
| if( excludes != null && excludes.length() > 0 ) | |||||
| final Pattern[] patterns = parsePatterns( excludes ); | |||||
| for( int i = 0; i < patterns.length; i++ ) | |||||
| { | { | ||||
| StringTokenizer tok = new StringTokenizer( excludes, ", ", false ); | |||||
| while( tok.hasMoreTokens() ) | |||||
| { | |||||
| createExclude().setName( tok.nextToken() ); | |||||
| } | |||||
| addExclude( patterns[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Sets the name of the file containing the excludes patterns. | |||||
| * | |||||
| * @param excludesFile The file to fetch the exclude patterns from. | |||||
| * @exception TaskException Description of Exception | |||||
| */ | |||||
| public void setExcludesfile( File excludesFile ) | |||||
| { | |||||
| createExcludesFile().setName( excludesFile.getAbsolutePath() ); | |||||
| } | |||||
| /** | /** | ||||
| * Sets the set of include patterns. Patterns may be separated by a comma or | * Sets the set of include patterns. Patterns may be separated by a comma or | ||||
| * a space. | * a space. | ||||
| * | * | ||||
| * @param includes the string containing the include patterns | * @param includes the string containing the include patterns | ||||
| */ | */ | ||||
| public void setIncludes( String includes ) | |||||
| public void setIncludes( final String includes ) | |||||
| { | { | ||||
| if( includes != null && includes.length() > 0 ) | |||||
| final Pattern[] patterns = parsePatterns( includes ); | |||||
| for( int i = 0; i < patterns.length; i++ ) | |||||
| { | { | ||||
| StringTokenizer tok = new StringTokenizer( includes, ", ", false ); | |||||
| while( tok.hasMoreTokens() ) | |||||
| { | |||||
| createInclude().setName( tok.nextToken() ); | |||||
| } | |||||
| addInclude( patterns[ i ] ); | |||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Sets the name of the file containing the includes patterns. | |||||
| * add a name entry on the exclude list | |||||
| */ | */ | ||||
| public void setIncludesfile( File includesFile ) | |||||
| { | |||||
| createIncludesFile().setName( includesFile.getAbsolutePath() ); | |||||
| } | |||||
| public String[] getExcludePatterns( final TaskContext context ) | |||||
| throws TaskException | |||||
| public void addExclude( final Pattern pattern ) | |||||
| { | { | ||||
| readFiles( context ); | |||||
| return makeArray( m_excludeList, context ); | |||||
| m_excludeList.add( pattern ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Returns the filtered include patterns. | |||||
| * add a name entry on the include list | |||||
| */ | */ | ||||
| public String[] getIncludePatterns( final TaskContext context ) | |||||
| throws TaskException | |||||
| public void addInclude( final Pattern pattern ) | |||||
| { | { | ||||
| readFiles( context ); | |||||
| return makeArray( m_includeList, context ); | |||||
| m_includeList.add( pattern ); | |||||
| } | } | ||||
| /** | |||||
| * Adds the patterns of the other instance to this set. | |||||
| */ | |||||
| protected void append( PatternSet other ) | |||||
| public String[] getExcludePatterns( final TaskContext context ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| String[] incl = other.getIncludePatterns( (TaskContext)null ); | |||||
| if( incl != null ) | |||||
| { | |||||
| for( int i = 0; i < incl.length; i++ ) | |||||
| { | |||||
| createInclude().setName( incl[ i ] ); | |||||
| } | |||||
| } | |||||
| String[] excl = other.getExcludePatterns( (TaskContext)null ); | |||||
| if( excl != null ) | |||||
| { | |||||
| for( int i = 0; i < excl.length; i++ ) | |||||
| { | |||||
| createExclude().setName( excl[ i ] ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * add a name entry on the exclude list | |||||
| * | |||||
| * @return Description of the Returned Value | |||||
| */ | |||||
| public Pattern createExclude() | |||||
| { | |||||
| return addPatternToList( m_excludeList ); | |||||
| } | |||||
| /** | |||||
| * add a name entry on the exclude files list | |||||
| * | |||||
| * @return Description of the Returned Value | |||||
| */ | |||||
| public Pattern createExcludesFile() | |||||
| { | |||||
| return addPatternToList( m_excludesFileList ); | |||||
| return toArray( m_excludeList, context ); | |||||
| } | } | ||||
| /** | /** | ||||
| * add a name entry on the include list | |||||
| * Returns the filtered include patterns. | |||||
| */ | */ | ||||
| public Pattern createInclude() | |||||
| public String[] getIncludePatterns( final TaskContext context ) | |||||
| throws TaskException | |||||
| { | { | ||||
| return addPatternToList( m_includeList ); | |||||
| return toArray( m_includeList, context ); | |||||
| } | } | ||||
| /** | /** | ||||
| * add a name entry on the include files list | |||||
| * Adds the patterns of the other instance to this set. | |||||
| */ | */ | ||||
| public Pattern createIncludesFile() | |||||
| protected void append( final PatternSet other ) | |||||
| { | { | ||||
| return addPatternToList( m_includesFileList ); | |||||
| m_includeList.addAll( other.m_includeList ); | |||||
| m_excludeList.addAll( other.m_excludeList ); | |||||
| } | } | ||||
| public String toString() | public String toString() | ||||
| @@ -185,154 +110,44 @@ public class PatternSet | |||||
| " excludes: " + m_excludeList + " }"; | " excludes: " + m_excludeList + " }"; | ||||
| } | } | ||||
| /** | |||||
| * helper for FileSet. | |||||
| */ | |||||
| boolean hasPatterns() | |||||
| { | |||||
| return m_includesFileList.size() > 0 || m_excludesFileList.size() > 0 || | |||||
| m_includeList.size() > 0 || m_excludeList.size() > 0; | |||||
| } | |||||
| /** | |||||
| * add a name entry to the given list | |||||
| */ | |||||
| private Pattern addPatternToList( final ArrayList list ) | |||||
| private Pattern[] parsePatterns( final String patternString ) | |||||
| { | { | ||||
| final Pattern result = new Pattern(); | |||||
| list.add( result ); | |||||
| return result; | |||||
| } | |||||
| /** | |||||
| * Convert a vector of Pattern elements into an array of Strings. | |||||
| */ | |||||
| private String[] makeArray( final ArrayList list, final TaskContext context ) | |||||
| { | |||||
| if( list.size() == 0 ) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| final ArrayList tmpNames = new ArrayList(); | |||||
| for( Iterator e = list.iterator(); e.hasNext(); ) | |||||
| final ArrayList patterns = new ArrayList(); | |||||
| if( patternString != null && patternString.length() > 0 ) | |||||
| { | { | ||||
| final Pattern ne = (Pattern)e.next(); | |||||
| final String pattern = ne.evaluateName( context ); | |||||
| if( pattern != null && pattern.length() > 0 ) | |||||
| StringTokenizer tok = new StringTokenizer( patternString, ", ", false ); | |||||
| while( tok.hasMoreTokens() ) | |||||
| { | { | ||||
| tmpNames.add( pattern ); | |||||
| final Pattern pattern = new Pattern( tok.nextToken() ); | |||||
| patterns.add( pattern ); | |||||
| } | } | ||||
| } | } | ||||
| final String[] result = new String[ tmpNames.size() ]; | |||||
| return (String[])tmpNames.toArray( result ); | |||||
| return (Pattern[])patterns.toArray( new Pattern[ patterns.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Read includesfile ot excludesfile if not already done so. | |||||
| * Convert a vector of Pattern elements into an array of Strings. | |||||
| */ | */ | ||||
| private void readFiles( final TaskContext context ) | |||||
| throws TaskException | |||||
| private String[] toArray( final ArrayList list, final TaskContext context ) | |||||
| { | { | ||||
| if( m_includesFileList.size() > 0 ) | |||||
| if( list.size() == 0 ) | |||||
| { | { | ||||
| Iterator e = m_includesFileList.iterator(); | |||||
| while( e.hasNext() ) | |||||
| { | |||||
| Pattern ne = (Pattern)e.next(); | |||||
| String fileName = ne.evaluateName( (TaskContext)null ); | |||||
| if( fileName != null ) | |||||
| { | |||||
| File inclFile = resolveFile( fileName ); | |||||
| if( !inclFile.exists() ) | |||||
| { | |||||
| throw new TaskException( "Includesfile " | |||||
| + inclFile.getAbsolutePath() | |||||
| + " not found." ); | |||||
| } | |||||
| readPatterns( inclFile, m_includeList, null ); | |||||
| } | |||||
| } | |||||
| m_includesFileList.clear(); | |||||
| return null; | |||||
| } | } | ||||
| if( m_excludesFileList.size() > 0 ) | |||||
| final ArrayList names = new ArrayList(); | |||||
| final Iterator e = list.iterator(); | |||||
| while( e.hasNext() ) | |||||
| { | { | ||||
| Iterator e = m_excludesFileList.iterator(); | |||||
| while( e.hasNext() ) | |||||
| final Pattern pattern = (Pattern)e.next(); | |||||
| final String result = pattern.evaluateName( context ); | |||||
| if( null != result && result.length() > 0 ) | |||||
| { | { | ||||
| Pattern ne = (Pattern)e.next(); | |||||
| String fileName = ne.evaluateName( null ); | |||||
| if( fileName != null ) | |||||
| { | |||||
| File exclFile = resolveFile( fileName ); | |||||
| if( !exclFile.exists() ) | |||||
| { | |||||
| throw new TaskException( "Excludesfile " | |||||
| + exclFile.getAbsolutePath() | |||||
| + " not found." ); | |||||
| } | |||||
| readPatterns( exclFile, m_excludeList, null ); | |||||
| } | |||||
| names.add( result ); | |||||
| } | } | ||||
| m_excludesFileList.clear(); | |||||
| } | } | ||||
| } | |||||
| /** | |||||
| * Reads path matching patterns from a file and adds them to the includes or | |||||
| * excludes list (as appropriate). | |||||
| * | |||||
| * @param patternfile Description of Parameter | |||||
| * @param patternlist Description of Parameter | |||||
| * @param p Description of Parameter | |||||
| * @exception TaskException Description of Exception | |||||
| */ | |||||
| private void readPatterns( File patternfile, ArrayList patternlist, Project p ) | |||||
| throws TaskException | |||||
| { | |||||
| BufferedReader patternReader = null; | |||||
| try | |||||
| { | |||||
| // Get a FileReader | |||||
| patternReader = | |||||
| new BufferedReader( new FileReader( patternfile ) ); | |||||
| // Create one Pattern in the appropriate pattern list for each | |||||
| // line in the file. | |||||
| String line = patternReader.readLine(); | |||||
| while( line != null ) | |||||
| { | |||||
| if( line.length() > 0 ) | |||||
| { | |||||
| line = p.replaceProperties( line ); | |||||
| addPatternToList( patternlist ).setName( line ); | |||||
| } | |||||
| line = patternReader.readLine(); | |||||
| } | |||||
| } | |||||
| catch( IOException ioe ) | |||||
| { | |||||
| String msg = "An error occured while reading from pattern file: " | |||||
| + patternfile; | |||||
| throw new TaskException( msg, ioe ); | |||||
| } | |||||
| finally | |||||
| { | |||||
| if( null != patternReader ) | |||||
| { | |||||
| try | |||||
| { | |||||
| patternReader.close(); | |||||
| } | |||||
| catch( IOException ioe ) | |||||
| { | |||||
| //Ignore exception | |||||
| } | |||||
| } | |||||
| } | |||||
| return (String[])names.toArray( new String[ names.size() ] ); | |||||
| } | } | ||||
| } | } | ||||