git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270469 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -19,10 +19,9 @@ import javax.sound.sampled.LineEvent; | |||
| 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. | |||
| @@ -35,8 +34,8 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
| * @version $Revision$, $Date$ | |||
| */ | |||
| 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 @@ public class AntSoundPlayer | |||
| 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; | |||
| } | |||
| /** | |||
| @@ -174,6 +131,23 @@ public class AntSoundPlayer | |||
| } | |||
| } | |||
| 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 ); | |||
| } | |||
| } | |||
| /** | |||
| * Plays the file for duration milliseconds or loops. | |||
| */ | |||
| @@ -19,10 +19,9 @@ import javax.sound.sampled.LineEvent; | |||
| 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. | |||
| @@ -35,8 +34,8 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
| * @version $Revision$, $Date$ | |||
| */ | |||
| 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 @@ public class AntSoundPlayer | |||
| 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; | |||
| } | |||
| /** | |||
| @@ -174,6 +131,23 @@ public class AntSoundPlayer | |||
| } | |||
| } | |||
| 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 ); | |||
| } | |||
| } | |||
| /** | |||
| * Plays the file for duration milliseconds or loops. | |||
| */ | |||