[gnome-builder/wip/greeter] miner: mine .doap from autotools projects



commit f47026e9fffc47ee187b4c32b96c9086c6501075
Author: Christian Hergert <christian hergert me>
Date:   Sun May 10 01:24:25 2015 -0700

    miner: mine .doap from autotools projects

 libide/autotools/ide-autotools-project-miner.c |   59 ++++++++++++++++++++++++
 libide/ide-project-info.c                      |   37 +++++++++++++++
 2 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/libide/autotools/ide-autotools-project-miner.c b/libide/autotools/ide-autotools-project-miner.c
index 9630349..97ccf36 100644
--- a/libide/autotools/ide-autotools-project-miner.c
+++ b/libide/autotools/ide-autotools-project-miner.c
@@ -22,6 +22,8 @@
 
 #include "ide-autotools-project-miner.h"
 #include "ide-debug.h"
+#include "ide-doap.h"
+#include "ide-macros.h"
 
 #define MAX_MINE_DEPTH 5
 
@@ -41,6 +43,48 @@ enum {
 
 static GParamSpec *gParamSpecs [LAST_PROP];
 
+static IdeDoap *
+ide_autotools_project_miner_find_doap (IdeAutotoolsProjectMiner *self,
+                                       GCancellable             *cancellable,
+                                       GFile                    *directory)
+{
+  g_autoptr(GFileEnumerator) enumerator = NULL;
+  GFileInfo *file_info = NULL;
+
+  g_assert (IDE_IS_AUTOTOOLS_PROJECT_MINER (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_assert (G_IS_FILE (directory));
+
+  enumerator = g_file_enumerate_children (directory,
+                                          G_FILE_ATTRIBUTE_STANDARD_NAME,
+                                          G_FILE_QUERY_INFO_NONE,
+                                          cancellable,
+                                          NULL);
+  if (!enumerator)
+    return NULL;
+
+  while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, NULL)))
+    {
+      const gchar *name = g_file_info_get_name (file_info);
+
+      if (name != NULL && g_str_has_suffix (name, ".doap"))
+        {
+          g_autoptr(GFile) doap_file = g_file_get_child (directory, name);
+          IdeDoap *doap = doap = ide_doap_new ();
+
+          if (!ide_doap_load_from_file (doap, doap_file, cancellable, NULL))
+            {
+              g_object_unref (doap);
+              continue;
+            }
+
+          return doap;
+        }
+    }
+
+  return NULL;
+}
+
 static void
 ide_autotools_project_miner_discovered (IdeAutotoolsProjectMiner *self,
                                         GCancellable             *cancellable,
@@ -54,6 +98,7 @@ ide_autotools_project_miner_discovered (IdeAutotoolsProjectMiner *self,
   g_autoptr(GFileInfo) index_info = NULL;
   g_autoptr(IdeProjectInfo) project_info = NULL;
   g_autoptr(GDateTime) last_modified_at = NULL;
+  g_autoptr(IdeDoap) doap = NULL;
   const gchar *filename;
   guint64 mtime;
 
@@ -68,6 +113,8 @@ ide_autotools_project_miner_discovered (IdeAutotoolsProjectMiner *self,
 
   mtime = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
+  doap = ide_autotools_project_miner_find_doap (self, cancellable, directory);
+
   /*
    * If there is a git repo, trust the .git/index file for time info,
    * it is more reliable than our directory mtime.
@@ -87,8 +134,20 @@ ide_autotools_project_miner_discovered (IdeAutotoolsProjectMiner *self,
   file = g_file_get_child (directory, filename);
   name = g_file_get_basename (directory);
 
+  if (doap != NULL)
+    {
+      const gchar *doap_name = ide_doap_get_name (doap);
+
+      if (!ide_str_empty0 (doap_name))
+        {
+          g_free (name);
+          name = g_strdup (doap_name);
+        }
+    }
+
   project_info = g_object_new (IDE_TYPE_PROJECT_INFO,
                                "directory", directory,
+                               "doap", doap,
                                "file", file,
                                "last-modified-at", last_modified_at,
                                "name", name,
diff --git a/libide/ide-project-info.c b/libide/ide-project-info.c
index 7f2da77..647fbd0 100644
--- a/libide/ide-project-info.c
+++ b/libide/ide-project-info.c
@@ -25,6 +25,7 @@
 #include <glib/gi18n.h>
 #include <string.h>
 
+#include "ide-doap.h"
 #include "ide-project-info.h"
 
 /**
@@ -40,6 +41,7 @@ struct _IdeProjectInfo
 {
   GObject    parent_instance;
 
+  IdeDoap   *doap;
   GDateTime *last_modified_at;
   GFile     *directory;
   GFile     *file;
@@ -55,6 +57,7 @@ G_DEFINE_TYPE (IdeProjectInfo, ide_project_info, G_TYPE_OBJECT)
 enum {
   PROP_0,
   PROP_DIRECTORY,
+  PROP_DOAP,
   PROP_FILE,
   PROP_IS_RECENT,
   PROP_LAST_MODIFIED_AT,
@@ -65,6 +68,25 @@ enum {
 
 static GParamSpec *gParamSpecs [LAST_PROP];
 
+IdeDoap *
+ide_project_info_get_doap (IdeProjectInfo *self)
+{
+  g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
+
+  return self->doap;
+}
+
+void
+ide_project_info_set_doap (IdeProjectInfo *self,
+                           IdeDoap        *doap)
+{
+  g_return_if_fail (IDE_IS_PROJECT_INFO (self));
+  g_return_if_fail (!doap || IDE_IS_DOAP (doap));
+
+  if (g_set_object (&self->doap, doap))
+    g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DOAP]);
+}
+
 gint
 ide_project_info_get_priority (IdeProjectInfo *self)
 {
@@ -242,6 +264,10 @@ ide_project_info_get_property (GObject    *object,
       g_value_set_object (value, ide_project_info_get_directory (self));
       break;
 
+    case PROP_DOAP:
+      g_value_set_object (value, ide_project_info_get_doap (self));
+      break;
+
     case PROP_FILE:
       g_value_set_object (value, ide_project_info_get_file (self));
       break;
@@ -281,6 +307,10 @@ ide_project_info_set_property (GObject      *object,
       ide_project_info_set_directory (self, g_value_get_object (value));
       break;
 
+    case PROP_DOAP:
+      ide_project_info_set_doap (self, g_value_get_object (value));
+      break;
+
     case PROP_FILE:
       ide_project_info_set_file (self, g_value_get_object (value));
       break;
@@ -329,6 +359,13 @@ ide_project_info_class_init (IdeProjectInfoClass *klass)
                          G_TYPE_FILE,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  gParamSpecs [PROP_DOAP] =
+    g_param_spec_object ("doap",
+                         _("Doap"),
+                         _("A DOAP describing the project."),
+                         IDE_TYPE_DOAP,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   gParamSpecs [PROP_FILE] =
     g_param_spec_object ("file",
                          _("File"),


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