Added the compile and provided classpaths to the sourceSet when DokkaOperation().fromProject() is called. Closes #3

This commit is contained in:
Erik C. Thauvin 2024-05-25 00:59:51 -07:00
parent deb66a2d20
commit d2560125d7
Signed by: erik
GPG key ID: 776702A6A2DA330E
4 changed files with 45 additions and 16 deletions

View file

@ -50,8 +50,8 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
private final Collection<String> globalPackageOptions_ = new ArrayList<>();
private final Collection<String> globalSrcLinks_ = new ArrayList<>();
private final Collection<String> includes_ = new ArrayList<>();
private final Map<String, String> pluginsConfiguration_ = new ConcurrentHashMap<>();
private final Collection<String> pluginsClasspath_ = new ArrayList<>();
private final Map<String, String> pluginsConfiguration_ = new ConcurrentHashMap<>();
private boolean delayTemplateSubstitution_;
private boolean failOnWarning_;
private LoggingLevel loggingLevel_;
@ -226,15 +226,18 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
/**
* Configures the operation from a {@link BaseProject}.
* <p>
* Sets the {@link #sourceSet sourceSet}, {@link SourceSet#jdkVersion jdkVersion} and {@link #moduleName moduleName}
* from the project.
* Sets the {@link #sourceSet sourceSet}, {@link SourceSet#jdkVersion jdkVersion}, {@link #moduleName moduleName}
* and {@link SourceSet#classpath(String...) classpath} from the project.
*
* @param project the project to configure the operation from
*/
@Override
public DokkaOperation fromProject(BaseProject project) {
project_ = project;
sourceSet_ = new SourceSet().src(new File(project.srcMainDirectory(), "kotlin").getAbsolutePath());
sourceSet_ = new SourceSet()
.src(new File(project.srcMainDirectory(), "kotlin").getAbsolutePath())
.classpath(project.compileClasspathJars())
.classpath(project.providedClasspathJars());
if (project.javaRelease() != null) {
sourceSet_ = sourceSet_.jdkVersion(project.javaRelease());
}

View file

@ -16,6 +16,7 @@
package rife.bld.extension.dokka;
import java.io.File;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -236,11 +237,11 @@ public class SourceSet {
* <p>
* This option accepts both {@code .jar} and {@code .klib} files.
*
* @param classpath one or more classpath
* @param files one or more file
* @return this operation instance
*/
public SourceSet classpath(String... classpath) {
classpath_.addAll(Arrays.asList(classpath));
public SourceSet classpath(String... files) {
classpath_.addAll(Arrays.asList(files));
return this;
}
@ -251,11 +252,26 @@ public class SourceSet {
* <p>
* This option accepts both {@code .jar} and {@code .klib} files.
*
* @param classpath the list of classpath
* @param files the list of files
* @return this operation instance
*/
public SourceSet classpath(Collection<String> classpath) {
classpath_.addAll(classpath);
public SourceSet classpath(Collection<String> files) {
classpath_.addAll(files);
return this;
}
/**
* Sets classpath for analysis and interactive samples.
* <p>
* This is useful if some types that come from dependencies are not resolved/picked up automatically.
* <p>
* This option accepts both {@code .jar} and {@code .klib} files.
*
* @param files the list of files
* @return this operation instance
*/
public SourceSet classpath(List<File> files) {
files.forEach(it -> classpath_.add(it.getAbsolutePath()));
return this;
}

View file

@ -55,6 +55,11 @@ class DokkaOperationTest {
.outputDir(new File(examples, "build"))
.outputFormat(OutputFormat.JAVADOC)
.suppressInheritedMembers(true)
.sourceSet(new SourceSet().classpath(
List.of(
new File("examples/foo.jar"),
new File("examples/bar.jar")
)))
.executeConstructProcessCommandList();
var path = examples.getAbsolutePath();
@ -66,7 +71,7 @@ class DokkaOperationTest {
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",
"-sourceSet", "-src " + path + "/src/main/kotlin" + " -classpath " + path + "/foo.jar;" + path + "/bar.jar",
"-outputDir", path + "/build",
"-delayTemplateSubstitution",
"-failOnWarning",
@ -87,9 +92,9 @@ class DokkaOperationTest {
IntStream.range(0, args.size()).forEach(i -> {
if (args.get(i).contains(".jar;")) {
var jars = args.get(i).split(";");
Arrays.stream(jars).forEach(jar -> assertThat(matches.get(i)).contains(jar));
Arrays.stream(jars).forEach(jar -> assertThat(matches.get(i)).as(matches.get(i)).contains(jar));
} else {
assertThat(args.get(i)).isEqualTo(matches.get(i));
assertThat(args.get(i)).as(args.get(i)).isEqualTo(matches.get(i));
}
});
}

View file

@ -53,7 +53,7 @@ class SourceSetTest {
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
void sourceSetTest() {
var args = new SourceSet()
var sourceSet = new SourceSet()
.classpath("classpath1", "classpath2")
.dependentSourceSets("moduleName", "sourceSetName")
.documentedVisibilities(DocumentedVisibility.PACKAGE, DocumentedVisibility.PRIVATE)
@ -76,8 +76,9 @@ class SourceSetTest {
.noStdlibLink(true)
.reportUndocumented(true)
.skipDeprecated(true)
.sourceSetName("setName")
.args();
.sourceSetName("setName");
var args = sourceSet.args();
var matches = List.of(
"-analysisPlatform", "jvm",
@ -105,5 +106,9 @@ class SourceSetTest {
assertThat(args).hasSize(matches.size());
IntStream.range(0, args.size()).forEach(i -> assertThat(args.get(i)).isEqualTo(matches.get(i)));
sourceSet.classpath(List.of("classpath1", "classpath2"));
IntStream.range(0, args.size()).forEach(i -> assertThat(args.get(i)).isEqualTo(matches.get(i)));
}
}