Move URL utilities from ProjectExplorer to Utils

This way we can access them from the qmldebug library.

Change-Id: I90ba80228f44a9d5ea825ad59f4bd1572969980e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Ulf Hermann
2017-09-29 12:41:53 +02:00
parent 2f9d82791e
commit fb370f460d
12 changed files with 144 additions and 72 deletions

View File

@@ -31,7 +31,7 @@
#include <qmldebug/qmldebugconnection.h>
#include <utils/qtcassert.h>
#include <projectexplorer/runnables.h>
#include <utils/url.h>
namespace QmlProfiler {
namespace Internal {
@@ -75,9 +75,9 @@ void QmlProfilerClientManager::connectToServer(const QUrl &server)
disconnectClient();
stopConnectionTimer();
}
if (server.scheme() == ProjectExplorer::urlTcpScheme())
if (server.scheme() == Utils::urlTcpScheme())
connectToTcpServer();
else if (server.scheme() == ProjectExplorer::urlSocketScheme())
else if (server.scheme() == Utils::urlSocketScheme())
startLocalServer();
else
QTC_ASSERT(false, emit connectionFailed());
@@ -175,9 +175,9 @@ void QmlProfilerClientManager::stopRecording()
void QmlProfilerClientManager::retryConnect()
{
if (m_server.scheme() == ProjectExplorer::urlSocketScheme()) {
if (m_server.scheme() == Utils::urlSocketScheme()) {
startLocalServer();
} else if (m_server.scheme() == ProjectExplorer::urlTcpScheme()) {
} else if (m_server.scheme() == Utils::urlTcpScheme()) {
disconnectClient();
connectToTcpServer();
} else {

View File

@@ -48,6 +48,7 @@
#include <utils/qtcassert.h>
#include <utils/qtcfallthrough.h>
#include <utils/url.h>
#include <QMessageBox>
@@ -247,12 +248,12 @@ static QUrl localServerUrl(RunControl *runControl)
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
if (version) {
if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0))
serverUrl = urlFromLocalSocket();
serverUrl = Utils::urlFromLocalSocket();
else
serverUrl = urlFromLocalHostAndFreePort();
serverUrl = Utils::urlFromLocalHostAndFreePort();
} else {
qWarning("Running QML profiler on Kit without Qt version?");
serverUrl = urlFromLocalHostAndFreePort();
serverUrl = Utils::urlFromLocalHostAndFreePort();
}
return serverUrl;
}
@@ -278,9 +279,9 @@ LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const Q
StandardRunnable debuggee = runnable().as<StandardRunnable>();
QString code;
if (serverUrl.scheme() == urlSocketScheme())
if (serverUrl.scheme() == Utils::urlSocketScheme())
code = QString("file:%1").arg(serverUrl.path());
else if (serverUrl.scheme() == urlTcpScheme())
else if (serverUrl.scheme() == Utils::urlTcpScheme())
code = QString("port:%1").arg(serverUrl.port());
else
QTC_CHECK(false);

View File

@@ -29,6 +29,8 @@
#include <projectexplorer/runnables.h>
#include <qmlprofiler/qmlprofilerruncontrol.h>
#include <utils/url.h>
#include <QtTest>
#include <QTcpServer>
@@ -56,7 +58,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
debuggee.environment = Utils::Environment::systemEnvironment();
// should not be used anywhere but cannot be empty
serverUrl.setScheme(ProjectExplorer::urlSocketScheme());
serverUrl.setScheme(Utils::urlSocketScheme());
serverUrl.setPath("invalid");
runControl = new ProjectExplorer::RunControl(nullptr,
@@ -102,7 +104,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
serverUrl = ProjectExplorer::urlFromLocalSocket();
serverUrl = Utils::urlFromLocalSocket();
debuggee.executable = qApp->applicationFilePath();
// comma is used to specify a test function. In this case, an invalid one.
@@ -126,7 +128,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
debuggee.commandLineArguments.clear();
serverUrl.clear();
serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort();
serverUrl = Utils::urlFromLocalHostAndFreePort();
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
@@ -148,7 +150,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
void LocalQmlProfilerRunnerTest::testFindFreePort()
{
QUrl serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort();
QUrl serverUrl = Utils::urlFromLocalHostAndFreePort();
QVERIFY(serverUrl.port() != -1);
QVERIFY(!serverUrl.host().isEmpty());
QTcpServer server;
@@ -157,7 +159,7 @@ void LocalQmlProfilerRunnerTest::testFindFreePort()
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
{
QUrl serverUrl = ProjectExplorer::urlFromLocalSocket();
QUrl serverUrl = Utils::urlFromLocalSocket();
QString socket = serverUrl.path();
QVERIFY(!socket.isEmpty());
QVERIFY(!QFile::exists(socket));

View File

@@ -27,6 +27,7 @@
#include <qmlprofiler/qmlprofilerruncontrol.h>
#include <qmldebug/qpacketprotocol.h>
#include <projectexplorer/applicationlauncher.h>
#include <utils/url.h>
#include <QTcpServer>
#include <QTcpSocket>
@@ -70,13 +71,15 @@ void QmlProfilerClientManagerTest::testConnectionFailure_data()
QTest::addColumn<QmlProfilerStateManager *>("stateManager");
QVarLengthArray<QmlProfilerStateManager *> stateManagers({nullptr, &stateManager});
QUrl localUrl = urlFromLocalHostAndFreePort();
QUrl localUrl = Utils::urlFromLocalHostAndFreePort();
QTest::addColumn<QUrl>("serverUrl");
const QVarLengthArray<QString> hosts({"", "/-/|\\-\\|/-", localUrl.host()});
const QVarLengthArray<int> ports({-1, 5, localUrl.port()});
const QVarLengthArray<QString> sockets({"", "/-/|\\-\\|/-", urlFromLocalSocket().path()});
const QVarLengthArray<QString> schemes({"", urlSocketScheme(), urlTcpScheme()});
const QVarLengthArray<QString> sockets({"", "/-/|\\-\\|/-",
Utils::urlFromLocalSocket().path()});
const QVarLengthArray<QString> schemes({"", Utils::urlSocketScheme(),
Utils::urlTcpScheme()});
for (QmlProfilerModelManager *modelManager : modelManagers) {
for (QmlProfilerStateManager *stateManager : stateManagers) {
@@ -162,7 +165,7 @@ void QmlProfilerClientManagerTest::testUnresponsiveTcp()
clientManager.setProfilerStateManager(&stateManager);
clientManager.setModelManager(&modelManager);
QUrl serverUrl = urlFromLocalHostAndFreePort();
QUrl serverUrl = Utils::urlFromLocalHostAndFreePort();
QTcpServer server;
server.listen(QHostAddress(serverUrl.host()), serverUrl.port());
@@ -190,7 +193,7 @@ void QmlProfilerClientManagerTest::testUnresponsiveLocal()
clientManager.setProfilerStateManager(&stateManager);
clientManager.setModelManager(&modelManager);
QUrl socketUrl = urlFromLocalSocket();
QUrl socketUrl = Utils::urlFromLocalSocket();
QLocalSocket socket;
QSignalSpy connectionSpy(&socket, SIGNAL(connected()));
@@ -241,7 +244,7 @@ void QmlProfilerClientManagerTest::testResponsiveTcp()
{
QFETCH(quint32, flushInterval);
QUrl serverUrl = urlFromLocalHostAndFreePort();
QUrl serverUrl = Utils::urlFromLocalHostAndFreePort();
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
@@ -299,7 +302,7 @@ void QmlProfilerClientManagerTest::testResponsiveLocal()
{
QFETCH(quint32, flushInterval);
QUrl socketUrl = urlFromLocalSocket();
QUrl socketUrl = Utils::urlFromLocalSocket();
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
@@ -363,7 +366,7 @@ void QmlProfilerClientManagerTest::testInvalidData()
clientManager.setProfilerStateManager(&stateManager);
clientManager.setModelManager(&modelManager);
QUrl serverUrl = urlFromLocalHostAndFreePort();
QUrl serverUrl = Utils::urlFromLocalHostAndFreePort();
bool dataSent = false;
QTcpServer server;
@@ -393,7 +396,7 @@ void QmlProfilerClientManagerTest::testInvalidData()
void QmlProfilerClientManagerTest::testStopRecording()
{
QUrl socketUrl = urlFromLocalSocket();
QUrl socketUrl = Utils::urlFromLocalSocket();
{
QmlProfilerClientManager clientManager;