Made compile options modifiable

This commit is contained in:
Erik C. Thauvin 2023-11-15 11:02:26 -08:00
parent 11c0b2b582
commit 28ad500a12
9 changed files with 57 additions and 34 deletions

View file

@ -19,7 +19,6 @@ To compile the source code located in `src/main/kotlin` and `src/test/kotlin` fr
public void compile() throws IOException { public void compile() throws IOException {
new CompileKotlinOperation() new CompileKotlinOperation()
.fromProject(this) .fromProject(this)
.compileOptions(new CompileKotlinOptions().verbose(true))
.execute(); .execute();
} }
``` ```

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<pattern value="com.example.ExampleBuild" /> <pattern value="com.example.ExampleBuild" />
@ -6,20 +7,7 @@
<pattern value="com.example.ExampleBuild" method="dokkaGfm" /> <pattern value="com.example.ExampleBuild" method="dokkaGfm" />
<pattern value="com.example.ExampleBuild" method="dokkaJekyll" /> <pattern value="com.example.ExampleBuild" method="dokkaJekyll" />
</component> </component>
<component name="PDMPlugin">
<option name="customRuleSets">
<list>
<option value="K:\java\semver\config\pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-pitest/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-jacoco-report/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-checkstyle/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-exec/config/pmd.xml" />
<option value="$PROJECT_DIR$/../../bld-testng/config/pmd.xml" />
</list>
</option>
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" /> <output url="file://$PROJECT_DIR$/build" />
</component> </component>
</project> </project>

View file

@ -3,7 +3,6 @@ package com.example;
import rife.bld.BuildCommand; import rife.bld.BuildCommand;
import rife.bld.Project; import rife.bld.Project;
import rife.bld.extension.CompileKotlinOperation; import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.CompileKotlinOptions;
import rife.bld.extension.dokka.DokkaOperation; import rife.bld.extension.dokka.DokkaOperation;
import rife.bld.extension.dokka.LoggingLevel; import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat; import rife.bld.extension.dokka.OutputFormat;
@ -64,12 +63,11 @@ public class ExampleBuild extends Project {
// The source code located in src/main/kotlin and src/test/kotlin will be compiled // The source code located in src/main/kotlin and src/test/kotlin will be compiled
new CompileKotlinOperation() new CompileKotlinOperation()
.fromProject(this) .fromProject(this)
.compileOptions(
new CompileKotlinOptions()
.jdkRelease(javaRelease)
.verbose(true)
)
.execute(); .execute();
// var op = new CompileKotlinOperation().fromProject(this);
// op.compileOptions().verbose(true);
// op.execute();
} }
@BuildCommand(value = "dokka-gfm", summary = "Generates documentation in GitHub flavored markdown format") @BuildCommand(value = "dokka-gfm", summary = "Generates documentation in GitHub flavored markdown format")

View file

@ -46,7 +46,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
private final Collection<File> testSourceFiles_ = new ArrayList<>(); private final Collection<File> testSourceFiles_ = new ArrayList<>();
private File buildMainDirectory_; private File buildMainDirectory_;
private File buildTestDirectory_; private File buildTestDirectory_;
private CompileKotlinOptions compileOptions_; private CompileKotlinOptions compileOptions_ = new CompileKotlinOptions();
private BaseProject project_; private BaseProject project_;
/** /**
@ -159,6 +159,13 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
return compileMainClasspath_; return compileMainClasspath_;
} }
/**
* Retrieves the list of compilation options for the compiler.
*/
public CompileKotlinOptions compileOptions() {
return compileOptions_;
}
/** /**
* Provides a list of compilation options to pass to the {@code kotlinc} compiler. * Provides a list of compilation options to pass to the {@code kotlinc} compiler.
* *
@ -320,9 +327,11 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* <li>{@link #buildTestDirectory() buildTestDirectory}</li> * <li>{@link #buildTestDirectory() buildTestDirectory}</li>
* <li>{@link #compileMainClasspath() compileMainClassPath}</li> * <li>{@link #compileMainClasspath() compileMainClassPath}</li>
* <li>{@link #compileTestClasspath() compilesTestClassPath}</li> * <li>{@link #compileTestClasspath() compilesTestClassPath}</li>
* <li>{@link #mainSourceFiles() mainSourceFiles}</li> * <li>{@link #mainSourceFiles() mainSourceFiles} to the {@code kotlin} directory in
* <li>{@link #testSourceFiles() testSourceFile}</li> * {@link BaseProject#srcMainDirectory() srcMainDirectory}</li>
* <li>{@link CompileKotlinOptions#jdkRelease jdkRelease}</li> * <li>{@link #testSourceFiles() testSourceFile} to the {@code kotlin} directory in
* {@link BaseProject#srcTestDirectory() srcTestDirectory}</li>
* <li>{@link CompileKotlinOptions#jdkRelease jdkRelease} to {@link BaseProject#javaRelease() javaRelease}</li>
* </ul> * </ul>
* *
* @param project the project to configure the compile operation from * @param project the project to configure the compile operation from
@ -335,8 +344,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
.compileTestClasspath(project.compileTestClasspath()) .compileTestClasspath(project.compileTestClasspath())
.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")));
if (project.javaRelease() != null) { if (project.javaRelease() != null && !compileOptions_.hasRelease()) {
return op.compileOptions(new CompileKotlinOptions().jdkRelease(project.javaRelease())); compileOptions_.jdkRelease(project.javaRelease());
} }
return op; return op;
@ -440,6 +449,26 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
return this; return this;
} }
/**
* Provides compiler plugins.
*
* @param jars the list of plugin JARs
* @param plugins one or more plugins
* @return this class instance
*/
public CompileKotlinOperation plugins(Collection<File> jars, CompileKotlinPlugin... plugins) {
jars.forEach(jar -> {
for (var plugin : plugins) {
if (jar.getName().matches(plugin.label)) {
plugins_.add(jar.getAbsolutePath());
break;
}
}
});
return this;
}
// Combine Kotlin sources // Combine Kotlin sources
private Collection<File> sources(Collection<File> files, Collection<File> directories) { private Collection<File> sources(Collection<File> files, Collection<File> directories) {
var sources = new ArrayList<>(files); var sources = new ArrayList<>(files);

View file

@ -265,6 +265,15 @@ public class CompileKotlinOptions {
return this; return this;
} }
/**
* Indicates whether the {@link #jdkRelease(String) jdkRelease} was set.
*
* @return {@code true} if the release was set; or {@code false} otherwise
*/
public boolean hasRelease() {
return jdkRelease_ != null;
}
/** /**
* Include the Kotlin runtime into the resulting JAR file. Makes the resulting archive runnable on any Java-enabled * Include the Kotlin runtime into the resulting JAR file. Makes the resulting archive runnable on any Java-enabled
* environment. * environment.
@ -317,7 +326,7 @@ public class CompileKotlinOptions {
* Specify the target version of the generated JVM bytecode. * Specify the target version of the generated JVM bytecode.
* *
* @param version the target version * @param version the target version
* @return this class insance * @return this class instance
* @see #jdkRelease(String) * @see #jdkRelease(String)
*/ */
public CompileKotlinOptions jdkRelease(int version) { public CompileKotlinOptions jdkRelease(int version) {
@ -557,7 +566,7 @@ public class CompileKotlinOptions {
* @param wError {@code true} or {@code false} * @param wError {@code true} or {@code false}
* @return this class instance * @return this class instance
*/ */
public CompileKotlinOptions wErrpr(boolean wError) { public CompileKotlinOptions wError(boolean wError) {
wError_ = wError; wError_ = wError;
return this; return this;
} }

View file

@ -17,7 +17,7 @@
package rife.bld.extension.dokka; package rife.bld.extension.dokka;
/** /**
* Dokka analysis platforms. * Dokka's analysis platforms.
* *
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a> * @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0 * @since 1.0

View file

@ -52,7 +52,7 @@ public class SourceSet {
/** /**
* Sets the platform used for setting up analysis. Default is {@link AnalysisPlatform#JVM} * Sets the platform used for setting up analysis. Default is {@link AnalysisPlatform#JVM}
* *
* @param analysisPlatform the analysis platfrom * @param analysisPlatform the analysis platform
* @return this operation instance * @return this operation instance
*/ */
public SourceSet analysisPlatform(AnalysisPlatform analysisPlatform) { public SourceSet analysisPlatform(AnalysisPlatform analysisPlatform) {
@ -424,7 +424,7 @@ public class SourceSet {
} }
/** /**
* Sets Wwether to report undocumented declarations. * Sets whether to report undocumented declarations.
* *
* @param reportUndocumented {@code true} or {@code false} * @param reportUndocumented {@code true} or {@code false}
* @return this operation instance * @return this operation instance

View file

@ -72,7 +72,6 @@ class CompileKotlinOperationTest {
var op = new CompileKotlinOperation() var op = new CompileKotlinOperation()
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
"Example")) "Example"))
.compileOptions(new CompileKotlinOptions().verbose(true))
.buildMainDirectory(mainDir) .buildMainDirectory(mainDir)
.buildTestDirectory(testDir) .buildTestDirectory(testDir)
.compileMainClasspath(compileJars) .compileMainClasspath(compileJars)
@ -80,6 +79,7 @@ class CompileKotlinOperationTest {
.compileTestClasspath(compileJars) .compileTestClasspath(compileJars)
.compileTestClasspath(mainDir.getAbsolutePath()); .compileTestClasspath(mainDir.getAbsolutePath());
op.compileOptions().verbose(true);
op.execute(); op.execute();
assertThat(tmpDir).isNotEmptyDirectory(); assertThat(tmpDir).isNotEmptyDirectory();

View file

@ -76,7 +76,7 @@ class CompileKotlinOptionsTest {
.progressive(true) .progressive(true)
.scriptTemplates("name", "name2") .scriptTemplates("name", "name2")
.verbose(true) .verbose(true)
.wErrpr(true) .wError(true)
.args(); .args();
var matches = List.of( var matches = List.of(