Made compile options modifiable
This commit is contained in:
parent
11c0b2b582
commit
28ad500a12
9 changed files with 57 additions and 34 deletions
|
@ -19,7 +19,6 @@ To compile the source code located in `src/main/kotlin` and `src/test/kotlin` fr
|
|||
public void compile() throws IOException {
|
||||
new CompileKotlinOperation()
|
||||
.fromProject(this)
|
||||
.compileOptions(new CompileKotlinOptions().verbose(true))
|
||||
.execute();
|
||||
}
|
||||
```
|
||||
|
|
16
examples/.idea/misc.xml
generated
16
examples/.idea/misc.xml
generated
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<pattern value="com.example.ExampleBuild" />
|
||||
|
@ -6,20 +7,7 @@
|
|||
<pattern value="com.example.ExampleBuild" method="dokkaGfm" />
|
||||
<pattern value="com.example.ExampleBuild" method="dokkaJekyll" />
|
||||
</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">
|
||||
<output url="file://$PROJECT_DIR$/build" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.example;
|
|||
import rife.bld.BuildCommand;
|
||||
import rife.bld.Project;
|
||||
import rife.bld.extension.CompileKotlinOperation;
|
||||
import rife.bld.extension.CompileKotlinOptions;
|
||||
import rife.bld.extension.dokka.DokkaOperation;
|
||||
import rife.bld.extension.dokka.LoggingLevel;
|
||||
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
|
||||
new CompileKotlinOperation()
|
||||
.fromProject(this)
|
||||
.compileOptions(
|
||||
new CompileKotlinOptions()
|
||||
.jdkRelease(javaRelease)
|
||||
.verbose(true)
|
||||
)
|
||||
.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")
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
private final Collection<File> testSourceFiles_ = new ArrayList<>();
|
||||
private File buildMainDirectory_;
|
||||
private File buildTestDirectory_;
|
||||
private CompileKotlinOptions compileOptions_;
|
||||
private CompileKotlinOptions compileOptions_ = new CompileKotlinOptions();
|
||||
private BaseProject project_;
|
||||
|
||||
/**
|
||||
|
@ -159,6 +159,13 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
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.
|
||||
*
|
||||
|
@ -320,9 +327,11 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* <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>
|
||||
* <li>{@link CompileKotlinOptions#jdkRelease jdkRelease}</li>
|
||||
* <li>{@link #mainSourceFiles() mainSourceFiles} to the {@code kotlin} directory in
|
||||
* {@link BaseProject#srcMainDirectory() srcMainDirectory}</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>
|
||||
*
|
||||
* @param project the project to configure the compile operation from
|
||||
|
@ -335,8 +344,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
.compileTestClasspath(project.compileTestClasspath())
|
||||
.mainSourceFiles(getKotlinFileList(new File(project.srcMainDirectory(), "kotlin")))
|
||||
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
|
||||
if (project.javaRelease() != null) {
|
||||
return op.compileOptions(new CompileKotlinOptions().jdkRelease(project.javaRelease()));
|
||||
if (project.javaRelease() != null && !compileOptions_.hasRelease()) {
|
||||
compileOptions_.jdkRelease(project.javaRelease());
|
||||
}
|
||||
|
||||
return op;
|
||||
|
@ -440,6 +449,26 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
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
|
||||
private Collection<File> sources(Collection<File> files, Collection<File> directories) {
|
||||
var sources = new ArrayList<>(files);
|
||||
|
|
|
@ -265,6 +265,15 @@ public class CompileKotlinOptions {
|
|||
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
|
||||
* environment.
|
||||
|
@ -317,7 +326,7 @@ public class CompileKotlinOptions {
|
|||
* Specify the target version of the generated JVM bytecode.
|
||||
*
|
||||
* @param version the target version
|
||||
* @return this class insance
|
||||
* @return this class instance
|
||||
* @see #jdkRelease(String)
|
||||
*/
|
||||
public CompileKotlinOptions jdkRelease(int version) {
|
||||
|
@ -557,7 +566,7 @@ public class CompileKotlinOptions {
|
|||
* @param wError {@code true} or {@code false}
|
||||
* @return this class instance
|
||||
*/
|
||||
public CompileKotlinOptions wErrpr(boolean wError) {
|
||||
public CompileKotlinOptions wError(boolean wError) {
|
||||
wError_ = wError;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package rife.bld.extension.dokka;
|
||||
|
||||
/**
|
||||
* Dokka analysis platforms.
|
||||
* Dokka's analysis platforms.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
|
|
|
@ -52,7 +52,7 @@ public class SourceSet {
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
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}
|
||||
* @return this operation instance
|
||||
|
|
|
@ -72,7 +72,6 @@ class CompileKotlinOperationTest {
|
|||
var op = new CompileKotlinOperation()
|
||||
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
|
||||
"Example"))
|
||||
.compileOptions(new CompileKotlinOptions().verbose(true))
|
||||
.buildMainDirectory(mainDir)
|
||||
.buildTestDirectory(testDir)
|
||||
.compileMainClasspath(compileJars)
|
||||
|
@ -80,6 +79,7 @@ class CompileKotlinOperationTest {
|
|||
.compileTestClasspath(compileJars)
|
||||
.compileTestClasspath(mainDir.getAbsolutePath());
|
||||
|
||||
op.compileOptions().verbose(true);
|
||||
op.execute();
|
||||
|
||||
assertThat(tmpDir).isNotEmptyDirectory();
|
||||
|
|
|
@ -76,7 +76,7 @@ class CompileKotlinOptionsTest {
|
|||
.progressive(true)
|
||||
.scriptTemplates("name", "name2")
|
||||
.verbose(true)
|
||||
.wErrpr(true)
|
||||
.wError(true)
|
||||
.args();
|
||||
|
||||
var matches = List.of(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue