summaryrefslogtreecommitdiff
path: root/platform/android/gradle/android-nitpick.gradle
blob: 6db3519678c9d578aedd9594219e434b5ab8211d (plain)
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
apply from: "${rootDir}/gradle/dependencies.gradle"

def MAPBOX_JAVA_DIR = 'mapbox-java'
def MAPBOX_JAVA_TAG_PREFIX = 'v'

def MAPBOX_TELEMETRY_DIR = 'mapbox-events-android'
def MAPBOX_TELEMETRY_TAG_PREFIX = 'telem-'
def MAPBOX_CORE_TAG_PREFIX = '-core-'

def MAPBOX_GESTURES_DIR = 'mapbox-gestures-android'
def MAPBOX_GESTURES_TAG_PREFIX = 'v'

task androidNitpick {
    doLast {
        println "Running android nitpick script"

        println "Verify vendor submodule pins"
        verifyVendorSubmodulePin(MAPBOX_JAVA_DIR, MAPBOX_JAVA_TAG_PREFIX, versions.mapboxServices)
        verifyVendorSubmodulePin(MAPBOX_TELEMETRY_DIR, MAPBOX_TELEMETRY_TAG_PREFIX,
                versions.mapboxTelemetry + MAPBOX_CORE_TAG_PREFIX + versions.mapboxCore)
        verifyVendorSubmodulePin(MAPBOX_GESTURES_DIR, MAPBOX_GESTURES_TAG_PREFIX, versions.mapboxGestures)

        verifyLicenseGeneration()
    }
}

private def verifyVendorSubmodulePin(def dir, def prefix, def version) {
    println "Verify vendor submodule pin: ${dir} (${prefix + version})"
    exec {
        workingDir = "${rootDir}/vendor/${dir}"
        commandLine "git", "fetch", "-t"
    }

    def output = new ByteArrayOutputStream()
    exec {
        workingDir = "${rootDir}/vendor/${dir}"
        commandLine "git", "rev-list", "-n", "1", "tags/${prefix + version}"
        standardOutput = output
    }
    def expectedCommit = output.toString().trim()
    output.reset()

    exec {
        workingDir = "${rootDir}/vendor/${dir}"
        commandLine "git", "rev-parse", "HEAD"
        standardOutput = output
    }
    def actualCommit = output.toString().trim()

    if (actualCommit != expectedCommit) {
        throw new IllegalStateException("${dir} vendor repository is not checked out on the consumed binary's tag.\n" +
                "Expected commit: " + expectedCommit + "(${prefix + version} tag).\n" +
                "Actual commit: " + actualCommit + ".\n" +
                "If you've updated the version in the dependencies.gradle file, make sure to bump the submodule pin in the platform/android/vendor/ directory to match the release tag.\n" +
                "If you've bumped the pin, make sure to verify the version tag prefix in the android-nitpick.gradle file.")
    }
    output.close()
}

private def verifyLicenseGeneration() {
    println "Verify license generation with git diff..."
    exec {
        workingDir = "${rootDir}"
        commandLine "python", "scripts/validate-license.py"
    }
}