diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | libappstream-builder/asb-app.c | 122 | ||||
-rw-r--r-- | libappstream-builder/asb-app.h | 11 | ||||
-rw-r--r-- | libappstream-builder/asb-plugin-loader.c | 17 | ||||
-rw-r--r-- | libappstream-builder/asb-self-test.c | 131 | ||||
-rw-r--r-- | libappstream-builder/asb-task.c | 12 | ||||
-rw-r--r-- | libappstream-builder/plugins/Makefile.am | 18 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-appdata.c | 358 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-blacklist.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-desktop.c | 124 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-firmware.c | 139 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-gstreamer.c | 101 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-hardcoded.c | 28 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-ibus-sql.c | 264 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-ibus-xml.c | 224 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-metainfo.c | 184 | ||||
-rw-r--r-- | libappstream-glib/as-app-validate.c | 8 |
17 files changed, 328 insertions, 1417 deletions
diff --git a/configure.ac b/configure.ac index e8e48a3..6e6f2be 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ AC_SUBST(AS_VERSION) # this refers to the plugin API version # this is not in any way related to a package or soname version -AS_PLUGIN_VERSION=2 +AS_PLUGIN_VERSION=3 AC_SUBST(AS_PLUGIN_VERSION) AC_DEFINE_UNQUOTED([AS_PLUGIN_VERSION], "$AS_PLUGIN_VERSION", [plugin API version]) diff --git a/libappstream-builder/asb-app.c b/libappstream-builder/asb-app.c index d2a59e4..69f8909 100644 --- a/libappstream-builder/asb-app.c +++ b/libappstream-builder/asb-app.c @@ -88,84 +88,50 @@ asb_app_class_init (AsbAppClass *klass) } /** - * asb_app_add_requires_appdata: + * asb_app_get_package: * @app: A #AsbApp - * @fmt: format string - * @...: varargs - * - * Adds a reason that AppData is required. * - * Since: 0.1.0 - **/ -void -asb_app_add_requires_appdata (AsbApp *app, const gchar *fmt, ...) -{ - AsbAppPrivate *priv = GET_PRIVATE (app); - gchar *tmp; - va_list args; - if (priv->ignore_requires_appdata) - return; - va_start (args, fmt); - tmp = g_strdup_vprintf (fmt, args); - va_end (args); - g_ptr_array_add (priv->requires_appdata, tmp); -} - -/** - * asb_app_set_requires_appdata: - * @app: A #AsbApp - * @requires_appdata: boolean + * Gets the package that backs the application. * - * Sets (or clears) the requirement for AppData. + * Returns: (transfer none): package * * Since: 0.1.0 **/ -void -asb_app_set_requires_appdata (AsbApp *app, gboolean requires_appdata) +AsbPackage * +asb_app_get_package (AsbApp *app) { AsbAppPrivate *priv = GET_PRIVATE (app); - if (requires_appdata) { - if (priv->ignore_requires_appdata) - return; - g_ptr_array_add (priv->requires_appdata, NULL); - } else { - g_ptr_array_set_size (priv->requires_appdata, 0); - priv->ignore_requires_appdata = TRUE; - } + return priv->pkg; } /** - * asb_app_get_requires_appdata: + * asb_app_set_package: * @app: A #AsbApp + * @pkg: A #AsbPackage * - * Gets if AppData is still required for the application. - * - * Returns: (transfer none) (element-type utf8): A list of reasons + * Sets the package that backs the application. * - * Since: 0.1.0 + * Since: 0.5.1 **/ -GPtrArray * -asb_app_get_requires_appdata (AsbApp *app) +void +asb_app_set_package (AsbApp *app, AsbPackage *pkg) { AsbAppPrivate *priv = GET_PRIVATE (app); - return priv->requires_appdata; -} -/** - * asb_app_get_package: - * @app: A #AsbApp - * - * Gets the package that backs the application. - * - * Returns: (transfer none): package - * - * Since: 0.1.0 - **/ -AsbPackage * -asb_app_get_package (AsbApp *app) -{ - AsbAppPrivate *priv = GET_PRIVATE (app); - return priv->pkg; + if (priv->pkg != NULL) + g_object_unref (priv->pkg); + priv->pkg = g_object_ref (pkg); + + /* be helpful */ + if (asb_package_get_kind (pkg) == ASB_PACKAGE_KIND_DEFAULT) { + as_app_add_pkgname (AS_APP (app), asb_package_get_name (pkg)); + } else if (asb_package_get_kind (pkg) == ASB_PACKAGE_KIND_BUNDLE) { + g_autoptr(AsBundle) bundle = NULL; + bundle = as_bundle_new (); + as_bundle_set_id (bundle, asb_package_get_source (pkg)); + as_bundle_set_kind (bundle, AS_BUNDLE_KIND_XDG_APP); + as_app_add_bundle (AS_APP (app), bundle); + } } /** @@ -215,7 +181,8 @@ asb_app_save_resources (AsbApp *app, AsbAppSaveFlags save_flags, GError **error) /* don't save some types of icons */ icon = g_ptr_array_index (icons, i); - if (as_icon_get_kind (icon) == AS_ICON_KIND_STOCK || + if (as_icon_get_kind (icon) == AS_ICON_KIND_UNKNOWN || + as_icon_get_kind (icon) == AS_ICON_KIND_STOCK || as_icon_get_kind (icon) == AS_ICON_KIND_EMBEDDED || as_icon_get_kind (icon) == AS_ICON_KIND_LOCAL || as_icon_get_kind (icon) == AS_ICON_KIND_REMOTE) @@ -231,8 +198,9 @@ asb_app_save_resources (AsbApp *app, AsbAppSaveFlags save_flags, GError **error) g_set_error (error, AS_APP_ERROR, AS_APP_ERROR_FAILED, - "No pixbuf for %s", - as_icon_get_name (icon)); + "No pixbuf for %s in %s", + as_icon_get_name (icon), + as_app_get_id (AS_APP (app))); return FALSE; } if (!gdk_pixbuf_save (pixbuf, filename, "png", error, NULL)) @@ -248,8 +216,8 @@ asb_app_save_resources (AsbApp *app, AsbAppSaveFlags save_flags, GError **error) /** * asb_app_new: - * @pkg: A #AsbPackage - * @id: The ID for the package + * @pkg: A #AsbPackage, or %NULL + * @id: The ID for the package, or %NULL * * Creates a new application object. * @@ -261,29 +229,9 @@ AsbApp * asb_app_new (AsbPackage *pkg, const gchar *id) { AsbApp *app; - AsbAppPrivate *priv; - app = g_object_new (ASB_TYPE_APP, NULL); - priv = GET_PRIVATE (app); - if (pkg != NULL) { - priv->pkg = g_object_ref (pkg); - switch (asb_package_get_kind (pkg)) { - case ASB_PACKAGE_KIND_DEFAULT: - as_app_add_pkgname (AS_APP (app), - asb_package_get_name (pkg)); - break; - case ASB_PACKAGE_KIND_BUNDLE: - { - g_autoptr(AsBundle) bundle = NULL; - bundle = as_bundle_new (); - as_bundle_set_id (bundle, asb_package_get_source (pkg)); - as_bundle_set_kind (bundle, AS_BUNDLE_KIND_XDG_APP); - as_app_add_bundle (AS_APP (app), bundle); - }; - default: - break; - } - } + if (pkg != NULL) + asb_app_set_package (app, pkg); if (id != NULL) as_app_set_id (AS_APP (app), id); return ASB_APP (app); diff --git a/libappstream-builder/asb-app.h b/libappstream-builder/asb-app.h index 0abf4bf..c575195 100644 --- a/libappstream-builder/asb-app.h +++ b/libappstream-builder/asb-app.h @@ -68,16 +68,9 @@ AsbApp *asb_app_new (AsbPackage *pkg, const gchar *id); void asb_app_set_hidpi_enabled (AsbApp *app, gboolean hidpi_enabled); -void asb_app_add_requires_appdata (AsbApp *app, - const gchar *fmt, - ...) - G_GNUC_PRINTF(2,3); -void asb_app_set_requires_appdata (AsbApp *app, - gboolean requires_appdata); - -GPtrArray *asb_app_get_requires_appdata (AsbApp *app); +void asb_app_set_package (AsbApp *app, + AsbPackage *pkg); AsbPackage *asb_app_get_package (AsbApp *app); - gboolean asb_app_save_resources (AsbApp *app, AsbAppSaveFlags save_flags, GError **error); diff --git a/libappstream-builder/asb-plugin-loader.c b/libappstream-builder/asb-plugin-loader.c index ee6de00..ed3c32c 100644 --- a/libappstream-builder/asb-plugin-loader.c +++ b/libappstream-builder/asb-plugin-loader.c @@ -186,18 +186,11 @@ asb_plugin_loader_process_app (AsbPluginLoader *plugin_loader, "Running asb_plugin_process_app() from %s", plugin->name); if (!plugin_func (plugin, pkg, app, tmpdir, &error_local)) { - if (g_error_matches (error_local, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_IGNORE)) { - asb_package_log (pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Ignoring: %s", - error_local->message); - g_clear_error (&error_local); - } else { - g_propagate_error (error, error_local); - return FALSE; - } + asb_package_log (pkg, + ASB_PACKAGE_LOG_LEVEL_WARNING, + "Ignoring: %s", + error_local->message); + g_clear_error (&error_local); } } return TRUE; diff --git a/libappstream-builder/asb-self-test.c b/libappstream-builder/asb-self-test.c index 511278a..8b9046a 100644 --- a/libappstream-builder/asb-self-test.c +++ b/libappstream-builder/asb-self-test.c @@ -267,7 +267,7 @@ asb_test_plugin_loader_func (void) /* get the list of plugins */ plugins = asb_plugin_loader_get_plugins (loader); - g_assert_cmpint (plugins->len, >=, 17); + g_assert_cmpint (plugins->len, >=, 16); plugin = g_ptr_array_index (plugins, 0); g_assert (plugin != NULL); g_assert (plugin->module != NULL); @@ -275,9 +275,9 @@ asb_test_plugin_loader_func (void) g_assert (plugin->ctx == ctx); /* match the correct one */ - plugin = asb_plugin_loader_match_fn (loader, "/usr/share/applications/gimp.desktop"); + plugin = asb_plugin_loader_match_fn (loader, "/usr/share/appdata/gimp.appdata.xml"); g_assert (plugin != NULL); - g_assert_cmpstr (plugin->name, ==, "desktop"); + g_assert_cmpstr (plugin->name, ==, "appdata"); } #ifdef HAVE_RPM @@ -399,7 +399,7 @@ asb_test_context_test_func (AsbTestContextMode mode) ret = as_store_from_file (store, file, NULL, NULL, &error); g_assert_no_error (error); g_assert (ret); - g_assert_cmpint (as_store_get_size (store), ==, 6); + g_assert_cmpint (as_store_get_size (store), ==, 4); app = as_store_get_app_by_pkgname (store, "app"); g_assert (app != NULL); app = as_store_get_app_by_id (store, "app.desktop"); @@ -518,6 +518,7 @@ asb_test_context_test_func (AsbTestContextMode mode) "<description><p>Updating the firmware on your ColorHug device " "improves performance and adds new features.</p></description>\n" "<icon type=\"stock\">application-x-executable</icon>\n" + "<project_license>GPL-2.0+</project_license>\n" "<url type=\"homepage\">http://www.hughski.com/</url>\n" "<releases>\n" "<release version=\"2.0.2\" timestamp=\"1424116753\">\n" @@ -537,48 +538,6 @@ asb_test_context_test_func (AsbTestContextMode mode) "<value key=\"X-CacheID\">colorhug-als-2.0.2.cab</value>\n" "</metadata>\n" "</component>\n" - "<component type=\"desktop\">\n" - "<id>valid1.desktop</id>\n" - "<pkgname>composite</pkgname>\n" - "<name>Frobnicator</name>\n" - "<summary>Frobnicator</summary>\n" - "<icon type=\"stock\">computer</icon>\n" - "<categories>\n" - "<category>Profiling</category>\n" - "</categories>\n" - "<kudos>\n" - "<kudo>HiDpiIcon</kudo>\n" - "</kudos>\n" - "<project_license>GPL-2.0+</project_license>\n" - "<url type=\"homepage\">http://people.freedesktop.org/</url>\n" - "<releases>\n" - "<release version=\"1\" timestamp=\"1407844800\"/>\n" - "</releases>\n" - "<metadata>\n" - "<value key=\"X-CacheID\">composite-1-1.fc21.x86_64.rpm</value>\n" - "</metadata>\n" - "</component>\n" - "<component type=\"desktop\">\n" - "<id>valid2.desktop</id>\n" - "<pkgname>composite</pkgname>\n" - "<name>Frobnicator Example</name>\n" - "<summary>Frobnicator Example Program</summary>\n" - "<icon type=\"stock\">computer</icon>\n" - "<categories>\n" - "<category>Profiling</category>\n" - "</categories>\n" - "<kudos>\n" - "<kudo>HiDpiIcon</kudo>\n" - "</kudos>\n" - "<project_license>GPL-2.0+</project_license>\n" - "<url type=\"homepage\">http://people.freedesktop.org/</url>\n" - "<releases>\n" - "<release version=\"1\" timestamp=\"1407844800\"/>\n" - "</releases>\n" - "<metadata>\n" - "<value key=\"X-CacheID\">composite-1-1.fc21.x86_64.rpm</value>\n" - "</metadata>\n" - "</component>\n" "</components>\n"; ret = asb_test_compare_lines (xml->str, expected_xml, &error); g_assert_no_error (error); @@ -590,11 +549,11 @@ asb_test_context_test_func (AsbTestContextMode mode) ret = as_store_from_file (store_failed, file_failed, NULL, NULL, &error); g_assert_no_error (error); g_assert (ret); - g_assert_cmpint (as_store_get_size (store_failed), ==, 4); - app = as_store_get_app_by_id (store_failed, "console1.desktop"); - g_assert (app != NULL); - app = as_store_get_app_by_id (store_failed, "console2.desktop"); - g_assert (app != NULL); + g_assert_cmpint (as_store_get_size (store_failed), ==, 2); +// app = as_store_get_app_by_id (store_failed, "console1.desktop"); +// g_assert (app != NULL); +// app = as_store_get_app_by_id (store_failed, "console2.desktop"); +// g_assert (app != NULL); /* check output */ xml_failed = as_store_to_xml (store_failed, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); @@ -670,64 +629,6 @@ asb_test_context_test_func (AsbTestContextMode mode) "<value key=\"X-Merge-With-Parent\">app.desktop</value>\n" "</metadata>\n" "</component>\n" - "<component type=\"desktop\">\n" - "<id>console1.desktop</id>\n" - "<pkgname>app-console</pkgname>\n" - "<source_pkgname>app</source_pkgname>\n" - "<name>Console1</name>\n" - "<summary>A console1 test application</summary>\n" - "<icon height=\"64\" width=\"64\" type=\"cached\">console1.png</icon>\n" - "<categories>\n" - "<category>ConsoleOnly</category>\n" - "</categories>\n" - "<kudos>\n" - "<kudo>ModernToolkit</kudo>\n" - "</kudos>\n" - "<vetos>\n" - "<veto>Required AppData: ConsoleOnly</veto>\n" - "</vetos>\n" - "<project_license>GPL-2.0+</project_license>\n" - "<url type=\"homepage\">http://people.freedesktop.org/</url>\n" - "<releases>\n" - "<release version=\"1\" timestamp=\"1407844800\"/>\n" - "</releases>\n" - "<languages>\n" - "<lang percentage=\"100\">en_GB</lang>\n" - "<lang percentage=\"33\">ru</lang>\n" - "</languages>\n" - "<metadata>\n" - "<value key=\"X-CacheID\">app-console-1-1.fc21.noarch.rpm</value>\n" - "</metadata>\n" - "</component>\n" - "<component type=\"desktop\">\n" - "<id>console2.desktop</id>\n" - "<pkgname>app-console</pkgname>\n" - "<source_pkgname>app</source_pkgname>\n" - "<name>Console2</name>\n" - "<summary>A console2 test application</summary>\n" - "<icon height=\"64\" width=\"64\" type=\"cached\">console2.png</icon>\n" - "<categories>\n" - "<category>ConsoleOnly</category>\n" - "</categories>\n" - "<kudos>\n" - "<kudo>ModernToolkit</kudo>\n" - "</kudos>\n" - "<vetos>\n" - "<veto>Required AppData: ConsoleOnly</veto>\n" - "</vetos>\n" - "<project_license>GPL-2.0+</project_license>\n" - "<url type=\"homepage\">http://people.freedesktop.org/</url>\n" - "<releases>\n" - "<release version=\"1\" timestamp=\"1407844800\"/>\n" - "</releases>\n" - "<languages>\n" - "<lang percentage=\"100\">en_GB</lang>\n" - "<lang percentage=\"33\">ru</lang>\n" - "</languages>\n" - "<metadata>\n" - "<value key=\"X-CacheID\">app-console-1-1.fc21.noarch.rpm</value>\n" - "</metadata>\n" - "</component>\n" "</components>\n"; ret = asb_test_compare_lines (xml_failed->str, expected_xml, &error); g_assert_no_error (error); @@ -759,6 +660,13 @@ asb_test_context_test_func (AsbTestContextMode mode) "</metadata>\n" "</component>\n" "<component>\n" + "<id>composite.x86_64</id>\n" + "<pkgname>composite</pkgname>\n" + "<metadata>\n" + "<value key=\"X-CacheID\">composite-1-1.fc21.x86_64.rpm</value>\n" + "</metadata>\n" + "</component>\n" + "<component>\n" "<id>font-serif.noarch</id>\n" "<pkgname>font-serif</pkgname>\n" "<metadata>\n" @@ -923,6 +831,7 @@ asb_test_firmware_func (void) "<description><p>Updating the firmware on your ColorHug device " "improves performance and adds new features.</p></description>\n" "<icon type=\"stock\">application-x-executable</icon>\n" + "<project_license>GPL-2.0+</project_license>\n" "<url type=\"homepage\">http://www.hughski.com/</url>\n" "<releases>\n" "<release version=\"2.0.2\" timestamp=\"1424116753\">\n" @@ -943,10 +852,6 @@ asb_test_firmware_func (void) "<li>Scale XYZ measurement with a constant factor to make the CCMX more " "sane</li></ul></description>\n" "</release>\n" - "<release version=\"2.0.0\" timestamp=\"1425168000\">\n" - "<checksum filename=\"colorhug-als-2.0.0.cab\" target=\"container\" type=\"sha1\">abcedb24d0a2fa8c9cab065d6751e1b89b4c79c1</checksum>\n" - "<checksum filename=\"firmware.bin\" target=\"content\" type=\"sha1\">767a8a7b8a7b350b513f57761204b4aaa657aa44</checksum>\n" - "</release>\n" "</releases>\n" "<provides>\n" "<firmware type=\"flashed\">84f40464-9272-4ef7-9399-cd95f12da696</firmware>\n" diff --git a/libappstream-builder/asb-task.c b/libappstream-builder/asb-task.c index 57bd192..f6bdca5 100644 --- a/libappstream-builder/asb-task.c +++ b/libappstream-builder/asb-task.c @@ -236,7 +236,6 @@ asb_task_process (AsbTask *task, GError **error_not_used) GPtrArray *array; gboolean ret; gchar *cache_id; - gchar *tmp; guint i; guint nr_added = 0; g_autoptr(GError) error = NULL; @@ -403,17 +402,6 @@ asb_task_process (AsbTask *task, GError **error_not_used) goto skip; } - /* veto apps that *still* require appdata */ - array = asb_app_get_requires_appdata (app); - for (i = 0; i < array->len; i++) { - tmp = g_ptr_array_index (array, i); - if (tmp == NULL) { - as_app_add_veto (AS_APP (app), "Required AppData"); - continue; - } - as_app_add_veto (AS_APP (app), "Required AppData: %s", tmp); - } - /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); diff --git a/libappstream-builder/plugins/Makefile.am b/libappstream-builder/plugins/Makefile.am index f697631..96840ad 100644 --- a/libappstream-builder/plugins/Makefile.am +++ b/libappstream-builder/plugins/Makefile.am @@ -27,9 +27,6 @@ plugin_LTLIBRARIES = \ libasb_plugin_gettext.la \ libasb_plugin_gstreamer.la \ libasb_plugin_hardcoded.la \ - libasb_plugin_ibus_sql.la \ - libasb_plugin_ibus_xml.la \ - libasb_plugin_metainfo.la \ libasb_plugin_kde_services.la \ libasb_plugin_kde_notifyrc.la \ libasb_plugin_nm.la @@ -69,11 +66,6 @@ libasb_plugin_gstreamer_la_LIBADD = $(GLIB_LIBS) libasb_plugin_gstreamer_la_LDFLAGS = -module -avoid-version libasb_plugin_gstreamer_la_CFLAGS = $(GLIB_CFLAGS) $(WARNINGFLAGS_C) -libasb_plugin_metainfo_la_SOURCES = asb-plugin-metainfo.c -libasb_plugin_metainfo_la_LIBADD = $(GLIB_LIBS) -libasb_plugin_metainfo_la_LDFLAGS = -module -avoid-version -libasb_plugin_metainfo_la_CFLAGS = $(GLIB_CFLAGS) $(WARNINGFLAGS_C) - libasb_plugin_gettext_la_SOURCES = asb-plugin-gettext.c libasb_plugin_gettext_la_LIBADD = $(GLIB_LIBS) libasb_plugin_gettext_la_LDFLAGS = -module -avoid-version @@ -114,16 +106,6 @@ libasb_plugin_nm_la_LIBADD = $(GLIB_LIBS) libasb_plugin_nm_la_LDFLAGS = -module -avoid-version libasb_plugin_nm_la_CFLAGS = $(GLIB_CFLAGS) $(WARNINGFLAGS_C) -libasb_plugin_ibus_sql_la_SOURCES = asb-plugin-ibus-sql.c -libasb_plugin_ibus_sql_la_LIBADD = $(GLIB_LIBS) $(SQLITE_LIBS) -libasb_plugin_ibus_sql_la_LDFLAGS = -module -avoid-version -libasb_plugin_ibus_sql_la_CFLAGS = $(GLIB_CFLAGS) $(WARNINGFLAGS_C) - -libasb_plugin_ibus_xml_la_SOURCES = asb-plugin-ibus-xml.c -libasb_plugin_ibus_xml_la_LIBADD = $(GLIB_LIBS) $(SQLITE_LIBS) -libasb_plugin_ibus_xml_la_LDFLAGS = -module -avoid-version -libasb_plugin_ibus_xml_la_CFLAGS = $(GLIB_CFLAGS) $(WARNINGFLAGS_C) - libasb_plugin_font_la_SOURCES = asb-plugin-font.c libasb_plugin_font_la_LIBADD = $(GLIB_LIBS) $(FREETYPE_LIBS) $(GDKPIXBUF_LIBS) $(GTK_LIBS) libasb_plugin_font_la_LDFLAGS = -module -avoid-version diff --git a/libappstream-builder/plugins/asb-plugin-appdata.c b/libappstream-builder/plugins/asb-plugin-appdata.c index e0d3851..26e68c5 100644 --- a/libappstream-builder/plugins/asb-plugin-appdata.c +++ b/libappstream-builder/plugins/asb-plugin-appdata.c @@ -20,8 +20,7 @@ */ #include <config.h> - -#include <appstream-glib.h> +#include <fnmatch.h> #include <asb-plugin.h> @@ -40,46 +39,73 @@ asb_plugin_get_name (void) void asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) { + asb_plugin_add_glob (globs, "/usr/share/appdata/*.metainfo.xml"); asb_plugin_add_glob (globs, "/usr/share/appdata/*.appdata.xml"); asb_plugin_add_glob (globs, "*.metainfo.xml"); } /** + * _asb_plugin_check_filename: + */ +static gboolean +_asb_plugin_check_filename (const gchar *filename) +{ + if (asb_plugin_match_glob ("*.metainfo.xml", filename) || + asb_plugin_match_glob ("/usr/share/appdata/*.metainfo.xml", filename) || + asb_plugin_match_glob ("/usr/share/appdata/*.appdata.xml", filename)) + return TRUE; + return FALSE; +} + +/** + * asb_plugin_check_filename: + */ +gboolean +asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) +{ + return _asb_plugin_check_filename (filename); +} + +/** * asb_plugin_process_filename: */ static gboolean asb_plugin_process_filename (AsbPlugin *plugin, - AsbApp *app, + AsbPackage *pkg, const gchar *filename, + GList **apps, GError **error) { AsProblemKind problem_kind; AsProblem *problem; - const gchar *key; - const gchar *old; + GPtrArray *icons; const gchar *tmp; - gboolean ret; - GHashTable *hash; - GPtrArray *array; - GList *l; - GList *list; guint i; - g_autoptr(AsApp) appdata = NULL; + g_autoptr(AsbApp) app = NULL; g_autoptr(GPtrArray) problems = NULL; - /* validate */ - appdata = as_app_new (); - ret = as_app_parse_file (appdata, filename, - AS_APP_PARSE_FLAG_NONE, - error); - if (!ret) + app = asb_app_new (NULL, NULL); + if (!as_app_parse_file (AS_APP (app), filename, + AS_APP_PARSE_FLAG_NONE, + error)) + return FALSE; + if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_UNKNOWN) { + g_set_error (error, + ASB_PLUGIN_ERROR, + ASB_PLUGIN_ERROR_FAILED, + "%s has no recognised type", + as_app_get_id (AS_APP (app))); return FALSE; - problems = as_app_validate (appdata, + } + + /* validate */ + problems = as_app_validate (AS_APP (app), AS_APP_VALIDATE_FLAG_NO_NETWORK | AS_APP_VALIDATE_FLAG_RELAX, error); if (problems == NULL) return FALSE; + asb_app_set_package (app, pkg); for (i = 0; i < problems->len; i++) { problem = g_ptr_array_index (problems, i); problem_kind = as_problem_get_kind (problem); @@ -90,34 +116,14 @@ asb_plugin_process_filename (AsbPlugin *plugin, as_problem_get_message (problem)); } - /* check <id> matches, but still accept if missing or incorrect */ - tmp = as_app_get_id (appdata); - if (tmp == NULL) { - asb_package_log (asb_app_get_package (app), - ASB_PACKAGE_LOG_LEVEL_WARNING, - "AppData %s has no ID", filename); - } else if (g_strcmp0 (tmp, as_app_get_id (AS_APP (app))) != 0) { - asb_package_log (asb_app_get_package (app), - ASB_PACKAGE_LOG_LEVEL_WARNING, - "AppData %s does not match '%s':'%s'", - filename, tmp, - as_app_get_id (AS_APP (app))); - } - - /* overwrite the app ID with the metadata one for firmware */ - if (as_app_get_id_kind (appdata) == AS_ID_KIND_FIRMWARE) { - old = as_app_get_id (AS_APP (app)); - if (old != NULL) { - asb_package_log (asb_app_get_package (app), - ASB_PACKAGE_LOG_LEVEL_DEBUG, - "renaming ID %s -> %s", - old, as_app_get_id (AS_APP (appdata))); - } - as_app_set_id (AS_APP (app), as_app_get_id (AS_APP (appdata))); - } + /* nuke things that do not belong */ + icons = as_app_get_icons (AS_APP (app)); + if (icons->len > 0) + g_ptr_array_set_size (icons, 0); /* add provide if missing */ - if (as_app_get_id_kind (appdata) == AS_ID_KIND_FIRMWARE && + tmp = as_app_get_id (AS_APP (app)); + if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_FIRMWARE && as_utils_guid_is_valid (tmp)) { g_autoptr(AsProvide) provide = NULL; provide = as_provide_new (); @@ -127,7 +133,7 @@ asb_plugin_process_filename (AsbPlugin *plugin, } /* check license */ - tmp = as_app_get_metadata_license (appdata); + tmp = as_app_get_metadata_license (AS_APP (app)); if (tmp == NULL) { g_set_error (error, ASB_PLUGIN_ERROR, @@ -145,189 +151,149 @@ asb_plugin_process_filename (AsbPlugin *plugin, return FALSE; } - /* other optional data */ - tmp = as_app_get_url_item (appdata, AS_URL_KIND_HOMEPAGE); - if (tmp != NULL) - as_app_add_url (AS_APP (app), AS_URL_KIND_HOMEPAGE, tmp); - tmp = as_app_get_project_group (appdata); + /* check project group */ + tmp = as_app_get_project_group (AS_APP (app)); if (tmp != NULL) { - /* check the category is valid */ if (!as_utils_is_environment_id (tmp)) { asb_package_log (asb_app_get_package (app), ASB_PACKAGE_LOG_LEVEL_WARNING, "AppData project group invalid, " "so ignoring: %s", tmp); - } else { - as_app_set_project_group (AS_APP (app), tmp); - } - } - array = as_app_get_compulsory_for_desktops (appdata); - if (array->len > 0) { - tmp = g_ptr_array_index (array, 0); - as_app_add_compulsory_for_desktop (AS_APP (app), tmp); - } - - /* perhaps get name */ - hash = as_app_get_names (appdata); - list = g_hash_table_get_keys (hash); - for (l = list; l != NULL; l = l->next) { - key = l->data; - tmp = g_hash_table_lookup (hash, key); - as_app_set_name (AS_APP (app), key, tmp); - } - g_list_free (list); - - /* perhaps get summary */ - hash = as_app_get_comments (appdata); - list = g_hash_table_get_keys (hash); - for (l = list; l != NULL; l = l->next) { - key = l->data; - tmp = g_hash_table_lookup (hash, key); - as_app_set_comment (AS_APP (app), key, tmp); - } - g_list_free (list); - - /* get descriptions */ - hash = as_app_get_descriptions (appdata); - list = g_hash_table_get_keys (hash); - for (l = list; l != NULL; l = l->next) { - key = l->data; - tmp = g_hash_table_lookup (hash, key); - as_app_set_description (AS_APP (app), key, tmp); - } - g_list_free (list); - - /* add screenshots if not already added */ - array = as_app_get_screenshots (AS_APP (app)); - if (array->len == 0) { - /* just use the upstream locations */ - array = as_app_get_screenshots (appdata); - for (i = 0; i < array->len; i++) { - AsScreenshot *ss; - ss = g_ptr_array_index (array, i); - as_app_add_screenshot (AS_APP (app), ss); - } - } else { - array = as_app_get_screenshots (appdata); - if (array->len > 0) { - asb_package_log (asb_app_get_package (app), - ASB_PACKAGE_LOG_LEVEL_INFO, - "AppData screenshots ignored"); + as_app_set_project_group (AS_APP (app), NULL); } } - /* add metadata */ - hash = as_app_get_metadata (appdata); - list = g_hash_table_get_keys (hash); - for (l = list; l != NULL; l = l->next) { - key = l->data; - tmp = g_hash_table_lookup (hash, key); - as_app_add_metadata (AS_APP (app), key, tmp); + /* log updateinfo */ + tmp = as_app_get_update_contact (AS_APP (app)); + if (tmp != NULL) { + asb_package_log (asb_app_get_package (app), + ASB_PACKAGE_LOG_LEVEL_INFO, + "Upstream contact <%s>", tmp); } - /* add developer name */ - tmp = as_app_get_developer_name (AS_APP (appdata), NULL); - if (tmp != NULL) - as_app_set_developer_name (AS_APP (app), NULL, tmp); - - /* add releases */ - array = as_app_get_releases (appdata); - for (i = 0; i < array->len; i++) { - AsRelease *rel = g_ptr_array_index (array, i); - as_app_add_release (AS_APP (app), rel); + /* add icon for firmware */ + if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_FIRMWARE) { + g_autoptr(AsIcon) icon = NULL; + icon = as_icon_new (); + as_icon_set_kind (icon, AS_ICON_KIND_STOCK); + as_icon_set_name (icon, "application-x-executable"); + as_app_add_icon (AS_APP (app), icon); } - /* add provides */ - array = as_app_get_provides (appdata); - for (i = 0; i < array->len; i++) { - AsProvide *pr = g_ptr_array_index (array, i); - as_app_add_provide (AS_APP (app), pr); + /* fix up input methods */ + if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_INPUT_METHOD) { + g_autoptr(AsIcon) icon = NULL; + icon = as_icon_new (); + as_icon_set_kind (icon, AS_ICON_KIND_STOCK); + as_icon_set_name (icon, "system-run-symbolic"); + as_app_add_icon (AS_APP (app), icon); + as_app_add_category (AS_APP (app), "Addons"); + as_app_add_category (AS_APP (app), "InputSources"); } - /* log updateinfo */ - tmp = as_app_get_update_contact (AS_APP (appdata)); - if (tmp != NULL) { - asb_package_log (asb_app_get_package (app), - ASB_PACKAGE_LOG_LEVEL_INFO, - "Upstream contact <%s>", tmp); + /* fix up codecs */ + if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_CODEC) { + g_autoptr(AsIcon) icon = NULL; + icon = as_icon_new (); + as_icon_set_kind (icon, AS_ICON_KIND_STOCK); + as_icon_set_name (icon, "application-x-executable"); + as_app_add_icon (AS_APP (app), icon); + as_app_add_category (AS_APP (app), "Addons"); + as_app_add_category (AS_APP (app), "Codecs"); } /* success */ - asb_app_set_requires_appdata (app, FALSE); + asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, + ASB_CONTEXT_FLAG_HIDPI_ICONS)); + asb_plugin_add_app (apps, AS_APP (app)); return TRUE; } /** - * asb_plugin_appdata_get_fn_for_app: + * asb_plugin_process: */ -static gchar * -asb_plugin_appdata_get_fn_for_app (AsApp *app) +GList * +asb_plugin_process (AsbPlugin *plugin, + AsbPackage *pkg, + const gchar *tmpdir, + GError **error) { - gchar *fn = g_strdup (as_app_get_id (app)); - gchar *tmp; + gboolean ret; + GList *apps = NULL; + guint i; + gchar **filelist; - /* just cut off the last section without munging the name */ - tmp = g_strrstr (fn, "."); - if (tmp != NULL) - *tmp = '\0'; - return fn; + filelist = asb_package_get_filelist (pkg); + for (i = 0; filelist[i] != NULL; i++) { + g_autofree gchar *filename_tmp = NULL; + if (!_asb_plugin_check_filename (filelist[i])) + continue; + filename_tmp = g_build_filename (tmpdir, filelist[i], NULL); + ret = asb_plugin_process_filename (plugin, + pkg, + filename_tmp, + &apps, + error); + if (!ret) { + g_list_free_full (apps, (GDestroyNotify) g_object_unref); + return NULL; + } + } + + /* no desktop files we care about */ + if (apps == NULL) { + g_set_error (error, + ASB_PLUGIN_ERROR, + ASB_PLUGIN_ERROR_FAILED, + "nothing interesting in %s", + asb_package_get_basename (pkg)); + return NULL; + } + return apps; } /** - * asb_plugin_process_app: + * asb_plugin_merge: */ -gboolean -asb_plugin_process_app (AsbPlugin *plugin, - AsbPackage *pkg, - AsbApp *app, - const gchar *tmpdir, - GError **error) +void +asb_plugin_merge (AsbPlugin *plugin, GList *list) { - GError *error_local = NULL; - g_autofree gchar *appdata_filename = NULL; - - /* get possible sources */ - if (asb_package_get_kind (pkg) == ASB_PACKAGE_KIND_FIRMWARE) { - appdata_filename = g_build_filename (tmpdir, - as_app_get_metadata_item (AS_APP (app), "MetainfoBasename"), - NULL); - } else { - g_autofree gchar *appdata_basename = NULL; - appdata_basename = asb_plugin_appdata_get_fn_for_app (AS_APP (app)); - appdata_filename = g_strdup_printf ("%s/files/share/appdata/%s.appdata.xml", - tmpdir, appdata_basename); - if (!g_file_test (appdata_filename, G_FILE_TEST_EXISTS)) { - g_free (appdata_filename); - appdata_filename = g_strdup_printf ("%s/usr/share/appdata/%s.appdata.xml", - tmpdir, appdata_basename); - } - } + AsApp *app; + AsApp *found; + GList *l; + g_autoptr(GHashTable) hash = NULL; - /* any installed appdata file */ - if (g_file_test (appdata_filename, G_FILE_TEST_EXISTS)) { - /* be understanding if upstream gets the AppData file - * wrong -- just fall back to the desktop file data */ - if (!asb_plugin_process_filename (plugin, - app, - appdata_filename, - &error_local)) { - error_local->code = ASB_PLUGIN_ERROR_IGNORE; - g_propagate_error (error, error_local); - g_prefix_error (error, - "AppData file '%s' invalid: ", - appdata_filename); - return FALSE; - } - return TRUE; + /* make a hash table of ID->AsApp */ + hash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) g_object_unref); + for (l = list; l != NULL; l = l->next) { + app = AS_APP (l->data); + if (as_app_get_id_kind (app) != AS_ID_KIND_DESKTOP) + continue; + g_hash_table_insert (hash, + g_strdup (as_app_get_id (app)), + g_object_ref (app)); } - /* we're going to require this soon */ - if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_DESKTOP && - as_app_get_metadata_item (AS_APP (app), "NoDisplay") == NULL) { - asb_package_log (pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "desktop application %s has no AppData", - as_app_get_id (AS_APP (app))); + /* add addons where the pkgname is different from the + * main package */ + for (l = list; l != NULL; l = l->next) { + if (!ASB_IS_APP (l->data)) + continue; + app = AS_APP (l->data); + if (as_app_get_id_kind (app) != AS_ID_KIND_ADDON) + continue; + found = g_hash_table_lookup (hash, as_app_get_id (app)); + if (found == NULL) + continue; + if (g_strcmp0 (as_app_get_pkgname_default (app), + as_app_get_pkgname_default (found)) != 0) + continue; + as_app_add_veto (app, + "absorbing addon %s shipped in " + "main package %s", + as_app_get_id (app), + as_app_get_pkgname_default (app)); + as_app_subsume_full (found, app, AS_APP_SUBSUME_FLAG_PARTIAL); } - return TRUE; } diff --git a/libappstream-builder/plugins/asb-plugin-blacklist.c b/libappstream-builder/plugins/asb-plugin-blacklist.c index d441b5a..e4360ef 100644 --- a/libappstream-builder/plugins/asb-plugin-blacklist.c +++ b/libappstream-builder/plugins/asb-plugin-blacklist.c @@ -133,6 +133,6 @@ asb_plugin_process_app (AsbPlugin *plugin, tmp = asb_glob_value_search (plugin->priv->vetos, as_app_get_id (AS_APP (app))); if (tmp != NULL) - asb_app_add_requires_appdata (app, "%s", tmp); + as_app_add_veto (AS_APP (app), "%s", tmp); return TRUE; } diff --git a/libappstream-builder/plugins/asb-plugin-desktop.c b/libappstream-builder/plugins/asb-plugin-desktop.c index ec412c1..34cf795 100644 --- a/libappstream-builder/plugins/asb-plugin-desktop.c +++ b/libappstream-builder/plugins/asb-plugin-desktop.c @@ -53,28 +53,6 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) } /** - * _asb_plugin_check_filename: - */ -static gboolean -_asb_plugin_check_filename (const gchar *filename) -{ - if (asb_plugin_match_glob ("/usr/share/applications/*.desktop", filename)) - return TRUE; - if (asb_plugin_match_glob ("/usr/share/applications/kde4/*.desktop", filename)) - return TRUE; - return FALSE; -} - -/** - * asb_plugin_check_filename: - */ -gboolean -asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) -{ - return _asb_plugin_check_filename (filename); -} - -/** * asb_app_load_icon: */ static GdkPixbuf * @@ -301,22 +279,21 @@ asb_plugin_desktop_add_icons (AsbPlugin *plugin, } /** - * asb_plugin_process_filename: + * asb_plugin_desktop_refine: */ static gboolean -asb_plugin_process_filename (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *filename, - GList **apps, - const gchar *tmpdir, - GError **error) +asb_plugin_desktop_refine (AsbPlugin *plugin, + AsbPackage *pkg, + const gchar *filename, + AsbApp *app, + const gchar *tmpdir, + GError **error) { AsIcon *icon; AsAppParseFlags parse_flags = AS_APP_PARSE_FLAG_USE_HEURISTICS; gboolean ret; g_autofree gchar *app_id = NULL; - g_autofree gchar *full_filename = NULL; - g_autoptr(AsbApp) app = NULL; + g_autoptr(AsApp) desktop_app = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; /* use GenericName fallback */ @@ -325,23 +302,16 @@ asb_plugin_process_filename (AsbPlugin *plugin, /* create app */ app_id = g_path_get_basename (filename); - app = asb_app_new (pkg, app_id); - asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); - full_filename = g_build_filename (tmpdir, filename, NULL); - if (!as_app_parse_file (AS_APP (app), full_filename, parse_flags, error)) + desktop_app = as_app_new (); + if (!as_app_parse_file (desktop_app, filename, parse_flags, error)) return FALSE; /* NoDisplay apps are never included */ - if (as_app_get_metadata_item (AS_APP (app), "NoDisplay") != NULL) - asb_app_add_requires_appdata (app, "NoDisplay=true"); - - /* Settings or DesktopSettings requires AppData */ - if (!asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_IGNORE_SETTINGS)) { - if (as_app_has_category (AS_APP (app), "Settings")) - asb_app_add_requires_appdata (app, "Category=Settings"); - if (as_app_has_category (AS_APP (app), "DesktopSettings")) - asb_app_add_requires_appdata (app, "Category=DesktopSettings"); - } + if (as_app_get_metadata_item (desktop_app, "NoDisplay") != NULL) + as_app_add_veto (AS_APP (app), "NoDisplay=true"); + + /* copy all metadata */ + as_app_subsume_full (AS_APP (app), desktop_app, AS_APP_SUBSUME_FLAG_NO_OVERWRITE); /* is the icon a stock-icon-name? */ icon = as_app_get_icon_default (AS_APP (app)); @@ -367,54 +337,38 @@ asb_plugin_process_filename (AsbPlugin *plugin, } } - /* add */ - asb_plugin_add_app (apps, AS_APP (app)); return TRUE; } /** - * asb_plugin_process: + * asb_plugin_process_app: */ -GList * -asb_plugin_process (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *tmpdir, - GError **error) +gboolean +asb_plugin_process_app (AsbPlugin *plugin, + AsbPackage *pkg, + AsbApp *app, + const gchar *tmpdir, + GError **error) { - gboolean ret; - GError *error_local = NULL; - GList *apps = NULL; guint i; - gchar **filelist; - - filelist = asb_package_get_filelist (pkg); - for (i = 0; filelist[i] != NULL; i++) { - if (!_asb_plugin_check_filename (filelist[i])) - continue; - ret = asb_plugin_process_filename (plugin, - pkg, - filelist[i], - &apps, - tmpdir, - &error_local); - if (!ret) { - asb_package_log (pkg, - ASB_PACKAGE_LOG_LEVEL_INFO, - "Failed to process %s: %s", - filelist[i], - error_local->message); - g_clear_error (&error_local); + const gchar *app_dirs[] = { + "/usr/share/applications", + "/usr/share/applications/kde4", + NULL }; + + /* use the .desktop file to refine the application */ + for (i = 0; app_dirs[i] != NULL; i++) { + g_autofree gchar *fn = NULL; + fn = g_build_filename (tmpdir, + app_dirs[i], + as_app_get_id (AS_APP (app)), + NULL); + if (g_file_test (fn, G_FILE_TEST_EXISTS)) { + if (!asb_plugin_desktop_refine (plugin, pkg, fn, + app, tmpdir, error)) + return FALSE; } } - /* no desktop files we care about */ - if (apps == NULL) { - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "nothing interesting in %s", - asb_package_get_basename (pkg)); - return NULL; - } - return apps; + return TRUE; } diff --git a/libappstream-builder/plugins/asb-plugin-firmware.c b/libappstream-builder/plugins/asb-plugin-firmware.c index bd98f07..2ef9b5c 100644 --- a/libappstream-builder/plugins/asb-plugin-firmware.c +++ b/libappstream-builder/plugins/asb-plugin-firmware.c @@ -46,39 +46,19 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) } /** - * _asb_plugin_check_filename: - */ -static gboolean -_asb_plugin_check_filename (const gchar *filename) -{ - if (asb_plugin_match_glob ("*.inf", filename)) - return TRUE; - return FALSE; -} - -/** - * asb_plugin_check_filename: - */ -gboolean -asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) -{ - return _asb_plugin_check_filename (filename); -} - -/** - * asb_plugin_firmware_get_metainfo_fn: + * asb_plugin_firmware_get_inf_fn: */ static gchar * -asb_plugin_firmware_get_metainfo_fn (const gchar *filename) +asb_plugin_firmware_get_inf_fn (const gchar *filename) { gchar *basename; gchar *tmp; basename = g_path_get_basename (filename); - tmp = g_strrstr (basename, ".inf"); + tmp = g_strrstr (basename, ".metainfo.xml"); if (tmp != NULL) *tmp = '\0'; - return g_strdup_printf ("%s.metainfo.xml", basename); + return g_strdup_printf ("%s.inf", basename); } /** @@ -98,30 +78,28 @@ asb_plugin_firmware_get_checksum (const gchar *filename, } /** - * asb_plugin_process_filename: + * asb_plugin_firmware_refine: */ static gboolean -asb_plugin_process_filename (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *filename, - GList **apps, - const gchar *tmpdir, - GError **error) +asb_plugin_firmware_refine (AsbPlugin *plugin, + AsbPackage *pkg, + const gchar *filename, + AsbApp *app, + const gchar *tmpdir, + GError **error) { AsRelease *release; GError *error_local = NULL; const gchar *fw_basename = NULL; g_autofree gchar *checksum = NULL; - g_autofree gchar *filename_full = NULL; g_autofree gchar *location_checksum = NULL; g_autofree gchar *metainfo_fn = NULL; - g_autoptr(AsbApp) app = NULL; + g_autoptr(AsApp) inf = NULL; g_autoptr(AsChecksum) csum = NULL; /* parse */ - filename_full = g_build_filename (tmpdir, filename, NULL); - app = asb_app_new (pkg, NULL); - if (!as_app_parse_file (AS_APP (app), filename_full, + inf = as_app_new (); + if (!as_app_parse_file (inf, filename, AS_APP_PARSE_FLAG_NONE, &error_local)) { g_set_error_literal (error, ASB_PLUGIN_ERROR, @@ -130,7 +108,7 @@ asb_plugin_process_filename (AsbPlugin *plugin, return FALSE; } - /* get the default release, creating if required */ + /* get the correct release, creating if required */ release = as_app_get_release_default (AS_APP (app)); if (release == NULL) { release = as_release_new (); @@ -152,13 +130,8 @@ asb_plugin_process_filename (AsbPlugin *plugin, as_checksum_set_filename (csum, asb_package_get_basename (pkg)); as_release_add_checksum (release, csum); - /* for the adddata plugin; removed in asb_plugin_merge() */ - metainfo_fn = asb_plugin_firmware_get_metainfo_fn (filename); - if (metainfo_fn != NULL) - as_app_add_metadata (AS_APP (app), "MetainfoBasename", metainfo_fn); - /* set the internal checksum */ - fw_basename = as_app_get_metadata_item (AS_APP (app), "FirmwareBasename"); + fw_basename = as_app_get_metadata_item (inf, "FirmwareBasename"); if (fw_basename != NULL) { g_autofree gchar *checksum_bin = NULL; g_autofree gchar *fn_bin = NULL; @@ -181,72 +154,40 @@ asb_plugin_process_filename (AsbPlugin *plugin, as_release_add_checksum (release, csum_bin); } - asb_plugin_add_app (apps, AS_APP (app)); return TRUE; } /** - * asb_plugin_process: + * asb_plugin_process_app: */ -GList * -asb_plugin_process (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *tmpdir, - GError **error) +gboolean +asb_plugin_process_app (AsbPlugin *plugin, + AsbPackage *pkg, + AsbApp *app, + const gchar *tmpdir, + GError **error) { - gboolean ret; - GError *error_local = NULL; - GList *apps = NULL; - guint i; - gchar **filelist; - - filelist = asb_package_get_filelist (pkg); - for (i = 0; filelist[i] != NULL; i++) { - if (!_asb_plugin_check_filename (filelist[i])) - continue; - ret = asb_plugin_process_filename (plugin, - pkg, - filelist[i], - &apps, - tmpdir, - &error_local); - if (!ret) { - asb_package_log (pkg, - ASB_PACKAGE_LOG_LEVEL_INFO, - "Failed to process %s: %s", - filelist[i], - error_local->message); - g_clear_error (&error_local); - } - } + const gchar *tmp; + g_autofree gchar *fn = NULL; + g_autofree gchar *inf_fn = NULL; - /* no desktop files we care about */ - if (apps == NULL) { + /* use metainfo basename */ + tmp = as_app_get_source_file (AS_APP (app)); + if (tmp == NULL) { g_set_error (error, ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "nothing interesting in %s", - asb_package_get_basename (pkg)); - return NULL; + ASB_PLUGIN_ERROR_NOT_SUPPORTED, + "no source_file set for %s", + as_app_get_id (AS_APP (app))); + return FALSE; } - return apps; -} -/** - * asb_plugin_merge: - */ -void -asb_plugin_merge (AsbPlugin *plugin, GList *list) -{ - AsApp *app; - GList *l; - - /* remove the MetainfoBasename metadata */ - for (l = list; l != NULL; l = l->next) { - app = AS_APP (l->data); - if (as_app_get_id_kind (app) != AS_ID_KIND_FIRMWARE) - continue; - as_app_remove_metadata (app, "MetainfoBasename"); - as_app_remove_metadata (app, "FirmwareBasename"); + /* use the .inf file to refine the application */ + inf_fn = asb_plugin_firmware_get_inf_fn (tmp); + fn = g_build_filename (tmpdir, inf_fn, NULL); + if (g_file_test (fn, G_FILE_TEST_EXISTS)) { + if (!asb_plugin_firmware_refine (plugin, pkg, fn, app, tmpdir, error)) + return FALSE; } + return TRUE; } diff --git a/libappstream-builder/plugins/asb-plugin-gstreamer.c b/libappstream-builder/plugins/asb-plugin-gstreamer.c index 9f0c710..8c5a8a4 100644 --- a/libappstream-builder/plugins/asb-plugin-gstreamer.c +++ b/libappstream-builder/plugins/asb-plugin-gstreamer.c @@ -42,17 +42,6 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) asb_plugin_add_glob (globs, "/usr/lib64/gstreamer-1.0/libgst*.so"); } -/** - * asb_plugin_check_filename: - */ -gboolean -asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) -{ - if (asb_plugin_match_glob ("/usr/lib64/gstreamer-1.0/libgst*.so", filename)) - return TRUE; - return FALSE; -} - typedef struct { const gchar *path; const gchar *text; @@ -117,98 +106,26 @@ asb_utils_is_file_in_tmpdir (const gchar *tmpdir, const gchar *filename) } /** - * asb_utils_string_sort_cb: - */ -static gint -asb_utils_string_sort_cb (gconstpointer a, gconstpointer b) -{ - return g_strcmp0 (*((const gchar **) a), *((const gchar **) b)); -} - -/** - * asb_plugin_process: + * asb_plugin_process_app: */ -GList * -asb_plugin_process (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *tmpdir, - GError **error) +gboolean +asb_plugin_process_app (AsbPlugin *plugin, + AsbPackage *pkg, + AsbApp *app, + const gchar *tmpdir, + GError **error) { - const gchar *tmp; - gchar **split; - GList *apps = NULL; - GPtrArray *keywords; guint i; guint j; - g_autofree gchar *app_id = NULL; - g_autoptr(AsbApp) app = NULL; - g_autoptr(AsIcon) icon = NULL; - g_autoptr(GString) str = NULL; - - /* use the pkgname suffix as the app-id */ - tmp = asb_package_get_name (pkg); - if (g_str_has_prefix (tmp, "gstreamer1-")) - tmp += 11; - if (g_str_has_prefix (tmp, "gstreamer-")) - tmp += 10; - if (g_str_has_prefix (tmp, "plugins-")) - tmp += 8; - app_id = g_strdup_printf ("gstreamer-%s", tmp); - - /* create app */ - app = asb_app_new (pkg, app_id); - as_app_set_id_kind (AS_APP (app), AS_ID_KIND_CODEC); - as_app_set_name (AS_APP (app), "C", "GStreamer Multimedia Codecs"); - asb_app_set_requires_appdata (app, TRUE); - asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); - as_app_add_category (AS_APP (app), "Addons"); - as_app_add_category (AS_APP (app), "Codecs"); - - /* add icon */ - icon = as_icon_new (); - as_icon_set_kind (icon, AS_ICON_KIND_STOCK); - as_icon_set_name (icon, "application-x-executable"); - as_app_add_icon (AS_APP (app), icon); for (i = 0; data[i].path != NULL; i++) { + g_auto(GStrv) split = NULL; if (!asb_utils_is_file_in_tmpdir (tmpdir, data[i].path)) continue; split = g_strsplit (data[i].text, "|", -1); for (j = 0; split[j] != NULL; j++) as_app_add_keyword (AS_APP (app), NULL, split[j]); - g_strfreev (split); - } - - /* no codecs we care about */ - keywords = as_app_get_keywords (AS_APP (app), NULL); - if (keywords == NULL) { - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "nothing interesting in %s", - asb_package_get_basename (pkg)); - return NULL; - } - - /* sort categories by name */ - g_ptr_array_sort (keywords, asb_utils_string_sort_cb); - - /* create a description */ - str = g_string_new ("Multimedia playback for "); - if (keywords->len > 1) { - for (i = 0; i < keywords->len - 1; i++) { - tmp = g_ptr_array_index (keywords, i); - g_string_append_printf (str, "%s, ", tmp); - } - g_string_truncate (str, str->len - 2); - tmp = g_ptr_array_index (keywords, keywords->len - 1); - g_string_append_printf (str, " and %s", tmp); - } else { - g_string_append (str, g_ptr_array_index (keywords, 0)); } - as_app_set_comment (AS_APP (app), "C", str->str); - /* add */ - asb_plugin_add_app (&apps, AS_APP (app)); - return apps; + return TRUE; } diff --git a/libappstream-builder/plugins/asb-plugin-hardcoded.c b/libappstream-builder/plugins/asb-plugin-hardcoded.c index b2e7396..d17271b 100644 --- a/libappstream-builder/plugins/asb-plugin-hardcoded.c +++ b/libappstream-builder/plugins/asb-plugin-hardcoded.c @@ -222,18 +222,6 @@ asb_plugin_process_app (AsbPlugin *plugin, as_app_add_veto (AS_APP (app), "Uses obsolete Elektra library"); break; } - if (g_strcmp0 (tmp, "libXt.so.6") == 0) { - asb_app_add_requires_appdata (app, "Uses obsolete X11 toolkit"); - break; - } - if (g_strcmp0 (tmp, "Xvfb") == 0) { - asb_app_add_requires_appdata (app, "Uses obsolete Xvfb"); - break; - } - if (g_strcmp0 (tmp, "wine-core") == 0) { - asb_app_add_requires_appdata (app, "Uses wine"); - break; - } } } @@ -261,21 +249,21 @@ asb_plugin_process_app (AsbPlugin *plugin, secs = (g_get_real_time () / G_USEC_PER_SEC) - as_release_get_timestamp (release); days = secs / (60 * 60 * 24); - /* we need AppData if the app needs saving */ if (secs > 0 && days > 365 * 5) { - asb_app_add_requires_appdata (app, - "Dead upstream for > %i years", 5); + asb_package_log (asb_app_get_package (app), + ASB_PACKAGE_LOG_LEVEL_WARNING, + "Dead upstream for > %i years", 5); } } /* a ConsoleOnly category means we require AppData */ if (as_app_has_category (AS_APP(app), "ConsoleOnly")) - asb_app_add_requires_appdata (app, "ConsoleOnly"); + as_app_add_veto (AS_APP (app), "ConsoleOnly"); - /* no categories means we require AppData */ - if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_DESKTOP && - as_app_get_categories(AS_APP(app))->len == 0) - asb_app_add_requires_appdata (app, "no Categories"); + /* no categories means veto */ +// if (as_app_get_id_kind (AS_APP (app)) == AS_ID_KIND_DESKTOP && +// as_app_get_categories(AS_APP(app))->len == 0) +// as_app_add_veto (AS_APP (app), "no Categories"); return TRUE; } diff --git a/libappstream-builder/plugins/asb-plugin-ibus-sql.c b/libappstream-builder/plugins/asb-plugin-ibus-sql.c deleted file mode 100644 index 6a6919c..0000000 --- a/libappstream-builder/plugins/asb-plugin-ibus-sql.c +++ /dev/null @@ -1,264 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com> - * - * Licensed under the GNU Lesser General Public License Version 2.1 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <config.h> -#include <fnmatch.h> -#include <sqlite3.h> - -#include <asb-plugin.h> - -/** - * asb_plugin_get_name: - */ -const gchar * -asb_plugin_get_name (void) -{ - return "ibus-sqlite"; -} - -/** - * asb_plugin_add_globs: - */ -void -asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) -{ - asb_plugin_add_glob (globs, "/usr/share/ibus-table/tables/*.db"); -} - -/** - * _asb_plugin_check_filename: - */ -static gboolean -_asb_plugin_check_filename (const gchar *filename) -{ - if (asb_plugin_match_glob ("/usr/share/ibus-table/tables/*.db", filename)) - return TRUE; - return FALSE; -} - -/** - * asb_plugin_check_filename: - */ -gboolean -asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) -{ - return _asb_plugin_check_filename (filename); -} - -/** - * asb_plugin_sqlite_callback_cb: - */ -static int -asb_plugin_sqlite_callback_cb (void *user_data, int argc, char **argv, char **data) -{ - gchar **tmp = (gchar **) user_data; - *tmp = g_strdup (argv[1]); - return 0; -} - -/** - * asb_plugin_process_filename: - */ -static gboolean -asb_plugin_process_filename (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *filename, - GList **apps, - const gchar *tmpdir, - GError **error) -{ - gboolean ret = TRUE; - gchar *error_msg = 0; - gchar *filename_tmp; - gint rc; - guint i; - sqlite3 *db = NULL; - g_autofree gchar *basename = NULL; - g_autofree gchar *description = NULL; - g_autofree gchar *language_string = NULL; - g_autofree gchar *name = NULL; - g_autofree gchar *symbol = NULL; - g_autoptr(AsbApp) app = NULL; - g_autoptr(AsIcon) icon = NULL; - g_auto(GStrv) languages = NULL; - - /* open IME database */ - filename_tmp = g_build_filename (tmpdir, filename, NULL); - rc = sqlite3_open (filename_tmp, &db); - if (rc) { - ret = FALSE; - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "Can't open database: %s", - sqlite3_errmsg (db)); - goto out; - } - - /* get name */ - rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'name' LIMIT 1;", - asb_plugin_sqlite_callback_cb, - &name, &error_msg); - if (rc != SQLITE_OK) { - ret = FALSE; - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "Can't get IME name from %s: %s", - filename, error_msg); - sqlite3_free(error_msg); - goto out; - } - - /* get symbol */ - rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'symbol' LIMIT 1;", - asb_plugin_sqlite_callback_cb, - &symbol, &error_msg); - if (rc != SQLITE_OK) { - ret = FALSE; - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "Can't get IME symbol from %s: %s", - filename, error_msg); - sqlite3_free(error_msg); - goto out; - } - - /* get languages */ - rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'languages' LIMIT 1;", - asb_plugin_sqlite_callback_cb, - &language_string, &error_msg); - if (rc != SQLITE_OK) { - ret = FALSE; - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "Can't get IME languages from %s: %s", - filename, error_msg); - sqlite3_free(error_msg); - goto out; - } - - /* get description */ - rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'description' LIMIT 1;", - asb_plugin_sqlite_callback_cb, - &description, &error_msg); - if (rc != SQLITE_OK) { - ret = FALSE; - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "Can't get IME name from %s: %s", - filename, error_msg); - sqlite3_free(error_msg); - goto out; - } - - /* this is _required_ */ - if (name == NULL || description == NULL) { - ret = FALSE; - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "No 'name' and 'description' in %s", - filename); - goto out; - } - - /* create new app */ - basename = g_path_get_basename (filename); - app = asb_app_new (pkg, basename); - as_app_set_id_kind (AS_APP (app), AS_ID_KIND_INPUT_METHOD); - as_app_add_category (AS_APP (app), "Addons"); - as_app_add_category (AS_APP (app), "InputSources"); - as_app_set_name (AS_APP (app), "C", name); - as_app_set_comment (AS_APP (app), "C", description); - if (symbol != NULL && symbol[0] != '\0') - as_app_add_metadata (AS_APP (app), "X-IBus-Symbol", symbol); - if (language_string != NULL) { - languages = g_strsplit (language_string, ",", -1); - for (i = 0; languages[i] != NULL; i++) { - if (g_strcmp0 (languages[i], "other") == 0) - continue; - as_app_add_language (AS_APP (app), - 100, languages[i]); - } - } - asb_app_set_requires_appdata (app, TRUE); - asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); - - /* add icon */ - icon = as_icon_new (); - as_icon_set_kind (icon, AS_ICON_KIND_STOCK); - as_icon_set_name (icon, "system-run-symbolic"); - as_app_add_icon (AS_APP (app), icon); - - asb_plugin_add_app (apps, AS_APP (app)); -out: - if (db != NULL) - sqlite3_close (db); - return ret; -} - -/** - * asb_plugin_process: - */ -GList * -asb_plugin_process (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *tmpdir, - GError **error) -{ - gboolean ret; - GList *apps = NULL; - guint i; - gchar **filelist; - - filelist = asb_package_get_filelist (pkg); - for (i = 0; filelist[i] != NULL; i++) { - if (!_asb_plugin_check_filename (filelist[i])) - continue; - ret = asb_plugin_process_filename (plugin, - pkg, - filelist[i], - &apps, - tmpdir, - error); - if (!ret) { - g_list_free_full (apps, (GDestroyNotify) g_object_unref); - apps = NULL; - goto out; - } - } - - /* no desktop files we care about */ - if (apps == NULL) { - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "nothing interesting in %s", - asb_package_get_basename (pkg)); - goto out; - } -out: - return apps; -} diff --git a/libappstream-builder/plugins/asb-plugin-ibus-xml.c b/libappstream-builder/plugins/asb-plugin-ibus-xml.c deleted file mode 100644 index f5180fb..0000000 --- a/libappstream-builder/plugins/asb-plugin-ibus-xml.c +++ /dev/null @@ -1,224 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com> - * - * Licensed under the GNU Lesser General Public License Version 2.1 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <config.h> -#include <fnmatch.h> -#include <sqlite3.h> -#include <appstream-glib.h> - -#include <asb-plugin.h> - -/** - * asb_plugin_get_name: - */ -const gchar * -asb_plugin_get_name (void) -{ - return "ibus-xml"; -} - -/** - * asb_plugin_add_globs: - */ -void -asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) -{ - asb_plugin_add_glob (globs, "/usr/share/ibus/component/*.xml"); -} - -/** - * _asb_plugin_check_filename: - */ -static gboolean -_asb_plugin_check_filename (const gchar *filename) -{ - if (asb_plugin_match_glob ("/usr/share/ibus/component/*.xml", filename)) - return TRUE; - return FALSE; -} - -/** - * asb_plugin_check_filename: - */ -gboolean -asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) -{ - return _asb_plugin_check_filename (filename); -} - -/** - * asb_plugin_process_filename: - */ -static gboolean -asb_plugin_process_filename (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *filename, - GList **apps, - const gchar *tmpdir, - GError **error) -{ - GNode *root = NULL; - GString *valid_xml; - const gchar *tmp; - const GNode *n; - gboolean found_header = FALSE; - gboolean ret; - guint i; - g_autofree gchar *basename = NULL; - g_autofree gchar *data = NULL; - g_autofree gchar *filename_tmp = NULL; - g_autoptr(AsbApp) app = NULL; - g_autoptr(AsIcon) icon = NULL; - g_auto(GStrv) languages = NULL; - g_auto(GStrv) lines = NULL; - - /* open file */ - filename_tmp = g_build_filename (tmpdir, filename, NULL); - ret = g_file_get_contents (filename_tmp, &data, NULL, error); - if (!ret) - goto out; - - /* some components start with a comment (invalid XML) and some - * don't even have '<?xml' -- try to fix up best we can */ - valid_xml = g_string_new (""); - lines = g_strsplit (data, "\n", -1); - for (i = 0; lines[i] != NULL; i++) { - if (g_str_has_prefix (lines[i], "<?xml") || - g_str_has_prefix (lines[i], "<component>")) - found_header = TRUE; - if (found_header) - g_string_append_printf (valid_xml, "%s\n", lines[i]); - } - - /* parse contents */ - root = as_node_from_xml (valid_xml->str, - AS_NODE_FROM_XML_FLAG_NONE, - error); - if (!ret) - goto out; - - /* create new app */ - basename = g_path_get_basename (filename); - app = asb_app_new (pkg, basename); - as_app_set_id_kind (AS_APP (app), AS_ID_KIND_INPUT_METHOD); - as_app_add_category (AS_APP (app), "Addons"); - as_app_add_category (AS_APP (app), "InputSources"); - asb_app_set_requires_appdata (app, TRUE); - asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); - - /* add icon */ - icon = as_icon_new (); - as_icon_set_kind (icon, AS_ICON_KIND_STOCK); - as_icon_set_name (icon, "system-run-symbolic"); - as_app_add_icon (AS_APP (app), icon); - - /* read the component header which all input methods have */ - n = as_node_find (root, "component/description"); - if (n != NULL) { - as_app_set_name (AS_APP (app), "C", as_node_get_data (n)); - as_app_set_comment (AS_APP (app), "C", as_node_get_data (n)); - } - n = as_node_find (root, "component/homepage"); - if (n != NULL) { - as_app_add_url (AS_APP (app), - AS_URL_KIND_HOMEPAGE, - as_node_get_data (n)); - } - - /* do we have a engine section we can use? */ - n = as_node_find (root, "component/engines/engine/longname"); - if (n != NULL) - as_app_set_name (AS_APP (app), "C", as_node_get_data (n)); - n = as_node_find (root, "component/engines/engine/description"); - if (n != NULL) - as_app_set_comment (AS_APP (app), "C", as_node_get_data (n)); - n = as_node_find (root, "component/engines/engine/symbol"); - if (n != NULL) { - tmp = as_node_get_data (n); - if (tmp != NULL && tmp[0] != '\0') { - as_app_add_metadata (AS_APP (app), - "X-IBus-Symbol", - tmp); - } - } - n = as_node_find (root, "component/engines/engine/language"); - if (n != NULL) { - tmp = as_node_get_data (n); - if (tmp != NULL) { - languages = g_strsplit (tmp, ",", -1); - for (i = 0; languages[i] != NULL; i++) { - if (g_strcmp0 (languages[i], "other") == 0) - continue; - as_app_add_language (AS_APP (app), - 100, languages[i]); - } - } - } - - /* add */ - asb_plugin_add_app (apps, AS_APP (app)); -out: - if (root != NULL) - as_node_unref (root); - return ret; -} - -/** - * asb_plugin_process: - */ -GList * -asb_plugin_process (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *tmpdir, - GError **error) -{ - gboolean ret; - GList *apps = NULL; - guint i; - gchar **filelist; - - filelist = asb_package_get_filelist (pkg); - for (i = 0; filelist[i] != NULL; i++) { - if (!_asb_plugin_check_filename (filelist[i])) - continue; - ret = asb_plugin_process_filename (plugin, - pkg, - filelist[i], - &apps, - tmpdir, - error); - if (!ret) { - g_list_free_full (apps, (GDestroyNotify) g_object_unref); - return NULL; - } - } - - /* no desktop files we care about */ - if (apps == NULL) { - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "nothing interesting in %s", - asb_package_get_basename (pkg)); - return NULL; - } - return apps; -} diff --git a/libappstream-builder/plugins/asb-plugin-metainfo.c b/libappstream-builder/plugins/asb-plugin-metainfo.c deleted file mode 100644 index 5f54d65..0000000 --- a/libappstream-builder/plugins/asb-plugin-metainfo.c +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com> - * - * Licensed under the GNU Lesser General Public License Version 2.1 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <config.h> -#include <fnmatch.h> - -#include <asb-plugin.h> - -/** - * asb_plugin_get_name: - */ -const gchar * -asb_plugin_get_name (void) -{ - return "metainfo"; -} - -/** - * asb_plugin_add_globs: - */ -void -asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) -{ - asb_plugin_add_glob (globs, "/usr/share/appdata/*.metainfo.xml"); -} - -/** - * _asb_plugin_check_filename: - */ -static gboolean -_asb_plugin_check_filename (const gchar *filename) -{ - if (asb_plugin_match_glob ("/usr/share/appdata/*.metainfo.xml", filename)) - return TRUE; - return FALSE; -} - -/** - * asb_plugin_check_filename: - */ -gboolean -asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) -{ - return _asb_plugin_check_filename (filename); -} - -/** - * asb_plugin_process_filename: - */ -static gboolean -asb_plugin_process_filename (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *filename, - GList **apps, - GError **error) -{ - g_autoptr(AsbApp) app = NULL; - - app = asb_app_new (pkg, NULL); - if (!as_app_parse_file (AS_APP (app), filename, - AS_APP_PARSE_FLAG_APPEND_DATA, - error)) - return FALSE; - if (as_app_get_id_kind (AS_APP (app)) != AS_ID_KIND_ADDON && - as_app_get_id_kind (AS_APP (app)) != AS_ID_KIND_FONT) { - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "%s is not an addon or font", - as_app_get_id (AS_APP (app))); - return FALSE; - } - asb_app_set_requires_appdata (app, FALSE); - asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); - asb_plugin_add_app (apps, AS_APP (app)); - return TRUE; -} - -/** - * asb_plugin_process: - */ -GList * -asb_plugin_process (AsbPlugin *plugin, - AsbPackage *pkg, - const gchar *tmpdir, - GError **error) -{ - gboolean ret; - GList *apps = NULL; - guint i; - gchar **filelist; - - filelist = asb_package_get_filelist (pkg); - for (i = 0; filelist[i] != NULL; i++) { - g_autofree gchar *filename_tmp = NULL; - if (!_asb_plugin_check_filename (filelist[i])) - continue; - filename_tmp = g_build_filename (tmpdir, filelist[i], NULL); - ret = asb_plugin_process_filename (plugin, - pkg, - filename_tmp, - &apps, - error); - if (!ret) { - g_list_free_full (apps, (GDestroyNotify) g_object_unref); - return NULL; - } - } - - /* no desktop files we care about */ - if (apps == NULL) { - g_set_error (error, - ASB_PLUGIN_ERROR, - ASB_PLUGIN_ERROR_FAILED, - "nothing interesting in %s", - asb_package_get_basename (pkg)); - return NULL; - } - return apps; -} - -/** - * asb_plugin_merge: - */ -void -asb_plugin_merge (AsbPlugin *plugin, GList *list) -{ - AsApp *app; - AsApp *found; - GList *l; - g_autoptr(GHashTable) hash = NULL; - - /* make a hash table of ID->AsApp */ - hash = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify) g_object_unref); - for (l = list; l != NULL; l = l->next) { - app = AS_APP (l->data); - if (as_app_get_id_kind (app) != AS_ID_KIND_DESKTOP) - continue; - g_hash_table_insert (hash, - g_strdup (as_app_get_id (app)), - g_object_ref (app)); - } - - /* add addons where the pkgname is different from the - * main package */ - for (l = list; l != NULL; l = l->next) { - if (!ASB_IS_APP (l->data)) - continue; - app = AS_APP (l->data); - if (as_app_get_id_kind (app) != AS_ID_KIND_ADDON) - continue; - found = g_hash_table_lookup (hash, as_app_get_id (app)); - if (found == NULL) - continue; - if (g_strcmp0 (as_app_get_pkgname_default (app), - as_app_get_pkgname_default (found)) != 0) - continue; - as_app_add_veto (app, - "absorbing addon %s shipped in " - "main package %s", - as_app_get_id (app), - as_app_get_pkgname_default (app)); - as_app_subsume_full (found, app, AS_APP_SUBSUME_FLAG_PARTIAL); - } -} diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c index 36632d7..d8076ca 100644 --- a/libappstream-glib/as-app-validate.c +++ b/libappstream-glib/as-app-validate.c @@ -1209,6 +1209,14 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error) "<pkgname> not allowed in metainfo"); } + /* appdata */ + if (as_app_get_icon_default (app) != NULL && + as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_APPDATA) { + ai_app_validate_add (&helper, + AS_PROBLEM_KIND_TAG_INVALID, + "<icon> not allowed in appdata"); + } + /* extends */ if (as_app_get_extends(app)->len == 0 && as_app_get_id_kind (app) == AS_ID_KIND_ADDON && |