Skip to content

Commit

Permalink
Ensured exit status is set on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jul 22, 2024
1 parent bd9aa20 commit 6a6d6ce
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 111 deletions.
1 change: 1 addition & 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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
## Build the documentation with [Dokka](https://github.com/Kotlin/dokka)

```console
./bld docs

./bld javadoc
./bld dokka-html
./bld dokka-gfm
Expand Down
8 changes: 8 additions & 0 deletions examples/src/bld/java/com/example/ExampleBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public void compile() throws Exception {
.execute();
}

@BuildCommand(value = "docs", summary = "Generates all documentation")
public void docs() throws ExitStatusException, IOException, InterruptedException {
dokkaGfm();
dokkaHtml();
dokkaJekyll();
javadoc();
}

@BuildCommand(value = "dokka-gfm", summary = "Generates documentation in GitHub flavored markdown format")
public void dokkaGfm() throws ExitStatusException, IOException, InterruptedException {
new DokkaOperation()
Expand Down
226 changes: 120 additions & 106 deletions src/main/java/rife/bld/extension/DokkaOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import rife.bld.extension.dokka.OutputFormat;
import rife.bld.extension.dokka.SourceSet;
import rife.bld.operations.AbstractProcessOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
Expand Down Expand Up @@ -78,6 +80,8 @@ private static String encodeJson(final String json) {

/**
* Returns the JARs contained in a given directory.
* <p>
* Sources and Javadoc JARs are ignored.
*
* @param directory the directory
* @param regex the regular expression to match
Expand Down Expand Up @@ -124,143 +128,153 @@ public DokkaOperation delayTemplateSubstitution(Boolean delayTemplateSubstitutio
return this;
}

@Override
public void execute() throws IOException, InterruptedException, ExitStatusException {
if (project_ == null) {
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
LOGGER.severe("A project must be specified.");
}
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
} else {
super.execute();
}
}

/**
* Part of the {@link #execute execute} operation, constructs the command list to use for building the process.
*
* @since 1.5
*/
@Override
protected List<String> executeConstructProcessCommandList() {
if (project_ == null) {
throw new IllegalArgumentException("A project must be specified.");
}

final List<String> args = new ArrayList<>();

// java
args.add(javaTool());
if (project_ != null) {
// java
args.add(javaTool());

var cli = getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
var jarList = getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
if (!jarList.isEmpty()) {
// class path
args.add("-cp");
args.add(jarList.stream().map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator)));
}

if (cli.size() != 1) {
throw new RuntimeException("The dokka-cli JAR could not be found.");
}
// main class
args.add("org.jetbrains.dokka.MainKt");

// -jar dokka-cli
args.add("-jar");
args.add(cli.get(0).getAbsolutePath());
// -pluginClasspath
if (!pluginsClasspath_.isEmpty()) {
args.add("-pluginsClasspath");
args.add(pluginsClasspath_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}

// -pluginClasspath
if (!pluginsClasspath_.isEmpty()) {
args.add("-pluginsClasspath");
args.add(pluginsClasspath_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -sourceSet
var sourceSetArgs = sourceSet_.args();
if (sourceSetArgs.isEmpty()) {
throw new IllegalArgumentException("At least one sourceSet is required.");
} else {
args.add("-sourceSet");
args.add(String.join(" ", sourceSet_.args()));
}

// -sourceSet
var sourceSetArgs = sourceSet_.args();
if (sourceSetArgs.isEmpty()) {
throw new IllegalArgumentException("At least one sourceSet is required.");
} else {
args.add("-sourceSet");
args.add(String.join(" ", sourceSet_.args()));
}
// -outputDir
if (outputDir_ != null) {
if (!outputDir_.exists() && !outputDir_.mkdirs()) {
throw new RuntimeException("Could not create: " + outputDir_.getAbsolutePath());
}

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

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

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

// -failOnWarning
if (failOnWarning_) {
args.add("-failOnWarning");
}
// -failOnWarning
if (failOnWarning_) {
args.add("-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));
}
// -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(SEMICOLON, globalPackageOptions_));
}
// -globalPackageOptions
if (!globalPackageOptions_.isEmpty()) {
args.add("-globalPackageOptions");
args.add(String.join(SEMICOLON, globalPackageOptions_));
}

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

// -includes
if (!includes_.isEmpty()) {
args.add("-includes");
args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -includes
if (!includes_.isEmpty()) {
args.add("-includes");
args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}

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

// -moduleName
if (isNotBlank(moduleName_)) {
args.add("-moduleName");
args.add(moduleName_);
}
// -moduleName
if (isNotBlank(moduleName_)) {
args.add("-moduleName");
args.add(moduleName_);
}

// -moduleVersion
if (isNotBlank(moduleVersion_)) {
args.add("-moduleVersion");
args.add(moduleVersion_);
}
// -moduleVersion
if (isNotBlank(moduleVersion_)) {
args.add("-moduleVersion");
args.add(moduleVersion_);
}

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

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

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

// -suppressInheritedMembers
if (suppressInheritedMembers_) {
args.add("-suppressInheritedMembers");
}
// -suppressInheritedMembers
if (suppressInheritedMembers_) {
args.add("-suppressInheritedMembers");
}

// json
if (json_ != null) {
args.add(json_.getAbsolutePath());
}
// json
if (json_ != null) {
args.add(json_.getAbsolutePath());
}

if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.join(" ", args));
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.join(" ", args));
}
}

return args;
Expand Down
Loading

0 comments on commit 6a6d6ce

Please sign in to comment.