Skip to content

Commit

Permalink
Add nuget push and delete commands
Browse files Browse the repository at this point in the history
Issue: #27
  • Loading branch information
dtretyakov committed Mar 21, 2017
1 parent 726ac3a commit ebd4f29
Show file tree
Hide file tree
Showing 28 changed files with 501 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import jetbrains.buildServer.dotnet.logger.DotnetLogger
*/
class DotnetRunnerBuildService : BuildServiceAdapter() {

private val myArgumentsProviders: Map<String, ArgumentsProvider>

init {
myArgumentsProviders = mapOf(
Pair(DotnetConstants.COMMAND_BUILD, BuildArgumentsProvider()),
Pair(DotnetConstants.COMMAND_PACK, PackArgumentsProvider()),
Pair(DotnetConstants.COMMAND_PUBLISH, PublishArgumentsProvider()),
Pair(DotnetConstants.COMMAND_RESTORE, RestoreArgumentsProvider()),
Pair(DotnetConstants.COMMAND_RUN, RunArgumentsProvider()),
Pair(DotnetConstants.COMMAND_TEST, TestArgumentsProvider()))
}
private val myArgumentsProviders: Map<String, ArgumentsProvider> = mapOf(
DotnetConstants.COMMAND_BUILD to BuildArgumentsProvider(),
DotnetConstants.COMMAND_PACK to PackArgumentsProvider(),
DotnetConstants.COMMAND_PUBLISH to PublishArgumentsProvider(),
DotnetConstants.COMMAND_RESTORE to RestoreArgumentsProvider(),
DotnetConstants.COMMAND_RUN to RunArgumentsProvider(),
DotnetConstants.COMMAND_TEST to TestArgumentsProvider(),
DotnetConstants.COMMAND_NUGET_PUSH to NugetPushArgumentsProvider(),
DotnetConstants.COMMAND_NUGET_DELETE to NugetDeleteArgumentsProvider())

@Throws(RunBuildException::class)
override fun makeProgramCommandLine(): ProgramCommandLine {
Expand All @@ -44,7 +42,6 @@ class DotnetRunnerBuildService : BuildServiceAdapter() {
val arguments = argumentsProvider.getArguments(parameters)
val toolPath: String
try {

toolPath = getToolPath(DotnetConstants.RUNNER_TYPE)
} catch (e: ToolCannotBeFoundException) {
val exception = RunBuildException(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* See LICENSE in the project root for license information.
*/

package jetbrains.buildServer.dotnet.dotnet

import jetbrains.buildServer.dotnet.ArgumentsProvider
import jetbrains.buildServer.dotnet.DotnetConstants
import jetbrains.buildServer.util.StringUtil

import java.util.ArrayList

/**
* Provides arguments to dotnet nuget delete command.
*/
class NugetDeleteArgumentsProvider : ArgumentsProvider {

override fun getArguments(parameters: Map<String, String>): List<String> {
val arguments = ArrayList<String>()
arguments.addAll(StringUtil.split(DotnetConstants.COMMAND_NUGET_DELETE))

parameters[DotnetConstants.PARAM_NUGET_DELETE_ID]?.trim()?.let {
if (it.isNotBlank()) {
arguments.addAll(StringUtil.split(it))
}
}

parameters[DotnetConstants.PARAM_NUGET_API_KEY]?.trim()?.let {
if (it.isNotBlank()) {
arguments.addAll(listOf("--api-key", it))
}
}

parameters[DotnetConstants.PARAM_NUGET_SOURCE]?.trim()?.let {
if (it.isNotBlank()) {
arguments.addAll(listOf("--source", it))
}
}

arguments.addAll(listOf("--non-interactive"))

parameters[DotnetConstants.PARAM_ARGUMENTS]?.trim()?.let {
arguments.addAll(StringUtil.splitCommandArgumentsAndUnquote(it))
}

return arguments
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* See LICENSE in the project root for license information.
*/

package jetbrains.buildServer.dotnet.dotnet

import jetbrains.buildServer.dotnet.ArgumentsProvider
import jetbrains.buildServer.dotnet.DotnetConstants
import jetbrains.buildServer.util.StringUtil

import java.util.ArrayList

/**
* Provides arguments to dotnet nuget push command.
*/
class NugetPushArgumentsProvider : ArgumentsProvider {

override fun getArguments(parameters: Map<String, String>): List<String> {
val arguments = ArrayList<String>()
arguments.addAll(StringUtil.split(DotnetConstants.COMMAND_NUGET_PUSH))

parameters[DotnetConstants.PARAM_PATHS]?.trim()?.let {
if (it.isNotBlank()) {
arguments.add(it)
}
}

parameters[DotnetConstants.PARAM_NUGET_API_KEY]?.trim()?.let {
if (it.isNotBlank()) {
arguments.addAll(listOf("--api-key", it))
}
}

parameters[DotnetConstants.PARAM_NUGET_SOURCE]?.trim()?.let {
if (it.isNotBlank()) {
arguments.addAll(listOf("--source", it))
}
}

if (parameters.getOrElse(DotnetConstants.PARAM_NUGET_PUSH_NO_SYMBOLS, { "" }).trim().toBoolean()) {
arguments.addAll(listOf("--no-symbols", "true"))
}

if (parameters.getOrElse(DotnetConstants.PARAM_NUGET_PUSH_NO_BUFFER, { "" }).trim().toBoolean()) {
arguments.addAll(listOf("--disable-buffering", "true"))
}

parameters[DotnetConstants.PARAM_ARGUMENTS]?.trim()?.let {
arguments.addAll(StringUtil.splitCommandArgumentsAndUnquote(it))
}

return arguments
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ class DotnetRunnerBuildServiceTest {
Assert.assertEquals(result, arguments)
}

@Test(dataProvider = "testNugetPushArgumentsData")
fun testNugetPushArguments(parameters: Map<String, String>, arguments: List<String>) {
val argumentsProvider = NugetPushArgumentsProvider()
val result = argumentsProvider.getArguments(parameters)

Assert.assertEquals(result, arguments)
}

@Test(dataProvider = "testNugetDeleteArgumentsData")
fun testNugetDeleteArguments(parameters: Map<String, String>, arguments: List<String>) {
val argumentsProvider = NugetDeleteArgumentsProvider()
val result = argumentsProvider.getArguments(parameters)

Assert.assertEquals(result, arguments)
}

@DataProvider
fun testBuildArgumentsData(): Array<Array<Any>> {
return arrayOf(
Expand Down Expand Up @@ -137,11 +153,19 @@ class DotnetRunnerBuildServiceTest {
DotnetConstants.PARAM_PUBLISH_RUNTIME to " active",
DotnetConstants.PARAM_VERBOSITY to "normal "),
listOf("publish", "--runtime", "active", "--verbosity", "normal")),

arrayOf(mapOf(
Pair(DotnetConstants.PARAM_PUBLISH_OUTPUT, "out"),
Pair(DotnetConstants.PARAM_PUBLISH_CONFIG, "Release")),
listOf("publish", "--configuration", "Release", "--output", "out")))
listOf("publish", "--configuration", "Release", "--output", "out")),
arrayOf(mapOf(
DotnetConstants.PARAM_PUBLISH_OUTPUT to "c:\\build\\out",
DotnetConstants.PARAM_PATHS to "project.csproj",
DotnetConstants.PARAM_PUBLISH_CONFIG to "Release",
DotnetConstants.PARAM_ARGUMENTS to
"""/p:ExternalToolsPath="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Web\External""""),
listOf("publish", "project.csproj", "--configuration", "Release", "--output", "c:\\build\\out",
"""/p:ExternalToolsPath="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Web\External""""))
)
}

@DataProvider
Expand Down Expand Up @@ -170,4 +194,32 @@ class DotnetRunnerBuildServiceTest {
arrayOf(mapOf(Pair(DotnetConstants.PARAM_TEST_OUTPUT, "out")),
listOf("test", "--output", "out")))
}

@DataProvider
fun testNugetPushArgumentsData(): Array<Array<Any>> {
return arrayOf(
arrayOf(mapOf(
DotnetConstants.PARAM_PATHS to "package.nupkg",
DotnetConstants.PARAM_NUGET_API_KEY to "key",
DotnetConstants.PARAM_NUGET_SOURCE to "http://jb.com"),
listOf("nuget", "push", "package.nupkg", "--api-key", "key", "--source", "http://jb.com")),
arrayOf(mapOf(
DotnetConstants.PARAM_PATHS to "package.nupkg",
DotnetConstants.PARAM_NUGET_PUSH_NO_BUFFER to "true",
DotnetConstants.PARAM_NUGET_PUSH_NO_SYMBOLS to "true"),
listOf("nuget", "push", "package.nupkg", "--no-symbols", "true", "--disable-buffering", "true"))
)
}

@DataProvider
fun testNugetDeleteArgumentsData(): Array<Array<Any>> {
return arrayOf(
arrayOf(mapOf(
DotnetConstants.PARAM_NUGET_DELETE_ID to "id version",
DotnetConstants.PARAM_NUGET_API_KEY to "key",
DotnetConstants.PARAM_NUGET_SOURCE to "http://jb.com"),
listOf("nuget", "delete", "id", "version", "--api-key", "key",
"--source", "http://jb.com", "--non-interactive"))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,74 @@ package jetbrains.buildServer.dotnet
/**
* Dotnet runner constants.
*/
class DotnetConstants {
companion object {
val RUNNER_TYPE = "dotnet"
val RUNNER_DISPLAY_NAME = ".NET Core (dotnet)"
val RUNNER_DESCRIPTION = "Provides build tools for .NET Core projects"
object DotnetConstants {
const val RUNNER_TYPE = "dotnet"
const val RUNNER_DISPLAY_NAME = ".NET Core (dotnet)"
const val RUNNER_DESCRIPTION = "Provides build tools for .NET Core projects"

val TOOL_HOME = "DOTNET_HOME"
val CONFIG_NAME = "DotNetCore"
val CONFIG_PATH = CONFIG_NAME + "_Path"
val PROJECT_JSON = "project.json"
val PROJECT_CSPROJ = ".csproj"
val PROJECT_SLN = ".sln"
const val TOOL_HOME = "DOTNET_HOME"
const val CONFIG_NAME = "DotNetCore"
const val CONFIG_PATH = CONFIG_NAME + "_Path"
const val PROJECT_JSON = "project.json"
const val PROJECT_CSPROJ = ".csproj"
const val PROJECT_SLN = ".sln"

val COMMAND_BUILD = "build"
val COMMAND_PACK = "pack"
val COMMAND_PUBLISH = "publish"
val COMMAND_RESTORE = "restore"
val COMMAND_TEST = "test"
val COMMAND_RUN = "run"
const val COMMAND_BUILD = "build"
const val COMMAND_PACK = "pack"
const val COMMAND_PUBLISH = "publish"
const val COMMAND_RESTORE = "restore"
const val COMMAND_TEST = "test"
const val COMMAND_RUN = "run"
const val COMMAND_NUGET_PUSH = "nuget push"
const val COMMAND_NUGET_DELETE = "nuget delete"

val PARAM_COMMAND = "dotnet-command"
val PARAM_PATHS = "dotnet-paths"
val PARAM_ARGUMENTS = "dotnet-args"
val PARAM_VERBOSITY = "dotnet-verbosity"
const val PARAM_COMMAND = "dotnet-command"
const val PARAM_PATHS = "dotnet-paths"
const val PARAM_ARGUMENTS = "dotnet-args"
const val PARAM_VERBOSITY = "dotnet-verbosity"

val PARAM_BUILD_FRAMEWORK = "dotnet-build-framework"
val PARAM_BUILD_CONFIG = "dotnet-build-config"
val PARAM_BUILD_RUNTIME = "dotnet-build-runtime"
val PARAM_BUILD_NON_INCREMENTAL = "dotnet-build-not-incremental"
val PARAM_BUILD_NO_DEPENDENCIES = "dotnet-build-no-deps"
val PARAM_BUILD_OUTPUT = "dotnet-build-output"
val PARAM_BUILD_VERSION_SUFFIX = "dotnet-build-version-suffix"
const val PARAM_BUILD_FRAMEWORK = "dotnet-build-framework"
const val PARAM_BUILD_CONFIG = "dotnet-build-config"
const val PARAM_BUILD_RUNTIME = "dotnet-build-runtime"
const val PARAM_BUILD_NON_INCREMENTAL = "dotnet-build-not-incremental"
const val PARAM_BUILD_NO_DEPENDENCIES = "dotnet-build-no-deps"
const val PARAM_BUILD_OUTPUT = "dotnet-build-output"
const val PARAM_BUILD_VERSION_SUFFIX = "dotnet-build-version-suffix"

val PARAM_RESTORE_PARALLEL = "dotnet-restore-parallel"
val PARAM_RESTORE_PACKAGES = "dotnet-restore-packages"
val PARAM_RESTORE_SOURCE = "dotnet-restore-source"
val PARAM_RESTORE_CONFIG = "dotnet-restore-config"
val PARAM_RESTORE_NO_CACHE = "dotnet-restore-no-cache"
val PARAM_RESTORE_IGNORE_FAILED = "dotnet-restore-ignore-failed"
val PARAM_RESTORE_ROOT_PROJECT = "dotnet-restore-root-project"
const val PARAM_RESTORE_PARALLEL = "dotnet-restore-parallel"
const val PARAM_RESTORE_PACKAGES = "dotnet-restore-packages"
const val PARAM_RESTORE_SOURCE = "dotnet-restore-source"
const val PARAM_RESTORE_CONFIG = "dotnet-restore-config"
const val PARAM_RESTORE_NO_CACHE = "dotnet-restore-no-cache"
const val PARAM_RESTORE_IGNORE_FAILED = "dotnet-restore-ignore-failed"
const val PARAM_RESTORE_ROOT_PROJECT = "dotnet-restore-root-project"

val PARAM_PUBLISH_FRAMEWORK = "dotnet-publish-framework"
val PARAM_PUBLISH_CONFIG = "dotnet-publish-config"
val PARAM_PUBLISH_OUTPUT = "dotnet-publish-output"
val PARAM_PUBLISH_RUNTIME = "dotnet-publish-runtime"
val PARAM_PUBLISH_VERSION_SUFFIX = "dotnet-publish-version-suffix"
const val PARAM_PUBLISH_FRAMEWORK = "dotnet-publish-framework"
const val PARAM_PUBLISH_CONFIG = "dotnet-publish-config"
const val PARAM_PUBLISH_OUTPUT = "dotnet-publish-output"
const val PARAM_PUBLISH_RUNTIME = "dotnet-publish-runtime"
const val PARAM_PUBLISH_VERSION_SUFFIX = "dotnet-publish-version-suffix"

val PARAM_PACK_CONFIG = "dotnet-pack-config"
val PARAM_PACK_OUTPUT = "dotnet-pack-output"
val PARAM_PACK_TEMP = "dotnet-pack-temp"
val PARAM_PACK_VERSION_SUFFIX = "dotnet-pack-version-suffix"
val PARAM_PACK_NO_BUILD = "dotnet-pack-no-build"
val PARAM_PACK_SERVICEABLE = "dotnet-pack-serviceable"
const val PARAM_PACK_CONFIG = "dotnet-pack-config"
const val PARAM_PACK_OUTPUT = "dotnet-pack-output"
const val PARAM_PACK_TEMP = "dotnet-pack-temp"
const val PARAM_PACK_VERSION_SUFFIX = "dotnet-pack-version-suffix"
const val PARAM_PACK_NO_BUILD = "dotnet-pack-no-build"
const val PARAM_PACK_SERVICEABLE = "dotnet-pack-serviceable"

val PARAM_TEST_FRAMEWORK = "dotnet-test-framework"
val PARAM_TEST_CONFIG = "dotnet-test-config"
val PARAM_TEST_OUTPUT = "dotnet-test-output"
val PARAM_TEST_TEMP = "dotnet-test-temp"
val PARAM_TEST_RUNTIME = "dotnet-test-runtime"
val PARAM_TEST_NO_BUILD = "dotnet-test-no-build"
const val PARAM_TEST_FRAMEWORK = "dotnet-test-framework"
const val PARAM_TEST_CONFIG = "dotnet-test-config"
const val PARAM_TEST_OUTPUT = "dotnet-test-output"
const val PARAM_TEST_TEMP = "dotnet-test-temp"
const val PARAM_TEST_RUNTIME = "dotnet-test-runtime"
const val PARAM_TEST_NO_BUILD = "dotnet-test-no-build"

val PARAM_RUN_FRAMEWORK = "dotnet-run-framework"
val PARAM_RUN_CONFIG = "dotnet-run-config"
const val PARAM_RUN_FRAMEWORK = "dotnet-run-framework"
const val PARAM_RUN_CONFIG = "dotnet-run-config"

}
const val PARAM_NUGET_SOURCE = "dotnet-nuget-source"
const val PARAM_NUGET_API_KEY = "dotnet-nuget-api-key"
const val PARAM_NUGET_PUSH_NO_BUFFER = "dotnet-nuget-push-no-buffer"
const val PARAM_NUGET_PUSH_NO_SYMBOLS = "dotnet-nuget-push-no-symbols"
const val PARAM_NUGET_DELETE_ID = "dotnet-nuget-delete-id"
}
Loading

0 comments on commit ebd4f29

Please sign in to comment.