Added Kotlin libs directory option (untested)
This commit is contained in:
parent
6cb2955575
commit
b7037378bc
4 changed files with 78 additions and 36 deletions
|
@ -44,7 +44,7 @@ public class CompileKotlinOperationBuild extends Project {
|
||||||
var kotlin = version(1, 9, 20);
|
var kotlin = version(1, 9, 20);
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("org.jetbrains.kotlin", "kotlin-compiler", kotlin))
|
.include(dependency("org.jetbrains.kotlin", "kotlin-compiler", kotlin))
|
||||||
.include(dependency("org.jetbrains.kotlin", "kotlin-annotation-processing", kotlin ))
|
.include(dependency("org.jetbrains.kotlin", "kotlin-annotation-processing", kotlin))
|
||||||
.include(dependency("org.jetbrains.dokka", "dokka-cli", dokka))
|
.include(dependency("org.jetbrains.dokka", "dokka-cli", dokka))
|
||||||
.include(dependency("org.jetbrains.dokka", "dokka-base", dokka))
|
.include(dependency("org.jetbrains.dokka", "dokka-base", dokka))
|
||||||
.include(dependency("org.jetbrains.dokka", "analysis-kotlin-descriptors", dokka))
|
.include(dependency("org.jetbrains.dokka", "analysis-kotlin-descriptors", dokka))
|
||||||
|
|
|
@ -47,6 +47,31 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
private File buildTestDirectory_;
|
private File buildTestDirectory_;
|
||||||
private CompileKotlinOptions compileOptions_;
|
private CompileKotlinOptions compileOptions_;
|
||||||
private KaptOptions kaptOptions_;
|
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) {
|
public static Collection<File> getKotlinFileList(File directory) {
|
||||||
if (directory == null) {
|
if (directory == null) {
|
||||||
|
@ -239,15 +264,21 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
args.addAll(compileOptions_.args());
|
args.addAll(compileOptions_.args());
|
||||||
}
|
}
|
||||||
|
|
||||||
// kapt options
|
// kapt plugin & options
|
||||||
if (kaptOptions_ != null) {
|
if (kotlinLibsDirectory_ != null && kaptOptions_ != null) {
|
||||||
kaptOptions_.args().forEach(a -> {
|
var kaptJar = getJarList(kotlinLibsDirectory_, "^.*kotlin-annotation-processing.*\\.jar$");
|
||||||
args.add("-P");
|
if (kaptJar.size() == 1) {
|
||||||
args.add(a);
|
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()));
|
sources.forEach(f -> args.add(f.getAbsolutePath()));
|
||||||
|
|
||||||
if (LOGGER.isLoggable(Level.FINE) && !silent()) {
|
if (LOGGER.isLoggable(Level.FINE) && !silent()) {
|
||||||
|
@ -293,6 +324,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
.buildTestDirectory(project.buildTestDirectory())
|
.buildTestDirectory(project.buildTestDirectory())
|
||||||
.compileMainClasspath(project.compileMainClasspath())
|
.compileMainClasspath(project.compileMainClasspath())
|
||||||
.compileTestClasspath(project.compileTestClasspath())
|
.compileTestClasspath(project.compileTestClasspath())
|
||||||
|
.kotlinLibsDirectory(project.libBldDirectory())
|
||||||
.mainSourceFiles(getKotlinFileList(new File(project.srcMainDirectory(), "kotlin")))
|
.mainSourceFiles(getKotlinFileList(new File(project.srcMainDirectory(), "kotlin")))
|
||||||
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
|
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
|
||||||
}
|
}
|
||||||
|
@ -308,6 +340,28 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
return this;
|
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.
|
* Provides main source directories that should be compiled.
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,8 +31,8 @@ import java.util.logging.Logger;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class KaptOptions {
|
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 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 List<String> apClasspath_ = new ArrayList<>();
|
||||||
private final Collection<Map<String, String>> apOptions_ = new ArrayList<>();
|
private final Collection<Map<String, String>> apOptions_ = new ArrayList<>();
|
||||||
private final AptMode aptMode_;
|
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
|
* @param apClasspath the list of classpath
|
||||||
* @return this class instance
|
* @return this class instance
|
||||||
|
@ -229,7 +229,7 @@ public class KaptOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base-64 encodes the option list
|
// Base-64 encodes the options list
|
||||||
private String encodeList(Map<String, String> options) throws IOException {
|
private String encodeList(Map<String, String> options) throws IOException {
|
||||||
var os = new ByteArrayOutputStream();
|
var os = new ByteArrayOutputStream();
|
||||||
var oos = new ObjectOutputStream(os);
|
var oos = new ObjectOutputStream(os);
|
||||||
|
@ -269,7 +269,7 @@ public class KaptOptions {
|
||||||
/**
|
/**
|
||||||
* A list of the options passed to {@code javac}.
|
* A list of the options passed to {@code javac}.
|
||||||
*
|
*
|
||||||
* @param javacArguments the arguments
|
* @param javacArguments the {@code javac} arguments
|
||||||
* @return this class instance
|
* @return this class instance
|
||||||
*/
|
*/
|
||||||
public KaptOptions javacArguments(Map<String, String> javacArguments) {
|
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
|
* A list of annotation processor qualified class names. If specified, {@code kapt} does not try to find annotation
|
||||||
* processors in apclasspath
|
* processors in {@link #apClasspath}.
|
||||||
*
|
*
|
||||||
* @param processors the list of qualified class names
|
* @param processors the list of qualified class names
|
||||||
* @return this class instance
|
* @return this class instance
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package rife.bld.extension.dokka;
|
package rife.bld.extension.dokka;
|
||||||
|
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
|
import rife.bld.extension.CompileKotlinOperation;
|
||||||
import rife.bld.operations.AbstractProcessOperation;
|
import rife.bld.operations.AbstractProcessOperation;
|
||||||
import rife.tools.StringUtils;
|
import rife.tools.StringUtils;
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
||||||
// java
|
// java
|
||||||
args.add(javaTool());
|
args.add(javaTool());
|
||||||
|
|
||||||
var cli = getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
|
var cli = CompileKotlinOperation.getJarList(project_.libBldDirectory(), "^.*dokka-cli.*\\.jar$");
|
||||||
|
|
||||||
if (cli.size() != 1) {
|
if (cli.size() != 1) {
|
||||||
throw new RuntimeException("The dokka-cli JAR could not be found.");
|
throw new RuntimeException("The dokka-cli JAR could not be found.");
|
||||||
|
@ -239,23 +240,6 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
||||||
return this;
|
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
|
* Set the global external documentation links
|
||||||
*
|
*
|
||||||
|
@ -449,13 +433,17 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
||||||
public DokkaOperation outputFormat(OutputFormat format) {
|
public DokkaOperation outputFormat(OutputFormat format) {
|
||||||
pluginsClasspath_.clear();
|
pluginsClasspath_.clear();
|
||||||
if (format.equals(OutputFormat.JAVADOC)) {
|
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)) {
|
} 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)) {
|
} 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)) {
|
} 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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue