|
| 1 | +/* |
| 2 | + * Copyright 2017 Denis N. Antonioli |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package ro.lmn.maven.dmn.impl; |
| 17 | + |
| 18 | +import org.apache.maven.artifact.versioning.ComparableVersion; |
| 19 | +import ro.lmn.maven.dmn.api.NotificationType; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | + |
| 23 | +/** |
| 24 | + * NotifierFactory for Mac OS X based on OSA <code><a href="https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW224>display notification</a></code>. |
| 25 | + * Support has been introduced with <code><a href="https://developer.apple.com/library/content/releasenotes/AppleScript/RN-AppleScript/RN-10_9/RN-10_9.html">Mac OS X 10.9</a></code>. |
| 26 | + */ |
| 27 | +public class MacOSXOsaNotifier extends AbstractNotifier { |
| 28 | + |
| 29 | + public static final String OSASCRIPT = "/usr/bin/osascript"; |
| 30 | + |
| 31 | + @Override |
| 32 | + public void notify(String title, String details, NotificationType notificationType) throws IOException { |
| 33 | + ProcessBuilder builder = new ProcessBuilder(OSASCRIPT, "-e", "display notification \"" + details + "\" with title \"" + title + "\""); |
| 34 | + executeProcess(builder); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public boolean isAvailable() { |
| 39 | + return OSType.MAC == OSType.getDetected() && osaScriptHasDisplayNotification(); |
| 40 | + } |
| 41 | + |
| 42 | + private static boolean osaScriptHasDisplayNotification() { |
| 43 | + return new ComparableVersion(System.getProperty("os.version")).compareTo(new ComparableVersion("10.9")) >= 0; |
| 44 | + } |
| 45 | +} |
0 commit comments