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

Fix Javadoc generation.

This commit is contained in:
Cedric Beust 2017-01-04 15:19:34 -08:00
parent 8589c46b43
commit 5609bb27aa
13 changed files with 115 additions and 59 deletions

View file

@ -143,7 +143,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
dependencies {
// Used by the plugins
compile("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.3")
compile("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.5")
// Used by the main app
compile("com.github.spullara.mustache.java:compiler:0.9.1",
@ -157,7 +157,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
"com.squareup.retrofit2:retrofit:${Versions.retrofit}",
"com.squareup.retrofit2:converter-gson:${Versions.retrofit}",
"com.squareup.okhttp3:okhttp-ws:${Versions.okhttp}",
"org.codehaus.plexus:plexus-utils:3.0.22",
"org.codehaus.plexus:plexus-utils:4.0",
"biz.aQute.bnd:bndlib:2.4.0",
"com.squareup.okhttp3:logging-interceptor:3.2.0",

View file

@ -3,13 +3,27 @@ package com.beust.kobalt.api
/**
* Plugins that add compiler flags.
*/
interface ICompilerFlagContributor : IContributor {
fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
suffixesBeingCompiled: List<String>): List<String>
val flagPriority: Int
get() = DEFAULT_FLAG_PRIORITY
class FlagContributor(val flagPriority: Int = DEFAULT_FLAG_PRIORITY,
val closure: (project: Project, context: KobaltContext, currentFlags: List<String>,
suffixesBeingCompiled: List<String>) -> List<String>) : IContributor {
companion object {
val DEFAULT_FLAG_PRIORITY = 20
}
fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
suffixesBeingCompiled: List<String>) = closure(project, context, currentFlags, suffixesBeingCompiled)
}
interface IFlagBase {
val flagPriority: Int get() = FlagContributor.DEFAULT_FLAG_PRIORITY
}
interface ICompilerFlagContributor : IContributor, IFlagBase {
fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
suffixesBeingCompiled: List<String>): List<String>
}
interface IDocFlagContributor : IContributor, IFlagBase {
fun docFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
suffixesBeingCompiled: List<String>): List<String>
}

View file

@ -12,7 +12,7 @@ abstract class BaseJvmPlugin<T>(open val configActor: ConfigActor<T>) :
ICompilerFlagContributor {
companion object {
// Run before other flag contributors
val FLAG_CONTRIBUTOR_PRIORITY = ICompilerFlagContributor.DEFAULT_FLAG_PRIORITY - 10
val FLAG_CONTRIBUTOR_PRIORITY = FlagContributor.DEFAULT_FLAG_PRIORITY - 10
}
protected fun maybeCompilerArgs(sourceSuffixes: List<String>, suffixesBeingCompiled: List<String>,
@ -21,14 +21,14 @@ abstract class BaseJvmPlugin<T>(open val configActor: ConfigActor<T>) :
override val flagPriority = FLAG_CONTRIBUTOR_PRIORITY
override fun accept(project: Project) = hasSourceFiles(project)
override fun accept(project: Project) = sourceFileCount(project) > 0
// IBuildConfigContributor
private fun hasSourceFiles(project: Project)
= KFiles.findSourceFiles(project.directory, project.sourceDirectories, sourceSuffixes()).size > 0
protected fun sourceFileCount(project: Project)
= KFiles.findSourceFiles(project.directory, project.sourceDirectories, sourceSuffixes()).size
fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
fun affinity(project: Project) = sourceFileCount(project)
abstract fun sourceSuffixes() : List<String>
}

View file

@ -229,4 +229,25 @@ class CompilerUtils @Inject constructor(val files: KFiles,
private fun isDependencyExcluded(id: IClasspathDependency, excluded: List<IClasspathDependency>)
= excluded.any { id.id.startsWith(it.id) }
fun sourceCompilerFlags(project: Project?, context: KobaltContext, info: CompilerActionInfo) : List<String> {
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 compilerFlags(project, context, info, adapters)
}
fun compilerFlags(project: Project?, context: KobaltContext, info: CompilerActionInfo,
adapters: List<FlagContributor>) : List<String> {
val result = arrayListOf<String>()
if (project != null) {
adapters.sortedBy { it.flagPriority }
adapters.forEach {
result.addAll(it.flagsFor(project, context, result, info.suffixesBeingCompiled))
}
}
return result
}
}

View file

@ -15,13 +15,12 @@ import java.util.*
* Also validates the classpath and run all the contributors.
*/
class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) {
/**
* Take the given CompilerActionInfo and enrich it with all the applicable contributors and
* then pass it to the ICompilerAction.
*/
fun doCompile(project: Project?, context: KobaltContext?, action: ICompilerAction, info: CompilerActionInfo)
: TaskResult {
fun doCompile(project: Project?, context: KobaltContext?, action: ICompilerAction, info: CompilerActionInfo,
flags: List<String>): TaskResult {
// Dependencies
val allDependencies = (info.dependencies
@ -30,16 +29,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
// Plugins that add flags to the compiler
val currentFlags = arrayListOf<String>().apply { addAll(info.compilerArgs) }
val contributorFlags : List<String> = if (project != null) {
val contributors = context.pluginInfo.compilerFlagContributors
contributors.sortBy { it.flagPriority }
context.pluginInfo.compilerFlagContributors.forEach {
currentFlags.addAll(it.flagsFor(project, context, currentFlags, info.suffixesBeingCompiled))
}
currentFlags
} else {
emptyList()
}
val contributorFlags : List<String> = if (project != null) flags else emptyList()
val addedFlags = contributorFlags + ArrayList(info.compilerArgs)

View file

@ -150,8 +150,7 @@ open class JvmCompilerPlugin @Inject constructor(
val results = arrayListOf<TaskResult>()
val compilerContributors = context.pluginInfo.compilerContributors
ActorUtils.selectAffinityActors(project, context,
context.pluginInfo.compilerContributors)
ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
var failedResult: TaskResult? = null
if (compilerContributors.isEmpty()) {

View file

@ -98,6 +98,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
val localMavenRepoPathInterceptors = arrayListOf<ILocalMavenRepoPathInterceptor>()
val buildListeners = arrayListOf<IBuildListener>()
val buildReportContributors = arrayListOf<IBuildReportContributor>()
val docFlagContributors = arrayListOf<IDocFlagContributor>()
// Note: intentionally repeating them here even though they are defined by our base class so
// that this class always contains the full list of contributors and interceptors
@ -216,6 +217,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
if (this is ILocalMavenRepoPathInterceptor) localMavenRepoPathInterceptors.add(this)
if (this is IBuildListener) buildListeners.add(this)
if (this is IBuildReportContributor) buildReportContributors.add(this)
if (this is IDocFlagContributor) docFlagContributors.add(this)
}
}
}
@ -230,11 +232,9 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
taskContributors, incrementalTaskContributors, assemblyContributors,
incrementalAssemblyContributors, testJvmFlagInterceptors,
jvmFlagContributors, localMavenRepoPathInterceptors, buildListeners,
buildReportContributors
buildReportContributors, docFlagContributors
).forEach {
it.forEach {
it.cleanUpActors()
}
it.forEach(IPluginActor::cleanUpActors)
}
}
@ -273,6 +273,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
localMavenRepoPathInterceptors.addAll(pluginInfo.localMavenRepoPathInterceptors)
buildListeners.addAll(pluginInfo.buildListeners)
buildReportContributors.addAll(pluginInfo.buildReportContributors)
docFlagContributors.addAll(pluginInfo.docFlagContributors)
}
}

View file

@ -192,6 +192,7 @@ class TaskManager @Inject constructor(val args: Args,
= TaskAnnotation(method, plugin, ta.name, ta.description, ta.group, ta.dependsOn, ta.reverseDependsOn,
ta.runBefore, ta.runAfter, ta.alwaysRunAfter,
{ project ->
Kobalt.context?.variant = Variant()
method.invoke(plugin, project) as TaskResult
})

View file

@ -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()

View file

@ -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!!)
fun javadoc(project: Project?, context: KobaltContext?, cai: CompilerActionInfo) : TaskResult
= run(project, context, cai, JavaInfo.create(File(SystemProperties.javaBase)).javadocExecutable!!)
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, 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))
}
}

View file

@ -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)

View file

@ -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())
}
}

View file

@ -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>()
//