git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270858 13f79535-47bb-0310-9956-ffa450edef68master
@@ -5,14 +5,13 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.types; | |||||
package org.apache.myrmidon.framework; | |||||
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; | |||||
/** | /** | ||||
* Named collection of include/exclude tags. <p> | * Named collection of include/exclude tags. <p> |
@@ -21,7 +21,7 @@ import org.apache.avalon.excalibur.io.FileUtil; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.types.DirectoryScanner; | import org.apache.tools.ant.types.DirectoryScanner; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
import org.apache.tools.ant.types.ScannerUtil; | import org.apache.tools.ant.types.ScannerUtil; | ||||
/** | /** | ||||
@@ -13,7 +13,7 @@ import org.apache.myrmidon.framework.Pattern; | |||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
import org.apache.tools.ant.types.DirectoryScanner; | import org.apache.tools.ant.types.DirectoryScanner; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
/** | /** | ||||
* This is an abstract task that should be used by all those tasks that require | * This is an abstract task that should be used by all those tasks that require | ||||
@@ -10,7 +10,7 @@ package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.io.File; | import java.io.File; | ||||
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.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
/** | /** | ||||
* Export packages from the Visual Age for Java workspace. The packages are | * Export packages from the Visual Age for Java workspace. The packages are | ||||
@@ -16,7 +16,7 @@ import org.apache.tools.ant.taskdefs.exec.Execute; | |||||
import org.apache.tools.ant.taskdefs.exec.ExecuteOn; | import org.apache.tools.ant.taskdefs.exec.ExecuteOn; | ||||
import org.apache.tools.ant.types.Argument; | import org.apache.tools.ant.types.Argument; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
/** | /** | ||||
* Chmod equivalent for unix-like environments. | * Chmod equivalent for unix-like environments. | ||||
@@ -11,6 +11,7 @@ import java.io.File; | |||||
import java.util.ArrayList; | 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.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
/** | /** | ||||
@@ -21,7 +21,7 @@ import org.apache.avalon.excalibur.io.FileUtil; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.types.DirectoryScanner; | import org.apache.tools.ant.types.DirectoryScanner; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
import org.apache.tools.ant.types.ScannerUtil; | import org.apache.tools.ant.types.ScannerUtil; | ||||
/** | /** | ||||
@@ -13,7 +13,7 @@ import org.apache.myrmidon.framework.Pattern; | |||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
import org.apache.tools.ant.types.DirectoryScanner; | import org.apache.tools.ant.types.DirectoryScanner; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
/** | /** | ||||
* This is an abstract task that should be used by all those tasks that require | * This is an abstract task that should be used by all those tasks that require | ||||
@@ -10,7 +10,7 @@ package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.io.File; | import java.io.File; | ||||
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.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
/** | /** | ||||
* Export packages from the Visual Age for Java workspace. The packages are | * Export packages from the Visual Age for Java workspace. The packages are | ||||
@@ -16,7 +16,7 @@ import org.apache.tools.ant.taskdefs.exec.Execute; | |||||
import org.apache.tools.ant.taskdefs.exec.ExecuteOn; | import org.apache.tools.ant.taskdefs.exec.ExecuteOn; | ||||
import org.apache.tools.ant.types.Argument; | import org.apache.tools.ant.types.Argument; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.PatternSet; | |||||
import org.apache.myrmidon.framework.PatternSet; | |||||
/** | /** | ||||
* Chmod equivalent for unix-like environments. | * Chmod equivalent for unix-like environments. | ||||
@@ -11,6 +11,7 @@ import java.io.File; | |||||
import java.util.ArrayList; | 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.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
/** | /** | ||||
@@ -1,148 +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.types; | |||||
import java.util.ArrayList; | |||||
import java.util.Iterator; | |||||
import java.util.StringTokenizer; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.Pattern; | |||||
/** | |||||
* Named collection of include/exclude tags. <p> | |||||
* | |||||
* @author <a href="mailto:ajkuiper@wxs.nl">Arnout J. Kuiper</a> | |||||
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a> | |||||
* @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a> | |||||
* @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a> | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class PatternSet | |||||
{ | |||||
private ArrayList m_includeList = new ArrayList(); | |||||
private ArrayList m_excludeList = new ArrayList(); | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma or | |||||
* a space. | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes( final String excludes ) | |||||
{ | |||||
final Pattern[] patterns = parsePatterns( excludes ); | |||||
for( int i = 0; i < patterns.length; i++ ) | |||||
{ | |||||
addExclude( patterns[ i ] ); | |||||
} | |||||
} | |||||
/** | |||||
* 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 void setIncludes( final String includes ) | |||||
{ | |||||
final Pattern[] patterns = parsePatterns( includes ); | |||||
for( int i = 0; i < patterns.length; i++ ) | |||||
{ | |||||
addInclude( patterns[ i ] ); | |||||
} | |||||
} | |||||
/** | |||||
* add a name entry on the exclude list | |||||
*/ | |||||
public void addExclude( final Pattern pattern ) | |||||
{ | |||||
m_excludeList.add( pattern ); | |||||
} | |||||
/** | |||||
* add a name entry on the include list | |||||
*/ | |||||
public void addInclude( final Pattern pattern ) | |||||
{ | |||||
m_includeList.add( pattern ); | |||||
} | |||||
public String[] getExcludePatterns( final TaskContext context ) | |||||
throws TaskException | |||||
{ | |||||
return toArray( m_excludeList, context ); | |||||
} | |||||
/** | |||||
* Returns the filtered include patterns. | |||||
*/ | |||||
public String[] getIncludePatterns( final TaskContext context ) | |||||
throws TaskException | |||||
{ | |||||
return toArray( m_includeList, context ); | |||||
} | |||||
/** | |||||
* Adds the patterns of the other instance to this set. | |||||
*/ | |||||
protected void append( final PatternSet other ) | |||||
{ | |||||
m_includeList.addAll( other.m_includeList ); | |||||
m_excludeList.addAll( other.m_excludeList ); | |||||
} | |||||
public String toString() | |||||
{ | |||||
return "PatternSet [ includes: " + m_includeList + | |||||
" excludes: " + m_excludeList + " ]"; | |||||
} | |||||
private Pattern[] parsePatterns( final String patternString ) | |||||
{ | |||||
final ArrayList patterns = new ArrayList(); | |||||
if( patternString != null && patternString.length() > 0 ) | |||||
{ | |||||
StringTokenizer tok = new StringTokenizer( patternString, ", ", false ); | |||||
while( tok.hasMoreTokens() ) | |||||
{ | |||||
final Pattern pattern = new Pattern( tok.nextToken() ); | |||||
patterns.add( pattern ); | |||||
} | |||||
} | |||||
return (Pattern[])patterns.toArray( new Pattern[ patterns.size() ] ); | |||||
} | |||||
/** | |||||
* Convert a vector of Pattern elements into an array of Strings. | |||||
*/ | |||||
private String[] toArray( final ArrayList list, final TaskContext context ) | |||||
{ | |||||
if( list.size() == 0 ) | |||||
{ | |||||
return null; | |||||
} | |||||
final ArrayList names = new ArrayList(); | |||||
final Iterator e = list.iterator(); | |||||
while( e.hasNext() ) | |||||
{ | |||||
final Pattern pattern = (Pattern)e.next(); | |||||
final String result = pattern.evaluateName( context ); | |||||
if( null != result && result.length() > 0 ) | |||||
{ | |||||
names.add( result ); | |||||
} | |||||
} | |||||
return (String[])names.toArray( new String[ names.size() ] ); | |||||
} | |||||
} |