Skip to content

Commit 714ef57

Browse files
authored
Merge pull request #75 from commontk/expand-placeholders
Expand placeholders
2 parents 04b1120 + 1f6b6b3 commit 714ef57

10 files changed

+53
-24
lines changed

Base/ctkAppLauncherSettings.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,9 @@ void ctkAppLauncherSettingsPrivate::readPathSettings(QSettings& settings)
161161
// --------------------------------------------------------------------------
162162
QString ctkAppLauncherSettingsPrivate::expandValue(const QString& value) const
163163
{
164-
QHash<QString, QString> mapOfEnvVars = this->MapOfExpandedEnvVars;
165-
QHash<QString, QString> keyValueMap;
166-
keyValueMap["<APPLAUNCHER_DIR>"] = this->LauncherDir;
167-
keyValueMap["<APPLAUNCHER_NAME>"] = this->LauncherName;
168-
keyValueMap["<PATHSEP>"] = this->PathSep;
164+
QString updatedValue = this->expandPlaceHolders(value);
169165

170-
QString updatedValue = value;
171-
foreach(const QString& key, keyValueMap.keys())
172-
{
173-
updatedValue.replace(key, keyValueMap.value(key), Qt::CaseInsensitive);
174-
}
166+
QHash<QString, QString> mapOfEnvVars = this->MapOfExpandedEnvVars;
175167

176168
// Consider environment expression
177169
QRegExp regex("\\<env\\:([a-zA-Z0-9\\-\\_]+)\\>");
@@ -195,6 +187,22 @@ QString ctkAppLauncherSettingsPrivate::expandValue(const QString& value) const
195187
return updatedValue;
196188
}
197189

190+
// --------------------------------------------------------------------------
191+
QString ctkAppLauncherSettingsPrivate::expandPlaceHolders(const QString& value) const
192+
{
193+
QHash<QString, QString> keyValueMap;
194+
keyValueMap["<APPLAUNCHER_DIR>"] = this->LauncherDir;
195+
keyValueMap["<APPLAUNCHER_NAME>"] = this->LauncherName;
196+
keyValueMap["<PATHSEP>"] = this->PathSep;
197+
198+
QString updatedValue = value;
199+
foreach(const QString& key, keyValueMap.keys())
200+
{
201+
updatedValue.replace(key, keyValueMap.value(key), Qt::CaseInsensitive);
202+
}
203+
return updatedValue;
204+
}
205+
198206
// --------------------------------------------------------------------------
199207
void ctkAppLauncherSettingsPrivate::expandEnvVars()
200208
{
@@ -235,7 +243,7 @@ void ctkAppLauncherSettingsPrivate::expandEnvVars()
235243
}
236244
previousPos = pos;
237245
}
238-
expanded[key] = value;
246+
expanded[key] = this->expandPlaceHolders(value);
239247
}
240248
this->MapOfExpandedEnvVars = expanded;
241249
}

Base/ctkAppLauncherSettings_p.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ class ctkAppLauncherSettingsPrivate : public QObject
3636
};
3737

3838
/// \brief Expand setting \a value
39-
/// The following string will be updated:
39+
///
40+
/// The following placeholder strings will be updated:
4041
/// <ul>
4142
/// <li>&lt;APPLAUNCHER_DIR&gt; -> LauncherDir</li>
4243
/// <li>&lt;APPLAUNCHER_NAME&gt; -> LauncherName</li>
4344
/// <li>&lt;PATHSEP&gt; -> PathSep</li>
4445
/// <li>&lt;env:VARNAME&gt; -> If any, expand to corresponding system environment variable</li>
4546
/// </ul>
47+
///
48+
/// \sa expandPlaceHolders()
4649
QString expandValue(const QString& value) const;
4750

51+
QString expandPlaceHolders(const QString& value) const;
52+
4853
void expandEnvVars();
4954
QHash<QString, QString> MapOfExpandedEnvVars;
5055

Testing/Launcher/App4ConfigureLauncherTest-expected-buildtree-settings.cmake.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(CTKAPPLAUNCHER_PATHS "1\\path=<APPLAUNCHER_DIR>/dog
77
2\\path=<APPLAUNCHER_DIR>/cat
88
size=2")
99
set(CTKAPPLAUNCHER_ENVVARS "BAR=NONE
10+
PLACEHOLDER=build-<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>
1011
")
1112
set(CTKAPPLAUNCHER_ADDITIONAL_PATH_ENVVARS "PYTHONPATH,QT_PLUGIN_PATH")
1213
set(CTKAPPLAUNCHER_ADDITIONAL_PATHS "
@@ -18,4 +19,3 @@ size=1
1819
[QT_PLUGIN_PATH]
1920
1\\path=<APPLAUNCHER_DIR>/build/libexec/qt
2021
size=1")
21-

Testing/Launcher/App4ConfigureLauncherTest-expected-installtree-settings.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(CTKAPPLAUNCHER_PATHS "1\\path=<APPLAUNCHER_DIR>/cow
77
2\\path=<APPLAUNCHER_DIR>/pig
88
size=2")
99
set(CTKAPPLAUNCHER_ENVVARS "BAR=ASSOCIATION
10+
PLACEHOLDER=install-<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>
1011
")
1112
set(CTKAPPLAUNCHER_ADDITIONAL_PATH_ENVVARS "PYTHONPATH,QT_PLUGIN_PATH")
1213
set(CTKAPPLAUNCHER_ADDITIONAL_PATHS "

Testing/Launcher/App4ConfigureLauncherTest/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ ctkAppLauncherConfigure(
3939
PATHS_INSTALLED "<APPLAUNCHER_DIR>/cow;<APPLAUNCHER_DIR>/pig"
4040
LIBRARY_PATHS_BUILD "<APPLAUNCHER_DIR>/build/lib"
4141
LIBRARY_PATHS_INSTALLED "<APPLAUNCHER_DIR>/lib"
42-
ENVVARS_BUILD "BAR=NONE"
43-
ENVVARS_INSTALLED "BAR=ASSOCIATION"
42+
ENVVARS_BUILD "BAR=NONE" "PLACEHOLDER=build-<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>"
43+
ENVVARS_INSTALLED "BAR=ASSOCIATION" "PLACEHOLDER=install-<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>"
4444
ADDITIONAL_PATH_ENVVARS_BUILD "PYTHONPATH;QT_PLUGIN_PATH"
4545
ADDITIONAL_PATH_ENVVARS_INSTALLED "PYTHONPATH;QT_PLUGIN_PATH"
4646
ADDITIONAL_PATH_ENVVARS_PREFIX TEST_

Testing/Launcher/App4ConfigureLauncherTestLauncherSettings.ini.expected.in

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ size=2
2929

3030
[EnvironmentVariables]
3131
BAR=NONE
32+
PLACEHOLDER=build-<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>
3233

3334

3435

Testing/Launcher/App4ConfigureLauncherTestLauncherSettingsToInstall.ini.expected.in

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ size=2
2929

3030
[EnvironmentVariables]
3131
BAR=ASSOCIATION
32+
PLACEHOLDER=install-<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>
3233

3334

3435

Testing/Launcher/ConfiguredAppLauncher-ConfigurationContents.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ function(compare_files ACTUAL EXPECTED)
99
string(CONFIGURE "${expected}" expected @ONLY)
1010
string(STRIP "${expected}" expected)
1111
if(NOT "${actual}" STREQUAL "${expected}")
12-
message(FATAL_ERROR "Content validation of '${ACTUAL}' failed:
12+
message(FATAL_ERROR "Content validation failed:
13+
ACTUAL: ${ACTUAL}
14+
EXPECTED: ${EXPECTED}
1315
1416
--
1517
expected content:

Testing/LauncherLib/AppWithLauncherLib/launcher-settings.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ organizationName=Kitware
1414
size=3
1515

1616
[Paths]
17-
1\path=<APPLAUNCHER_DIR>/cow
17+
1\path=<APPLAUNCHER_DIR>/cow/<APPLAUNCHER_NAME>
1818
2\path=/path/to/pig-<env:BOTH>
1919
3\path=/path/to/<env:PET>
2020
size=3
@@ -23,6 +23,7 @@ size=3
2323
BAR=ASSOCIATION
2424
PET=dog
2525
BOTH=cat-and-<env:PET>
26+
PLACEHOLDER=<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>
2627

2728
[PYTHONPATH]
2829
1\path=<APPLAUNCHER_DIR>/lib/python/site-packages

Testing/LauncherLib/AppWithLauncherLib/main.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int checkReadSettingsWithoutExpand()
210210
CHECK_QSTRINGLIST(
211211
appLauncherSettings.paths(/* expand= */ false),
212212
QStringList()
213-
<< "<APPLAUNCHER_DIR>/cow"
213+
<< "<APPLAUNCHER_DIR>/cow/<APPLAUNCHER_NAME>"
214214
<< "/path/to/pig-<env:BOTH>"
215215
<< "/path/to/<env:PET>"
216216
);
@@ -238,6 +238,11 @@ int checkReadSettingsWithoutExpand()
238238
"cat-and-<env:PET>"
239239
);
240240

241+
CHECK_QSTRING(
242+
appLauncherSettings.envVar("PLACEHOLDER", /* expand= */ false),
243+
"<APPLAUNCHER_DIR>-<APPLAUNCHER_NAME>"
244+
);
245+
241246
#if defined(Q_OS_WIN32)
242247
CHECK_QSTRING(
243248
appLauncherSettings.envVar("PYTHONPATH", /* expand= */ false),
@@ -285,7 +290,7 @@ int checkReadSettingsWithoutExpand()
285290
CHECK_QSTRINGLIST(
286291
pathsEnvVars.value("PATH"),
287292
QStringList()
288-
<< "<APPLAUNCHER_DIR>/cow"
293+
<< "<APPLAUNCHER_DIR>/cow/<APPLAUNCHER_NAME>"
289294
<< "/path/to/pig-<env:BOTH>"
290295
<< "/path/to/<env:PET>"
291296
<< "/path/to/libA"
@@ -296,7 +301,7 @@ int checkReadSettingsWithoutExpand()
296301
CHECK_QSTRINGLIST(
297302
pathsEnvVars.value("PATH"),
298303
QStringList()
299-
<< "<APPLAUNCHER_DIR>/cow"
304+
<< "<APPLAUNCHER_DIR>/cow/<APPLAUNCHER_NAME>"
300305
<< "/path/to/pig-<env:BOTH>"
301306
<< "/path/to/<env:PET>"
302307
);
@@ -355,7 +360,7 @@ int checkReadSettingsWithExpand()
355360
CHECK_QSTRINGLIST(
356361
appLauncherSettings.paths(),
357362
QStringList()
358-
<< "/awesome/path/to/cow"
363+
<< "/awesome/path/to/cow/AwesomeApp"
359364
<< "/path/to/pig-cat-and-dog"
360365
<< "/path/to/dog"
361366
);
@@ -383,6 +388,11 @@ int checkReadSettingsWithExpand()
383388
"cat-and-dog"
384389
);
385390

391+
CHECK_QSTRING(
392+
appLauncherSettings.envVar("PLACEHOLDER"),
393+
"/awesome/path/to-AwesomeApp"
394+
);
395+
386396
#if defined(Q_OS_WIN32)
387397
CHECK_QSTRING(
388398
appLauncherSettings.envVar("PYTHONPATH"),
@@ -444,7 +454,7 @@ int checkReadSettingsWithExpand()
444454
CHECK_QSTRINGLIST(
445455
pathsEnvVars.value("PATH"),
446456
QStringList()
447-
<< "/awesome/path/to/cow"
457+
<< "/awesome/path/to/cow/AwesomeApp"
448458
<< "/path/to/pig-cat-and-dog"
449459
<< "/path/to/dog"
450460
<< "/path/to/libA"
@@ -455,7 +465,7 @@ int checkReadSettingsWithExpand()
455465
CHECK_QSTRINGLIST(
456466
pathsEnvVars.value("PATH"),
457467
QStringList()
458-
<< "/awesome/path/to/cow"
468+
<< "/awesome/path/to/cow/AwesomeApp"
459469
<< "/path/to/pig-cat-and-dog"
460470
<< "/path/to/dog"
461471
);
@@ -563,7 +573,7 @@ int checkReadAdditionalSettingsWithExpand()
563573
<< "/awesome/path/to/fawn"
564574
<< "/path/to/cat-and-dog"
565575
<< "/path/to/Klimt"
566-
<< "/awesome/path/to/cow"
576+
<< QString("/awesome/path/to/cow/%1").arg(appName)
567577
<< "/path/to/pig-cat-and-dog"
568578
<< "/path/to/dog"
569579
);

0 commit comments

Comments
 (0)