build.gradle 16.8 KB
Newer Older
1
import com.badlogic.gdx.graphics.Texture
2 3
import com.badlogic.gdx.tools.texturepacker.TexturePacker

Matyáš Latner's avatar
Matyáš Latner committed
4 5
buildscript {
    repositories {
6 7 8
        maven   { url "http://repo1.maven.org/maven2" }
        maven   { url "https://jitpack.io" }
        jcenter { url "http://jcenter.bintray.com/" }
Matyáš Latner's avatar
Matyáš Latner committed
9 10
    }
    dependencies {
11 12
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
13
        classpath 'de.felixschulze.gradle:gradle-spoon-plugin:2.1'
14
        classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
15
        classpath 'com.novoda:gradle-android-command-plugin:1.3.0'
16
        classpath 'com.badlogicgames.gdx:gdx-tools:1.6.1'
Matyáš Latner's avatar
Matyáš Latner committed
17 18 19
    }
}

20
final assetsDirName = "assets"
21 22
final assetsSourceDirName = "src"
final assetsDestinationDirName = "dest"
23

24 25 26
final assetsGameDirectory = "game"
final assetsGameGlobalDirectory = "_global"
final assetsGameCommonDifficultyDirectory = "common"
27
final assetsGameExcludedDirectory = "excluded"
28

29 30 31
final String TABLEXIA_GIT_PATH  = './'
final String MODEL_GIT_PATH     = 'core/external/'

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

35
ext {
Matyáš Latner's avatar
Matyáš Latner committed
36
    assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
37
    assetsChecksum = [:]
38 39

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

Matyáš Latner's avatar
Matyáš Latner committed
42 43 44 45 46
allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    ext {
47
        appName = 'Tablexia'
48 49 50
        masterBranch = 'master'
        applicationBaseId = 'cz.nic.tablexia'
        tablexiaAppName = getTablexiaAppName()
51 52 53 54
        tablexiaVersionName = getVersionNameFromGit(TABLEXIA_GIT_PATH)
        tablexiaVersionCode = getVersionCodeFromGit(TABLEXIA_GIT_PATH)
        tablexiaModelVersionName = getVersionNameFromGit(MODEL_GIT_PATH)
        tablexiaModelVersionCode = getVersionCodeFromGit(MODEL_GIT_PATH)
55 56
        applicationIdBranch = getTablexiaAppId()
        applicationIdRelease = applicationBaseId + applicationIdBranch
57 58
        applicationIdDebugSuffix = '.debug'
        applicationIdDebug = applicationIdRelease + applicationIdDebugSuffix
59
        applicationIdDevelSuffix = '.devel'
60
        applicationIdDevel = applicationBaseId + applicationIdDevelSuffix
61

62 63 64
        //Fallback value if sentry DSN is not defined (gradle parameter SENTRY_DSN_DEBUG or SENTRY_DSN_RELEASE)
        sentryDSNFallbackValue = "None"

65
        gdxVersion = '1.9.2'
66
		gdxUtilsVersion = '0.13.2'
67
	    mbassadorVersion = '1.2.0'
68
        roboVMVersion = '1.12.0'
69 70
        sqlDroidVersion = '1.0.3'
        sqlLiteJdbcVersion = '3.8.10.1'
71
        guavaVersion = '18.0'
72
        roboPodsVersion = '1.13.0'
73 74
        androidSupportV4Version = '22.0.0'
        googlePlayServicesVersion = '8.3.+'
75 76 77

        servletApiVersion = '5.5.23'
        ravenVersion = '7.5.0'
Matyáš Latner's avatar
Matyáš Latner committed
78 79
    }

80
    version = getVersionNameFromGit(TABLEXIA_GIT_PATH)
81

Matyáš Latner's avatar
Matyáš Latner committed
82
    repositories {
83 84 85 86
        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/" }
Matyáš Latner's avatar
Matyáš Latner committed
87 88 89
    }
}

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
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()
            }
        }
    }
}
115

116 117 118 119 120 121 122 123 124 125
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 ->
126
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
127 128 129 130 131
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.mp3'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
132
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
133
                        }
134
                        outputs.upToDateWhen { false }
135 136 137 138 139 140 141
                    }.execute()
                }
            }
        }
    }
}

142 143 144 145 146 147 148 149 150 151
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 ->
152
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
153 154 155 156 157
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.json'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
158
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
159
                        }
160
                        outputs.upToDateWhen { false }
161 162 163 164 165 166 167
                    }.execute()
                }
            }
        }
    }
}

168 169 170 171 172 173 174 175
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();
Matyáš Latner's avatar
Matyáš Latner committed
176
        settings.pot = false;
177 178
        settings.maxWidth = 1024;
        settings.maxHeight = 1024;
179 180 181 182 183 184 185
        settings.combineSubdirectories = true;
        settings.filterMin = Texture.TextureFilter.Linear;
        settings.filterMag = Texture.TextureFilter.Linear;

        new File("${assetsDir.absolutePath}/${assetsSourceDirName}/").eachDir() { langDir ->
            langDir.eachDir() { sectionDir ->
                sectionDir.eachDir() { atlasDir ->
186 187
                    if (assetsGameDirectory.equals(sectionDir.name) && !assetsGameGlobalDirectory.equals(atlasDir.name)) {
                        atlasDir.eachDir() { difficultyDir ->
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
                            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()
                            }
203 204 205 206 207 208 209
                        }
                    } else {
                        TexturePacker.process(settings,
                                "${atlasDir}",
                                "${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
                                "${atlasDir.name}")
                    }
210 211 212 213 214 215
                }
            }
        }
    }
}

216
task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJsonAssets]) {
217 218 219 220 221
    doLast {
        new File(project(":core").projectDir.absolutePath + "/${assetsDirName}").eachDir() { dir ->

            if (!dir.name.equals('common')) {
                task("${name}_${dir.name}", type: Zip) {
222
                    archiveName = dir.getName() + "_SNAPSHOT.zip"
223
                    destinationDir = rootProject.ext.assetsPackDir
224 225
                    from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
                }.execute()
226 227 228 229 230
            }
        }
    }
}

231
task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum']) {
232
    doLast {
233 234
        if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL')) {
            def data = new URL("${TABLEXIA_ASSETS_DOWNLOAD_URL}").getText()
235 236 237 238 239 240 241 242 243 244 245
            rootProject.ext.assetsPackDir.eachFile() { file ->
                String fileName = file.getName()
                String[] fileNameParts = fileName.split("_SNAPSHOT\\.");
                String packageName = "${fileNameParts[0]}_${assetsChecksum[fileNameParts[0]]}.${fileNameParts[1]}";

                boolean isProductionVersion = project.hasProperty('TABLEXIA_ASSETS_UPLOAD_PRODUCTION') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD_PRODUCTION).booleanValue()
                String uploadFileName = isProductionVersion ? packageName : fileName
                if (!isProductionVersion || !data.contains(packageName)) {
                    println "AssetsUploader: UPLOADING FILE: ${uploadFileName}"
                    task ("${name}_${packageName}", type:Exec) {
                        workingDir "${rootProject.projectDir}"
246
                        commandLine 'scp', file.getAbsolutePath(), "${TABLEXIA_ASSETS_UPLOAD_USER}@${TABLEXIA_ASSETS_UPLOAD_URL}/${uploadFileName}"
247 248 249 250 251 252 253 254
                        standardOutput = new ByteArrayOutputStream()
                        ext.output = {
                            return standardOutput.toString()
                        }
                    }.execute()
                } else {
                    println "AssetsUploader: FILE: ${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
                }
255 256 257 258 259
            }
        }
    }
}

260 261 262 263 264 265 266 267 268 269 270 271 272 273
def getTablexiaAppName() {
    String branchName = getBranchNameFromGit()
    if (project.masterBranch.equals(branchName)) {
        return "${project.appName}"
    } else {
        return "${project.appName} (${branchName})"
    }
}

def getTablexiaAppId() {
    String branchName = getBranchNameFromGit()
    if (project.masterBranch.equals(branchName)) {
        return ""
    } else {
274
        return ".${branchName.trim().replaceAll('-', '').replaceAll('\\.', '').toLowerCase()}"
275 276 277
    }
}

278
def getVersionNameFromGit(String relativePath) {
279
    def stdout = new ByteArrayOutputStream()
280
    String branchName = getBranchNameFromGit()
281 282

    // get last tag in current branch
283
    exec {
284
        workingDir relativePath
285
        commandLine 'git', 'describe', '--abbrev=0', '--tags'
286 287
        standardOutput = stdout
    }
288 289 290
    String result = stdout.toString().trim();

    // for non release branches add number of commits and branch name
291
    if (!project.masterBranch.equals(branchName)) {
292 293
        stdout = new ByteArrayOutputStream()
        exec {
294
            workingDir relativePath
295
            commandLine 'git', 'rev-list', "${result}..HEAD", '--count'
296 297 298 299
            standardOutput = stdout
        }
        String numberOfCommits = stdout.toString().trim()

300 301 302 303
        if (!"0".equals(numberOfCommits)) {
            // add branch name and number of commits
            result = "${result}-${numberOfCommits}"
        }
304 305
    }
    return result
306 307
}

308
def getVersionCodeFromGit(String relativePath) {
309 310
    def stdout = new ByteArrayOutputStream()
    exec {
311
        workingDir relativePath
312 313 314 315 316 317
        commandLine 'git', 'log', '-1', '--format=%at'
        standardOutput = stdout
    }
    return stdout.toString().trim().toInteger()
}

318
def getBranchNameFromGit() {
319 320
    def stdout = new ByteArrayOutputStream()
    exec {
321
        commandLine  'git', 'describe', '--contains', '--all', 'HEAD'
322 323
        standardOutput = stdout
    }
324 325
    String branchString = stdout.toString().trim()
    return branchString.contains("/") ? branchString.substring(branchString.lastIndexOf("/") + 1) : branchString
326 327
}

328 329 330 331 332 333 334 335 336
def getMapConvertedToString(Map map) {
    String result = "";
    map.each { key, value ->
        if (result.size() > 0) result = result + ","
        result = result + "$key:$value"
    }
    return result;
}

Matyáš Latner's avatar
Matyáš Latner committed
337 338 339 340 341 342 343 344 345
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"
346 347 348
	    compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
	    compile "net.engio:mbassador:$mbassadorVersion"
        compile "com.jcabi:jcabi-manifests:1.1"
Matyáš Latner's avatar
Matyáš Latner committed
349
        compile "org.xerial:sqlite-jdbc:$sqlLiteJdbcVersion"
Matyáš Latner's avatar
Matyáš Latner committed
350 351 352 353
    }
}

project(":android") {
354
    apply plugin: 'android-sdk-manager'
Matyáš Latner's avatar
Matyáš Latner committed
355
    apply plugin: "android"
Matyáš Latner's avatar
Matyáš Latner committed
356
    apply plugin: "spoon"
357
    apply plugin: 'android-command'
Matyáš Latner's avatar
Matyáš Latner committed
358 359 360 361 362 363

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
364 365
	    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
	    compile "net.engio:mbassador:$mbassadorVersion"
366
        compile "org.sqldroid:sqldroid:$sqlDroidVersion"
367 368 369
        compile "com.android.support:support-v4:$androidSupportV4Version"
        compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
        compile files('libs/FlurryAnalytics-6.1.0.jar')
370 371 372
	    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
	    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
	    natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
Matyáš Latner's avatar
Matyáš Latner committed
373 374 375
        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"
376 377 378 379

        testCompile 'org.robolectric:robolectric:2.3'
        androidTestCompile "com.squareup.spoon:spoon-client:1.1.7"
        androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.3.1'
Matyáš Latner's avatar
Matyáš Latner committed
380 381 382 383 384 385 386 387 388 389 390 391 392
    }
}

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

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "org.robovm:robovm-rt:${roboVMVersion}"
        compile "org.robovm:robovm-cocoatouch:${roboVMVersion}"
393
	    compile "net.engio:mbassador:$mbassadorVersion"
Matyáš Latner's avatar
Matyáš Latner committed
394
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
395
	    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
Matyáš Latner's avatar
Matyáš Latner committed
396 397
	    compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
Matyáš Latner's avatar
Matyáš Latner committed
398 399 400 401 402 403
    }
}

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

404
    sourceSets.test.java.srcDirs = ["test/"]
405
	tasks.processResources.dependsOn processAssets
Matyáš Latner's avatar
Matyáš Latner committed
406 407

    dependencies {
408
        compile project(":util:checksum")
Matyáš Latner's avatar
Matyáš Latner committed
409
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
410
		compile "net.dermetfan.libgdx-utils:libgdx-utils:$gdxUtilsVersion"
411 412
	    compile "net.engio:mbassador:$mbassadorVersion"
	    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
413
        compile "com.google.guava:guava:$guavaVersion"
414

415 416
        compile "tomcat:servlet-api:$servletApiVersion"
        compile "com.getsentry.raven:raven:$ravenVersion"
417

418
        testCompile "junit:junit:4.11"
419 420 421
		testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"               
        testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"                                
        testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
Matyáš Latner's avatar
Matyáš Latner committed
422 423 424 425 426
    }
}

tasks.eclipse.doLast {
    delete ".project"
427
}