Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Sep 3, 2024
1 parent 125a450 commit 7101c3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand All @@ -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)
Expand Down Expand Up @@ -134,17 +135,4 @@ class Yaxunit implements Serializable {
}
}

private static ArrayList<String> 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()
}
}
20 changes: 20 additions & 0 deletions src/ru/pulsar/jenkins/library/utils/CoverageUtils.groovy
Original file line number Diff line number Diff line change
@@ -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<String> 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()
}
}

0 comments on commit 7101c3a

Please sign in to comment.