Added standard compiler plugins
This commit is contained in:
parent
971de30902
commit
11c0b2b582
3 changed files with 58 additions and 8 deletions
|
@ -83,9 +83,8 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
var dir_abs = directory.getAbsoluteFile();
|
return FileUtils.getFileList(directory, KOTLIN_FILE_PATTERN, null).stream().map((file) ->
|
||||||
return FileUtils.getFileList(dir_abs, KOTLIN_FILE_PATTERN, null).stream().map((file) ->
|
new File(directory, file)).toList();
|
||||||
new File(dir_abs, file)).toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,6 +426,20 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides compiler plugins.
|
||||||
|
*
|
||||||
|
* @param directory the directory containing the plugin JARs
|
||||||
|
* @param plugins one or more plugins
|
||||||
|
* @return this class instance
|
||||||
|
*/
|
||||||
|
public CompileKotlinOperation plugins(File directory, CompileKotlinPlugin... plugins) {
|
||||||
|
for (var plugin : plugins) {
|
||||||
|
plugins_.addAll(CompileKotlinOperation.getJarList(directory, plugin.label));
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|
34
src/main/java/rife/bld/extension/CompileKotlinPlugin.java
Normal file
34
src/main/java/rife/bld/extension/CompileKotlinPlugin.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rife.bld.extension;
|
||||||
|
|
||||||
|
public enum CompileKotlinPlugin {
|
||||||
|
ALL_OPEN("^allopen-compiler-plugin-.*$"),
|
||||||
|
ASSIGNMENT("^assignment-compiler-plugin-.*$"),
|
||||||
|
KOTLIN_IMPORTS_DUMPER("^kotlin-imports-dumper-compiler-plugin-.*$"),
|
||||||
|
KOTLIN_SERIALIZATION("^kotlin-serialization-compiler-plugin-.*$"),
|
||||||
|
KOTLINX_SERIALIZATION("^kotlinx-serialization-compiler-plugin-.*$"),
|
||||||
|
LOMBOK("^lombok-compiler-plugin-.*$"),
|
||||||
|
NOARG("^noarg-compiler-plugin-.*$"),
|
||||||
|
SAM_WITH_RECEIVER("^sam-with-receiver-compiler-plugin-.*$");
|
||||||
|
|
||||||
|
public final String label;
|
||||||
|
|
||||||
|
CompileKotlinPlugin(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
}
|
|
@ -68,6 +68,7 @@ class CompileKotlinOperationTest {
|
||||||
testJars.add(f.getAbsolutePath());
|
testJars.add(f.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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"))
|
||||||
|
@ -77,9 +78,7 @@ class CompileKotlinOperationTest {
|
||||||
.compileMainClasspath(compileJars)
|
.compileMainClasspath(compileJars)
|
||||||
.compileTestClasspath(testJars)
|
.compileTestClasspath(testJars)
|
||||||
.compileTestClasspath(compileJars)
|
.compileTestClasspath(compileJars)
|
||||||
.compileTestClasspath(mainDir.getAbsolutePath())
|
.compileTestClasspath(mainDir.getAbsolutePath());
|
||||||
.mainSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/main/kotlin")))
|
|
||||||
.testSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/test/kotlin")));
|
|
||||||
|
|
||||||
op.execute();
|
op.execute();
|
||||||
|
|
||||||
|
@ -87,8 +86,12 @@ class CompileKotlinOperationTest {
|
||||||
assertThat(mainDir).isNotEmptyDirectory();
|
assertThat(mainDir).isNotEmptyDirectory();
|
||||||
assertThat(testDir).isNotEmptyDirectory();
|
assertThat(testDir).isNotEmptyDirectory();
|
||||||
|
|
||||||
var exampleClass = Path.of(mainDir.getAbsolutePath(), "com", "example", "Example.class").toFile();
|
var mainOut = Path.of(mainDir.getAbsolutePath(), "com", "example").toFile();
|
||||||
assertThat(exampleClass).exists();
|
assertThat(new File(mainOut, "Example.class")).exists();
|
||||||
|
assertThat(new File(mainOut, "Example$Companion.class")).exists();
|
||||||
|
|
||||||
|
var testOut = Path.of(testDir.getAbsolutePath(), "com", "example").toFile();
|
||||||
|
assertThat(new File(testOut, "ExampleTest.class")).exists();
|
||||||
} finally {
|
} finally {
|
||||||
FileUtils.deleteDirectory(tmpDir);
|
FileUtils.deleteDirectory(tmpDir);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue