diff options
Diffstat (limited to 'runners/maven-plugin')
-rw-r--r-- | runners/maven-plugin/build.gradle | 80 | ||||
-rw-r--r-- | runners/maven-plugin/pom.tpl.xml | 26 | ||||
-rw-r--r-- | runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 179 | ||||
-rw-r--r-- | runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt | 18 |
4 files changed, 303 insertions, 0 deletions
diff --git a/runners/maven-plugin/build.gradle b/runners/maven-plugin/build.gradle new file mode 100644 index 00000000..c0b9df2e --- /dev/null +++ b/runners/maven-plugin/build.gradle @@ -0,0 +1,80 @@ + +apply plugin: 'kotlin' +apply plugin: 'com.github.johnrengelman.shadow' + + +configurations { + provided +} + +tasks.withType(AbstractCompile) { + classpath += configurations.provided + classpath += configurations.shadow +} + +dependencies { + shadow project(":runners:fatjar") + shadow "org.apache.maven:maven-core:$maven_version" + shadow "org.apache.maven:maven-model:$maven_version" + shadow "org.apache.maven:maven-plugin-api:$maven_version" + shadow "org.apache.maven:maven-archiver:$maven_archiver_version" + shadow "org.codehaus.plexus:plexus-utils:$plexus_utils_version" + shadow "org.codehaus.plexus:plexus-archiver:$plexus_archiver_version" + shadow "org.apache.maven.plugin-tools:maven-plugin-annotations:$maven_plugin_tools_version" +} + +task generatePom << { + final pomTemplate = new File(projectDir, "pom.tpl.xml") + final pom = new File(buildDir, "pom.xml") + pom.text = pomTemplate.text.replace("<version>dokka_version</version>", "<version>$dokka_version</version>") + .replace("<maven.version></maven.version>", "<maven.version>$maven_version</maven.version>") + .replace("<version>maven-plugin-plugin</version>", "<version>$maven_plugin_tools_version</version>") +} + +task pluginDescriptor(type: Exec) { + workingDir buildDir + commandLine 'mvn', '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:descriptor' +} + +task helpMojo(type: Exec) { + workingDir buildDir + commandLine 'mvn', '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:helpmojo' +} + + +helpMojo.dependsOn generatePom +sourceSets.main.java.srcDir("$buildDir/generated-sources/plugin") +compileJava.dependsOn helpMojo + +pluginDescriptor.dependsOn generatePom + +shadowJar { + baseName = 'dokka-maven-plugin' + classifier = '' + + relocate('kotlin.', 'dokkakotlin.') +} + +shadowJar.dependsOn pluginDescriptor + + +task sourceJar(type: Jar) { + from sourceSets.main.allSource +} + +apply plugin: 'maven-publish' + +publishing { + publications { + dokkaMavenPlugin(MavenPublication) { + from components.shadow + artifactId = 'dokka-maven-plugin' + + artifact sourceJar { + classifier "sources" + } + } + } +} + +bintrayPublication(project, ['dokkaMavenPlugin'])
\ No newline at end of file diff --git a/runners/maven-plugin/pom.tpl.xml b/runners/maven-plugin/pom.tpl.xml new file mode 100644 index 00000000..3b5afd74 --- /dev/null +++ b/runners/maven-plugin/pom.tpl.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.jetbrains.dokka</groupId> + <artifactId>dokka-maven-plugin</artifactId> + <version>dokka_version</version> + <packaging>maven-plugin</packaging> + <properties> + <maven.version></maven.version> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>maven-plugin-plugin</version> + <configuration> + <helpPackageName>org.jetbrains.dokka.maven</helpPackageName> + </configuration> + </plugin> + </plugins> + <directory>./</directory> + <outputDirectory>classes/main</outputDirectory> + </build> +</project> diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt new file mode 100644 index 00000000..899d2dde --- /dev/null +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -0,0 +1,179 @@ +package org.jetbrains.dokka.maven + +import org.apache.maven.archiver.MavenArchiveConfiguration +import org.apache.maven.archiver.MavenArchiver +import org.apache.maven.execution.MavenSession +import org.apache.maven.plugin.AbstractMojo +import org.apache.maven.plugins.annotations.* +import org.apache.maven.project.MavenProject +import org.apache.maven.project.MavenProjectHelper +import org.jetbrains.dokka.DokkaGenerator +import org.jetbrains.dokka.SourceLinkDefinition +import org.jetbrains.dokka.DocumentationOptions +import org.codehaus.plexus.archiver.Archiver +import org.codehaus.plexus.archiver.jar.JarArchiver +import java.io.File + +class SourceLinkMapItem { + @Parameter(name = "dir", required = true) + var dir: String = "" + + @Parameter(name = "url", required = true) + var url: String = "" + + @Parameter(name = "urlSuffix") + var urlSuffix: String? = null +} + +abstract class AbstractDokkaMojo : AbstractMojo() { + @Parameter(required = true, defaultValue = "\${project.compileSourceRoots}") + var sourceDirectories: List<String> = emptyList() + + @Parameter + var samplesDirs: List<String> = emptyList() + + @Parameter + @Deprecated("Use <includes> instead") + var includeDirs: List<String> = emptyList() + + @Parameter + var includes: List<String> = emptyList() + + @Parameter(required = true, defaultValue = "\${project.compileClasspathElements}") + var classpath: List<String> = emptyList() + + @Parameter + var sourceLinks: Array<SourceLinkMapItem> = emptyArray() + + @Parameter(required = true, defaultValue = "\${project.artifactId}") + var moduleName: String = "" + + @Parameter(required = false, defaultValue = "false") + var skip: Boolean = false + + @Parameter(required = false, defaultValue = "6") + var jdkVersion: Int = 6 + + protected abstract fun getOutDir(): String + protected abstract fun getOutFormat(): String + + override fun execute() { + if (skip) { + log.info("Dokka skip parameter is true so no dokka output will be produced") + return + } + + val gen = DokkaGenerator( + MavenDokkaLogger(log), + classpath, + sourceDirectories, + samplesDirs, + includeDirs + includes, + moduleName, + DocumentationOptions(getOutDir(), getOutFormat(), + sourceLinks = sourceLinks.map { SourceLinkDefinition(it.dir, it.url, it.urlSuffix) }, + jdkVersion = jdkVersion + ) + ) + + gen.generate() + } +} + +@Mojo(name = "dokka", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) +class DokkaMojo : AbstractDokkaMojo() { + @Parameter(required = true, defaultValue = "html") + var outputFormat: String = "html" + + @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokka") + var outputDir: String = "" + + override fun getOutFormat() = outputFormat + override fun getOutDir() = outputDir +} + +@Mojo(name = "javadoc", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) +class DokkaJavadocMojo : AbstractDokkaMojo() { + @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokkaJavadoc") + var outputDir: String = "" + + override fun getOutFormat() = "javadoc" + override fun getOutDir() = outputDir +} + +@Mojo(name = "javadocJar", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) +class DokkaJavadocJarMojo : AbstractDokkaMojo() { + @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokkaJavadocJar") + var outputDir: String = "" + + /** + * Specifies the directory where the generated jar file will be put. + */ + @Parameter(property = "project.build.directory") + private var jarOutputDirectory: String? = null + + /** + * Specifies the filename that will be used for the generated jar file. Please note that `-javadoc` + * or `-test-javadoc` will be appended to the file name. + */ + @Parameter(property = "project.build.finalName") + private var finalName: String? = null + + /** + * Specifies whether to attach the generated artifact to the project helper. + */ + @Parameter(property = "attach", defaultValue = "true") + private val attach: Boolean = false + + /** + * The archive configuration to use. + * See [Maven Archiver Reference](http://maven.apache.org/shared/maven-archiver/index.html) + */ + @Parameter + private val archive = MavenArchiveConfiguration() + + @Parameter(property = "maven.javadoc.classifier", defaultValue = "javadoc", required = true) + private var classifier: String? = null + + @Parameter(defaultValue = "\${session}", readonly = true, required = true) + protected var session: MavenSession? = null + + @Parameter(defaultValue = "\${project}", readonly = true, required = true) + protected var project: MavenProject? = null + + @Component + private var projectHelper: MavenProjectHelper? = null + + @Component(role = Archiver::class, hint = "jar") + private var jarArchiver: JarArchiver? = null + + override fun getOutFormat() = "javadoc" + override fun getOutDir() = outputDir + + override fun execute() { + super.execute() + if(!File(outputDir).exists()) { + log.warn("No javadoc generated so no javadoc jar will be generated") + return + } + val outputFile = generateArchive("$finalName-$classifier.jar") + if (attach) { + projectHelper?.attachArtifact(project, "javadoc", classifier, outputFile) + } + } + + private fun generateArchive(jarFileName: String): File { + val javadocJar = File(jarOutputDirectory, jarFileName) + + val archiver = MavenArchiver() + archiver.setArchiver(jarArchiver) + archiver.setOutputFile(javadocJar) + archiver.archiver.addDirectory(File(outputDir), arrayOf("**/**"), arrayOf()) + + archive.setAddMavenDescriptor(false) + archiver.createArchive(session, project, archive) + + return javadocJar + } +} + diff --git a/runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt b/runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt new file mode 100644 index 00000000..a535c807 --- /dev/null +++ b/runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt @@ -0,0 +1,18 @@ +package org.jetbrains.dokka.maven + +import org.apache.maven.plugin.logging.Log +import org.jetbrains.dokka.DokkaLogger + +class MavenDokkaLogger(val log: Log) : DokkaLogger { + override fun error(message: String) { + log.error(message) + } + + override fun info(message: String) { + log.info(message) + } + + override fun warn(message: String) { + log.warn(message) + } +}
\ No newline at end of file |