Made a project required for all operations
This commit is contained in:
parent
5e8629c418
commit
91ba216545
4 changed files with 51 additions and 29 deletions
|
@ -47,7 +47,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
private File buildTestDirectory_;
|
||||
private CompileKotlinOptions compileOptions_;
|
||||
private KaptOptions kaptOptions_;
|
||||
private File kotlinLibsDirectory_;
|
||||
private BaseProject project_;
|
||||
|
||||
/**
|
||||
* Returns the list JARs contained in a given directory.
|
||||
|
@ -208,6 +208,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
@SuppressWarnings("PMD.SystemPrintln")
|
||||
public void execute()
|
||||
throws IOException {
|
||||
if (project_ == null) {
|
||||
throw new IllegalArgumentException("A project must be specified.");
|
||||
}
|
||||
|
||||
executeCreateBuildDirectories();
|
||||
executeBuildMainSources();
|
||||
executeBuildTestSources();
|
||||
|
@ -236,7 +240,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @param destination the destination directory
|
||||
* @param friendPaths the output directory for friendly modules
|
||||
*/
|
||||
protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination, File friendPaths)
|
||||
protected void executeBuildSources(Collection<String> classpath, Collection<File> sources, File destination,
|
||||
File friendPaths)
|
||||
throws IOException {
|
||||
if (sources.isEmpty() || destination == null) {
|
||||
return;
|
||||
|
@ -265,8 +270,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
}
|
||||
|
||||
// kapt plugin & options
|
||||
if (kotlinLibsDirectory_ != null && kaptOptions_ != null) {
|
||||
var kaptJar = getJarList(kotlinLibsDirectory_, "^.*kotlin-annotation-processing.*\\.jar$");
|
||||
if (kaptOptions_ != null) {
|
||||
var kaptJar = getJarList(project_.libBldDirectory(), "^.*kotlin-annotation-processing.*\\.jar$");
|
||||
if (kaptJar.size() == 1) {
|
||||
args.add("-Xplugin=" + kaptJar.get(0));
|
||||
kaptOptions_.args().forEach(a -> {
|
||||
|
@ -274,7 +279,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
args.add(a);
|
||||
});
|
||||
} else if (LOGGER.isLoggable(Level.WARNING)) {
|
||||
LOGGER.warning("Could not locate the Kotlin annotation processing JAR in:" + kotlinLibsDirectory_);
|
||||
LOGGER.warning("Could not locate the Kotlin annotation processing JAR in:" +
|
||||
project_.libBldDirectory().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,15 +322,25 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
|
||||
/**
|
||||
* Configures a compile operation from a {@link BaseProject}.
|
||||
* <p>
|
||||
* Sets the following from the project:
|
||||
* <ul>
|
||||
* <li>{@link #buildMainDirectory() buildMainDirectory}</li>
|
||||
* <li>{@link #buildTestDirectory() buildTestDirectory}</li>
|
||||
* <li>{@link #compileMainClasspath() compileMainClassPath}</li>
|
||||
* <li>{@link #compileTestClasspath() compilesTestClassPath}</li>
|
||||
* <li>{@link #mainSourceFiles() mainSourceFiles}</li>
|
||||
* <li>{@link #testSourceFiles() testSourceFile}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param project the project to configure the compile operation from
|
||||
*/
|
||||
public CompileKotlinOperation fromProject(BaseProject project) {
|
||||
project_ = project;
|
||||
return buildMainDirectory(project.buildMainDirectory())
|
||||
.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")));
|
||||
}
|
||||
|
@ -340,28 +356,6 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the directory containing the Kotlin libraries (compiler, plugins, dokka, 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, dokka, 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.
|
||||
*
|
||||
|
|
|
@ -98,6 +98,17 @@ public class KaptOptions {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A path to the annotation processor JAR. Pass as many classpath as the number of JARs that you have.
|
||||
*
|
||||
* @param apClasspath one or more classpath
|
||||
* @return this class instance
|
||||
*/
|
||||
public KaptOptions apClasspath(String... apClasspath) {
|
||||
apClasspath_.addAll(List.of(apClasspath));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of the annotation processor options.
|
||||
*
|
||||
|
@ -181,7 +192,7 @@ public class KaptOptions {
|
|||
|
||||
// processors
|
||||
if (!processors_.isEmpty()) {
|
||||
processors_.forEach(p -> args.add(PLUGIN_ID + "processors=" + p));
|
||||
args.add(PLUGIN_ID + "processors=" + String.join(",", processors_));
|
||||
}
|
||||
|
||||
// verbose
|
||||
|
@ -289,6 +300,18 @@ public class KaptOptions {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of annotation processor qualified class names. If specified, {@code kapt} does not try to find annotation
|
||||
* processors in {@link #apClasspath}.
|
||||
*
|
||||
* @param processors one or moe qualified class names
|
||||
* @return this class instance
|
||||
*/
|
||||
public KaptOptions processors(String... processors) {
|
||||
processors_.addAll(List.of(processors));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables verbose output.
|
||||
*
|
||||
|
|
|
@ -218,6 +218,8 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
|
|||
|
||||
/**
|
||||
* Configures the operation from a {@link BaseProject}.
|
||||
* <p>
|
||||
* Sets the {@link #sourceSet_ sourceSet} and {@link #moduleName_ moduleName} from the project.
|
||||
*
|
||||
* @param project the project to configure the operation from
|
||||
*/
|
||||
|
|
|
@ -18,6 +18,7 @@ package rife.bld.extension;
|
|||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.blueprints.BaseProjectBlueprint;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -68,6 +69,8 @@ class CompileKotlinOperationTest {
|
|||
}
|
||||
|
||||
var op = new CompileKotlinOperation()
|
||||
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
|
||||
"Example"))
|
||||
.compileOptions(new CompileKotlinOptions().verbose(true))
|
||||
.buildMainDirectory(mainDir)
|
||||
.buildTestDirectory(testDir)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue