| 1277 | } |
| 1278 | |
| 1279 | void DebuggerPlugin::replaceKeysInJson( |
| 1280 | nlohmann::json& json, int randomPort, |
| 1281 | const std::unordered_map<std::string, std::string>& solvedInputs ) { |
| 1282 | auto pbm = getPluginContext()->getProjectBuildManager(); |
| 1283 | auto runConfig = pbm ? pbm->getCurrentRunConfig() : std::optional<ProjectBuildStep>{}; |
| 1284 | auto buildConfig = pbm ? pbm->getCurrentBuild() : nullptr; |
| 1285 | |
| 1286 | const auto replaceVal = [this, &solvedInputs, &runConfig, &buildConfig, |
| 1287 | randomPort]( nlohmann::json& j, std::string& val ) -> bool { |
| 1288 | replaceInVal( val, runConfig, buildConfig, randomPort ); |
| 1289 | |
| 1290 | LuaPattern::Range matches[2]; |
| 1291 | if ( inputPtrn.matches( val, matches ) ) { |
| 1292 | std::string id( val.substr( matches[1].start, matches[1].end - matches[1].start ) ); |
| 1293 | auto solvedIdIt = solvedInputs.find( id ); |
| 1294 | if ( solvedIdIt != solvedInputs.end() ) |
| 1295 | String::replaceAll( val, String::format( "${input:%s}", id ), solvedIdIt->second ); |
| 1296 | } |
| 1297 | |
| 1298 | LuaPattern::Range matches2[2]; |
| 1299 | if ( commandPtrn.matches( val, matches2 ) ) { |
| 1300 | std::string name( |
| 1301 | val.substr( matches2[0].start, matches2[0].end - matches2[0].start ) ); |
| 1302 | std::string id( val.substr( matches2[1].start, matches2[1].end - matches2[1].start ) ); |
| 1303 | String::toLowerInPlace( id ); |
| 1304 | auto solvedIdIt = solvedInputs.find( id ); |
| 1305 | if ( solvedIdIt != solvedInputs.end() ) { |
| 1306 | if ( id == "pickprocess" ) { |
| 1307 | int pid = 0; |
| 1308 | if ( String::fromString( pid, solvedIdIt->second ) ) { |
| 1309 | j = pid; |
| 1310 | return false; |
| 1311 | } |
| 1312 | } else { |
| 1313 | String::replaceAll( val, name, solvedIdIt->second ); |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | return true; |
| 1319 | }; |
| 1320 | |
| 1321 | std::vector<std::string> keysToRemove; |
| 1322 | |
| 1323 | for ( auto& j : json ) { |
| 1324 | if ( j.is_object() ) { |
| 1325 | replaceKeysInJson( j, randomPort, solvedInputs ); |
| 1326 | } else if ( j.is_array() ) { |
| 1327 | for ( auto& e : j ) { |
| 1328 | if ( e.is_string() ) { |
| 1329 | std::string val( e.get<std::string>() ); |
| 1330 | replaceVal( e, val ); |
| 1331 | e = std::move( val ); |
| 1332 | } |
| 1333 | } |
| 1334 | } else if ( j.is_string() ) { |
| 1335 | std::string val( j.get<std::string>() ); |
| 1336 |
nothing calls this directly
no test coverage detected