| 99 | } |
| 100 | |
| 101 | void JavaDebugger::initialize(const QString &configHomePath, |
| 102 | const QString &jreExecute, |
| 103 | const QString &launchPackageFile, |
| 104 | const QString &launchConfigPath, |
| 105 | const QString &workspace) |
| 106 | { |
| 107 | if (d->initialized) |
| 108 | return; |
| 109 | |
| 110 | int startPort = 6000; |
| 111 | |
| 112 | auto checkPortFree = [](int port) { |
| 113 | QProcess process; |
| 114 | QString cmd = QString("fuser %1/tcp").arg(port); |
| 115 | process.start(cmd); |
| 116 | process.waitForFinished(); |
| 117 | QString ret = process.readAll(); |
| 118 | if (ret.isEmpty()) |
| 119 | return true; |
| 120 | return false; |
| 121 | }; |
| 122 | |
| 123 | while (startPort) { |
| 124 | if (checkPortFree(startPort)) { |
| 125 | break; |
| 126 | } |
| 127 | startPort--; |
| 128 | } |
| 129 | |
| 130 | QString validPort = QString::number(startPort); |
| 131 | QString logFolder = configHomePath + "/dap/javalog/" + QFileInfo(workspace).fileName() + |
| 132 | "_" + QDateTime::currentDateTime().toString("yyyyMMddHHmmss"); |
| 133 | QString heapDumpPath = logFolder + "/heapdump/headdump.java"; |
| 134 | QString dataPath = logFolder + "/jdt_ws"; |
| 135 | |
| 136 | QString param = d->javaparam.getInitBackendParam(validPort, |
| 137 | jreExecute, |
| 138 | launchPackageFile, |
| 139 | heapDumpPath, |
| 140 | launchConfigPath, |
| 141 | dataPath); |
| 142 | qInfo() << validPort; |
| 143 | QStringList options; |
| 144 | options << "-c" << param; |
| 145 | outputMsg("normal", options.join(";")); |
| 146 | d->process.start("/bin/bash", options); |
| 147 | d->process.waitForStarted(); |
| 148 | |
| 149 | d->initialized = true; |
| 150 | } |
| 151 | |
| 152 | void JavaDebugger::slotReceivePojectInfo(const QString &uuid, |
| 153 | const QString &kit, |