mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Fix Javadoc generation.
This commit is contained in:
parent
8589c46b43
commit
5609bb27aa
13 changed files with 115 additions and 59 deletions
|
@ -102,7 +102,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
context.variant.toIntermediateDir())
|
||||
|
||||
// ICompilerFlagContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>): List<String> {
|
||||
if (!suffixesBeingCompiled.contains("java")) return emptyList()
|
||||
|
||||
|
|
|
@ -3,10 +3,8 @@ 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.CompilerActionInfo
|
||||
import com.beust.kobalt.api.ICompiler
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.internal.CompilerUtils
|
||||
import com.beust.kobalt.internal.ICompilerAction
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.internal.ParallelLogger
|
||||
|
@ -22,7 +20,8 @@ import javax.tools.JavaFileObject
|
|||
import javax.tools.ToolProvider
|
||||
|
||||
@Singleton
|
||||
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltLog: ParallelLogger) : ICompiler {
|
||||
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltLog: ParallelLogger,
|
||||
val compilerUtils: CompilerUtils) : ICompiler {
|
||||
fun compilerAction(executable: File) = object : ICompilerAction {
|
||||
override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult {
|
||||
if (info.sourceFiles.isEmpty()) {
|
||||
|
@ -35,11 +34,12 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
|
|||
val compiler = ToolProvider.getSystemJavaCompiler()
|
||||
fun logk(level: Int, message: CharSequence) = kobaltLog.log(projectName ?: "", level, message)
|
||||
val result =
|
||||
if (compiler != null) {
|
||||
if (false) {
|
||||
// if (compiler != null) {
|
||||
logk(2, "Found system Java compiler, using the compiler API")
|
||||
val allArgs = arrayListOf(
|
||||
"-d", KFiles.makeDir(info.directory!!, info.outputDir.path).path)
|
||||
if (info.dependencies.size > 0) {
|
||||
if (info.dependencies.isNotEmpty()) {
|
||||
allArgs.add("-classpath")
|
||||
allArgs.add(info.dependencies.map { it.jarFile.get() }.joinToString(File.pathSeparator))
|
||||
}
|
||||
|
@ -63,12 +63,12 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
|
|||
errorMessage = dc.diagnostics.joinToString("\n")
|
||||
result
|
||||
} else {
|
||||
logk(2, "Didn't find system Java compiler, forking javac")
|
||||
logk(2, "Forking $executable")
|
||||
val allArgs = arrayListOf(
|
||||
executable.absolutePath,
|
||||
"-d", KFiles.makeDir(info.directory!!, info.outputDir.path).path)
|
||||
|
||||
if (info.dependencies.size > 0) {
|
||||
if (info.dependencies.isNotEmpty()) {
|
||||
allArgs.add("-classpath")
|
||||
allArgs.add(info.dependencies.map { it.jarFile.get() }.joinToString(File.pathSeparator))
|
||||
}
|
||||
|
@ -103,13 +103,30 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
|
|||
/**
|
||||
* Invoke the given executable on the CompilerActionInfo.
|
||||
*/
|
||||
private fun run(project: Project?, context: KobaltContext?, cai: CompilerActionInfo, executable: File): TaskResult {
|
||||
return jvmCompiler.doCompile(project, context, compilerAction(executable), cai)
|
||||
private fun run(project: Project?, context: KobaltContext?, cai: CompilerActionInfo, executable: File,
|
||||
flags: List<String>): TaskResult {
|
||||
return jvmCompiler.doCompile(project, context, compilerAction(executable), cai, flags)
|
||||
}
|
||||
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult
|
||||
= run(project, context, info, JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!)
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val adapters = context.pluginInfo.compilerFlagContributors.map {
|
||||
val closure = { project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>
|
||||
-> it.compilerFlagsFor(project, context, currentFlags, suffixesBeingCompiled) }
|
||||
FlagContributor(it.flagPriority, closure)
|
||||
}
|
||||
return run(project, context, info, JavaInfo.create(File(SystemProperties.javaBase)).javacExecutable!!,
|
||||
compilerUtils.compilerFlags(project, context, info, adapters))
|
||||
}
|
||||
|
||||
fun javadoc(project: Project?, context: KobaltContext?, cai: CompilerActionInfo) : TaskResult
|
||||
= run(project, context, cai, JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!)
|
||||
fun javadoc(project: Project?, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val adapters = context.pluginInfo.docFlagContributors.map {
|
||||
val closure = { project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>
|
||||
-> it.docFlagsFor(project, context, currentFlags, suffixesBeingCompiled) }
|
||||
FlagContributor(it.flagPriority, closure)
|
||||
}
|
||||
return run(project, context, info, JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!,
|
||||
compilerUtils.compilerFlags(project, context, info, adapters))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import javax.inject.Singleton
|
|||
@Singleton
|
||||
class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler, override val configActor: ConfigActor<JavaConfig>)
|
||||
: BaseJvmPlugin<JavaConfig>(configActor), IDocContributor, ICompilerContributor,
|
||||
ITestSourceDirectoryContributor, IBuildConfigContributor {
|
||||
ITestSourceDirectoryContributor, IBuildConfigContributor, IDocFlagContributor {
|
||||
|
||||
companion object {
|
||||
val PLUGIN_NAME = "Java"
|
||||
|
@ -24,14 +24,13 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler, override va
|
|||
override val name = PLUGIN_NAME
|
||||
|
||||
// IDocContributor
|
||||
override fun affinity(project: Project, context: KobaltContext) =
|
||||
if (accept(project)) 1 else 0
|
||||
override fun affinity(project: Project, context: KobaltContext) = sourceFileCount(project)
|
||||
|
||||
override fun sourceSuffixes() = SOURCE_SUFFIXES
|
||||
|
||||
override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
if (info.sourceFiles.size > 0) {
|
||||
if (info.sourceFiles.isNotEmpty()) {
|
||||
javaCompiler.javadoc(project, context, info)
|
||||
} else {
|
||||
warn("Couldn't find any source files to run Javadoc on")
|
||||
|
@ -41,15 +40,22 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler, override va
|
|||
}
|
||||
|
||||
// ICompilerFlagsContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) =
|
||||
maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled,
|
||||
configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||
|
||||
// IDocFlagContributor
|
||||
override fun docFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>): List<String> {
|
||||
return listOf("-d", "javadoc", "-Xdoclint:none", "-Xmaxerrs", "1", "-quiet")
|
||||
}
|
||||
|
||||
// ICompilerContributor
|
||||
val compiler = CompilerDescription(PLUGIN_NAME, "java", SOURCE_SUFFIXES, javaCompiler)
|
||||
|
||||
override fun compilersFor(project: Project, context: KobaltContext) = listOf(compiler)
|
||||
override fun compilersFor(project: Project, context: KobaltContext)
|
||||
= if (sourceFileCount(project) > 0) listOf(compiler) else emptyList()
|
||||
|
||||
// ITestSourceDirectoryContributor
|
||||
override fun testSourceDirectoriesFor(project: Project, context: KobaltContext)
|
||||
|
|
|
@ -31,7 +31,7 @@ class KotlinCompiler @Inject constructor(
|
|||
val executors: KobaltExecutors,
|
||||
val settings: KobaltSettings,
|
||||
val jvmCompiler: JvmCompiler,
|
||||
val kotlinJarFiles: KotlinJarFiles,
|
||||
val compilerUtils: CompilerUtils,
|
||||
val kobaltLog: ParallelLogger) {
|
||||
|
||||
val compilerAction = object: ICompilerAction {
|
||||
|
@ -93,6 +93,10 @@ class KotlinCompiler @Inject constructor(
|
|||
+ " -classpath " + args.classpath
|
||||
+ " " + sourceFiles.joinToString(" "))
|
||||
val collector = object : MessageCollector {
|
||||
override fun clear() {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
|
||||
override fun hasErrors(): Boolean {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
|
@ -214,7 +218,8 @@ class KotlinCompiler @Inject constructor(
|
|||
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args,
|
||||
friendPaths)
|
||||
|
||||
return jvmCompiler.doCompile(project, context, compilerAction, info)
|
||||
return jvmCompiler.doCompile(project, context, compilerAction, info,
|
||||
if (context != null) compilerUtils.sourceCompilerFlags(project, context, info) else emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,10 +40,11 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
|
|||
}
|
||||
|
||||
// ICompilerFlagsContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) : List<String> {
|
||||
val args = (configurationFor(project)?.compilerArgs ?: listOf<String>()) + "-no-stdlib"
|
||||
return maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled, args)
|
||||
val result = maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled, args)
|
||||
return result
|
||||
}
|
||||
|
||||
// override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
|
@ -113,7 +114,8 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
|
|||
val compiler = CompilerDescription(PLUGIN_NAME, "kotlin", SOURCE_SUFFIXES, KotlinCompiler(),
|
||||
ICompilerDescription.DEFAULT_PRIORITY - 5, canCompileDirectories = false)
|
||||
|
||||
override fun compilersFor(project: Project, context: KobaltContext) = arrayListOf(compiler)
|
||||
override fun compilersFor(project: Project, context: KobaltContext)
|
||||
= if (sourceFileCount(project) > 0) listOf(compiler) else emptyList()
|
||||
|
||||
// private val dokkaConfigurations = ArrayListMultimap.create<String, DokkaConfig>()
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue