[gnome-builder: 44/139] editorconfig: move editorconfig code to a plugin



commit 8957927e7f558a39e776b24d610d2b41f4fd6bf8
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 16:28:57 2019 -0800

    editorconfig: move editorconfig code to a plugin

 src/libide/editorconfig/OVERVIEW.md                |  9 ----
 src/libide/editorconfig/editorconfig-glib.h        | 17 -------
 .../editorconfig/editorconfig-glib.c               |  8 +++-
 src/plugins/editorconfig/editorconfig-glib.h       | 31 +++++++++++++
 src/plugins/editorconfig/editorconfig-plugin.c     | 37 +++++++++++++++
 .../editorconfig/editorconfig.gresource.xml        |  6 +++
 src/plugins/editorconfig/editorconfig.plugin       |  9 ++++
 .../editorconfig/gbp-editorconfig-file-settings.c} | 53 ++++++++++------------
 .../editorconfig/gbp-editorconfig-file-settings.h} | 11 ++---
 src/plugins/editorconfig/meson.build               | 20 ++++++++
 10 files changed, 136 insertions(+), 65 deletions(-)
---
diff --git a/src/libide/editorconfig/editorconfig-glib.c b/src/plugins/editorconfig/editorconfig-glib.c
similarity index 96%
rename from src/libide/editorconfig/editorconfig-glib.c
rename to src/plugins/editorconfig/editorconfig-glib.c
index 7a2ca5b2e..c12f1605a 100644
--- a/src/libide/editorconfig/editorconfig-glib.c
+++ b/src/plugins/editorconfig/editorconfig-glib.c
@@ -18,9 +18,13 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include <editorconfig/editorconfig.h>
+#define G_LOG_DOMAIN "editorconfig-glib"
 
-#include "editorconfig/editorconfig-glib.h"
+#include "config.h"
+
+#include <editorconfig.h>
+
+#include "editorconfig-glib.h"
 
 static void
 _g_value_free (gpointer data)
diff --git a/src/plugins/editorconfig/editorconfig-glib.h b/src/plugins/editorconfig/editorconfig-glib.h
new file mode 100644
index 000000000..f4ce075e7
--- /dev/null
+++ b/src/plugins/editorconfig/editorconfig-glib.h
@@ -0,0 +1,31 @@
+/* editorconfig-glib.h
+ *
+ * Copyright 2018-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 <gio/gio.h>
+
+G_BEGIN_DECLS
+
+GHashTable *editorconfig_glib_read (GFile         *file,
+                                    GCancellable  *cancellable,
+                                    GError       **error);
+
+G_BEGIN_DECLS
diff --git a/src/plugins/editorconfig/editorconfig-plugin.c b/src/plugins/editorconfig/editorconfig-plugin.c
new file mode 100644
index 000000000..0b55b1881
--- /dev/null
+++ b/src/plugins/editorconfig/editorconfig-plugin.c
@@ -0,0 +1,37 @@
+/* editorconfig-plugin.c
+ *
+ * Copyright 2018-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 "editorconfig-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-code.h>
+
+#include "gbp-editorconfig-file-settings.h"
+
+_IDE_EXTERN void
+_gbp_editorconfig_register_types (PeasObjectModule *module)
+{
+  g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
+                                  GBP_TYPE_EDITORCONFIG_FILE_SETTINGS,
+                                  IDE_FILE_SETTINGS_EXTENSION_POINT".editorconfig",
+                                  -200);
+}
diff --git a/src/plugins/editorconfig/editorconfig.gresource.xml 
b/src/plugins/editorconfig/editorconfig.gresource.xml
new file mode 100644
index 000000000..efa19b0c2
--- /dev/null
+++ b/src/plugins/editorconfig/editorconfig.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/editorconfig">
+    <file>editorconfig.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/editorconfig/editorconfig.plugin b/src/plugins/editorconfig/editorconfig.plugin
new file mode 100644
index 000000000..3bb96bde9
--- /dev/null
+++ b/src/plugins/editorconfig/editorconfig.plugin
@@ -0,0 +1,9 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2014-2018 Christian Hergert
+Depends=editor;
+Description=Editorconfig integration
+Embedded=_gbp_editorconfig_register_types
+Module=editorconfig
+Name=Editorconfig
diff --git a/src/libide/editorconfig/ide-editorconfig-file-settings.c 
b/src/plugins/editorconfig/gbp-editorconfig-file-settings.c
similarity index 78%
rename from src/libide/editorconfig/ide-editorconfig-file-settings.c
rename to src/plugins/editorconfig/gbp-editorconfig-file-settings.c
index 7073017dd..eecd43b42 100644
--- a/src/libide/editorconfig/ide-editorconfig-file-settings.c
+++ b/src/plugins/editorconfig/gbp-editorconfig-file-settings.c
@@ -1,4 +1,4 @@
-/* ide-editorconfig-file-settings.c
+/* gbp-editorconfig-file-settings.c
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -18,45 +18,42 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "editorconfig"
+#define G_LOG_DOMAIN "gbp-editorconfig-file-settings"
 
 #include "config.h"
 
-#include "editorconfig/editorconfig-glib.h"
 #include <glib/gi18n.h>
+#include <libide-threading.h>
 
-#include "ide-debug.h"
+#include "editorconfig-glib.h"
+#include "gbp-editorconfig-file-settings.h"
 
-#include "editorconfig/ide-editorconfig-file-settings.h"
-#include "files/ide-file.h"
-#include "threading/ide-task.h"
-
-struct _IdeEditorconfigFileSettings
+struct _GbpEditorconfigFileSettings
 {
   IdeFileSettings parent_instance;
 };
 
 static void async_initable_iface_init (GAsyncInitableIface *iface);
 
-G_DEFINE_TYPE_EXTENDED (IdeEditorconfigFileSettings,
-                        ide_editorconfig_file_settings,
+G_DEFINE_TYPE_EXTENDED (GbpEditorconfigFileSettings,
+                        gbp_editorconfig_file_settings,
                         IDE_TYPE_FILE_SETTINGS,
                         0,
                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
                                                async_initable_iface_init))
 
 static void
-ide_editorconfig_file_settings_class_init (IdeEditorconfigFileSettingsClass *klass)
+gbp_editorconfig_file_settings_class_init (GbpEditorconfigFileSettingsClass *klass)
 {
 }
 
 static void
-ide_editorconfig_file_settings_init (IdeEditorconfigFileSettings *self)
+gbp_editorconfig_file_settings_init (GbpEditorconfigFileSettings *self)
 {
 }
 
 static void
-ide_editorconfig_file_settings_init_worker (IdeTask      *task,
+gbp_editorconfig_file_settings_init_worker (IdeTask      *task,
                                             gpointer      source_object,
                                             gpointer      task_data,
                                             GCancellable *cancellable)
@@ -68,7 +65,7 @@ ide_editorconfig_file_settings_init_worker (IdeTask      *task,
   gpointer k, v;
 
   g_assert (IDE_IS_TASK (task));
-  g_assert (IDE_IS_EDITORCONFIG_FILE_SETTINGS (source_object));
+  g_assert (GBP_IS_EDITORCONFIG_FILE_SETTINGS (source_object));
   g_assert (G_IS_FILE (file));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
@@ -134,29 +131,25 @@ ide_editorconfig_file_settings_init_worker (IdeTask      *task,
 }
 
 static void
-ide_editorconfig_file_settings_init_async (GAsyncInitable      *initable,
+gbp_editorconfig_file_settings_init_async (GAsyncInitable      *initable,
                                            gint                 io_priority,
                                            GCancellable        *cancellable,
                                            GAsyncReadyCallback  callback,
                                            gpointer             user_data)
 {
-  IdeEditorconfigFileSettings *self = (IdeEditorconfigFileSettings *)initable;
+  GbpEditorconfigFileSettings *self = (GbpEditorconfigFileSettings *)initable;
   g_autoptr(IdeTask) task = NULL;
-  IdeFile *file;
-  GFile *gfile = NULL;
+  GFile *file;
 
   IDE_ENTRY;
 
-  g_return_if_fail (IDE_IS_EDITORCONFIG_FILE_SETTINGS (self));
+  g_return_if_fail (GBP_IS_EDITORCONFIG_FILE_SETTINGS (self));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, gbp_editorconfig_file_settings_init_async);
 
-  file = ide_file_settings_get_file (IDE_FILE_SETTINGS (self));
-  if (file)
-    gfile = ide_file_get_file (file);
-
-  if (!gfile)
+  if (!(file = ide_file_settings_get_file (IDE_FILE_SETTINGS (self))))
     {
       ide_task_return_new_error (task,
                                  G_IO_ERROR,
@@ -165,14 +158,14 @@ ide_editorconfig_file_settings_init_async (GAsyncInitable      *initable,
       IDE_EXIT;
     }
 
-  ide_task_set_task_data (task, g_object_ref (gfile), g_object_unref);
-  ide_task_run_in_thread (task, ide_editorconfig_file_settings_init_worker);
+  ide_task_set_task_data (task, g_object_ref (file), g_object_unref);
+  ide_task_run_in_thread (task, gbp_editorconfig_file_settings_init_worker);
 
   IDE_EXIT;
 }
 
 static gboolean
-ide_editorconfig_file_settings_init_finish (GAsyncInitable  *initable,
+gbp_editorconfig_file_settings_init_finish (GAsyncInitable  *initable,
                                             GAsyncResult    *result,
                                             GError         **error)
 {
@@ -190,6 +183,6 @@ ide_editorconfig_file_settings_init_finish (GAsyncInitable  *initable,
 static void
 async_initable_iface_init (GAsyncInitableIface *iface)
 {
-  iface->init_async = ide_editorconfig_file_settings_init_async;
-  iface->init_finish = ide_editorconfig_file_settings_init_finish;
+  iface->init_async = gbp_editorconfig_file_settings_init_async;
+  iface->init_finish = gbp_editorconfig_file_settings_init_finish;
 }
diff --git a/src/libide/editorconfig/ide-editorconfig-file-settings.h 
b/src/plugins/editorconfig/gbp-editorconfig-file-settings.h
similarity index 72%
rename from src/libide/editorconfig/ide-editorconfig-file-settings.h
rename to src/plugins/editorconfig/gbp-editorconfig-file-settings.h
index 99192ed5f..43bc76cdd 100644
--- a/src/libide/editorconfig/ide-editorconfig-file-settings.h
+++ b/src/plugins/editorconfig/gbp-editorconfig-file-settings.h
@@ -1,4 +1,4 @@
-/* ide-editorconfig-file-settings.h
+/* gbp-editorconfig-file-settings.h
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -20,15 +20,12 @@
 
 #pragma once
 
-#include "ide-version-macros.h"
-
-#include "files/ide-file-settings.h"
+#include <libide-code.h>
 
 G_BEGIN_DECLS
 
-#define IDE_TYPE_EDITORCONFIG_FILE_SETTINGS (ide_editorconfig_file_settings_get_type())
+#define GBP_TYPE_EDITORCONFIG_FILE_SETTINGS (gbp_editorconfig_file_settings_get_type())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_FINAL_TYPE (IdeEditorconfigFileSettings, ide_editorconfig_file_settings, IDE, 
EDITORCONFIG_FILE_SETTINGS, IdeFileSettings)
+G_DECLARE_FINAL_TYPE (GbpEditorconfigFileSettings, gbp_editorconfig_file_settings, GBP, 
EDITORCONFIG_FILE_SETTINGS, IdeFileSettings)
 
 G_END_DECLS
diff --git a/src/plugins/editorconfig/meson.build b/src/plugins/editorconfig/meson.build
new file mode 100644
index 000000000..8cbf269d1
--- /dev/null
+++ b/src/plugins/editorconfig/meson.build
@@ -0,0 +1,20 @@
+if get_option('plugin_editorconfig')
+
+subdir('libeditorconfig')
+
+plugins_sources += files([
+  'editorconfig-glib.c',
+  'editorconfig-plugin.c',
+  'gbp-editorconfig-file-settings.c',
+])
+
+plugin_editorconfig_resources = gnome.compile_resources(
+  'gbp-editorconfig-resources',
+  'editorconfig.gresource.xml',
+  c_name: 'gbp_editorconfig',
+)
+
+plugins_sources += plugin_editorconfig_resources[0]
+plugins_deps += libeditorconfig_dep
+
+endif


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