Skip to content
Snippets Groups Projects
build.gradle 17.6 KiB
Newer Older
/*
 * 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/>.
 */

import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.tools.texturepacker.TexturePacker

Matyáš Latner's avatar
Matyáš Latner committed
buildscript {
    repositories {
        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
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
        classpath 'de.felixschulze.gradle:gradle-spoon-plugin:2.1'
        classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
        classpath 'com.novoda:gradle-android-command-plugin:1.3.0'
        classpath 'com.badlogicgames.gdx:gdx-tools:1.6.1'
final assetsDirName = "assets"
final assetsSourceDirName = "src"
final assetsDestinationDirName = "dest"
final assetsGameDirectory = "game"
final assetsGameGlobalDirectory = "_global"
final assetsGameCommonDifficultyDirectory = "common"
final assetsGameExcludedDirectory = "excluded"
final String TABLEXIA_GIT_PATH  = './'
final String MODEL_GIT_PATH     = 'core/external/'

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

Matyáš Latner's avatar
Matyáš Latner committed
    assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
    assetsChecksum = [:]

    assetsPackDir = new File("${rootProject.buildDir}/${assetsDirName}/pack/")
Matyáš Latner's avatar
Matyáš Latner committed
allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    ext {
        appName = 'Tablexia'
        masterBranch = 'master'
        applicationBaseId = 'cz.nic.tablexia'
        tablexiaAppName = getTablexiaAppName()
        tablexiaVersionName = getVersionNameFromGit(TABLEXIA_GIT_PATH)
        tablexiaVersionCode = getVersionCodeFromGit(TABLEXIA_GIT_PATH)
        tablexiaModelVersionName = getVersionNameFromGit(MODEL_GIT_PATH)
        tablexiaModelVersionCode = getVersionCodeFromGit(MODEL_GIT_PATH)
        applicationIdBranch = getTablexiaAppId()
        applicationIdRelease = applicationBaseId + applicationIdBranch
        applicationIdDebugSuffix = '.debug'
        applicationIdDebug = applicationIdRelease + applicationIdDebugSuffix
        applicationIdDevelSuffix = '.devel'
        applicationIdDevel = applicationBaseId + applicationIdDevelSuffix
        //Fallback value if sentry DSN is not defined (gradle parameter SENTRY_DSN_DEBUG or SENTRY_DSN_RELEASE)
        sentryDSNFallbackValue = "None"

	    mbassadorVersion = '1.2.0'
        sqlDroidVersion = '1.0.3'
        sqlLiteJdbcVersion = '3.8.10.1'
        guavaVersion = '18.0'
        roboPodsVersion = '1.13.0'
        androidSupportV4Version = '22.0.0'
        googlePlayServicesVersion = '8.3.+'
        zxingVersion = '3.2.1'

        servletApiVersion = '5.5.23'
        ravenVersion = '7.5.0'
    version = getVersionNameFromGit(TABLEXIA_GIT_PATH)
Matyáš Latner's avatar
Matyáš Latner committed
    repositories {
        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/" }
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()
            }
        }
    }
}
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 ->
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.mp3'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
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 ->
                    task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
                        from atlasDir
                        into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
                        include '**/*.json'
                        includeEmptyDirs false
                        eachFile { FileCopyDetails fcd ->
                            fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
                        outputs.upToDateWhen { false }
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;
        settings.maxWidth = 1024;
        settings.maxHeight = 1024;
        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 ->
                    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()
                            }
                        }
                    } else {
                        TexturePacker.process(settings,
                                "${atlasDir}",
                                "${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
                                "${atlasDir.name}")
                    }
task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJsonAssets]) {
    doLast {
        new File(project(":core").projectDir.absolutePath + "/${assetsDirName}").eachDir() { dir ->

            if (!dir.name.equals('common')) {
                task("${name}_${dir.name}", type: Zip) {
                    archiveName = dir.getName() + "_SNAPSHOT.zip"
                    destinationDir = rootProject.ext.assetsPackDir
                    from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
                }.execute()
task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum']) {
        if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL')) {
            def data = new URL("${TABLEXIA_ASSETS_DOWNLOAD_URL}").getText()
            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}"
                        commandLine 'scp', file.getAbsolutePath(), "${TABLEXIA_ASSETS_UPLOAD_USER}@${TABLEXIA_ASSETS_UPLOAD_URL}/${uploadFileName}"
                        standardOutput = new ByteArrayOutputStream()
                        ext.output = {
                            return standardOutput.toString()
                        }
                    }.execute()
                } else {
                    println "AssetsUploader: FILE: ${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
                }
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 {
        return ".${branchName.trim().replaceAll('-', '').replaceAll('\\.', '').toLowerCase()}"
def getVersionNameFromGit(String relativePath) {
    def stdout = new ByteArrayOutputStream()
    String branchName = getBranchNameFromGit()

    // get last tag in current branch
Matyáš Latner's avatar
Matyáš Latner committed
        commandLine 'git', 'describe', '--abbrev=0', '--tags', '--always'
        standardOutput = stdout
    }
    String result = stdout.toString().trim();

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

        if (!"0".equals(numberOfCommits)) {
            // add branch name and number of commits
            result = "${result}-${numberOfCommits}"
        }
    }
    return result
def getVersionCodeFromGit(String relativePath) {
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'log', '-1', '--format=%at'
        standardOutput = stdout
    }
    return stdout.toString().trim().toInteger()
}

def getBranchNameFromGit() {
    def stdout = new ByteArrayOutputStream()
    exec {
Matyáš Latner's avatar
Matyáš Latner committed
        commandLine  'git', 'describe', '--contains', '--all', 'HEAD', '--always'
        standardOutput = stdout
    }
    String branchString = stdout.toString().trim()
    return branchString.contains("/") ? branchString.substring(branchString.lastIndexOf("/") + 1) : branchString
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
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"
	    compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
	    compile "net.engio:mbassador:$mbassadorVersion"
        compile "com.jcabi:jcabi-manifests:1.1"
        compile "org.xerial:sqlite-jdbc:$sqlLiteJdbcVersion"
Matyáš Latner's avatar
Matyáš Latner committed
    }
}

project(":android") {
    apply plugin: 'android-sdk-manager'
Matyáš Latner's avatar
Matyáš Latner committed
    apply plugin: "android"
Matyáš Latner's avatar
Matyáš Latner committed
    apply plugin: "spoon"
    apply plugin: 'android-command'
Matyáš Latner's avatar
Matyáš Latner committed

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
	    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
	    compile "net.engio:mbassador:$mbassadorVersion"
        compile "org.sqldroid:sqldroid:$sqlDroidVersion"
        compile "com.android.support:support-v4:$androidSupportV4Version"
        compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
        compile files('libs/FlurryAnalytics-6.1.0.jar')
	    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
        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"

        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
    }
}

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}"
	    compile "net.engio:mbassador:$mbassadorVersion"
Matyáš Latner's avatar
Matyáš Latner committed
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
	    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
Matyáš Latner's avatar
Matyáš Latner committed
	    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
    }
}

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

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

    dependencies {
        compile project(":util:checksum")
Matyáš Latner's avatar
Matyáš Latner committed
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
		compile "net.dermetfan.libgdx-utils:libgdx-utils:$gdxUtilsVersion"
	    compile "net.engio:mbassador:$mbassadorVersion"
	    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.google.guava:guava:$guavaVersion"
Vitaliy Vashchenko's avatar
Vitaliy Vashchenko committed
        compile "com.google.zxing:core:$zxingVersion"
        compile "tomcat:servlet-api:$servletApiVersion"
        compile "com.getsentry.raven:raven:$ravenVersion"
        testCompile "junit:junit:4.11"
		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
    }
}

tasks.eclipse.doLast {
    delete ".project"