Merge lp:~ted/ubuntu-app-launch/reenable-only-show-in into lp:ubuntu-app-launch

Proposed by Ted Gould
Status: Merged
Approved by: Ted Gould
Approved revision: 241
Merged at revision: 273
Proposed branch: lp:~ted/ubuntu-app-launch/reenable-only-show-in
Merge into: lp:ubuntu-app-launch
Diff against target: 193 lines (+94/-16)
2 files modified
libubuntu-app-launch/application-info-desktop.cpp (+49/-5)
tests/application-info-desktop.cpp (+45/-11)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/reenable-only-show-in
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
unity-api-1-bot continuous-integration Needs Fixing
Lukáš Tinkl (community) Needs Fixing
Iain Lane Pending
Larry Price Pending
PS Jenkins bot continuous-integration Pending
Review via email: mp+310213@code.launchpad.net

This proposal supersedes a proposal from 2016-05-10.

Commit message

Reenable OnlyShowIn checking for Desktop files

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:231
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/5/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/113/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/120
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/72
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/72
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/72
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/55/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/55/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/55/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/55/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/55
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/55/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/55
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/55/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/55/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/55/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/55/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/5/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:232
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/22/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/283/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/289
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/223
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/223
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/223
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/152/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/152
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/152/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/152
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/152/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/152/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/152/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/152/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/152/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/152
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/152/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/152
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/152/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/22/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote : Posted in a previous version of this proposal

hooray! looks good to me

review: Approve
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote : Posted in a previous version of this proposal

You need to split the XDG_CURRENT_DESKTOP value on ":" and look at each part separately, I'm afraid.

See https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html "OnlyShowIn".

review: Needs Fixing
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Lukáš Tinkl (lukas-kde) wrote :

Text conflict in tests/application-info-desktop.cpp

review: Needs Fixing
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
234. By Ted Gould

Merge trunk

235. By Ted Gould

Update to new Desktop object

236. By Ted Gould

Try to split out CURRENT_DESKTOP

237. By Ted Gould

First pass doing set comparisons of the lists

238. By Ted Gould

Switch to find_first_of

239. By Ted Gould

Typo on name

240. By Ted Gould

Fix variable name

241. By Ted Gould

Add some more tests for sets

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:241
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/166/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1363/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1370
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1148/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1148
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1148/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1148
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1148/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1148
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1148/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1148
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1148/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1148
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1148/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/166/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Minor suggestions & random drunken comments inline

review: Approve
Revision history for this message
Ted Gould (ted) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntu-app-launch/application-info-desktop.cpp'
2--- libubuntu-app-launch/application-info-desktop.cpp 2016-09-14 16:42:20 +0000
3+++ libubuntu-app-launch/application-info-desktop.cpp 2017-01-13 03:03:05 +0000
4@@ -20,6 +20,7 @@
5 #include "application-info-desktop.h"
6 #include "application-icon-finder.h"
7 #include "registry-impl.h"
8+#include <algorithm>
9 #include <cstdlib>
10
11 namespace ubuntu
12@@ -30,6 +31,25 @@
13 {
14 namespace
15 {
16+
17+static std::set<std::string> strvToSet(gchar** strv)
18+{
19+ std::set<std::string> retval;
20+
21+ if (strv != nullptr)
22+ {
23+ for (int i = 0; strv[i] != nullptr; i++)
24+ {
25+ if (strv[i][0] != '\0')
26+ {
27+ retval.emplace(strv[i]);
28+ }
29+ }
30+ }
31+
32+ return retval;
33+}
34+
35 constexpr const char* DESKTOP_GROUP = "Desktop Entry";
36
37 struct TypeTag;
38@@ -224,6 +244,21 @@
39 return result;
40 }
41
42+std::set<std::string> stringlistFromKeyfileSet(const std::shared_ptr<GKeyFile>& keyfile, const gchar* key)
43+{
44+ GError* error = nullptr;
45+ auto results = g_key_file_get_string_list(keyfile.get(), DESKTOP_GROUP, key, nullptr, &error);
46+ if (error != nullptr)
47+ {
48+ g_error_free(error);
49+ return {};
50+ }
51+
52+ auto retval = strvToSet(results);
53+ g_strfreev(results);
54+ return retval;
55+}
56+
57 Desktop::Desktop(const std::shared_ptr<GKeyFile>& keyfile,
58 const std::string& basePath,
59 const std::string& rootDir,
60@@ -250,12 +285,21 @@
61 auto xdg_current_desktop = getenv("XDG_CURRENT_DESKTOP");
62 if (xdg_current_desktop != nullptr)
63 {
64- if (stringlistFromKeyfileContains(keyfile, "NotShowIn", xdg_current_desktop, false) ||
65- !stringlistFromKeyfileContains(keyfile, "OnlyShowIn", xdg_current_desktop, true))
66+ /* Split the CURRENT_DESKTOP by colons if there are multiple */
67+ auto current_desktops = g_strsplit(xdg_current_desktop, ":", -1);
68+ auto cdesktops = strvToSet(current_desktops);
69+ g_strfreev(current_desktops);
70+
71+ auto onlyshowin = stringlistFromKeyfileSet(keyfile, "OnlyShowIn");
72+ auto noshowin = stringlistFromKeyfileSet(keyfile, "NotShowIn");
73+
74+ auto hasAnyOf = [](std::set<std::string>& a, std::set<std::string>& b) {
75+ return std::find_first_of(a.cbegin(), a.cend(), b.cbegin(), b.cend()) != a.cend();
76+ };
77+
78+ if ((!hasAnyOf(onlyshowin, cdesktops) && !onlyshowin.empty()) || hasAnyOf(noshowin, cdesktops))
79 {
80- g_warning("Application is not shown in Unity");
81- // Exception removed for OTA11 as a temporary fix
82- // throw std::runtime_error("Application is not shown in Unity");
83+ throw std::runtime_error("Application is not shown in '" + std::string{xdg_current_desktop} + "'");
84 }
85 }
86
87
88=== modified file 'tests/application-info-desktop.cpp'
89--- tests/application-info-desktop.cpp 2016-09-14 16:43:36 +0000
90+++ tests/application-info-desktop.cpp 2017-01-13 03:03:05 +0000
91@@ -30,13 +30,13 @@
92 {
93 protected:
94 ApplicationInfoDesktop()
95- : test_dekstop_env("SomeFreeDesktop")
96+ : test_desktop_env("SomeFreeDesktop")
97 {
98 }
99
100 virtual void SetUp()
101 {
102- setenv("XDG_CURRENT_DESKTOP", test_dekstop_env.c_str(), true);
103+ setenv("XDG_CURRENT_DESKTOP", test_desktop_env.c_str(), true);
104 }
105
106 virtual void TearDown()
107@@ -53,7 +53,7 @@
108 return keyfile;
109 }
110
111- const std::string test_dekstop_env;
112+ const std::string test_desktop_env;
113 };
114
115 TEST_F(ApplicationInfoDesktop, DefaultState)
116@@ -120,18 +120,19 @@
117 ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr),
118 std::runtime_error);
119
120-/* Disabling for OTA11 */
121-#if 0
122 // not shown in Unity
123 auto notshowin = defaultKeyfile();
124- g_key_file_set_string(notshowin.get(), DESKTOP, "NotShowIn", ("Gnome;" + test_dekstop_env + ";").c_str());
125- EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(notshowin, "/"), std::runtime_error);
126+ g_key_file_set_string(notshowin.get(), DESKTOP, "NotShowIn", ("Gnome;" + test_desktop_env + ";").c_str());
127+ EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(notshowin, "/", {},
128+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr),
129+ std::runtime_error);
130
131 // only show in not Unity
132 auto onlyshowin = defaultKeyfile();
133 g_key_file_set_string(onlyshowin.get(), DESKTOP, "OnlyShowIn", "KDE;Gnome;");
134- EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(onlyshowin, "/"), std::runtime_error);
135-#endif
136+ EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(onlyshowin, "/", {},
137+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr),
138+ std::runtime_error);
139 }
140
141 TEST_F(ApplicationInfoDesktop, KeyfileIconPatterns)
142@@ -191,16 +192,49 @@
143
144 // Appearing explicitly in only show list
145 auto onlyshowin = defaultKeyfile();
146- g_key_file_set_string(onlyshowin.get(), DESKTOP, "OnlyShowIn", (test_dekstop_env + ";Gnome;").c_str());
147+ g_key_file_set_string(onlyshowin.get(), DESKTOP, "OnlyShowIn", (test_desktop_env + ";Gnome;").c_str());
148 EXPECT_NO_THROW(ubuntu::app_launch::app_info::Desktop(onlyshowin, "/", {},
149 ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr));
150
151 // Appearing explicitly in only show list not first
152 auto onlyshowinmiddle = defaultKeyfile();
153 g_key_file_set_string(onlyshowinmiddle.get(), DESKTOP, "OnlyShowIn",
154- ("Gnome;" + test_dekstop_env + ";KDE;").c_str());
155+ ("Gnome;" + test_desktop_env + ";KDE;").c_str());
156 EXPECT_NO_THROW(ubuntu::app_launch::app_info::Desktop(onlyshowinmiddle, "/", {},
157 ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr));
158+
159+ // Chance current to be a list
160+ setenv("XDG_CURRENT_DESKTOP", ("notafreedesktop:" + test_desktop_env + "::someotherdesktop").c_str(), true);
161+
162+ // Make sure we can parse it and just not blow up
163+ auto base = defaultKeyfile();
164+ EXPECT_NO_THROW(ubuntu::app_launch::app_info::Desktop(base, "/", {},
165+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr));
166+
167+ // Put in both, make sure we reject
168+ auto everything = defaultKeyfile();
169+ g_key_file_set_string(everything.get(), DESKTOP, "OnlyShowIn", ("Gnome;" + test_desktop_env + ";KDE;").c_str());
170+ g_key_file_set_string(everything.get(), DESKTOP, "NotShowIn", ("Gnome;" + test_desktop_env + ";").c_str());
171+ EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(everything, "/", {},
172+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr),
173+ std::runtime_error);
174+
175+ // Reject us
176+ auto notlist = defaultKeyfile();
177+ g_key_file_set_string(notlist.get(), DESKTOP, "NotShowIn", ("Gnome;Foo;" + test_desktop_env + ";KDE;").c_str());
178+ EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(notlist, "/", {},
179+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr),
180+ std::runtime_error);
181+
182+ // Only Show us
183+ g_key_file_set_string(onlyshowin.get(), DESKTOP, "OnlyShowIn", (test_desktop_env + ";Gnome;").c_str());
184+ EXPECT_NO_THROW(ubuntu::app_launch::app_info::Desktop(onlyshowin, "/", {},
185+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr));
186+
187+ // Make sure we can still go with nothing set
188+ auto notset = defaultKeyfile();
189+ EXPECT_NO_THROW(ubuntu::app_launch::app_info::Desktop(notset, "/", {},
190+ ubuntu::app_launch::app_info::DesktopFlags::NONE, nullptr));
191 }
192
193 TEST_F(ApplicationInfoDesktop, Orientations)

Subscribers

People subscribed via source and target branches