[gnome-builder] podman: add basic podman runtime provider



commit 579074c4ad9daf7c4152f166720f985296516262
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 18 16:56:53 2019 -0800

    podman: add basic podman runtime provider
    
    This implements a basic podman provider. It is currently disabled by
    default because we do not yet have support for passing FDs across the
    podman boundary. This is needed for our GDB plugin to work correctly as
    we pass the FD for the inferior PTY.

 meson_options.txt                                  |   1 +
 src/plugins/meson.build                            |   2 +
 src/plugins/podman/gbp-podman-runtime-provider.c   | 213 +++++++++++++++++++++
 src/plugins/podman/gbp-podman-runtime-provider.h   |  31 +++
 src/plugins/podman/gbp-podman-runtime.c            | 105 ++++++++++
 src/plugins/podman/gbp-podman-runtime.h            |  34 ++++
 .../podman/gbp-podman-subprocess-launcher.c        | 198 +++++++++++++++++++
 .../podman/gbp-podman-subprocess-launcher.h        |  31 +++
 src/plugins/podman/meson.build                     |  18 ++
 src/plugins/podman/podman-plugin.c                 |  36 ++++
 src/plugins/podman/podman.gresource.xml            |   6 +
 src/plugins/podman/podman.plugin                   |  10 +
 12 files changed, 685 insertions(+)
---
diff --git a/meson_options.txt b/meson_options.txt
index 128f13246..6624227c4 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -57,6 +57,7 @@ option('plugin_newcomers', type: 'boolean')
 option('plugin_notification', type: 'boolean')
 option('plugin_npm', type: 'boolean')
 option('plugin_phpize', type: 'boolean')
+option('plugin_podman', type: 'boolean', value: false)
 option('plugin_python_pack', type: 'boolean')
 option('plugin_qemu', type: 'boolean')
 option('plugin_quick_highlight', type: 'boolean')
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index b23147cad..66f787d14 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -93,6 +93,7 @@ subdir('notification')
 subdir('npm')
 subdir('omni-gutter')
 subdir('phpize')
+subdir('podman')
 subdir('project-tree')
 subdir('python-gi-imports-completion')
 subdir('python-pack')
@@ -167,6 +168,7 @@ status += [
   'Notifications ......... : @0@'.format(get_option('plugin_notification')),
   'Npm ................... : @0@'.format(get_option('plugin_npm')),
   'PHPize ................ : @0@'.format(get_option('plugin_phpize')),
+  'Podman ................ : @0@'.format(get_option('plugin_podman')),
   'Python Pack ........... : @0@'.format(get_option('plugin_python_pack')),
   'Qemu .................. : @0@'.format(get_option('plugin_qemu')),
   'Quick Highlight ....... : @0@'.format(get_option('plugin_quick_highlight')),
diff --git a/src/plugins/podman/gbp-podman-runtime-provider.c 
b/src/plugins/podman/gbp-podman-runtime-provider.c
new file mode 100644
index 000000000..6d3d038e7
--- /dev/null
+++ b/src/plugins/podman/gbp-podman-runtime-provider.c
@@ -0,0 +1,213 @@
+/* gbp-podman-runtime-provider.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-podman-runtime-provider"
+
+#include "config.h"
+
+#include <libide-foundry.h>
+#include <libide-threading.h>
+#include <json-glib/json-glib.h>
+
+#include "gbp-podman-runtime.h"
+#include "gbp-podman-runtime-provider.h"
+
+struct _GbpPodmanRuntimeProvider
+{
+  IdeObject          parent_instance;
+  GCancellable      *cancellable;
+  IdeRuntimeManager *manager;
+};
+
+static void
+gbp_podman_runtime_provider_apply_cb (JsonArray *ar,
+                                      guint      index_,
+                                      JsonNode  *element_node,
+                                      gpointer   user_data)
+{
+  GbpPodmanRuntimeProvider *self = user_data;
+  g_autoptr(GbpPodmanRuntime) runtime = NULL;
+  JsonObject *obj;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PODMAN_RUNTIME_PROVIDER (self));
+
+  if (self->manager == NULL)
+    return;
+
+  if (!JSON_NODE_HOLDS_OBJECT (element_node) ||
+      !(obj = json_node_get_object (element_node)))
+    return;
+
+  if ((runtime = gbp_podman_runtime_new (obj)))
+    {
+      ide_object_append (IDE_OBJECT (self), IDE_OBJECT (runtime));
+      ide_runtime_manager_add (self->manager, IDE_RUNTIME (runtime));
+    }
+}
+
+static gboolean
+gbp_podman_runtime_provider_apply (GbpPodmanRuntimeProvider  *self,
+                                   const gchar               *json_string,
+                                   GError                   **error)
+{
+  g_autoptr(JsonParser) parser = NULL;
+  JsonArray *ar;
+  JsonNode *root;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PODMAN_RUNTIME_PROVIDER (self));
+  g_assert (json_string != NULL);
+
+  parser = json_parser_new ();
+
+  if (!json_parser_load_from_data (parser, json_string, -1, error))
+    return FALSE;
+
+  if (!(root = json_parser_get_root (parser)) ||
+      !JSON_NODE_HOLDS_ARRAY (root) ||
+      !(ar = json_node_get_array (root)))
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_DATA,
+                   "Expected [] for root JSON node");
+      return FALSE;
+    }
+
+  json_array_foreach_element (ar,
+                              gbp_podman_runtime_provider_apply_cb,
+                              self);
+
+  return TRUE;
+}
+
+static void
+gbp_podman_runtime_provider_load_communicate_cb (GObject      *object,
+                                                 GAsyncResult *result,
+                                                 gpointer      user_data)
+{
+  IdeSubprocess *subprocess = (IdeSubprocess *)object;
+  GbpPodmanRuntimeProvider *self;
+  g_autofree gchar *stdout_buf = NULL;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_SUBPROCESS (subprocess));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  self = ide_task_get_source_object (task);
+
+  if (!ide_subprocess_communicate_utf8_finish (subprocess, result, &stdout_buf, NULL, &error) ||
+      !gbp_podman_runtime_provider_apply (self, stdout_buf, &error))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_boolean (task, TRUE);
+}
+
+static void
+gbp_podman_runtime_provider_load_async (GbpPodmanRuntimeProvider *self,
+                                        GCancellable             *cancellable,
+                                        GAsyncReadyCallback       callback,
+                                        gpointer                  user_data)
+{
+  g_autoptr(IdeTask) task = NULL;
+  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+  g_autoptr(IdeSubprocess) subprocess = NULL;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PODMAN_RUNTIME_PROVIDER (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, gbp_podman_runtime_provider_load_async);
+
+  launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
+  ide_subprocess_launcher_set_cwd (launcher, g_get_home_dir ());
+  ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+  ide_subprocess_launcher_push_argv (launcher, "podman");
+  ide_subprocess_launcher_push_argv (launcher, "ps");
+  ide_subprocess_launcher_push_argv (launcher, "--all");
+  ide_subprocess_launcher_push_argv (launcher, "--format=json");
+
+  if (!(subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error)))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_subprocess_communicate_utf8_async (subprocess,
+                                           NULL,
+                                           cancellable,
+                                           gbp_podman_runtime_provider_load_communicate_cb,
+                                           g_steal_pointer (&task));
+}
+
+static void
+gbp_podman_runtime_provider_load (IdeRuntimeProvider *provider,
+                                  IdeRuntimeManager  *manager)
+{
+  GbpPodmanRuntimeProvider *self = (GbpPodmanRuntimeProvider *)provider;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PODMAN_RUNTIME_PROVIDER (self));
+  g_assert (IDE_IS_RUNTIME_MANAGER (manager));
+
+  self->cancellable = g_cancellable_new ();
+  self->manager = manager;
+
+  gbp_podman_runtime_provider_load_async (self, self->cancellable, NULL, NULL);
+}
+
+static void
+gbp_podman_runtime_provider_unload (IdeRuntimeProvider *provider,
+                                    IdeRuntimeManager  *manager)
+{
+  GbpPodmanRuntimeProvider *self = (GbpPodmanRuntimeProvider *)provider;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PODMAN_RUNTIME_PROVIDER (self));
+  g_assert (IDE_IS_RUNTIME_MANAGER (manager));
+
+  self->manager = NULL;
+
+  g_cancellable_cancel (self->cancellable);
+  g_clear_object (&self->cancellable);
+}
+
+static void
+runtime_provider_iface_init (IdeRuntimeProviderInterface *iface)
+{
+  iface->load = gbp_podman_runtime_provider_load;
+  iface->unload = gbp_podman_runtime_provider_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpPodmanRuntimeProvider, gbp_podman_runtime_provider, IDE_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_RUNTIME_PROVIDER, runtime_provider_iface_init))
+
+static void
+gbp_podman_runtime_provider_class_init (GbpPodmanRuntimeProviderClass *klass)
+{
+}
+
+static void
+gbp_podman_runtime_provider_init (GbpPodmanRuntimeProvider *self)
+{
+}
diff --git a/src/plugins/podman/gbp-podman-runtime-provider.h 
b/src/plugins/podman/gbp-podman-runtime-provider.h
new file mode 100644
index 000000000..6b6898f4b
--- /dev/null
+++ b/src/plugins/podman/gbp-podman-runtime-provider.h
@@ -0,0 +1,31 @@
+/* gbp-podman-runtime-provider.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PODMAN_RUNTIME_PROVIDER (gbp_podman_runtime_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPodmanRuntimeProvider, gbp_podman_runtime_provider, GBP, PODMAN_RUNTIME_PROVIDER, 
IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/podman/gbp-podman-runtime.c b/src/plugins/podman/gbp-podman-runtime.c
new file mode 100644
index 000000000..6a2e6ee7f
--- /dev/null
+++ b/src/plugins/podman/gbp-podman-runtime.c
@@ -0,0 +1,105 @@
+/* gbp-podman-runtime.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-podman-runtime"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gbp-podman-runtime.h"
+#include "gbp-podman-subprocess-launcher.h"
+
+struct _GbpPodmanRuntime
+{
+  IdeRuntime  parent_instance;
+  JsonObject *object;
+};
+
+G_DEFINE_TYPE (GbpPodmanRuntime, gbp_podman_runtime, IDE_TYPE_RUNTIME)
+
+static IdeSubprocessLauncher *
+gbp_podman_runtime_create_launcher (IdeRuntime  *runtime,
+                                    GError     **error)
+{
+  GbpPodmanRuntime *self = (GbpPodmanRuntime *)runtime;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PODMAN_RUNTIME (self));
+
+  return g_object_new (GBP_TYPE_PODMAN_SUBPROCESS_LAUNCHER,
+                       "id", json_object_get_string_member (self->object, "ID"),
+                       "run-on-host", TRUE,
+                       NULL);
+}
+
+static void
+gbp_podman_runtime_destroy (IdeObject *object)
+{
+  GbpPodmanRuntime *self = (GbpPodmanRuntime *)object;
+
+  g_clear_pointer (&self->object, json_object_unref);
+
+  IDE_OBJECT_CLASS (gbp_podman_runtime_parent_class)->destroy (object);
+}
+
+static void
+gbp_podman_runtime_class_init (GbpPodmanRuntimeClass *klass)
+{
+  IdeObjectClass *i_object_class = IDE_OBJECT_CLASS (klass);
+  IdeRuntimeClass *runtime_class = IDE_RUNTIME_CLASS (klass);
+
+  i_object_class->destroy = gbp_podman_runtime_destroy;
+
+  runtime_class->create_launcher = gbp_podman_runtime_create_launcher;
+}
+
+static void
+gbp_podman_runtime_init (GbpPodmanRuntime *self)
+{
+}
+
+GbpPodmanRuntime *
+gbp_podman_runtime_new (JsonObject *object)
+{
+  g_autofree gchar *full_id = NULL;
+  GbpPodmanRuntime *self;
+  const gchar *id;
+  const gchar *names;
+
+  g_return_val_if_fail (object != NULL, NULL);
+
+  id = json_object_get_string_member (object, "ID");
+  names = json_object_get_string_member (object, "Names");
+  full_id = g_strdup_printf ("podman:%s", id);
+
+  g_return_val_if_fail (id != NULL, NULL);
+  g_return_val_if_fail (names != NULL, NULL);
+
+  self = g_object_new (GBP_TYPE_PODMAN_RUNTIME,
+                       "id", full_id,
+                       /* translators: this is a path to browse to the runtime, likely only "containers" 
should be translated */
+                       "category", _("Containers/Podman"),
+                       "display-name", names,
+                       NULL);
+  self->object = json_object_ref (object);
+
+  return g_steal_pointer (&self);
+}
diff --git a/src/plugins/podman/gbp-podman-runtime.h b/src/plugins/podman/gbp-podman-runtime.h
new file mode 100644
index 000000000..a5ab1e502
--- /dev/null
+++ b/src/plugins/podman/gbp-podman-runtime.h
@@ -0,0 +1,34 @@
+/* gbp-podman-runtime.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+#include <json-glib/json-glib.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PODMAN_RUNTIME (gbp_podman_runtime_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPodmanRuntime, gbp_podman_runtime, GBP, PODMAN_RUNTIME, IdeRuntime)
+
+GbpPodmanRuntime *gbp_podman_runtime_new (JsonObject *object);
+
+G_END_DECLS
diff --git a/src/plugins/podman/gbp-podman-subprocess-launcher.c 
b/src/plugins/podman/gbp-podman-subprocess-launcher.c
new file mode 100644
index 000000000..4e2201501
--- /dev/null
+++ b/src/plugins/podman/gbp-podman-subprocess-launcher.c
@@ -0,0 +1,198 @@
+/* gbp-podman-subprocess-launcher.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-podman-subprocess-launcher"
+
+#include "config.h"
+
+#include "gbp-podman-subprocess-launcher.h"
+
+struct _GbpPodmanSubprocessLauncher
+{
+  IdeSubprocessLauncher parent_instance;
+  gchar *id;
+};
+
+enum {
+  PROP_0,
+  PROP_ID,
+  N_PROPS
+};
+
+G_DEFINE_TYPE (GbpPodmanSubprocessLauncher, gbp_podman_subprocess_launcher, IDE_TYPE_SUBPROCESS_LAUNCHER)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+copy_envvar (IdeSubprocessLauncher *launcher,
+             guint                  position,
+             const gchar           *key)
+{
+  const gchar *val;
+
+  if ((val = g_getenv (key)))
+    {
+      g_autofree gchar *arg = g_strdup_printf ("--env=%s=%s", key, val);
+      ide_subprocess_launcher_insert_argv (launcher, position, arg);
+    }
+}
+
+static IdeSubprocess *
+gbp_podman_subprocess_launcher_spawn (IdeSubprocessLauncher  *launcher,
+                                      GCancellable           *cancellable,
+                                      GError                **error)
+{
+  GbpPodmanSubprocessLauncher *self = (GbpPodmanSubprocessLauncher *)launcher;
+  const gchar * const *argv;
+
+  g_assert (GBP_IS_PODMAN_SUBPROCESS_LAUNCHER (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_assert (self->id != NULL);
+
+  argv = ide_subprocess_launcher_get_argv (launcher);
+
+  if (!ide_str_equal0 (argv[0], "podman"))
+    {
+      const gchar * const *environ;
+      const gchar *cwd;
+      guint i = 0;
+
+      ide_subprocess_launcher_insert_argv (launcher, i++, "podman");
+      ide_subprocess_launcher_insert_argv (launcher, i++, "exec");
+      ide_subprocess_launcher_insert_argv (launcher, i++, "--privileged");
+
+      if (ide_subprocess_launcher_get_needs_tty (launcher))
+        ide_subprocess_launcher_insert_argv (launcher, i++, "--tty");
+
+      if ((cwd = ide_subprocess_launcher_get_cwd (launcher)))
+        {
+          ide_subprocess_launcher_insert_argv (launcher, i++, "--workdir");
+          ide_subprocess_launcher_insert_argv (launcher, i++, cwd);
+        }
+
+      if (!ide_subprocess_launcher_get_clear_env (launcher))
+        {
+          copy_envvar (launcher, i++, "COLORTERM");
+          copy_envvar (launcher, i++, "DBUS_SESSION_BUS_ADDRESS");
+          copy_envvar (launcher, i++, "DESKTOP_SESSION");
+          copy_envvar (launcher, i++, "DISPLAY");
+          copy_envvar (launcher, i++, "LANG");
+          copy_envvar (launcher, i++, "SSH_AUTH_SOCK");
+          copy_envvar (launcher, i++, "WAYLAND_DISPLAY");
+          copy_envvar (launcher, i++, "XDG_CURRENT_DESKTOP");
+          copy_envvar (launcher, i++, "XDG_SEAT");
+          copy_envvar (launcher, i++, "XDG_SESSION_DESKTOP");
+          copy_envvar (launcher, i++, "XDG_SESSION_ID");
+          copy_envvar (launcher, i++, "XDG_SESSION_TYPE");
+          copy_envvar (launcher, i++, "XDG_VTNR");
+        }
+
+      if ((environ = ide_subprocess_launcher_get_environ (launcher)))
+        {
+          for (guint j = 0; environ[j]; j++)
+            {
+              ide_subprocess_launcher_insert_argv (launcher, i++, "--env");
+              ide_subprocess_launcher_insert_argv (launcher, i++, environ[j]);
+            }
+
+          ide_subprocess_launcher_set_environ (launcher, NULL);
+        }
+
+      ide_subprocess_launcher_insert_argv (launcher, i++, self->id);
+    }
+
+  return IDE_SUBPROCESS_LAUNCHER_CLASS (gbp_podman_subprocess_launcher_parent_class)->spawn (launcher, 
cancellable, error);
+}
+
+static void
+gbp_podman_subprocess_launcher_finalize (GObject *object)
+{
+  GbpPodmanSubprocessLauncher *self = (GbpPodmanSubprocessLauncher *)object;
+
+  g_clear_pointer (&self->id, g_free);
+
+  G_OBJECT_CLASS (gbp_podman_subprocess_launcher_parent_class)->finalize (object);
+}
+
+static void
+gbp_podman_subprocess_launcher_get_property (GObject    *object,
+                                             guint       prop_id,
+                                             GValue     *value,
+                                             GParamSpec *pspec)
+{
+  GbpPodmanSubprocessLauncher *self = GBP_PODMAN_SUBPROCESS_LAUNCHER (object);
+
+  switch (prop_id)
+    {
+    case PROP_ID:
+      g_value_set_string (value, self->id);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_podman_subprocess_launcher_set_property (GObject      *object,
+                                             guint         prop_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec)
+{
+  GbpPodmanSubprocessLauncher *self = GBP_PODMAN_SUBPROCESS_LAUNCHER (object);
+
+  switch (prop_id)
+    {
+    case PROP_ID:
+      self->id = g_value_dup_string (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_podman_subprocess_launcher_class_init (GbpPodmanSubprocessLauncherClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeSubprocessLauncherClass *launcher_class = IDE_SUBPROCESS_LAUNCHER_CLASS (klass);
+
+  object_class->finalize = gbp_podman_subprocess_launcher_finalize;
+  object_class->get_property = gbp_podman_subprocess_launcher_get_property;
+  object_class->set_property = gbp_podman_subprocess_launcher_set_property;
+
+  launcher_class->spawn = gbp_podman_subprocess_launcher_spawn;
+
+  properties [PROP_ID] =
+    g_param_spec_string ("id",
+                         "Id",
+                         "The identifier for the podman runtime",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_podman_subprocess_launcher_init (GbpPodmanSubprocessLauncher *self)
+{
+  ide_subprocess_launcher_set_run_on_host (IDE_SUBPROCESS_LAUNCHER (self), TRUE);
+}
diff --git a/src/plugins/podman/gbp-podman-subprocess-launcher.h 
b/src/plugins/podman/gbp-podman-subprocess-launcher.h
new file mode 100644
index 000000000..16ea62518
--- /dev/null
+++ b/src/plugins/podman/gbp-podman-subprocess-launcher.h
@@ -0,0 +1,31 @@
+/* gbp-podman-subprocess-launcher.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-threading.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PODMAN_SUBPROCESS_LAUNCHER (gbp_podman_subprocess_launcher_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPodmanSubprocessLauncher, gbp_podman_subprocess_launcher, GBP, 
PODMAN_SUBPROCESS_LAUNCHER, IdeSubprocessLauncher)
+
+G_END_DECLS
diff --git a/src/plugins/podman/meson.build b/src/plugins/podman/meson.build
new file mode 100644
index 000000000..b1a589444
--- /dev/null
+++ b/src/plugins/podman/meson.build
@@ -0,0 +1,18 @@
+if get_option('plugin_podman')
+
+plugins_sources += files([
+  'podman-plugin.c',
+  'gbp-podman-runtime.c',
+  'gbp-podman-runtime-provider.c',
+  'gbp-podman-subprocess-launcher.c',
+])
+
+plugin_podman_resources = gnome.compile_resources(
+  'podman-resources',
+  'podman.gresource.xml',
+  c_name: 'gbp_podman'
+)
+
+plugins_sources += plugin_podman_resources[0]
+
+endif
diff --git a/src/plugins/podman/podman-plugin.c b/src/plugins/podman/podman-plugin.c
new file mode 100644
index 000000000..e179e14d3
--- /dev/null
+++ b/src/plugins/podman/podman-plugin.c
@@ -0,0 +1,36 @@
+/* podman-plugin.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "podman-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-foundry.h>
+
+#include "gbp-podman-runtime-provider.h"
+
+_IDE_EXTERN void
+_gbp_podman_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_RUNTIME_PROVIDER,
+                                              GBP_TYPE_PODMAN_RUNTIME_PROVIDER);
+}
diff --git a/src/plugins/podman/podman.gresource.xml b/src/plugins/podman/podman.gresource.xml
new file mode 100644
index 000000000..313995da3
--- /dev/null
+++ b/src/plugins/podman/podman.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/podman">
+    <file>podman.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/podman/podman.plugin b/src/plugins/podman/podman.plugin
new file mode 100644
index 000000000..979feaa05
--- /dev/null
+++ b/src/plugins/podman/podman.plugin
@@ -0,0 +1,10 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2019 Christian Hergert
+Depends=buildui;
+Description=Provides support for podman containers
+Embedded=_gbp_podman_register_types
+Hidden=true
+Module=podman
+Name=Podman


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]