From 9134c41cc599fed7d1c423ddf23b0b36266b0c73 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 2 Nov 2015 23:11:25 -0800 Subject: [PATCH] Pass the current directory to Java compilation. --- .../com/beust/kobalt/internal/JvmCompiler.kt | 2 +- .../com/beust/kobalt/plugin/java/JavaCompiler.kt | 16 ++++++++++------ .../beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt index f36b3b2e..de7ea2b5 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt @@ -62,7 +62,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) } -data class CompilerActionInfo(val dependencies: List, +data class CompilerActionInfo(val directory: String?, val dependencies: List, val sourceFiles: List, val outputDir: File, val compilerArgs: List) interface ICompilerAction { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt index 92ae64ed..524fc71a 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt @@ -18,6 +18,7 @@ import java.io.File class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { fun compilerAction(executable: File) = object : ICompilerAction { override fun compile(info: CompilerActionInfo): TaskResult { + info.outputDir.mkdirs() val allArgs = arrayListOf( executable.absolutePath, @@ -30,7 +31,9 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { allArgs.addAll(info.sourceFiles) val pb = ProcessBuilder(allArgs) - pb.directory(info.outputDir) + info.directory?.let { + pb.directory(File(it)) + } pb.inheritIO() val line = allArgs.joinToString(" ") log(2, " Compiling $line") @@ -46,19 +49,20 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { * Create an ICompilerAction based on the parameters and send it to JvmCompiler.doCompile() with * the given executable. */ - private fun run(project: Project?, context: KobaltContext?, dependencies: List, - sourceFiles: List, outputDir: File, args: List, executable: File) : TaskResult { - val info = CompilerActionInfo(dependencies, sourceFiles, outputDir, args) + private fun run(project: Project?, context: KobaltContext?, directory: String?, + dependencies: List, sourceFiles: List, outputDir: File, + args: List, executable: File): TaskResult { + val info = CompilerActionInfo(directory, dependencies, sourceFiles, outputDir, args) return jvmCompiler.doCompile(project, context, compilerAction(executable), info) } fun compile(project: Project?, context: KobaltContext?, dependencies: List, sourceFiles: List, outputDir: File, args: List) : TaskResult - = run(project, context, dependencies, sourceFiles, outputDir, args, + = run(project, context, project?.directory, dependencies, sourceFiles, outputDir, args, JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!) fun javadoc(project: Project?, context: KobaltContext?, dependencies: List, sourceFiles: List, outputDir: File, args: List) : TaskResult - = run(project, context, dependencies, sourceFiles, outputDir, args, + = run(project, context, project?.directory, dependencies, sourceFiles, outputDir, args, JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 02ab9902..88b960d0 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -72,7 +72,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, .map { FileDependency(it) } val dependencies = compileDependencies + classpathList + otherClasspath.map { FileDependency(it)} - val info = CompilerActionInfo(dependencies, sourceFiles, outputDir, args) + val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, outputDir, args) return jvmCompiler.doCompile(project, context, compilerAction, info) } }