aboutsummaryrefslogtreecommitdiff
path: root/src/main/groovy/frege/gradle/NativeGenTask.groovy
blob: 94f2fec11bed9ed03966ba40483f407a404f1771 (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
package frege.gradle

import org.gradle.api.DefaultTask
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

import org.gradle.process.internal.DefaultJavaExecAction
import org.gradle.process.internal.JavaExecAction

class NativeGenTask extends DefaultTask {

    @Optional
    @InputFile
    File typesFile = new File(project.projectDir, "types.properties")

    @Input
    String className = null

    @Optional
    @OutputFile
    File outputFile = new File(project.buildDir, "generated/frege/NativeGenOutput.fr")


    @TaskAction
    void gen() {

        FileResolver fileResolver = getServices().get(FileResolver.class)
        JavaExecAction action = new DefaultJavaExecAction(fileResolver)
        action.setMain("frege.nativegen.Main")
        action.workingDir = project.projectDir
        action.standardInput = System.in
        action.standardOutput = outputFile.newOutputStream()
        action.errorOutput = System.err
        action.setClasspath(project.files(project.configurations.compile) + project.files("$project.buildDir/classes/main"))

        def args = []
        args << className
        args << typesFile.absolutePath
        action.args args
        action.execute()
    }


}