Moved Dokka operation to its own extension

This commit is contained in:
Erik C. Thauvin 2024-06-15 21:31:36 -07:00
parent 1623b902f9
commit 8d34f37af0
Signed by: erik
GPG key ID: 776702A6A2DA330E
19 changed files with 26 additions and 1828 deletions

View file

@ -1,123 +0,0 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension.dokka;
import org.junit.jupiter.api.Test;
import rife.bld.blueprints.BaseProjectBlueprint;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat;
class DokkaOperationTest {
@Test
@SuppressWarnings({"ExtractMethodRecommender", "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 params = 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"))
.globalSrcLink("link1", "link2")
.globalSrcLink(List.of("link3", "link4"))
.includes("file1", "file2")
.includes(List.of("file3", "file4"))
.json(jsonConf)
.loggingLevel(LoggingLevel.DEBUG)
.moduleName("name")
.moduleVersion("1.0")
.noSuppressObviousFunctions(true)
.offlineMode(true)
.outputDir(new File(examples, "build"))
.outputFormat(OutputFormat.JAVADOC)
.pluginConfigurations("name", "{\"json\"}")
.pluginConfigurations(Map.of("{\"name2\"}", "json2", "name3}", "{json3"))
.pluginsClasspath("path1", "path2")
.pluginsClasspath(List.of("path3", "path4"))
.sourceSet(new SourceSet().classpath(
List.of(
new File("examples/foo.jar"),
new File("examples/bar.jar")
)))
.suppressInheritedMembers(true)
.executeConstructProcessCommandList();
for (var p : args) {
var found = false;
for (var a : params) {
if (a.startsWith(p)) {
found = true;
break;
}
}
assertThat(found).as(p + " not found.").isTrue();
}
var path = examples.getAbsolutePath();
var dokkaJar = "1.9.20.jar";
var matches = List.of("java",
"-jar", path + "/lib/bld/dokka-cli-" + dokkaJar,
"-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 + ";path1;path2;path3;path4",
"-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",
"-globalSrcLinks_", "link1;link2;link3;link4",
"-includes", "file1;file2;file3;file4",
"-loggingLevel", "debug",
"-moduleName", "name",
"-moduleVersion", "1.0",
"-noSuppressObviousFunctions",
"-offlineMode",
"-pluginsConfiguration", "{\\\"name2\\\"}={json2}^^{name}={\\\"json\\\"}^^{name3}}={{json3}",
"-suppressInheritedMembers",
jsonConf.getAbsolutePath());
assertThat(params).hasSize(matches.size());
IntStream.range(0, params.size()).forEach(i -> {
if (params.get(i).contains(".jar;")) {
var jars = params.get(i).split(";");
Arrays.stream(jars).forEach(jar -> assertThat(matches.get(i)).as(matches.get(i)).contains(jar));
} else {
assertThat(params.get(i)).as(params.get(i)).isEqualTo(matches.get(i));
}
});
}
}

View file

@ -1,132 +0,0 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rife.bld.extension.dokka;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat;
class SourceSetTest {
@Test
void sourceSetCollectionsTest() {
var args = new SourceSet()
.classpath(List.of("path1", "path2"))
.dependentSourceSets(Map.of("set1", "set2", "set3", "set4"))
.externalDocumentationLinks(Map.of("link1", "link2", "link3", "link4"))
.perPackageOptions(List.of("option1", "option2"))
.samples(List.of("samples1", "samples1"))
.suppressedFiles(List.of("sup1", "sup2"))
.args();
var matches = List.of(
"-classpath", "path1;path2",
"-dependentSourceSets", "set1/set2;set3/set4",
"-externalDocumentationLinks", "link3^link4^^link1^link2",
"-perPackageOptions", "option1;option2",
"-samples", "samples1;samples1",
"-suppressedFiles", "sup1;sup2"
);
assertThat(args).hasSize(matches.size());
IntStream.range(0, args.size()).forEach(i -> assertThat(args.get(i)).isEqualTo(matches.get(i)));
}
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
void sourceSetTest() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-sourceset-args.txt"));
assertThat(args).isNotEmpty();
var sourceSet = new SourceSet()
.analysisPlatform(AnalysisPlatform.JVM)
.apiVersion("1.0")
.classpath("classpath1", "classpath2")
.dependentSourceSets("moduleName", "sourceSetName")
.displayName("name")
.documentedVisibilities(DocumentedVisibility.PACKAGE, DocumentedVisibility.PRIVATE)
.externalDocumentationLinks("url1", "packageListUrl1")
.externalDocumentationLinks("url2", "packageListUrl2")
.includes("includes1", "includes2")
.jdkVersion(18)
.languageVersion("2.0")
.noJdkLink(true)
.noSkipEmptyPackages(true)
.noStdlibLink(true)
.perPackageOptions("options1", "options2")
.reportUndocumented(true)
.samples("samples1", "sample2")
.skipDeprecated(true)
.sourceSetName("setName")
.src("src1", "src2")
.srcLink("path1", "remote1", "#suffix1")
.srcLink("path2", "remote2", "#suffix2")
.suppressedFiles("sup1", "sup2");
var params = sourceSet.args();
for (var p : args) {
var found = false;
for (var a : params) {
if (a.startsWith(p)) {
found = true;
break;
}
}
assertThat(found).as(p + " not found.").isTrue();
}
var matches = List.of(
"-analysisPlatform", "jvm",
"-apiVersion", "1.0",
"-classpath", "classpath1;classpath2",
"-dependentSourceSets", "moduleName/sourceSetName",
"-displayName", "name",
"-documentedVisibilities", "package;private",
"-externalDocumentationLinks", "url1^packageListUrl1^^url2^packageListUrl2",
"-jdkVersion", "18",
"-includes", "includes1;includes2",
"-languageVersion", "2.0",
"-noJdkLink", "true",
"-noSkipEmptyPackages", "true",
"-noStdlibLink", "true",
"-reportUndocumented", "true",
"-perPackageOptions", "options1;options2",
"-samples", "samples1;sample2",
"-skipDeprecated", "true",
"-src", "src1;src2",
"-srcLink", "path1=remote1#suffix1;path2=remote2#suffix2",
"-sourceSetName", "setName",
"-suppressedFiles", "sup1;sup2");
assertThat(params).hasSize(matches.size());
IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i)));
sourceSet.classpath(List.of("classpath1", "classpath2"));
IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i)));
}
}

View file

@ -1,16 +0,0 @@
-delayTemplateSubstitution
-failOnWarning
-globalLinks
-globalPackageOptions
-globalSrcLink
-includes
-loggingLevel
-moduleName
-moduleVersion
-noSuppressObviousFunctions
-offlineMode
-outputDir
-pluginsClasspath
-pluginsConfiguration
-sourceSet
-suppressInheritedMembers

View file

@ -1,21 +0,0 @@
-analysisPlatform
-apiVersion
-classpath
-dependentSourceSets
-displayName
-documentedVisibilities
-externalDocumentationLinks
-includes
-jdkVersion
-languageVersion
-noJdkLink
-noSkipEmptyPackages
-noStdlibLink
-perPackageOptions
-reportUndocumented
-samples
-skipDeprecated
-sourceSetName
-src
-srcLink
-suppressedFiles