Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyzzz committed Aug 18, 2013
1 parent c378ed6 commit 26791ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ public abstract class BaseService : BuildServiceAdapter() {

protected fun execute(executable:String, arguments:List<String>) : ProgramCommandLine {
val that = this
return object:ScriptWrappingCommandLineGenerator<ProgramCommandLine> {
override fun createProgramCommandline(executable: String, args: List<String>): ProgramCommandLine
= SimpleProgramCommandLine(getRunnerContext(), executable, args)

return object:ScriptWrappingCommandLineGenerator<ProgramCommandLine>(getRunnerContext()) {
override fun execute(executable: String, args: List<String>): ProgramCommandLine
= SimpleProgramCommandLine(build, executable, args)
override fun disposeLater(action: () -> Unit) = that.disposeLater(action)
}.createProgramCommandline(executable, arguments)
}.generate(executable, arguments)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ public class NPMCommandExecution(val logger : BuildProgressLogger,
private val disposables = linkedListOf<() -> Unit>()

public override fun makeProgramCommandLine(): ProgramCommandLine =
object:ScriptWrappingCommandLineGenerator<ProgramCommandLine> {
override fun createProgramCommandline(executable: String, args: List<String>): ProgramCommandLine
= SimpleProgramCommandLine(runner, executable, args)
object:ScriptWrappingCommandLineGenerator<ProgramCommandLine>(runner) {
override fun execute(executable: String, args: List<String>): ProgramCommandLine
= SimpleProgramCommandLine(build, executable, args)

override fun disposeLater(action: () -> Unit) {
disposables add action
}
}.createProgramCommandline(cmd.program, cmd.arguments)
}.generate(cmd.program, cmd.arguments)


public override fun beforeProcessStarted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.intellij.execution.configurations.GeneralCommandLine
import jetbrains.buildServer.SimpleCommandLineProcessRunner
import jetbrains.buildServer.SimpleCommandLineProcessRunner.RunCommandEventsAdapter
import com.jonnyzzz.teamcity.plugins.node.common.log4j
import jetbrains.buildServer.agent.AgentRunningBuild
import jetbrains.buildServer.util.FileUtil
import jetbrains.buildServer.agent.BuildRunnerContext
import com.jonnyzzz.teamcity.plugins.node.common.tempFile
import com.jonnyzzz.teamcity.plugins.node.common.TempFileName
import com.jonnyzzz.teamcity.plugins.node.common.smartDelete
Expand Down Expand Up @@ -58,29 +58,27 @@ public class ShellBasedExecutionProxy(val config : BuildAgentConfiguration) : Ex
}
}

public trait ScriptWrappingCommandLineGenerator<ProgramCommandLine> {
fun createProgramCommandline(executable: String, args: List<String>): ProgramCommandLine
fun disposeLater(action: () -> Unit)
public abstract class ScriptWrappingCommandLineGenerator<ProgramCommandLine>(protected val build: BuildRunnerContext) {
protected abstract fun execute(executable: String, args: List<String>): ProgramCommandLine
protected abstract fun disposeLater(action: () -> Unit)

fun generate(build: AgentRunningBuild,
executable: String,
arguments: List<String>): ProgramCommandLine {
public fun generate(executable: String, arguments: List<String>): ProgramCommandLine {
log4j(javaClass).info("Executing ${executable} via wrapping script")
build.getBuildLogger().message("Executing ${executable} via wrapping shell script")
build.getBuild().getBuildLogger().message("Executing ${executable} via wrapping shell script")

if (build.getAgentConfiguration().getSystemInfo().isWindows()) {
return createProgramCommandline("cmd", arrayListOf<String>("/c", executable) + arguments)
if (build.getBuild().getAgentConfiguration().getSystemInfo().isWindows()) {
return execute("cmd", arrayListOf<String>("/c", executable) + arguments)
} else {
val scriptToRun = io("Failed to create temp file") {
build.getAgentTempDirectory() tempFile TempFileName(executable, ".sh")
build.getBuild().getAgentTempDirectory() tempFile TempFileName(executable, ".sh")
}
disposeLater { scriptToRun.smartDelete() }
io("Generate wrapping bash script") {
FileUtil.writeFileAndReportErrors(scriptToRun, "#!/bin/bash\n${executable} \"$@\"");
FileUtil.setExectuableAttribute(scriptToRun.getPath(), true)
}

return createProgramCommandline(scriptToRun.getPath(), arguments)
return execute(scriptToRun.getPath(), arguments)
}
}
}
Expand Down

0 comments on commit 26791ed

Please sign in to comment.