1
0
Fork 0
tt9/build.gradle

160 lines
4.4 KiB
Groovy

buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
}
}
apply plugin: 'com.android.application'
dependencies {
implementation "androidx.core:core:1.6.0"
implementation 'androidx.preference:preference:1.1.1'
implementation "androidx.room:room-runtime:2.1.0"
annotationProcessor "androidx.room:room-compiler:2.1.0"
}
repositories {
mavenCentral()
google()
}
def execThing ( String cmdStr ) {
def stdout = new ByteArrayOutputStream()
String prefix = System.getenv("GITCMDPREFIX")
if (prefix != null) {
String cmd = prefix + cmdStr
exec {
commandLine cmd.tokenize()
standardOutput = stdout
}
} else {
exec {
commandLine cmdStr.tokenize()
standardOutput = stdout
}
}
return stdout.toString().trim()
}
def computeVersionCode = { ->
String commitsCount = execThing("git rev-list --count HEAD")
return Integer.valueOf(commitsCount)
}
def computeVersionName = { ->
// major version
String versionTagsCount = execThing('git tag --list v*').split('\n').size()
// minor version
String lastVersionTag = execThing('git describe --match v* --tags --abbrev=0')
String gitLogResult = execThing("git log $lastVersionTag..HEAD --oneline")
String commitsSinceLastTag = gitLogResult == '' ? "0" : gitLogResult.split('\n').size()
// the commit we are building from
String currentHash = execThing('git log -1 --format=%h')
// beta string, if this is a beta
String lastTagName = execThing('git describe --tags --abbrev=0')
String lastTagHash = execThing("git log -1 --format=%h $lastTagName")
String betaString = lastTagHash == currentHash && lastTagName.contains("beta") ? '-beta' : ''
return "$versionTagsCount.$commitsSinceLastTag$betaString ($currentHash)"
}
android {
compileSdkVersion 30
buildToolsVersion "32.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
minSdkVersion 19
targetSdk 30
versionCode computeVersionCode()
versionName computeVersionName()
}
// http://stackoverflow.com/a/19130098
// signingConfigs {
// release {
// storeFile file(System.getenv("KEYSTORE"))
// storePassword System.getenv("KEYSTORE_PASS")
// keyAlias System.getenv("KEYALIAS")
// keyPassword System.getenv("KEYALIAS_PASS")
// }
// }
//
// buildTypes {
// release {
// signingConfig android.signingConfigs.release
// }
// }
}
task validateDictionaries {
inputs.dir fileTree(dir:'assets', excludes:['dict.properties'])
outputs.file "t9build.properties"
doLast {
String errors = ""
inputs.getFiles().each {File file ->
println "Validating dictionary: " + file.name
def geographicalName = ~"[A-Z]\\w+-[^\\n]+"
def uniqueWords = [:]
int lineNumber = 0
file.eachLine {line ->
lineNumber++
if (line.matches("\\d")) {
errors += "Dictionary '" + file.name + "' is invalid. Found numbers on line " + lineNumber + ". Please, remove all numbers.\n"
}
if (line.matches("^\\P{L}+\$")) {
errors += "Dictionary '" + file.name + "' is invalid. Found a garbage word: '" + line + "' on line " + lineNumber + ".\n"
}
if (line.matches("^.\$")) {
errors += "Dictionary '" + file.name + "' is invalid. Found a single letter: '" + line + "' on line " + lineNumber + ". Remove all single letters. The alphabet will be added automatically.\n"
}
String uniqueWordKey = line ==~ geographicalName ? line : line.toLowerCase()
if (uniqueWords[uniqueWordKey] != null && uniqueWords[uniqueWordKey] == true) {
errors += "Dictionary '" + file.name + "' is invalid. Found a repeating word: '" + line + "' on line " + lineNumber + ". Ensure all words appear only once.\n"
} else {
uniqueWords[uniqueWordKey] = true
}
}
}
if (errors != "") {
throw new GradleException(errors)
}
}
}
preBuild.dependsOn validateDictionaries
preBuild.mustRunAfter validateDictionaries