1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -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)
: TaskResult {
File(info.outputDir).mkdirs()
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>,
val sourceFiles: List<String>, val outputDir: String, val compilerArgs: List<String>)
val sourceFiles: List<String>, val outputDir: File, val compilerArgs: List<String>)
interface ICompilerAction {
fun compile(info: CompilerActionInfo): TaskResult

View file

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

View file

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

View file

@ -1,9 +1,9 @@
package com.beust.kobalt.misc
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.homeDir
import com.beust.kobalt.kotlin.BuildFile
import com.beust.kobalt.SystemProperties
import java.io.File
import java.io.IOException
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 makeDir(dir: String, s: String) : File {
val result = File(dir, s)
result.mkdirs()
return result
}
fun makeDir(dir: String, s: String? = null) =
(if (s != null) File(dir, s) else File(dir)).apply { mkdirs() }
public fun findRecursively(rootDir: File) : List<String> =
findRecursively(rootDir, arrayListOf(), { s -> true })
@ -192,5 +189,4 @@ public class KFiles {
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 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
}

View file

@ -16,15 +16,12 @@ import java.io.File
@Singleton
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
val compilerAction = object : ICompilerAction {
fun compilerAction(executable: File) = object : ICompilerAction {
override fun compile(info: CompilerActionInfo): TaskResult {
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
val javac = jvm.javacExecutable
val allArgs = arrayListOf(
javac!!.absolutePath,
"-d", info.outputDir)
executable.absolutePath,
"-d", info.outputDir.absolutePath)
if (info.dependencies.size > 0) {
allArgs.add("-classpath")
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)
val pb = ProcessBuilder(allArgs)
pb.directory(File(info.outputDir))
pb.directory(info.outputDir)
pb.inheritIO()
val line = allArgs.joinToString(" ")
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().
*/
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)
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
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
@ -59,60 +57,32 @@ public class JavaPlugin @Inject constructor(
@Task(name = TASK_JAVADOC, description = "Run Javadoc")
fun taskJavadoc(project: Project) : TaskResult {
val projectDir = File(project.directory)
val outputDir = File(projectDir,
project.buildDirectory + File.separator + JvmCompilerPlugin.DOCS_DIRECTORY)
outputDir.mkdirs()
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
val javadoc = jvm.javadocExecutable
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")
val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories)
val buildDir = File(projectDir,
project.buildDirectory + File.separator + JvmCompilerPlugin.DOCS_DIRECTORY).apply { mkdirs() }
return javaCompiler.javadoc(project, context, project.compileDependencies, sourceFiles,
buildDir, compilerArgs)
}
@Task(name = TASK_COMPILE, description = "Compile the project")
fun taskCompile(project: Project) : TaskResult {
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
val projectDir = File(project.directory)
val buildDir = File(projectDir,
project.buildDirectory + File.separator + "classes")
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)
return javaCompiler.compile(project, context, classpath, sourceFiles, buildDir.absolutePath, compilerArgs)
val sourceFiles = findSourceFiles(project.directory, project.sourceDirectories)
val buildDir = File(projectDir, project.buildDirectory + File.separator + "classes")
return javaCompiler.compile(project, context, project.compileDependencies, sourceFiles,
buildDir, compilerArgs)
}
@Task(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf("compile"))
fun taskCompileTest(project: Project): TaskResult {
copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST)
val projectDir = File(project.directory)
val sourceFiles = files.findRecursively(projectDir, project.sourceDirectoriesTest.map { File(it) })
{ it: String -> it.endsWith(".java") }
.map { File(projectDir, it).absolutePath }
val sourceFiles = findSourceFiles(project.directory, project.sourceDirectoriesTest)
val result =
if (sourceFiles.size > 0) {
javaCompiler.compile(project, context, testDependencies(project), sourceFiles,
makeOutputTestDir(project).absolutePath, compilerArgs)
makeOutputTestDir(project), compilerArgs)
} else {
// No files to compile
TaskResult()
@ -120,6 +90,13 @@ public class JavaPlugin @Inject constructor(
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>()
fun addCompilerArgs(vararg args: String) {

View file

@ -33,10 +33,10 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
override fun compile(info: CompilerActionInfo): TaskResult {
log(1, "Compiling ${info.sourceFiles.size} files")
val allArgs : Array<String> = arrayOf(
"-d", info.outputDir,
"-d", info.outputDir.path,
"-classpath", info.dependencies.map {it.jarFile.get()}.joinToString(File.pathSeparator),
*(info.compilerArgs.toTypedArray()),
info.sourceFiles.joinToString(" ")
*(info.sourceFiles.toTypedArray())
)
log(2, "Calling kotlinc " + allArgs.joinToString(" "))
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().
*/
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 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) }
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)
}
}
@ -81,7 +81,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){
val classpath = arrayListOf<String>()
val dependencies = arrayListOf<IClasspathDependency>()
var source = arrayListOf<String>()
var output: String by Delegates.notNull()
var output: File by Delegates.notNull()
val args = arrayListOf<String>()
fun sourceFiles(s: String) = source.add(s)

View file

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