Added Kotlin libs directory option (untested)

This commit is contained in:
Erik C. Thauvin 2023-11-09 02:57:42 -08:00
parent 6cb2955575
commit b7037378bc
4 changed files with 78 additions and 36 deletions

View file

@ -47,6 +47,31 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
private File buildTestDirectory_;
private CompileKotlinOptions compileOptions_;
private KaptOptions kaptOptions_;
private File kotlinLibsDirectory_;
/**
* Returns the list JARs contained in a given directory.
*
* @param directory the directory
* @param regex the regular expression to match
* @return the list of JARs
*/
public static List<String> getJarList(File directory, String regex) {
var jars = new ArrayList<String>();
if (directory.isDirectory()) {
var files = directory.listFiles();
if (files != null) {
for (var f : files) {
if (!f.getName().contains("-sources") && f.getName().matches(regex)) {
jars.add(f.getAbsolutePath());
}
}
}
}
return jars;
}
public static Collection<File> getKotlinFileList(File directory) {
if (directory == null) {
@ -239,15 +264,21 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
args.addAll(compileOptions_.args());
}
// kapt options
if (kaptOptions_ != null) {
// kapt plugin & options
if (kotlinLibsDirectory_ != null && kaptOptions_ != null) {
var kaptJar = getJarList(kotlinLibsDirectory_, "^.*kotlin-annotation-processing.*\\.jar$");
if (kaptJar.size() == 1) {
args.add("-Xplugin=" + kaptJar.get(0));
kaptOptions_.args().forEach(a -> {
args.add("-P");
args.add(a);
});
} else if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("Could not locate the Kotlin annotation processing JAR in:" + kotlinLibsDirectory_);
}
}
// source
// sources
sources.forEach(f -> args.add(f.getAbsolutePath()));
if (LOGGER.isLoggable(Level.FINE) && !silent()) {
@ -293,6 +324,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
.buildTestDirectory(project.buildTestDirectory())
.compileMainClasspath(project.compileMainClasspath())
.compileTestClasspath(project.compileTestClasspath())
.kotlinLibsDirectory(project.libBldDirectory())
.mainSourceFiles(getKotlinFileList(new File(project.srcMainDirectory(), "kotlin")))
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
}
@ -308,6 +340,28 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
return this;
}
/**
* Provides the directory containing the Kotlin libraries (compiler, plugins, etc.) JARs.
*
* @param directory the directory location
* @return this class instance
*/
public CompileKotlinOperation kotlinLibsDirectory(File directory) {
kotlinLibsDirectory_ = directory;
return this;
}
/**
* Provides the directory containing the Kotlin libraries (compiler, plugins, etc.) JARs.
*
* @param directory the directory location
* @return this class instance
*/
public CompileKotlinOperation kotlinLibsDirectory(String directory) {
kotlinLibsDirectory_ = new File(directory);
return this;
}
/**
* Provides main source directories that should be compiled.
*

View file

@ -31,8 +31,8 @@ import java.util.logging.Logger;
* @since 1.0
*/
public class KaptOptions {
private final Logger LOGGER = Logger.getLogger(KaptOptions.class.getName());
private final static String PLUGIN_ID = "plugin:org.jetbrains.kotlin.kapt3:";
private final Logger LOGGER = Logger.getLogger(KaptOptions.class.getName());
private final List<String> apClasspath_ = new ArrayList<>();
private final Collection<Map<String, String>> apOptions_ = new ArrayList<>();
private final AptMode aptMode_;
@ -88,7 +88,7 @@ public class KaptOptions {
}
/**
* A path to the annotation processor JAR. Pass as many apclasspath as the number of JARs that you have.
* A path to the annotation processor JAR. Pass as many classpath as the number of JARs that you have.
*
* @param apClasspath the list of classpath
* @return this class instance
@ -229,7 +229,7 @@ public class KaptOptions {
return this;
}
// Base-64 encodes the option list
// Base-64 encodes the options list
private String encodeList(Map<String, String> options) throws IOException {
var os = new ByteArrayOutputStream();
var oos = new ObjectOutputStream(os);
@ -269,7 +269,7 @@ public class KaptOptions {
/**
* A list of the options passed to {@code javac}.
*
* @param javacArguments the arguments
* @param javacArguments the {@code javac} arguments
* @return this class instance
*/
public KaptOptions javacArguments(Map<String, String> javacArguments) {
@ -278,8 +278,8 @@ public class KaptOptions {
}
/**
* A list of annotation processor qualified class names. If specified, kapt does not try to find annotation
* processors in apclasspath
* A list of annotation processor qualified class names. If specified, {@code kapt} does not try to find annotation
* processors in {@link #apClasspath}.
*
* @param processors the list of qualified class names
* @return this class instance

View file

@ -17,6 +17,7 @@
package rife.bld.extension.dokka;
import rife.bld.BaseProject;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.operations.AbstractProcessOperation;
import rife.tools.StringUtils;
@ -89,7 +90,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
// java
args.add(javaTool());
var cli = getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
var cli = CompileKotlinOperation.getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
if (cli.size() != 1) {
throw new RuntimeException("The dokka-cli JAR could not be found.");
@ -239,23 +240,6 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
return this;
}
private List<String> getJarList(File directory, String regex) {
var jars = new ArrayList<String>();
if (directory.isDirectory()) {
var files = directory.listFiles();
if (files != null) {
for (var f : files) {
if (!f.getName().contains("-sources") && f.getName().matches(regex)) {
jars.add(f.getAbsolutePath());
}
}
}
}
return jars;
}
/**
* Set the global external documentation links
*
@ -449,13 +433,17 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
public DokkaOperation outputFormat(OutputFormat format) {
pluginsClasspath_.clear();
if (format.equals(OutputFormat.JAVADOC)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), JAVADOC_PLUGIN_REGEXP));
pluginsClasspath_.addAll(CompileKotlinOperation.getJarList(project_.libBldDirectory(),
JAVADOC_PLUGIN_REGEXP));
} else if (format.equals(OutputFormat.HTML)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), HTML_PLUGIN_REGEXP));
pluginsClasspath_.addAll(CompileKotlinOperation.getJarList(project_.libBldDirectory(),
HTML_PLUGIN_REGEXP));
} else if (format.equals(OutputFormat.MARKDOWN)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), GFM_PLUGIN_REGEXP));
pluginsClasspath_.addAll(CompileKotlinOperation.getJarList(project_.libBldDirectory(),
GFM_PLUGIN_REGEXP));
} else if (format.equals(OutputFormat.JEKYLL)) {
pluginsClasspath_.addAll(getJarList(project_.libBldDirectory(), JEKYLL_PLUGIN_REGEXP));
pluginsClasspath_.addAll(CompileKotlinOperation.getJarList(project_.libBldDirectory(),
JEKYLL_PLUGIN_REGEXP));
}
return this;
}