Skip to content

Commit 19fea52

Browse files
committed
Drop support for old xml connection configs
1 parent 06bd25a commit 19fea52

File tree

6 files changed

+16
-221
lines changed

6 files changed

+16
-221
lines changed

src/app/app.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ void Application::initConnectionsManager()
184184
{
185185
//connection manager
186186
ConfigManager confManager(m_settingsDir);
187-
if (confManager.migrateOldConfig("connections.xml", "connections.json")) {
188-
LOG(INFO) << "Migrate connections.xml to connections.json";
189-
}
190187

191188
QString config = confManager.getApplicationConfigPath("connections.json");
192189

src/app/models/configmanager.cpp

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -34,121 +34,6 @@ QString ConfigManager::getApplicationConfigPath(const QString &configFile, bool
3434
return configPath;
3535
}
3636

37-
/**
38-
* @brief ConfigManager::migrateOldConfig
39-
* @param oldFileName - config.xml
40-
* @param newFileName - config.json
41-
* @return true or false
42-
*/
43-
bool ConfigManager::migrateOldConfig(const QString &oldFileName, const QString &newFileName)
44-
{
45-
QString jsonConfigPath = getApplicationConfigPath(newFileName, false);
46-
47-
if (QFile::exists(jsonConfigPath)) {
48-
qDebug() << "New config already exist. Ignore old configs.";
49-
return false;
50-
}
51-
52-
// Move config from 0.7.5 or older to appropriate directory
53-
QString homeConfig = QString("%1/%2").arg(m_basePath).arg(oldFileName);
54-
55-
QString xmlConfigPath = getApplicationConfigPath(oldFileName, false);
56-
57-
if (xmlConfigPath.isEmpty())
58-
return false;
59-
60-
if (QFile::exists(homeConfig)) {
61-
qDebug() << "Config migration: 0.7.5 config detected.";
62-
QFile::remove(xmlConfigPath);
63-
if (QFile::copy(homeConfig, xmlConfigPath)
64-
&& QFile::remove(homeConfig)) {
65-
qDebug() << "Old config moved to new dir";
66-
}
67-
}
68-
69-
if (!QFile::exists(xmlConfigPath))
70-
return false;
71-
72-
QJsonArray newConfig = xmlConfigToJsonArray(xmlConfigPath);
73-
74-
QFile::rename(xmlConfigPath, QString("%1.backup").arg(xmlConfigPath));
75-
76-
if (newConfig.size() == 0)
77-
return false;
78-
79-
return saveJsonArrayToFile(newConfig, jsonConfigPath);
80-
}
81-
82-
/**
83-
* @brief ConfigManager::xmlConfigToJsonArray - Migrate XML config to JSON array
84-
* @param xmlConfigPath
85-
* @return
86-
*/
87-
QJsonArray ConfigManager::xmlConfigToJsonArray(const QString &xmlConfigPath)
88-
{
89-
LOG(WARNING) << "XML support is deprecated and will be removed in RDM 1.0";
90-
QJsonArray newConfig;
91-
92-
QFile* xmlConfigfile = new QFile(xmlConfigPath);
93-
if (!xmlConfigfile->open(QIODevice::ReadOnly | QIODevice::Text))
94-
return newConfig;
95-
96-
QXmlStreamReader xml(xmlConfigfile);
97-
98-
QHash<QString, QString> attrMapping ({
99-
{"sshHost", "ssh_host"},
100-
{"sshUser", "ssh_user"},
101-
{"sshPassword", "ssh_password"},
102-
{"sshPort", "ssh_port"},
103-
{"sshPrivateKey", "ssh_private_key_path"},
104-
{"namespaceSeparator", "namespace_separator"},
105-
{"connectionTimeout", "timeout_connect"},
106-
{"executeTimeout", "timeout_execute"},
107-
});
108-
109-
while (!xml.atEnd() && !xml.hasError())
110-
{
111-
QXmlStreamReader::TokenType token = xml.readNext();
112-
if (token == QXmlStreamReader::StartDocument)
113-
continue;
114-
if (token == QXmlStreamReader::StartElement)
115-
{
116-
if (xml.name() == "connections")
117-
continue;
118-
if (xml.name() == "connection") {
119-
QXmlStreamAttributes attributes = xml.attributes();
120-
121-
QString name, value;
122-
QVariantHash connection;
123-
124-
for (QXmlStreamAttribute attr : attributes) {
125-
name = attr.name().toString();
126-
if (attrMapping.contains(name)) {
127-
name = attrMapping[name];
128-
}
129-
130-
value = attr.value().toString();
131-
132-
if (name.contains("port") || name.contains("timeout")) {
133-
connection.insert(name, value.toInt());
134-
} else {
135-
connection.insert(name, value);
136-
}
137-
}
138-
139-
// NOTE(u_glide): We should add NS separator to new config
140-
if (!connection.contains("namespace_separator")) {
141-
connection.insert("namespace_separator",
142-
QString(ServerConfig::DEFAULT_NAMESPACE_SEPARATOR));
143-
}
144-
145-
newConfig.append(QJsonObjectFromVariantHash(connection));
146-
}
147-
}
148-
}
149-
return newConfig;
150-
}
151-
15237
bool ConfigManager::chechPath(const QString &configPath)
15338
{
15439
QFile testConfig(configPath);

src/app/models/configmanager.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ class ConfigManager
88
{
99
public:
1010
ConfigManager(const QString& basePath = QDir::homePath());
11-
QString getApplicationConfigPath(const QString &, bool checkPath=true);
12-
bool migrateOldConfig(const QString &oldFileName, const QString &newFileName);
11+
QString getApplicationConfigPath(const QString &, bool checkPath=true);
1312
public:
14-
static QString getConfigPath(QString basePath = QDir::homePath());
15-
static QJsonArray xmlConfigToJsonArray(const QString &xmlConfigPath);
13+
static QString getConfigPath(QString basePath = QDir::homePath());
1614

1715
private:
1816
static bool chechPath(const QString&);

src/app/models/connectionsmanager.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,26 @@ bool ConnectionsManager::loadConnectionsConfigFromFile(const QString& config, bo
100100
{
101101
QJsonArray connections;
102102

103-
if (config.endsWith(".xml")) {
104-
connections = ConfigManager::xmlConfigToJsonArray(config);
105-
} else {
106-
QFile conf(config);
103+
QFile conf(config);
107104

108-
if (!conf.open(QIODevice::ReadOnly))
109-
return false;
110-
111-
QByteArray data = conf.readAll();
112-
conf.close();
105+
if (!conf.open(QIODevice::ReadOnly))
106+
return false;
113107

114-
QJsonDocument jsonConfig = QJsonDocument::fromJson(data);
108+
QByteArray data = conf.readAll();
109+
conf.close();
115110

116-
if (jsonConfig.isEmpty())
117-
return true;
111+
QJsonDocument jsonConfig = QJsonDocument::fromJson(data);
118112

119-
if (!jsonConfig.isArray()) {
120-
return false;
121-
}
113+
if (jsonConfig.isEmpty())
114+
return true;
122115

123-
connections = jsonConfig.array();
116+
if (!jsonConfig.isArray()) {
117+
return false;
124118
}
125119

120+
connections = jsonConfig.array();
121+
122+
126123
for (QJsonValue connection : connections) {
127124
if (!connection.isObject())
128125
continue;

tests/unit_tests/testcases/app/test_configmanager.cpp

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -29,83 +29,3 @@ void TestConfigManager::testGetApplicationConfigPath()
2929
actual_result);
3030
QCOMPARE(check_path, QFile::exists(actual_result));
3131
}
32-
33-
void TestConfigManager::testMigrateOldConfig()
34-
{
35-
#ifdef Q_OS_MACX
36-
QSKIP("SKIP ON OSX");
37-
#endif
38-
#ifdef Q_OS_WIN
39-
QSKIP("SKIP ON Windows");
40-
#endif
41-
// Given
42-
QTemporaryDir tmpDir;
43-
tmpDir.setAutoRemove(true);
44-
QString basePath = tmpDir.path();
45-
ConfigManager manager(basePath);
46-
qDebug() << "Base path:" << basePath;
47-
48-
// When
49-
// Case 1 - Migrate from old versions (<= 0.7.6)
50-
// cp connections.xml to temp dir
51-
QString targetConfigPath = QString("%1/connections.xml").arg(basePath);
52-
QVERIFY(QFile::copy("./unit_tests/testcases/app/connections.xml", targetConfigPath));
53-
54-
bool actual_result = manager.migrateOldConfig("connections.xml", "connections.json");
55-
56-
// Then
57-
QCOMPARE(true, actual_result);
58-
// check that connections.xml doesn't exist in base dir
59-
QCOMPARE(false, QFile::exists(targetConfigPath));
60-
// check that .rdm dir exist in base path
61-
QDir configDir(QString("%1/.rdm").arg(basePath));
62-
QCOMPARE(true, configDir.exists());
63-
// check that .rdm/connections.json exists
64-
QFile newConfig(QString("%1/.rdm/connections.json").arg(basePath));
65-
QCOMPARE(true, newConfig.exists());
66-
// check that .rdm/connections.xml.backup exists
67-
QFile oldConfigBackup(QString("%1/.rdm/connections.xml.backup").arg(basePath));
68-
QCOMPARE(true, oldConfigBackup.exists());
69-
// check that .rdm/connections.xml doesn't exist
70-
QCOMPARE(false, QFile::exists(QString("%1/.rdm/connections.xml").arg(basePath)));
71-
// check that backup and new config is not empty
72-
QCOMPARE(true, newConfig.size() > 0);
73-
QCOMPARE(true, oldConfigBackup.size() > 0);
74-
75-
// Clean run - Run on (>= 0.8.0) when connections.xml doesn't exist
76-
// Check that connections.xml not created
77-
actual_result = manager.migrateOldConfig("connections.xml", "connections.json");
78-
QCOMPARE(false, QFile::exists(targetConfigPath));
79-
QCOMPARE(false, QFile::exists(QString("%1/.rdm/connections.xml").arg(basePath)));
80-
81-
// Negative run
82-
// connections.xml, .rdm/connections.xml and .rdm/connections.json exist
83-
QVERIFY(QFile::copy("./unit_tests/testcases/app/connections.xml", targetConfigPath));
84-
QVERIFY(QFile::copy("./unit_tests/testcases/app/connections.xml",
85-
QString("%1/.rdm/connections.xml").arg(basePath)));
86-
QFileInfo configInfo(newConfig);
87-
QDateTime currentModificationTime = configInfo.lastModified();
88-
89-
actual_result = manager.migrateOldConfig("connections.xml", "connections.json");
90-
// Check that old files are untouched and connections.json is not updated
91-
QCOMPARE(false, actual_result);
92-
QCOMPARE(true, QFile::exists(targetConfigPath));
93-
QCOMPARE(true, QFile::exists(QString("%1/.rdm/connections.xml").arg(basePath)));
94-
configInfo.refresh();
95-
QCOMPARE(currentModificationTime, configInfo.lastModified());
96-
}
97-
98-
void TestConfigManager::testXmlConfigToJsonArray()
99-
{
100-
// Given
101-
QString pathToXmlConfig("./unit_tests/testcases/app/connections.xml");
102-
103-
// When
104-
QJsonArray actual_result = ConfigManager::xmlConfigToJsonArray(pathToXmlConfig);
105-
106-
// Then
107-
// Check that resulting array contains namespace separator if it missing in original XML
108-
for (auto connection : actual_result) {
109-
QCOMPARE(QString(":"), connection.toObject()["namespace_separator"].toString());
110-
}
111-
}

tests/unit_tests/testcases/app/test_configmanager.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class TestConfigManager : public BaseTestCase
55
{
66
Q_OBJECT
77
private slots:
8-
void testGetApplicationConfigPath();
9-
void testMigrateOldConfig();
10-
void testXmlConfigToJsonArray();
8+
void testGetApplicationConfigPath();
119
};
1210

0 commit comments

Comments
 (0)