Rename -jdk compiler option to -jdk-home (jdkHome), add jdk path validation.
This commit is contained in:
+2
-2
@@ -31,9 +31,9 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
|||||||
@Argument(value = "include-runtime", description = "Include Kotlin runtime in to resulting .jar")
|
@Argument(value = "include-runtime", description = "Include Kotlin runtime in to resulting .jar")
|
||||||
public boolean includeRuntime;
|
public boolean includeRuntime;
|
||||||
|
|
||||||
@Argument(value = "jdk", description = "Path to JDK home to include into classpath, if differs from default %JAVA_HOME%")
|
@Argument(value = "jdk-home", description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME")
|
||||||
@ValueDescription("<path>")
|
@ValueDescription("<path>")
|
||||||
public String jdk;
|
public String jdkHome;
|
||||||
|
|
||||||
@Argument(value = "no-jdk", description = "Don't include Java runtime into classpath")
|
@Argument(value = "no-jdk", description = "Don't include Java runtime into classpath")
|
||||||
public boolean noJdk;
|
public boolean noJdk;
|
||||||
|
|||||||
@@ -60,26 +60,8 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Using Kotlin home directory " + paths.homePath, CompilerMessageLocation.NO_LOCATION)
|
messageCollector.report(CompilerMessageSeverity.LOGGING, "Using Kotlin home directory " + paths.homePath, CompilerMessageLocation.NO_LOCATION)
|
||||||
PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf)
|
PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf)
|
||||||
|
|
||||||
try {
|
setupJdkClasspathRoots(arguments, configuration, messageCollector).let {
|
||||||
if (!arguments.noJdk) {
|
if (it != OK) return it
|
||||||
if (arguments.jdk != null) {
|
|
||||||
configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots(File(arguments.jdk)))
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (arguments.jdk != null) {
|
|
||||||
messageCollector.report(CompilerMessageSeverity.WARNING,
|
|
||||||
"The '-jdk' option with a path to JDK is ignored because '-no-jdk' is specified",
|
|
||||||
CompilerMessageLocation.NO_LOCATION)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (t: Throwable) {
|
|
||||||
MessageCollectorUtil.reportException(messageCollector, t)
|
|
||||||
return INTERNAL_ERROR
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -325,6 +307,41 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
return classpath
|
return classpath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupJdkClasspathRoots(arguments: K2JVMCompilerArguments, configuration: CompilerConfiguration, messageCollector: MessageCollector): ExitCode {
|
||||||
|
try {
|
||||||
|
if (!arguments.noJdk) {
|
||||||
|
if (arguments.jdkHome != null) {
|
||||||
|
messageCollector.report(CompilerMessageSeverity.LOGGING,
|
||||||
|
"Using JDK home directory ${arguments.jdkHome}",
|
||||||
|
CompilerMessageLocation.NO_LOCATION)
|
||||||
|
val classesRoots = PathUtil.getJdkClassesRoots(File(arguments.jdkHome))
|
||||||
|
if (classesRoots.isEmpty()) {
|
||||||
|
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||||
|
"No class roots are found in the JDK path: ${arguments.jdkHome}",
|
||||||
|
CompilerMessageLocation.NO_LOCATION)
|
||||||
|
return COMPILATION_ERROR
|
||||||
|
}
|
||||||
|
configuration.addJvmClasspathRoots(classesRoots)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (arguments.jdkHome != null) {
|
||||||
|
messageCollector.report(CompilerMessageSeverity.WARNING,
|
||||||
|
"The '-jdk-home' option is ignored because '-no-jdk' is specified",
|
||||||
|
CompilerMessageLocation.NO_LOCATION)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (t: Throwable) {
|
||||||
|
MessageCollectorUtil.reportException(messageCollector, t)
|
||||||
|
return INTERNAL_ERROR
|
||||||
|
}
|
||||||
|
return OK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ where possible options include:
|
|||||||
-d <directory|jar> Destination for generated class files
|
-d <directory|jar> Destination for generated class files
|
||||||
-classpath (-cp) <path> Paths where to find user class files
|
-classpath (-cp) <path> Paths where to find user class files
|
||||||
-include-runtime Include Kotlin runtime in to resulting .jar
|
-include-runtime Include Kotlin runtime in to resulting .jar
|
||||||
-jdk <path> Path to JDK home to include into classpath, if differs from default %JAVA_HOME%
|
-jdk-home <path> Path to JDK home directory to include into classpath, if differs from default JAVA_HOME
|
||||||
-no-jdk Don't include Java runtime into classpath
|
-no-jdk Don't include Java runtime into classpath
|
||||||
-no-stdlib Don't include Kotlin runtime into classpath
|
-no-stdlib Don't include Kotlin runtime into classpath
|
||||||
-module <path> Path to the module file to compile
|
-module <path> Path to the module file to compile
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
$TESTDATA_DIR$/simple.kt
|
$TESTDATA_DIR$/simple.kt
|
||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
-jdk
|
-jdk-home
|
||||||
$TESTDATA_DIR$
|
$TESTDATA_DIR$
|
||||||
-no-jdk
|
-no-jdk
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
warning: the '-jdk' option with a path to JDK is ignored because '-no-jdk' is specified
|
warning: the '-jdk-home' option is ignored because '-no-jdk' is specified
|
||||||
OK
|
OK
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ where possible options include:
|
|||||||
-d <directory|jar> Destination for generated class files
|
-d <directory|jar> Destination for generated class files
|
||||||
-classpath (-cp) <path> Paths where to find user class files
|
-classpath (-cp) <path> Paths where to find user class files
|
||||||
-include-runtime Include Kotlin runtime in to resulting .jar
|
-include-runtime Include Kotlin runtime in to resulting .jar
|
||||||
-jdk <path> Path to JDK home to include into classpath, if differs from default %JAVA_HOME%
|
-jdk-home <path> Path to JDK home directory to include into classpath, if differs from default JAVA_HOME
|
||||||
-no-jdk Don't include Java runtime into classpath
|
-no-jdk Don't include Java runtime into classpath
|
||||||
-no-stdlib Don't include Kotlin runtime into classpath
|
-no-stdlib Don't include Kotlin runtime into classpath
|
||||||
-module <path> Path to the module file to compile
|
-module <path> Path to the module file to compile
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-jdk-home
|
||||||
|
$TESTDATA_DIR$
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
error: no class roots are found in the JDK path: compiler/testData/cli/jvm
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -295,6 +295,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
doJvmTest(fileName);
|
doJvmTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("wrongJdkPath.args")
|
||||||
|
public void testWrongJdkPath() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/wrongJdkPath.args");
|
||||||
|
doJvmTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("wrongJvmTargetVersion.args")
|
@TestMetadata("wrongJvmTargetVersion.args")
|
||||||
public void testWrongJvmTargetVersion() throws Exception {
|
public void testWrongJvmTargetVersion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/wrongJvmTargetVersion.args");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/wrongJvmTargetVersion.args");
|
||||||
|
|||||||
+1
-1
@@ -195,7 +195,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
logger.kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}")
|
logger.kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}")
|
||||||
|
|
||||||
args.noStdlib = true
|
args.noStdlib = true
|
||||||
args.jdk = kotlinOptions.jdk
|
args.jdkHome = kotlinOptions.jdkHome
|
||||||
args.noJdk = kotlinOptions.noJdk
|
args.noJdk = kotlinOptions.noJdk
|
||||||
args.noInline = kotlinOptions.noInline
|
args.noInline = kotlinOptions.noInline
|
||||||
args.noOptimize = kotlinOptions.noOptimize
|
args.noOptimize = kotlinOptions.noOptimize
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
kotlinOptions.jdk = System.getenv("JDK_17")
|
kotlinOptions.jdkHome = System.getenv("JDK_17")
|
||||||
}
|
}
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<kotlin.compiler.jdk>${env.JDK_18}</kotlin.compiler.jdk>
|
<kotlin.compiler.jdkHome>${env.JDK_17}</kotlin.compiler.jdkHome>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+5
-5
@@ -62,8 +62,8 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
@Parameter(property = "kotlin.compiler.jvmTarget", required = false, readonly = false)
|
@Parameter(property = "kotlin.compiler.jvmTarget", required = false, readonly = false)
|
||||||
protected String jvmTarget;
|
protected String jvmTarget;
|
||||||
|
|
||||||
@Parameter(property = "kotlin.compiler.jdk", required = false, readonly = false)
|
@Parameter(property = "kotlin.compiler.jdkHome", required = false, readonly = false)
|
||||||
protected String jdk;
|
protected String jdkHome;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -110,9 +110,9 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
arguments.languageVersion = languageVersion;
|
arguments.languageVersion = languageVersion;
|
||||||
arguments.jvmTarget = jvmTarget;
|
arguments.jvmTarget = jvmTarget;
|
||||||
|
|
||||||
if (jdk != null) {
|
if (jdkHome != null) {
|
||||||
getLog().info("Overriding JDK path with: " + jdk);
|
getLog().info("Overriding JDK home path with: " + jdkHome);
|
||||||
arguments.jdk = jdk;
|
arguments.jdkHome = jdkHome;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user