Support classpath argument when running scripts using the -script flag
Signed-off-by: Isak Karlsson <isak-kar@dsv.su.se>
This commit is contained in:
committed by
Alexander Udalov
parent
f632a90741
commit
efae5c05a1
@@ -176,7 +176,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
List<String> scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size());
|
||||
JetCoreEnvironment environment =
|
||||
JetCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(paths, environment, scriptArgs);
|
||||
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(configuration, paths, environment, scriptArgs);
|
||||
}
|
||||
else {
|
||||
JetCoreEnvironment environment =
|
||||
|
||||
+13
-6
@@ -222,11 +222,12 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
public static void compileAndExecuteScript(
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull KotlinPaths paths,
|
||||
@NotNull JetCoreEnvironment environment,
|
||||
@NotNull List<String> scriptArgs
|
||||
) {
|
||||
Class<?> scriptClass = compileScript(paths, environment);
|
||||
Class<?> scriptClass = compileScript(configuration, paths, environment);
|
||||
if (scriptClass == null) return;
|
||||
|
||||
try {
|
||||
@@ -241,7 +242,11 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Class<?> compileScript(@NotNull KotlinPaths paths, @NotNull JetCoreEnvironment environment) {
|
||||
public static Class<?> compileScript(
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull KotlinPaths paths,
|
||||
@NotNull JetCoreEnvironment environment
|
||||
) {
|
||||
List<AnalyzerScriptParameter> scriptParameters = environment.getConfiguration().getList(JVMConfigurationKeys.SCRIPT_PARAMETERS);
|
||||
if (!scriptParameters.isEmpty()) {
|
||||
JetScriptDefinitionProvider.getInstance(environment.getProject()).addScriptDefinition(
|
||||
@@ -255,11 +260,13 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
GeneratedClassLoader classLoader;
|
||||
try {
|
||||
List<URL> classPaths = Lists.newArrayList(paths.getRuntimePath().toURI().toURL());
|
||||
for (File file : configuration.get(JVMConfigurationKeys.CLASSPATH_KEY, Collections.<File>emptyList())) {
|
||||
classPaths.add(file.toURI().toURL());
|
||||
}
|
||||
classLoader = new GeneratedClassLoader(state.getFactory(),
|
||||
new URLClassLoader(new URL[] {
|
||||
// TODO: add all classpath
|
||||
paths.getRuntimePath().toURI().toURL()
|
||||
}, AllModules.class.getClassLoader())
|
||||
new URLClassLoader(classPaths.toArray(new URL[classPaths.size()]),
|
||||
AllModules.class.getClassLoader())
|
||||
);
|
||||
|
||||
FqName nameForScript = ScriptNameUtil.classNameForScript(environment.getSourceFiles().get(0).getScript());
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ScriptTest {
|
||||
|
||||
try {
|
||||
JetScriptDefinitionProvider.getInstance(environment.getProject()).markFileAsScript(environment.getSourceFiles().get(0));
|
||||
return KotlinToJVMBytecodeCompiler.compileScript(paths, environment);
|
||||
return KotlinToJVMBytecodeCompiler.compileScript(configuration, paths, environment);
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
|
||||
|
||||
Reference in New Issue
Block a user