diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 2fe0ebd9..5be076e7 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -142,7 +142,12 @@ abstract class JvmCompilerPlugin @Inject constructor( override fun projects() = projects @Task(name = JavaPlugin.TASK_COMPILE, description = "Compile the project") - fun taskCompile(project: Project) : TaskResult { + fun taskCompile(project: Project) = doCompile(project, createCompilerActionInfo(project)) + + @Task(name = JavaPlugin.TASK_JAVADOC, description = "Run Javadoc") + fun taskJavadoc(project: Project) = doJavadoc(project, createCompilerActionInfo(project)) + + private fun createCompilerActionInfo(project: Project) : CompilerActionInfo { copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN) val projDeps = dependencyManager.dependentProjectDependencies(projects(), project, context) @@ -158,10 +163,11 @@ abstract class JvmCompilerPlugin @Inject constructor( { it .endsWith(project.sourceSuffix) }) .map { File(projectDirectory, it).absolutePath } - val result = doCompile(project, classpath, sourceFiles, buildDirectory) - return result + val cai = CompilerActionInfo(projectDirectory.absolutePath, classpath, sourceFiles, buildDirectory, + emptyList()) + return cai } - abstract fun doCompile(project: Project, classpath: List, sourceFiles: List, - buildDirectory: File) : TaskResult + abstract fun doCompile(project: Project, cai: CompilerActionInfo) : TaskResult + abstract fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt index e699bb8c..42c92290 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt @@ -6,6 +6,7 @@ import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.homeDir +import com.beust.kobalt.internal.CompilerActionInfo import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.FileDependency import com.beust.kobalt.maven.IClasspathDependency @@ -206,10 +207,9 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) private fun compile(project: Project, rDirectory: String): File { val sourceFiles = arrayListOf(Paths.get(rDirectory, "R.java").toFile().path) val buildDir = Paths.get(project.buildDirectory, "generated", "classes").toFile() - - javaCompiler.compile(project, context, listOf(), sourceFiles, buildDir, listOf( - "-source", "1.6", "-target", "1.6" - )) + val cai = CompilerActionInfo(project.directory, listOf(), sourceFiles, buildDir, listOf( + "-source", "1.6", "-target", "1.6")) + javaCompiler.compile(project, context, cai) return buildDir } 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 3cbc1107..af8314c3 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt @@ -2,13 +2,12 @@ package com.beust.kobalt.plugin.java import com.beust.kobalt.JavaInfo import com.beust.kobalt.SystemProperties +import com.beust.kobalt.TaskResult import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.internal.CompilerActionInfo import com.beust.kobalt.internal.ICompilerAction import com.beust.kobalt.internal.JvmCompiler -import com.beust.kobalt.TaskResult -import com.beust.kobalt.maven.IClasspathDependency import com.beust.kobalt.misc.log import com.google.inject.Inject import com.google.inject.Singleton @@ -46,23 +45,15 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { } /** - * Create an ICompilerAction based on the parameters and send it to JvmCompiler.doCompile() with - * the given executable. + * Invoke the given executale on the CompilerActionInfo. */ - 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) + private fun run(project: Project?, context: KobaltContext?, cai: CompilerActionInfo, executable: File): TaskResult { + return jvmCompiler.doCompile(project, context, compilerAction(executable), cai) } - fun compile(project: Project?, context: KobaltContext?, dependencies: List, - sourceFiles: List, outputDir: File, args: List) : TaskResult - = run(project, context, project?.directory, dependencies, sourceFiles, outputDir, args, - JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!) + fun compile(project: Project?, context: KobaltContext?, cai: CompilerActionInfo) : TaskResult + = run(project, context, cai, JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!) - fun javadoc(project: Project?, context: KobaltContext?, dependencies: List, - sourceFiles: List, outputDir: File, args: List) : TaskResult - = run(project, context, project?.directory, dependencies, sourceFiles, outputDir, args, - JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!) + fun javadoc(project: Project?, context: KobaltContext?, cai: CompilerActionInfo) : TaskResult + = run(project, context, cai, JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt index f411a8d3..0e8a58e4 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt @@ -6,11 +6,11 @@ import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Project import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.internal.CompilerActionInfo import com.beust.kobalt.internal.JvmCompiler import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.DependencyManager -import com.beust.kobalt.maven.IClasspathDependency import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors @@ -52,30 +52,21 @@ public class JavaPlugin @Inject constructor( return dirs } - @Task(name = TASK_JAVADOC, description = "Run Javadoc") - fun taskJavadoc(project: Project) : TaskResult { - val projectDir = File(project.directory) - val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories) + override fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult { val result = - if (sourceFiles.size > 0) { - val buildDir = File(projectDir, - project.buildDirectory + File.separator + JvmCompilerPlugin.DOCS_DIRECTORY).apply { mkdirs() } - javaCompiler.javadoc(project, context, project.compileDependencies, sourceFiles, - buildDir, compilerArgs) - } else { - warn("Couldn't find any source files to run Javadoc on") - TaskResult() - } + if (cai.sourceFiles.size > 0) { + javaCompiler.javadoc(project, context, cai.copy(compilerArgs = compilerArgs)) + } else { + warn("Couldn't find any source files to run Javadoc on") + TaskResult() + } return result - } - override fun doCompile(project: Project, classpath: List, sourceFiles: List, - buildDirectory: File) : TaskResult { + override fun doCompile(project: Project, cai: CompilerActionInfo) : TaskResult { val result = - if (sourceFiles.size > 0) { - javaCompiler.compile(project, context, classpath, sourceFiles, - buildDirectory, compilerArgs) + if (cai.sourceFiles.size > 0) { + javaCompiler.compile(project, context, cai.copy(compilerArgs = compilerArgs)) } else { warn("Couldn't find any source files to compile") TaskResult() @@ -90,8 +81,8 @@ public class JavaPlugin @Inject constructor( if (sourceFiles.size > 0) { copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST) val buildDir = makeOutputTestDir(project) - javaCompiler.compile(project, context, testDependencies(project), sourceFiles, - buildDir, compilerArgs) + javaCompiler.compile(project, context, CompilerActionInfo(project.directory, testDependencies(project), + sourceFiles, buildDir, compilerArgs)) } else { warn("Couldn't find any tests to compile") TaskResult() diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 7dc329e6..ce4d5658 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -7,6 +7,7 @@ import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Project import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.internal.CompilerActionInfo import com.beust.kobalt.internal.JvmCompiler import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.* @@ -37,11 +38,10 @@ class KotlinPlugin @Inject constructor( override fun accept(project: Project) = project is KotlinProject - override fun doCompile(project: Project, classpath: List, sourceFiles: List, - buildDirectory: File) : TaskResult { + override fun doCompile(project: Project, cai: CompilerActionInfo) : TaskResult { val result = - if (sourceFiles.size > 0) { - compilePrivate(project, classpath, sourceFiles, buildDirectory) + if (cai.sourceFiles.size > 0) { + compilePrivate(project, cai.dependencies, cai.sourceFiles, cai.outputDir) lp(project, "Compilation succeeded") TaskResult() } else { @@ -51,7 +51,12 @@ class KotlinPlugin @Inject constructor( return result } - @Task(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf(TASK_COMPILE)) + override fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult { + warn("javadoc task not implemented for Kotlin, call the dokka task instead") + return TaskResult() + } + + @Task(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf(TASK_COMPILE)) fun taskCompileTest(project: Project): TaskResult { copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST) val projectDir = File(project.directory)