Compare commits
3 commits
31e4208d7f
...
3c5b1fde8f
Author | SHA1 | Date | |
---|---|---|---|
3c5b1fde8f | |||
832447771d | |||
48c896f0df |
9 changed files with 146 additions and 13 deletions
2
.github/workflows/bld.yml
vendored
2
.github/workflows/bld.yml
vendored
|
@ -12,7 +12,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java-version: [17, 21, 24]
|
java-version: [17, 21, 24]
|
||||||
kotlin-version: [1.9.25, 2.0.21, 2.1.10]
|
kotlin-version: [1.9.25, 2.0.21, 2.1.20]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source repository
|
- name: Checkout source repository
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
bld.downloadExtensionJavadoc=false
|
bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.4
|
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.5-SNAPSHOT
|
||||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.sourceDirectories=
|
bld.sourceDirectories=
|
||||||
bld.version=2.2.1
|
bld.version=2.2.1
|
||||||
|
|
|
@ -3,6 +3,8 @@ 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.kotlin.CompileOptions;
|
||||||
|
import rife.bld.extension.kotlin.JvmOptions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -28,7 +30,7 @@ public class ExampleBuild extends Project {
|
||||||
|
|
||||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);
|
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);
|
||||||
|
|
||||||
final var kotlin = version(2, 1, 10);
|
final var kotlin = version(2, 1, 20);
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin));
|
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin));
|
||||||
scope(test)
|
scope(test)
|
||||||
|
@ -58,12 +60,14 @@ public class ExampleBuild extends Project {
|
||||||
@BuildCommand(summary = "Compiles the Kotlin project")
|
@BuildCommand(summary = "Compiles the Kotlin project")
|
||||||
@Override
|
@Override
|
||||||
public void compile() throws Exception {
|
public void compile() throws Exception {
|
||||||
|
var options = new CompileOptions().verbose(true);
|
||||||
|
options.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||||
// 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
|
||||||
var op = new CompileKotlinOperation()
|
new CompileKotlinOperation()
|
||||||
// .kotlinHome("path/to/kotlin")
|
// .kotlinHome("path/to/kotlin")
|
||||||
// .kotlinc("path/to/kotlinc")
|
// .kotlinc("path/to/kotlinc")
|
||||||
.fromProject(this);
|
.compileOptions(options)
|
||||||
op.compileOptions().verbose(true);
|
.fromProject(this)
|
||||||
op.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ new=/tmp/checkcliargs-new
|
||||||
old=/tmp/checkcliargs-old
|
old=/tmp/checkcliargs-old
|
||||||
|
|
||||||
kotlinc -h 2>$new
|
kotlinc -h 2>$new
|
||||||
~/.sdkman/candidates/kotlin/2.1.0/bin/kotlinc -h 2>$old
|
~/.sdkman/candidates/kotlin/2.1.10/bin/kotlinc -h 2>$old
|
||||||
|
|
||||||
code --diff --wait $old $new
|
code --diff --wait $old $new
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class CompileOptions {
|
||||||
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
||||||
private final Collection<File> argFile_ = new ArrayList<>();
|
private final Collection<File> argFile_ = new ArrayList<>();
|
||||||
private final Collection<File> classpath_ = new ArrayList<>();
|
private final Collection<File> classpath_ = new ArrayList<>();
|
||||||
private final Collection<String> jvmOptions_ = new ArrayList<>();
|
private final JvmOptions jvmOptions_ = new JvmOptions();
|
||||||
private final Collection<String> optIn_ = new ArrayList<>();
|
private final Collection<String> optIn_ = new ArrayList<>();
|
||||||
private final Collection<String> options_ = new ArrayList<>();
|
private final Collection<String> options_ = new ArrayList<>();
|
||||||
private final Collection<String> plugin_ = new ArrayList<>();
|
private final Collection<String> plugin_ = new ArrayList<>();
|
||||||
|
@ -709,12 +709,12 @@ public class CompileOptions {
|
||||||
*
|
*
|
||||||
* @return the JVM options
|
* @return the JVM options
|
||||||
*/
|
*/
|
||||||
public Collection<String> jvmOptions() {
|
public JvmOptions jvmOptions() {
|
||||||
return jvmOptions_;
|
return jvmOptions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass an option directly to Java Virtual Machine
|
* Pass an option directly to the Java Virtual Machine
|
||||||
*
|
*
|
||||||
* @param jvmOptions the JVM options
|
* @param jvmOptions the JVM options
|
||||||
* @return this operation instance
|
* @return this operation instance
|
||||||
|
@ -725,7 +725,7 @@ public class CompileOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass an option directly to JVM
|
* Pass an option directly to the Java Virtual Machine
|
||||||
*
|
*
|
||||||
* @param jvmOptions one or more JVM option
|
* @param jvmOptions one or more JVM option
|
||||||
* @return this operation instance
|
* @return this operation instance
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package rife.bld.extension.kotlin;
|
package rife.bld.extension.kotlin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||||
* Defines the known Kotlin compiler plugin JARs.
|
* Defines the known Kotlin compiler plugin JARs.
|
||||||
*
|
*
|
||||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||||
|
@ -25,6 +26,8 @@ package rife.bld.extension.kotlin;
|
||||||
public enum CompilerPlugin {
|
public enum CompilerPlugin {
|
||||||
ALL_OPEN("allopen-compiler-plugin.jar"),
|
ALL_OPEN("allopen-compiler-plugin.jar"),
|
||||||
ASSIGNMENT("assignment-compiler-plugin.jar"),
|
ASSIGNMENT("assignment-compiler-plugin.jar"),
|
||||||
|
COMPOSE("compose-compiler-plugin.jar"),
|
||||||
|
KOTLIN_IMPORTS_DUMPER("kotlin-imports-dumper-compiler-plugin.jar"),
|
||||||
KOTLINX_SERIALIZATION("kotlinx-serialization-compiler-plugin.jar"),
|
KOTLINX_SERIALIZATION("kotlinx-serialization-compiler-plugin.jar"),
|
||||||
KOTLIN_SERIALIZATION("kotlin-serialization-compiler-plugin.jar"),
|
KOTLIN_SERIALIZATION("kotlin-serialization-compiler-plugin.jar"),
|
||||||
LOMBOK("lombok-compiler-plugin.jar"),
|
LOMBOK("lombok-compiler-plugin.jar"),
|
||||||
|
|
61
src/main/java/rife/bld/extension/kotlin/JvmOptions.java
Normal file
61
src/main/java/rife/bld/extension/kotlin/JvmOptions.java
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-2025 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.kotlin;
|
||||||
|
|
||||||
|
import rife.tools.StringUtils;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java Virtual Machine options.
|
||||||
|
*
|
||||||
|
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||||
|
* @since 1.0.5
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("PMD.LooseCoupling")
|
||||||
|
public class JvmOptions extends ArrayList<String> {
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keyword to enable native access for all code on the class path.
|
||||||
|
*/
|
||||||
|
public final static String ALL_UNNAMED = "ALL-UNNAMED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules that are permitted to perform restricted native operations.
|
||||||
|
* The module name can also be {@link #ALL_UNNAMED}.
|
||||||
|
*
|
||||||
|
* @return this list of options
|
||||||
|
*/
|
||||||
|
public JvmOptions enableNativeAccess(String... modules) {
|
||||||
|
return enableNativeAccess(List.of(modules));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules that are permitted to perform restricted native operations.
|
||||||
|
* The module name can also be {@link #ALL_UNNAMED}.
|
||||||
|
*
|
||||||
|
* @return this list of options
|
||||||
|
*/
|
||||||
|
public JvmOptions enableNativeAccess(List<String> modules) {
|
||||||
|
add("--enable-native-access=" + StringUtils.join(modules, ","));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ import rife.bld.BaseProject;
|
||||||
import rife.bld.blueprints.BaseProjectBlueprint;
|
import rife.bld.blueprints.BaseProjectBlueprint;
|
||||||
import rife.bld.extension.kotlin.CompileOptions;
|
import rife.bld.extension.kotlin.CompileOptions;
|
||||||
import rife.bld.extension.kotlin.CompilerPlugin;
|
import rife.bld.extension.kotlin.CompilerPlugin;
|
||||||
|
import rife.bld.extension.kotlin.JvmOptions;
|
||||||
import rife.tools.FileUtils;
|
import rife.tools.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -177,9 +178,10 @@ class CompileKotlinOperationTest {
|
||||||
|
|
||||||
op.compileOptions().verbose(true);
|
op.compileOptions().verbose(true);
|
||||||
op.compileOptions().jdkRelease("17");
|
op.compileOptions().jdkRelease("17");
|
||||||
|
op.compileOptions().jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||||
|
|
||||||
var args = op.compileOptions().args();
|
var args = op.compileOptions().args();
|
||||||
var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
|
var matches = List.of("-Xjdk-release=17", "-J--enable-native-access=ALL-UNNAMED", "-no-stdlib", "-verbose");
|
||||||
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
|
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
|
||||||
|
|
||||||
op.execute();
|
op.execute();
|
||||||
|
|
63
src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java
Normal file
63
src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-2025 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.kotlin;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||||
|
class JvmOptionsTest {
|
||||||
|
@Test
|
||||||
|
void testCompileOptions() {
|
||||||
|
var compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
||||||
|
assertThat(compileOptions.jvmOptions()).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
|
||||||
|
assertThat(compileOptions.args()).as("args()").containsExactly("-J--enable-native-access=ALL-UNNAMED");
|
||||||
|
|
||||||
|
compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
|
||||||
|
assertThat(compileOptions.jvmOptions()).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
|
||||||
|
assertThat(compileOptions.args()).as("args(m1,m2)").containsExactly("-J--enable-native-access=m1,m2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEnableNativeAccess() {
|
||||||
|
var options = new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||||
|
assertThat(options).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
|
||||||
|
|
||||||
|
options = new JvmOptions().enableNativeAccess("m1", "m2");
|
||||||
|
assertThat(options).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testJvmOptions() {
|
||||||
|
var compileOptions = new CompileOptions().jvmOptions("option1", "option2");
|
||||||
|
assertThat(compileOptions.jvmOptions()).as("option1,option2").containsExactly("option1", "option2");
|
||||||
|
assertThat(compileOptions.args()).as("args()").containsExactly("-Joption1", "-Joption2");
|
||||||
|
|
||||||
|
compileOptions = new CompileOptions().jvmOptions(List.of("option1", "option2"));
|
||||||
|
assertThat(compileOptions.jvmOptions()).as("List.of(option1,option2)").containsExactly("option1", "option2");
|
||||||
|
assertThat(compileOptions.args()).as("args(list)").containsExactly("-Joption1", "-Joption2");
|
||||||
|
|
||||||
|
compileOptions = compileOptions.jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
||||||
|
assertThat(compileOptions.jvmOptions()).as("List.of(option1,option2,ALL_UNNAMED)")
|
||||||
|
.containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED");
|
||||||
|
assertThat(compileOptions.args()).as("args(option1,option2,ALL_UNNAMED)")
|
||||||
|
.containsExactly("-Joption1", "-Joption2", "-J--enable-native-access=ALL-UNNAMED");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue