ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound SoundTask.java
Date Sun, 30 Dec 2001 08:19:21 GMT
donaldp     01/12/30 00:19:21

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound
                        SoundTask.java
  Log:
  Moved BuildAlert from inner class to top-level class.
  
  Made AntSoundPlayer a ProjectListener rather than a BuildListener
  
  Revision  Changes    Path
  1.9       +48 -117   jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java
  
  Index: SoundTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SoundTask.java	23 Dec 2001 14:22:48 -0000	1.8
  +++ SoundTask.java	30 Dec 2001 08:19:21 -0000	1.9
  @@ -24,163 +24,94 @@
    * in xml and have Ant play them back
    *
    * @author Nick Pellow
  - * @version $Revision: 1.8 $, $Date: 2001/12/23 14:22:48 $
  + * @version $Revision: 1.9 $, $Date: 2001/12/30 08:19:21 $
    */
  -
  -public class SoundTask extends Task
  +public class SoundTask
  +    extends Task
   {
  -
  -    private BuildAlert success = null;
  -    private BuildAlert fail = null;
  -
  -    public SoundTask()
  -    {
  -    }
  +    private BuildAlert m_success;
  +    private BuildAlert m_fail;
   
       public BuildAlert createFail()
       {
  -        fail = new BuildAlert();
  -        return fail;
  +        m_fail = new BuildAlert();
  +        return m_fail;
       }
   
       public BuildAlert createSuccess()
       {
  -        success = new BuildAlert();
  -        return success;
  +        m_success = new BuildAlert();
  +        return m_success;
       }
   
       public void execute()
       {
  -
  -        AntSoundPlayer soundPlayer = new AntSoundPlayer();
  -
  -        if( success == null )
  +        final AntSoundPlayer soundPlayer = new AntSoundPlayer();
  +        if( null == m_success )
           {
               getLogger().warn( "No nested success element found." );
           }
           else
           {
  -            soundPlayer.addBuildSuccessfulSound( success.getSource(),
  -                                                 success.getLoops(), success.getDuration()
);
  +            soundPlayer.addBuildSuccessfulSound( getRandomSource( m_success ),
  +                                                 m_success.getLoops(), m_success.getDuration()
);
           }
   
  -        if( fail == null )
  +        if( null == m_fail )
           {
               getLogger().warn( "No nested failure element found." );
           }
           else
           {
  -            soundPlayer.addBuildFailedSound( fail.getSource(),
  -                                             fail.getLoops(), fail.getDuration() );
  +            soundPlayer.addBuildFailedSound( getRandomSource( m_fail ),
  +                                             m_fail.getLoops(), m_fail.getDuration() );
           }
   
  -        getProject().addBuildListener( soundPlayer );
  -
  +        getProject().addProjectListener( soundPlayer );
       }
   
       /**
  -     * A class to be extended by any BuildAlert's that require the output of
  -     * sound.
  +     * Gets the location of the file to get the audio.
  +     *
  +     * @return The Source value
        */
  -    public class BuildAlert
  +    private File getRandomSource( final BuildAlert alert )
       {
  -        private File source = null;
  -        private int loops = 0;
  -        private Long duration = null;
  -
  -        /**
  -         * Sets the duration in milliseconds the file should be played.
  -         *
  -         * @param duration The new Duration value
  -         */
  -        public void setDuration( Long duration )
  +        final File source = alert.getSource();
  +        // Check if source is a directory
  +        if( source.exists() )
           {
  -            this.duration = duration;
  -        }
  -
  -        /**
  -         * Sets the number of times the source file should be played.
  -         *
  -         * @param loops the number of loops to play the source file
  -         */
  -        public void setLoops( int loops )
  -        {
  -            this.loops = loops;
  -        }
  -
  -        /**
  -         * Sets the location of the file to get the audio.
  -         *
  -         * @param source the name of a sound-file directory or of the audio file
  -         */
  -        public void setSource( File source )
  -        {
  -            this.source = source;
  -        }
  -
  -        /**
  -         * Gets the duration in milliseconds the file should be played.
  -         *
  -         * @return The Duration value
  -         */
  -        public Long getDuration()
  -        {
  -            return this.duration;
  -        }
  -
  -        /**
  -         * Sets the number of times the source file should be played.
  -         *
  -         * @return the number of loops to play the source file
  -         */
  -        public int getLoops()
  -        {
  -            return this.loops;
  -        }
  -
  -        /**
  -         * Gets the location of the file to get the audio.
  -         *
  -         * @return The Source value
  -         */
  -        public File getSource()
  -        {
  -            File nofile = null;
  -            // Check if source is a directory
  -            if( source.exists() )
  +            if( source.isDirectory() )
               {
  -                if( source.isDirectory() )
  +                // get the list of files in the dir
  +                final String[] entries = source.list();
  +                ArrayList files = new ArrayList();
  +                for( int i = 0; i < entries.length; i++ )
                   {
  -                    // get the list of files in the dir
  -                    String[] entries = source.list();
  -                    ArrayList files = new ArrayList();
  -                    for( int i = 0; i < entries.length; i++ )
  -                    {
  -                        File f = new File( source, entries[ i ] );
  -                        if( f.isFile() )
  -                        {
  -                            files.add( f );
  -                        }
  -                    }
  -                    if( files.size() < 1 )
  +                    File f = new File( source, entries[ i ] );
  +                    if( f.isFile() )
                       {
  -                        throw new TaskException( "No files found in directory " + source
);
  +                        files.add( f );
                       }
  -                    int numfiles = files.size();
  -                    // get a random number between 0 and the number of files
  -                    Random rn = new Random();
  -                    int x = rn.nextInt( numfiles );
  -                    // set the source to the file at that location
  -                    this.source = (File)files.get( x );
                   }
  +                if( files.size() < 1 )
  +                {
  +                    throw new TaskException( "No files found in directory " + source );
  +                }
  +                final int numfiles = files.size();
  +                // get a random number between 0 and the number of files
  +                final Random random = new Random();
  +                final int x = random.nextInt( numfiles );
  +                // set the source to the file at that location
  +                source = (File)files.get( x );
               }
  -            else
  -            {
  -                getLogger().warn( source + ": invalid path." );
  -                this.source = nofile;
  -            }
  -            return this.source;
           }
  +        else
  +        {
  +            getLogger().warn( source + ": invalid path." );
  +            source = null;
  +        }
  +        return source;
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message