From 7101c3afb3f40e521015f20a838fb40e2c6bc5ef Mon Sep 17 00:00:00 2001 From: Dima Date: Tue, 3 Sep 2024 13:19:01 +0300 Subject: [PATCH] refactor --- .../jenkins/library/steps/Yaxunit.groovy | 22 +++++-------------- .../library/utils/CoverageUtils.groovy | 20 +++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/ru/pulsar/jenkins/library/utils/CoverageUtils.groovy diff --git a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy index 6b02daa8..4a50a5f3 100644 --- a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy +++ b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy @@ -6,6 +6,7 @@ import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.utils.CoverageUtils import ru.pulsar.jenkins.library.utils.FileUtils import ru.pulsar.jenkins.library.utils.Logger import ru.pulsar.jenkins.library.utils.VRunner @@ -72,8 +73,8 @@ class Yaxunit implements Serializable { def coverageOpts = config.coverageOptions def port = options.dbgsPort def lockableResource = RandomStringUtils.random(9, true, false) - def currentDbgsPids = getPIDs("dbgs") - def currentCoverage41CPids = getPIDs("Coverage41C") + def currentDbgsPids = CoverageUtils.getPIDs("dbgs") + def currentCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") if (options.coverage) { lockableResource = "${env.NODE_NAME}_$port" } @@ -84,8 +85,8 @@ class Yaxunit implements Serializable { steps.start("${coverageOpts.coverage41CPath} start -i DefAlias -u http://127.0.0.1:$port -P $workspaceDir -s $srcDir -o $COVERAGE_STASH_PATH") steps.cmd("${coverageOpts.coverage41CPath} check -i DefAlias -u http://127.0.0.1:$port") - def newDbgsPids = getPIDs("dbgs") - def newCoverage41CPids = getPIDs("Coverage41C") + def newDbgsPids = CoverageUtils.getPIDs("dbgs") + def newCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") newDbgsPids.removeAll(currentDbgsPids) newCoverage41CPids.removeAll(currentCoverage41CPids) @@ -134,17 +135,4 @@ class Yaxunit implements Serializable { } } - private static ArrayList getPIDs(String name) { - - IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() - - String pids - - if (steps.isUnix()) { - pids = steps.sh("ps -aux | grep '$name' | awk '{print \$2}'", false, true, 'UTF-8') - } else { - pids = steps.bat("chcp 65001 > nul \nfor /f \"tokens=2\" %a in ('tasklist ^| findstr $name') do @echo %a", false, true, 'UTF-8') - } - return pids.split('\n').toList() - } } diff --git a/src/ru/pulsar/jenkins/library/utils/CoverageUtils.groovy b/src/ru/pulsar/jenkins/library/utils/CoverageUtils.groovy new file mode 100644 index 00000000..e897ae46 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/utils/CoverageUtils.groovy @@ -0,0 +1,20 @@ +package ru.pulsar.jenkins.library.utils + +import ru.pulsar.jenkins.library.IStepExecutor +import ru.pulsar.jenkins.library.ioc.ContextRegistry + +class CoverageUtils { + static ArrayList getPIDs(String name) { + + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + String pids + + if (steps.isUnix()) { + pids = steps.sh("ps -aux | grep '$name' | awk '{print \$2}'", false, true, 'UTF-8') + } else { + pids = steps.bat("chcp 65001 > nul \nfor /f \"tokens=2\" %a in ('tasklist ^| findstr $name') do @echo %a", false, true, 'UTF-8') + } + return pids.split('\n').toList() + } +}