Skip to content

Commit adc856b

Browse files
committed
Added output formats for Dokka
1 parent 84f1421 commit adc856b

File tree

6 files changed

+74
-18
lines changed

6 files changed

+74
-18
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ To generate the Javadoc using [Dokka](https://github.com/Kotlin/dokka):
4242
public void javadoc() throws ExitStatusException, IOException, InterruptedException {
4343
new DokkaOperation()
4444
.fromProject(this)
45+
.outputDir(new File(buildDirectory(), "javadoc"))
46+
.outputFormat(OutputFormat.JAVADOC)
4547
.execute();
4648
}
4749
```

examples/src/bld/java/com/example/ExampleBuild.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import rife.bld.extension.CompileKotlinOperation;
66
import rife.bld.extension.dokka.DokkaOperation;
77
import rife.bld.extension.dokka.LoggingLevel;
8+
import rife.bld.extension.dokka.OutputFormat;
89
import rife.bld.operations.exceptions.ExitStatusException;
910

11+
import java.io.File;
1012
import java.io.IOException;
1113
import java.nio.file.Path;
1214
import java.util.List;
@@ -60,12 +62,8 @@ public void dokkaGfm() throws ExitStatusException, IOException, InterruptedExcep
6062
new DokkaOperation()
6163
.fromProject(this)
6264
.loggingLevel(LoggingLevel.INFO)
63-
.pluginsClasspath(true)
64-
.pluginsClasspath("lib/bld/dokka-base-1.9.10.jar",
65-
"lib/bld/analysis-kotlin-descriptors-1.9.10.jar",
66-
"lib/bld/gfm-plugin-1.9.10.jar",
67-
"lib/bld/freemarker-2.3.31.jar")
6865
.outputDir(Path.of(buildDirectory().getAbsolutePath(), "dokka", "gfm").toFile())
66+
.outputFormat(OutputFormat.MARKDOWN)
6967
.execute();
7068
}
7169

@@ -74,12 +72,8 @@ public void dokkaHtml() throws ExitStatusException, IOException, InterruptedExce
7472
new DokkaOperation()
7573
.fromProject(this)
7674
.loggingLevel(LoggingLevel.INFO)
77-
.pluginsClasspath(true)
78-
.pluginsClasspath("lib/bld/dokka-base-1.9.10.jar",
79-
"lib/bld/analysis-kotlin-descriptors-1.9.10.jar",
80-
"lib/bld/kotlinx-html-jvm-0.7.5.jar",
81-
"lib/bld/freemarker-2.3.31.jar")
8275
.outputDir(Path.of(buildDirectory().getAbsolutePath(), "dokka", "html").toFile())
76+
.outputFormat(OutputFormat.HTML)
8377
.execute();
8478
}
8579

@@ -88,6 +82,8 @@ public void javadoc() throws ExitStatusException, IOException, InterruptedExcept
8882
new DokkaOperation()
8983
.fromProject(this)
9084
.loggingLevel(LoggingLevel.INFO)
85+
.outputDir(new File(buildDirectory(), "javadoc"))
86+
.outputFormat(OutputFormat.JAVADOC)
9187
.execute();
9288
}
9389
}

src/bld/java/rife/bld/extension/CompileKotlinOperationBuild.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public CompileKotlinOperationBuild() {
5050
.include(dependency("org.jetbrains.dokka", "gfm-plugin", dokka))
5151
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 5)));
5252
scope(test)
53-
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0)))
54-
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0)))
53+
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
54+
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
5555
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
5656

5757
javadocOperation()
@@ -90,4 +90,4 @@ public void pmd() {
9090
.ruleSets("config/pmd.xml")
9191
.execute();
9292
}
93-
}
93+
}

src/main/java/rife/bld/extension/dokka/DokkaOperation.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
*/
3535
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
3636
public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
37+
private final static String GFM_PLUGIN_REGEXP =
38+
"^.*(dokka-base|analysis-kotlin-descriptors|gfm-plugin|freemarker).*\\.jar$";
39+
private final static String HTML_PLUGIN_REGEXP =
40+
"^.*(dokka-base|analysis-kotlin-descriptors|kotlinx-html-jvm|freemarker).*\\.jar$";
41+
private final static String JAVADOC_PLUGIN_REGEXP =
42+
"^.*(dokka-base|analysis-kotlin-descriptors|javadoc-plugin|kotlin-as-java-plugin|korte-jvm).*\\.jar$";
3743
private final Logger LOGGER = Logger.getLogger(DokkaOperation.class.getName());
3844
private final Map<String, String> globalLinks_ = new ConcurrentHashMap<>();
3945
private final Collection<String> globalPackageOptions_ = new ArrayList<>();
@@ -215,12 +221,7 @@ protected List<String> executeConstructProcessCommandList() {
215221
@Override
216222
public DokkaOperation fromProject(BaseProject project) {
217223
project_ = project;
218-
var plugins = getJarList(
219-
project.libBldDirectory(),
220-
"^.*(dokka-base|analysis-kotlin-descriptors|javadoc-plugin|kotlin-as-java-plugin|korte-jvm).*\\.jar$");
221-
pluginsClasspath_.addAll(plugins);
222224
sourceSet_ = new SourceSet().src(new File(project.srcMainDirectory(), "kotlin").getAbsolutePath());
223-
outputDir_ = new File(project.buildDirectory(), "javadoc");
224225
moduleName_ = project.name();
225226
return this;
226227
}
@@ -426,6 +427,35 @@ public DokkaOperation outputDir(File outputDir) {
426427
return this;
427428
}
428429

430+
/**
431+
* Sets the output directory path, {@code ./dokka} by default
432+
*
433+
* @param outputDir the output directory
434+
* @return this operation instance
435+
*/
436+
public DokkaOperation outputDir(String outputDir) {
437+
outputDir_ = new File(outputDir);
438+
return this;
439+
}
440+
441+
/**
442+
* Sets the Dokka {@link OutputFormat output format}.
443+
*
444+
* @param format The {@link OutputFormat output format}
445+
* @return this operation instance
446+
*/
447+
public DokkaOperation outputFormat(OutputFormat format) {
448+
pluginsClasspath_.clear();
449+
if (format.equals(OutputFormat.JAVADOC)) {
450+
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), JAVADOC_PLUGIN_REGEXP));
451+
} else if (format.equals(OutputFormat.HTML)) {
452+
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), HTML_PLUGIN_REGEXP));
453+
} else if (format.equals(OutputFormat.MARKDOWN)) {
454+
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), GFM_PLUGIN_REGEXP));
455+
}
456+
return this;
457+
}
458+
429459
/**
430460
* Sets the configuration for Dokka plugins.
431461
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package rife.bld.extension.dokka;
18+
19+
/**
20+
* Dokka output formats.
21+
*
22+
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
23+
* @since 1.0
24+
*/
25+
public enum OutputFormat {
26+
JAVADOC, HTML, MARKDOWN
27+
}

src/test/java/rife/bld/extension/dokka/DokkaOperationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void executeConstructProcessCommandListTest() {
5353
.noSuppressObviousFunctions(true)
5454
.offlineMode(true)
5555
.outputDir(new File(examples, "build"))
56+
.outputFormat(OutputFormat.JAVADOC)
5657
.suppressInheritedMembers(true)
5758
.executeConstructProcessCommandList();
5859

0 commit comments

Comments
 (0)