2 // JSpec - Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
13 * Execute the given _cmd_, returning an array of lines from stdout.
17 * Growl.exec('growlnotify', '-m', msg)
19 * @param {string ...} cmd
26 with (JavaImporter(java.lang, java.io)) {
27 var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
28 var stream = new DataInputStream(proccess.getInputStream())
29 while (line = stream.readLine())
37 * Return the extension of the given _path_ or null.
39 * @param {string} path
44 extname: function(path) {
45 return path.lastIndexOf('.') != -1 ?
46 path.slice(path.lastIndexOf('.') + 1, path.length) :
51 * Version of the 'growlnotify' binary.
57 binVersion: function() {
58 try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
62 * Send growl notification _msg_ with _options_.
66 * - title Notification title
67 * - sticky Make the notification stick (defaults to false)
68 * - name Application name (defaults to growlnotify)
70 * - path to an icon sets --iconpath
71 * - path to an image sets --image
72 * - capitalized word sets --appIcon
73 * - filename uses extname as --icon
74 * - otherwise treated as --icon
78 * Growl.notify('New email')
79 * Growl.notify('5 new emails', { title: 'Thunderbird' })
82 * @param {options} hash
86 notify: function(msg, options) {
87 options = options || {}
88 var args = ['growlnotify', '-m', msg]
89 if (!this.binVersion()) throw new Error('growlnotify executable is required')
90 if (image = options.image) {
91 var flag, ext = this.extname(image)
92 flag = flag || ext == 'icns' && 'iconpath'
93 flag = flag || /^[A-Z]/.test(image) && 'appIcon'
94 flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
95 flag = flag || ext && (image = ext) && 'icon'
97 args.push('--' + flag, image)
99 if (options.sticky) args.push('--sticky')
100 if (options.name) args.push('--name', options.name)
101 if (options.title) args.push(options.title)
102 this.exec.apply(this, args)
108 reporting: function(options){
109 var stats = JSpec.stats
110 if (stats.failures) Growl.notify('failed ' + stats.failures + ' assertions', { title: 'JSpec'})
111 else Growl.notify('passed ' + stats.passes + ' assertions', { title: 'JSpec' })