diff options
-rw-r--r-- | runners/maven-plugin/build.gradle | 14 | ||||
-rw-r--r-- | runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 233 |
2 files changed, 150 insertions, 97 deletions
diff --git a/runners/maven-plugin/build.gradle b/runners/maven-plugin/build.gradle index 5fd06901..76fab68d 100644 --- a/runners/maven-plugin/build.gradle +++ b/runners/maven-plugin/build.gradle @@ -13,8 +13,8 @@ sourceCompatibility = 1.8 tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { kotlinOptions { freeCompilerArgs += "-Xjsr305=strict" - languageVersion = language_version - apiVersion = language_version + languageVersion = "1.2" + apiVersion = languageVersion jvmTarget = "1.8" } } @@ -52,10 +52,10 @@ task setupMaven(type: Sync) { def mavenBuildDir = "$buildDir/maven" -//sourceSets.main.resources { -// srcDirs += "$mavenBuildDir/classes/java/main" -// exclude "**/*.class" -//} +sourceSets.main.resources { + srcDirs += "$mavenBuildDir/classes/java/main" + exclude "**/*.class" +} task generatePom() { inputs.file(new File(projectDir, "pom.tpl.xml")) @@ -124,7 +124,7 @@ task pluginDescriptor(type: CrossPlatformExec, dependsOn: setupMaven) { //mergeClassOutputs.dependsOn compileKotlin //helpMojo.dependsOn mergeClassOutputs helpMojo.dependsOn generatePom -//sourceSets.main.java.srcDir("$buildDir/maven/generated-sources/plugin") +sourceSets.main.java.srcDir("$buildDir/maven/generated-sources/plugin") compileJava.dependsOn helpMojo processResources.dependsOn pluginDescriptor diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index 83ee17d4..ca3a65fd 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -14,23 +14,23 @@ import org.jetbrains.dokka.* import java.io.File import java.net.URL -class SourceLinkMapItem { - @Parameter(name = "dir", required = true) - var dir: String = "" +class SourceLinkMapItem : DokkaConfiguration.SourceLinkDefinition { + @Parameter(name = "path", required = true) + override var path: String = "" @Parameter(name = "url", required = true) - var url: String = "" + override var url: String = "" - @Parameter(name = "urlSuffix") - var urlSuffix: String? = null + @Parameter(name = "lineSuffix") + override var lineSuffix: String? = null } -class ExternalDocumentationLinkBuilder : DokkaConfiguration.ExternalDocumentationLink.Builder() { +class ExternalDocumentationLink : DokkaConfiguration.ExternalDocumentationLink { @Parameter(name = "url", required = true) - override var url: URL? = null + override var url: URL = URL("") @Parameter(name = "packageListUrl", required = true) - override var packageListUrl: URL? = null + override var packageListUrl: URL = URL("") } abstract class AbstractDokkaMojo : AbstractMojo() { @@ -52,125 +52,178 @@ abstract class AbstractDokkaMojo : AbstractMojo() { override var suppress: Boolean = false } - @Parameter(required = true, defaultValue = "\${project.compileSourceRoots}") - var sourceDirectories: List<String> = emptyList() + class Multiplatform : DokkaConfiguration.PassConfiguration { + @Parameter(required = true, defaultValue = "\${project.compileSourceRoots}") + var sourceDirectories: List<String> = emptyList() - @Parameter - var sourceRoots: List<SourceRoot> = emptyList() + @Parameter(required = true, defaultValue = "\${project.artifactId}") + override var moduleName: String = "" - @Parameter - var samplesDirs: List<String> = emptyList() + @Parameter(required = true, defaultValue = "\${project.compileClasspathElements}") + override var classpath: List<String> = emptyList() - @Parameter - var includes: List<String> = emptyList() + @Parameter + override var sourceRoots: List<SourceRoot> = emptyList() - @Parameter(required = true, defaultValue = "\${project.compileClasspathElements}") - var classpath: List<String> = emptyList() + @Parameter + override val samples: List<String> = emptyList() - @Parameter - var sourceLinks: Array<SourceLinkMapItem> = emptyArray() + @Parameter + override val includes: List<String> = emptyList() - @Parameter(required = true, defaultValue = "\${project.artifactId}") - var moduleName: String = "" + @Parameter + override val includeNonPublic: Boolean = false - @Parameter(required = false, defaultValue = "false") - var skip: Boolean = false + @Parameter + override val includeRootPackage: Boolean = false - @Parameter(required = false, defaultValue = "6") - var jdkVersion: Int = 6 + @Parameter + override val reportUndocumented: Boolean = true + @Parameter + override val skipEmptyPackages: Boolean = true - @Parameter - var skipDeprecated = false - @Parameter - var skipEmptyPackages = true - @Parameter - var reportUndocumented = true + @Parameter + override val skipDeprecated: Boolean = false - @Parameter - var impliedPlatforms: List<String> = emptyList() + @Parameter(required = false, defaultValue = "6") + override var jdkVersion: Int = 6 - @Parameter - var perPackageOptions: List<PackageOptions> = emptyList() + @Parameter + override val sourceLinks: List<SourceLinkMapItem> = emptyList() - @Parameter - var externalDocumentationLinks: List<ExternalDocumentationLinkBuilder> = emptyList() + @Parameter + override val perPackageOptions: List<PackageOptions> = emptyList() - @Parameter(defaultValue = "false") - var noStdlibLink: Boolean = false + @Parameter + override val externalDocumentationLinks: List<ExternalDocumentationLink> = emptyList() - @Parameter(defaultValue = "false") - var noJdkLink: Boolean = false + @Parameter + override val languageVersion: String? = null + + @Parameter + override val apiVersion: String? = null + + @Parameter(defaultValue = "false") + override var noStdlibLink: Boolean = false + + @Parameter(defaultValue = "false") + override var noJdkLink: Boolean = false + + @Parameter + override val suppressedFiles: List<String> = emptyList() + + @Parameter + override val collectInheritedExtensionsFromLibraries: Boolean = false + + override var analysisPlatform: Platform = Platform.DEFAULT + + @Parameter + val platform: String = "" + + @Parameter + override val targets: List<String> = emptyList() + + @Parameter + override val sinceKotlin: String = "1.0" + } @Parameter - var cacheRoot: String? = null + var multiplatform: List<Multiplatform> = emptyList() @Parameter - var languageVersion: String? = null + var config: Multiplatform? = null + + @Parameter(required = true, defaultValue = "\${project.artifactId}") + var moduleName: String = "" @Parameter - var apiVersion: String? = null + var impliedPlatforms: List<String> = emptyList() //TODO check + + @Parameter + var cacheRoot: String? = null protected abstract fun getOutDir(): String + protected abstract fun getOutFormat(): String + @Parameter(required = false, defaultValue = "false") + var skip: Boolean = false + + @Parameter(required = true, defaultValue = "\${project.compileClasspathElements}") + var classpath: List<String> = emptyList() + + //TODO remove + @Parameter(required = true, defaultValue = "\${project.compileSourceRoots}") + var sourceDirectories: List<String> = emptyList() + @Parameter(required = false, defaultValue = "6") + val jdkVersion: Int = 6 + @Parameter(defaultValue = "false") + val noStdlibLink: Boolean = false + @Parameter(defaultValue = "false") + val noJdkLink: Boolean = false + override fun execute() { if (skip) { log.info("Dokka skip parameter is true so no dokka output will be produced") return } - sourceLinks.forEach { - if (it.dir.contains("\\")) { - throw MojoExecutionException("Incorrect dir property, only Unix based path allowed.") + val passConfigurationList = ( + if (multiplatform.isEmpty() && config != null) listOf(config!!) else multiplatform + ).map { + defaultPassConfiguration(it) + } + + passConfigurationList.flatMap { it.sourceLinks }.forEach { + if (it.path.contains("\\")) { + throw MojoExecutionException("Incorrect path property, only Unix based path allowed.") } } - val passConfiguration = PassConfigurationImpl( - classpath = classpath, - sourceRoots = sourceDirectories.map { SourceRootImpl(it) } + sourceRoots.map { SourceRootImpl(path = it.path) }, - samples = samplesDirs, - includes = includes, - collectInheritedExtensionsFromLibraries = false, // TODO: Should we implement this? - sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.dir, it.url, it.urlSuffix) }, - jdkVersion = jdkVersion, - skipDeprecated = skipDeprecated, - skipEmptyPackages = skipEmptyPackages, - reportUndocumented = reportUndocumented, - perPackageOptions = perPackageOptions.map { - PackageOptionsImpl( - prefix = it.prefix, - includeNonPublic = it.includeNonPublic, - reportUndocumented = it.reportUndocumented, - skipDeprecated = it.skipDeprecated, - suppress = it.suppress - )}, - externalDocumentationLinks = externalDocumentationLinks.map { it.build() as ExternalDocumentationLinkImpl }, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, - languageVersion = languageVersion, - apiVersion = apiVersion, - moduleName = moduleName, - suppressedFiles = emptyList(), // TODO: Should we implement this? - sinceKotlin = "1.0", // TODO: Should we implement this? - analysisPlatform = Platform.DEFAULT, // TODO: Should we implement this? - targets = emptyList(), // TODO: Should we implement this? - includeNonPublic = false, // TODO: Should we implement this? - includeRootPackage = false // TODO: Should we implement this? - ) - - val configuration = DokkaConfigurationImpl( - outputDir = getOutDir(), - format = getOutFormat(), - impliedPlatforms = impliedPlatforms, - cacheRoot = cacheRoot, - passesConfigurations = listOf(passConfiguration), - generateIndexPages = false // TODO: Should we implement this? - ) + val platforms = impliedPlatforms + val cacheRoot = cacheRoot + + val configuration = object : DokkaConfiguration { + override val outputDir = getOutDir() + override val format = getOutFormat() + override val impliedPlatforms = platforms + override val cacheRoot = cacheRoot + override val passesConfigurations = passConfigurationList + override val generateIndexPages = false // TODO: Should we implement this? + } val gen = DokkaGenerator(configuration, MavenDokkaLogger(log)) gen.generate() } + + private fun defaultPassConfiguration(passConfig: Multiplatform): Multiplatform { + passConfig.moduleName = moduleName + passConfig.classpath = classpath + passConfig.externalDocumentationLinks.map { + val builder = DokkaConfiguration.ExternalDocumentationLink.Builder(it.url, it.packageListUrl) + builder.build() + } + if(passConfig.platform.isNotEmpty()){ + passConfig.analysisPlatform = Platform.fromString(passConfig.platform) + } + // TODO fix + passConfig.sourceRoots = sourceDirectories.map { + val sourceRoot = SourceRoot() + sourceRoot.path = it + sourceRoot + } + passConfig.sourceRoots + passConfig.jdkVersion = jdkVersion + passConfig.noStdlibLink = noStdlibLink + passConfig.noJdkLink = noJdkLink +// passConfig.sourceRoots = passConfig.sourceDirectories.map { +// val sourceRoot = SourceRoot() +// sourceRoot.path = it +// sourceRoot +// } + passConfig.sourceRoots + + return passConfig + } } @Mojo(name = "dokka", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) |