build.gradle 19.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2016 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

18
import com.badlogic.gdx.graphics.Texture
19 20
import com.badlogic.gdx.tools.texturepacker.TexturePacker

21 22
buildscript {
    repositories {
23 24 25
        maven   { url "http://repo1.maven.org/maven2" }
        maven   { url "https://jitpack.io" }
        jcenter { url "http://jcenter.bintray.com/" }
26 27
    }
    dependencies {
28
        classpath 'com.android.tools.build:gradle:2.2.3'
29
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.1'
30
        classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
31
        classpath 'com.novoda:gradle-android-command-plugin:1.3.0'
32
        classpath 'com.badlogicgames.gdx:gdx-tools:1.6.1'
33
        classpath 'edu.sc.seis.gradle:launch4j:2.3.0'
34 35 36
    }
}

37
final assetsDirName = "assets"
38 39
final assetsSourceDirName = "src"
final assetsDestinationDirName = "dest"
40

41 42 43
final assetsGameDirectory = "game"
final assetsGameGlobalDirectory = "_global"
final assetsGameCommonDifficultyDirectory = "common"
44
final assetsGameExcludedDirectory = "excluded"
45

46 47 48
final String TABLEXIA_GIT_PATH  = './'
final String MODEL_GIT_PATH     = 'core/external/'

49 50 51
System.setProperty("javax.net.ssl.trustStore", new File("${project(":android").projectDir.absolutePath}/assets/keystore/tablexiaTrustKeystore").getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "tablexia");

52
ext {
Matyáš Latner's avatar
Matyáš Latner committed
53
    assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
54
    assetsChecksum = [:]
55 56

    assetsPackDir = new File("${rootProject.buildDir}/${assetsDirName}/pack/")
57 58
}

59 60 61 62 63
allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    ext {
64
        appName = 'Tablexia'
65 66 67
        masterBranch = 'master'
        applicationBaseId = 'cz.nic.tablexia'
        tablexiaAppName = getTablexiaAppName()
68 69 70
        assetsDebugURLPart = onMaster() ? '' : 'debug/'
        assetsDownloadUrl = project.hasProperty("TABLEXIA_ASSETS_DOWNLOAD_URL") ? ("${TABLEXIA_ASSETS_DOWNLOAD_URL}/${assetsDebugURLPart}") : "<NO_URL_CONFIGURED>/"
        assetsUploadURL = (project.hasProperty("TABLEXIA_ASSETS_UPLOAD_USER") && project.hasProperty("TABLEXIA_ASSETS_UPLOAD_URL")) ? "${TABLEXIA_ASSETS_UPLOAD_USER}@${TABLEXIA_ASSETS_UPLOAD_URL}/${assetsDebugURLPart}" : "<NO_URL_CONFIGURED>/"
71 72
        serverFallbackHost = "<NO_SERVER_HOST>"
        serverHost = onMaster() ? getPropertyValueOrFallbackValue("TABLEXIA_SERVER_HOST_PRODUCTION", serverFallbackHost) : getPropertyValueOrFallbackValue("TABLEXIA_SERVER_HOST_DEBUG", serverFallbackHost)
73 74
        serverSecretFallback = "";
        serverSecret = onMaster() ? getPropertyValueOrFallbackValue("TABLEXIA_SERVER_SECRET_PRODUCTION", serverSecretFallback) : getPropertyValueOrFallbackValue("TABLEXIA_SERVER_SECRET_DEBUG", serverSecretFallback);
75 76 77 78
        tablexiaVersionName = getVersionNameFromGit(TABLEXIA_GIT_PATH)
        tablexiaVersionCode = getVersionCodeFromGit(TABLEXIA_GIT_PATH)
        tablexiaModelVersionName = getVersionNameFromGit(MODEL_GIT_PATH)
        tablexiaModelVersionCode = getVersionCodeFromGit(MODEL_GIT_PATH)
79 80
        applicationIdBranch = getTablexiaAppId()
        applicationIdRelease = applicationBaseId + applicationIdBranch
81 82
        applicationIdDebugSuffix = '.debug'
        applicationIdDebug = applicationIdRelease + applicationIdDebugSuffix
83 84
        applicationIdITestSuffix = '.itest'
        applicationIdITest = applicationIdRelease + applicationIdITestSuffix
85
        applicationIdDevelSuffix = '.devel'
86
        applicationIdDevel = applicationBaseId + applicationIdDevelSuffix
87

88 89
        //Fallback value if sentry DSN is not defined (gradle parameter SENTRY_DSN_DEBUG or SENTRY_DSN_RELEASE)
        sentryDSNFallbackValue = "None"
90
        sentryDSN = onMaster() ? getPropertyValueOrFallbackValue("TABLEXIA_SENTRY_DSN_RELEASE", sentryDSNFallbackValue) : getPropertyValueOrFallbackValue("TABLEXIA_SENTRY_DSN_DEBUG", sentryDSNFallbackValue)
91

92
        gdxVersion = '1.9.6'
93
		gdxUtilsVersion = '0.13.2'
94
	    mbassadorVersion = '1.2.0'
95
        roboVMVersion = '2.3.1'
96 97
        sqlDroidVersion = '1.0.3'
        sqlLiteJdbcVersion = '3.8.10.1'
98
        guavaVersion = '18.0'
99
        roboPodsVersion = '1.13.0'
100 101
        androidSupportV4Version = '22.0.0'
        googlePlayServicesVersion = '8.3.+'
102
        zxingVersion = '3.2.1'
103 104 105

        servletApiVersion = '5.5.23'
        ravenVersion = '7.5.0'
106 107
    }

108
    version = getVersionNameFromGit(TABLEXIA_GIT_PATH)
109

110
    repositories {
111 112 113 114
        maven   { url "http://repo1.maven.org/maven2" }
        jcenter { url "http://jcenter.bintray.com/" }
        maven   { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven   { url "https://oss.sonatype.org/content/repositories/releases/" }
115 116 117
    }
}

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
task clean << {
    delete "${buildDir}"
}

task prepareAssets {
    def sourceDir = new File(project(":core").projectDir.absolutePath + "/${assetsDirName}")

    inputs.dir(sourceDir.absolutePath)
    outputs.dir("${buildDir}/${assetsDirName}/${assetsSourceDirName}/")

    doLast {
        sourceDir.eachDir() { dir ->

            if (!dir.name.equals('common')) {
                String dirName = dir.getName()
                String destDir = "${buildDir}/${assetsDirName}/${assetsSourceDirName}/${dirName}"
                task("${name}_${dirName}", type: Copy) {
                    from sourceDir.absolutePath + "/common"
                    from dir.absolutePath
                    into destDir
                }.execute()
            }
        }
    }
}
143

144 145 146 147 148 149 150 151 152 153
task prepareSoundAssets(dependsOn: prepareAssets) {
    def assetsDir = new File("${buildDir}/${assetsDirName}/")

    inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
    outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")

    doLast {
        new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
            langDir.eachDir() { sectionDir ->
                sectionDir.eachDir() { atlasDir ->
154
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
155 156 157 158 159
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.mp3'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
160
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
161
                        }
162
                        outputs.upToDateWhen { false }
163 164 165 166 167 168 169
                    }.execute()
                }
            }
        }
    }
}

170 171 172 173 174 175 176 177 178 179
task prepareJsonAssets(dependsOn: prepareAssets) {
    def assetsDir = new File("${buildDir}/${assetsDirName}/")

    inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
    outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")

    doLast {
        new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
            langDir.eachDir() { sectionDir ->
                sectionDir.eachDir() { atlasDir ->
180
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
181 182 183 184 185
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.json'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
186
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
187
                        }
188
                        outputs.upToDateWhen { false }
189 190 191 192 193 194 195
                    }.execute()
                }
            }
        }
    }
}

196 197 198 199 200 201 202 203 204
task prepareGraphicAssets(dependsOn: prepareAssets) {
    def assetsDir = new File("${buildDir}/${assetsDirName}/")

    inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
    outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")

    doLast {
        TexturePacker.Settings settings = new TexturePacker.Settings();
        settings.pot = false;
205 206
        settings.maxWidth = 1024;
        settings.maxHeight = 1024;
207 208 209 210 211 212
        settings.combineSubdirectories = true;
        settings.filterMin = Texture.TextureFilter.Linear;
        settings.filterMag = Texture.TextureFilter.Linear;

        new File("${assetsDir.absolutePath}/${assetsSourceDirName}/").eachDir() { langDir ->
            langDir.eachDir() { sectionDir ->
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
                //If section dir has no dirs, copy whole content
                if (hasAtlasDir(sectionDir)) {
                    sectionDir.eachDir() { atlasDir ->
                        if (assetsGameDirectory.equals(sectionDir.name) && !assetsGameGlobalDirectory.equals(atlasDir.name)) {
                            atlasDir.eachDir() { difficultyDir ->
                                if (!assetsGameExcludedDirectory.equals(difficultyDir.name)) {
                                    String packFileName = assetsGameCommonDifficultyDirectory.equals(difficultyDir.name) ? atlasDir.name : difficultyDir.name;
                                    TexturePacker.process(settings,
                                            "${difficultyDir}",
                                            "${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
                                            "${packFileName}")
                                } else {
                                    task("${name}_" + sectionDir.name + "_" + langDir.name + "_" + atlasDir.name + "_" + difficultyDir.name, type: Copy) {
                                        from difficultyDir
                                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/${difficultyDir.name}"
                                        include '**/*'
                                        includeEmptyDirs false
                                        outputs.upToDateWhen { false }
                                    }.execute()
                                }
233
                            }
234 235 236 237 238
                        } else {
                            TexturePacker.process(settings,
                                    "${atlasDir}",
                                    "${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
                                    "${atlasDir.name}")
239 240
                        }
                    }
241 242 243 244 245 246 247 248
                } else {
                    task("${name}_" + sectionDir.name + "_" + langDir.name, type: Copy) {
                        from sectionDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}"
                        include '**/*'
                        includeEmptyDirs false
                        outputs.upToDateWhen { false }
                    }.execute()
249 250 251 252 253 254
                }
            }
        }
    }
}

255 256 257 258 259 260 261
def hasAtlasDir(File file) {
    for(File f : file.listFiles()) {
        if(f.isDirectory()) return true;
    }
    return false;
}

262
task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJsonAssets]) {
263 264 265 266 267
    doLast {
        new File(project(":core").projectDir.absolutePath + "/${assetsDirName}").eachDir() { dir ->

            if (!dir.name.equals('common')) {
                task("${name}_${dir.name}", type: Zip) {
268
                    archiveName = dir.getName() + "_SNAPSHOT.zip"
269
                    destinationDir = rootProject.ext.assetsPackDir
270 271
                    from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
                }.execute()
272 273 274 275 276
            }
        }
    }
}

277
task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum']) {
278
    doLast {
279 280
        if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD).booleanValue()) {
            def data = new URL(project.assetsDownloadUrl).getText()
281 282 283 284 285
            rootProject.ext.assetsPackDir.eachFile() { file ->
                String fileName = file.getName()
                String[] fileNameParts = fileName.split("_SNAPSHOT\\.");
                String packageName = "${fileNameParts[0]}_${assetsChecksum[fileNameParts[0]]}.${fileNameParts[1]}";

286 287 288
                if (!data.contains(packageName)) {
                    String assetsUploadPath = "${project.assetsUploadURL}${packageName}"
                    println "AssetsUploader: UPLOADING FILE: ${project.assetsDebugURLPart}${packageName}"
289 290
                    task ("${name}_${packageName}", type:Exec) {
                        workingDir "${rootProject.projectDir}"
291
                        commandLine 'scp', file.getAbsolutePath(), assetsUploadPath
292 293 294 295 296 297
                        standardOutput = new ByteArrayOutputStream()
                        ext.output = {
                            return standardOutput.toString()
                        }
                    }.execute()
                } else {
298
                    println "AssetsUploader: FILE: ${project.assetsDebugURLPart}${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
299
                }
300
            }
301 302
        } else {
            println "ASSETS UPLOAD NOT CONFIGURED -> SKIPPING UPLOAD"
303 304 305 306
        }
    }
}

307 308 309 310 311 312 313 314 315 316
task unlockIOSKeyChain() << {
    if (project.hasProperty('TABLEXIA_KEYCHAIN_USER') && project.hasProperty('TABLEXIA_KEYCHAIN_PATH')) {
        exec {
            commandLine  'security', 'unlock-keychain', '-p', TABLEXIA_KEYCHAIN_USER, TABLEXIA_KEYCHAIN_PATH
        }
    } else {
        println "CANNOT UNLOCK KEYCHAIN -> TABLEXIA_KEYCHAIN_USER OR TABLEXIA_KEYCHAIN_PATH BUILD VARIABLE IS NOT SET!"
    }
}

317 318 319 320
def getPropertyValueOrFallbackValue(String key, String fallbackValue) {
    return project.hasProperty(key) ? project.getProperties().get(key) : fallbackValue
}

321
def getTablexiaAppName() {
322
    if (onMaster()) {
323 324
        return "${project.appName}"
    } else {
325
        return "${project.appName} (${getBranchNameFromGit()})"
326 327 328 329
    }
}

def getTablexiaAppId() {
330
    if (onMaster()) {
331 332
        return ""
    } else {
333
        return ".${getBranchNameFromGit().trim().replaceAll('-', '').replaceAll('\\.', '').toLowerCase()}"
334 335 336
    }
}

337
def getVersionNameFromGit(String relativePath) {
338
    def stdout = new ByteArrayOutputStream()
339 340

    // get last tag in current branch
341
    exec {
342
        workingDir relativePath
Matyáš Latner's avatar
Matyáš Latner committed
343
        commandLine 'git', 'describe', '--abbrev=0', '--tags', '--always'
344 345
        standardOutput = stdout
    }
346 347 348
    String result = stdout.toString().trim();

    // for non release branches add number of commits and branch name
349
    if (!onMaster()) {
350 351
        stdout = new ByteArrayOutputStream()
        exec {
352
            workingDir relativePath
353
            commandLine 'git', 'rev-list', "${result}..HEAD", '--count'
354 355 356 357
            standardOutput = stdout
        }
        String numberOfCommits = stdout.toString().trim()

358
        if (!"0".equals(numberOfCommits)) {
359
            // add branch name and number of commits
360
            result = "${result}-${numberOfCommits}"
361 362 363
        }
    }
    return result
364 365
}

366
def getVersionCodeFromGit(String relativePath) {
367 368
    def stdout = new ByteArrayOutputStream()
    exec {
369
        workingDir relativePath
370 371 372 373 374 375
        commandLine 'git', 'log', '-1', '--format=%at'
        standardOutput = stdout
    }
    return stdout.toString().trim().toInteger()
}

376
def getBranchNameFromGit() {
377 378
    def stdout = new ByteArrayOutputStream()
    exec {
Matyáš Latner's avatar
Matyáš Latner committed
379
        commandLine  'git', 'describe', '--contains', '--all', 'HEAD', '--always'
380 381
        standardOutput = stdout
    }
382 383
    String branchString = stdout.toString().trim()
    return branchString.contains("/") ? branchString.substring(branchString.lastIndexOf("/") + 1) : branchString
384 385
}

386 387 388 389
boolean onMaster() {
    return project.masterBranch.equals(getBranchNameFromGit());
}

390 391 392 393 394 395 396 397 398
def getMapConvertedToString(Map map) {
    String result = "";
    map.each { key, value ->
        if (result.size() > 0) result = result + ","
        result = result + "$key:$value"
    }
    return result;
}

399 400 401 402 403 404 405 406 407
project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
408 409
	    compile "net.engio:mbassador:$mbassadorVersion"
        compile "com.jcabi:jcabi-manifests:1.1"
410
        compile "org.xerial:sqlite-jdbc:$sqlLiteJdbcVersion"
411 412 413 414
    }
}

project(":android") {
415
    apply plugin: 'android-sdk-manager'
416
    apply plugin: 'com.android.application'
417
    apply plugin: 'android-command'
418 419 420 421 422

    configurations { natives }

    dependencies {
        compile project(":core")
423

424
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
425
	    compile "net.engio:mbassador:$mbassadorVersion"
426
        compile "org.sqldroid:sqldroid:$sqlDroidVersion"
427 428 429 430 431 432 433 434 435 436 437 438 439 440
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    }
}

project(":ios") {
    apply plugin: "java"
    apply plugin: "robovm"

    configurations { natives }

    dependencies {
        compile project(":core")
441 442
        compile "com.mobidevelop.robovm:robovm-rt:${roboVMVersion}"
        compile "com.mobidevelop.robovm:robovm-cocoatouch:${roboVMVersion}"
443
	    compile "net.engio:mbassador:$mbassadorVersion"
444
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
Matyáš Latner's avatar
Matyáš Latner committed
445
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
446 447 448 449 450 451
    }
}

project(":core") {
    apply plugin: "java"

452
    sourceSets.test.java.srcDirs = ["test/"]
453
	tasks.processResources.dependsOn processAssets
454 455

    dependencies {
456
        compile project(":util:checksum")
457
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
458
		compile "net.dermetfan.libgdx-utils:libgdx-utils:$gdxUtilsVersion"
459
	    compile "net.engio:mbassador:$mbassadorVersion"
460
        compile "com.google.guava:guava:$guavaVersion"
Vitaliy Vashchenko's avatar
Vitaliy Vashchenko committed
461
        compile "com.google.zxing:core:$zxingVersion"
462

463

464 465
        compile "tomcat:servlet-api:$servletApiVersion"
        compile "com.getsentry.raven:raven:$ravenVersion"
466

467
        testCompile "junit:junit:4.11"
468 469 470
		testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"               
        testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"                                
        testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
471 472 473
    }
}

Matyáš Latner's avatar
Matyáš Latner committed
474 475 476 477 478 479 480 481
project(":itest") {
    apply plugin: "java"

    dependencies {
        compile project(':core')
    }
}

482 483
tasks.eclipse.doLast {
    delete ".project"
484
}