summaryrefslogtreecommitdiff
path: root/src/main/groovy/FlycheckAndroidJavaTask.groovy
blob: 14c1fc4b986b62d3695fb8f6dce45c06cb1e0375 (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
67
68
69
70
package org.thejk

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.compile.JavaCompile

class FlycheckAndroidJavaTask extends DefaultTask {
    FlycheckAndroidJavaTask() {
    }

    @TaskAction
    def action() {
        def variants = []
        def android = project.extensions.findByName('android')
        if (android && android.class.simpleName == 'AppExtension_Decorated') {
            variants = android.applicationVariants.collect { it.name }
        } else if (android && android.class.simpleName == 'LibraryExtension_Decorated') {
            variants = android.libraryVariants.collect { it.name }
        } else {
            def buildTypes = project.extensions.buildTypes.names
            if (buildTypes.isEmpty()) buildTypes = ['debug', 'release']
            def flavors = project.extensions.flavors.names
            if (flavors.isEmpty()) {
                variants = buildTypes
            } else {
                flavors.each { flavor ->
                    buildTypes.each { buildType ->
                        variants.add(flavor + buildType.capitalize())
                    }
                }
            }
        }
        variants = variants.sort()
        def configurations = ['', 'UnitTest']
        variants.each { variant ->
            configurations.each { configuration ->
                def name = 'compile'
                name += variant.capitalize()
                name += configuration.capitalize() + 'JavaWithJavac'
                def compile = project.tasks.findByName(name)
                if (compile) {
                    try {
                        def cp = compile.classpath.asPath
                        def bootcp = compile.options.bootClasspath ?: ''
                        println '***'
                        println 'variant=' + variant
                        println 'args=' + compile.options.compilerArgs.every {
                            !it.startsWith('-X') }
                        println 'encoding=' + compile.options.encoding
                        println 'bootcp=' + bootcp
                        println 'cp=' + cp
                        println 'source=' + compile.sourceCompatibility
                        println 'target=' + compile.targetCompatibility
                        println 'files=' + compile.inputs.files.asPath
                        println 'output=' + compile.destinationDir
                    } catch (Throwable t) {
                    }
                }
            }

            def name = 'generate'
            name += variant.capitalize() + 'Sources'
            def generate = project.tasks.findByName(name)
            if (generate != null) {
                println '!!!'
                println generate.path
            }
        }
    }
}