holtdl 01/11/27 09:44:52 Modified: src/main/org/apache/tools/ant/taskdefs/optional/sound SoundTask.java Log: Make sure only files are passed as possibilites when a directory is given. PR: 5128 Revision Changes Path 1.5 +18 -6 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java Index: SoundTask.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SoundTask.java 2001/10/28 21:30:24 1.4 +++ SoundTask.java 2001/11/27 17:44:52 1.5 @@ -56,9 +56,11 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; import java.io.File; import java.util.Random; +import java.util.Vector; /** * This is an example of an AntTask that makes of use of the AntSoundPlayer. @@ -77,7 +79,7 @@ * Ant play them back * * @author Nick Pellow - * @version $Revision: 1.4 $, $Date: 2001/10/28 21:30:24 $ + * @version $Revision: 1.5 $, $Date: 2001/11/27 17:44:52 $ */ public class SoundTask extends Task { @@ -142,7 +144,7 @@ /** * Sets the location of the file to get the audio. * - * @param source the name a sound-file directory or of the audio file + * @param source the name of a sound-file directory or of the audio file */ public void setSource(File source) { this.source = source; @@ -166,13 +168,23 @@ if( source.exists() ) { if( source.isDirectory() ) { // get the list of files in the dir - File[] files = source.listFiles() ; - int numfiles = files.length ; + String[] entries = source.list() ; + Vector files = new Vector() ; + for (int i=0 ; i < entries.length ; i++) { + File f = new File(source, entries[i]) ; + if (f.isFile()) { + files.addElement(f) ; + } + } + if ( files.size() < 1 ) { + throw new BuildException("No files found in directory " + source); + } + int numfiles = files.size() ; // get a random number between 0 and the number of files Random rn = new Random() ; - int i = rn.nextInt(numfiles) ; + int x = rn.nextInt(numfiles) ; // set the source to the file at that location - this.source = files[i] ; + this.source = (File)files.elementAt(x) ; } } else { log(source + ": invalid path.", Project.MSG_WARN) ;
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>