|
| 1 | +// https://github.com/mockk/mockk |
| 2 | +def pathExists(String envPath) { |
| 3 | + if (envPath != null && !envPath.empty) { |
| 4 | + return file(envPath).exists() |
| 5 | + } |
| 6 | + |
| 7 | + return false |
| 8 | +} |
| 9 | + |
| 10 | +def setPropPath(Properties props, String prop, String path) { |
| 11 | + if (!file(path).isDirectory()) return |
| 12 | + if (props.hasProperty(prop)) return |
| 13 | + props[prop] = path |
| 14 | +} |
| 15 | + |
| 16 | +def propsPath = file("../local.properties") |
| 17 | +def props = new Properties() |
| 18 | + |
| 19 | +if (propsPath.isFile()) { |
| 20 | + props.load(new FileReader(propsPath)) |
| 21 | +} |
| 22 | + |
| 23 | +ext.hasAndroidSdk = false |
| 24 | +String newAndroidSdkPath = null |
| 25 | +if (props.containsKey("sdk.dir")) { |
| 26 | + ext.hasAndroidSdk = true |
| 27 | +} else if (pathExists(System.env.ANDROID_HOME)) { |
| 28 | + newAndroidSdkPath = System.env.ANDROID_HOME |
| 29 | +} else if (pathExists(System.env.ANDROID_SDK_ROOT)) { |
| 30 | + newAndroidSdkPath = System.env.ANDROID_SDK_ROOT |
| 31 | +} else if (pathExists(System.env.HOME + "/Android/Sdk")) { |
| 32 | + newAndroidSdkPath = System.env.HOME + "/Android/Sdk" |
| 33 | +} |
| 34 | + |
| 35 | +if (newAndroidSdkPath != null) { |
| 36 | + setPropPath(props, "sdk.dir", newAndroidSdkPath) |
| 37 | + |
| 38 | + def oldProps = new Properties(props) |
| 39 | + |
| 40 | + if (props != oldProps) { |
| 41 | + def writer = new FileWriter(propsPath) |
| 42 | + try { |
| 43 | + props.store(writer, "generated by 'detect-android-sdk.gradle'") |
| 44 | + } finally { |
| 45 | + writer.close() |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + ext.hasAndroidSdk = true |
| 50 | +} |
| 51 | + |
| 52 | +if (ext.hasAndroidSdk != true){ |
| 53 | + println '''\ |
| 54 | +[WARNING] Skipping build of Android related modules because Android SDK has not been found! |
| 55 | + Define Android SDK location in 'local.properties' file or with ANDROID_HOME |
| 56 | + environment variable to build Android modules |
| 57 | +''' |
| 58 | +} |
0 commit comments