Files
core/X2tConverter/test/androidTest/extra-builds/gradle/common.gradle
2018-11-28 15:37:24 +03:00

181 lines
5.3 KiB
Groovy

import java.text.DateFormat
import java.text.SimpleDateFormat
import org.apache.tools.ant.taskdefs.condition.Os
/*
* Create a variable called keystorePropertiesFile, and initialize it to your
* keystore.properties file, in the rootProject folder.
* Example of file content:
* storePassword=password
* keyPassword=password
* keyAlias=AliasInKeyStore
* storeFile=C:/example/MyAndroidKeys.jks
*/
def getKeyStoreProperties(String filePath) {
// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()
// You can place here passwords and path to keystore instead of file properties
keystoreProperties["keyAlias"] = "<YOUR_ALIAS>"
keystoreProperties["keyPassword"] = "<YOUR_PASSWORD>"
keystoreProperties["storeFile"] = "<PATH_TO_KEYSTORE_FILE>"
keystoreProperties["storePassword"] = "<KEYSTORE_PASSWORD>"
// Get file with properties
def keystorePropertiesFile = rootProject.file(filePath)
// File check to exist for success script building
if (keystorePropertiesFile.exists()) {
// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
} else {
def writer = new FileWriter(keystorePropertiesFile, false)
keystoreProperties.store(writer, "Google keystore file")
}
return keystoreProperties
}
def getBuildTimeMark() {
println "Get time mark..."
def date = new SimpleDateFormat("MMMMM.dd_HH-mm")
return date.format(new Date())
}
def getScriptExtensionOs() {
def scriptExt = Os.isFamily(Os.FAMILY_WINDOWS)? 'bat' : 'sh'
println "Script extension: $scriptExt"
return scriptExt
}
def getShellTypeOs() {
def shellType = Os.isFamily(Os.FAMILY_WINDOWS)? 'cmd' : 'sh'
println "Shell type: $shellType"
return shellType
}
def isUnixOs() {
return Os.isFamily(Os.FAMILY_UNIX);
}
def isWindowsOs() {
return Os.isFamily(Os.FAMILY_WINDOWS);
}
def getPathEnvOs(String path) {
return System.env.PATH + System.getProperty("path.separator") + path
}
def isFolderNotEmptyCheck(String path) {
def file = new File(path)
return file.exists() && file.isDirectory() && file.listFiles().length > 0
}
def getCmdArgsOs(String ... args) {
def argsList = []
if (args.length > 0) {
if (isWindowsOs()) {
argsList.add('cmd')
argsList.add('/c')
}
argsList.addAll(args)
}
println "Concatenated args: $args"
return argsList
}
def getBackSlashExt(String str) {
println "System path separator: $File.separator"
return str.replaceAll("\\\\", "/")
}
def findDirNameExt(String path, String name) {
def countFolders = 0
def nameFolder = ''
file(path).listFiles().each { it ->
if (it.isDirectory()) {
if (it.getName().contains(name)) {
nameFolder = it.getName()
++countFolders
}
}
}
return countFolders == 1? nameFolder : ''
}
def getHostNameExt() {
final String value = System.getProperty("os.name").toLowerCase();
println "System: ${value}"
if (value.contains("linux")) {
return ("linux");
} else if (value.contains("mac os x") || value.contains("darwin") || value.contains("osx")) {
return ("darwin");
} else if (value.contains("windows")) {
return ("windows");
}
throw new GradleException("UNKNOWN SYSTEM FOR ANDROID NDK: ${value}!")
}
def getHostArchExt() {
final String value = System.getProperty("os.arch");
println "Architecture: ${value}"
if ("x86" == value) {
return value
} else if ("amd64" == value || "x86_64" == value) {
return "x86_64"
}
throw new GradleException("UNKNOWN ARCHITECTRE FOR ANDROID NDK: ${value}!")
}
def getHostNameFullExt() {
return "${getHostNameExt()}-${getHostArchExt()}"
}
/*
* Add methods/values here for export
* */
ext {
// Global constants
project.ext.SDK_MIN = 21
project.ext.SUPPORT = '27.1.1'
// Extra path
// Args for cmake
project.ext.SRC_CORE = "$rootProject.rootDir/../../.."
project.ext.PATH_TO_NATIVE_BUILDS = getBackSlashExt("$rootProject.projectDir/extra-builds/native")
project.ext.PATH_TO_NATIVE_LIBS = "$project.ext.PATH_TO_NATIVE_BUILDS/libs"
project.ext.PATH_TO_NATIVE_ARCHS = "$project.ext.PATH_TO_NATIVE_BUILDS/libs.tar"
project.ext.PATH_TO_NATIVE_SRC = "$project.ext.PATH_TO_NATIVE_BUILDS/src"
project.ext.PATH_STANDALONE_DEST = "$project.ext.PATH_TO_NATIVE_BUILDS/toolchain"
project.ext.LIBS_PACK_NAME = "libs.tar"
project.ext.LIB_WRAPPER = "wrapper"
project.ext.LIB_CORE = "core"
// ABIs
project.ext.ABI_ARM = 'armeabi-v7a'
project.ext.ABI_ARM_64 = 'arm64-v8a'
project.ext.ABI_x86 = 'x86'
project.ext.ABI_x64 = 'x86_64'
// Global methods
getKeystore = this.&getKeyStoreProperties
getTimeMark = this.&getBuildTimeMark
getScriptExt = this.&getScriptExtensionOs
getShellType = this.&getShellTypeOs
isUnix = this.&isUnixOs
isWindows = this.&isWindowsOs
getCmdArgs = this.&getCmdArgsOs
getPathEnv = this.&getPathEnvOs
isFolderNotEmpty = this.&isFolderNotEmptyCheck
getBackSlash = this.&getBackSlashExt
findDirName = this.&findDirNameExt
getHostNameFull = this.&getHostNameFullExt
getHostName = this.&getHostNameExt
}