Skip to content

Commit

Permalink
remove "my" #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Ma-iu-shan authored and Vlad Ma-iu-shan committed May 8, 2024
1 parent f3cafc2 commit a49d869
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import jetbrains.buildServer.util.FileUtil
import java.io.File

class AfterBuildPublisher(
private val myContextProvider: BuildRunnerContextProvider,
private val myLoggerService: LoggerService
private val _contextProvider: BuildRunnerContextProvider,
private val _loggerService: LoggerService
) : ResourcePublisher {
override fun publishBeforeBuildFile(executionContext: CommandLineExecutionContext, file: File, content: String) {
}

override fun publishAfterBuildArtifactFile(executionContext: CommandLineExecutionContext, file: File) {
val commandLineIndex = executionContext.commandLineIndex
var buildName = myContextProvider.runnerId
var buildName = _contextProvider.runnerId
if (commandLineIndex != 0) {
buildName += ("_$commandLineIndex")
}

myLoggerService.onMessage(
_loggerService.onMessage(
PublishArtifactsServiceMessage(
file.absolutePath, FileUtil.fixDirectoryName(
buildName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import jetbrains.buildServer.agent.AgentLifeCycleListener
import jetbrains.buildServer.util.Disposable
import jetbrains.buildServer.util.EventDispatcher

class AgentEventDispatcherImpl(private val myEventDispatcher: EventDispatcher<AgentLifeCycleListener>) :
AgentEventDispatcher {
class AgentEventDispatcherImpl(
private val _eventDispatcher: EventDispatcher<AgentLifeCycleListener>
) : AgentEventDispatcher {
override fun subscribe(listener: AgentLifeCycleListener): Disposable {
myEventDispatcher.addListener(listener)
return Disposable { myEventDispatcher.removeListener(listener) }
_eventDispatcher.addListener(listener)
return Disposable { _eventDispatcher.removeListener(listener) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import java.io.File
import java.io.IOException

class BeforeBuildPublisher(
private val myContextProvider: BuildRunnerContextProvider,
private val myFileService: FileService,
private val myLoggerService: LoggerService
private val _contextProvider: BuildRunnerContextProvider,
private val _fileService: FileService,
private val _loggerService: LoggerService
) : ResourcePublisher {
override fun publishBeforeBuildFile(executionContext: CommandLineExecutionContext, file: File, content: String) {
try {
myFileService.writeAllTextFile(content, file)
_fileService.writeAllTextFile(content, file)
} catch (ignored: IOException) {
throw BuildException("Unable to create temporary file " + file.path + " required to run this build")
}
}

override fun publishAfterBuildArtifactFile(executionContext: CommandLineExecutionContext, file: File) {
val buildName = myContextProvider.runnerId
myLoggerService.onMessage(
val buildName = _contextProvider.runnerId
_loggerService.onMessage(
PublishArtifactsServiceMessage(
file.absolutePath,
FileUtil.fixDirectoryName(buildName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import jetbrains.buildServer.util.Disposable
import java.io.File

class BuildCommandLineProcessorAdapterImpl(
private val mySetupBuilder: CommandLineSetupBuilder,
private val myContextProvider: BuildRunnerContextProvider,
private val myEventDispatcher: AgentEventDispatcher,
private val myExceptionHandler: ExceptionHandler,
private val myCommandLineArgumentsService: CommandLineArgumentsService
private val _setupBuilder: CommandLineSetupBuilder,
private val _contextProvider: BuildRunnerContextProvider,
private val _eventDispatcher: AgentEventDispatcher,
private val _exceptionHandler: ExceptionHandler,
private val _commandLineArgumentsService: CommandLineArgumentsService
) : BuildCommandLineProcessorAdapter {
@Throws(RunBuildException::class)
override fun process(runnerContext: BuildRunnerContext, origCommandLine: ProgramCommandLine): ProgramCommandLine {
try {
myContextProvider.initialize(runnerContext)
_contextProvider.initialize(runnerContext)
val args: MutableList<CommandLineArgument> = ArrayList(origCommandLine.arguments.size)
for (argStr in origCommandLine.arguments) {
args.add(CommandLineArgument(argStr!!, CommandLineArgument.Type.PARAMETER))
Expand All @@ -32,7 +31,7 @@ class BuildCommandLineProcessorAdapterImpl(
File(origCommandLine.workingDirectory)
)
val setups = ArrayList<CommandLineSetup>()
for (setup in mySetupBuilder.build(baseSetup)) {
for (setup in _setupBuilder.build(baseSetup)) {
setups.add(setup)
}

Expand All @@ -57,8 +56,8 @@ class BuildCommandLineProcessorAdapterImpl(
}
}

subscription[0] = myEventDispatcher.subscribe(listener)
val normalizedArgs = myCommandLineArgumentsService.normalizeCommandLineArguments(setup.args)
subscription[0] = _eventDispatcher.subscribe(listener)
val normalizedArgs = _commandLineArgumentsService.normalizeCommandLineArguments(setup.args)
val argsStr: MutableList<String> = ArrayList(normalizedArgs.size)
for (arg in normalizedArgs) {
argsStr.add(arg.value)
Expand All @@ -71,7 +70,7 @@ class BuildCommandLineProcessorAdapterImpl(
argsStr
)
} catch (ex: BuildException) {
val exceptionToThrow = myExceptionHandler.handle(BuildCommandLineProcessorAdapterImpl::class.java, ex)
val exceptionToThrow = _exceptionHandler.handle(BuildCommandLineProcessorAdapterImpl::class.java, ex)
if (exceptionToThrow != null) {
throw exceptionToThrow
}
Expand All @@ -80,14 +79,13 @@ class BuildCommandLineProcessorAdapterImpl(
return origCommandLine
}

@Throws(RunBuildException::class)
private fun publishBeforeBuild(setup: CommandLineSetup, executionContext: CommandLineExecutionContext) {
try {
for (resource in setup.resources) {
resource.publishBeforeBuild(executionContext)
}
} catch (ex: BuildException) {
val wrappedException = myExceptionHandler.handle(BuildCommandLineProcessorAdapterImpl::class.java, ex)
val wrappedException = _exceptionHandler.handle(BuildCommandLineProcessorAdapterImpl::class.java, ex)
if (wrappedException != null) {
throw wrappedException
}
Expand All @@ -100,7 +98,7 @@ class BuildCommandLineProcessorAdapterImpl(
resource.publishAfterBuild(executionContext)
}
} catch (ex: BuildException) {
myExceptionHandler.handle(BuildCommandLineProcessorAdapterImpl::class.java, ex)
_exceptionHandler.handle(BuildCommandLineProcessorAdapterImpl::class.java, ex)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package jetbrains.buildServer.nunit.agent
import jetbrains.buildServer.agent.BuildRunnerContext

class BuildRunnerContextProviderImpl : BuildRunnerContextProvider {
private var myContext: BuildRunnerContext? = null
private var _context: BuildRunnerContext? = null

override fun initialize(context: BuildRunnerContext) {
myContext = context
_context = context
}

override val context: BuildRunnerContext
get() {
checkNotNull(myContext)
checkNotNull(_context)

return myContext!!
return _context!!
}

override val runnerId: String
get() = String.format("%s_%s", context.build.buildTypeId, context.id)
get() = "${context.build.buildTypeId}_${context.id}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package jetbrains.buildServer.nunit.agent
import jetbrains.buildServer.agent.runner.CommandExecution

interface CommandExecutionAdapter : CommandExecution {
fun initialize(stateHandler: StatusHandler, commandLineSetup: CommandLineSetup, commandLineIndex: Int)
fun initialize(statusHandler: StatusHandler, commandLineSetup: CommandLineSetup, commandLineIndex: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ import jetbrains.buildServer.agent.runner.TerminationAction
import java.io.File

class CommandExecutionAdapterImpl(
private val myContextProvider: BuildRunnerContextProvider,
private val myLogger: LoggerService,
private val myCommandLineArgumentsService: CommandLineArgumentsService
private val _contextProvider: BuildRunnerContextProvider,
private val _logger: LoggerService,
private val _commandLineArgumentsService: CommandLineArgumentsService
) : CommandExecutionAdapter {
private var myStatusHandler: StatusHandler? = null
private var myCommandLineSetup: CommandLineSetup? = null
private var myCommandLineExecutionContext: CommandLineExecutionContext? = null
private var _statusHandler: StatusHandler? = null
private var _commandLineSetup: CommandLineSetup? = null
private var _commandLineExecutionContext: CommandLineExecutionContext? = null

override fun initialize(statusHandler: StatusHandler, commandLineSetup: CommandLineSetup, commandLineIndex: Int) {
checkInitialized(false)
myStatusHandler = statusHandler
myCommandLineSetup = commandLineSetup
myCommandLineExecutionContext = CommandLineExecutionContext(commandLineIndex)
_statusHandler = statusHandler
_commandLineSetup = commandLineSetup
_commandLineExecutionContext = CommandLineExecutionContext(commandLineIndex)
}

override fun makeProgramCommandLine(): ProgramCommandLine {
checkInitialized(true)
val normalizedArgs = myCommandLineArgumentsService.normalizeCommandLineArguments(
myCommandLineSetup!!.args
val normalizedArgs = _commandLineArgumentsService.normalizeCommandLineArguments(
_commandLineSetup!!.args
)
val args: MutableList<String> = ArrayList(normalizedArgs.size)
for (arg in normalizedArgs) {
args.add(arg.value)
}

val workingDirectory = myCommandLineSetup!!.workingDirectory
val workingDirectory = _commandLineSetup!!.workingDirectory
?: return SimpleProgramCommandLine(
myContextProvider.context,
myCommandLineSetup!!.toolPath,
_contextProvider.context,
_commandLineSetup!!.toolPath,
args
)

return SimpleProgramCommandLine(
myContextProvider.context.buildParameters.environmentVariables,
_contextProvider.context.buildParameters.environmentVariables,
workingDirectory.absolutePath,
myCommandLineSetup!!.toolPath,
_commandLineSetup!!.toolPath,
args
)
}

override fun interruptRequested(): TerminationAction {
myStatusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createInterruptedStatus())
_statusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createInterruptedStatus())
return TerminationAction.KILL_PROCESS_TREE
}

Expand All @@ -56,44 +56,44 @@ class CommandExecutionAdapterImpl(
}

override fun onStandardOutput(text: String) {
myLogger.onStandardOutput(text)
_logger.onStandardOutput(text)
}

override fun onErrorOutput(text: String) {
myLogger.onErrorOutput(text)
_logger.onErrorOutput(text)
}

override fun beforeProcessStarted() {
checkInitialized(true)
try {
for (resource in myCommandLineSetup!!.resources) {
resource.publishBeforeBuild(myCommandLineExecutionContext!!)
for (resource in _commandLineSetup!!.resources) {
resource.publishBeforeBuild(_commandLineExecutionContext!!)
}
} catch (ex: BuildException) {
myStatusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createErrorStatus(ex))
_statusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createErrorStatus(ex))
}
}

override fun processStarted(programCommandLine: String, workingDirectory: File) {
checkInitialized(true)
myStatusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createStartedStatus())
_statusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createStartedStatus())
}

override fun processFinished(exitCode: Int) {
checkInitialized(true)
try {
for (resource in myCommandLineSetup!!.resources) {
resource.publishAfterBuild(myCommandLineExecutionContext!!)
for (resource in _commandLineSetup!!.resources) {
resource.publishAfterBuild(_commandLineExecutionContext!!)
}

myStatusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createFinishStatus(exitCode))
_statusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createFinishStatus(exitCode))
} catch (ex: BuildException) {
myStatusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createErrorStatus(ex))
_statusHandler!!.handleExecutionStatusChanged(ExecutionStatus.createErrorStatus(ex))
}
}

private fun checkInitialized(expectedInitialized: Boolean) {
check((myCommandLineSetup != null) == expectedInitialized) { NOT_INITIALIZED_ERROR }
check((_commandLineSetup != null) == expectedInitialized) { NOT_INITIALIZED_ERROR }
}

companion object {
Expand Down

0 comments on commit a49d869

Please sign in to comment.