summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-06-23 14:55:13 +0200
committerSimon Rettberg2023-06-23 14:55:13 +0200
commit01b7a047176302a42c0e2a413261073fd444e04d (patch)
treea5c43747dbb817fd24dfb540ac20053bbf2b0cd4
parent[qemu] Add option to edit XML before launching (diff)
downloadmltk-01b7a047176302a42c0e2a413261073fd444e04d.tar.gz
mltk-01b7a047176302a42c0e2a413261073fd444e04d.tar.xz
mltk-01b7a047176302a42c0e2a413261073fd444e04d.zip
[qemu] Add missing file
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/EditorRunner.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/EditorRunner.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/EditorRunner.java
new file mode 100644
index 00000000..6dbb26c5
--- /dev/null
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/EditorRunner.java
@@ -0,0 +1,50 @@
+package org.openslx.runvirt.plugin.qemu;
+
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Small wrapper around Process that will try to launch any sensible GUI
+ * text editor on the given file.
+ */
+public class EditorRunner
+{
+
+ private static final String[] EDITORS = {
+ "mousepad",
+ "leafpad",
+ "gedit",
+ "gvim",
+ "medit",
+ "kate",
+ "featherpad",
+ };
+
+ public static void open( String file )
+ {
+ for ( String editor : EDITORS ) {
+ if ( open( editor, file ) )
+ return;
+ }
+ return;
+ }
+
+ private static boolean open( String editor, String file )
+ {
+ ProcessBuilder pr = new ProcessBuilder( editor, file );
+ pr.redirectError( Redirect.DISCARD );
+ pr.redirectOutput( Redirect.DISCARD );
+ try {
+ final Process p = pr.start();
+ p.waitFor( 1, TimeUnit.SECONDS );
+ if ( !p.isAlive() )
+ return false;
+ p.waitFor();
+ } catch ( IOException | InterruptedException e ) {
+ return false;
+ }
+ return true;
+ }
+
+}