[gnome-builder] dep-updater: add new interface for updating dependencies



commit e22aa0a4378fb58569589ebeceaeb4e22833b78a
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 16 17:55:00 2017 -0800

    dep-updater: add new interface for updating dependencies
    
    This gives us an interface that plugins can implement to update
    dependencies. The omnibar will activate this command instead of
    the flatpak-specific backend.
    
    This should allow plugins for other languages such as NodeJS or
    Pip to provide an updater in a similar fashion.

 src/libide/buildsystem/ide-dependency-updater.c |   79 +++++++++++++++++++++++
 src/libide/buildsystem/ide-dependency-updater.h |   50 ++++++++++++++
 src/libide/buildsystem/meson.build              |    2 +
 src/libide/ide.h                                |    1 +
 src/libide/workbench/ide-omni-bar.ui            |    2 +-
 src/libide/workbench/ide-workbench-actions.c    |   69 ++++++++++++++++++++
 6 files changed, 202 insertions(+), 1 deletions(-)
---
diff --git a/src/libide/buildsystem/ide-dependency-updater.c b/src/libide/buildsystem/ide-dependency-updater.c
new file mode 100644
index 0000000..34a8923
--- /dev/null
+++ b/src/libide/buildsystem/ide-dependency-updater.c
@@ -0,0 +1,79 @@
+/* ide-dependency-updater.c
+ *
+ * Copyright © 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "ide-dependency-updater"
+
+#include "ide-dependency-updater.h"
+
+G_DEFINE_INTERFACE (IdeDependencyUpdater, ide_dependency_updater, IDE_TYPE_OBJECT)
+
+static void
+ide_dependency_updater_real_update_async (IdeDependencyUpdater *self,
+                                          GCancellable         *cancellable,
+                                          GAsyncReadyCallback   callback,
+                                          gpointer              user_data)
+{
+  g_task_report_new_error (self,
+                           callback,
+                           user_data,
+                           ide_dependency_updater_real_update_async,
+                           G_IO_ERROR,
+                           G_IO_ERROR_NOT_SUPPORTED,
+                           "update_async is not supported");
+}
+
+static gboolean
+ide_dependency_updater_real_update_finish (IdeDependencyUpdater  *self,
+                                           GAsyncResult          *result,
+                                           GError               **error)
+{
+  g_assert (IDE_IS_DEPENDENCY_UPDATER (self));
+  g_assert (G_IS_TASK (result));
+
+  return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+static void
+ide_dependency_updater_default_init (IdeDependencyUpdaterInterface *iface)
+{
+  iface->update_async = ide_dependency_updater_real_update_async;
+  iface->update_finish = ide_dependency_updater_real_update_finish;
+}
+
+void
+ide_dependency_updater_update_async (IdeDependencyUpdater *self,
+                                     GCancellable         *cancellable,
+                                     GAsyncReadyCallback   callback,
+                                     gpointer              user_data)
+{
+  g_return_if_fail (IDE_IS_DEPENDENCY_UPDATER (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  IDE_DEPENDENCY_UPDATER_GET_IFACE (self)->update_async (self, cancellable, callback, user_data);
+}
+
+gboolean
+ide_dependency_updater_update_finish (IdeDependencyUpdater  *self,
+                                      GAsyncResult          *result,
+                                      GError               **error)
+{
+  g_return_val_if_fail (IDE_IS_DEPENDENCY_UPDATER (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+  return IDE_DEPENDENCY_UPDATER_GET_IFACE (self)->update_finish (self, result, error);
+}
diff --git a/src/libide/buildsystem/ide-dependency-updater.h b/src/libide/buildsystem/ide-dependency-updater.h
new file mode 100644
index 0000000..3d2987a
--- /dev/null
+++ b/src/libide/buildsystem/ide-dependency-updater.h
@@ -0,0 +1,50 @@
+/* ide-dependency-updater.h
+ *
+ * Copyright © 2017 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/>.
+ */
+
+#pragma once
+
+#include "ide-object.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_DEPENDENCY_UPDATER (ide_dependency_updater_get_type ())
+
+G_DECLARE_INTERFACE (IdeDependencyUpdater, ide_dependency_updater, IDE, DEPENDENCY_UPDATER, IdeObject)
+
+struct _IdeDependencyUpdaterInterface
+{
+  GTypeInterface parent;
+
+  void     (*update_async)  (IdeDependencyUpdater  *self,
+                             GCancellable          *cancellable,
+                             GAsyncReadyCallback    callback,
+                             gpointer               user_data);
+  gboolean (*update_finish) (IdeDependencyUpdater  *self,
+                             GAsyncResult          *result,
+                             GError               **error);
+};
+
+void     ide_dependency_updater_update_async  (IdeDependencyUpdater  *self,
+                                               GCancellable          *cancellable,
+                                               GAsyncReadyCallback    callback,
+                                               gpointer               user_data);
+gboolean ide_dependency_updater_update_finish (IdeDependencyUpdater  *self,
+                                               GAsyncResult          *result,
+                                               GError               **error);
+
+G_END_DECLS
diff --git a/src/libide/buildsystem/meson.build b/src/libide/buildsystem/meson.build
index de193b4..7abf129 100644
--- a/src/libide/buildsystem/meson.build
+++ b/src/libide/buildsystem/meson.build
@@ -16,6 +16,7 @@ buildsystem_headers = [
   'ide-configuration-manager.h',
   'ide-configuration-provider.h',
   'ide-configuration.h',
+  'ide-dependency-updater.h',
   'ide-environment-variable.h',
   'ide-environment.h',
 ]
@@ -37,6 +38,7 @@ buildsystem_sources = [
   'ide-configuration-manager.c',
   'ide-configuration-provider.c',
   'ide-configuration.c',
+  'ide-dependency-updater.c',
   'ide-environment-variable.c',
   'ide-environment.c',
 ]
diff --git a/src/libide/ide.h b/src/libide/ide.h
index 211f997..37a320a 100644
--- a/src/libide/ide.h
+++ b/src/libide/ide.h
@@ -62,6 +62,7 @@ G_BEGIN_DECLS
 #include "buildsystem/ide-configuration-manager.h"
 #include "buildsystem/ide-configuration.h"
 #include "buildsystem/ide-configuration-provider.h"
+#include "buildsystem/ide-dependency-updater.h"
 #include "buildsystem/ide-environment-variable.h"
 #include "buildsystem/ide-environment.h"
 #include "debugger/ide-debug-manager.h"
diff --git a/src/libide/workbench/ide-omni-bar.ui b/src/libide/workbench/ide-omni-bar.ui
index a882400..3a0fcb3 100644
--- a/src/libide/workbench/ide-omni-bar.ui
+++ b/src/libide/workbench/ide-omni-bar.ui
@@ -194,7 +194,7 @@
                       <object class="GtkButton">
                         <property name="focus-on-click">false</property>
                         <property name="valign">baseline</property>
-                        <property name="action-name">flatpak.update-dependencies</property>
+                        <property name="action-name">win.update-dependencies</property>
                         <property name="tooltip-text" translatable="yes">Update project 
dependencies</property>
                         <property name="visible">true</property>
                         <style>
diff --git a/src/libide/workbench/ide-workbench-actions.c b/src/libide/workbench/ide-workbench-actions.c
index 6cf2be5..01d134b 100644
--- a/src/libide/workbench/ide-workbench-actions.c
+++ b/src/libide/workbench/ide-workbench-actions.c
@@ -20,12 +20,15 @@
 
 #include <dazzle.h>
 #include <glib/gi18n.h>
+#include <libpeas/peas.h>
+#include <libpeas/peas-autocleanups.h>
 #include <unistd.h>
 
 #include "ide-debug.h"
 
 #include "application/ide-application.h"
 #include "buffers/ide-buffer-manager.h"
+#include "buildsystem/ide-dependency-updater.h"
 #include "vcs/ide-vcs.h"
 #include "workbench/ide-workbench.h"
 #include "workbench/ide-workbench-header-bar.h"
@@ -232,6 +235,71 @@ ide_workbench_actions_inspector (GSimpleAction *action,
   gtk_window_set_interactive_debugging (TRUE);
 }
 
+static void
+ide_workbench_actions_update_cb (GObject      *object,
+                                 GAsyncResult *result,
+                                 gpointer      user_data)
+{
+  IdeDependencyUpdater *updater = (IdeDependencyUpdater *)object;
+  g_autoptr(IdeWorkbench) self = user_data;
+  g_autoptr(GError) error = NULL;
+  IdeContext *context;
+
+  g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  context = ide_workbench_get_context (self);
+
+  if (!ide_dependency_updater_update_finish (updater, result, &error))
+    ide_context_warning (context, "%s", error->message);
+}
+
+static void
+ide_workbench_actions_update_dependencies_cb (PeasExtensionSet *set,
+                                              PeasPluginInfo   *plugin_info,
+                                              PeasExtension    *exten,
+                                              gpointer          user_data)
+{
+  IdeDependencyUpdater *updater = (IdeDependencyUpdater *)exten;
+  IdeWorkbench *self = user_data;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  ide_dependency_updater_update_async (updater,
+                                       NULL,
+                                       ide_workbench_actions_update_cb,
+                                       g_object_ref (self));
+}
+
+static void
+ide_workbench_actions_update_dependencies (GSimpleAction *action,
+                                           GVariant      *variant,
+                                           gpointer       user_data)
+{
+  g_autoptr(PeasExtensionSet) set = NULL;
+  IdeWorkbench *self = user_data;
+  IdeContext *context;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  context = ide_workbench_get_context (self);
+  if (context == NULL)
+    return;
+
+  set = peas_extension_set_new (peas_engine_get_default (),
+                                IDE_TYPE_DEPENDENCY_UPDATER,
+                                "context", context,
+                                NULL);
+  peas_extension_set_foreach (set,
+                              ide_workbench_actions_update_dependencies_cb,
+                              self);
+}
+
 void
 ide_workbench_actions_init (IdeWorkbench *self)
 {
@@ -244,6 +312,7 @@ ide_workbench_actions_init (IdeWorkbench *self)
     { "save-all-quit", ide_workbench_actions_save_all_quit },
     { "counters", ide_workbench_actions_counters },
     { "inspector", ide_workbench_actions_inspector },
+    { "update-dependencies", ide_workbench_actions_update_dependencies },
   };
 
   g_action_map_add_action_entries (G_ACTION_MAP (self), actions, G_N_ELEMENTS (actions), self);


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