build.gradle 30.3 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
        maven   { url "http://repo1.maven.org/maven2" }
        maven   { url "https://jitpack.io" }
25
        maven   { url "https://plugins.gradle.org/m2/" }
26
        jcenter { url "http://jcenter.bintray.com/" }
27 28
    }
    dependencies {
29
        classpath 'com.android.tools.build:gradle:2.2.3'
30
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.1'
31
        classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
32
        classpath 'com.novoda:gradle-android-command-plugin:1.3.0'
33
        classpath 'com.badlogicgames.gdx:gdx-tools:1.6.1'
34
        classpath 'edu.sc.seis.gradle:launch4j:2.3.0'
35
        classpath "gradle.plugin.edu.sc.seis:macAppBundle:2.1.9"
36 37 38
    }
}

39
final assetsDirName = "assets"
40 41
final assetsSourceDirName = "src"
final assetsDestinationDirName = "dest"
42

43 44
final assetsHdDirName = "hd"

45 46 47
final assetsGameDirectory = "game"
final assetsGameGlobalDirectory = "_global"
final assetsGameCommonDifficultyDirectory = "common"
48
final assetsGameExcludedDirectory = "excluded"
49

50 51 52
final String TABLEXIA_GIT_PATH  = './'
final String MODEL_GIT_PATH     = 'core/external/'

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

56
ext {
Matyáš Latner's avatar
Matyáš Latner committed
57
    assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
58
    assetsChecksum = [:]
59 60
    assetsHdChecksum = [:]

61 62

    assetsPackDir = new File("${rootProject.buildDir}/${assetsDirName}/pack/")
63
    assetsHdPackDir = new File("${rootProject.buildDir}/${assetsDirName}/${assetsHdDirName}/pack/")
64 65
}

66 67 68 69 70
allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    ext {
71
        appName = 'Tablexia'
72 73 74
        masterBranch = 'master'
        applicationBaseId = 'cz.nic.tablexia'
        tablexiaAppName = getTablexiaAppName()
75
        assetsDebugURLPart = isReleaseBuild() ? '' : 'debug/'
76 77
        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>/"
78
        serverFallbackHost = "<NO_SERVER_HOST>"
79 80 81
        serverHost = isReleaseBuild() ? getPropertyValueOrFallbackValue("TABLEXIA_SERVER_HOST_PRODUCTION", serverFallbackHost) : getPropertyValueOrFallbackValue("TABLEXIA_SERVER_HOST_DEBUG", serverFallbackHost)
        serverSecretFallback = ""
        serverSecret = isReleaseBuild() ? getPropertyValueOrFallbackValue("TABLEXIA_SERVER_SECRET_PRODUCTION", serverSecretFallback) : getPropertyValueOrFallbackValue("TABLEXIA_SERVER_SECRET_DEBUG", serverSecretFallback);
82 83 84 85
        tablexiaVersionName = getVersionNameFromGit(TABLEXIA_GIT_PATH)
        tablexiaVersionCode = getVersionCodeFromGit(TABLEXIA_GIT_PATH)
        tablexiaModelVersionName = getVersionNameFromGit(MODEL_GIT_PATH)
        tablexiaModelVersionCode = getVersionCodeFromGit(MODEL_GIT_PATH)
86 87
        applicationIdBranch = getTablexiaAppId()
        applicationIdRelease = applicationBaseId + applicationIdBranch
88 89
        applicationIdDebugSuffix = '.debug'
        applicationIdDebug = applicationIdRelease + applicationIdDebugSuffix
90 91
        applicationIdITestSuffix = '.itest'
        applicationIdITest = applicationIdRelease + applicationIdITestSuffix
92
        applicationIdDevelSuffix = '.devel'
93
        applicationIdDevel = applicationBaseId + applicationIdDevelSuffix
94

95 96
        //Fallback value if sentry DSN is not defined (gradle parameter SENTRY_DSN_DEBUG or SENTRY_DSN_RELEASE)
        sentryDSNFallbackValue = "None"
97
        sentryDSN = isReleaseBuild() ? getPropertyValueOrFallbackValue("TABLEXIA_SENTRY_DSN_RELEASE", sentryDSNFallbackValue) : getPropertyValueOrFallbackValue("TABLEXIA_SENTRY_DSN_DEBUG", sentryDSNFallbackValue)
98

99
        gdxVersion = '1.9.8'
100
		gdxUtilsVersion = '0.13.2'
101
	    mbassadorVersion = '1.2.0'
102
        roboVMVersion = '2.3.1'
103 104
        sqlDroidVersion = '1.0.3'
        sqlLiteJdbcVersion = '3.8.10.1'
105
        guavaVersion = '18.0'
106
        roboPodsVersion = '1.13.0'
107 108
        androidSupportV4Version = '22.0.0'
        googlePlayServicesVersion = '8.3.+'
109
        zxingVersion = '3.2.1'
110 111 112

        servletApiVersion = '5.5.23'
        ravenVersion = '7.5.0'
113 114
    }

115
    version = getVersionNameFromGit(TABLEXIA_GIT_PATH)
116

117
    repositories {
118 119 120 121
        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/" }
122 123 124
    }
}

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
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()
            }
        }
    }
}
150

151

152 153 154 155 156 157 158 159 160 161
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 ->
162
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
163 164 165 166 167
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.mp3'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
168
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
169
                        }
170
                        outputs.upToDateWhen { false }
171 172 173 174 175 176 177
                    }.execute()
                }
            }
        }
    }
}

178 179 180 181 182 183 184 185 186 187
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 ->
188
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
189 190 191 192 193
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.json'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
194
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
195
                        }
196
                        outputs.upToDateWhen { false }
197 198 199 200 201 202 203
                    }.execute()
                }
            }
        }
    }
}

204

205
task prepareHdAssets(dependsOn: prepareAssets) {
206
    def sourceDir = new File("${buildDir}/${assetsDirName}/src/")
207
    def assetsDir = new File("${buildDir}/${assetsDirName}/")
208
    def hdSourceDir = new File(project(":desktop").projectDir.absolutePath + "/${assetsDirName}/${assetsHdDirName}")
209 210


211
    inputs.dir(hdSourceDir.absolutePath)
212
    inputs.dir(sourceDir.absolutePath)
213
    outputs.dir("${buildDir}/${assetsDirName}/${assetsHdDirName}/${assetsSourceDirName}/")
214 215

    doLast {
216
        if (project.hasProperty('TABLEXIA_HD_ASSETS') && Boolean.valueOf(project.property('TABLEXIA_HD_ASSETS')).booleanValue()) {
217

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
            new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
                langDir.eachDir() { sectionDir ->
                    sectionDir.eachDir() { atlasDir ->
                        task("${name}_sounds_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
                            from atlasDir
                            into "${buildDir}/${assetsDirName}/${assetsHdDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                            include '**/*.mp3', '**/*.json'
                            includeEmptyDirs false
                            eachFile { FileCopyDetails fcd ->
                                fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
                            }
                            outputs.upToDateWhen { false }
                        }.execute()
                    }
                }
            }
234 235 236 237 238

            sourceDir.eachDir() { dir ->

                if (!dir.name.equals('common')) {
                    String dirName = dir.getName()
239
                    String destDir = "${buildDir}/${assetsDirName}/${assetsHdDirName}/${assetsSourceDirName}/${dirName}"
240 241
                    task("${name}_${dirName}", type: Copy) {
                        from dir.absolutePath
242
                        from hdSourceDir.absolutePath + "/common"
243 244 245 246 247 248 249 250 251 252 253
                        from hdSourceDir.absolutePath + "/" + dirName
                        into destDir
                    }.execute()
                }
            }
        } else {
            println "HD PACK IS NOT REQUESTED"
        }
    }
}

254 255 256 257 258 259 260 261 262
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;
263 264
        settings.maxWidth = 1024;
        settings.maxHeight = 1024;
265 266 267 268 269 270
        settings.combineSubdirectories = true;
        settings.filterMin = Texture.TextureFilter.Linear;
        settings.filterMag = Texture.TextureFilter.Linear;

        new File("${assetsDir.absolutePath}/${assetsSourceDirName}/").eachDir() { langDir ->
            langDir.eachDir() { sectionDir ->
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
                //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()
                                }
291
                            }
292 293 294 295 296
                        } else {
                            TexturePacker.process(settings,
                                    "${atlasDir}",
                                    "${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
                                    "${atlasDir.name}")
297 298
                        }
                    }
299 300 301 302 303 304 305 306
                } 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()
307 308 309 310
                }
            }
        }

311
        //optimizing for uploading
312
        if (project.hasProperty('TABLEXIA_ASSETS_OPTIMIZE') && Boolean.valueOf(TABLEXIA_ASSETS_OPTIMIZE).booleanValue()) {
313 314
            println "ASSETS OPTIMIZATION: ENABLED."
            println "ASSETS OPTIMIZATION: START."
315 316
            new File("${assetsDir.absolutePath}/${assetsDestinationDirName}/").eachDir() { dir ->
                dir.eachFileRecurse() { file ->
317
                    if (file.name.endsWith(".png") && !file.absolutePath.contains("excluded") && !file.name.contains("clickmap")) {
318
                        println "Optimizing: ${file.name}"
319
                        exec {
320
                            commandLine 'pngquant', '--ext', '.png', '--nofs', '-f', 256, file.absolutePath
321 322 323 324
                        }
                    }
                }
            }
325
            println "ASSETS OPTIMIZATION: FINISH."
326
        } else {
327
            println "ASSETS OPTIMIZATION NOT CONFIGURED -> SKIPPING OPTIMIZATION"
328
        }
329 330
    }
}
331

332 333 334 335 336 337 338 339 340
def hasAtlasDir(File file) {
    for(File f : file.listFiles()) {
        if(f.isDirectory()) return true;
    }
    return false;
}

task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJsonAssets]) {
    doLast {
341 342 343 344
        new File(project(":core").projectDir.absolutePath + "/${assetsDirName}").eachDir() { dir ->

            if (!dir.name.equals('common')) {
                task("${name}_${dir.name}", type: Zip) {
345
                    archiveName = dir.getName() + "_SNAPSHOT.zip"
346
                    destinationDir = rootProject.ext.assetsPackDir
347 348
                    from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
                }.execute()
349 350 351 352 353
            }
        }
    }
}

354
task prepareHdGraphicAssets(dependsOn: prepareHdAssets) {
355
    def assetsDir = new File("${buildDir}/${assetsDirName}/${assetsHdDirName}/")
356

357 358
    inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
    outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")
359 360

    doLast {
361
        if (project.hasProperty('TABLEXIA_HD_ASSETS') && Boolean.valueOf(project.property('TABLEXIA_HD_ASSETS')).booleanValue()) {
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
            TexturePacker.Settings settings = new TexturePacker.Settings();
            settings.pot = false;
            settings.maxWidth = 2048;
            settings.maxHeight = 2048;
            settings.combineSubdirectories = true;
            settings.filterMin = Texture.TextureFilter.Linear;
            settings.filterMag = Texture.TextureFilter.Linear;

            new File("${assetsDir.absolutePath}/${assetsSourceDirName}/").eachDir() { langDir ->
                langDir.eachDir() { sectionDir ->
                    //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
386
                                            into "${buildDir}/${assetsDirName}/${assetsHdDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/${difficultyDir.name}"
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
                                            include '**/*'
                                            includeEmptyDirs false
                                            outputs.upToDateWhen { false }
                                        }.execute()
                                    }
                                }
                            } else {
                                TexturePacker.process(settings,
                                        "${atlasDir}",
                                        "${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
                                        "${atlasDir.name}")
                            }
                        }
                    } else {
                        task("${name}_" + sectionDir.name + "_" + langDir.name, type: Copy) {
                            from sectionDir
403
                            into "${buildDir}/${assetsDirName}/${assetsHdDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}"
404 405 406 407 408 409
                            include '**/*'
                            includeEmptyDirs false
                            outputs.upToDateWhen { false }
                        }.execute()
                    }
                }
410 411 412 413 414 415 416
            }        //optimizing for uploading
            if (project.hasProperty('TABLEXIA_ASSETS_OPTIMIZE') && Boolean.valueOf(TABLEXIA_ASSETS_OPTIMIZE).booleanValue()) {
                println "HD ASSETS OPTIMIZATION: ENABLED."
                println "HD ASSETS OPTIMIZATION: START."
                new File("${assetsDir.absolutePath}/${assetsDestinationDirName}/").eachDir() { dir ->
                    dir.eachFileRecurse() { file ->
                        if (file.name.endsWith(".png") && !file.absolutePath.contains("excluded")) {
417
                            println "Optimizing: ${file.name}"
418
                            exec {
419
                                commandLine 'pngquant', '--ext', '.png', '--nofs', '-f', 256, file.absolutePath
420 421 422 423 424 425 426
                            }
                        }
                    }
                }
                println "HD ASSETS OPTIMIZATION: FINISH."
            } else {
                println "ASSETS OPTIMIZATION NOT CONFIGURED -> SKIPPING OPTIMIZATION"
427 428 429 430 431 432 433 434 435
            }
        } else {
            println "HD PACK IS NOT REQUESTED"
        }
    }
}

task zipHdAssets(dependsOn: prepareHdGraphicAssets) {
    doLast {
436
        if (project.hasProperty('TABLEXIA_HD_ASSETS') && Boolean.valueOf(project.property('TABLEXIA_HD_ASSETS')).booleanValue()) {
437 438 439 440
            new File(project(":core").projectDir.absolutePath + "/${assetsDirName}/").eachDir() { dir ->

                if (!dir.name.equals('common')) {
                    task("${name}_${dir.name}", type: Zip) {
441
                        archiveName = dir.getName() + "_SNAPSHOT_HD.zip"
442
                        destinationDir = rootProject.ext.assetsHdPackDir
443
                        from "${buildDir}/${assetsDirName}/${assetsHdDirName}/${assetsDestinationDirName}/${dir.name}"
444 445 446 447 448 449 450 451 452
                    }.execute()
                }
            }
        } else {
            println "HD PACK IS NOT REQUESTED"
        }
    }
}

453
task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum']) {
454
    doLast {
455
        if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD') && Boolean.valueOf(project.property('TABLEXIA_ASSETS_UPLOAD')).booleanValue()) {
456
            def data = new URL(project.assetsDownloadUrl).getText()
457 458 459 460 461
            rootProject.ext.assetsPackDir.eachFile() { file ->
                String fileName = file.getName()
                String[] fileNameParts = fileName.split("_SNAPSHOT\\.");
                String packageName = "${fileNameParts[0]}_${assetsChecksum[fileNameParts[0]]}.${fileNameParts[1]}";

462 463 464
                if (!data.contains(packageName)) {
                    String assetsUploadPath = "${project.assetsUploadURL}${packageName}"
                    println "AssetsUploader: UPLOADING FILE: ${project.assetsDebugURLPart}${packageName}"
465 466
                    task ("${name}_${packageName}", type:Exec) {
                        workingDir "${rootProject.projectDir}"
467
                        commandLine 'scp', file.getAbsolutePath(), assetsUploadPath
468 469 470 471 472 473
                        standardOutput = new ByteArrayOutputStream()
                        ext.output = {
                            return standardOutput.toString()
                        }
                    }.execute()
                } else {
474
                    println "AssetsUploader: FILE: ${project.assetsDebugURLPart}${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
475
                }
476
            }
477 478
        } else {
            println "ASSETS UPLOAD NOT CONFIGURED -> SKIPPING UPLOAD"
479 480 481 482
        }
    }
}

483 484 485
task prepareHdPack(dependsOn: [':util:checksum:runHdChecksum', ':util:checksum:runHdAssetsArchivesChecksum']) {
    doLast {
        //prepare and upload hd packs
486 487 488 489
        if (project.hasProperty('TABLEXIA_HD_ASSETS') &&
                project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') &&
                project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL') &&
                project.hasProperty('TABLEXIA_ASSETS_UPLOAD') &&
490 491
                Boolean.valueOf(project.property('TABLEXIA_ASSETS_UPLOAD')).booleanValue() &&
                Boolean.valueOf(project.property('TABLEXIA_HD_ASSETS')).booleanValue()) {
492

493 494 495
            def data = new URL(project.assetsDownloadUrl).getText()
            rootProject.ext.assetsHdPackDir.eachFile() { file ->
                String fileName = file.getName()
496
                String[] fileNameParts = fileName.split("_SNAPSHOT");
497
                String packageName = "${fileNameParts[0]}_${assetsHdChecksum[fileNameParts[0]]}${fileNameParts[1]}";
498 499

                if (!data.contains(packageName)) {
500
                    String assetsUploadPath = "${project.assetsUploadURL}${packageName}"
501
                    println "AssetsUploader: UPLOADING FILE: ${project.assetsDebugURLPart}${packageName}"
502
                    task("${name}_${packageName}", type: Exec) {
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
                        workingDir "${rootProject.projectDir}"
                        commandLine 'scp', file.getAbsolutePath(), assetsUploadPath
                        standardOutput = new ByteArrayOutputStream()
                        ext.output = {
                            return standardOutput.toString()
                        }
                    }.execute()
                } else {
                    println "AssetsUploader: FILE: ${project.assetsDebugURLPart}${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
                }
            }
        } else {
            println "ASSETS UPLOAD NOT CONFIGURED -> SKIPPING UPLOAD"
        }
    }
}

520 521 522 523 524 525 526 527 528 529
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!"
    }
}

530 531 532 533
def getPropertyValueOrFallbackValue(String key, String fallbackValue) {
    return project.hasProperty(key) ? project.getProperties().get(key) : fallbackValue
}

534
def getTablexiaAppName() {
535
    if (isReleaseBuild()) {
536 537
        return "${project.appName}"
    } else {
538
        return "${project.appName} (${getBranchNameFromGit()})"
539 540 541 542
    }
}

def getTablexiaAppId() {
543
    if (isReleaseBuild()) {
544 545
        return ""
    } else {
546
        return ".${getBranchNameFromGit().trim().replaceAll('-', '').replaceAll('\\.', '').replaceAll('\\d', '').toLowerCase()}"
547 548 549
    }
}

550
def getVersionNameFromGit(String relativePath) {
551
    def stdout = new ByteArrayOutputStream()
552 553

    // get last tag in current branch
554
    exec {
555
        workingDir relativePath
Matyáš Latner's avatar
Matyáš Latner committed
556
        commandLine 'git', 'describe', '--abbrev=0', '--tags', '--always'
557 558
        standardOutput = stdout
    }
559 560 561
    String result = stdout.toString().trim();

    // for non release branches add number of commits and branch name
562
    if (!isReleaseBuild()) {
563 564
        stdout = new ByteArrayOutputStream()
        exec {
565
            workingDir relativePath
566
            commandLine 'git', 'rev-list', "${result}..HEAD", '--count'
567 568 569 570
            standardOutput = stdout
        }
        String numberOfCommits = stdout.toString().trim()

571
        if (!"0".equals(numberOfCommits)) {
572
            // add branch name and number of commits
573
            result = "${result}-${numberOfCommits}"
574 575 576
        }
    }
    return result
577 578
}

579
def getVersionCodeFromGit(String relativePath) {
580 581
    def stdout = new ByteArrayOutputStream()
    exec {
582
        workingDir relativePath
583 584 585 586 587 588
        commandLine 'git', 'log', '-1', '--format=%at'
        standardOutput = stdout
    }
    return stdout.toString().trim().toInteger()
}

589
def getBranchNameFromGit() {
590 591
    def stdout = new ByteArrayOutputStream()
    exec {
Matyáš Latner's avatar
Matyáš Latner committed
592
        commandLine  'git', 'describe', '--contains', '--all', 'HEAD', '--always'
593 594
        standardOutput = stdout
    }
595 596
    String branchString = stdout.toString().trim()
    return branchString.contains("/") ? branchString.substring(branchString.lastIndexOf("/") + 1) : branchString
597 598
}

599
boolean isReleaseBuild() {
600
    return project.hasProperty('TABLEXIA_RELEASE_BUILD') && Boolean.valueOf(project.property('TABLEXIA_RELEASE_BUILD')).booleanValue()
601 602
}

603 604 605 606 607 608 609 610 611
def getMapConvertedToString(Map map) {
    String result = "";
    map.each { key, value ->
        if (result.size() > 0) result = result + ","
        result = result + "$key:$value"
    }
    return result;
}

612 613 614
project(":desktop") {
    apply plugin: "java"

615
    tasks.processResources.dependsOn prepareHdPack
616 617 618 619 620 621

    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"
622 623
	    compile "net.engio:mbassador:$mbassadorVersion"
        compile "com.jcabi:jcabi-manifests:1.1"
624
        compile "org.xerial:sqlite-jdbc:$sqlLiteJdbcVersion"
625 626 627 628
    }
}

project(":android") {
629
    apply plugin: 'android-sdk-manager'
630
    apply plugin: 'com.android.application'
631
    apply plugin: 'android-command'
632 633 634 635 636

    configurations { natives }

    dependencies {
        compile project(":core")
637

638
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
639
	    compile "net.engio:mbassador:$mbassadorVersion"
640
        compile "org.sqldroid:sqldroid:$sqlDroidVersion"
641 642 643 644 645 646 647 648 649 650 651 652 653 654
        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")
655 656
        compile "com.mobidevelop.robovm:robovm-rt:${roboVMVersion}"
        compile "com.mobidevelop.robovm:robovm-cocoatouch:${roboVMVersion}"
657
	    compile "net.engio:mbassador:$mbassadorVersion"
658
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
Matyáš Latner's avatar
Matyáš Latner committed
659
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
660 661 662 663 664 665
    }
}

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

666
    sourceSets.test.java.srcDirs = ["test/"]
667
	tasks.processResources.dependsOn processAssets
668 669

    dependencies {
670
        compile project(":util:checksum")
671
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
672
		compile "net.dermetfan.libgdx-utils:libgdx-utils:$gdxUtilsVersion"
673
	    compile "net.engio:mbassador:$mbassadorVersion"
674
        compile "com.google.guava:guava:$guavaVersion"
Vitaliy Vashchenko's avatar
Vitaliy Vashchenko committed
675
        compile "com.google.zxing:core:$zxingVersion"
676

677

678 679
        compile "tomcat:servlet-api:$servletApiVersion"
        compile "com.getsentry.raven:raven:$ravenVersion"
680

681
        testCompile "junit:junit:4.11"
682 683
		testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
        testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
684
        testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
685 686 687
    }
}

Matyáš Latner's avatar
Matyáš Latner committed
688 689 690 691 692 693 694 695
project(":itest") {
    apply plugin: "java"

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

696 697
tasks.eclipse.doLast {
    delete ".project"
698
}