Added output formats for Dokka

This commit is contained in:
Erik C. Thauvin 2023-11-06 15:35:23 -08:00
parent 84f14212f4
commit adc856b1e4
6 changed files with 74 additions and 18 deletions

View file

@ -42,6 +42,8 @@ To generate the Javadoc using [Dokka](https://github.com/Kotlin/dokka):
public void javadoc() throws ExitStatusException, IOException, InterruptedException {
new DokkaOperation()
.fromProject(this)
.outputDir(new File(buildDirectory(), "javadoc"))
.outputFormat(OutputFormat.JAVADOC)
.execute();
}
```

View file

@ -5,8 +5,10 @@ import rife.bld.BuildCommand;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.dokka.DokkaOperation;
import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
@ -60,12 +62,8 @@ public class ExampleBuild extends BaseProject {
new DokkaOperation()
.fromProject(this)
.loggingLevel(LoggingLevel.INFO)
.pluginsClasspath(true)
.pluginsClasspath("lib/bld/dokka-base-1.9.10.jar",
"lib/bld/analysis-kotlin-descriptors-1.9.10.jar",
"lib/bld/gfm-plugin-1.9.10.jar",
"lib/bld/freemarker-2.3.31.jar")
.outputDir(Path.of(buildDirectory().getAbsolutePath(), "dokka", "gfm").toFile())
.outputFormat(OutputFormat.MARKDOWN)
.execute();
}
@ -74,12 +72,8 @@ public class ExampleBuild extends BaseProject {
new DokkaOperation()
.fromProject(this)
.loggingLevel(LoggingLevel.INFO)
.pluginsClasspath(true)
.pluginsClasspath("lib/bld/dokka-base-1.9.10.jar",
"lib/bld/analysis-kotlin-descriptors-1.9.10.jar",
"lib/bld/kotlinx-html-jvm-0.7.5.jar",
"lib/bld/freemarker-2.3.31.jar")
.outputDir(Path.of(buildDirectory().getAbsolutePath(), "dokka", "html").toFile())
.outputFormat(OutputFormat.HTML)
.execute();
}
@ -88,6 +82,8 @@ public class ExampleBuild extends BaseProject {
new DokkaOperation()
.fromProject(this)
.loggingLevel(LoggingLevel.INFO)
.outputDir(new File(buildDirectory(), "javadoc"))
.outputFormat(OutputFormat.JAVADOC)
.execute();
}
}

View file

@ -50,8 +50,8 @@ public class CompileKotlinOperationBuild extends Project {
.include(dependency("org.jetbrains.dokka", "gfm-plugin", dokka))
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 5)));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
javadocOperation()
@ -90,4 +90,4 @@ public class CompileKotlinOperationBuild extends Project {
.ruleSets("config/pmd.xml")
.execute();
}
}
}

View file

@ -34,6 +34,12 @@ import java.util.logging.Logger;
*/
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
private final static String GFM_PLUGIN_REGEXP =
"^.*(dokka-base|analysis-kotlin-descriptors|gfm-plugin|freemarker).*\\.jar$";
private final static String HTML_PLUGIN_REGEXP =
"^.*(dokka-base|analysis-kotlin-descriptors|kotlinx-html-jvm|freemarker).*\\.jar$";
private final static String JAVADOC_PLUGIN_REGEXP =
"^.*(dokka-base|analysis-kotlin-descriptors|javadoc-plugin|kotlin-as-java-plugin|korte-jvm).*\\.jar$";
private final Logger LOGGER = Logger.getLogger(DokkaOperation.class.getName());
private final Map<String, String> globalLinks_ = new ConcurrentHashMap<>();
private final Collection<String> globalPackageOptions_ = new ArrayList<>();
@ -215,12 +221,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
@Override
public DokkaOperation fromProject(BaseProject project) {
project_ = project;
var plugins = getJarList(
project.libBldDirectory(),
"^.*(dokka-base|analysis-kotlin-descriptors|javadoc-plugin|kotlin-as-java-plugin|korte-jvm).*\\.jar$");
pluginsClasspath_.addAll(plugins);
sourceSet_ = new SourceSet().src(new File(project.srcMainDirectory(), "kotlin").getAbsolutePath());
outputDir_ = new File(project.buildDirectory(), "javadoc");
moduleName_ = project.name();
return this;
}
@ -426,6 +427,35 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
return this;
}
/**
* Sets the output directory path, {@code ./dokka} by default
*
* @param outputDir the output directory
* @return this operation instance
*/
public DokkaOperation outputDir(String outputDir) {
outputDir_ = new File(outputDir);
return this;
}
/**
* Sets the Dokka {@link OutputFormat output format}.
*
* @param format The {@link OutputFormat output format}
* @return this operation instance
*/
public DokkaOperation outputFormat(OutputFormat format) {
pluginsClasspath_.clear();
if (format.equals(OutputFormat.JAVADOC)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), JAVADOC_PLUGIN_REGEXP));
} else if (format.equals(OutputFormat.HTML)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), HTML_PLUGIN_REGEXP));
} else if (format.equals(OutputFormat.MARKDOWN)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), GFM_PLUGIN_REGEXP));
}
return this;
}
/**
* Sets the configuration for Dokka plugins.
*

View file

@ -0,0 +1,27 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension.dokka;
/**
* Dokka output formats.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public enum OutputFormat {
JAVADOC, HTML, MARKDOWN
}

View file

@ -53,6 +53,7 @@ class DokkaOperationTest {
.noSuppressObviousFunctions(true)
.offlineMode(true)
.outputDir(new File(examples, "build"))
.outputFormat(OutputFormat.JAVADOC)
.suppressInheritedMembers(true)
.executeConstructProcessCommandList();