Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdd93a7
commit 9ad7d77
Showing
9 changed files
with
229 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/org/adoptopenjdk/jitwatch/sandbox/compiler/CompilerKotlin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
/* | |||
* Copyright (c) 2013, 2014 Chris Newland. | |||
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD | |||
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki | |||
*/ | |||
package org.adoptopenjdk.jitwatch.sandbox.compiler; | |||
|
|||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.io.IOException; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
|
|||
import org.adoptopenjdk.jitwatch.sandbox.AbstractProcess; | |||
import org.adoptopenjdk.jitwatch.sandbox.ISandboxLogListener; | |||
|
|||
public class CompilerKotlin extends AbstractProcess implements ICompiler | |||
{ | |||
private Path compilerPath; | |||
|
|||
private final String COMPILER_NAME = "kotlinc-jvm"; | |||
public static final String KOTLIN_EXECUTABLE_JAR = "jitwatch-sandbox-kotlin.jar"; | |||
|
|||
public CompilerKotlin(String languageHomeDir) throws FileNotFoundException | |||
{ | |||
compilerPath = Paths.get(languageHomeDir, "bin", COMPILER_NAME); | |||
|
|||
if (!compilerPath.toFile().exists()) | |||
{ | |||
throw new FileNotFoundException("Could not find " + COMPILER_NAME); | |||
} | |||
|
|||
compilerPath = compilerPath.normalize(); | |||
} | |||
|
|||
@Override | |||
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, ISandboxLogListener logListener) | |||
throws IOException | |||
{ | |||
List<String> commands = new ArrayList<>(); | |||
|
|||
commands.add(compilerPath.toString()); | |||
|
|||
String outputDirPath = outputDir.getAbsolutePath().toString(); | |||
|
|||
List<String> compileOptions = Arrays.asList(new String[] { | |||
"-include-runtime", | |||
"-d", | |||
outputDirPath + File.separator + KOTLIN_EXECUTABLE_JAR }); | |||
|
|||
commands.addAll(compileOptions); | |||
|
|||
if (classpathEntries.size() > 0) | |||
{ | |||
commands.add("-classpath"); | |||
commands.add(makeClassPath(classpathEntries)); | |||
} | |||
|
|||
for (File sourceFile : sourceFiles) | |||
{ | |||
commands.add(sourceFile.getAbsolutePath()); | |||
} | |||
|
|||
return runCommands(commands, logListener); | |||
} | |||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/org/adoptopenjdk/jitwatch/sandbox/runtime/RuntimeKotlin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,85 @@ | |||
/* | |||
* Copyright (c) 2013, 2014 Chris Newland. | |||
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD | |||
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki | |||
*/ | |||
package org.adoptopenjdk.jitwatch.sandbox.runtime; | |||
|
|||
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_EMPTY; | |||
|
|||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Properties; | |||
|
|||
import org.adoptopenjdk.jitwatch.loader.ResourceLoader; | |||
import org.adoptopenjdk.jitwatch.sandbox.AbstractProcess; | |||
import org.adoptopenjdk.jitwatch.sandbox.ISandboxLogListener; | |||
import org.adoptopenjdk.jitwatch.sandbox.Sandbox; | |||
import org.adoptopenjdk.jitwatch.sandbox.compiler.CompilerKotlin; | |||
|
|||
public class RuntimeKotlin extends AbstractProcess implements IRuntime | |||
{ | |||
private Path runtimePath; | |||
|
|||
private final Path pathToRuntimeJar = Paths.get(Sandbox.SANDBOX_CLASS_DIR.toString(), CompilerKotlin.KOTLIN_EXECUTABLE_JAR); | |||
|
|||
private final String RUNTIME_NAME = "java" + getExecutableSuffix(); | |||
|
|||
public RuntimeKotlin(String languageHomeDir) throws FileNotFoundException | |||
{ | |||
// Kotlin is executed on the current running Java VM | |||
runtimePath = Paths.get(System.getProperty("java.home"), "bin", RUNTIME_NAME); | |||
|
|||
if (!runtimePath.toFile().exists()) | |||
{ | |||
throw new FileNotFoundException("Could not find " + RUNTIME_NAME); | |||
} | |||
|
|||
runtimePath = runtimePath.normalize(); | |||
} | |||
|
|||
@Override | |||
public boolean execute(String className, List<String> classpathEntries, List<String> vmOptions, ISandboxLogListener logListener) | |||
{ | |||
List<String> commands = new ArrayList<>(); | |||
|
|||
commands.add(runtimePath.toString()); | |||
|
|||
if (vmOptions.size() > 0) | |||
{ | |||
commands.addAll(vmOptions); | |||
} | |||
|
|||
if (classpathEntries.size() > 0) | |||
{ | |||
commands.add("-cp"); | |||
commands.add(makeClassPath(classpathEntries)); | |||
} | |||
|
|||
commands.add("-jar"); | |||
commands.add(pathToRuntimeJar.toString()); | |||
|
|||
return runCommands(commands, logListener); | |||
} | |||
|
|||
@Override | |||
public String getClassToExecute(File fileToRun) | |||
{ | |||
// Main class is in the jar manifest | |||
return S_EMPTY; | |||
} | |||
|
|||
@Override | |||
public String getClassForTriView(File fileToRun) | |||
{ | |||
Properties manifest = ResourceLoader.readManifestFromZip(pathToRuntimeJar.toFile()); | |||
|
|||
String mainClass = manifest.getProperty("Main-Class"); | |||
|
|||
return mainClass; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters