Skip to content

Commit 28ad500

Browse files
committed
Made compile options modifiable
1 parent 11c0b2b commit 28ad500

File tree

9 files changed

+57
-34
lines changed

9 files changed

+57
-34
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ To compile the source code located in `src/main/kotlin` and `src/test/kotlin` fr
1919
public void compile() throws IOException {
2020
new CompileKotlinOperation()
2121
.fromProject(this)
22-
.compileOptions(new CompileKotlinOptions().verbose(true))
2322
.execute();
2423
}
2524
```

examples/.idea/misc.xml

Lines changed: 2 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/src/bld/java/com/example/ExampleBuild.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import rife.bld.BuildCommand;
44
import rife.bld.Project;
55
import rife.bld.extension.CompileKotlinOperation;
6-
import rife.bld.extension.CompileKotlinOptions;
76
import rife.bld.extension.dokka.DokkaOperation;
87
import rife.bld.extension.dokka.LoggingLevel;
98
import rife.bld.extension.dokka.OutputFormat;
@@ -64,12 +63,11 @@ public void compile() throws IOException {
6463
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
6564
new CompileKotlinOperation()
6665
.fromProject(this)
67-
.compileOptions(
68-
new CompileKotlinOptions()
69-
.jdkRelease(javaRelease)
70-
.verbose(true)
71-
)
7266
.execute();
67+
68+
// var op = new CompileKotlinOperation().fromProject(this);
69+
// op.compileOptions().verbose(true);
70+
// op.execute();
7371
}
7472

7573
@BuildCommand(value = "dokka-gfm", summary = "Generates documentation in GitHub flavored markdown format")

src/main/java/rife/bld/extension/CompileKotlinOperation.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
4646
private final Collection<File> testSourceFiles_ = new ArrayList<>();
4747
private File buildMainDirectory_;
4848
private File buildTestDirectory_;
49-
private CompileKotlinOptions compileOptions_;
49+
private CompileKotlinOptions compileOptions_ = new CompileKotlinOptions();
5050
private BaseProject project_;
5151

5252
/**
@@ -159,6 +159,13 @@ public Collection<String> compileMainClasspath() {
159159
return compileMainClasspath_;
160160
}
161161

162+
/**
163+
* Retrieves the list of compilation options for the compiler.
164+
*/
165+
public CompileKotlinOptions compileOptions() {
166+
return compileOptions_;
167+
}
168+
162169
/**
163170
* Provides a list of compilation options to pass to the {@code kotlinc} compiler.
164171
*
@@ -320,9 +327,11 @@ protected void executeCreateBuildDirectories() throws IOException {
320327
* <li>{@link #buildTestDirectory() buildTestDirectory}</li>
321328
* <li>{@link #compileMainClasspath() compileMainClassPath}</li>
322329
* <li>{@link #compileTestClasspath() compilesTestClassPath}</li>
323-
* <li>{@link #mainSourceFiles() mainSourceFiles}</li>
324-
* <li>{@link #testSourceFiles() testSourceFile}</li>
325-
* <li>{@link CompileKotlinOptions#jdkRelease jdkRelease}</li>
330+
* <li>{@link #mainSourceFiles() mainSourceFiles} to the {@code kotlin} directory in
331+
* {@link BaseProject#srcMainDirectory() srcMainDirectory}</li>
332+
* <li>{@link #testSourceFiles() testSourceFile} to the {@code kotlin} directory in
333+
* {@link BaseProject#srcTestDirectory() srcTestDirectory}</li>
334+
* <li>{@link CompileKotlinOptions#jdkRelease jdkRelease} to {@link BaseProject#javaRelease() javaRelease}</li>
326335
* </ul>
327336
*
328337
* @param project the project to configure the compile operation from
@@ -335,8 +344,8 @@ public CompileKotlinOperation fromProject(BaseProject project) {
335344
.compileTestClasspath(project.compileTestClasspath())
336345
.mainSourceFiles(getKotlinFileList(new File(project.srcMainDirectory(), "kotlin")))
337346
.testSourceFiles(getKotlinFileList(new File(project.srcTestDirectory(), "kotlin")));
338-
if (project.javaRelease() != null) {
339-
return op.compileOptions(new CompileKotlinOptions().jdkRelease(project.javaRelease()));
347+
if (project.javaRelease() != null && !compileOptions_.hasRelease()) {
348+
compileOptions_.jdkRelease(project.javaRelease());
340349
}
341350

342351
return op;
@@ -440,6 +449,26 @@ public CompileKotlinOperation plugins(File directory, CompileKotlinPlugin... plu
440449
return this;
441450
}
442451

452+
/**
453+
* Provides compiler plugins.
454+
*
455+
* @param jars the list of plugin JARs
456+
* @param plugins one or more plugins
457+
* @return this class instance
458+
*/
459+
public CompileKotlinOperation plugins(Collection<File> jars, CompileKotlinPlugin... plugins) {
460+
jars.forEach(jar -> {
461+
for (var plugin : plugins) {
462+
if (jar.getName().matches(plugin.label)) {
463+
plugins_.add(jar.getAbsolutePath());
464+
break;
465+
}
466+
}
467+
});
468+
469+
return this;
470+
}
471+
443472
// Combine Kotlin sources
444473
private Collection<File> sources(Collection<File> files, Collection<File> directories) {
445474
var sources = new ArrayList<>(files);

src/main/java/rife/bld/extension/CompileKotlinOptions.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ public CompileKotlinOptions classpath(Collection<String> paths) {
265265
return this;
266266
}
267267

268+
/**
269+
* Indicates whether the {@link #jdkRelease(String) jdkRelease} was set.
270+
*
271+
* @return {@code true} if the release was set; or {@code false} otherwise
272+
*/
273+
public boolean hasRelease() {
274+
return jdkRelease_ != null;
275+
}
276+
268277
/**
269278
* Include the Kotlin runtime into the resulting JAR file. Makes the resulting archive runnable on any Java-enabled
270279
* environment.
@@ -317,7 +326,7 @@ public CompileKotlinOptions jdkRelease(String version) {
317326
* Specify the target version of the generated JVM bytecode.
318327
*
319328
* @param version the target version
320-
* @return this class insance
329+
* @return this class instance
321330
* @see #jdkRelease(String)
322331
*/
323332
public CompileKotlinOptions jdkRelease(int version) {
@@ -557,7 +566,7 @@ public CompileKotlinOptions verbose(boolean verbose) {
557566
* @param wError {@code true} or {@code false}
558567
* @return this class instance
559568
*/
560-
public CompileKotlinOptions wErrpr(boolean wError) {
569+
public CompileKotlinOptions wError(boolean wError) {
561570
wError_ = wError;
562571
return this;
563572
}

src/main/java/rife/bld/extension/dokka/AnalysisPlatform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package rife.bld.extension.dokka;
1818

1919
/**
20-
* Dokka analysis platforms.
20+
* Dokka's analysis platforms.
2121
*
2222
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
2323
* @since 1.0

src/main/java/rife/bld/extension/dokka/SourceSet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class SourceSet {
5252
/**
5353
* Sets the platform used for setting up analysis. Default is {@link AnalysisPlatform#JVM}
5454
*
55-
* @param analysisPlatform the analysis platfrom
55+
* @param analysisPlatform the analysis platform
5656
* @return this operation instance
5757
*/
5858
public SourceSet analysisPlatform(AnalysisPlatform analysisPlatform) {
@@ -424,7 +424,7 @@ public SourceSet perPackageOptions(String... perPackageOptions) {
424424
}
425425

426426
/**
427-
* Sets Wwether to report undocumented declarations.
427+
* Sets whether to report undocumented declarations.
428428
*
429429
* @param reportUndocumented {@code true} or {@code false}
430430
* @return this operation instance

src/test/java/rife/bld/extension/CompileKotlinOperationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ void testExecute() throws IOException {
7272
var op = new CompileKotlinOperation()
7373
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
7474
"Example"))
75-
.compileOptions(new CompileKotlinOptions().verbose(true))
7675
.buildMainDirectory(mainDir)
7776
.buildTestDirectory(testDir)
7877
.compileMainClasspath(compileJars)
7978
.compileTestClasspath(testJars)
8079
.compileTestClasspath(compileJars)
8180
.compileTestClasspath(mainDir.getAbsolutePath());
8281

82+
op.compileOptions().verbose(true);
8383
op.execute();
8484

8585
assertThat(tmpDir).isNotEmptyDirectory();

src/test/java/rife/bld/extension/CompileKotlinOptionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void argsTest() {
7676
.progressive(true)
7777
.scriptTemplates("name", "name2")
7878
.verbose(true)
79-
.wErrpr(true)
79+
.wError(true)
8080
.args();
8181

8282
var matches = List.of(

0 commit comments

Comments
 (0)