Last active
March 14, 2024 07:30
-
-
Save etiennestuder/5653547be88410d914fbf0700d4d6be4 to your computer and use it in GitHub Desktop.
Voice notification when when Gradle build finishes (for Mac OS X)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When runnning a Gradle build in the background, it is convenient to be notified immediately | |
// via voice once the build has finished - without having to actively switch windows to find out - | |
// and being told the actual exception in case of a build failure. | |
// Put this file into the folder ~/.gradle/init.d to enable the acoustic notifications for all builds | |
gradle.addBuildListener(new BuildAdapter() { | |
@Override | |
void buildFinished(BuildResult result) { | |
def projectName = gradle.rootProject.name | |
if (result.failure) { | |
playSound('Submarine.aiff') | |
def e = getExceptionParts(result) | |
"say '$projectName build failed: ${e.first} ${e.second}.'".execute() | |
} else { | |
if (projectName != "buildSrc") { | |
playSound('Glass.aiff') | |
"say '$projectName build successful.'".execute() | |
} | |
} | |
} | |
private Tuple2<String, String> getExceptionParts(BuildResult result) { | |
def exception = result.failure | |
if (exception.cause != null) { | |
exception = exception.cause | |
} | |
def className = exception.class.simpleName | |
def of = className.indexOf('Exception') | |
new Tuple2<String, String>(className.substring(0, of), className.substring(of)) | |
} | |
private void playSound(def sound) { | |
"afplay /System/Library/Sounds/$sound".execute() | |
sleep(100) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice! Thank you very much for sharing!