Skip to content

Commit

Permalink
Allow JVM args in JavaProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Sep 25, 2024
1 parent 94d4a6f commit 5649923
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@

public class DialogFactory {

private static Executor executor = Executors.newFixedThreadPool(4);

private DialogFactory() { }

public static void createYesOrNo(Component parent, String message, String submessage, IntConsumer result) {
Expand Down Expand Up @@ -165,7 +163,7 @@ public static FileAlreadyExists.UserChoice createFileAlreadyExistsDialog(EOCVSim
}

private static void invokeLater(Runnable runn) {
executor.execute(runn);
SwingUtilities.invokeLater(runn);
}

public static class FileChooser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void mouseClicked(MouseEvent e) {

public void joinInit() {
while (!hasFinishedInitializing) {
Thread.yield();
Thread.onSpinWait();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private JavaProcess() {}
* @throws InterruptedException if the process is interrupted
* @throws IOException if an I/O error occurs
*/
public static int execClasspath(Class klass, String classpath, String... args) throws InterruptedException, IOException {
public static int execClasspath(Class klass, String classpath, List<String> jvmArgs, List<String> args) throws InterruptedException, IOException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome +
File.separator + "bin" +
Expand All @@ -52,11 +52,14 @@ public static int execClasspath(Class klass, String classpath, String... args) t

List<String> command = new LinkedList<>();
command.add(javaBin);
if(jvmArgs != null) {
command.addAll(jvmArgs);
}
command.add("-cp");
command.add(classpath);
command.add(className);
if (args != null) {
command.addAll(List.of(args));
command.addAll(args);
}

ProcessBuilder builder = new ProcessBuilder(command);
Expand All @@ -67,8 +70,8 @@ public static int execClasspath(Class klass, String classpath, String... args) t
}


public static int exec(Class klass, String... args) throws InterruptedException, IOException {
return execClasspath(klass, System.getProperty("java.class.path"), args);
public static int exec(Class klass, List<String> jvmArgs, List<String> args) throws InterruptedException, IOException {
return execClasspath(klass, System.getProperty("java.class.path"), jvmArgs, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SuperAccessRequest(sourceName: String, reason: String) {
// Setup the frame
frame.contentPane = panel
frame.isAlwaysOnTop = true
frame.defaultCloseOperation = JDialog.DISPOSE_ON_CLOSE
frame.defaultCloseOperation = JDialog.HIDE_ON_CLOSE
frame.isResizable = false

frame.addWindowListener(object: WindowListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PluginLoader(val pluginFile: File, val eocvSim: EOCVSim) {
throw UnsupportedPluginException("Plugin request api version of v${parsedVersion}, EOCV-Sim is currently running at v${EOCVSim.PARSED_VERSION}")
}

if(pluginToml.contains("super-access") && pluginToml.getBoolean("super-access", false)) {
if(pluginToml.getBoolean("super-access", false)) {
requestSuperAccess(pluginToml.getString("super-access-reason", ""))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.github.serivesmejia.eocvsim.util.io.EOCVSimFolder
import com.github.serivesmejia.eocvsim.util.loggerForThis
import io.github.deltacv.eocvsim.gui.dialog.SuperAccessRequestMain
import java.io.File
import java.util.*

/**
* Manages the loading, enabling and disabling of plugins
Expand Down Expand Up @@ -145,6 +146,8 @@ class PluginManager(val eocvSim: EOCVSim) {
fun requestSuperAccessFor(loader: PluginLoader, reason: String): Boolean {
if(loader.hasSuperAccess) return true

logger.info("Requesting super access for ${loader.pluginName} v${loader.pluginVersion}")

var warning = "<html>$GENERIC_SUPERACCESS_WARN"
if(reason.trim().isNotBlank()) {
warning += "<br><br><i>$reason</i>"
Expand All @@ -156,7 +159,7 @@ class PluginManager(val eocvSim: EOCVSim) {

val name = "${loader.pluginName} by ${loader.pluginAuthor}".replace(" ", "-")

if(JavaProcess.exec(SuperAccessRequestMain::class.java, name, warning) == 171) {
if(JavaProcess.exec(SuperAccessRequestMain::class.java, null, Arrays.asList(name, warning)) == 171) {
eocvSim.config.superAccessPluginHashes.add(loader.pluginHash)
eocvSim.configManager.saveToFile()
return true
Expand Down

0 comments on commit 5649923

Please sign in to comment.