From 38d67216b5f3636670849f7f5bfdae7ed3c79140 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 21 Aug 2014 19:19:31 -0600 Subject: [PATCH] fix gradle macosx OperatingSystem naming --- build.gradle | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index d2b001c4eb..50b04cb582 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,41 @@ apply plugin: 'ivy-publish' apply plugin: 'java' apply plugin: 'artifactory-publish' +enum SupportedOS implements OperatingSystem { + LINUX, WINDOWS, MACOSX; + + public static final SupportedOS CURRENT; + + static { + String p = System.properties['os.name'] + switch(p.replaceAll(' ', '').toLowerCase()) { + case ~/.*linux.*/: CURRENT = LINUX; break; + case ~/.*darwin.*/: CURRENT = MACOSX; break; + case ~/.*osx.*/: CURRENT = MACOSX; break; + case ~/.*win.*/: CURRENT = WINDOWS; break; + default: + String m = "SupportedOS: unrecognized platform: ${p}" + println(m) + throw new IllegalArgumentException(m) + } + } + + public String getName() { + return toString().toLowerCase() + } + + public String getDisplayName() { + return getName() + } + public boolean isCurrent() { return this == CURRENT } + public boolean isFreeBSD() { return false } + public boolean isLinux() { return this == LINUX } + public boolean isMacOsX() { return this == MACOSX } + public boolean isSolaris() { return false } + public boolean isWindows() { return this == WINDOWS } + +} + public String adjustArch(String arch) { switch(arch) { case ~/.*64.*/: return 'x86_64' @@ -20,18 +55,8 @@ public String adjustArch(String arch) { } } -public String adjustPlatform(String platform) { - switch(platform.replaceAll(' ', '').toLowerCase()) { - case ~/.*linux.*/: return 'linux' - case ~/.*darwin.*/: return 'macosx' - case ~/.*osx.*/: return 'macosx' - case ~/.*win.*/: return 'windows' - default: return platform - } -} - ext { - currentPlatform = adjustPlatform(System.properties['os.name']) + currentPlatform = SupportedOS.CURRENT.getName() currentArch = adjustArch(System.properties['os.arch']) currentPlatformArch = "${currentPlatform}-${currentArch}" @@ -50,12 +75,12 @@ ext { model { platforms { create(platformArch) { - operatingSystem "${platform}" + operatingSystem SupportedOS.valueOf(platform.toUpperCase()) architecture "${arch}" } if(platformArch != currentPlatformArch) { create(currentPlatformArch) { - operatingSystem "${currentPlatform}" + operatingSystem SupportedOS.CURRENT architecture "${currentArch}" } }