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

Move javadoc under ICompilerAction.

This commit is contained in:
Cedric Beust 2015-10-30 17:38:51 -07:00
parent 7bd0e57772
commit 6714a24c6a
9 changed files with 52 additions and 77 deletions

View file

@ -20,7 +20,6 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
*/ */
fun doCompile(project: Project?, context: KobaltContext?, action: ICompilerAction, info: CompilerActionInfo) fun doCompile(project: Project?, context: KobaltContext?, action: ICompilerAction, info: CompilerActionInfo)
: TaskResult { : TaskResult {
File(info.outputDir).mkdirs()
val allDependencies = info.dependencies + calculateDependencies(project, context, info.dependencies) val allDependencies = info.dependencies + calculateDependencies(project, context, info.dependencies)
@ -64,7 +63,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
} }
data class CompilerActionInfo(val dependencies: List<IClasspathDependency>, data class CompilerActionInfo(val dependencies: List<IClasspathDependency>,
val sourceFiles: List<String>, val outputDir: String, val compilerArgs: List<String>) val sourceFiles: List<String>, val outputDir: File, val compilerArgs: List<String>)
interface ICompilerAction { interface ICompilerAction {
fun compile(info: CompilerActionInfo): TaskResult fun compile(info: CompilerActionInfo): TaskResult

View file

@ -88,8 +88,8 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
classpath(files.kobaltJar) classpath(files.kobaltJar)
classpath(pluginUrls.map { it.file }) classpath(pluginUrls.map { it.file })
sourceFiles(listOf(buildFile.path.toFile().absolutePath)) sourceFiles(listOf(buildFile.path.toFile().absolutePath))
output = buildScriptJarFile.absolutePath output = buildScriptJarFile
}.compile(null /* no projects yet */) }.compile()
} }
} }
@ -154,7 +154,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
kotlinCompilePrivate { kotlinCompilePrivate {
classpath(files.kobaltJar) classpath(files.kobaltJar)
sourceFiles(buildFile.path.toFile().absolutePath) sourceFiles(buildFile.path.toFile().absolutePath)
output = buildScriptJarFile.absolutePath output = File(buildScriptJarFile.absolutePath)
}.compile() }.compile()
} }

View file

@ -1,7 +1,8 @@
package com.beust.kobalt.maven package com.beust.kobalt.maven
import com.beust.kobalt.api.Project
import com.beust.kobalt.SystemProperties import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import com.google.common.base.Preconditions import com.google.common.base.Preconditions
import com.google.inject.assistedinject.Assisted import com.google.inject.assistedinject.Assisted
@ -52,8 +53,8 @@ public class PomGenerator @Inject constructor(@Assisted val project: Project) {
val s = StringWriter() val s = StringWriter()
MavenXpp3Writer().write(s, m) MavenXpp3Writer().write(s, m)
val buildDir = com.beust.kobalt.misc.KFiles.makeDir(project.directory, project.buildDirectory!!) val buildDir = KFiles.makeDir(project.directory, project.buildDirectory!!)
val outputDir = com.beust.kobalt.misc.KFiles.makeDir(buildDir.path, "libs") val outputDir = KFiles.makeDir(buildDir.path, "libs")
val mavenId = MavenId.create(project.group!!, project.artifactId!!, project.packaging, project.version!!) val mavenId = MavenId.create(project.group!!, project.artifactId!!, project.packaging, project.version!!)
val pomFile = SimpleDep(mavenId).toPomFileName() val pomFile = SimpleDep(mavenId).toPomFileName()
val outputFile = File(outputDir, pomFile) val outputFile = File(outputDir, pomFile)

View file

@ -1,9 +1,9 @@
package com.beust.kobalt.misc package com.beust.kobalt.misc
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.homeDir import com.beust.kobalt.homeDir
import com.beust.kobalt.kotlin.BuildFile import com.beust.kobalt.kotlin.BuildFile
import com.beust.kobalt.SystemProperties
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.nio.file.Files import java.nio.file.Files
@ -57,11 +57,8 @@ public class KFiles {
public fun joinDir(vararg ts: String): String = ts.toArrayList().joinToString(File.separator) public fun joinDir(vararg ts: String): String = ts.toArrayList().joinToString(File.separator)
public fun makeDir(dir: String, s: String) : File { fun makeDir(dir: String, s: String? = null) =
val result = File(dir, s) (if (s != null) File(dir, s) else File(dir)).apply { mkdirs() }
result.mkdirs()
return result
}
public fun findRecursively(rootDir: File) : List<String> = public fun findRecursively(rootDir: File) : List<String> =
findRecursively(rootDir, arrayListOf(), { s -> true }) findRecursively(rootDir, arrayListOf(), { s -> true })
@ -192,5 +189,4 @@ public class KFiles {
os.close() os.close()
} }
} }
} }

View file

@ -146,7 +146,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) :
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()
javaCompiler.compile(project, context, listOf(), sourceFiles, buildDir.absolutePath, listOf()) javaCompiler.compile(project, context, listOf(), sourceFiles, buildDir, listOf())
return buildDir return buildDir
} }

View file

@ -16,15 +16,12 @@ import java.io.File
@Singleton @Singleton
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) { class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
val compilerAction = object : ICompilerAction { fun compilerAction(executable: File) = object : ICompilerAction {
override fun compile(info: CompilerActionInfo): TaskResult { override fun compile(info: CompilerActionInfo): TaskResult {
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
val javac = jvm.javacExecutable
val allArgs = arrayListOf( val allArgs = arrayListOf(
javac!!.absolutePath, executable.absolutePath,
"-d", info.outputDir) "-d", info.outputDir.absolutePath)
if (info.dependencies.size > 0) { if (info.dependencies.size > 0) {
allArgs.add("-classpath") allArgs.add("-classpath")
allArgs.add(info.dependencies.map {it.jarFile.get()}.joinToString(File.pathSeparator)) allArgs.add(info.dependencies.map {it.jarFile.get()}.joinToString(File.pathSeparator))
@ -33,7 +30,7 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
allArgs.addAll(info.sourceFiles) allArgs.addAll(info.sourceFiles)
val pb = ProcessBuilder(allArgs) val pb = ProcessBuilder(allArgs)
pb.directory(File(info.outputDir)) pb.directory(info.outputDir)
pb.inheritIO() pb.inheritIO()
val line = allArgs.joinToString(" ") val line = allArgs.joinToString(" ")
log(1, " Compiling ${info.sourceFiles.size} files with classpath size " + info.dependencies.size) log(1, " Compiling ${info.sourceFiles.size} files with classpath size " + info.dependencies.size)
@ -50,9 +47,16 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
* Create an ICompilerAction based on the parameters and send it to JvmCompiler.doCompile(). * Create an ICompilerAction based on the parameters and send it to JvmCompiler.doCompile().
*/ */
fun compile(project: Project?, context: KobaltContext?, dependencies: List<IClasspathDependency>, fun compile(project: Project?, context: KobaltContext?, dependencies: List<IClasspathDependency>,
sourceFiles: List<String>, outputDir: String, args: List<String>) : TaskResult { sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult {
val info = CompilerActionInfo(dependencies, sourceFiles, outputDir, args) val info = CompilerActionInfo(dependencies, sourceFiles, outputDir, args)
return jvmCompiler.doCompile(project, context, compilerAction, info) val jvm = JavaInfo.create(File(SystemProperties.javaBase))
return jvmCompiler.doCompile(project, context, compilerAction(jvm.javacExecutable!!), info)
}
fun javadoc(project: Project?, context: KobaltContext?, dependencies: List<IClasspathDependency>,
sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult {
val info = CompilerActionInfo(dependencies, sourceFiles, outputDir, args)
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
return jvmCompiler.doCompile(project, context, compilerAction(jvm.javadocExecutable!!), info)
} }
} }

View file

@ -1,7 +1,5 @@
package com.beust.kobalt.plugin.java package com.beust.kobalt.plugin.java
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Kobalt 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
@ -59,60 +57,32 @@ public class JavaPlugin @Inject constructor(
@Task(name = TASK_JAVADOC, description = "Run Javadoc") @Task(name = TASK_JAVADOC, description = "Run Javadoc")
fun taskJavadoc(project: Project) : TaskResult { fun taskJavadoc(project: Project) : TaskResult {
val projectDir = File(project.directory) val projectDir = File(project.directory)
val outputDir = File(projectDir, val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories)
project.buildDirectory + File.separator + JvmCompilerPlugin.DOCS_DIRECTORY) val buildDir = File(projectDir,
outputDir.mkdirs() project.buildDirectory + File.separator + JvmCompilerPlugin.DOCS_DIRECTORY).apply { mkdirs() }
val jvm = JavaInfo.create(File(SystemProperties.javaBase)) return javaCompiler.javadoc(project, context, project.compileDependencies, sourceFiles,
val javadoc = jvm.javadocExecutable buildDir, compilerArgs)
val sourceFiles = files.findRecursively(projectDir, project.sourceDirectories.map { File(it) })
{ it: String -> it.endsWith(".java") }
.map { File(projectDir, it).absolutePath }
val classpath = jvmCompiler.calculateDependencies(project, context!!, project.compileDependencies)
val args = arrayListOf(
javadoc!!.absolutePath,
"-classpath", classpath.map { it.jarFile.get().absolutePath }.joinToString(File.pathSeparator),
"-d", outputDir.absolutePath)
val compressed = sourcesToDirectories(sourceFiles, project.sourceSuffix)
args.addAll(compressed)
val pb = ProcessBuilder(args)
pb.directory(File(project.directory))
pb.inheritIO()
val process = pb.start()
val errorCode = process.waitFor()
return if (errorCode == 0) TaskResult(true, "Compilation succeeded")
else TaskResult(false, "There were errors")
} }
@Task(name = TASK_COMPILE, description = "Compile the project") @Task(name = TASK_COMPILE, description = "Compile the project")
fun taskCompile(project: Project) : TaskResult { fun taskCompile(project: Project) : TaskResult {
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN) copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
val projectDir = File(project.directory) val projectDir = File(project.directory)
val buildDir = File(projectDir, val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories)
project.buildDirectory + File.separator + "classes") val buildDir = File(projectDir, project.buildDirectory + File.separator + "classes")
val sourceFiles = files.findRecursively(projectDir, project.sourceDirectories.map { File(it) }) return javaCompiler.compile(project, context, project.compileDependencies, sourceFiles,
{ it: String -> it.endsWith(".java") } buildDir, compilerArgs)
.map { File(projectDir, it).absolutePath }
val classpath = jvmCompiler.calculateDependencies(project, context!!, project.compileDependencies)
return javaCompiler.compile(project, context, classpath, sourceFiles, buildDir.absolutePath, compilerArgs)
} }
@Task(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf("compile")) @Task(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf("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 sourceFiles = findSourceFiles(project.directory, project.sourceDirectoriesTest)
val sourceFiles = files.findRecursively(projectDir, project.sourceDirectoriesTest.map { File(it) })
{ it: String -> it.endsWith(".java") }
.map { File(projectDir, it).absolutePath }
val result = val result =
if (sourceFiles.size > 0) { if (sourceFiles.size > 0) {
javaCompiler.compile(project, context, testDependencies(project), sourceFiles, javaCompiler.compile(project, context, testDependencies(project), sourceFiles,
makeOutputTestDir(project).absolutePath, compilerArgs) makeOutputTestDir(project), compilerArgs)
} else { } else {
// No files to compile // No files to compile
TaskResult() TaskResult()
@ -120,6 +90,13 @@ public class JavaPlugin @Inject constructor(
return result return result
} }
private fun findSourceFiles(dir: String, sourceDirectories: List<String>): List<String> {
val projectDir = File(dir)
return files.findRecursively(projectDir,
sourceDirectories.map { File(it) }) { it: String -> it.endsWith(".java") }
.map { File(projectDir, it).absolutePath }
}
private val compilerArgs = arrayListOf<String>() private val compilerArgs = arrayListOf<String>()
fun addCompilerArgs(vararg args: String) { fun addCompilerArgs(vararg args: String) {

View file

@ -33,10 +33,10 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
override fun compile(info: CompilerActionInfo): TaskResult { override fun compile(info: CompilerActionInfo): TaskResult {
log(1, "Compiling ${info.sourceFiles.size} files") log(1, "Compiling ${info.sourceFiles.size} files")
val allArgs : Array<String> = arrayOf( val allArgs : Array<String> = arrayOf(
"-d", info.outputDir, "-d", info.outputDir.path,
"-classpath", info.dependencies.map {it.jarFile.get()}.joinToString(File.pathSeparator), "-classpath", info.dependencies.map {it.jarFile.get()}.joinToString(File.pathSeparator),
*(info.compilerArgs.toTypedArray()), *(info.compilerArgs.toTypedArray()),
info.sourceFiles.joinToString(" ") *(info.sourceFiles.toTypedArray())
) )
log(2, "Calling kotlinc " + allArgs.joinToString(" ")) log(2, "Calling kotlinc " + allArgs.joinToString(" "))
CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs) CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs)
@ -55,7 +55,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
* Create an ICompilerAction based on the parameters and send it to JvmCompiler.doCompile(). * Create an ICompilerAction based on the parameters and send it to JvmCompiler.doCompile().
*/ */
fun compile(project: Project?, context: KobaltContext?, compileDependencies: List<IClasspathDependency>, fun compile(project: Project?, context: KobaltContext?, compileDependencies: List<IClasspathDependency>,
otherClasspath: List<String>, source: List<String>, outputDir: String, args: List<String>) : TaskResult { otherClasspath: List<String>, sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult {
val executor = executors.newExecutor("KotlinCompiler", 10) val executor = executors.newExecutor("KotlinCompiler", 10)
val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION", executor) val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION", executor)
@ -72,7 +72,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
.map { FileDependency(it) } .map { FileDependency(it) }
val dependencies = compileDependencies + classpathList + otherClasspath.map { FileDependency(it)} val dependencies = compileDependencies + classpathList + otherClasspath.map { FileDependency(it)}
val info = CompilerActionInfo(dependencies, source, outputDir, args) val info = CompilerActionInfo(dependencies, sourceFiles, outputDir, args)
return jvmCompiler.doCompile(project, context, compilerAction, info) return jvmCompiler.doCompile(project, context, compilerAction, info)
} }
} }
@ -81,7 +81,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){
val classpath = arrayListOf<String>() val classpath = arrayListOf<String>()
val dependencies = arrayListOf<IClasspathDependency>() val dependencies = arrayListOf<IClasspathDependency>()
var source = arrayListOf<String>() var source = arrayListOf<String>()
var output: String by Delegates.notNull() var output: File by Delegates.notNull()
val args = arrayListOf<String>() val args = arrayListOf<String>()
fun sourceFiles(s: String) = source.add(s) fun sourceFiles(s: String) = source.add(s)

View file

@ -59,7 +59,7 @@ class KotlinPlugin @Inject constructor(
File(projectDirectory, it).absolutePath File(projectDirectory, it).absolutePath
} }
compilePrivate(project, classpath, absoluteSourceFiles, buildDirectory.absolutePath) compilePrivate(project, classpath, absoluteSourceFiles, buildDirectory)
lp(project, "Compilation succeeded") lp(project, "Compilation succeeded")
return TaskResult() return TaskResult()
} }
@ -79,16 +79,14 @@ class KotlinPlugin @Inject constructor(
compilePrivate(project, testDependencies(project), compilePrivate(project, testDependencies(project),
absoluteSourceFiles, absoluteSourceFiles,
makeOutputTestDir(project).absolutePath) makeOutputTestDir(project))
lp(project, "Compilation of tests succeeded") lp(project, "Compilation of tests succeeded")
return TaskResult() return TaskResult()
} }
private fun compilePrivate(project: Project, cpList: List<IClasspathDependency>, sources: List<String>, private fun compilePrivate(project: Project, cpList: List<IClasspathDependency>, sources: List<String>,
outputDirectory: String): TaskResult { outputDirectory: File): TaskResult {
File(outputDirectory).mkdirs()
log(1, " Compiling ${sources.size} files with classpath size ${cpList.size}") log(1, " Compiling ${sources.size} files with classpath size ${cpList.size}")
return kotlinCompilePrivate { return kotlinCompilePrivate {