Compare commits

..

6 commits

Author SHA1 Message Date
6a6d6ce62a
Ensured exit status is set on failure
Some checks failed
bld-ci / build-bld-project (17, 1.19.24) (push) Has been cancelled
bld-ci / build-bld-project (17, 2.0.0) (push) Has been cancelled
bld-ci / build-bld-project (21, 1.19.24) (push) Has been cancelled
bld-ci / build-bld-project (21, 2.0.0) (push) Has been cancelled
bld-ci / build-bld-project (22, 1.19.24) (push) Has been cancelled
bld-ci / build-bld-project (22, 2.0.0) (push) Has been cancelled
javadocs-pages / deploy (push) Has been cancelled
2024-07-22 10:23:19 -07:00
bd9aa20223
Bumped bld to version 2.0.0-SNAPSHOT 2024-07-22 09:58:10 -07:00
c8878968ef
Cleaned up tests 2024-06-23 21:41:13 -07:00
6b6057f52e
Fixed invalid boolean arguments 2024-06-23 20:36:35 -07:00
2f9da45172
More code cleanups 2024-06-23 18:06:17 -07:00
75a864acfe
Bumped extensions properties
Exec to version 1.0.1
PMD to version 1.1.0
2024-06-23 18:00:16 -07:00
18 changed files with 348 additions and 277 deletions

View file

@ -1,6 +1,6 @@
name: bld-ci name: bld-ci
on: [push, pull_request, workflow_dispatch] on: [ push, pull_request, workflow_dispatch ]
jobs: jobs:
build-bld-project: build-bld-project:
@ -8,7 +8,8 @@ jobs:
strategy: strategy:
matrix: matrix:
java-version: [17, 21, 22] java-version: [ 17, 21, 22 ]
kotlin-version: [ 1.19.24, 2.0.0 ]
steps: steps:
- name: Checkout source repository - name: Checkout source repository
@ -22,17 +23,15 @@ jobs:
distribution: "zulu" distribution: "zulu"
java-version: ${{ matrix.java-version }} java-version: ${{ matrix.java-version }}
- name: Download the examples dependencies - name: Download dependencies [examples]
working-directory: examples working-directory: examples
run: | run: ./bld download
chmod +x bld
./bld download
- name: Run examples tests - name: Run tests [examples]
working-directory: examples working-directory: examples
run: ./bld compile test run: ./bld compile test
- name: Build examples documentation - name: Build documentation [examples]
working-directory: examples working-directory: examples
run: | run: |
./bld javadoc ./bld javadoc
@ -40,10 +39,7 @@ jobs:
./bld dokka-gfm ./bld dokka-gfm
./bld dokka-jekyll ./bld dokka-jekyll
- name: Grant execute permission for bld - name: Download dependencies
run: chmod +x bld
- name: Download the dependencies
run: ./bld download run: ./bld download
- name: Run tests - name: Run tests

View file

@ -2,12 +2,12 @@
<library name="bld"> <library name="bld">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT.jar!/" />
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT-sources.jar!/" />
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
</SOURCES> </SOURCES>
<excluded> <excluded>

View file

@ -9,7 +9,7 @@
], ],
"java.configuration.updateBuildConfiguration": "automatic", "java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [ "java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-1.9.1.jar", "${HOME}/.bld/dist/bld-2.0.0-SNAPSHOT.jar",
"lib/**/*.jar" "lib/**/*.jar"
] ]
} }

View file

@ -2,12 +2,12 @@
<library name="bld"> <library name="bld">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT-sources.jar!/" />
</SOURCES> </SOURCES>
<excluded> <excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" /> <root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />

View file

@ -6,6 +6,7 @@
<pattern value="com.example.ExampleBuild" method="dokkaHtml" /> <pattern value="com.example.ExampleBuild" method="dokkaHtml" />
<pattern value="com.example.ExampleBuild" method="dokkaGfm" /> <pattern value="com.example.ExampleBuild" method="dokkaGfm" />
<pattern value="com.example.ExampleBuild" method="dokkaJekyll" /> <pattern value="com.example.ExampleBuild" method="dokkaJekyll" />
<pattern value="com.example.ExampleBuild" method="docs" />
</component> </component>
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="customRuleSets"> <option name="customRuleSets">

View file

@ -9,7 +9,7 @@
], ],
"java.configuration.updateBuildConfiguration": "automatic", "java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [ "java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-1.9.1.jar", "${HOME}/.bld/dist/bld-2.0.0-SNAPSHOT.jar",
"lib/**/*.jar" "lib/**/*.jar"
] ]
} }

View file

@ -20,6 +20,8 @@
## Build the documentation with [Dokka](https://github.com/Kotlin/dokka) ## Build the documentation with [Dokka](https://github.com/Kotlin/dokka)
```console ```console
./bld docs
./bld javadoc ./bld javadoc
./bld dokka-html ./bld dokka-html
./bld dokka-gfm ./bld dokka-gfm

Binary file not shown.

View file

@ -5,4 +5,4 @@ bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.0-SNAPSHOT
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.0-SNAPSHOT bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.0-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=1.9.1 bld.version=2.0.0-SNAPSHOT

View file

@ -39,8 +39,8 @@ public class ExampleBuild extends Project {
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)); .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin));
scope(test) scope(test)
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin)) .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2))); .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)));
// Include the Kotlin source directory when creating or publishing sources Java Archives // Include the Kotlin source directory when creating or publishing sources Java Archives
jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin")); jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin"));
@ -48,26 +48,34 @@ public class ExampleBuild extends Project {
public static void main(String[] args) { public static void main(String[] args) {
// Enable detailed logging for the Kotlin extension // Enable detailed logging for the Kotlin extension
// var level = Level.ALL; var level = Level.ALL;
// var logger = Logger.getLogger("rife.bld.extension"); var logger = Logger.getLogger("rife.bld.extension");
// var consoleHandler = new ConsoleHandler(); var consoleHandler = new ConsoleHandler();
//
// consoleHandler.setLevel(level); consoleHandler.setLevel(level);
// logger.addHandler(consoleHandler); logger.addHandler(consoleHandler);
// logger.setLevel(level); logger.setLevel(level);
// logger.setUseParentHandlers(false); logger.setUseParentHandlers(false);
new ExampleBuild().start(args); new ExampleBuild().start(args);
} }
@BuildCommand(summary = "Compiles the Kotlin project") @BuildCommand(summary = "Compiles the Kotlin project")
@Override @Override
public void compile() throws IOException { public void compile() throws Exception {
new CompileKotlinOperation() new CompileKotlinOperation()
.fromProject(this) .fromProject(this)
.execute(); .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") @BuildCommand(value = "dokka-gfm", summary = "Generates documentation in GitHub flavored markdown format")
public void dokkaGfm() throws ExitStatusException, IOException, InterruptedException { public void dokkaGfm() throws ExitStatusException, IOException, InterruptedException {
new DokkaOperation() new DokkaOperation()

Binary file not shown.

View file

@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.0 bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.1
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.0.1 bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.2
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_RELEASES bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=1.9.1 bld.version=2.0.0-SNAPSHOT

View file

@ -51,9 +51,9 @@ public class DokkaOperationBuild extends Project {
.include(dependency("org.jetbrains.dokka", "jekyll-plugin", dokka)) .include(dependency("org.jetbrains.dokka", "jekyll-plugin", dokka))
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1))); .include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1)));
scope(test) scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)))
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0))); .include(dependency("org.assertj", "assertj-core", version(3, 26, 3)));
javadocOperation() javadocOperation()
.javadocOptions() .javadocOptions()
@ -95,7 +95,7 @@ public class DokkaOperationBuild extends Project {
} }
@BuildCommand(summary = "Runs PMD analysis") @BuildCommand(summary = "Runs PMD analysis")
public void pmd() { public void pmd() throws Exception {
new PmdOperation() new PmdOperation()
.fromProject(this) .fromProject(this)
.failOnViolation(true) .failOnViolation(true)

View file

@ -21,9 +21,11 @@ import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat; import rife.bld.extension.dokka.OutputFormat;
import rife.bld.extension.dokka.SourceSet; import rife.bld.extension.dokka.SourceSet;
import rife.bld.operations.AbstractProcessOperation; import rife.bld.operations.AbstractProcessOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.StringUtils; import rife.tools.StringUtils;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level; import java.util.logging.Level;
@ -56,7 +58,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
private final Map<String, String> pluginsConfiguration_ = new ConcurrentHashMap<>(); private final Map<String, String> pluginsConfiguration_ = new ConcurrentHashMap<>();
private boolean delayTemplateSubstitution_; private boolean delayTemplateSubstitution_;
private boolean failOnWarning_; private boolean failOnWarning_;
private File json; private File json_;
private LoggingLevel loggingLevel_; private LoggingLevel loggingLevel_;
private String moduleName_; private String moduleName_;
private String moduleVersion_; private String moduleVersion_;
@ -77,11 +79,13 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
} }
/** /**
* Returns the list of JARs contained in a given directory. * Returns the JARs contained in a given directory.
* <p>
* Sources and Javadoc JARs are ignored.
* *
* @param directory the directory * @param directory the directory
* @param regex the regular expression to match * @param regex the regular expression to match
* @return the list of JARs * @return the Java Archives
*/ */
public static List<File> getJarList(File directory, String regex) { public static List<File> getJarList(File directory, String regex) {
var jars = new ArrayList<File>(); var jars = new ArrayList<File>();
@ -124,6 +128,18 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
return this; 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. * Part of the {@link #execute execute} operation, constructs the command list to use for building the process.
* *
@ -131,136 +147,134 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
*/ */
@Override @Override
protected List<String> executeConstructProcessCommandList() { protected List<String> executeConstructProcessCommandList() {
if (project_ == null) {
throw new IllegalArgumentException("A project must be specified.");
}
final List<String> args = new ArrayList<>(); final List<String> args = new ArrayList<>();
// java if (project_ != null) {
args.add(javaTool()); // java
args.add(javaTool());
var cli = getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$"); var jarList = getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
if (!jarList.isEmpty()) {
if (cli.size() != 1) { // class path
throw new RuntimeException("The dokka-cli JAR could not be found."); args.add("-cp");
} args.add(jarList.stream().map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator)));
// -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)));
}
// -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());
} }
args.add("-outputDir"); // main class
args.add(outputDir_.getAbsolutePath()); args.add("org.jetbrains.dokka.MainKt");
}
// -delayTemplateSubstitution // -pluginClasspath
if (delayTemplateSubstitution_) { if (!pluginsClasspath_.isEmpty()) {
args.add("-delayTemplateSubstitution"); args.add("-pluginsClasspath");
} args.add(pluginsClasspath_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -failOnWarning // -sourceSet
if (failOnWarning_) { var sourceSetArgs = sourceSet_.args();
args.add("-failOnWarning"); if (sourceSetArgs.isEmpty()) {
} throw new IllegalArgumentException("At least one sourceSet is required.");
} else {
args.add("-sourceSet");
args.add(String.join(" ", sourceSet_.args()));
}
// -globalLinks_ // -outputDir
if (!globalLinks_.isEmpty()) { if (outputDir_ != null) {
args.add("-globalLinks"); if (!outputDir_.exists() && !outputDir_.mkdirs()) {
var links = new ArrayList<String>(); throw new RuntimeException("Could not create: " + outputDir_.getAbsolutePath());
globalLinks_.forEach((k, v) -> }
links.add(String.format("%s^%s", k, v)));
args.add(String.join("^^", links));
}
// -globalPackageOptions args.add("-outputDir");
if (!globalPackageOptions_.isEmpty()) { args.add(outputDir_.getAbsolutePath());
args.add("-globalPackageOptions"); }
args.add(String.join(SEMICOLON, globalPackageOptions_));
}
// -globalSrcLinks // -delayTemplateSubstitution
if (!globalSrcLinks_.isEmpty()) { if (delayTemplateSubstitution_) {
args.add("-globalSrcLinks_"); args.add("-delayTemplateSubstitution");
args.add(String.join(SEMICOLON, globalSrcLinks_)); }
}
// -includes // -failOnWarning
if (!includes_.isEmpty()) { if (failOnWarning_) {
args.add("-includes"); args.add("-failOnWarning");
args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON))); }
}
// -loggingLevel // -globalLinks_
if (loggingLevel_ != null) { if (!globalLinks_.isEmpty()) {
args.add("-loggingLevel"); args.add("-globalLinks");
args.add(loggingLevel_.name().toLowerCase()); var links = new ArrayList<String>();
} globalLinks_.forEach((k, v) ->
links.add(String.format("%s^%s", k, v)));
args.add(String.join("^^", links));
}
// -moduleName // -globalPackageOptions
if (isNotBlank(moduleName_)) { if (!globalPackageOptions_.isEmpty()) {
args.add("-moduleName"); args.add("-globalPackageOptions");
args.add(moduleName_); args.add(String.join(SEMICOLON, globalPackageOptions_));
} }
// -moduleVersion // -globalSrcLinks
if (isNotBlank(moduleVersion_)) { if (!globalSrcLinks_.isEmpty()) {
args.add("-moduleVersion"); args.add("-globalSrcLinks_");
args.add(moduleVersion_); args.add(String.join(SEMICOLON, globalSrcLinks_));
} }
// -noSuppressObviousFunctions // -includes
if (noSuppressObviousFunctions_) { if (!includes_.isEmpty()) {
args.add("-noSuppressObviousFunctions"); args.add("-includes");
} args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -offlineMode // -loggingLevel
if (offlineMode_) { if (loggingLevel_ != null) {
args.add("-offlineMode"); args.add("-loggingLevel");
} args.add(loggingLevel_.name().toLowerCase());
}
// -pluginConfiguration // -moduleName
if (!pluginsConfiguration_.isEmpty()) { if (isNotBlank(moduleName_)) {
args.add("-pluginsConfiguration"); args.add("-moduleName");
var confs = new ArrayList<String>(); args.add(moduleName_);
pluginsConfiguration_.forEach((k, v) -> }
confs.add(String.format("%s=%s", encodeJson(k), encodeJson(v))));
args.add(String.join("^^", confs));
}
// -suppressInheritedMembers // -moduleVersion
if (suppressInheritedMembers_) { if (isNotBlank(moduleVersion_)) {
args.add("-suppressInheritedMembers"); args.add("-moduleVersion");
} args.add(moduleVersion_);
}
// json // -noSuppressObviousFunctions
if (json != null) { if (noSuppressObviousFunctions_) {
args.add(json.getAbsolutePath()); args.add("-noSuppressObviousFunctions");
} }
if (LOGGER.isLoggable(Level.FINE)) { // -offlineMode
LOGGER.fine(String.join(" ", args)); 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));
}
// -suppressInheritedMembers
if (suppressInheritedMembers_) {
args.add("-suppressInheritedMembers");
}
// json
if (json_ != null) {
args.add(json_.getAbsolutePath());
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.join(" ", args));
}
} }
return args; return args;
@ -338,7 +352,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
} }
/** /**
* Sets the global list of package configurations. * Sets the global package configurations.
* <p> * <p>
* Using format: * Using format:
* <ul> * <ul>
@ -355,12 +369,12 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation globalPackageOptions(String... options) { public DokkaOperation globalPackageOptions(String... options) {
Collections.addAll(globalPackageOptions_, options); globalPackageOptions_.addAll(List.of(options));
return this; return this;
} }
/** /**
* Retrieves the global list of package configurations. * Retrieves the global package configurations.
* *
* @return the package configurations * @return the package configurations
*/ */
@ -369,7 +383,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
} }
/** /**
* Sets the global list of package configurations. * Sets the global package configurations.
* <p> * <p>
* Using format: * Using format:
* <ul> * <ul>
@ -382,7 +396,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* <li>...</li> * <li>...</li>
* </ul> * </ul>
* *
* @param options the list of package configurations * @param options the package configurations
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation globalPackageOptions(Collection<String> options) { public DokkaOperation globalPackageOptions(Collection<String> options) {
@ -397,7 +411,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation globalSrcLink(String... links) { public DokkaOperation globalSrcLink(String... links) {
Collections.addAll(globalSrcLinks_, links); globalSrcLinks_.addAll(List.of(links));
return this; return this;
} }
@ -432,7 +446,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation includes(File... files) { public DokkaOperation includes(File... files) {
Collections.addAll(includes_, files); includes_.addAll(List.of(files));
return this; return this;
} }
@ -447,9 +461,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation includes(String... files) { public DokkaOperation includes(String... files) {
Collections.addAll(includes_, Arrays.stream(files) includes_.addAll(Arrays.stream(files).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -469,7 +481,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* <p> * <p>
* This can be configured on per-package basis. * This can be configured on per-package basis.
* *
* @param files the list of files * @param files the markdown files
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation includes(Collection<File> files) { public DokkaOperation includes(Collection<File> files) {
@ -483,7 +495,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @param configuration the configuration file path * @param configuration the configuration file path
*/ */
public DokkaOperation json(File configuration) { public DokkaOperation json(File configuration) {
json = configuration; json_ = configuration;
return this; return this;
} }
@ -648,26 +660,24 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
} }
/** /**
* Sets the list of jars with Dokka plugins and their dependencies. * Sets the jars for Dokka plugins and their dependencies.
* *
* @param jars one or more jars * @param jars one or more jars
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation pluginsClasspath(File... jars) { public DokkaOperation pluginsClasspath(File... jars) {
Collections.addAll(pluginsClasspath_, jars); pluginsClasspath_.addAll(List.of(jars));
return this; return this;
} }
/** /**
* Sets the list of jars with Dokka plugins and their dependencies. * Sets the jars for Dokka plugins and their dependencies.
* *
* @param jars one or more jars * @param jars one or more jars
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation pluginsClasspath(String... jars) { public DokkaOperation pluginsClasspath(String... jars) {
Collections.addAll(pluginsClasspath_, Arrays.stream(jars) pluginsClasspath_.addAll(Arrays.stream(jars).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -681,9 +691,9 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
} }
/** /**
* Sets the list of jars with Dokka plugins and their dependencies. * Sets the jars for Dokka plugins and their dependencies.
* *
* @param jars the list of jars * @param jars the jars
* @return this operation instance * @return this operation instance
*/ */
public DokkaOperation pluginsClasspath(Collection<File> jars) { public DokkaOperation pluginsClasspath(Collection<File> jars) {

View file

@ -164,25 +164,21 @@ public class SourceSet {
// -noJdkLink // -noJdkLink
if (noJdkLink_) { if (noJdkLink_) {
args.add("-noJdkLink"); args.add("-noJdkLink");
args.add(String.valueOf(noJdkLink_));
} }
// -noSkipEmptyPackages // -noSkipEmptyPackages
if (noSkipEmptyPackages_) { if (noSkipEmptyPackages_) {
args.add("-noSkipEmptyPackages"); args.add("-noSkipEmptyPackages");
args.add(String.valueOf(noSkipEmptyPackages_));
} }
// -noStdlibLink // -noStdlibLink
if (noStdlibLink_) { if (noStdlibLink_) {
args.add("-noStdlibLink"); args.add("-noStdlibLink");
args.add(String.valueOf(noStdlibLink_));
} }
// -reportUndocumented // -reportUndocumented
if (reportUndocumented_) { if (reportUndocumented_) {
args.add("-reportUndocumented"); args.add("-reportUndocumented");
args.add(String.valueOf(reportUndocumented_));
} }
// -perPackageOptions // -perPackageOptions
@ -200,7 +196,6 @@ public class SourceSet {
// -skipDeprecated // -skipDeprecated
if (skipDeprecated_) { if (skipDeprecated_) {
args.add("-skipDeprecated"); args.add("-skipDeprecated");
args.add(String.valueOf(skipDeprecated_));
} }
// -src // -src
@ -243,7 +238,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet classpath(File... files) { public SourceSet classpath(File... files) {
Collections.addAll(classpath_, files); classpath_.addAll(List.of(files));
return this; return this;
} }
@ -258,9 +253,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet classpath(String... files) { public SourceSet classpath(String... files) {
Collections.addAll(classpath_, Arrays.stream(files) classpath_.addAll(Arrays.stream(files).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -271,7 +264,7 @@ public class SourceSet {
* <p> * <p>
* This option accepts both {@code .jar} and {@code .klib} files. * This option accepts both {@code .jar} and {@code .klib} files.
* *
* @param files the list of files * @param files the collection of files
* @return this operation instance * @return this operation instance
*/ */
public SourceSet classpath(Collection<File> files) { public SourceSet classpath(Collection<File> files) {
@ -349,7 +342,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet documentedVisibilities(DocumentedVisibility... visibilities) { public SourceSet documentedVisibilities(DocumentedVisibility... visibilities) {
documentedVisibilities_.addAll(Arrays.asList(visibilities)); documentedVisibilities_.addAll(List.of(visibilities));
return this; return this;
} }
@ -402,7 +395,7 @@ public class SourceSet {
/** /**
* Sets the Markdown files that contain module and package documentation. * Sets the Markdown files that contain module and package documentation.
* <p> * <p>
* A list of Markdown files that contain module and package documentation. * The Markdown files that contain module and package documentation.
* <p> * <p>
* The contents of the specified files are parsed and embedded into documentation as module and package * The contents of the specified files are parsed and embedded into documentation as module and package
* descriptions. * descriptions.
@ -411,14 +404,14 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet includes(File... files) { public SourceSet includes(File... files) {
Collections.addAll(includes_, files); includes_.addAll(List.of(files));
return this; return this;
} }
/** /**
* Sets the Markdown files that contain module and package documentation. * Sets the Markdown files that contain module and package documentation.
* <p> * <p>
* A list of Markdown files that contain module and package documentation. * The Markdown files that contain module and package documentation.
* <p> * <p>
* The contents of the specified files are parsed and embedded into documentation as module and package * The contents of the specified files are parsed and embedded into documentation as module and package
* descriptions. * descriptions.
@ -427,9 +420,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet includes(String... files) { public SourceSet includes(String... files) {
Collections.addAll(includes_, Arrays.stream(files) includes_.addAll(Arrays.stream(files).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -445,12 +436,12 @@ public class SourceSet {
/** /**
* Sets the Markdown files that contain module and package documentation. * Sets the Markdown files that contain module and package documentation.
* <p> * <p>
* A list of Markdown files that contain module and package documentation. * The Markdown files that contain module and package documentation.
* <p> * <p>
* The contents of the specified files are parsed and embedded into documentation as module and package * The contents of the specified files are parsed and embedded into documentation as module and package
* descriptions. * descriptions.
* *
* @param files the list of files * @param files the collection of files
* @return this operation instance * @return this operation instance
*/ */
public SourceSet includes(Collection<File> files) { public SourceSet includes(Collection<File> files) {
@ -559,7 +550,7 @@ public class SourceSet {
} }
/** /**
* Set the list of package source set configuration. * Set the package source set configuration.
* <p> * <p>
* A set of parameters specific to matched packages within this source set. * A set of parameters specific to matched packages within this source set.
* <p> * <p>
@ -574,7 +565,7 @@ public class SourceSet {
* <li>...</li> * <li>...</li>
* </ul> * </ul>
* *
* @param perPackageOptions the list of per package options * @param perPackageOptions the per package options
* @return this operation instance * @return this operation instance
*/ */
public SourceSet perPackageOptions(Collection<String> perPackageOptions) { public SourceSet perPackageOptions(Collection<String> perPackageOptions) {
@ -583,7 +574,7 @@ public class SourceSet {
} }
/** /**
* Retrieves the list of package source set configuration. * Retrieves the package source set configuration.
* *
* @return the package source set configuration * @return the package source set configuration
*/ */
@ -592,7 +583,7 @@ public class SourceSet {
} }
/** /**
* Set the list of package source set configuration. * Set the package source set configuration.
* <p> * <p>
* A set of parameters specific to matched packages within this source set. * A set of parameters specific to matched packages within this source set.
* <p> * <p>
@ -607,11 +598,11 @@ public class SourceSet {
* <li>...</li> * <li>...</li>
* </ul> * </ul>
* *
* @param perPackageOptions the list of per package options * @param perPackageOptions the per package options
* @return this operation instance * @return this operation instance
*/ */
public SourceSet perPackageOptions(String... perPackageOptions) { public SourceSet perPackageOptions(String... perPackageOptions) {
Collections.addAll(perPackageOptions_, perPackageOptions); perPackageOptions_.addAll(List.of(perPackageOptions));
return this; return this;
} }
@ -634,12 +625,12 @@ public class SourceSet {
} }
/** /**
* Set the list of directories or files that contain sample functions. * Set the directories or files that contain sample functions.
* <p> * <p>
* A list of directories or files that contain sample functions which are referenced via the {@code @sample} KDoc * The directories or files that contain sample functions which are referenced via the {@code @sample} KDoc
* tag. * tag.
* *
* @param samples the list of samples * @param samples the samples
* @return this operation instance * @return this operation instance
*/ */
public SourceSet samples(Collection<File> samples) { public SourceSet samples(Collection<File> samples) {
@ -648,7 +639,7 @@ public class SourceSet {
} }
/** /**
* Retrieves the list of directories or files that contain sample functions. * Retrieves the directories or files that contain sample functions.
* *
* @return the directories or files * @return the directories or files
*/ */
@ -657,32 +648,30 @@ public class SourceSet {
} }
/** /**
* Set the list of directories or files that contain sample functions. * Set the directories or files that contain sample functions.
* <p> * <p>
* A list of directories or files that contain sample functions which are referenced via the {@code @sample} KDoc * The directories or files that contain sample functions which are referenced via the {@code @sample} KDoc
* tag. * tag.
* *
* @param samples nne or more samples * @param samples nne or more samples
* @return this operation instance * @return this operation instance
*/ */
public SourceSet samples(File... samples) { public SourceSet samples(File... samples) {
Collections.addAll(samples_, samples); samples_.addAll(List.of(samples));
return this; return this;
} }
/** /**
* Set the list of directories or files that contain sample functions. * Set the directories or files that contain sample functions.
* <p> * <p>
* A list of directories or files that contain sample functions which are referenced via the {@code @sample} KDoc * The directories or files that contain sample functions which are referenced via the {@code @sample} KDoc
* tag. * tag.
* *
* @param samples nne or more samples * @param samples nne or more samples
* @return this operation instance * @return this operation instance
*/ */
public SourceSet samples(String... samples) { public SourceSet samples(String... samples) {
Collections.addAll(samples_, Arrays.stream(samples) samples_.addAll(Arrays.stream(samples).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -718,7 +707,7 @@ public class SourceSet {
* The source code roots to be analyzed and documented. Acceptable inputs are directories and individual * The source code roots to be analyzed and documented. Acceptable inputs are directories and individual
* {@code .kt} / {@code .java} files. * {@code .kt} / {@code .java} files.
* *
* @param src the list of source code roots * @param src the source code roots
* @return this operation instance * @return this operation instance
*/ */
public SourceSet src(Collection<File> src) { public SourceSet src(Collection<File> src) {
@ -736,7 +725,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet src(File... src) { public SourceSet src(File... src) {
Collections.addAll(src_, src); src_.addAll(List.of(src));
return this; return this;
} }
@ -750,9 +739,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet src(String... src) { public SourceSet src(String... src) {
Collections.addAll(src_, Arrays.stream(src) src_.addAll(Arrays.stream(src).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -805,7 +792,7 @@ public class SourceSet {
* <p> * <p>
* The files to be suppressed when generating documentation. * The files to be suppressed when generating documentation.
* *
* @param suppressedFiles the list of suppressed files * @param suppressedFiles the suppressed files
* @return this operation instance * @return this operation instance
*/ */
public SourceSet suppressedFiles(Collection<File> suppressedFiles) { public SourceSet suppressedFiles(Collection<File> suppressedFiles) {
@ -832,9 +819,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet suppressedFiles(String... suppressedFiles) { public SourceSet suppressedFiles(String... suppressedFiles) {
Collections.addAll(suppressedFiles_, Arrays.stream(suppressedFiles) suppressedFiles_.addAll(Arrays.stream(suppressedFiles).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -847,7 +832,7 @@ public class SourceSet {
* @return this operation instance * @return this operation instance
*/ */
public SourceSet suppressedFiles(File... suppressedFiles) { public SourceSet suppressedFiles(File... suppressedFiles) {
suppressedFiles_.addAll(Arrays.asList(suppressedFiles)); suppressedFiles_.addAll(List.of(suppressedFiles));
return this; return this;
} }
} }

View file

@ -16,11 +16,13 @@
package rife.bld.extension; package rife.bld.extension;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.bld.blueprints.BaseProjectBlueprint; import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.dokka.LoggingLevel; import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat; import rife.bld.extension.dokka.OutputFormat;
import rife.bld.extension.dokka.SourceSet; import rife.bld.extension.dokka.SourceSet;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -29,46 +31,74 @@ import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
class DokkaOperationTest { class DokkaOperationTest {
private static final File EXAMPLES = new File("examples");
private static final String FILE_1 = "file1";
private static final String FILE_2 = "file2";
private static final String FILE_3 = "file3";
private static final String FILE_4 = "file4";
private static final String OPTION_1 = "option1";
private static final String OPTION_2 = "option2";
private static final String OPTION_3 = "option3";
private static final String OPTION_4 = "option4";
private static final String PATH_1 = "path1";
private static final String PATH_2 = "path2";
private static final String PATH_3 = "path3";
private static final String PATH_4 = "path4";
@BeforeAll
static void beforeAll() {
var level = Level.ALL;
var logger = Logger.getLogger("rife.bld.extension");
var consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(level);
logger.addHandler(consoleHandler);
logger.setLevel(level);
logger.setUseParentHandlers(false);
}
@Test @Test
@SuppressWarnings({"PMD.AvoidDuplicateLiterals"})
void executeConstructProcessCommandListTest() throws IOException { void executeConstructProcessCommandListTest() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-args.txt")); var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-args.txt"));
assertThat(args).isNotEmpty(); assertThat(args).isNotEmpty();
var examples = new File("examples");
var jsonConf = new File("config.json"); var jsonConf = new File("config.json");
var op = new DokkaOperation() var op = new DokkaOperation()
.delayTemplateSubstitution(true) .delayTemplateSubstitution(true)
.failOnWarning(true) .failOnWarning(true)
.fromProject(new BaseProjectBlueprint(examples, "com.example", "Example")) .fromProject(new BaseProjectBlueprint(EXAMPLES, "com.example", "Example"))
.globalLinks("s", "link") .globalLinks("s", "gLink1")
.globalLinks(Map.of("s2", "link2")) .globalLinks(Map.of("s2", "gLink2"))
.globalPackageOptions("option1", "option2") .globalPackageOptions(OPTION_1, OPTION_2)
.globalPackageOptions(List.of("option3", "option4")) .globalPackageOptions(List.of(OPTION_3, OPTION_4))
.globalSrcLink("link1", "link2") .globalSrcLink("link1", "link2")
.globalSrcLink(List.of("link3", "link4")) .globalSrcLink(List.of("link3", "link4"))
.includes(new File("file1")) .includes(new File(FILE_1))
.includes("file2") .includes(FILE_2)
.includes(List.of(new File("file3"), new File("file4"))) .includes(List.of(new File(FILE_3), new File(FILE_4)))
.json(jsonConf) .json(jsonConf)
.loggingLevel(LoggingLevel.DEBUG) .loggingLevel(LoggingLevel.DEBUG)
.moduleName("name") .moduleName("name")
.moduleVersion("1.0") .moduleVersion("1.0")
.noSuppressObviousFunctions(true) .noSuppressObviousFunctions(true)
.offlineMode(true) .offlineMode(true)
.outputDir(new File(examples, "build")) .outputDir(new File(EXAMPLES, "build"))
.outputFormat(OutputFormat.JAVADOC) .outputFormat(OutputFormat.JAVADOC)
.pluginConfigurations("name", "{\"json\"}") .pluginConfigurations("name", "{\"json\"}")
.pluginConfigurations(Map.of("{\"name2\"}", "json2", "name3}", "{json3")) .pluginConfigurations(Map.of("{\"name2\"}", "json2", "name3}", "{json3"))
.pluginsClasspath(new File("path1")) .pluginsClasspath(new File(PATH_1))
.pluginsClasspath("path2") .pluginsClasspath(PATH_2)
.pluginsClasspath(List.of(new File("path3"), new File("path4"))) .pluginsClasspath(List.of(new File(PATH_3), new File(PATH_4)))
.sourceSet(new SourceSet().classpath( .sourceSet(new SourceSet().classpath(
List.of( List.of(
new File("examples/foo.jar"), new File("examples/foo.jar"),
@ -95,25 +125,26 @@ class DokkaOperationTest {
assertThat(found).as(p + " not found.").isTrue(); assertThat(found).as(p + " not found.").isTrue();
} }
var path = examples.getAbsolutePath(); var path = EXAMPLES.getAbsolutePath();
var dokkaJar = "1.9.20.jar"; var dokkaJar = "1.9.20.jar";
var matches = List.of("java", var matches = List.of("java",
"-jar", path + "/lib/bld/dokka-cli-" + dokkaJar, "-cp", path + "/lib/bld/dokka-cli-" + dokkaJar,
"org.jetbrains.dokka.MainKt",
"-pluginsClasspath", path + "/lib/bld/dokka-base-" + dokkaJar + ';' + "-pluginsClasspath", path + "/lib/bld/dokka-base-" + dokkaJar + ';' +
path + "/lib/bld/analysis-kotlin-descriptors-" + dokkaJar + ';' + path + "/lib/bld/analysis-kotlin-descriptors-" + dokkaJar + ';' +
path + "/lib/bld/javadoc-plugin-" + dokkaJar + ';' + path + "/lib/bld/javadoc-plugin-" + dokkaJar + ';' +
path + "/lib/bld/korte-jvm-4.0.10.jar;" + path + "/lib/bld/korte-jvm-4.0.10.jar;" +
path + "/lib/bld/kotlin-as-java-plugin-" + dokkaJar + ';' + path + "/lib/bld/kotlin-as-java-plugin-" + dokkaJar + ';' +
TestUtil.localPath("path1", "path2", "path3", "path4"), TestUtils.localPath(PATH_1, PATH_2, PATH_3, PATH_4),
"-sourceSet", "-src " + path + "/src/main/kotlin" + " -classpath " + path + "/foo.jar;" "-sourceSet", "-src " + path + "/src/main/kotlin" + " -classpath " + path + "/foo.jar;"
+ path + "/bar.jar", + path + "/bar.jar",
"-outputDir", path + "/build", "-outputDir", path + "/build",
"-delayTemplateSubstitution", "-delayTemplateSubstitution",
"-failOnWarning", "-failOnWarning",
"-globalLinks", "s^link^^s2^link2", "-globalLinks", "s^gLink1^^s2^gLink2",
"-globalPackageOptions", "option1;option2;option3;option4", "-globalPackageOptions", OPTION_1 + ';' + OPTION_2 + ';' + OPTION_3 + ';' + OPTION_4,
"-globalSrcLinks_", "link1;link2;link3;link4", "-globalSrcLinks_", "link1;link2;link3;link4",
"-includes", TestUtil.localPath("file1", "file2", "file3", "file4"), "-includes", TestUtils.localPath(FILE_1, FILE_2, FILE_3, FILE_4),
"-loggingLevel", "debug", "-loggingLevel", "debug",
"-moduleName", "name", "-moduleName", "name",
"-moduleVersion", "1.0", "-moduleVersion", "1.0",
@ -134,4 +165,20 @@ class DokkaOperationTest {
} }
}); });
} }
@Test
void executeNoProjectTest() {
var op = new DokkaOperation();
assertThatThrownBy(op::execute).isInstanceOf(ExitStatusException.class);
}
@Test
void executeTest() {
var op = new DokkaOperation()
.fromProject(
new BaseProjectBlueprint(EXAMPLES, "com.example", "examples"))
.outputDir("build/javadoc")
.outputFormat(OutputFormat.JAVADOC);
assertThatCode(op::execute).doesNotThrowAnyException();
}
} }

View file

@ -23,8 +23,8 @@ import java.util.stream.Collectors;
import static rife.bld.extension.DokkaOperation.SEMICOLON; import static rife.bld.extension.DokkaOperation.SEMICOLON;
@SuppressWarnings("PMD.TestClassWithoutTestCases") @SuppressWarnings("PMD.TestClassWithoutTestCases")
public final class TestUtil { public final class TestUtils {
private TestUtil() { private TestUtils() {
// no-op // no-op
} }
@ -35,6 +35,6 @@ public final class TestUtil {
* @return the local path * @return the local path
*/ */
public static String localPath(String... fileNames) { public static String localPath(String... fileNames) {
return Arrays.stream(fileNames).map(it -> new File(it).getAbsolutePath()).collect(Collectors.joining(SEMICOLON)); return Arrays.stream(fileNames).map(f -> new File(f).getAbsolutePath()).collect(Collectors.joining(SEMICOLON));
} }
} }

View file

@ -27,36 +27,52 @@ import java.util.Map;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static rife.bld.extension.TestUtil.localPath; import static rife.bld.extension.TestUtils.localPath;
class SourceSetTest { class SourceSetTest {
public static final String SAMPLES_1 = "samples1"; private static final String CLASSPATH_1 = "classpath1";
public static final String SAMPLES_2 = "samples2"; private static final String CLASSPATH_2 = "classpath2";
public static final String SUP_1 = "sup1"; private static final String INCLUDES_1 = "includes1";
public static final String SUP_2 = "sup2"; private static final String INCLUDES_2 = "includes2";
private static final String INCLUDES_3 = "includes3";
private static final String INCLUDES_4 = "includes4";
private static final String OPTION_1 = "option1";
private static final String OPTION_2 = "option2";
private static final String PATH_1 = "path1";
private static final String PATH_2 = "path2";
private static final String SAMPLES_1 = "samples1";
private static final String SAMPLES_2 = "samples2";
private static final String SAMPLES_3 = "samples3";
private static final String SRC_1 = "src1";
private static final String SRC_2 = "src2";
private static final String SRC_3 = "src3";
private static final String SRC_4 = "src4";
private static final String SUP_1 = "sup1";
private static final String SUP_2 = "sup2";
private static final String SUP_3 = "sup3";
@Test @Test
void sourceSetCollectionsTest() { void sourceSetCollectionsTest() {
var args = new SourceSet() var args = new SourceSet()
.classpath(List.of(new File("path1"), new File("path2"))) .classpath(List.of(new File(PATH_1), new File(PATH_2)))
.dependentSourceSets(Map.of("set1", "set2", "set3", "set4")) .dependentSourceSets(Map.of("set1", "set2", "set3", "set4"))
.externalDocumentationLinks(Map.of("link1", "link2", "link3", "link4")) .externalDocumentationLinks(Map.of("link1", "link2", "link3", "link4"))
.perPackageOptions(List.of("option1", "option2")) .perPackageOptions(List.of(OPTION_1, OPTION_2))
.samples(List.of(new File(SAMPLES_1))) .samples(List.of(new File(SAMPLES_1)))
.samples(new File(SAMPLES_2)) .samples(new File(SAMPLES_2))
.samples("samples3") .samples(SAMPLES_3)
.suppressedFiles(List.of(new File(SUP_1))) .suppressedFiles(List.of(new File(SUP_1)))
.suppressedFiles(new File(SUP_2)) .suppressedFiles(new File(SUP_2))
.suppressedFiles("sup3") .suppressedFiles(SUP_3)
.args(); .args();
var matches = List.of( var matches = List.of(
"-classpath", localPath("path1", "path2"), "-classpath", localPath(PATH_1, PATH_2),
"-dependentSourceSets", "set1/set2;set3/set4", "-dependentSourceSets", "set1/set2;set3/set4",
"-externalDocumentationLinks", "link3^link4^^link1^link2", "-externalDocumentationLinks", "link3^link4^^link1^link2",
"-perPackageOptions", "option1;option2", "-perPackageOptions", OPTION_1 + ';' + OPTION_2,
"-samples", localPath(SAMPLES_1, SAMPLES_2, "samples3"), "-samples", localPath(SAMPLES_1, SAMPLES_2, SAMPLES_3),
"-suppressedFiles", localPath(SUP_1, SUP_2, "sup3") "-suppressedFiles", localPath(SUP_1, SUP_2, SUP_3)
); );
assertThat(args).hasSize(matches.size()); assertThat(args).hasSize(matches.size());
@ -65,7 +81,12 @@ class SourceSetTest {
} }
@Test @Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals") void sourceSetIntVersionsTest() {
var args = new SourceSet().apiVersion(1).languageVersion(2);
assertThat(args.args()).containsExactly("-apiVersion", "1", "-languageVersion", "2");
}
@Test
void sourceSetTest() throws IOException { void sourceSetTest() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-sourceset-args.txt")); var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-sourceset-args.txt"));
@ -74,32 +95,32 @@ class SourceSetTest {
var sourceSet = new SourceSet() var sourceSet = new SourceSet()
.analysisPlatform(AnalysisPlatform.JVM) .analysisPlatform(AnalysisPlatform.JVM)
.apiVersion("1.0") .apiVersion("1.0")
.classpath("classpath1") .classpath(CLASSPATH_1)
.classpath(new File("classpath2")) .classpath(new File(CLASSPATH_2))
.dependentSourceSets("moduleName", "sourceSetName") .dependentSourceSets("moduleName", "sourceSetName")
.dependentSourceSets("moduleName2", "sourceSetName2") .dependentSourceSets("moduleName2", "sourceSetName2")
.displayName("name") .displayName("name")
.documentedVisibilities(DocumentedVisibility.PACKAGE, DocumentedVisibility.PRIVATE) .documentedVisibilities(DocumentedVisibility.PACKAGE, DocumentedVisibility.PRIVATE)
.externalDocumentationLinks("url1", "packageListUrl1") .externalDocumentationLinks("url1", "packageListUrl1")
.externalDocumentationLinks("url2", "packageListUrl2") .externalDocumentationLinks("url2", "packageListUrl2")
.includes("includes1", "includes2") .includes(INCLUDES_1, INCLUDES_2)
.includes(new File("includes3")) .includes(new File(INCLUDES_3))
.includes(List.of(new File("includes4"))) .includes(List.of(new File(INCLUDES_4)))
.jdkVersion(18) .jdkVersion(18)
.languageVersion("2.0") .languageVersion("2.0")
.noJdkLink(true) .noJdkLink(true)
.noSkipEmptyPackages(true) .noSkipEmptyPackages(true)
.noStdlibLink(true) .noStdlibLink(true)
.perPackageOptions("options1", "options2") .perPackageOptions(OPTION_1, OPTION_2)
.reportUndocumented(true) .reportUndocumented(true)
.samples(SAMPLES_1, SAMPLES_2) .samples(SAMPLES_1, SAMPLES_2)
.skipDeprecated(true) .skipDeprecated(true)
.sourceSetName("setName") .sourceSetName("setName")
.src("src1", "src2") .src(SRC_1, SRC_2)
.src(new File("src3")) .src(new File(SRC_3))
.src(List.of(new File("src4"))) .src(List.of(new File(SRC_4)))
.srcLink("path1", "remote1", "#suffix1") .srcLink(PATH_1, "remote1", "#suffix1")
.srcLink(new File("path2"), "remote2", "#suffix2") .srcLink(new File(PATH_2), "remote2", "#suffix2")
.suppressedFiles(SUP_1, SUP_2); .suppressedFiles(SUP_1, SUP_2);
assertThat(sourceSet.classpath()).as("classpath").hasSize(2); assertThat(sourceSet.classpath()).as("classpath").hasSize(2);
@ -129,31 +150,32 @@ class SourceSetTest {
var matches = List.of( var matches = List.of(
"-analysisPlatform", "jvm", "-analysisPlatform", "jvm",
"-apiVersion", "1.0", "-apiVersion", "1.0",
"-classpath", localPath("classpath1", "classpath2"), "-classpath", localPath(CLASSPATH_1, CLASSPATH_2),
"-dependentSourceSets", "moduleName/sourceSetName;moduleName2/sourceSetName2", "-dependentSourceSets", "moduleName/sourceSetName;moduleName2/sourceSetName2",
"-displayName", "name", "-displayName", "name",
"-documentedVisibilities", "package;private", "-documentedVisibilities", "package;private",
"-externalDocumentationLinks", "url1^packageListUrl1^^url2^packageListUrl2", "-externalDocumentationLinks", "url1^packageListUrl1^^url2^packageListUrl2",
"-jdkVersion", "18", "-jdkVersion", "18",
"-includes", localPath("includes1", "includes2", "includes3", "includes4"), "-includes", localPath(INCLUDES_1, INCLUDES_2, INCLUDES_3, INCLUDES_4),
"-languageVersion", "2.0", "-languageVersion", "2.0",
"-noJdkLink", "true", "-noJdkLink",
"-noSkipEmptyPackages", "true", "-noSkipEmptyPackages",
"-noStdlibLink", "true", "-noStdlibLink",
"-reportUndocumented", "true", "-reportUndocumented",
"-perPackageOptions", "options1;options2", "-perPackageOptions", OPTION_1 + ';' + OPTION_2,
"-samples", localPath(SAMPLES_1, SAMPLES_2), "-samples", localPath(SAMPLES_1, SAMPLES_2),
"-skipDeprecated", "true", "-skipDeprecated",
"-src", localPath("src1", "src2", "src3", "src4"), "-src", localPath(SRC_1, SRC_2, SRC_3, SRC_4),
"-srcLink", localPath("path2") + "=remote2#suffix2;path1=remote1#suffix1", "-srcLink", localPath(PATH_2) + "=remote2#suffix2;path1=remote1#suffix1",
"-sourceSetName", "setName", "-sourceSetName", "setName",
"-suppressedFiles", localPath(SUP_1, SUP_2)); "-suppressedFiles", localPath(SUP_1, SUP_2));
assertThat(params).hasSize(matches.size()); assertThat(params).hasSize(matches.size());
IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i))); IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i)));
sourceSet.classpath(List.of(new File("classpath1"), new File("classpath2"))); sourceSet.classpath(List.of(new File(CLASSPATH_1), new File(CLASSPATH_2)));
IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i))); IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i)));
} }