-
Notifications
You must be signed in to change notification settings - Fork 78
New Java executor #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ee52b6a
chore: introduce java-runner
AlexanderPrendota 2f2c297
fix(executor): correct output parsing
AlexanderPrendota a50c167
refactor: introduce message as const
AlexanderPrendota bad5463
fix(test): correct parsing coroutines output
AlexanderPrendota 17fc480
test: update output
AlexanderPrendota def894c
docs: update tasks
AlexanderPrendota f3dd557
test: add kotlin npe
AlexanderPrendota 54f0e94
refactor: clean up
AlexanderPrendota 6538228
сhore: catch kotlin compiler exception
AlexanderPrendota 39d1c28
chore: validate exception in executor
AlexanderPrendota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package executors | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.PrintStream | ||
import java.lang.reflect.InvocationTargetException | ||
|
||
const val NO_MAIN_METHOD = "No main method found in project." | ||
|
||
class JavaRunnerExecutor { | ||
companion object { | ||
private val outputStream = ByteArrayOutputStream() | ||
private val errorOutputStream = ErrorStream(outputStream) | ||
private val standardOutputStream = OutStream(outputStream) | ||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
val defaultOutputStream = System.out | ||
try { | ||
System.setOut(PrintStream(standardOutputStream)) | ||
System.setErr(PrintStream(errorOutputStream)) | ||
val outputObj = RunOutput() | ||
val className: String | ||
if (args.isNotEmpty()) { | ||
className = args[0] | ||
try { | ||
val mainMethod = Class.forName(className) | ||
.getMethod("main", Array<String>::class.java) | ||
mainMethod.invoke(null, args.copyOfRange(1, args.size) as Any) | ||
} | ||
catch (e: InvocationTargetException) { | ||
outputObj.exception = e.cause | ||
} | ||
catch (e: NoSuchMethodException) { | ||
System.err.println(NO_MAIN_METHOD) | ||
} | ||
catch (e: ClassNotFoundException) { | ||
System.err.println(NO_MAIN_METHOD) | ||
} | ||
} | ||
else { | ||
System.err.println(NO_MAIN_METHOD) | ||
} | ||
System.out.flush() | ||
System.err.flush() | ||
System.setOut(defaultOutputStream) | ||
outputObj.text = outputStream.toString() | ||
.replace("</errStream><errStream>".toRegex(), "") | ||
.replace("</outStream><outStream>".toRegex(), "") | ||
print(mapper.writeValueAsString(outputObj)) | ||
} | ||
catch (e: Throwable) { | ||
System.setOut(defaultOutputStream) | ||
println("{\"text\":\"<errStream>" + e.javaClass.name + ": " + e.message) | ||
e.printStackTrace() | ||
print("</errStream>\"}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
data class RunOutput(var text: String = "", var exception: Throwable? = null) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.