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 AntSoundPlayer.java
Date Sun, 30 Dec 2001 08:18:26 GMT
donaldp     01/12/30 00:18:26

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound
                        AntSoundPlayer.java
  Log:
  Made into a ProjectListener for new style event notification
  
  Revision  Changes    Path
  1.9       +56 -82    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
  
  Index: AntSoundPlayer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AntSoundPlayer.java	30 Dec 2001 03:44:05 -0000	1.8
  +++ AntSoundPlayer.java	30 Dec 2001 08:18:25 -0000	1.9
  @@ -19,10 +19,9 @@
   import javax.sound.sampled.LineListener;
   import javax.sound.sampled.LineUnavailableException;
   import javax.sound.sampled.UnsupportedAudioFileException;
  -import org.apache.tools.ant.BuildEvent;
  -import org.apache.tools.ant.BuildListener;
  -import org.apache.tools.ant.Project;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.myrmidon.listeners.AbstractProjectListener;
   
   /**
    * This class is designed to be used by any AntTask that requires audio output.
  @@ -32,11 +31,11 @@
    * Both seem to work fine.
    *
    * @author Nick Pellow
  - * @version $Revision: 1.8 $, $Date: 2001/12/30 03:44:05 $
  + * @version $Revision: 1.9 $, $Date: 2001/12/30 08:18:25 $
    */
   public class AntSoundPlayer
  -    extends AbstractLogEnabled
  -    implements LineListener, BuildListener
  +    extends AbstractProjectListener
  +    implements LineListener, LogEnabled
   {
       private File m_fileSuccess;
       private int m_loopsSuccess;
  @@ -46,110 +45,68 @@
       private int m_loopsFail;
       private Long m_durationFail;
   
  -    public AntSoundPlayer()
  -    {
  -    }
  -
  -    /**
  -     * @param fileFail The feature to be added to the BuildFailedSound attribute
  -     * @param loopsFail The feature to be added to the BuildFailedSound
  -     *      attribute
  -     * @param durationFail The feature to be added to the BuildFailedSound
  -     *      attribute
  -     */
  -    public void addBuildFailedSound( File fileFail, int loopsFail, Long durationFail )
  -    {
  -        m_fileFail = fileFail;
  -        m_loopsFail = loopsFail;
  -        m_durationFail = durationFail;
  -    }
  -
  -    /**
  -     * @param loops the number of times the file should be played when the build
  -     *      is successful
  -     * @param duration the number of milliseconds the file should be played when
  -     *      the build is successful
  -     * @param file The feature to be added to the BuildSuccessfulSound attribute
  -     */
  -    public void addBuildSuccessfulSound( File file, int loops, Long duration )
  -    {
  -        m_fileSuccess = file;
  -        m_loopsSuccess = loops;
  -        m_durationSuccess = duration;
  -    }
  +    private Logger m_logger;
   
       /**
  -     * Fired after the last target has finished. This event will still be thrown
  -     * if an error occured during the build.
  +     * Provide component with a logger.
        *
  -     * @see BuildEvent#getException()
  +     * @param logger the logger
        */
  -    public void buildFinished( BuildEvent event )
  +    public void enableLogging( final Logger logger )
       {
  -        if( event.getException() == null && m_fileSuccess != null )
  -        {
  -            // build successfull!
  -            play( m_fileSuccess, m_loopsSuccess, m_durationSuccess );
  -        }
  -        else if( event.getException() != null && m_fileFail != null )
  -        {
  -            play( m_fileFail, m_loopsFail, m_durationFail );
  -        }
  +        m_logger = logger;
       }
   
  -    /**
  -     * Fired before any targets are started.
  -     */
  -    public void buildStarted( BuildEvent event )
  +    protected final Logger getLogger()
       {
  +        return m_logger;
       }
   
       /**
  -     * Fired whenever a message is logged.
  -     *
  -     * @see BuildEvent#getMessage()
  -     * @see BuildEvent#getPriority()
  +     * Notify listener of projectFinished event.
        */
  -    public void messageLogged( BuildEvent event )
  +    public void projectFinished()
       {
  +        success();
       }
   
       /**
  -     * Fired when a target has finished. This event will still be thrown if an
  -     * error occured during the build.
  +     * Notify listener of log message event.
        *
  -     * @see BuildEvent#getException()
  +     * @param message the message
  +     * @param throwable the throwable
        */
  -    public void targetFinished( BuildEvent event )
  +    public void log( final String message, final Throwable throwable )
       {
  +        failure();
       }
   
       /**
  -     * Fired when a target is started.
  -     *
  -     * @see BuildEvent#getTarget()
  -     */
  -    public void targetStarted( BuildEvent event )
  -    {
  -    }
  -
  -    /**
  -     * Fired when a task has finished. This event will still be throw if an
  -     * error occured during the build.
  -     *
  -     * @see BuildEvent#getException()
  +     * @param fileFail The feature to be added to the BuildFailedSound attribute
  +     * @param loopsFail The feature to be added to the BuildFailedSound
  +     *      attribute
  +     * @param durationFail The feature to be added to the BuildFailedSound
  +     *      attribute
        */
  -    public void taskFinished( BuildEvent event )
  +    public void addBuildFailedSound( File fileFail, int loopsFail, Long durationFail )
       {
  +        m_fileFail = fileFail;
  +        m_loopsFail = loopsFail;
  +        m_durationFail = durationFail;
       }
   
       /**
  -     * Fired when a task is started.
  -     *
  -     * @see BuildEvent#getTask()
  +     * @param loops the number of times the file should be played when the build
  +     *      is successful
  +     * @param duration the number of milliseconds the file should be played when
  +     *      the build is successful
  +     * @param file The feature to be added to the BuildSuccessfulSound attribute
        */
  -    public void taskStarted( BuildEvent event )
  +    public void addBuildSuccessfulSound( File file, int loops, Long duration )
       {
  +        m_fileSuccess = file;
  +        m_loopsSuccess = loops;
  +        m_durationSuccess = duration;
       }
   
       /**
  @@ -171,6 +128,23 @@
                * So we have to exit ourselves.
                */
               //System.exit(0);
  +        }
  +    }
  +
  +    protected void success()
  +    {
  +        if( null != m_fileSuccess )
  +        {
  +            // build successfull!
  +            play( m_fileSuccess, m_loopsSuccess, m_durationSuccess );
  +        }
  +    }
  +
  +    protected void failure()
  +    {
  +        if( null != m_fileFail )
  +        {
  +            play( m_fileFail, m_loopsFail, m_durationFail );
           }
       }
   
  
  
  

--
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