Compare commits
2 commits
779e6d4b79
...
54228e3149
Author | SHA1 | Date | |
---|---|---|---|
54228e3149 | |||
5ca06f4d81 |
4 changed files with 65 additions and 6 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -9,6 +9,8 @@
|
||||||
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin NOARG" />
|
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin NOARG" />
|
||||||
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin POWER_ASSERT" />
|
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin POWER_ASSERT" />
|
||||||
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin SAM_WITH_RECEIVER" />
|
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin SAM_WITH_RECEIVER" />
|
||||||
|
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin COMPOSE" />
|
||||||
|
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin KOTLIN_IMPORTS_DUMPER" />
|
||||||
</entry_points>
|
</entry_points>
|
||||||
<pattern value="rife.bld.extension.CompileKotlinOperationBuild" method="pmd" />
|
<pattern value="rife.bld.extension.CompileKotlinOperationBuild" method="pmd" />
|
||||||
<pattern value="rife.bld.extension.kotlin.CompilerPlugin" />
|
<pattern value="rife.bld.extension.kotlin.CompilerPlugin" />
|
||||||
|
|
|
@ -31,18 +31,19 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.LooseCoupling")
|
@SuppressWarnings("PMD.LooseCoupling")
|
||||||
public class JvmOptions extends ArrayList<String> {
|
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.
|
* Keyword to enable native access for all code on the class path.
|
||||||
*/
|
*/
|
||||||
public final static String ALL_UNNAMED = "ALL-UNNAMED";
|
public final static String ALL_UNNAMED = "ALL-UNNAMED";
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules that are permitted to perform restricted native operations.
|
* Modules that are permitted to perform restricted native operations.
|
||||||
* The module name can also be {@link #ALL_UNNAMED}.
|
* The module name can also be {@link #ALL_UNNAMED}.
|
||||||
*
|
*
|
||||||
|
* @param modules the module names
|
||||||
* @return this list of options
|
* @return this list of options
|
||||||
*/
|
*/
|
||||||
public JvmOptions enableNativeAccess(String... modules) {
|
public JvmOptions enableNativeAccess(String... modules) {
|
||||||
|
@ -53,10 +54,37 @@ public class JvmOptions extends ArrayList<String> {
|
||||||
* Modules that are permitted to perform restricted native operations.
|
* Modules that are permitted to perform restricted native operations.
|
||||||
* The module name can also be {@link #ALL_UNNAMED}.
|
* The module name can also be {@link #ALL_UNNAMED}.
|
||||||
*
|
*
|
||||||
|
* @param modules the module names
|
||||||
* @return this list of options
|
* @return this list of options
|
||||||
*/
|
*/
|
||||||
public JvmOptions enableNativeAccess(Collection<String> modules) {
|
public JvmOptions enableNativeAccess(Collection<String> modules) {
|
||||||
add("--enable-native-access=" + StringUtils.join(modules, ","));
|
add("--enable-native-access=" + StringUtils.join(modules, ","));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls what action the Java runtime takes when native access is not enabled for a module.
|
||||||
|
*
|
||||||
|
* @param access the access mode
|
||||||
|
* @return this list of options
|
||||||
|
*/
|
||||||
|
public JvmOptions illegalNativeAccess(NativeAccess access) {
|
||||||
|
add("--illegal-native-access=" + access.mode);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Illegal native access modes.
|
||||||
|
*/
|
||||||
|
public enum NativeAccess {
|
||||||
|
ALLOW("allow"),
|
||||||
|
DENY("deny"),
|
||||||
|
WARN("warn");
|
||||||
|
|
||||||
|
public final String mode;
|
||||||
|
|
||||||
|
NativeAccess(String mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,9 +104,10 @@ class CompileKotlinOperationTest {
|
||||||
.testSourceFiles(List.of(new File("tfile3"), new File("tfile4")))
|
.testSourceFiles(List.of(new File("tfile3"), new File("tfile4")))
|
||||||
.testSourceFiles(new File("tfile5"), new File("tfile6"))
|
.testSourceFiles(new File("tfile5"), new File("tfile6"))
|
||||||
.plugins("plugin1", "plugin2")
|
.plugins("plugin1", "plugin2")
|
||||||
.plugins(CompilerPlugin.KOTLIN_SERIALIZATION, CompilerPlugin.ASSIGNMENT)
|
.plugins(CompilerPlugin.KOTLIN_SERIALIZATION, CompilerPlugin.ASSIGNMENT, CompilerPlugin.COMPOSE)
|
||||||
.plugins(new File("lib/compile"), CompilerPlugin.LOMBOK, CompilerPlugin.POWER_ASSERT)
|
.plugins(new File("lib/compile"), CompilerPlugin.LOMBOK, CompilerPlugin.POWER_ASSERT)
|
||||||
.plugins(Path.of("lib/compile"), CompilerPlugin.NOARG, CompilerPlugin.ALL_OPEN)
|
.plugins(Path.of("lib/compile"), CompilerPlugin.NOARG, CompilerPlugin.ALL_OPEN,
|
||||||
|
CompilerPlugin.KOTLIN_IMPORTS_DUMPER)
|
||||||
.plugins("lib/compile", CompilerPlugin.KOTLINX_SERIALIZATION, CompilerPlugin.SAM_WITH_RECEIVER)
|
.plugins("lib/compile", CompilerPlugin.KOTLINX_SERIALIZATION, CompilerPlugin.SAM_WITH_RECEIVER)
|
||||||
|
|
||||||
.plugins(List.of("plugin3", "plugin4"));
|
.plugins(List.of("plugin3", "plugin4"));
|
||||||
|
@ -134,10 +135,12 @@ class CompileKotlinOperationTest {
|
||||||
softly.assertThat(op.plugins()).as("plugins").contains("plugin1", "plugin2", "plugin3", "plugin4",
|
softly.assertThat(op.plugins()).as("plugins").contains("plugin1", "plugin2", "plugin3", "plugin4",
|
||||||
"/kotlin_home/lib/kotlin-serialization-compiler-plugin.jar",
|
"/kotlin_home/lib/kotlin-serialization-compiler-plugin.jar",
|
||||||
"/kotlin_home/lib/assignment-compiler-plugin.jar",
|
"/kotlin_home/lib/assignment-compiler-plugin.jar",
|
||||||
|
"/kotlin_home/lib/compose-compiler-plugin.jar",
|
||||||
new File("lib/compile", "lombok-compiler-plugin.jar").getAbsolutePath(),
|
new File("lib/compile", "lombok-compiler-plugin.jar").getAbsolutePath(),
|
||||||
new File("lib/compile", "power-assert-compiler-plugin.jar").getAbsolutePath(),
|
new File("lib/compile", "power-assert-compiler-plugin.jar").getAbsolutePath(),
|
||||||
new File("lib/compile", "noarg-compiler-plugin.jar").getAbsolutePath(),
|
new File("lib/compile", "noarg-compiler-plugin.jar").getAbsolutePath(),
|
||||||
new File("lib/compile", "allopen-compiler-plugin.jar").getAbsolutePath(),
|
new File("lib/compile", "allopen-compiler-plugin.jar").getAbsolutePath(),
|
||||||
|
new File("lib/compile", "kotlin-imports-dumper-compiler-plugin.jar").getAbsolutePath(),
|
||||||
new File("lib/compile", "kotlinx-serialization-compiler-plugin.jar").getAbsolutePath(),
|
new File("lib/compile", "kotlinx-serialization-compiler-plugin.jar").getAbsolutePath(),
|
||||||
new File("lib/compile", "sam-with-receiver-compiler-plugin.jar").getAbsolutePath());
|
new File("lib/compile", "sam-with-receiver-compiler-plugin.jar").getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -315,6 +318,8 @@ class CompileKotlinOperationTest {
|
||||||
.fromProject(new BaseProject())
|
.fromProject(new BaseProject())
|
||||||
.plugins(CompilerPlugin.ALL_OPEN,
|
.plugins(CompilerPlugin.ALL_OPEN,
|
||||||
CompilerPlugin.ASSIGNMENT,
|
CompilerPlugin.ASSIGNMENT,
|
||||||
|
CompilerPlugin.COMPOSE,
|
||||||
|
CompilerPlugin.KOTLIN_IMPORTS_DUMPER,
|
||||||
CompilerPlugin.KOTLINX_SERIALIZATION,
|
CompilerPlugin.KOTLINX_SERIALIZATION,
|
||||||
CompilerPlugin.KOTLIN_SERIALIZATION,
|
CompilerPlugin.KOTLIN_SERIALIZATION,
|
||||||
CompilerPlugin.LOMBOK,
|
CompilerPlugin.LOMBOK,
|
||||||
|
|
|
@ -27,7 +27,8 @@ class JvmOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
void testCompileOptions() {
|
void testCompileOptions() {
|
||||||
var compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
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.jvmOptions()).as(JvmOptions.ALL_UNNAMED)
|
||||||
|
.containsExactly("--enable-native-access=ALL-UNNAMED");
|
||||||
assertThat(compileOptions.args()).as("args()").containsExactly("-J--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"));
|
compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
|
||||||
|
@ -40,10 +41,25 @@ class JvmOptionsTest {
|
||||||
var options = new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
var options = new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||||
assertThat(options).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
|
assertThat(options).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
|
||||||
|
|
||||||
|
options = new JvmOptions().enableNativeAccess("m1");
|
||||||
|
assertThat(options).as("m1").containsExactly("--enable-native-access=m1");
|
||||||
|
|
||||||
options = new JvmOptions().enableNativeAccess("m1", "m2");
|
options = new JvmOptions().enableNativeAccess("m1", "m2");
|
||||||
assertThat(options).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
|
assertThat(options).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIllegalNativeAccess() {
|
||||||
|
var options = new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.ALLOW);
|
||||||
|
assertThat(options).as("ALLOW").containsExactly("--illegal-native-access=allow");
|
||||||
|
|
||||||
|
options = new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.DENY);
|
||||||
|
assertThat(options).as("DENY").containsExactly("--illegal-native-access=deny");
|
||||||
|
|
||||||
|
options = new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.WARN);
|
||||||
|
assertThat(options).as("WARN").containsExactly("--illegal-native-access=warn");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJvmOptions() {
|
void testJvmOptions() {
|
||||||
var compileOptions = new CompileOptions().jvmOptions("option1", "option2");
|
var compileOptions = new CompileOptions().jvmOptions("option1", "option2");
|
||||||
|
@ -59,5 +75,13 @@ class JvmOptionsTest {
|
||||||
.containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED");
|
.containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED");
|
||||||
assertThat(compileOptions.args()).as("args(option1,option2,ALL_UNNAMED)")
|
assertThat(compileOptions.args()).as("args(option1,option2,ALL_UNNAMED)")
|
||||||
.containsExactly("-Joption1", "-Joption2", "-J--enable-native-access=ALL-UNNAMED");
|
.containsExactly("-Joption1", "-Joption2", "-J--enable-native-access=ALL-UNNAMED");
|
||||||
|
|
||||||
|
compileOptions = compileOptions.jvmOptions(new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.ALLOW));
|
||||||
|
assertThat(compileOptions.jvmOptions()).as("allow")
|
||||||
|
.containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED",
|
||||||
|
"--illegal-native-access=allow");
|
||||||
|
assertThat(compileOptions.args()).as("args(option1,option2,ALL_UNNAMED,allow)")
|
||||||
|
.containsExactly("-Joption1", "-Joption2", "-J--enable-native-access=ALL-UNNAMED",
|
||||||
|
"-J--illegal-native-access=allow");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue