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

View file

@ -2,12 +2,12 @@
<library name="bld">
<CLASSES>
<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" />
</CLASSES>
<JAVADOC />
<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" />
</SOURCES>
<excluded>

View file

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

View file

@ -2,12 +2,12 @@
<library name="bld">
<CLASSES>
<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>
<JAVADOC />
<SOURCES>
<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>
<excluded>
<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="dokkaGfm" />
<pattern value="com.example.ExampleBuild" method="dokkaJekyll" />
<pattern value="com.example.ExampleBuild" method="docs" />
</component>
<component name="PDMPlugin">
<option name="customRuleSets">

View file

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

View file

@ -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

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.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
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));
scope(test)
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 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, 3)));
// Include the Kotlin source directory when creating or publishing sources Java Archives
jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin"));
@ -48,26 +48,34 @@ public class ExampleBuild extends Project {
public static void main(String[] args) {
// Enable detailed logging for the Kotlin extension
// 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);
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);
new ExampleBuild().start(args);
}
@BuildCommand(summary = "Compiles the Kotlin project")
@Override
public void compile() throws IOException {
public void compile() throws Exception {
new CompileKotlinOperation()
.fromProject(this)
.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()

Binary file not shown.

View file

@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.0
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.0.1
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_RELEASES
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.1
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.2
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
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("com.uwyn.rife2", "bld", version(1, 9, 1)));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0)));
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)))
.include(dependency("org.assertj", "assertj-core", version(3, 26, 3)));
javadocOperation()
.javadocOptions()
@ -95,7 +95,7 @@ public class DokkaOperationBuild extends Project {
}
@BuildCommand(summary = "Runs PMD analysis")
public void pmd() {
public void pmd() throws Exception {
new PmdOperation()
.fromProject(this)
.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.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;
@ -56,7 +58,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
private final Map<String, String> pluginsConfiguration_ = new ConcurrentHashMap<>();
private boolean delayTemplateSubstitution_;
private boolean failOnWarning_;
private File json;
private File json_;
private LoggingLevel loggingLevel_;
private String moduleName_;
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 regex the regular expression to match
* @return the list of JARs
* @return the Java Archives
*/
public static List<File> getJarList(File directory, String regex) {
var jars = new ArrayList<File>();
@ -124,6 +128,18 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
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.
*
@ -131,136 +147,134 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
*/
@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$");
if (cli.size() != 1) {
throw new RuntimeException("The dokka-cli JAR could not be found.");
}
// -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());
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)));
}
args.add("-outputDir");
args.add(outputDir_.getAbsolutePath());
}
// main class
args.add("org.jetbrains.dokka.MainKt");
// -delayTemplateSubstitution
if (delayTemplateSubstitution_) {
args.add("-delayTemplateSubstitution");
}
// -pluginClasspath
if (!pluginsClasspath_.isEmpty()) {
args.add("-pluginsClasspath");
args.add(pluginsClasspath_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -failOnWarning
if (failOnWarning_) {
args.add("-failOnWarning");
}
// -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()));
}
// -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));
}
// -outputDir
if (outputDir_ != null) {
if (!outputDir_.exists() && !outputDir_.mkdirs()) {
throw new RuntimeException("Could not create: " + outputDir_.getAbsolutePath());
}
// -globalPackageOptions
if (!globalPackageOptions_.isEmpty()) {
args.add("-globalPackageOptions");
args.add(String.join(SEMICOLON, globalPackageOptions_));
}
args.add("-outputDir");
args.add(outputDir_.getAbsolutePath());
}
// -globalSrcLinks
if (!globalSrcLinks_.isEmpty()) {
args.add("-globalSrcLinks_");
args.add(String.join(SEMICOLON, globalSrcLinks_));
}
// -delayTemplateSubstitution
if (delayTemplateSubstitution_) {
args.add("-delayTemplateSubstitution");
}
// -includes
if (!includes_.isEmpty()) {
args.add("-includes");
args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -failOnWarning
if (failOnWarning_) {
args.add("-failOnWarning");
}
// -loggingLevel
if (loggingLevel_ != null) {
args.add("-loggingLevel");
args.add(loggingLevel_.name().toLowerCase());
}
// -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));
}
// -moduleName
if (isNotBlank(moduleName_)) {
args.add("-moduleName");
args.add(moduleName_);
}
// -globalPackageOptions
if (!globalPackageOptions_.isEmpty()) {
args.add("-globalPackageOptions");
args.add(String.join(SEMICOLON, globalPackageOptions_));
}
// -moduleVersion
if (isNotBlank(moduleVersion_)) {
args.add("-moduleVersion");
args.add(moduleVersion_);
}
// -globalSrcLinks
if (!globalSrcLinks_.isEmpty()) {
args.add("-globalSrcLinks_");
args.add(String.join(SEMICOLON, globalSrcLinks_));
}
// -noSuppressObviousFunctions
if (noSuppressObviousFunctions_) {
args.add("-noSuppressObviousFunctions");
}
// -includes
if (!includes_.isEmpty()) {
args.add("-includes");
args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}
// -offlineMode
if (offlineMode_) {
args.add("-offlineMode");
}
// -loggingLevel
if (loggingLevel_ != null) {
args.add("-loggingLevel");
args.add(loggingLevel_.name().toLowerCase());
}
// -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));
}
// -moduleName
if (isNotBlank(moduleName_)) {
args.add("-moduleName");
args.add(moduleName_);
}
// -suppressInheritedMembers
if (suppressInheritedMembers_) {
args.add("-suppressInheritedMembers");
}
// -moduleVersion
if (isNotBlank(moduleVersion_)) {
args.add("-moduleVersion");
args.add(moduleVersion_);
}
// json
if (json != null) {
args.add(json.getAbsolutePath());
}
// -noSuppressObviousFunctions
if (noSuppressObviousFunctions_) {
args.add("-noSuppressObviousFunctions");
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.join(" ", args));
// -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));
}
// -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;
@ -338,7 +352,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
}
/**
* Sets the global list of package configurations.
* Sets the global package configurations.
* <p>
* Using format:
* <ul>
@ -355,12 +369,12 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance
*/
public DokkaOperation globalPackageOptions(String... options) {
Collections.addAll(globalPackageOptions_, options);
globalPackageOptions_.addAll(List.of(options));
return this;
}
/**
* Retrieves the global list of package configurations.
* Retrieves the global 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>
* Using format:
* <ul>
@ -382,7 +396,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* <li>...</li>
* </ul>
*
* @param options the list of package configurations
* @param options the package configurations
* @return this operation instance
*/
public DokkaOperation globalPackageOptions(Collection<String> options) {
@ -397,7 +411,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance
*/
public DokkaOperation globalSrcLink(String... links) {
Collections.addAll(globalSrcLinks_, links);
globalSrcLinks_.addAll(List.of(links));
return this;
}
@ -432,7 +446,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance
*/
public DokkaOperation includes(File... files) {
Collections.addAll(includes_, files);
includes_.addAll(List.of(files));
return this;
}
@ -447,9 +461,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @return this operation instance
*/
public DokkaOperation includes(String... files) {
Collections.addAll(includes_, Arrays.stream(files)
.map(File::new)
.toArray(File[]::new));
includes_.addAll(Arrays.stream(files).map(File::new).toList());
return this;
}
@ -469,7 +481,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* <p>
* This can be configured on per-package basis.
*
* @param files the list of files
* @param files the markdown files
* @return this operation instance
*/
public DokkaOperation includes(Collection<File> files) {
@ -483,7 +495,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
* @param configuration the configuration file path
*/
public DokkaOperation json(File configuration) {
json = configuration;
json_ = configuration;
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
* @return this operation instance
*/
public DokkaOperation pluginsClasspath(File... jars) {
Collections.addAll(pluginsClasspath_, jars);
pluginsClasspath_.addAll(List.of(jars));
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
* @return this operation instance
*/
public DokkaOperation pluginsClasspath(String... jars) {
Collections.addAll(pluginsClasspath_, Arrays.stream(jars)
.map(File::new)
.toArray(File[]::new));
pluginsClasspath_.addAll(Arrays.stream(jars).map(File::new).toList());
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
*/
public DokkaOperation pluginsClasspath(Collection<File> jars) {

View file

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

View file

@ -16,11 +16,13 @@
package rife.bld.extension;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat;
import rife.bld.extension.dokka.SourceSet;
import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.IOException;
@ -29,46 +31,74 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
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 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 {
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
@SuppressWarnings({"PMD.AvoidDuplicateLiterals"})
void executeConstructProcessCommandListTest() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-args.txt"));
assertThat(args).isNotEmpty();
var examples = new File("examples");
var jsonConf = new File("config.json");
var op = new DokkaOperation()
.delayTemplateSubstitution(true)
.failOnWarning(true)
.fromProject(new BaseProjectBlueprint(examples, "com.example", "Example"))
.globalLinks("s", "link")
.globalLinks(Map.of("s2", "link2"))
.globalPackageOptions("option1", "option2")
.globalPackageOptions(List.of("option3", "option4"))
.fromProject(new BaseProjectBlueprint(EXAMPLES, "com.example", "Example"))
.globalLinks("s", "gLink1")
.globalLinks(Map.of("s2", "gLink2"))
.globalPackageOptions(OPTION_1, OPTION_2)
.globalPackageOptions(List.of(OPTION_3, OPTION_4))
.globalSrcLink("link1", "link2")
.globalSrcLink(List.of("link3", "link4"))
.includes(new File("file1"))
.includes("file2")
.includes(List.of(new File("file3"), new File("file4")))
.includes(new File(FILE_1))
.includes(FILE_2)
.includes(List.of(new File(FILE_3), new File(FILE_4)))
.json(jsonConf)
.loggingLevel(LoggingLevel.DEBUG)
.moduleName("name")
.moduleVersion("1.0")
.noSuppressObviousFunctions(true)
.offlineMode(true)
.outputDir(new File(examples, "build"))
.outputDir(new File(EXAMPLES, "build"))
.outputFormat(OutputFormat.JAVADOC)
.pluginConfigurations("name", "{\"json\"}")
.pluginConfigurations(Map.of("{\"name2\"}", "json2", "name3}", "{json3"))
.pluginsClasspath(new File("path1"))
.pluginsClasspath("path2")
.pluginsClasspath(List.of(new File("path3"), new File("path4")))
.pluginsClasspath(new File(PATH_1))
.pluginsClasspath(PATH_2)
.pluginsClasspath(List.of(new File(PATH_3), new File(PATH_4)))
.sourceSet(new SourceSet().classpath(
List.of(
new File("examples/foo.jar"),
@ -95,25 +125,26 @@ class DokkaOperationTest {
assertThat(found).as(p + " not found.").isTrue();
}
var path = examples.getAbsolutePath();
var path = EXAMPLES.getAbsolutePath();
var dokkaJar = "1.9.20.jar";
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 + ';' +
path + "/lib/bld/analysis-kotlin-descriptors-" + dokkaJar + ';' +
path + "/lib/bld/javadoc-plugin-" + dokkaJar + ';' +
path + "/lib/bld/korte-jvm-4.0.10.jar;" +
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;"
+ path + "/bar.jar",
"-outputDir", path + "/build",
"-delayTemplateSubstitution",
"-failOnWarning",
"-globalLinks", "s^link^^s2^link2",
"-globalPackageOptions", "option1;option2;option3;option4",
"-globalLinks", "s^gLink1^^s2^gLink2",
"-globalPackageOptions", OPTION_1 + ';' + OPTION_2 + ';' + OPTION_3 + ';' + OPTION_4,
"-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",
"-moduleName", "name",
"-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;
@SuppressWarnings("PMD.TestClassWithoutTestCases")
public final class TestUtil {
private TestUtil() {
public final class TestUtils {
private TestUtils() {
// no-op
}
@ -35,6 +35,6 @@ public final class TestUtil {
* @return the local path
*/
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 static org.assertj.core.api.Assertions.assertThat;
import static rife.bld.extension.TestUtil.localPath;
import static rife.bld.extension.TestUtils.localPath;
class SourceSetTest {
public static final String SAMPLES_1 = "samples1";
public static final String SAMPLES_2 = "samples2";
public static final String SUP_1 = "sup1";
public static final String SUP_2 = "sup2";
private static final String CLASSPATH_1 = "classpath1";
private static final String CLASSPATH_2 = "classpath2";
private static final String INCLUDES_1 = "includes1";
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
void sourceSetCollectionsTest() {
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"))
.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(new File(SAMPLES_2))
.samples("samples3")
.samples(SAMPLES_3)
.suppressedFiles(List.of(new File(SUP_1)))
.suppressedFiles(new File(SUP_2))
.suppressedFiles("sup3")
.suppressedFiles(SUP_3)
.args();
var matches = List.of(
"-classpath", localPath("path1", "path2"),
"-classpath", localPath(PATH_1, PATH_2),
"-dependentSourceSets", "set1/set2;set3/set4",
"-externalDocumentationLinks", "link3^link4^^link1^link2",
"-perPackageOptions", "option1;option2",
"-samples", localPath(SAMPLES_1, SAMPLES_2, "samples3"),
"-suppressedFiles", localPath(SUP_1, SUP_2, "sup3")
"-perPackageOptions", OPTION_1 + ';' + OPTION_2,
"-samples", localPath(SAMPLES_1, SAMPLES_2, SAMPLES_3),
"-suppressedFiles", localPath(SUP_1, SUP_2, SUP_3)
);
assertThat(args).hasSize(matches.size());
@ -65,7 +81,12 @@ class SourceSetTest {
}
@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 {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-sourceset-args.txt"));
@ -74,32 +95,32 @@ class SourceSetTest {
var sourceSet = new SourceSet()
.analysisPlatform(AnalysisPlatform.JVM)
.apiVersion("1.0")
.classpath("classpath1")
.classpath(new File("classpath2"))
.classpath(CLASSPATH_1)
.classpath(new File(CLASSPATH_2))
.dependentSourceSets("moduleName", "sourceSetName")
.dependentSourceSets("moduleName2", "sourceSetName2")
.displayName("name")
.documentedVisibilities(DocumentedVisibility.PACKAGE, DocumentedVisibility.PRIVATE)
.externalDocumentationLinks("url1", "packageListUrl1")
.externalDocumentationLinks("url2", "packageListUrl2")
.includes("includes1", "includes2")
.includes(new File("includes3"))
.includes(List.of(new File("includes4")))
.includes(INCLUDES_1, INCLUDES_2)
.includes(new File(INCLUDES_3))
.includes(List.of(new File(INCLUDES_4)))
.jdkVersion(18)
.languageVersion("2.0")
.noJdkLink(true)
.noSkipEmptyPackages(true)
.noStdlibLink(true)
.perPackageOptions("options1", "options2")
.perPackageOptions(OPTION_1, OPTION_2)
.reportUndocumented(true)
.samples(SAMPLES_1, SAMPLES_2)
.skipDeprecated(true)
.sourceSetName("setName")
.src("src1", "src2")
.src(new File("src3"))
.src(List.of(new File("src4")))
.srcLink("path1", "remote1", "#suffix1")
.srcLink(new File("path2"), "remote2", "#suffix2")
.src(SRC_1, SRC_2)
.src(new File(SRC_3))
.src(List.of(new File(SRC_4)))
.srcLink(PATH_1, "remote1", "#suffix1")
.srcLink(new File(PATH_2), "remote2", "#suffix2")
.suppressedFiles(SUP_1, SUP_2);
assertThat(sourceSet.classpath()).as("classpath").hasSize(2);
@ -129,31 +150,32 @@ class SourceSetTest {
var matches = List.of(
"-analysisPlatform", "jvm",
"-apiVersion", "1.0",
"-classpath", localPath("classpath1", "classpath2"),
"-classpath", localPath(CLASSPATH_1, CLASSPATH_2),
"-dependentSourceSets", "moduleName/sourceSetName;moduleName2/sourceSetName2",
"-displayName", "name",
"-documentedVisibilities", "package;private",
"-externalDocumentationLinks", "url1^packageListUrl1^^url2^packageListUrl2",
"-jdkVersion", "18",
"-includes", localPath("includes1", "includes2", "includes3", "includes4"),
"-includes", localPath(INCLUDES_1, INCLUDES_2, INCLUDES_3, INCLUDES_4),
"-languageVersion", "2.0",
"-noJdkLink", "true",
"-noSkipEmptyPackages", "true",
"-noStdlibLink", "true",
"-reportUndocumented", "true",
"-perPackageOptions", "options1;options2",
"-noJdkLink",
"-noSkipEmptyPackages",
"-noStdlibLink",
"-reportUndocumented",
"-perPackageOptions", OPTION_1 + ';' + OPTION_2,
"-samples", localPath(SAMPLES_1, SAMPLES_2),
"-skipDeprecated", "true",
"-src", localPath("src1", "src2", "src3", "src4"),
"-srcLink", localPath("path2") + "=remote2#suffix2;path1=remote1#suffix1",
"-skipDeprecated",
"-src", localPath(SRC_1, SRC_2, SRC_3, SRC_4),
"-srcLink", localPath(PATH_2) + "=remote2#suffix2;path1=remote1#suffix1",
"-sourceSetName", "setName",
"-suppressedFiles", localPath(SUP_1, SUP_2));
assertThat(params).hasSize(matches.size());
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)));
}