Skip to content

Commit

Permalink
Added more Dokka options
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Nov 5, 2023
1 parent 2e9e2bc commit 79254d9
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 36 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

To install, please refer to the [extensions documentation](https://github.com/rife2/bld/wiki/Extensions).

To compile the Kotlin source code from the current project located in `src/main/kotlin` and `src/test/kotlin`:
## Compile Kotlin Source Code
To compile the source code located in `src/main/kotlin` and `src/test/kotlin` from the current project:

```java
@BuildCommand(summary = "Compile the Kotlin project")
Expand All @@ -27,4 +28,25 @@ public void compile() throws IOException {
```
- [View Examples Project](https://github.com/rife2/bld-kotlin/tree/main/examples/)

Please check the [Compile Operation documentation](https://rife2.github.io/bld-kotlin/rife/bld/extension/CompileKotlinOperation.html#method-summary) for all available configuration options.
Please check the [Compile Operation documentation](https://rife2.github.io/bld-kotlin/rife/bld/extension/CompileKotlinOperation.html#method-summary)
for all available configuration options.

## Generate Javadoc

To generate the Javadoc using [Dokka](https://github.com/Kotlin/dokka):

```java
@BuildCommand(summary = "Generates Javadoc for the project")
public void javadoc() throws ExitStatusException, IOException, InterruptedException {
new DokkaOperation()
.fromProject(this)
.execute();
}
```
```
./bld javadoc
```
- [View Examples Project](https://github.com/rife2/bld-kotlin/tree/main/examples/)

Please check the [Dokka Operation documentation](https://rife2.github.io/bld-kotlin/rife/bld/extension/dokka/DokkaOperation.html)
for all available configuration options.
4 changes: 4 additions & 0 deletions examples/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/src/bld/java/com/example/ExampleBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import rife.bld.BuildCommand;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.dokka.DokkaOperation;
import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.operations.exceptions.ExitStatusException;

import java.io.IOException;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void compile() throws IOException {
public void javadoc() throws ExitStatusException, IOException, InterruptedException {
new DokkaOperation()
.fromProject(this)
.loggingLevel(LoggingLevel.INFO)
.execute();
}
}
15 changes: 15 additions & 0 deletions examples/src/main/kotlin/com/example/Example.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
package com.example

/**
* Example class.
*/
class Example {
/**
* Message property.
*/
val message: String
/**
* Returns the message property.
*/
get() = "Hello World!"

/**
* Companion object.
*/
companion object {
/**
* Main function.
*/
@JvmStatic
fun main(args: Array<String>) {
println(Example().message)
Expand Down
119 changes: 105 additions & 14 deletions src/main/java/rife/bld/extension/dokka/DokkaOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import rife.bld.BaseProject;
import rife.bld.operations.AbstractProcessOperation;
import rife.tools.StringUtils;

import java.io.File;
import java.util.*;
Expand All @@ -36,20 +37,20 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
private final Map<String, String> globalLinks_ = new ConcurrentHashMap<>();
private final Collection<String> globalPackageOptions_ = new ArrayList<>();
private final Collection<String> globalSrcLinks_ = new ArrayList<>();
private final Collection<File> includes_ = new ArrayList<>();
private final Collection<String> includes_ = new ArrayList<>();
private final Map<String, String> pluginConfiguration_ = new ConcurrentHashMap<>();
private final Collection<String> pluginsClasspath_ = new ArrayList<>();
private Boolean delayTemplateSubstitution_;
private Boolean failOnWarning_;
private boolean delayTemplateSubstitution_;
private boolean failOnWarning_;
private LoggingLevel loggingLevel_;
private String moduleName_;
private String moduleVersion_;
private Boolean noSuppressObviousFunctions_;
private Boolean offlineMode_;
private boolean noSuppressObviousFunctions_;
private boolean offlineMode_;
private File outputDir_;
private BaseProject project_;
private SourceSet sourceSet_;
private Boolean suppressInheritedMembers_;
private boolean suppressInheritedMembers_;

/**
* Sets the delay substitution of some elements. Used in incremental builds of multimodule projects.
Expand Down Expand Up @@ -104,12 +105,101 @@ protected List<String> executeConstructProcessCommandList() {
args.add(String.join(" ", sourceSet_.args()));
}

// -outputdir
if (outputDir_ == null) {
outputDir_ = new File("./dokka");
// -outputDir
if (outputDir_ != null) {
if (!outputDir_.exists()) {
if (!outputDir_.mkdirs()) {
throw new RuntimeException("Could not create: " + outputDir_.getAbsolutePath());
}
}

args.add("-outputDir");
args.add(outputDir_.getAbsolutePath());
}

// -delayTemplateSubstitution
if (delayTemplateSubstitution_) {
args.add("-delayTemplateSubstitution");
args.add(String.valueOf(delayTemplateSubstitution_));
}

// -failOnWarning
if (failOnWarning_) {
args.add("-failOnWarning");
args.add(String.valueOf(failOnWarning_));
}

// -globalLinks_
if (!globalLinks_.isEmpty()) {
args.add("-globalLinks");
var links = new ArrayList<String>();
globalLinks_.forEach((k, v) ->
links.add(String.format("{%s}^{%s}", k, v)));
args.add(String.join("^^", links));
}

// -globalPackageOptions
if (!globalPackageOptions_.isEmpty()) {
args.add("-globalPackageOptions");
args.add(String.join(";", globalPackageOptions_));
}

// -globalSrcLinks
if (!globalSrcLinks_.isEmpty()) {
args.add("-globalSrcLinks_");
args.add(String.join(";", globalSrcLinks_));
}

// -includes
if (!includes_.isEmpty()) {
args.add("-includes");
args.add(String.join(";", includes_));
}

// -loggingLevel
if (loggingLevel_ != null) {
args.add("-loggingLevel");
args.add(loggingLevel_.name().toLowerCase());
}

// -moduleName
if (moduleName_ != null) {
args.add("-moduleName");
args.add(moduleName_);
}

// -moduleVersion
if (moduleVersion_ != null) {
args.add("-moduleVersion");
args.add(moduleVersion_);
}

// -noSuppressObviousFunctions
if (noSuppressObviousFunctions_) {
args.add("-noSuppressObviousFunctions");
args.add(String.valueOf(noSuppressObviousFunctions_));
}

// -offlineMode
if (offlineMode_) {
args.add("-offlineMode");
args.add(String.valueOf(offlineMode_));
}

// -pluginConfiguration
if (!pluginConfiguration_.isEmpty()) {
args.add("-pluginConfiguration");
var confs = new ArrayList<String>();
pluginConfiguration_.forEach((k, v) ->
confs.add(String.format("{%s}={%s}", StringUtils.encodeJson(k), StringUtils.encodeJson(v))));
args.add(String.join("^^", confs));
}

// -suppressInheritedMembers
if (suppressInheritedMembers_) {
args.add("-suppressInheritedMembers");
args.add(String.valueOf(suppressInheritedMembers_));
}
args.add("-outputDir");
args.add(outputDir_.getAbsolutePath());

if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.join(" ", args));
Expand All @@ -130,8 +220,9 @@ public DokkaOperation fromProject(BaseProject project) {
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"));
sourceSet_ = new SourceSet().src(new File(project.srcMainDirectory(), "kotlin").getAbsolutePath());
outputDir_ = new File(project.buildDirectory(), "javadoc");
moduleName_ = project.name();
return this;
}

Expand Down Expand Up @@ -255,7 +346,7 @@ public DokkaOperation globalSrcLink(Collection<String> links) {
* @param files one or more files
* @return this operation instance
*/
public DokkaOperation includes(File... files) {
public DokkaOperation includes(String... files) {
includes_.addAll(Arrays.asList(files));
return this;
}
Expand All @@ -266,7 +357,7 @@ public DokkaOperation includes(File... files) {
* @param files the list of files
* @return this operation instance
*/
public DokkaOperation includss(Collection<File> files) {
public DokkaOperation includes(Collection<String> files) {
includes_.addAll(files);
return this;
}
Expand Down
Loading

0 comments on commit 79254d9

Please sign in to comment.