1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

More pulling things up into JvmCompilerPlugin.

This commit is contained in:
Cedric Beust 2015-11-18 21:23:12 -08:00
parent c12bf1b646
commit 333b7c4375
5 changed files with 46 additions and 53 deletions

View file

@ -142,7 +142,12 @@ abstract class JvmCompilerPlugin @Inject constructor(
override fun projects() = projects override fun projects() = projects
@Task(name = JavaPlugin.TASK_COMPILE, description = "Compile the project") @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) copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
val projDeps = dependencyManager.dependentProjectDependencies(projects(), project, context) val projDeps = dependencyManager.dependentProjectDependencies(projects(), project, context)
@ -158,10 +163,11 @@ abstract class JvmCompilerPlugin @Inject constructor(
{ it .endsWith(project.sourceSuffix) }) { it .endsWith(project.sourceSuffix) })
.map { File(projectDirectory, it).absolutePath } .map { File(projectDirectory, it).absolutePath }
val result = doCompile(project, classpath, sourceFiles, buildDirectory) val cai = CompilerActionInfo(projectDirectory.absolutePath, classpath, sourceFiles, buildDirectory,
return result emptyList())
return cai
} }
abstract fun doCompile(project: Project, classpath: List<IClasspathDependency>, sourceFiles: List<String>, abstract fun doCompile(project: Project, cai: CompilerActionInfo) : TaskResult
buildDirectory: File) : TaskResult abstract fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult
} }

View file

@ -6,6 +6,7 @@ import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.homeDir import com.beust.kobalt.homeDir
import com.beust.kobalt.internal.CompilerActionInfo
import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.FileDependency import com.beust.kobalt.maven.FileDependency
import com.beust.kobalt.maven.IClasspathDependency 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 { private fun compile(project: Project, rDirectory: String): File {
val sourceFiles = arrayListOf(Paths.get(rDirectory, "R.java").toFile().path) val sourceFiles = arrayListOf(Paths.get(rDirectory, "R.java").toFile().path)
val buildDir = Paths.get(project.buildDirectory, "generated", "classes").toFile() val buildDir = Paths.get(project.buildDirectory, "generated", "classes").toFile()
val cai = CompilerActionInfo(project.directory, listOf(), sourceFiles, buildDir, listOf(
javaCompiler.compile(project, context, listOf(), sourceFiles, buildDir, listOf( "-source", "1.6", "-target", "1.6"))
"-source", "1.6", "-target", "1.6" javaCompiler.compile(project, context, cai)
))
return buildDir return buildDir
} }

View file

@ -2,13 +2,12 @@ package com.beust.kobalt.plugin.java
import com.beust.kobalt.JavaInfo import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties import com.beust.kobalt.SystemProperties
import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.internal.CompilerActionInfo import com.beust.kobalt.internal.CompilerActionInfo
import com.beust.kobalt.internal.ICompilerAction import com.beust.kobalt.internal.ICompilerAction
import com.beust.kobalt.internal.JvmCompiler 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.beust.kobalt.misc.log
import com.google.inject.Inject import com.google.inject.Inject
import com.google.inject.Singleton 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 * Invoke the given executale on the CompilerActionInfo.
* the given executable.
*/ */
private fun run(project: Project?, context: KobaltContext?, directory: String?, private fun run(project: Project?, context: KobaltContext?, cai: CompilerActionInfo, executable: File): TaskResult {
dependencies: List<IClasspathDependency>, sourceFiles: List<String>, outputDir: File, return jvmCompiler.doCompile(project, context, compilerAction(executable), cai)
args: List<String>, 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<IClasspathDependency>, fun compile(project: Project?, context: KobaltContext?, cai: CompilerActionInfo) : TaskResult
sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult = run(project, context, cai, JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!)
= run(project, context, project?.directory, dependencies, sourceFiles, outputDir, args,
JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!)
fun javadoc(project: Project?, context: KobaltContext?, dependencies: List<IClasspathDependency>, fun javadoc(project: Project?, context: KobaltContext?, cai: CompilerActionInfo) : TaskResult
sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult = run(project, context, cai, JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!)
= run(project, context, project?.directory, dependencies, sourceFiles, outputDir, args,
JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!)
} }

View file

@ -6,11 +6,11 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.CompilerActionInfo
import com.beust.kobalt.internal.JvmCompiler import com.beust.kobalt.internal.JvmCompiler
import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.DepFactory
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.KobaltExecutors
@ -52,30 +52,21 @@ public class JavaPlugin @Inject constructor(
return dirs return dirs
} }
@Task(name = TASK_JAVADOC, description = "Run Javadoc") override fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult {
fun taskJavadoc(project: Project) : TaskResult {
val projectDir = File(project.directory)
val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories)
val result = val result =
if (sourceFiles.size > 0) { if (cai.sourceFiles.size > 0) {
val buildDir = File(projectDir, javaCompiler.javadoc(project, context, cai.copy(compilerArgs = compilerArgs))
project.buildDirectory + File.separator + JvmCompilerPlugin.DOCS_DIRECTORY).apply { mkdirs() } } else {
javaCompiler.javadoc(project, context, project.compileDependencies, sourceFiles, warn("Couldn't find any source files to run Javadoc on")
buildDir, compilerArgs) TaskResult()
} else { }
warn("Couldn't find any source files to run Javadoc on")
TaskResult()
}
return result return result
} }
override fun doCompile(project: Project, classpath: List<IClasspathDependency>, sourceFiles: List<String>, override fun doCompile(project: Project, cai: CompilerActionInfo) : TaskResult {
buildDirectory: File) : TaskResult {
val result = val result =
if (sourceFiles.size > 0) { if (cai.sourceFiles.size > 0) {
javaCompiler.compile(project, context, classpath, sourceFiles, javaCompiler.compile(project, context, cai.copy(compilerArgs = compilerArgs))
buildDirectory, compilerArgs)
} else { } else {
warn("Couldn't find any source files to compile") warn("Couldn't find any source files to compile")
TaskResult() TaskResult()
@ -90,8 +81,8 @@ public class JavaPlugin @Inject constructor(
if (sourceFiles.size > 0) { if (sourceFiles.size > 0) {
copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST) copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST)
val buildDir = makeOutputTestDir(project) val buildDir = makeOutputTestDir(project)
javaCompiler.compile(project, context, testDependencies(project), sourceFiles, javaCompiler.compile(project, context, CompilerActionInfo(project.directory, testDependencies(project),
buildDir, compilerArgs) sourceFiles, buildDir, compilerArgs))
} else { } else {
warn("Couldn't find any tests to compile") warn("Couldn't find any tests to compile")
TaskResult() TaskResult()

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.CompilerActionInfo
import com.beust.kobalt.internal.JvmCompiler import com.beust.kobalt.internal.JvmCompiler
import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.* import com.beust.kobalt.maven.*
@ -37,11 +38,10 @@ class KotlinPlugin @Inject constructor(
override fun accept(project: Project) = project is KotlinProject override fun accept(project: Project) = project is KotlinProject
override fun doCompile(project: Project, classpath: List<IClasspathDependency>, sourceFiles: List<String>, override fun doCompile(project: Project, cai: CompilerActionInfo) : TaskResult {
buildDirectory: File) : TaskResult {
val result = val result =
if (sourceFiles.size > 0) { if (cai.sourceFiles.size > 0) {
compilePrivate(project, classpath, sourceFiles, buildDirectory) compilePrivate(project, cai.dependencies, cai.sourceFiles, cai.outputDir)
lp(project, "Compilation succeeded") lp(project, "Compilation succeeded")
TaskResult() TaskResult()
} else { } else {
@ -51,7 +51,12 @@ class KotlinPlugin @Inject constructor(
return result 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 { fun taskCompileTest(project: Project): TaskResult {
copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST) copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST)
val projectDir = File(project.directory) val projectDir = File(project.directory)