git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270510 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,177 +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.Stack; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | |||||
* Base class for those classes that can appear inside the build file as stand | |||||
* alone data types. <p> | |||||
* | |||||
* This class handles the common description attribute and provides a default | |||||
* implementation for reference handling and checking for circular references | |||||
* that is appropriate for types that can not be nested inside elements of the | |||||
* same type (i.e. <patternset> but not <path>).</p> | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
*/ | |||||
public abstract class DataType | |||||
extends ProjectComponent | |||||
{ | |||||
/** | |||||
* Value to the refid attribute. | |||||
*/ | |||||
protected Reference ref; | |||||
/** | |||||
* Are we sure we don't hold circular references? <p> | |||||
* | |||||
* Subclasses are responsible for setting this value to false if we'd need | |||||
* to investigate this condition (usually because a child element has been | |||||
* added that is a subclass of DataType).</p> | |||||
*/ | |||||
protected boolean checked = true; | |||||
/** | |||||
* Set the value of the refid attribute. <p> | |||||
* | |||||
* Subclasses may need to check whether any other attributes have been set | |||||
* as well or child elements have been created and thus override this | |||||
* method. if they do the must call <code>super.setRefid</code>.</p> | |||||
* | |||||
* @param ref The new Refid value | |||||
*/ | |||||
public void setRefid( Reference ref ) | |||||
throws TaskException | |||||
{ | |||||
this.ref = ref; | |||||
checked = false; | |||||
} | |||||
/** | |||||
* Has the refid attribute of this element been set? | |||||
* | |||||
* @return The Reference value | |||||
*/ | |||||
public boolean isReference() | |||||
{ | |||||
return ref != null; | |||||
} | |||||
/** | |||||
* Performs the check for circular references and returns the referenced | |||||
* object. | |||||
* | |||||
* @param requiredClass Description of Parameter | |||||
* @param dataTypeName Description of Parameter | |||||
* @return The CheckedRef value | |||||
*/ | |||||
protected Object getCheckedRef( Class requiredClass, String dataTypeName ) | |||||
throws TaskException | |||||
{ | |||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, getProject() ); | |||||
} | |||||
Object o = ref.getReferencedObject( getProject() ); | |||||
if( !( requiredClass.isAssignableFrom( o.getClass() ) ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a " + dataTypeName; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return o; | |||||
} | |||||
} | |||||
/** | |||||
* Creates an exception that indicates the user has generated a loop of data | |||||
* types referencing each other. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
protected TaskException circularReference() | |||||
{ | |||||
return new TaskException( "This data type contains a circular reference." ); | |||||
} | |||||
/** | |||||
* Check to see whether any DataType we hold references to is included in | |||||
* the Stack (which holds all DataType instances that directly or indirectly | |||||
* reference this instance, including this instance itself). <p> | |||||
* | |||||
* If one is included, throw a TaskException created by {@link | |||||
* #circularReference circularReference}.</p> <p> | |||||
* | |||||
* This implementation is appropriate only for a DataType that cannot hold | |||||
* other DataTypes as children.</p> <p> | |||||
* | |||||
* The general contract of this method is that it shouldn't do anything if | |||||
* {@link #checked <code>checked</code>} is true and set it to true on exit. | |||||
* </p> | |||||
* | |||||
* @param stk Description of Parameter | |||||
* @param p Description of Parameter | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
protected void dieOnCircularReference( Stack stk, Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( checked || !isReference() ) | |||||
{ | |||||
return; | |||||
} | |||||
Object o = ref.getReferencedObject( p ); | |||||
if( o instanceof DataType ) | |||||
{ | |||||
if( stk.contains( o ) ) | |||||
{ | |||||
throw circularReference(); | |||||
} | |||||
else | |||||
{ | |||||
stk.push( o ); | |||||
( (DataType)o ).dieOnCircularReference( stk, p ); | |||||
stk.pop(); | |||||
} | |||||
} | |||||
checked = true; | |||||
} | |||||
/** | |||||
* Creates an exception that indicates that this XML element must not have | |||||
* child elements if the refid attribute is set. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
protected TaskException noChildrenAllowed() | |||||
{ | |||||
return new TaskException( "You must not specify nested elements when using refid" ); | |||||
} | |||||
/** | |||||
* Creates an exception that indicates that refid has to be the only | |||||
* attribute if it is set. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
protected TaskException tooManyAttributes() | |||||
{ | |||||
return new TaskException( "You must not specify more than one attribute" + | |||||
" when using refid" ); | |||||
} | |||||
} |
@@ -9,10 +9,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.Stack; | |||||
import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* FileList represents an explicitly named list of files. FileLists are useful | * FileList represents an explicitly named list of files. FileLists are useful | ||||
@@ -23,135 +22,54 @@ import org.apache.tools.ant.Project; | |||||
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class FileList extends DataType | |||||
public class FileList | |||||
extends ProjectComponent | |||||
{ | { | ||||
private ArrayList filenames = new ArrayList(); | |||||
private File dir; | |||||
private final ArrayList m_filenames = new ArrayList(); | |||||
private File m_dir; | |||||
public FileList() | public FileList() | ||||
{ | { | ||||
super(); | |||||
} | |||||
protected FileList( FileList filelist ) | |||||
{ | |||||
this.dir = filelist.dir; | |||||
this.filenames = filelist.filenames; | |||||
} | } | ||||
public void setDir( File dir ) | public void setDir( File dir ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.dir = dir; | |||||
m_dir = dir; | |||||
} | } | ||||
public void setFiles( String filenames ) | public void setFiles( String filenames ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( filenames != null && filenames.length() > 0 ) | if( filenames != null && filenames.length() > 0 ) | ||||
{ | { | ||||
StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false ); | StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false ); | ||||
while( tok.hasMoreTokens() ) | while( tok.hasMoreTokens() ) | ||||
{ | { | ||||
this.filenames.add( tok.nextToken() ); | |||||
m_filenames.add( tok.nextToken() ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Makes this instance in effect a reference to another FileList instance. | |||||
* <p> | |||||
* | |||||
* You must not set another attribute or nest elements inside this element | |||||
* if you make it a reference.</p> | |||||
* | |||||
* @param r The new Refid value | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
public void setRefid( Reference r ) | |||||
throws TaskException | |||||
{ | |||||
if( ( dir != null ) || ( filenames.size() != 0 ) ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
super.setRefid( r ); | |||||
} | |||||
public File getDir( Project p ) | |||||
throws TaskException | |||||
public File getDir() | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef( p ).getDir( p ); | |||||
} | |||||
return dir; | |||||
return m_dir; | |||||
} | } | ||||
/** | /** | ||||
* Returns the list of files represented by this FileList. | * Returns the list of files represented by this FileList. | ||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Files value | |||||
*/ | */ | ||||
public String[] getFiles( Project p ) | |||||
public String[] getFiles() | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef( p ).getFiles( p ); | |||||
} | |||||
if( dir == null ) | |||||
if( m_dir == null ) | |||||
{ | { | ||||
throw new TaskException( "No directory specified for filelist." ); | throw new TaskException( "No directory specified for filelist." ); | ||||
} | } | ||||
if( filenames.size() == 0 ) | |||||
if( m_filenames.size() == 0 ) | |||||
{ | { | ||||
throw new TaskException( "No files specified for filelist." ); | throw new TaskException( "No files specified for filelist." ); | ||||
} | } | ||||
final String result[] = new String[ filenames.size() ]; | |||||
return (String[])filenames.toArray( result ); | |||||
return (String[])m_filenames.toArray( new String[ m_filenames.size() ] ); | |||||
} | } | ||||
/** | |||||
* Performs the check for circular references and returns the referenced | |||||
* FileList. | |||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Ref value | |||||
*/ | |||||
protected FileList getRef( Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, p ); | |||||
} | |||||
Object o = ref.getReferencedObject( p ); | |||||
if( !( o instanceof FileList ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a filelist"; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return (FileList)o; | |||||
} | |||||
} | |||||
}//-- FileList.java | |||||
} |
@@ -12,6 +12,7 @@ import java.util.ArrayList; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.FileScanner; | import org.apache.tools.ant.FileScanner; | ||||
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 | ||||
@@ -26,7 +27,7 @@ import org.apache.tools.ant.FileScanner; | |||||
* @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 DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
private PatternSet m_defaultPatterns = new PatternSet(); | private PatternSet m_defaultPatterns = new PatternSet(); | ||||
@@ -0,0 +1,78 @@ | |||||
/* | |||||
* 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; | |||||
/** | |||||
* Individual filter component of filterset | |||||
* | |||||
* @author Michael McCallum | |||||
* @created 14 March 2001 | |||||
*/ | |||||
public class Filter | |||||
{ | |||||
/** | |||||
* Token which will be replaced in the filter operation | |||||
*/ | |||||
private String m_token; | |||||
/** | |||||
* The value which will replace the token in the filtering operation | |||||
*/ | |||||
private String m_value; | |||||
/** | |||||
* Constructor for the Filter object | |||||
* | |||||
* @param token The token which will be replaced when filtering | |||||
* @param value The value which will replace the token when filtering | |||||
*/ | |||||
public Filter( final String token, final String value ) | |||||
{ | |||||
m_token = token; | |||||
m_value = value; | |||||
} | |||||
/** | |||||
* No argument conmstructor | |||||
*/ | |||||
public Filter() | |||||
{ | |||||
} | |||||
/** | |||||
* Sets the Token attribute of the Filter object | |||||
*/ | |||||
public void setToken( final String token ) | |||||
{ | |||||
m_token = token; | |||||
} | |||||
/** | |||||
* Sets the Value attribute of the Filter object | |||||
*/ | |||||
public void setValue( final String value ) | |||||
{ | |||||
m_value = value; | |||||
} | |||||
/** | |||||
* Gets the Token attribute of the Filter object | |||||
*/ | |||||
public String getToken() | |||||
{ | |||||
return m_token; | |||||
} | |||||
/** | |||||
* Gets the Value attribute of the Filter object | |||||
*/ | |||||
public String getValue() | |||||
{ | |||||
return m_value; | |||||
} | |||||
} |
@@ -16,6 +16,7 @@ import java.util.Hashtable; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* A set of filters to be applied to something. A filter set may have begintoken | * A set of filters to be applied to something. A filter set may have begintoken | ||||
@@ -25,7 +26,7 @@ import org.apache.myrmidon.api.TaskException; | |||||
* @created 14 March 2001 | * @created 14 March 2001 | ||||
*/ | */ | ||||
public class FilterSet | public class FilterSet | ||||
extends DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
@@ -39,13 +40,13 @@ public class FilterSet | |||||
*/ | */ | ||||
public final static String DEFAULT_TOKEN_END = "@"; | public final static String DEFAULT_TOKEN_END = "@"; | ||||
private String startOfToken = DEFAULT_TOKEN_START; | |||||
private String endOfToken = DEFAULT_TOKEN_END; | |||||
private String m_startOfToken = DEFAULT_TOKEN_START; | |||||
private String m_endOfToken = DEFAULT_TOKEN_END; | |||||
/** | /** | ||||
* List of ordered filters and filter files. | * List of ordered filters and filter files. | ||||
*/ | */ | ||||
private ArrayList filters = new ArrayList(); | |||||
private ArrayList m_filters = new ArrayList(); | |||||
public FilterSet() | public FilterSet() | ||||
{ | { | ||||
@@ -60,7 +61,7 @@ public class FilterSet | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
super(); | super(); | ||||
this.filters = (ArrayList)filterset.getFilters().clone(); | |||||
m_filters = (ArrayList)filterset.getFilters().clone(); | |||||
} | } | ||||
/** | /** | ||||
@@ -71,15 +72,11 @@ public class FilterSet | |||||
public void setBeginToken( String startOfToken ) | public void setBeginToken( String startOfToken ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( startOfToken == null || "".equals( startOfToken ) ) | if( startOfToken == null || "".equals( startOfToken ) ) | ||||
{ | { | ||||
throw new TaskException( "beginToken must not be empty" ); | throw new TaskException( "beginToken must not be empty" ); | ||||
} | } | ||||
this.startOfToken = startOfToken; | |||||
m_startOfToken = startOfToken; | |||||
} | } | ||||
/** | /** | ||||
@@ -90,15 +87,11 @@ public class FilterSet | |||||
public void setEndToken( String endOfToken ) | public void setEndToken( String endOfToken ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( endOfToken == null || "".equals( endOfToken ) ) | if( endOfToken == null || "".equals( endOfToken ) ) | ||||
{ | { | ||||
throw new TaskException( "endToken must not be empty" ); | throw new TaskException( "endToken must not be empty" ); | ||||
} | } | ||||
this.endOfToken = endOfToken; | |||||
m_endOfToken = endOfToken; | |||||
} | } | ||||
/** | /** | ||||
@@ -111,31 +104,17 @@ public class FilterSet | |||||
public void setFiltersfile( File filtersFile ) | public void setFiltersfile( File filtersFile ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
readFiltersFromFile( filtersFile ); | readFiltersFromFile( filtersFile ); | ||||
} | } | ||||
public String getBeginToken() | public String getBeginToken() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef().getBeginToken(); | |||||
} | |||||
return startOfToken; | |||||
return m_startOfToken; | |||||
} | } | ||||
public String getEndToken() | public String getEndToken() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef().getEndToken(); | |||||
} | |||||
return endOfToken; | |||||
return m_endOfToken; | |||||
} | } | ||||
/** | /** | ||||
@@ -162,13 +141,8 @@ public class FilterSet | |||||
* @param filter The feature to be added to the Filter attribute | * @param filter The feature to be added to the Filter attribute | ||||
*/ | */ | ||||
public void addFilter( Filter filter ) | public void addFilter( Filter filter ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
filters.add( filter ); | |||||
m_filters.add( filter ); | |||||
} | } | ||||
/** | /** | ||||
@@ -178,13 +152,8 @@ public class FilterSet | |||||
* @param value The value for the new filter. | * @param value The value for the new filter. | ||||
*/ | */ | ||||
public void addFilter( String token, String value ) | public void addFilter( String token, String value ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
filters.add( new Filter( token, value ) ); | |||||
m_filters.add( new Filter( token, value ) ); | |||||
} | } | ||||
/** | /** | ||||
@@ -193,34 +162,10 @@ public class FilterSet | |||||
* @param filterSet the filterset to be added to this filterset | * @param filterSet the filterset to be added to this filterset | ||||
*/ | */ | ||||
public void addFilterSet( FilterSet filterSet ) | public void addFilterSet( FilterSet filterSet ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
for( Iterator e = filterSet.getFilters().iterator(); e.hasNext(); ) | for( Iterator e = filterSet.getFilters().iterator(); e.hasNext(); ) | ||||
{ | { | ||||
filters.add( (Filter)e.next() ); | |||||
} | |||||
} | |||||
public Object clone() | |||||
{ | |||||
try | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
return new FilterSet( getRef() ); | |||||
} | |||||
else | |||||
{ | |||||
return new FilterSet( this ); | |||||
} | |||||
} | |||||
catch( final TaskException te ) | |||||
{ | |||||
throw new RuntimeException( te.toString() ); | |||||
m_filters.add( (Filter)e.next() ); | |||||
} | } | ||||
} | } | ||||
@@ -230,12 +175,7 @@ public class FilterSet | |||||
* @return The filter that was created. | * @return The filter that was created. | ||||
*/ | */ | ||||
public FiltersFile createFiltersfile() | public FiltersFile createFiltersfile() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
return new FiltersFile(); | return new FiltersFile(); | ||||
} | } | ||||
@@ -260,11 +200,6 @@ public class FilterSet | |||||
public void readFiltersFromFile( File filtersFile ) | public void readFiltersFromFile( File filtersFile ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( filtersFile.isFile() ) | if( filtersFile.isFile() ) | ||||
{ | { | ||||
getLogger().debug( "Reading filters from " + filtersFile ); | getLogger().debug( "Reading filters from " + filtersFile ); | ||||
@@ -371,97 +306,8 @@ public class FilterSet | |||||
} | } | ||||
protected ArrayList getFilters() | protected ArrayList getFilters() | ||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
return getRef().getFilters(); | |||||
} | |||||
return filters; | |||||
} | |||||
protected FilterSet getRef() | |||||
throws TaskException | |||||
{ | |||||
return (FilterSet)getCheckedRef( FilterSet.class, "filterset" ); | |||||
} | |||||
/** | |||||
* Individual filter component of filterset | |||||
* | |||||
* @author Michael McCallum | |||||
* @created 14 March 2001 | |||||
*/ | |||||
public static class Filter | |||||
{ | { | ||||
/** | |||||
* Token which will be replaced in the filter operation | |||||
*/ | |||||
String token; | |||||
/** | |||||
* The value which will replace the token in the filtering operation | |||||
*/ | |||||
String value; | |||||
/** | |||||
* Constructor for the Filter object | |||||
* | |||||
* @param token The token which will be replaced when filtering | |||||
* @param value The value which will replace the token when filtering | |||||
*/ | |||||
public Filter( String token, String value ) | |||||
{ | |||||
this.token = token; | |||||
this.value = value; | |||||
} | |||||
/** | |||||
* No argument conmstructor | |||||
*/ | |||||
public Filter() | |||||
{ | |||||
} | |||||
/** | |||||
* Sets the Token attribute of the Filter object | |||||
* | |||||
* @param token The new Token value | |||||
*/ | |||||
public void setToken( String token ) | |||||
{ | |||||
this.token = token; | |||||
} | |||||
/** | |||||
* Sets the Value attribute of the Filter object | |||||
* | |||||
* @param value The new Value value | |||||
*/ | |||||
public void setValue( String value ) | |||||
{ | |||||
this.value = value; | |||||
} | |||||
/** | |||||
* Gets the Token attribute of the Filter object | |||||
* | |||||
* @return The Token value | |||||
*/ | |||||
public String getToken() | |||||
{ | |||||
return token; | |||||
} | |||||
/** | |||||
* Gets the Value attribute of the Filter object | |||||
* | |||||
* @return The Value value | |||||
*/ | |||||
public String getValue() | |||||
{ | |||||
return value; | |||||
} | |||||
return m_filters; | |||||
} | } | ||||
/** | /** | ||||
@@ -472,7 +318,6 @@ public class FilterSet | |||||
*/ | */ | ||||
public class FiltersFile | public class FiltersFile | ||||
{ | { | ||||
/** | /** | ||||
* Constructor for the Filter object | * Constructor for the Filter object | ||||
*/ | */ | ||||
@@ -9,8 +9,8 @@ package org.apache.tools.ant.types; | |||||
import java.net.URL; | import java.net.URL; | ||||
import java.net.URLClassLoader; | import java.net.URLClassLoader; | ||||
import java.util.Stack; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.ProjectComponent; | |||||
import org.apache.tools.ant.util.FileNameMapper; | import org.apache.tools.ant.util.FileNameMapper; | ||||
/** | /** | ||||
@@ -19,7 +19,7 @@ import org.apache.tools.ant.util.FileNameMapper; | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
*/ | */ | ||||
public class Mapper | public class Mapper | ||||
extends DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
private MapperType m_type; | private MapperType m_type; | ||||
@@ -33,14 +33,9 @@ public class Mapper | |||||
* | * | ||||
* @param classname The new Classname value | * @param classname The new Classname value | ||||
*/ | */ | ||||
public void setClassname( String classname ) | |||||
throws TaskException | |||||
public void setClassname( final String classname ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_classname = classname; | |||||
m_classname = classname; | |||||
} | } | ||||
/** | /** | ||||
@@ -51,97 +46,38 @@ public class Mapper | |||||
public void setClasspath( Path classpath ) | public void setClasspath( Path classpath ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( this.m_classpath == null ) | |||||
if( m_classpath == null ) | |||||
{ | { | ||||
this.m_classpath = classpath; | |||||
m_classpath = classpath; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.m_classpath.append( classpath ); | |||||
m_classpath.append( classpath ); | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Set the classpath to load the FileNameMapper through via reference | |||||
* (attribute). | |||||
* | |||||
* @param r The new ClasspathRef value | |||||
*/ | |||||
public void setClasspathRef( Reference r ) | |||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
createClasspath().setRefid( r ); | |||||
} | |||||
/** | /** | ||||
* Set the argument to FileNameMapper.setFrom | * Set the argument to FileNameMapper.setFrom | ||||
* | |||||
* @param from The new From value | |||||
*/ | */ | ||||
public void setFrom( String from ) | |||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_from = from; | |||||
} | |||||
/** | |||||
* Make this Mapper instance a reference to another Mapper. <p> | |||||
* | |||||
* You must not set any other attribute if you make it a reference.</p> | |||||
* | |||||
* @param r The new Refid value | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
public void setRefid( Reference r ) | |||||
throws TaskException | |||||
public void setFrom( final String from ) | |||||
{ | { | ||||
if( m_type != null || m_from != null || m_to != null ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
super.setRefid( r ); | |||||
m_from = from; | |||||
} | } | ||||
/** | /** | ||||
* Set the argument to FileNameMapper.setTo | * Set the argument to FileNameMapper.setTo | ||||
* | |||||
* @param to The new To value | |||||
*/ | */ | ||||
public void setTo( String to ) | |||||
throws TaskException | |||||
public void setTo( final String to ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_to = to; | |||||
m_to = to; | |||||
} | } | ||||
/** | /** | ||||
* Set the type of FileNameMapper to use. | * Set the type of FileNameMapper to use. | ||||
* | |||||
* @param type The new Type value | |||||
*/ | */ | ||||
public void setType( MapperType type ) | public void setType( MapperType type ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_type = type; | |||||
m_type = type; | |||||
} | } | ||||
/** | /** | ||||
@@ -153,11 +89,6 @@ public class Mapper | |||||
public FileNameMapper getImplementation() | public FileNameMapper getImplementation() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef().getImplementation(); | |||||
} | |||||
if( m_type == null && m_classname == null ) | if( m_type == null && m_classname == null ) | ||||
{ | { | ||||
throw new TaskException( "one of the attributes type or classname is required" ); | throw new TaskException( "one of the attributes type or classname is required" ); | ||||
@@ -217,43 +148,10 @@ public class Mapper | |||||
public Path createClasspath() | public Path createClasspath() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
if( m_classpath == null ) | |||||
{ | { | ||||
throw noChildrenAllowed(); | |||||
m_classpath = new Path(); | |||||
} | } | ||||
if( this.m_classpath == null ) | |||||
{ | |||||
this.m_classpath = new Path(); | |||||
} | |||||
return this.m_classpath.createPath(); | |||||
return m_classpath.createPath(); | |||||
} | } | ||||
/** | |||||
* Performs the check for circular references and returns the referenced | |||||
* Mapper. | |||||
* | |||||
* @return The Ref value | |||||
*/ | |||||
protected Mapper getRef() | |||||
throws TaskException | |||||
{ | |||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, getProject() ); | |||||
} | |||||
Object o = ref.getReferencedObject( getProject() ); | |||||
if( !( o instanceof Mapper ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a mapper"; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return (Mapper)o; | |||||
} | |||||
} | |||||
} | } |
@@ -11,14 +11,12 @@ import java.io.File; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | |||||
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Stack; | |||||
import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.PathTokenizer; | import org.apache.tools.ant.PathTokenizer; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* This object represents a path as used by CLASSPATH or PATH environment | * This object represents a path as used by CLASSPATH or PATH environment | ||||
@@ -51,9 +49,8 @@ import org.apache.tools.ant.Project; | |||||
* @author Thomas.Haas@softwired-inc.com | * @author Thomas.Haas@softwired-inc.com | ||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
*/ | */ | ||||
public class Path | public class Path | ||||
extends DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
public final static Path systemClasspath = createSystemClasspath(); | public final static Path systemClasspath = createSystemClasspath(); | ||||
@@ -91,11 +88,8 @@ public class Path | |||||
/** | /** | ||||
* Returns its argument with all file separator characters replaced so that | * Returns its argument with all file separator characters replaced so that | ||||
* they match the local OS conventions. | * they match the local OS conventions. | ||||
* | |||||
* @param source Description of Parameter | |||||
* @return Description of the Returned Value | |||||
*/ | */ | ||||
public static String translateFile( String source ) | |||||
private static String translateFile( final String source ) | |||||
{ | { | ||||
if( source == null ) | if( source == null ) | ||||
return ""; | return ""; | ||||
@@ -112,7 +106,7 @@ public class Path | |||||
/** | /** | ||||
* Splits a PATH (with : or ; as separators) into its parts. | * Splits a PATH (with : or ; as separators) into its parts. | ||||
*/ | */ | ||||
public String[] translatePath( Project project, String source ) | |||||
private String[] translatePath( final File baseDirectory, String source ) | |||||
{ | { | ||||
final ArrayList result = new ArrayList(); | final ArrayList result = new ArrayList(); | ||||
if( source == null ) | if( source == null ) | ||||
@@ -123,15 +117,18 @@ public class Path | |||||
while( tok.hasMoreTokens() ) | while( tok.hasMoreTokens() ) | ||||
{ | { | ||||
element.setLength( 0 ); | element.setLength( 0 ); | ||||
String pathElement = tok.nextToken(); | |||||
final String pathElement = tok.nextToken(); | |||||
try | try | ||||
{ | { | ||||
element.append( resolveFile( project, pathElement ) ); | |||||
element.append( resolveFile( baseDirectory, pathElement ) ); | |||||
} | } | ||||
catch( TaskException e ) | catch( TaskException e ) | ||||
{ | { | ||||
getLogger().debug( "Dropping path element " + pathElement + " as it is not valid relative to the project" ); | |||||
final String message = | |||||
"Dropping path element " + pathElement + " as it is not valid relative to the project"; | |||||
getLogger().debug( message ); | |||||
} | } | ||||
for( int i = 0; i < element.length(); i++ ) | for( int i = 0; i < element.length(); i++ ) | ||||
{ | { | ||||
translateFileSep( element, i ); | translateFileSep( element, i ); | ||||
@@ -139,8 +136,7 @@ public class Path | |||||
result.add( element.toString() ); | result.add( element.toString() ); | ||||
} | } | ||||
final String[] res = new String[ result.size() ]; | |||||
return (String[])result.toArray( res ); | |||||
return (String[])result.toArray( new String[ result.size() ] ); | |||||
} | } | ||||
/** | /** | ||||
@@ -151,7 +147,7 @@ public class Path | |||||
* @param pos Description of Parameter | * @param pos Description of Parameter | ||||
* @return Description of the Returned Value | * @return Description of the Returned Value | ||||
*/ | */ | ||||
protected static boolean translateFileSep( StringBuffer buffer, int pos ) | |||||
private static boolean translateFileSep( StringBuffer buffer, int pos ) | |||||
{ | { | ||||
if( buffer.charAt( pos ) == '/' || buffer.charAt( pos ) == '\\' ) | if( buffer.charAt( pos ) == '/' || buffer.charAt( pos ) == '\\' ) | ||||
{ | { | ||||
@@ -163,15 +159,12 @@ public class Path | |||||
/** | /** | ||||
* Adds a String to the ArrayList if it isn't already included. | * Adds a String to the ArrayList if it isn't already included. | ||||
* | |||||
* @param v The feature to be added to the UnlessPresent attribute | |||||
* @param s The feature to be added to the UnlessPresent attribute | |||||
*/ | */ | ||||
private static void addUnlessPresent( ArrayList v, String s ) | |||||
private static void addUnlessPresent( final ArrayList list, final String entry ) | |||||
{ | { | ||||
if( v.indexOf( s ) == -1 ) | |||||
if( !list.contains( entry ) ) | |||||
{ | { | ||||
v.add( s ); | |||||
list.add( entry ); | |||||
} | } | ||||
} | } | ||||
@@ -179,18 +172,14 @@ public class Path | |||||
* Resolve a filename with Project's help - if we know one that is. <p> | * Resolve a filename with Project's help - if we know one that is. <p> | ||||
* | * | ||||
* Assume the filename is absolute if project is null.</p> | * Assume the filename is absolute if project is null.</p> | ||||
* | |||||
* @param project Description of Parameter | |||||
* @param relativeName Description of Parameter | |||||
* @return Description of the Returned Value | |||||
*/ | */ | ||||
private static String resolveFile( Project project, String relativeName ) | |||||
private static String resolveFile( final File baseDirectory, final String relativeName ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( project != null ) | |||||
if( null != baseDirectory ) | |||||
{ | { | ||||
File f = FileUtil.resolveFile( project.getBaseDir(), relativeName ); | |||||
return f.getAbsolutePath(); | |||||
final File file = FileUtil.resolveFile( baseDirectory, relativeName ); | |||||
return file.getAbsolutePath(); | |||||
} | } | ||||
return relativeName; | return relativeName; | ||||
} | } | ||||
@@ -200,15 +189,9 @@ public class Path | |||||
* | * | ||||
* @param location the location of the element to add (must not be <code>null</code> | * @param location the location of the element to add (must not be <code>null</code> | ||||
* nor empty. | * nor empty. | ||||
* @exception TaskException Description of Exception | |||||
*/ | */ | ||||
public void setLocation( File location ) | |||||
throws TaskException | |||||
public void setLocation( final File location ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
createPathElement().setLocation( location ); | createPathElement().setLocation( location ); | ||||
} | } | ||||
@@ -216,63 +199,28 @@ public class Path | |||||
* Parses a path definition and creates single PathElements. | * Parses a path definition and creates single PathElements. | ||||
* | * | ||||
* @param path the path definition. | * @param path the path definition. | ||||
* @exception TaskException Description of Exception | |||||
*/ | */ | ||||
public void setPath( String path ) | public void setPath( String path ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
createPathElement().setPath( path ); | createPathElement().setPath( path ); | ||||
} | } | ||||
/** | |||||
* Makes this instance in effect a reference to another Path instance. <p> | |||||
* | |||||
* You must not set another attribute or nest elements inside this element | |||||
* if you make it a reference.</p> | |||||
* | |||||
* @param r The new Refid value | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
public void setRefid( Reference r ) | |||||
throws TaskException | |||||
{ | |||||
if( !elements.isEmpty() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
elements.add( r ); | |||||
super.setRefid( r ); | |||||
} | |||||
/** | /** | ||||
* Adds the components on the given path which exist to this Path. | * Adds the components on the given path which exist to this Path. | ||||
* Components that don't exist, aren't added. | * Components that don't exist, aren't added. | ||||
* | * | ||||
* @param source - source path whose components are examined for existence | * @param source - source path whose components are examined for existence | ||||
*/ | */ | ||||
public void addExisting( Path source ) | |||||
public void addExisting( final Path source ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
String[] list = source.list(); | |||||
final String[] list = source.list(); | |||||
for( int i = 0; i < list.length; i++ ) | for( int i = 0; i < list.length; i++ ) | ||||
{ | { | ||||
File f = null; | |||||
if( getProject() != null ) | |||||
{ | |||||
f = resolveFile( list[ i ] ); | |||||
} | |||||
else | |||||
{ | |||||
f = new File( list[ i ] ); | |||||
} | |||||
if( f.exists() ) | |||||
final File file = new File( list[ i ] ); | |||||
if( file.exists() ) | |||||
{ | { | ||||
setLocation( f ); | |||||
setLocation( file ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -281,8 +229,6 @@ public class Path | |||||
* Emulation of extdirs feature in java >= 1.2. This method adds all files | * Emulation of extdirs feature in java >= 1.2. This method adds all files | ||||
* in the given directories (but not in sub-directories!) to the classpath, | * in the given directories (but not in sub-directories!) to the classpath, | ||||
* so that you don't have to specify them all one by one. | * so that you don't have to specify them all one by one. | ||||
* | |||||
* @param extdirs The feature to be added to the Extdirs attribute | |||||
*/ | */ | ||||
public void addExtdirs( Path extdirs ) | public void addExtdirs( Path extdirs ) | ||||
throws TaskException | throws TaskException | ||||
@@ -300,16 +246,16 @@ public class Path | |||||
} | } | ||||
} | } | ||||
String[] dirs = extdirs.list(); | |||||
final String[] dirs = extdirs.list(); | |||||
for( int i = 0; i < dirs.length; i++ ) | for( int i = 0; i < dirs.length; i++ ) | ||||
{ | { | ||||
File dir = resolveFile( dirs[ i ] ); | |||||
final File dir = resolveFile( dirs[ i ] ); | |||||
if( dir.exists() && dir.isDirectory() ) | if( dir.exists() && dir.isDirectory() ) | ||||
{ | { | ||||
FileSet fs = new FileSet(); | |||||
fs.setDir( dir ); | |||||
fs.setIncludes( "*" ); | |||||
addFileset( fs ); | |||||
final FileSet fileSet = new FileSet(); | |||||
fileSet.setDir( dir ); | |||||
fileSet.setIncludes( "*" ); | |||||
addFileset( fileSet ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -320,15 +266,9 @@ public class Path | |||||
* @param fs The feature to be added to the Fileset attribute | * @param fs The feature to be added to the Fileset attribute | ||||
* @exception TaskException Description of Exception | * @exception TaskException Description of Exception | ||||
*/ | */ | ||||
public void addFileset( FileSet fs ) | |||||
throws TaskException | |||||
public void addFileset( final FileSet fileSet ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
elements.add( fs ); | |||||
checked = false; | |||||
elements.add( fileSet ); | |||||
} | } | ||||
/** | /** | ||||
@@ -382,42 +322,24 @@ public class Path | |||||
/** | /** | ||||
* Append the contents of the other Path instance to this. | * Append the contents of the other Path instance to this. | ||||
* | |||||
* @param other Description of Parameter | |||||
*/ | */ | ||||
public void append( Path other ) | |||||
public void append( final Path other ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( other == null ) | |||||
return; | |||||
String[] l = other.list(); | |||||
for( int i = 0; i < l.length; i++ ) | |||||
if( null == other ) | |||||
{ | { | ||||
if( elements.indexOf( l[ i ] ) == -1 ) | |||||
{ | |||||
elements.add( l[ i ] ); | |||||
} | |||||
throw new NullPointerException( "other" ); | |||||
} | } | ||||
} | |||||
/** | |||||
* Return a Path that holds the same elements as this instance. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
public Object clone() | |||||
{ | |||||
try | |||||
{ | |||||
Path p = new Path(); | |||||
p.append( this ); | |||||
return p; | |||||
} | |||||
catch( TaskException e ) | |||||
final String[] list = other.list(); | |||||
for( int i = 0; i < list.length; i++ ) | |||||
{ | { | ||||
throw new IllegalStateException( e.getMessage() ); | |||||
final String file = list[ i ]; | |||||
if( elements.contains( file ) ) | |||||
{ | |||||
elements.add( file ); | |||||
} | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
@@ -459,20 +381,17 @@ public class Path | |||||
{ | { | ||||
// only: the developer knows what (s)he is doing | // only: the developer knows what (s)he is doing | ||||
result.addExisting( Path.systemClasspath ); | result.addExisting( Path.systemClasspath ); | ||||
} | } | ||||
else if( order.equals( "first" ) ) | else if( order.equals( "first" ) ) | ||||
{ | { | ||||
// first: developer could use a little help | // first: developer could use a little help | ||||
result.addExisting( Path.systemClasspath ); | result.addExisting( Path.systemClasspath ); | ||||
result.addExisting( this ); | result.addExisting( this ); | ||||
} | } | ||||
else if( order.equals( "ignore" ) ) | else if( order.equals( "ignore" ) ) | ||||
{ | { | ||||
// ignore: don't trust anyone | // ignore: don't trust anyone | ||||
result.addExisting( this ); | result.addExisting( this ); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -499,50 +418,27 @@ public class Path | |||||
public Path createPath() | public Path createPath() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
Path p = new Path(); | |||||
elements.add( p ); | |||||
checked = false; | |||||
return p; | |||||
final Path other = new Path(); | |||||
elements.add( other ); | |||||
return other; | |||||
} | } | ||||
/** | /** | ||||
* Creates the nested <code><pathelement></code> element. | * Creates the nested <code><pathelement></code> element. | ||||
* | |||||
* @return Description of the Returned Value | |||||
* @exception TaskException Description of Exception | |||||
*/ | */ | ||||
public PathElement createPathElement() | public PathElement createPathElement() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
PathElement pe = new PathElement(); | |||||
elements.add( pe ); | |||||
return pe; | |||||
final PathElement pathElement = new PathElement(); | |||||
elements.add( pathElement ); | |||||
return pathElement; | |||||
} | } | ||||
/** | /** | ||||
* Returns all path elements defined by this and nested path objects. | * Returns all path elements defined by this and nested path objects. | ||||
* | |||||
* @return list of path elements. | |||||
*/ | */ | ||||
public String[] list() | public String[] list() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( !checked ) | |||||
{ | |||||
// make sure we don't have a circular reference here | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, getProject() ); | |||||
} | |||||
ArrayList result = new ArrayList( 2 * elements.size() ); | ArrayList result = new ArrayList( 2 * elements.size() ); | ||||
for( int i = 0; i < elements.size(); i++ ) | for( int i = 0; i < elements.size(); i++ ) | ||||
{ | { | ||||
@@ -599,14 +495,11 @@ public class Path | |||||
} | } | ||||
} | } | ||||
} | } | ||||
String[] res = new String[ result.size() ]; | |||||
return (String[])result.toArray( res ); | |||||
return (String[])result.toArray( new String[ result.size() ] ); | |||||
} | } | ||||
/** | /** | ||||
* How many parts does this Path instance consist of. | * How many parts does this Path instance consist of. | ||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | */ | ||||
public int size() | public int size() | ||||
throws TaskException | throws TaskException | ||||
@@ -673,52 +566,8 @@ public class Path | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Overrides the version of DataType to recurse on all DataType child | |||||
* elements that may have been added. | |||||
* | |||||
* @param stk Description of Parameter | |||||
* @param p Description of Parameter | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
protected void dieOnCircularReference( Stack stk, Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( checked ) | |||||
{ | |||||
return; | |||||
} | |||||
Iterator enum = elements.iterator(); | |||||
while( enum.hasNext() ) | |||||
{ | |||||
Object o = enum.next(); | |||||
if( o instanceof Reference ) | |||||
{ | |||||
o = ( (Reference)o ).getReferencedObject( p ); | |||||
} | |||||
if( o instanceof DataType ) | |||||
{ | |||||
if( stk.contains( o ) ) | |||||
{ | |||||
throw circularReference(); | |||||
} | |||||
else | |||||
{ | |||||
stk.push( o ); | |||||
( (DataType)o ).dieOnCircularReference( stk, p ); | |||||
stk.pop(); | |||||
} | |||||
} | |||||
} | |||||
checked = true; | |||||
} | |||||
/** | /** | ||||
* Helper class, holds the nested <code><pathelement></code> values. | * Helper class, holds the nested <code><pathelement></code> values. | ||||
* | |||||
* @author RT | |||||
*/ | */ | ||||
public class PathElement | public class PathElement | ||||
{ | { | ||||
@@ -731,7 +580,7 @@ public class Path | |||||
public void setPath( String path ) | public void setPath( String path ) | ||||
{ | { | ||||
parts = translatePath( getProject(), path ); | |||||
parts = translatePath( getProject().getBaseDir(), path ); | |||||
} | } | ||||
public String[] getParts() | public String[] getParts() | ||||
@@ -16,6 +16,7 @@ import java.util.Iterator; | |||||
import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* Named collection of include/exclude tags. <p> | * Named collection of include/exclude tags. <p> | ||||
@@ -31,7 +32,7 @@ import org.apache.tools.ant.Project; | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
*/ | */ | ||||
public class PatternSet | public class PatternSet | ||||
extends DataType | |||||
extends ProjectComponent | |||||
{ | { | ||||
private ArrayList m_includeList = new ArrayList(); | private ArrayList m_includeList = new ArrayList(); | ||||
private ArrayList m_excludeList = new ArrayList(); | private ArrayList m_excludeList = new ArrayList(); | ||||
@@ -7,9 +7,8 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
import java.util.Stack; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
import org.apache.tools.ant.util.regexp.Regexp; | import org.apache.tools.ant.util.regexp.Regexp; | ||||
import org.apache.tools.ant.util.regexp.RegexpFactory; | import org.apache.tools.ant.util.regexp.RegexpFactory; | ||||
@@ -42,79 +41,37 @@ import org.apache.tools.ant.util.regexp.RegexpFactory; | |||||
* @see java.util.regex.Pattern | * @see java.util.regex.Pattern | ||||
* @see org.apache.tools.ant.util.regexp.Regexp | * @see org.apache.tools.ant.util.regexp.Regexp | ||||
*/ | */ | ||||
public class RegularExpression extends DataType | |||||
public class RegularExpression | |||||
extends ProjectComponent | |||||
{ | { | ||||
public final static String DATA_TYPE_NAME = "regularexpression"; | |||||
// The regular expression factory | // The regular expression factory | ||||
private final static RegexpFactory factory = new RegexpFactory(); | private final static RegexpFactory factory = new RegexpFactory(); | ||||
private Regexp regexp; | |||||
private Regexp m_regexp; | |||||
public RegularExpression() | public RegularExpression() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
this.regexp = factory.newRegexp(); | |||||
m_regexp = factory.newRegexp(); | |||||
} | } | ||||
public void setPattern( String pattern ) | |||||
public void setPattern( final String pattern ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
this.regexp.setPattern( pattern ); | |||||
m_regexp.setPattern( pattern ); | |||||
} | } | ||||
/** | /** | ||||
* Gets the pattern string for this RegularExpression in the given project. | * Gets the pattern string for this RegularExpression in the given project. | ||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Pattern value | |||||
*/ | */ | ||||
public String getPattern( Project p ) | |||||
public String getPattern() | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
return getRef( p ).getPattern( p ); | |||||
return regexp.getPattern(); | |||||
return m_regexp.getPattern(); | |||||
} | } | ||||
/** | |||||
* Get the RegularExpression this reference refers to in the given project. | |||||
* Check for circular references too | |||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Ref value | |||||
*/ | |||||
public RegularExpression getRef( Project p ) | |||||
throws TaskException | |||||
public Regexp getRegexp() | |||||
{ | { | ||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, p ); | |||||
} | |||||
Object o = ref.getReferencedObject( p ); | |||||
if( !( o instanceof RegularExpression ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a regularexpression"; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return (RegularExpression)o; | |||||
} | |||||
return m_regexp; | |||||
} | } | ||||
public Regexp getRegexp( Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
return getRef( p ).getRegexp( p ); | |||||
} | |||||
return this.regexp; | |||||
} | |||||
} | } |
@@ -1,177 +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.Stack; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | |||||
* Base class for those classes that can appear inside the build file as stand | |||||
* alone data types. <p> | |||||
* | |||||
* This class handles the common description attribute and provides a default | |||||
* implementation for reference handling and checking for circular references | |||||
* that is appropriate for types that can not be nested inside elements of the | |||||
* same type (i.e. <patternset> but not <path>).</p> | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
*/ | |||||
public abstract class DataType | |||||
extends ProjectComponent | |||||
{ | |||||
/** | |||||
* Value to the refid attribute. | |||||
*/ | |||||
protected Reference ref; | |||||
/** | |||||
* Are we sure we don't hold circular references? <p> | |||||
* | |||||
* Subclasses are responsible for setting this value to false if we'd need | |||||
* to investigate this condition (usually because a child element has been | |||||
* added that is a subclass of DataType).</p> | |||||
*/ | |||||
protected boolean checked = true; | |||||
/** | |||||
* Set the value of the refid attribute. <p> | |||||
* | |||||
* Subclasses may need to check whether any other attributes have been set | |||||
* as well or child elements have been created and thus override this | |||||
* method. if they do the must call <code>super.setRefid</code>.</p> | |||||
* | |||||
* @param ref The new Refid value | |||||
*/ | |||||
public void setRefid( Reference ref ) | |||||
throws TaskException | |||||
{ | |||||
this.ref = ref; | |||||
checked = false; | |||||
} | |||||
/** | |||||
* Has the refid attribute of this element been set? | |||||
* | |||||
* @return The Reference value | |||||
*/ | |||||
public boolean isReference() | |||||
{ | |||||
return ref != null; | |||||
} | |||||
/** | |||||
* Performs the check for circular references and returns the referenced | |||||
* object. | |||||
* | |||||
* @param requiredClass Description of Parameter | |||||
* @param dataTypeName Description of Parameter | |||||
* @return The CheckedRef value | |||||
*/ | |||||
protected Object getCheckedRef( Class requiredClass, String dataTypeName ) | |||||
throws TaskException | |||||
{ | |||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, getProject() ); | |||||
} | |||||
Object o = ref.getReferencedObject( getProject() ); | |||||
if( !( requiredClass.isAssignableFrom( o.getClass() ) ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a " + dataTypeName; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return o; | |||||
} | |||||
} | |||||
/** | |||||
* Creates an exception that indicates the user has generated a loop of data | |||||
* types referencing each other. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
protected TaskException circularReference() | |||||
{ | |||||
return new TaskException( "This data type contains a circular reference." ); | |||||
} | |||||
/** | |||||
* Check to see whether any DataType we hold references to is included in | |||||
* the Stack (which holds all DataType instances that directly or indirectly | |||||
* reference this instance, including this instance itself). <p> | |||||
* | |||||
* If one is included, throw a TaskException created by {@link | |||||
* #circularReference circularReference}.</p> <p> | |||||
* | |||||
* This implementation is appropriate only for a DataType that cannot hold | |||||
* other DataTypes as children.</p> <p> | |||||
* | |||||
* The general contract of this method is that it shouldn't do anything if | |||||
* {@link #checked <code>checked</code>} is true and set it to true on exit. | |||||
* </p> | |||||
* | |||||
* @param stk Description of Parameter | |||||
* @param p Description of Parameter | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
protected void dieOnCircularReference( Stack stk, Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( checked || !isReference() ) | |||||
{ | |||||
return; | |||||
} | |||||
Object o = ref.getReferencedObject( p ); | |||||
if( o instanceof DataType ) | |||||
{ | |||||
if( stk.contains( o ) ) | |||||
{ | |||||
throw circularReference(); | |||||
} | |||||
else | |||||
{ | |||||
stk.push( o ); | |||||
( (DataType)o ).dieOnCircularReference( stk, p ); | |||||
stk.pop(); | |||||
} | |||||
} | |||||
checked = true; | |||||
} | |||||
/** | |||||
* Creates an exception that indicates that this XML element must not have | |||||
* child elements if the refid attribute is set. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
protected TaskException noChildrenAllowed() | |||||
{ | |||||
return new TaskException( "You must not specify nested elements when using refid" ); | |||||
} | |||||
/** | |||||
* Creates an exception that indicates that refid has to be the only | |||||
* attribute if it is set. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
protected TaskException tooManyAttributes() | |||||
{ | |||||
return new TaskException( "You must not specify more than one attribute" + | |||||
" when using refid" ); | |||||
} | |||||
} |
@@ -9,10 +9,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.Stack; | |||||
import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* FileList represents an explicitly named list of files. FileLists are useful | * FileList represents an explicitly named list of files. FileLists are useful | ||||
@@ -23,135 +22,54 @@ import org.apache.tools.ant.Project; | |||||
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class FileList extends DataType | |||||
public class FileList | |||||
extends ProjectComponent | |||||
{ | { | ||||
private ArrayList filenames = new ArrayList(); | |||||
private File dir; | |||||
private final ArrayList m_filenames = new ArrayList(); | |||||
private File m_dir; | |||||
public FileList() | public FileList() | ||||
{ | { | ||||
super(); | |||||
} | |||||
protected FileList( FileList filelist ) | |||||
{ | |||||
this.dir = filelist.dir; | |||||
this.filenames = filelist.filenames; | |||||
} | } | ||||
public void setDir( File dir ) | public void setDir( File dir ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.dir = dir; | |||||
m_dir = dir; | |||||
} | } | ||||
public void setFiles( String filenames ) | public void setFiles( String filenames ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( filenames != null && filenames.length() > 0 ) | if( filenames != null && filenames.length() > 0 ) | ||||
{ | { | ||||
StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false ); | StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false ); | ||||
while( tok.hasMoreTokens() ) | while( tok.hasMoreTokens() ) | ||||
{ | { | ||||
this.filenames.add( tok.nextToken() ); | |||||
m_filenames.add( tok.nextToken() ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Makes this instance in effect a reference to another FileList instance. | |||||
* <p> | |||||
* | |||||
* You must not set another attribute or nest elements inside this element | |||||
* if you make it a reference.</p> | |||||
* | |||||
* @param r The new Refid value | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
public void setRefid( Reference r ) | |||||
throws TaskException | |||||
{ | |||||
if( ( dir != null ) || ( filenames.size() != 0 ) ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
super.setRefid( r ); | |||||
} | |||||
public File getDir( Project p ) | |||||
throws TaskException | |||||
public File getDir() | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef( p ).getDir( p ); | |||||
} | |||||
return dir; | |||||
return m_dir; | |||||
} | } | ||||
/** | /** | ||||
* Returns the list of files represented by this FileList. | * Returns the list of files represented by this FileList. | ||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Files value | |||||
*/ | */ | ||||
public String[] getFiles( Project p ) | |||||
public String[] getFiles() | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef( p ).getFiles( p ); | |||||
} | |||||
if( dir == null ) | |||||
if( m_dir == null ) | |||||
{ | { | ||||
throw new TaskException( "No directory specified for filelist." ); | throw new TaskException( "No directory specified for filelist." ); | ||||
} | } | ||||
if( filenames.size() == 0 ) | |||||
if( m_filenames.size() == 0 ) | |||||
{ | { | ||||
throw new TaskException( "No files specified for filelist." ); | throw new TaskException( "No files specified for filelist." ); | ||||
} | } | ||||
final String result[] = new String[ filenames.size() ]; | |||||
return (String[])filenames.toArray( result ); | |||||
return (String[])m_filenames.toArray( new String[ m_filenames.size() ] ); | |||||
} | } | ||||
/** | |||||
* Performs the check for circular references and returns the referenced | |||||
* FileList. | |||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Ref value | |||||
*/ | |||||
protected FileList getRef( Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, p ); | |||||
} | |||||
Object o = ref.getReferencedObject( p ); | |||||
if( !( o instanceof FileList ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a filelist"; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return (FileList)o; | |||||
} | |||||
} | |||||
}//-- FileList.java | |||||
} |
@@ -12,6 +12,7 @@ import java.util.ArrayList; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.FileScanner; | import org.apache.tools.ant.FileScanner; | ||||
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 | ||||
@@ -26,7 +27,7 @@ import org.apache.tools.ant.FileScanner; | |||||
* @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 DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
private PatternSet m_defaultPatterns = new PatternSet(); | private PatternSet m_defaultPatterns = new PatternSet(); | ||||
@@ -0,0 +1,78 @@ | |||||
/* | |||||
* 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; | |||||
/** | |||||
* Individual filter component of filterset | |||||
* | |||||
* @author Michael McCallum | |||||
* @created 14 March 2001 | |||||
*/ | |||||
public class Filter | |||||
{ | |||||
/** | |||||
* Token which will be replaced in the filter operation | |||||
*/ | |||||
private String m_token; | |||||
/** | |||||
* The value which will replace the token in the filtering operation | |||||
*/ | |||||
private String m_value; | |||||
/** | |||||
* Constructor for the Filter object | |||||
* | |||||
* @param token The token which will be replaced when filtering | |||||
* @param value The value which will replace the token when filtering | |||||
*/ | |||||
public Filter( final String token, final String value ) | |||||
{ | |||||
m_token = token; | |||||
m_value = value; | |||||
} | |||||
/** | |||||
* No argument conmstructor | |||||
*/ | |||||
public Filter() | |||||
{ | |||||
} | |||||
/** | |||||
* Sets the Token attribute of the Filter object | |||||
*/ | |||||
public void setToken( final String token ) | |||||
{ | |||||
m_token = token; | |||||
} | |||||
/** | |||||
* Sets the Value attribute of the Filter object | |||||
*/ | |||||
public void setValue( final String value ) | |||||
{ | |||||
m_value = value; | |||||
} | |||||
/** | |||||
* Gets the Token attribute of the Filter object | |||||
*/ | |||||
public String getToken() | |||||
{ | |||||
return m_token; | |||||
} | |||||
/** | |||||
* Gets the Value attribute of the Filter object | |||||
*/ | |||||
public String getValue() | |||||
{ | |||||
return m_value; | |||||
} | |||||
} |
@@ -16,6 +16,7 @@ import java.util.Hashtable; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* A set of filters to be applied to something. A filter set may have begintoken | * A set of filters to be applied to something. A filter set may have begintoken | ||||
@@ -25,7 +26,7 @@ import org.apache.myrmidon.api.TaskException; | |||||
* @created 14 March 2001 | * @created 14 March 2001 | ||||
*/ | */ | ||||
public class FilterSet | public class FilterSet | ||||
extends DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
@@ -39,13 +40,13 @@ public class FilterSet | |||||
*/ | */ | ||||
public final static String DEFAULT_TOKEN_END = "@"; | public final static String DEFAULT_TOKEN_END = "@"; | ||||
private String startOfToken = DEFAULT_TOKEN_START; | |||||
private String endOfToken = DEFAULT_TOKEN_END; | |||||
private String m_startOfToken = DEFAULT_TOKEN_START; | |||||
private String m_endOfToken = DEFAULT_TOKEN_END; | |||||
/** | /** | ||||
* List of ordered filters and filter files. | * List of ordered filters and filter files. | ||||
*/ | */ | ||||
private ArrayList filters = new ArrayList(); | |||||
private ArrayList m_filters = new ArrayList(); | |||||
public FilterSet() | public FilterSet() | ||||
{ | { | ||||
@@ -60,7 +61,7 @@ public class FilterSet | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
super(); | super(); | ||||
this.filters = (ArrayList)filterset.getFilters().clone(); | |||||
m_filters = (ArrayList)filterset.getFilters().clone(); | |||||
} | } | ||||
/** | /** | ||||
@@ -71,15 +72,11 @@ public class FilterSet | |||||
public void setBeginToken( String startOfToken ) | public void setBeginToken( String startOfToken ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( startOfToken == null || "".equals( startOfToken ) ) | if( startOfToken == null || "".equals( startOfToken ) ) | ||||
{ | { | ||||
throw new TaskException( "beginToken must not be empty" ); | throw new TaskException( "beginToken must not be empty" ); | ||||
} | } | ||||
this.startOfToken = startOfToken; | |||||
m_startOfToken = startOfToken; | |||||
} | } | ||||
/** | /** | ||||
@@ -90,15 +87,11 @@ public class FilterSet | |||||
public void setEndToken( String endOfToken ) | public void setEndToken( String endOfToken ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( endOfToken == null || "".equals( endOfToken ) ) | if( endOfToken == null || "".equals( endOfToken ) ) | ||||
{ | { | ||||
throw new TaskException( "endToken must not be empty" ); | throw new TaskException( "endToken must not be empty" ); | ||||
} | } | ||||
this.endOfToken = endOfToken; | |||||
m_endOfToken = endOfToken; | |||||
} | } | ||||
/** | /** | ||||
@@ -111,31 +104,17 @@ public class FilterSet | |||||
public void setFiltersfile( File filtersFile ) | public void setFiltersfile( File filtersFile ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
readFiltersFromFile( filtersFile ); | readFiltersFromFile( filtersFile ); | ||||
} | } | ||||
public String getBeginToken() | public String getBeginToken() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef().getBeginToken(); | |||||
} | |||||
return startOfToken; | |||||
return m_startOfToken; | |||||
} | } | ||||
public String getEndToken() | public String getEndToken() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef().getEndToken(); | |||||
} | |||||
return endOfToken; | |||||
return m_endOfToken; | |||||
} | } | ||||
/** | /** | ||||
@@ -162,13 +141,8 @@ public class FilterSet | |||||
* @param filter The feature to be added to the Filter attribute | * @param filter The feature to be added to the Filter attribute | ||||
*/ | */ | ||||
public void addFilter( Filter filter ) | public void addFilter( Filter filter ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
filters.add( filter ); | |||||
m_filters.add( filter ); | |||||
} | } | ||||
/** | /** | ||||
@@ -178,13 +152,8 @@ public class FilterSet | |||||
* @param value The value for the new filter. | * @param value The value for the new filter. | ||||
*/ | */ | ||||
public void addFilter( String token, String value ) | public void addFilter( String token, String value ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
filters.add( new Filter( token, value ) ); | |||||
m_filters.add( new Filter( token, value ) ); | |||||
} | } | ||||
/** | /** | ||||
@@ -193,34 +162,10 @@ public class FilterSet | |||||
* @param filterSet the filterset to be added to this filterset | * @param filterSet the filterset to be added to this filterset | ||||
*/ | */ | ||||
public void addFilterSet( FilterSet filterSet ) | public void addFilterSet( FilterSet filterSet ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
for( Iterator e = filterSet.getFilters().iterator(); e.hasNext(); ) | for( Iterator e = filterSet.getFilters().iterator(); e.hasNext(); ) | ||||
{ | { | ||||
filters.add( (Filter)e.next() ); | |||||
} | |||||
} | |||||
public Object clone() | |||||
{ | |||||
try | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
return new FilterSet( getRef() ); | |||||
} | |||||
else | |||||
{ | |||||
return new FilterSet( this ); | |||||
} | |||||
} | |||||
catch( final TaskException te ) | |||||
{ | |||||
throw new RuntimeException( te.toString() ); | |||||
m_filters.add( (Filter)e.next() ); | |||||
} | } | ||||
} | } | ||||
@@ -230,12 +175,7 @@ public class FilterSet | |||||
* @return The filter that was created. | * @return The filter that was created. | ||||
*/ | */ | ||||
public FiltersFile createFiltersfile() | public FiltersFile createFiltersfile() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
return new FiltersFile(); | return new FiltersFile(); | ||||
} | } | ||||
@@ -260,11 +200,6 @@ public class FilterSet | |||||
public void readFiltersFromFile( File filtersFile ) | public void readFiltersFromFile( File filtersFile ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( filtersFile.isFile() ) | if( filtersFile.isFile() ) | ||||
{ | { | ||||
getLogger().debug( "Reading filters from " + filtersFile ); | getLogger().debug( "Reading filters from " + filtersFile ); | ||||
@@ -371,97 +306,8 @@ public class FilterSet | |||||
} | } | ||||
protected ArrayList getFilters() | protected ArrayList getFilters() | ||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
return getRef().getFilters(); | |||||
} | |||||
return filters; | |||||
} | |||||
protected FilterSet getRef() | |||||
throws TaskException | |||||
{ | |||||
return (FilterSet)getCheckedRef( FilterSet.class, "filterset" ); | |||||
} | |||||
/** | |||||
* Individual filter component of filterset | |||||
* | |||||
* @author Michael McCallum | |||||
* @created 14 March 2001 | |||||
*/ | |||||
public static class Filter | |||||
{ | { | ||||
/** | |||||
* Token which will be replaced in the filter operation | |||||
*/ | |||||
String token; | |||||
/** | |||||
* The value which will replace the token in the filtering operation | |||||
*/ | |||||
String value; | |||||
/** | |||||
* Constructor for the Filter object | |||||
* | |||||
* @param token The token which will be replaced when filtering | |||||
* @param value The value which will replace the token when filtering | |||||
*/ | |||||
public Filter( String token, String value ) | |||||
{ | |||||
this.token = token; | |||||
this.value = value; | |||||
} | |||||
/** | |||||
* No argument conmstructor | |||||
*/ | |||||
public Filter() | |||||
{ | |||||
} | |||||
/** | |||||
* Sets the Token attribute of the Filter object | |||||
* | |||||
* @param token The new Token value | |||||
*/ | |||||
public void setToken( String token ) | |||||
{ | |||||
this.token = token; | |||||
} | |||||
/** | |||||
* Sets the Value attribute of the Filter object | |||||
* | |||||
* @param value The new Value value | |||||
*/ | |||||
public void setValue( String value ) | |||||
{ | |||||
this.value = value; | |||||
} | |||||
/** | |||||
* Gets the Token attribute of the Filter object | |||||
* | |||||
* @return The Token value | |||||
*/ | |||||
public String getToken() | |||||
{ | |||||
return token; | |||||
} | |||||
/** | |||||
* Gets the Value attribute of the Filter object | |||||
* | |||||
* @return The Value value | |||||
*/ | |||||
public String getValue() | |||||
{ | |||||
return value; | |||||
} | |||||
return m_filters; | |||||
} | } | ||||
/** | /** | ||||
@@ -472,7 +318,6 @@ public class FilterSet | |||||
*/ | */ | ||||
public class FiltersFile | public class FiltersFile | ||||
{ | { | ||||
/** | /** | ||||
* Constructor for the Filter object | * Constructor for the Filter object | ||||
*/ | */ | ||||
@@ -9,8 +9,8 @@ package org.apache.tools.ant.types; | |||||
import java.net.URL; | import java.net.URL; | ||||
import java.net.URLClassLoader; | import java.net.URLClassLoader; | ||||
import java.util.Stack; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.ProjectComponent; | |||||
import org.apache.tools.ant.util.FileNameMapper; | import org.apache.tools.ant.util.FileNameMapper; | ||||
/** | /** | ||||
@@ -19,7 +19,7 @@ import org.apache.tools.ant.util.FileNameMapper; | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
*/ | */ | ||||
public class Mapper | public class Mapper | ||||
extends DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
private MapperType m_type; | private MapperType m_type; | ||||
@@ -33,14 +33,9 @@ public class Mapper | |||||
* | * | ||||
* @param classname The new Classname value | * @param classname The new Classname value | ||||
*/ | */ | ||||
public void setClassname( String classname ) | |||||
throws TaskException | |||||
public void setClassname( final String classname ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_classname = classname; | |||||
m_classname = classname; | |||||
} | } | ||||
/** | /** | ||||
@@ -51,97 +46,38 @@ public class Mapper | |||||
public void setClasspath( Path classpath ) | public void setClasspath( Path classpath ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
if( this.m_classpath == null ) | |||||
if( m_classpath == null ) | |||||
{ | { | ||||
this.m_classpath = classpath; | |||||
m_classpath = classpath; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.m_classpath.append( classpath ); | |||||
m_classpath.append( classpath ); | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Set the classpath to load the FileNameMapper through via reference | |||||
* (attribute). | |||||
* | |||||
* @param r The new ClasspathRef value | |||||
*/ | |||||
public void setClasspathRef( Reference r ) | |||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
createClasspath().setRefid( r ); | |||||
} | |||||
/** | /** | ||||
* Set the argument to FileNameMapper.setFrom | * Set the argument to FileNameMapper.setFrom | ||||
* | |||||
* @param from The new From value | |||||
*/ | */ | ||||
public void setFrom( String from ) | |||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_from = from; | |||||
} | |||||
/** | |||||
* Make this Mapper instance a reference to another Mapper. <p> | |||||
* | |||||
* You must not set any other attribute if you make it a reference.</p> | |||||
* | |||||
* @param r The new Refid value | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
public void setRefid( Reference r ) | |||||
throws TaskException | |||||
public void setFrom( final String from ) | |||||
{ | { | ||||
if( m_type != null || m_from != null || m_to != null ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
super.setRefid( r ); | |||||
m_from = from; | |||||
} | } | ||||
/** | /** | ||||
* Set the argument to FileNameMapper.setTo | * Set the argument to FileNameMapper.setTo | ||||
* | |||||
* @param to The new To value | |||||
*/ | */ | ||||
public void setTo( String to ) | |||||
throws TaskException | |||||
public void setTo( final String to ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_to = to; | |||||
m_to = to; | |||||
} | } | ||||
/** | /** | ||||
* Set the type of FileNameMapper to use. | * Set the type of FileNameMapper to use. | ||||
* | |||||
* @param type The new Type value | |||||
*/ | */ | ||||
public void setType( MapperType type ) | public void setType( MapperType type ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.m_type = type; | |||||
m_type = type; | |||||
} | } | ||||
/** | /** | ||||
@@ -153,11 +89,6 @@ public class Mapper | |||||
public FileNameMapper getImplementation() | public FileNameMapper getImplementation() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
return getRef().getImplementation(); | |||||
} | |||||
if( m_type == null && m_classname == null ) | if( m_type == null && m_classname == null ) | ||||
{ | { | ||||
throw new TaskException( "one of the attributes type or classname is required" ); | throw new TaskException( "one of the attributes type or classname is required" ); | ||||
@@ -217,43 +148,10 @@ public class Mapper | |||||
public Path createClasspath() | public Path createClasspath() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
if( m_classpath == null ) | |||||
{ | { | ||||
throw noChildrenAllowed(); | |||||
m_classpath = new Path(); | |||||
} | } | ||||
if( this.m_classpath == null ) | |||||
{ | |||||
this.m_classpath = new Path(); | |||||
} | |||||
return this.m_classpath.createPath(); | |||||
return m_classpath.createPath(); | |||||
} | } | ||||
/** | |||||
* Performs the check for circular references and returns the referenced | |||||
* Mapper. | |||||
* | |||||
* @return The Ref value | |||||
*/ | |||||
protected Mapper getRef() | |||||
throws TaskException | |||||
{ | |||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, getProject() ); | |||||
} | |||||
Object o = ref.getReferencedObject( getProject() ); | |||||
if( !( o instanceof Mapper ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a mapper"; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return (Mapper)o; | |||||
} | |||||
} | |||||
} | } |
@@ -11,14 +11,12 @@ import java.io.File; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | |||||
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Stack; | |||||
import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.PathTokenizer; | import org.apache.tools.ant.PathTokenizer; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* This object represents a path as used by CLASSPATH or PATH environment | * This object represents a path as used by CLASSPATH or PATH environment | ||||
@@ -51,9 +49,8 @@ import org.apache.tools.ant.Project; | |||||
* @author Thomas.Haas@softwired-inc.com | * @author Thomas.Haas@softwired-inc.com | ||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
*/ | */ | ||||
public class Path | public class Path | ||||
extends DataType | |||||
extends ProjectComponent | |||||
implements Cloneable | implements Cloneable | ||||
{ | { | ||||
public final static Path systemClasspath = createSystemClasspath(); | public final static Path systemClasspath = createSystemClasspath(); | ||||
@@ -91,11 +88,8 @@ public class Path | |||||
/** | /** | ||||
* Returns its argument with all file separator characters replaced so that | * Returns its argument with all file separator characters replaced so that | ||||
* they match the local OS conventions. | * they match the local OS conventions. | ||||
* | |||||
* @param source Description of Parameter | |||||
* @return Description of the Returned Value | |||||
*/ | */ | ||||
public static String translateFile( String source ) | |||||
private static String translateFile( final String source ) | |||||
{ | { | ||||
if( source == null ) | if( source == null ) | ||||
return ""; | return ""; | ||||
@@ -112,7 +106,7 @@ public class Path | |||||
/** | /** | ||||
* Splits a PATH (with : or ; as separators) into its parts. | * Splits a PATH (with : or ; as separators) into its parts. | ||||
*/ | */ | ||||
public String[] translatePath( Project project, String source ) | |||||
private String[] translatePath( final File baseDirectory, String source ) | |||||
{ | { | ||||
final ArrayList result = new ArrayList(); | final ArrayList result = new ArrayList(); | ||||
if( source == null ) | if( source == null ) | ||||
@@ -123,15 +117,18 @@ public class Path | |||||
while( tok.hasMoreTokens() ) | while( tok.hasMoreTokens() ) | ||||
{ | { | ||||
element.setLength( 0 ); | element.setLength( 0 ); | ||||
String pathElement = tok.nextToken(); | |||||
final String pathElement = tok.nextToken(); | |||||
try | try | ||||
{ | { | ||||
element.append( resolveFile( project, pathElement ) ); | |||||
element.append( resolveFile( baseDirectory, pathElement ) ); | |||||
} | } | ||||
catch( TaskException e ) | catch( TaskException e ) | ||||
{ | { | ||||
getLogger().debug( "Dropping path element " + pathElement + " as it is not valid relative to the project" ); | |||||
final String message = | |||||
"Dropping path element " + pathElement + " as it is not valid relative to the project"; | |||||
getLogger().debug( message ); | |||||
} | } | ||||
for( int i = 0; i < element.length(); i++ ) | for( int i = 0; i < element.length(); i++ ) | ||||
{ | { | ||||
translateFileSep( element, i ); | translateFileSep( element, i ); | ||||
@@ -139,8 +136,7 @@ public class Path | |||||
result.add( element.toString() ); | result.add( element.toString() ); | ||||
} | } | ||||
final String[] res = new String[ result.size() ]; | |||||
return (String[])result.toArray( res ); | |||||
return (String[])result.toArray( new String[ result.size() ] ); | |||||
} | } | ||||
/** | /** | ||||
@@ -151,7 +147,7 @@ public class Path | |||||
* @param pos Description of Parameter | * @param pos Description of Parameter | ||||
* @return Description of the Returned Value | * @return Description of the Returned Value | ||||
*/ | */ | ||||
protected static boolean translateFileSep( StringBuffer buffer, int pos ) | |||||
private static boolean translateFileSep( StringBuffer buffer, int pos ) | |||||
{ | { | ||||
if( buffer.charAt( pos ) == '/' || buffer.charAt( pos ) == '\\' ) | if( buffer.charAt( pos ) == '/' || buffer.charAt( pos ) == '\\' ) | ||||
{ | { | ||||
@@ -163,15 +159,12 @@ public class Path | |||||
/** | /** | ||||
* Adds a String to the ArrayList if it isn't already included. | * Adds a String to the ArrayList if it isn't already included. | ||||
* | |||||
* @param v The feature to be added to the UnlessPresent attribute | |||||
* @param s The feature to be added to the UnlessPresent attribute | |||||
*/ | */ | ||||
private static void addUnlessPresent( ArrayList v, String s ) | |||||
private static void addUnlessPresent( final ArrayList list, final String entry ) | |||||
{ | { | ||||
if( v.indexOf( s ) == -1 ) | |||||
if( !list.contains( entry ) ) | |||||
{ | { | ||||
v.add( s ); | |||||
list.add( entry ); | |||||
} | } | ||||
} | } | ||||
@@ -179,18 +172,14 @@ public class Path | |||||
* Resolve a filename with Project's help - if we know one that is. <p> | * Resolve a filename with Project's help - if we know one that is. <p> | ||||
* | * | ||||
* Assume the filename is absolute if project is null.</p> | * Assume the filename is absolute if project is null.</p> | ||||
* | |||||
* @param project Description of Parameter | |||||
* @param relativeName Description of Parameter | |||||
* @return Description of the Returned Value | |||||
*/ | */ | ||||
private static String resolveFile( Project project, String relativeName ) | |||||
private static String resolveFile( final File baseDirectory, final String relativeName ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( project != null ) | |||||
if( null != baseDirectory ) | |||||
{ | { | ||||
File f = FileUtil.resolveFile( project.getBaseDir(), relativeName ); | |||||
return f.getAbsolutePath(); | |||||
final File file = FileUtil.resolveFile( baseDirectory, relativeName ); | |||||
return file.getAbsolutePath(); | |||||
} | } | ||||
return relativeName; | return relativeName; | ||||
} | } | ||||
@@ -200,15 +189,9 @@ public class Path | |||||
* | * | ||||
* @param location the location of the element to add (must not be <code>null</code> | * @param location the location of the element to add (must not be <code>null</code> | ||||
* nor empty. | * nor empty. | ||||
* @exception TaskException Description of Exception | |||||
*/ | */ | ||||
public void setLocation( File location ) | |||||
throws TaskException | |||||
public void setLocation( final File location ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
createPathElement().setLocation( location ); | createPathElement().setLocation( location ); | ||||
} | } | ||||
@@ -216,63 +199,28 @@ public class Path | |||||
* Parses a path definition and creates single PathElements. | * Parses a path definition and creates single PathElements. | ||||
* | * | ||||
* @param path the path definition. | * @param path the path definition. | ||||
* @exception TaskException Description of Exception | |||||
*/ | */ | ||||
public void setPath( String path ) | public void setPath( String path ) | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
createPathElement().setPath( path ); | createPathElement().setPath( path ); | ||||
} | } | ||||
/** | |||||
* Makes this instance in effect a reference to another Path instance. <p> | |||||
* | |||||
* You must not set another attribute or nest elements inside this element | |||||
* if you make it a reference.</p> | |||||
* | |||||
* @param r The new Refid value | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
public void setRefid( Reference r ) | |||||
throws TaskException | |||||
{ | |||||
if( !elements.isEmpty() ) | |||||
{ | |||||
throw tooManyAttributes(); | |||||
} | |||||
elements.add( r ); | |||||
super.setRefid( r ); | |||||
} | |||||
/** | /** | ||||
* Adds the components on the given path which exist to this Path. | * Adds the components on the given path which exist to this Path. | ||||
* Components that don't exist, aren't added. | * Components that don't exist, aren't added. | ||||
* | * | ||||
* @param source - source path whose components are examined for existence | * @param source - source path whose components are examined for existence | ||||
*/ | */ | ||||
public void addExisting( Path source ) | |||||
public void addExisting( final Path source ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
String[] list = source.list(); | |||||
final String[] list = source.list(); | |||||
for( int i = 0; i < list.length; i++ ) | for( int i = 0; i < list.length; i++ ) | ||||
{ | { | ||||
File f = null; | |||||
if( getProject() != null ) | |||||
{ | |||||
f = resolveFile( list[ i ] ); | |||||
} | |||||
else | |||||
{ | |||||
f = new File( list[ i ] ); | |||||
} | |||||
if( f.exists() ) | |||||
final File file = new File( list[ i ] ); | |||||
if( file.exists() ) | |||||
{ | { | ||||
setLocation( f ); | |||||
setLocation( file ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -281,8 +229,6 @@ public class Path | |||||
* Emulation of extdirs feature in java >= 1.2. This method adds all files | * Emulation of extdirs feature in java >= 1.2. This method adds all files | ||||
* in the given directories (but not in sub-directories!) to the classpath, | * in the given directories (but not in sub-directories!) to the classpath, | ||||
* so that you don't have to specify them all one by one. | * so that you don't have to specify them all one by one. | ||||
* | |||||
* @param extdirs The feature to be added to the Extdirs attribute | |||||
*/ | */ | ||||
public void addExtdirs( Path extdirs ) | public void addExtdirs( Path extdirs ) | ||||
throws TaskException | throws TaskException | ||||
@@ -300,16 +246,16 @@ public class Path | |||||
} | } | ||||
} | } | ||||
String[] dirs = extdirs.list(); | |||||
final String[] dirs = extdirs.list(); | |||||
for( int i = 0; i < dirs.length; i++ ) | for( int i = 0; i < dirs.length; i++ ) | ||||
{ | { | ||||
File dir = resolveFile( dirs[ i ] ); | |||||
final File dir = resolveFile( dirs[ i ] ); | |||||
if( dir.exists() && dir.isDirectory() ) | if( dir.exists() && dir.isDirectory() ) | ||||
{ | { | ||||
FileSet fs = new FileSet(); | |||||
fs.setDir( dir ); | |||||
fs.setIncludes( "*" ); | |||||
addFileset( fs ); | |||||
final FileSet fileSet = new FileSet(); | |||||
fileSet.setDir( dir ); | |||||
fileSet.setIncludes( "*" ); | |||||
addFileset( fileSet ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -320,15 +266,9 @@ public class Path | |||||
* @param fs The feature to be added to the Fileset attribute | * @param fs The feature to be added to the Fileset attribute | ||||
* @exception TaskException Description of Exception | * @exception TaskException Description of Exception | ||||
*/ | */ | ||||
public void addFileset( FileSet fs ) | |||||
throws TaskException | |||||
public void addFileset( final FileSet fileSet ) | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
elements.add( fs ); | |||||
checked = false; | |||||
elements.add( fileSet ); | |||||
} | } | ||||
/** | /** | ||||
@@ -382,42 +322,24 @@ public class Path | |||||
/** | /** | ||||
* Append the contents of the other Path instance to this. | * Append the contents of the other Path instance to this. | ||||
* | |||||
* @param other Description of Parameter | |||||
*/ | */ | ||||
public void append( Path other ) | |||||
public void append( final Path other ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( other == null ) | |||||
return; | |||||
String[] l = other.list(); | |||||
for( int i = 0; i < l.length; i++ ) | |||||
if( null == other ) | |||||
{ | { | ||||
if( elements.indexOf( l[ i ] ) == -1 ) | |||||
{ | |||||
elements.add( l[ i ] ); | |||||
} | |||||
throw new NullPointerException( "other" ); | |||||
} | } | ||||
} | |||||
/** | |||||
* Return a Path that holds the same elements as this instance. | |||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | |||||
public Object clone() | |||||
{ | |||||
try | |||||
{ | |||||
Path p = new Path(); | |||||
p.append( this ); | |||||
return p; | |||||
} | |||||
catch( TaskException e ) | |||||
final String[] list = other.list(); | |||||
for( int i = 0; i < list.length; i++ ) | |||||
{ | { | ||||
throw new IllegalStateException( e.getMessage() ); | |||||
final String file = list[ i ]; | |||||
if( elements.contains( file ) ) | |||||
{ | |||||
elements.add( file ); | |||||
} | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
@@ -459,20 +381,17 @@ public class Path | |||||
{ | { | ||||
// only: the developer knows what (s)he is doing | // only: the developer knows what (s)he is doing | ||||
result.addExisting( Path.systemClasspath ); | result.addExisting( Path.systemClasspath ); | ||||
} | } | ||||
else if( order.equals( "first" ) ) | else if( order.equals( "first" ) ) | ||||
{ | { | ||||
// first: developer could use a little help | // first: developer could use a little help | ||||
result.addExisting( Path.systemClasspath ); | result.addExisting( Path.systemClasspath ); | ||||
result.addExisting( this ); | result.addExisting( this ); | ||||
} | } | ||||
else if( order.equals( "ignore" ) ) | else if( order.equals( "ignore" ) ) | ||||
{ | { | ||||
// ignore: don't trust anyone | // ignore: don't trust anyone | ||||
result.addExisting( this ); | result.addExisting( this ); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -499,50 +418,27 @@ public class Path | |||||
public Path createPath() | public Path createPath() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
Path p = new Path(); | |||||
elements.add( p ); | |||||
checked = false; | |||||
return p; | |||||
final Path other = new Path(); | |||||
elements.add( other ); | |||||
return other; | |||||
} | } | ||||
/** | /** | ||||
* Creates the nested <code><pathelement></code> element. | * Creates the nested <code><pathelement></code> element. | ||||
* | |||||
* @return Description of the Returned Value | |||||
* @exception TaskException Description of Exception | |||||
*/ | */ | ||||
public PathElement createPathElement() | public PathElement createPathElement() | ||||
throws TaskException | |||||
{ | { | ||||
if( isReference() ) | |||||
{ | |||||
throw noChildrenAllowed(); | |||||
} | |||||
PathElement pe = new PathElement(); | |||||
elements.add( pe ); | |||||
return pe; | |||||
final PathElement pathElement = new PathElement(); | |||||
elements.add( pathElement ); | |||||
return pathElement; | |||||
} | } | ||||
/** | /** | ||||
* Returns all path elements defined by this and nested path objects. | * Returns all path elements defined by this and nested path objects. | ||||
* | |||||
* @return list of path elements. | |||||
*/ | */ | ||||
public String[] list() | public String[] list() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( !checked ) | |||||
{ | |||||
// make sure we don't have a circular reference here | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, getProject() ); | |||||
} | |||||
ArrayList result = new ArrayList( 2 * elements.size() ); | ArrayList result = new ArrayList( 2 * elements.size() ); | ||||
for( int i = 0; i < elements.size(); i++ ) | for( int i = 0; i < elements.size(); i++ ) | ||||
{ | { | ||||
@@ -599,14 +495,11 @@ public class Path | |||||
} | } | ||||
} | } | ||||
} | } | ||||
String[] res = new String[ result.size() ]; | |||||
return (String[])result.toArray( res ); | |||||
return (String[])result.toArray( new String[ result.size() ] ); | |||||
} | } | ||||
/** | /** | ||||
* How many parts does this Path instance consist of. | * How many parts does this Path instance consist of. | ||||
* | |||||
* @return Description of the Returned Value | |||||
*/ | */ | ||||
public int size() | public int size() | ||||
throws TaskException | throws TaskException | ||||
@@ -673,52 +566,8 @@ public class Path | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Overrides the version of DataType to recurse on all DataType child | |||||
* elements that may have been added. | |||||
* | |||||
* @param stk Description of Parameter | |||||
* @param p Description of Parameter | |||||
* @exception TaskException Description of Exception | |||||
*/ | |||||
protected void dieOnCircularReference( Stack stk, Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( checked ) | |||||
{ | |||||
return; | |||||
} | |||||
Iterator enum = elements.iterator(); | |||||
while( enum.hasNext() ) | |||||
{ | |||||
Object o = enum.next(); | |||||
if( o instanceof Reference ) | |||||
{ | |||||
o = ( (Reference)o ).getReferencedObject( p ); | |||||
} | |||||
if( o instanceof DataType ) | |||||
{ | |||||
if( stk.contains( o ) ) | |||||
{ | |||||
throw circularReference(); | |||||
} | |||||
else | |||||
{ | |||||
stk.push( o ); | |||||
( (DataType)o ).dieOnCircularReference( stk, p ); | |||||
stk.pop(); | |||||
} | |||||
} | |||||
} | |||||
checked = true; | |||||
} | |||||
/** | /** | ||||
* Helper class, holds the nested <code><pathelement></code> values. | * Helper class, holds the nested <code><pathelement></code> values. | ||||
* | |||||
* @author RT | |||||
*/ | */ | ||||
public class PathElement | public class PathElement | ||||
{ | { | ||||
@@ -731,7 +580,7 @@ public class Path | |||||
public void setPath( String path ) | public void setPath( String path ) | ||||
{ | { | ||||
parts = translatePath( getProject(), path ); | |||||
parts = translatePath( getProject().getBaseDir(), path ); | |||||
} | } | ||||
public String[] getParts() | public String[] getParts() | ||||
@@ -16,6 +16,7 @@ import java.util.Iterator; | |||||
import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.ProjectComponent; | |||||
/** | /** | ||||
* Named collection of include/exclude tags. <p> | * Named collection of include/exclude tags. <p> | ||||
@@ -31,7 +32,7 @@ import org.apache.tools.ant.Project; | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
*/ | */ | ||||
public class PatternSet | public class PatternSet | ||||
extends DataType | |||||
extends ProjectComponent | |||||
{ | { | ||||
private ArrayList m_includeList = new ArrayList(); | private ArrayList m_includeList = new ArrayList(); | ||||
private ArrayList m_excludeList = new ArrayList(); | private ArrayList m_excludeList = new ArrayList(); | ||||
@@ -7,9 +7,8 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
import java.util.Stack; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectComponent; | |||||
import org.apache.tools.ant.util.regexp.Regexp; | import org.apache.tools.ant.util.regexp.Regexp; | ||||
import org.apache.tools.ant.util.regexp.RegexpFactory; | import org.apache.tools.ant.util.regexp.RegexpFactory; | ||||
@@ -42,79 +41,37 @@ import org.apache.tools.ant.util.regexp.RegexpFactory; | |||||
* @see java.util.regex.Pattern | * @see java.util.regex.Pattern | ||||
* @see org.apache.tools.ant.util.regexp.Regexp | * @see org.apache.tools.ant.util.regexp.Regexp | ||||
*/ | */ | ||||
public class RegularExpression extends DataType | |||||
public class RegularExpression | |||||
extends ProjectComponent | |||||
{ | { | ||||
public final static String DATA_TYPE_NAME = "regularexpression"; | |||||
// The regular expression factory | // The regular expression factory | ||||
private final static RegexpFactory factory = new RegexpFactory(); | private final static RegexpFactory factory = new RegexpFactory(); | ||||
private Regexp regexp; | |||||
private Regexp m_regexp; | |||||
public RegularExpression() | public RegularExpression() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
this.regexp = factory.newRegexp(); | |||||
m_regexp = factory.newRegexp(); | |||||
} | } | ||||
public void setPattern( String pattern ) | |||||
public void setPattern( final String pattern ) | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
this.regexp.setPattern( pattern ); | |||||
m_regexp.setPattern( pattern ); | |||||
} | } | ||||
/** | /** | ||||
* Gets the pattern string for this RegularExpression in the given project. | * Gets the pattern string for this RegularExpression in the given project. | ||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Pattern value | |||||
*/ | */ | ||||
public String getPattern( Project p ) | |||||
public String getPattern() | |||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
if( isReference() ) | |||||
return getRef( p ).getPattern( p ); | |||||
return regexp.getPattern(); | |||||
return m_regexp.getPattern(); | |||||
} | } | ||||
/** | |||||
* Get the RegularExpression this reference refers to in the given project. | |||||
* Check for circular references too | |||||
* | |||||
* @param p Description of Parameter | |||||
* @return The Ref value | |||||
*/ | |||||
public RegularExpression getRef( Project p ) | |||||
throws TaskException | |||||
public Regexp getRegexp() | |||||
{ | { | ||||
if( !checked ) | |||||
{ | |||||
Stack stk = new Stack(); | |||||
stk.push( this ); | |||||
dieOnCircularReference( stk, p ); | |||||
} | |||||
Object o = ref.getReferencedObject( p ); | |||||
if( !( o instanceof RegularExpression ) ) | |||||
{ | |||||
String msg = ref.getRefId() + " doesn\'t denote a regularexpression"; | |||||
throw new TaskException( msg ); | |||||
} | |||||
else | |||||
{ | |||||
return (RegularExpression)o; | |||||
} | |||||
return m_regexp; | |||||
} | } | ||||
public Regexp getRegexp( Project p ) | |||||
throws TaskException | |||||
{ | |||||
if( isReference() ) | |||||
{ | |||||
return getRef( p ).getRegexp( p ); | |||||
} | |||||
return this.regexp; | |||||
} | |||||
} | } |