diff --git a/README.md b/README.md index ae5a4db..eb79334 100644 --- a/README.md +++ b/README.md @@ -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(); } ``` diff --git a/examples/src/bld/java/com/example/ExampleBuild.java b/examples/src/bld/java/com/example/ExampleBuild.java index ecd8beb..fa93f17 100644 --- a/examples/src/bld/java/com/example/ExampleBuild.java +++ b/examples/src/bld/java/com/example/ExampleBuild.java @@ -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(); } } \ No newline at end of file diff --git a/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java b/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java index bc47baf..dab80d3 100644 --- a/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java +++ b/src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java @@ -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(); } -} \ No newline at end of file +} diff --git a/src/main/java/rife/bld/extension/dokka/DokkaOperation.java b/src/main/java/rife/bld/extension/dokka/DokkaOperation.java index 9daf5d2..42ecfe8 100644 --- a/src/main/java/rife/bld/extension/dokka/DokkaOperation.java +++ b/src/main/java/rife/bld/extension/dokka/DokkaOperation.java @@ -34,6 +34,12 @@ import java.util.logging.Logger; */ @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes") public class DokkaOperation extends AbstractProcessOperation { + 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 globalLinks_ = new ConcurrentHashMap<>(); private final Collection globalPackageOptions_ = new ArrayList<>(); @@ -215,12 +221,7 @@ public class DokkaOperation extends AbstractProcessOperation { @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 { 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. * diff --git a/src/main/java/rife/bld/extension/dokka/OutputFormat.java b/src/main/java/rife/bld/extension/dokka/OutputFormat.java new file mode 100644 index 0000000..efa17a2 --- /dev/null +++ b/src/main/java/rife/bld/extension/dokka/OutputFormat.java @@ -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 Erik C. Thauvin + * @since 1.0 + */ +public enum OutputFormat { + JAVADOC, HTML, MARKDOWN +} diff --git a/src/test/java/rife/bld/extension/dokka/DokkaOperationTest.java b/src/test/java/rife/bld/extension/dokka/DokkaOperationTest.java index f37b9a5..3f1a9d3 100644 --- a/src/test/java/rife/bld/extension/dokka/DokkaOperationTest.java +++ b/src/test/java/rife/bld/extension/dokka/DokkaOperationTest.java @@ -53,6 +53,7 @@ class DokkaOperationTest { .noSuppressObviousFunctions(true) .offlineMode(true) .outputDir(new File(examples, "build")) + .outputFormat(OutputFormat.JAVADOC) .suppressInheritedMembers(true) .executeConstructProcessCommandList();