Skip to content

Commit 11c0b2b

Browse files
committed
Added standard compiler plugins
1 parent 971de30 commit 11c0b2b

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ public static Collection<File> getKotlinFileList(File directory) {
8383
}
8484
return Collections.emptyList();
8585
} else {
86-
var dir_abs = directory.getAbsoluteFile();
87-
return FileUtils.getFileList(dir_abs, KOTLIN_FILE_PATTERN, null).stream().map((file) ->
88-
new File(dir_abs, file)).toList();
86+
return FileUtils.getFileList(directory, KOTLIN_FILE_PATTERN, null).stream().map((file) ->
87+
new File(directory, file)).toList();
8988
}
9089
}
9190

@@ -427,6 +426,20 @@ public CompileKotlinOperation plugins(Collection<String> plugins) {
427426
return this;
428427
}
429428

429+
/**
430+
* Provides compiler plugins.
431+
*
432+
* @param directory the directory containing the plugin JARs
433+
* @param plugins one or more plugins
434+
* @return this class instance
435+
*/
436+
public CompileKotlinOperation plugins(File directory, CompileKotlinPlugin... plugins) {
437+
for (var plugin : plugins) {
438+
plugins_.addAll(CompileKotlinOperation.getJarList(directory, plugin.label));
439+
}
440+
return this;
441+
}
442+
430443
// Combine Kotlin sources
431444
private Collection<File> sources(Collection<File> files, Collection<File> directories) {
432445
var sources = new ArrayList<>(files);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package rife.bld.extension;
18+
19+
public enum CompileKotlinPlugin {
20+
ALL_OPEN("^allopen-compiler-plugin-.*$"),
21+
ASSIGNMENT("^assignment-compiler-plugin-.*$"),
22+
KOTLIN_IMPORTS_DUMPER("^kotlin-imports-dumper-compiler-plugin-.*$"),
23+
KOTLIN_SERIALIZATION("^kotlin-serialization-compiler-plugin-.*$"),
24+
KOTLINX_SERIALIZATION("^kotlinx-serialization-compiler-plugin-.*$"),
25+
LOMBOK("^lombok-compiler-plugin-.*$"),
26+
NOARG("^noarg-compiler-plugin-.*$"),
27+
SAM_WITH_RECEIVER("^sam-with-receiver-compiler-plugin-.*$");
28+
29+
public final String label;
30+
31+
CompileKotlinPlugin(String label) {
32+
this.label = label;
33+
}
34+
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void testExecute() throws IOException {
6868
testJars.add(f.getAbsolutePath());
6969
}
7070

71+
7172
var op = new CompileKotlinOperation()
7273
.fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
7374
"Example"))
@@ -77,18 +78,20 @@ void testExecute() throws IOException {
7778
.compileMainClasspath(compileJars)
7879
.compileTestClasspath(testJars)
7980
.compileTestClasspath(compileJars)
80-
.compileTestClasspath(mainDir.getAbsolutePath())
81-
.mainSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/main/kotlin")))
82-
.testSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/test/kotlin")));
81+
.compileTestClasspath(mainDir.getAbsolutePath());
8382

8483
op.execute();
8584

8685
assertThat(tmpDir).isNotEmptyDirectory();
8786
assertThat(mainDir).isNotEmptyDirectory();
8887
assertThat(testDir).isNotEmptyDirectory();
8988

90-
var exampleClass = Path.of(mainDir.getAbsolutePath(), "com", "example", "Example.class").toFile();
91-
assertThat(exampleClass).exists();
89+
var mainOut = Path.of(mainDir.getAbsolutePath(), "com", "example").toFile();
90+
assertThat(new File(mainOut, "Example.class")).exists();
91+
assertThat(new File(mainOut, "Example$Companion.class")).exists();
92+
93+
var testOut = Path.of(testDir.getAbsolutePath(), "com", "example").toFile();
94+
assertThat(new File(testOut, "ExampleTest.class")).exists();
9295
} finally {
9396
FileUtils.deleteDirectory(tmpDir);
9497
}

0 commit comments

Comments
 (0)