forked from qt-creator/qt-creator
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:
66
src/libs/utils/url.cpp
Normal file
66
src/libs/utils/url.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "url.h"
|
||||
#include "temporaryfile.h"
|
||||
|
||||
#include <QHostAddress>
|
||||
#include <QTcpServer>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
QUrl urlFromLocalHostAndFreePort()
|
||||
{
|
||||
QUrl serverUrl;
|
||||
QTcpServer server;
|
||||
serverUrl.setScheme(urlTcpScheme());
|
||||
if (server.listen(QHostAddress::LocalHost) || server.listen(QHostAddress::LocalHostIPv6)) {
|
||||
serverUrl.setHost(server.serverAddress().toString());
|
||||
serverUrl.setPort(server.serverPort());
|
||||
}
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
QUrl urlFromLocalSocket()
|
||||
{
|
||||
QUrl serverUrl;
|
||||
serverUrl.setScheme(urlSocketScheme());
|
||||
Utils::TemporaryFile file("qtcreator-freesocket");
|
||||
if (file.open())
|
||||
serverUrl.setPath(file.fileName());
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
QString urlSocketScheme()
|
||||
{
|
||||
return QString("socket");
|
||||
}
|
||||
|
||||
QString urlTcpScheme()
|
||||
{
|
||||
return QString("tcp");
|
||||
}
|
||||
|
||||
}
|
38
src/libs/utils/url.h
Normal file
38
src/libs/utils/url.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils_global.h"
|
||||
#include <QUrl>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QUrl urlFromLocalHostAndFreePort();
|
||||
QTCREATOR_UTILS_EXPORT QUrl urlFromLocalSocket();
|
||||
QTCREATOR_UTILS_EXPORT QString urlSocketScheme();
|
||||
QTCREATOR_UTILS_EXPORT QString urlTcpScheme();
|
||||
|
||||
}
|
@@ -118,7 +118,8 @@ SOURCES += \
|
||||
$$PWD/guard.cpp \
|
||||
$$PWD/highlightingitemdelegate.cpp \
|
||||
$$PWD/camelhumpmatcher.cpp \
|
||||
$$PWD/textutils.cpp
|
||||
$$PWD/textutils.cpp \
|
||||
$$PWD/url.cpp
|
||||
|
||||
win32:SOURCES += $$PWD/consoleprocess_win.cpp
|
||||
else:SOURCES += $$PWD/consoleprocess_unix.cpp
|
||||
@@ -249,7 +250,8 @@ HEADERS += \
|
||||
$$PWD/qtcfallthrough.h \
|
||||
$$PWD/highlightingitemdelegate.h \
|
||||
$$PWD/camelhumpmatcher.h \
|
||||
$$PWD/textutils.h
|
||||
$$PWD/textutils.h \
|
||||
$$PWD/url.h
|
||||
|
||||
FORMS += $$PWD/filewizardpage.ui \
|
||||
$$PWD/projectintropage.ui \
|
||||
|
@@ -44,6 +44,7 @@
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <utils/temporaryfile.h>
|
||||
#include <utils/url.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
@@ -293,7 +294,7 @@ AndroidRunnerWorker::AndroidRunnerWorker(RunControl *runControl, const AndroidRu
|
||||
QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|
||||
|| server.listen(QHostAddress::LocalHostIPv6),
|
||||
qDebug() << tr("No free ports available on host for QML debugging."));
|
||||
m_qmlServer.setScheme(urlTcpScheme());
|
||||
m_qmlServer.setScheme(Utils::urlTcpScheme());
|
||||
m_qmlServer.setHost(server.serverAddress().toString());
|
||||
m_qmlServer.setPort(server.serverPort());
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@
|
||||
#include <utils/portlist.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/url.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -643,7 +644,7 @@ bool DebuggerRunTool::fixupParameters()
|
||||
if (rp.isQmlDebugging) {
|
||||
if (device() && device()->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
||||
if (rp.qmlServer.port() <= 0) {
|
||||
rp.qmlServer = ProjectExplorer::urlFromLocalHostAndFreePort();
|
||||
rp.qmlServer = Utils::urlFromLocalHostAndFreePort();
|
||||
if (rp.qmlServer.port() <= 0) {
|
||||
reportFailure(DebuggerPlugin::tr("Not enough free ports for QML debugging."));
|
||||
return false;
|
||||
|
@@ -25,10 +25,6 @@
|
||||
|
||||
#include "runnables.h"
|
||||
|
||||
#include <QTcpServer>
|
||||
|
||||
#include <utils/temporaryfile.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
bool operator==(const StandardRunnable &r1, const StandardRunnable &r2)
|
||||
@@ -41,37 +37,4 @@ bool operator==(const StandardRunnable &r1, const StandardRunnable &r2)
|
||||
|
||||
void *StandardRunnable::staticTypeId = &StandardRunnable::staticTypeId;
|
||||
|
||||
|
||||
QUrl urlFromLocalHostAndFreePort()
|
||||
{
|
||||
QUrl serverUrl;
|
||||
QTcpServer server;
|
||||
serverUrl.setScheme(urlTcpScheme());
|
||||
if (server.listen(QHostAddress::LocalHost) || server.listen(QHostAddress::LocalHostIPv6)) {
|
||||
serverUrl.setHost(server.serverAddress().toString());
|
||||
serverUrl.setPort(server.serverPort());
|
||||
}
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
QUrl urlFromLocalSocket()
|
||||
{
|
||||
QUrl serverUrl;
|
||||
serverUrl.setScheme(urlSocketScheme());
|
||||
Utils::TemporaryFile file("qmlprofiler-freesocket");
|
||||
if (file.open())
|
||||
serverUrl.setPath(file.fileName());
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
QString urlSocketScheme()
|
||||
{
|
||||
return QString("socket");
|
||||
}
|
||||
|
||||
QString urlTcpScheme()
|
||||
{
|
||||
return QString("tcp");
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -33,7 +33,6 @@
|
||||
#include <utils/environment.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
@@ -53,9 +52,4 @@ public:
|
||||
|
||||
PROJECTEXPLORER_EXPORT bool operator==(const StandardRunnable &r1, const StandardRunnable &r2);
|
||||
|
||||
PROJECTEXPLORER_EXPORT QUrl urlFromLocalHostAndFreePort();
|
||||
PROJECTEXPLORER_EXPORT QUrl urlFromLocalSocket();
|
||||
PROJECTEXPLORER_EXPORT QString urlSocketScheme();
|
||||
PROJECTEXPLORER_EXPORT QString urlTcpScheme();
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -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 {
|
||||
|
@@ -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);
|
||||
|
@@ -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));
|
||||
|
@@ -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;
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include <QTcpServer>
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/url.h>
|
||||
|
||||
using namespace Debugger;
|
||||
using namespace ProjectExplorer;
|
||||
@@ -66,7 +67,7 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl)
|
||||
}
|
||||
|
||||
if (isQmlDebugging()) {
|
||||
QUrl qmlServer = ProjectExplorer::urlFromLocalHostAndFreePort();
|
||||
QUrl qmlServer = Utils::urlFromLocalHostAndFreePort();
|
||||
if (qmlServer.port() <= 0) {
|
||||
reportFailure(tr("Not enough free ports for QML debugging."));
|
||||
return;
|
||||
|
Reference in New Issue
Block a user