DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (04bee69b3274)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 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 143 144 145 146 147 148 149 150
import java.util.regex.Pattern

def tryInt = { string ->
    if (string == null) {
        return string
    }
    if (string.isInteger()) {
        return string as Integer
    }
    return string
}

allprojects {
    // Expose the per-object-directory configuration to all projects.
    ext {
        mozconfig = gradle.mozconfig
        topsrcdir = gradle.mozconfig.topsrcdir
        topobjdir = gradle.mozconfig.topobjdir

        compileSdkVersion = tryInt(mozconfig.substs.ANDROID_COMPILE_SDK_VERSION)
        buildToolsVersion = tryInt(mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION)
        targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
        minSdkVersion = tryInt(mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION)
        manifestPlaceholders = [
            ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
            ANDROID_TARGET_SDK: mozconfig.substs.ANDROID_TARGET_SDK,
            MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
            MOZ_ANDROID_SHARED_ID: "${mozconfig.substs.ANDROID_PACKAGE_NAME}.sharedID",
        ]
    }

    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url repository
            }
        }
    }
}

buildDir "${topobjdir}/gradle/build"

buildscript {
    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url repository
            }
        }
        // For dexcount-gradle-plugin and other in tree plugins.
        maven {
            url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.4') {
            // Without these, we get errors linting.
            exclude module: 'guava'
        }
        // Provided in tree.
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.1'
    }
}

task generateCodeAndResources(type:Exec) {
    workingDir "${topobjdir}"

    commandLine mozconfig.substs.GMAKE
    args '-C'
    args "${topobjdir}/mobile/android/base"
    args 'gradle-targets'

    // Only show the output if something went wrong.
    ignoreExitValue = true
    standardOutput = new ByteArrayOutputStream()
    errorOutput = standardOutput
    doLast {
        if (execResult.exitValue != 0) {
            throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
        }
    }
}

// Skip unit test for all build variants, unless if it was specifically requested by user.
// The enabled property for the unit test tasks is reset based on the command line task names just before the task execution.
// I bet there is a easier/cleaner way to do this, but this gets the job done for now.
Pattern pattern = Pattern.compile('.*test(.+UnitTest)?.*')
boolean startTasksIncludeTest = gradle.startParameter.taskNames.any {
    taskName ->
        taskName.matches(pattern)
}
gradle.taskGraph.beforeTask {
    Task task ->
        if (task.name.matches(pattern)) {
            task.enabled = startTasksIncludeTest
        }
}

afterEvaluate {
    subprojects {
        if (!hasProperty('android')) {
            return
        }
        android.applicationVariants.all {
            preBuild.dependsOn rootProject.generateCodeAndResources
        }
        android.libraryVariants.all {
            preBuild.dependsOn rootProject.generateCodeAndResources
        }
    }
}

apply plugin: 'idea'

idea {
    project {
        languageLevel = '1.7'
    }

    module {
        // Object directories take a huge amount of time for IntelliJ to index.
        // Exclude them.  Convention is that object directories start with obj.
        // IntelliJ is clever and will not exclude the parts of the object
        // directory that are referenced, if there are any.  In practice,
        // indexing the entirety of the tree is taking too long, so exclude all
        // but mobile/.
        def topsrcdirURI = file(topsrcdir).toURI()
        excludeDirs += files(file(topsrcdir)
            .listFiles({it.isDirectory()} as FileFilter)
            .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
            .findAll({!it.equals('mobile/')}))

        // If topobjdir is below topsrcdir, hide only some portions of that tree.
        def topobjdirURI = file(topobjdir).toURI()
        if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
            excludeDirs -= file(topobjdir)
            excludeDirs += files(file(topobjdir).listFiles())
            excludeDirs -= file("${topobjdir}/gradle")
        }

        if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
            excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
        }
    }
}

task wrapper(type: Wrapper) {
}