diff --git a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt index 1c78ba6ba12b7..1a155743eacd2 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt @@ -396,7 +396,8 @@ class Bazel( "--disk_cache=", "--lockfile_mode=update", workingDir = projectDir - ) + ).requireSuccess() + val mainModule = process.stdout.parseBazelModule() val (mainDeps, devDeps) = mainModule.dependencies.map { module -> val name = module.name ?: module.key.substringBefore("@", "") diff --git a/plugins/package-managers/bower/src/main/kotlin/Bower.kt b/plugins/package-managers/bower/src/main/kotlin/Bower.kt index 955913fec2b54..f74964842b227 100644 --- a/plugins/package-managers/bower/src/main/kotlin/Bower.kt +++ b/plugins/package-managers/bower/src/main/kotlin/Bower.kt @@ -100,7 +100,7 @@ class Bower( private fun getProjectPackageInfo(workingDir: File): PackageInfo { run(workingDir, "--allow-root", "install").requireSuccess() - val json = run(workingDir, "--allow-root", "list", "--json").stdout + val json = run(workingDir, "--allow-root", "list", "--json").requireSuccess().stdout return parsePackageInfoJson(json) } } diff --git a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt index 3db252c0a27a5..99c6be245f421 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt @@ -129,7 +129,7 @@ class Cargo( override fun resolveDependencies(definitionFile: File, labels: Map): List { val workingDir = definitionFile.parentFile - val metadataProcess = run(workingDir, "metadata", "--format-version=1") + val metadataProcess = run(workingDir, "metadata", "--format-version=1").requireSuccess() val metadata = json.decodeFromString(metadataProcess.stdout) val projectId = requireNotNull(metadata.resolve.root) { diff --git a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt index 488601d834739..0225daa393db0 100644 --- a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt +++ b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt @@ -92,7 +92,7 @@ class CocoaPods( override fun resolveDependencies(definitionFile: File, labels: Map): List = stashDirectories(Os.userHomeDirectory.resolve(".cocoapods/repos")).use { // Ensure to use the CDN instead of the monolithic specs repo. - run("repo", "add-cdn", "trunk", "https://cdn.cocoapods.org", "--allow-root") + run("repo", "add-cdn", "trunk", "https://cdn.cocoapods.org", "--allow-root").requireSuccess() try { resolveDependenciesInternal(definitionFile) @@ -188,7 +188,7 @@ class CocoaPods( "--allow-root", "--regex", workingDir = workingDir - ) + ).requireSuccess() }.getOrElse { val messages = it.collectMessages() diff --git a/plugins/package-managers/composer/src/main/kotlin/Composer.kt b/plugins/package-managers/composer/src/main/kotlin/Composer.kt index f4997d134171b..9d40877f3b3e8 100644 --- a/plugins/package-managers/composer/src/main/kotlin/Composer.kt +++ b/plugins/package-managers/composer/src/main/kotlin/Composer.kt @@ -254,7 +254,7 @@ class Composer( "--no-install".takeIf { composerVersion.major >= 2 } ) - run(workingDir, *args.toTypedArray()) + run(workingDir, *args.toTypedArray()).requireSuccess() return lockfile } diff --git a/plugins/package-managers/conan/src/main/kotlin/Conan.kt b/plugins/package-managers/conan/src/main/kotlin/Conan.kt index 85d443d2024d8..4111f955ecb55 100644 --- a/plugins/package-managers/conan/src/main/kotlin/Conan.kt +++ b/plugins/package-managers/conan/src/main/kotlin/Conan.kt @@ -172,8 +172,10 @@ class Conan( if (lockfileName != null) { verifyLockfileBelongsToProject(workingDir, lockfileName) run(workingDir, "info", definitionFile.name, "-l", lockfileName, "--json", jsonFile.absolutePath) + .requireSuccess() } else { run(workingDir, "info", definitionFile.name, "--json", jsonFile.absolutePath, *DUMMY_COMPILER_SETTINGS) + .requireSuccess() } val pkgInfos = parsePackageInfos(jsonFile) @@ -227,12 +229,12 @@ class Conan( private fun configureRemoteAuthentication(conanConfig: File?) { // Install configuration from a local directory if available. conanConfig?.let { - run("config", "install", it.absolutePath) + run("config", "install", it.absolutePath).requireSuccess() } // List configured remotes in "remotes.txt" format. val remoteList = runCatching { - run("remote", "list", "--raw") + run("remote", "list", "--raw").requireSuccess() }.getOrElse { logger.warn { "Failed to list remotes." } return @@ -271,6 +273,7 @@ class Conan( // Configure Conan's authentication based on ORT's authentication for the remote. runCatching { run("user", "-r", remoteName, "-p", String(auth.password).masked(), auth.userName.masked()) + .requireSuccess() }.onFailure { logger.error { "Failed to configure user authentication for remote '$remoteName'." } } @@ -341,7 +344,9 @@ class Conan( // Note: While Conan 2 supports inspect output to stdout, Conan 1 does not and a temporary file is required, // see https://github.com/conan-io/conan/issues/6972. val jsonFile = createOrtTempDir().resolve("inspect.json") - run(workingDir, "inspect", pkgName, "--json", jsonFile.absolutePath) + + run(workingDir, "inspect", pkgName, "--json", jsonFile.absolutePath).requireSuccess() + Json.parseToJsonElement(jsonFile.readText()).jsonObject.also { jsonFile.parentFile.safeDeleteRecursively() } diff --git a/plugins/package-managers/go/src/main/kotlin/GoMod.kt b/plugins/package-managers/go/src/main/kotlin/GoMod.kt index 0773791e84dc5..ace6be594062a 100644 --- a/plugins/package-managers/go/src/main/kotlin/GoMod.kt +++ b/plugins/package-managers/go/src/main/kotlin/GoMod.kt @@ -264,7 +264,7 @@ class GoMod( } private fun runGo(vararg args: CharSequence, workingDir: File? = null) = - run(args = args, workingDir = workingDir, environment = environment) + run(args = args, workingDir = workingDir, environment = environment).requireSuccess() private fun ModuleInfo.toId(): Identifier { if (replace != null) return replace.toId() // Apply replace directive. diff --git a/plugins/package-managers/gradle-inspector/src/funTest/kotlin/GradleFunTest.kt b/plugins/package-managers/gradle-inspector/src/funTest/kotlin/GradleFunTest.kt index 0cad5bb919ba6..82c7f5a4b8840 100644 --- a/plugins/package-managers/gradle-inspector/src/funTest/kotlin/GradleFunTest.kt +++ b/plugins/package-managers/gradle-inspector/src/funTest/kotlin/GradleFunTest.kt @@ -61,7 +61,7 @@ class GradleFunTest : StringSpec() { override suspend fun afterSpec(spec: Spec) { // Reset the Gradle wrapper files to the committed state. - GitCommand.run(projectDir, "checkout", "gradle/", "gradlew*") + GitCommand.run(projectDir, "checkout", "gradle/", "gradlew*").requireSuccess() } init { diff --git a/plugins/package-managers/gradle/src/funTest/kotlin/GradleFunTest.kt b/plugins/package-managers/gradle/src/funTest/kotlin/GradleFunTest.kt index b94f8471c84ef..2d3a547b822d3 100644 --- a/plugins/package-managers/gradle/src/funTest/kotlin/GradleFunTest.kt +++ b/plugins/package-managers/gradle/src/funTest/kotlin/GradleFunTest.kt @@ -61,7 +61,7 @@ class GradleFunTest : StringSpec() { override suspend fun afterSpec(spec: Spec) { // Reset the Gradle wrapper files to the committed state. - GitCommand.run(projectDir, "checkout", "gradle/", "gradlew*") + GitCommand.run(projectDir, "checkout", "gradle/", "gradlew*").requireSuccess() } init { diff --git a/plugins/package-managers/node/src/main/kotlin/npm/Npm.kt b/plugins/package-managers/node/src/main/kotlin/npm/Npm.kt index 8213d275bcde7..874a7c17a1406 100644 --- a/plugins/package-managers/node/src/main/kotlin/npm/Npm.kt +++ b/plugins/package-managers/node/src/main/kotlin/npm/Npm.kt @@ -144,7 +144,7 @@ class Npm( PackageManagerResult(projectResults, graphBuilder.build(), graphBuilder.packages()) private fun listModules(workingDir: File): ModuleInfo { - val json = run(workingDir, "list", "--depth", "Infinity", "--json", "--long").stdout + val json = run(workingDir, "list", "--depth", "Infinity", "--json", "--long").requireSuccess().stdout return parseNpmList(json) } @@ -153,7 +153,7 @@ class Npm( npmViewCache[packageName]?.let { return it } return runCatching { - val process = run(workingDir, "info", "--json", packageName) + val process = run(workingDir, "info", "--json", packageName).requireSuccess() parsePackageJson(process.stdout) }.onFailure { e -> diff --git a/plugins/package-managers/node/src/main/kotlin/pnpm/Pnpm.kt b/plugins/package-managers/node/src/main/kotlin/pnpm/Pnpm.kt index e9f1d21a65e9a..9edb6fe726250 100644 --- a/plugins/package-managers/node/src/main/kotlin/pnpm/Pnpm.kt +++ b/plugins/package-managers/node/src/main/kotlin/pnpm/Pnpm.kt @@ -103,7 +103,7 @@ class Pnpm( override fun command(workingDir: File?) = if (Os.isWindows) "pnpm.cmd" else "pnpm" private fun getWorkspaceModuleDirs(workingDir: File): Set { - val json = run(workingDir, "list", "--json", "--only-projects", "--recursive").stdout + val json = run(workingDir, "list", "--json", "--only-projects", "--recursive").requireSuccess().stdout return parsePnpmList(json).mapTo(mutableSetOf()) { File(it.path) } } @@ -114,7 +114,8 @@ class Pnpm( Scope.DEV_DEPENDENCIES -> "--dev" } - val json = run(workingDir, "list", "--json", "--recursive", "--depth", "Infinity", scopeOption).stdout + val json = run(workingDir, "list", "--json", "--recursive", "--depth", "Infinity", scopeOption).requireSuccess() + .stdout return parsePnpmList(json) } @@ -134,7 +135,7 @@ class Pnpm( "--ignore-scripts", "--frozen-lockfile", // Use the existing lockfile instead of updating an outdated one. workingDir = workingDir - ) + ).requireSuccess() override fun beforeResolution(definitionFiles: List) = // We do not actually depend on any features specific to a PNPM version, but we still want to stick to a @@ -145,7 +146,7 @@ class Pnpm( packageDetailsCache[packageName]?.let { return it } return runCatching { - val process = run(workingDir, "info", "--json", packageName) + val process = run(workingDir, "info", "--json", packageName).requireSuccess() parsePackageJson(process.stdout) }.onFailure { e -> diff --git a/plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt b/plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt index ec0bcd45d4fbd..18ef0cdfb61a6 100644 --- a/plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt +++ b/plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt @@ -345,13 +345,13 @@ open class Yarn( private fun installDependencies(workingDir: File) { requireLockfile(workingDir) { hasLockfile(workingDir) } - run(workingDir, "install", "--ignore-scripts", "--ignore-engines", "--immutable") + run(workingDir, "install", "--ignore-scripts", "--ignore-engines", "--immutable").requireSuccess() } internal fun getRemotePackageDetails(workingDir: File, packageName: String): PackageJson? { yarnInfoCache.read(packageName)?.let { return parsePackageJson(it) } - val process = run(workingDir, "info", "--json", packageName) + val process = run(workingDir, "info", "--json", packageName).requireSuccess() return parseYarnInfo(process.stdout, process.stderr)?.also { yarnInfoCache.write(packageName, Json.encodeToString(it)) diff --git a/plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt b/plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt index 09011bb72f608..a5220784480e3 100644 --- a/plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt +++ b/plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt @@ -211,7 +211,7 @@ class Yarn2( } private fun installDependencies(workingDir: File) { - run("install", workingDir = workingDir) + run("install", workingDir = workingDir).requireSuccess() } private fun getPackageInfos(workingDir: File): List { @@ -223,7 +223,7 @@ class Yarn2( "--json", workingDir = workingDir, environment = mapOf("YARN_NODE_LINKER" to "pnp") - ) + ).requireSuccess() return parsePackageInfos(process.stdout) } @@ -279,7 +279,8 @@ class Yarn2( environment = mapOf("NODE_TLS_REJECT_UNAUTHORIZED" to "0") .takeIf { disableRegistryCertificateVerification } .orEmpty() - ) + ).requireSuccess() + val packageJsons = parsePackageJsons(process.stdout) logger.info { "Chunk #$index packages details have been fetched." } diff --git a/plugins/package-managers/nuget/src/main/kotlin/utils/NuGetInspector.kt b/plugins/package-managers/nuget/src/main/kotlin/utils/NuGetInspector.kt index a12b182676417..5aaaca5aacbf0 100644 --- a/plugins/package-managers/nuget/src/main/kotlin/utils/NuGetInspector.kt +++ b/plugins/package-managers/nuget/src/main/kotlin/utils/NuGetInspector.kt @@ -65,7 +65,7 @@ internal object NuGetInspector : CommandLineTool { } return try { - run(workingDir, *commandLineOptions.toTypedArray()) + run(workingDir, *commandLineOptions.toTypedArray()).requireSuccess() outputFile.inputStream().use { json.decodeFromStream(it) } } finally { workingDir.resolve(".cache").safeDeleteRecursively() diff --git a/plugins/package-managers/pub/src/main/kotlin/Pub.kt b/plugins/package-managers/pub/src/main/kotlin/Pub.kt index 8a7ec773501f1..5675be0e36b7a 100644 --- a/plugins/package-managers/pub/src/main/kotlin/Pub.kt +++ b/plugins/package-managers/pub/src/main/kotlin/Pub.kt @@ -747,7 +747,7 @@ class Pub( } else { // The "get" command creates a "pubspec.lock" file (if not yet present) except for projects without any // dependencies, see https://dart.dev/tools/pub/cmd/pub-get. - run(workingDir, "get") + run(workingDir, "get").requireSuccess() } } diff --git a/plugins/package-managers/python/src/main/kotlin/utils/PythonInspector.kt b/plugins/package-managers/python/src/main/kotlin/utils/PythonInspector.kt index 69dde6884f94d..4351bb7dc1ddb 100644 --- a/plugins/package-managers/python/src/main/kotlin/utils/PythonInspector.kt +++ b/plugins/package-managers/python/src/main/kotlin/utils/PythonInspector.kt @@ -90,7 +90,7 @@ internal object PythonInspector : CommandLineTool { } return try { - run(workingDir, *commandLineOptions.toTypedArray()) + run(workingDir, *commandLineOptions.toTypedArray()).requireSuccess() outputFile.inputStream().use { json.decodeFromStream(it) } } finally { outputFile.parentFile.safeDeleteRecursively() diff --git a/plugins/package-managers/sbt/src/funTest/kotlin/SbtFunTest.kt b/plugins/package-managers/sbt/src/funTest/kotlin/SbtFunTest.kt index 336bcbdd5d851..b0991ffae78f4 100644 --- a/plugins/package-managers/sbt/src/funTest/kotlin/SbtFunTest.kt +++ b/plugins/package-managers/sbt/src/funTest/kotlin/SbtFunTest.kt @@ -37,7 +37,7 @@ class SbtFunTest : StringSpec({ val expectedResult = matchExpectedResult(expectedResultFile, definitionFile) // Clean any previously generated POM files / target directories. - GitCommand.run(definitionFile.parentFile, "clean", "-fd") + GitCommand.run(definitionFile.parentFile, "clean", "-fd").requireSuccess() val ortResult = analyze( definitionFile.parentFile, @@ -56,7 +56,7 @@ class SbtFunTest : StringSpec({ val expectedResult = matchExpectedResult(expectedResultFile, definitionFile) // Clean any previously generated POM files / target directories. - GitCommand.run(definitionFile.parentFile, "clean", "-fd") + GitCommand.run(definitionFile.parentFile, "clean", "-fd").requireSuccess() val ortResult = analyze( definitionFile.parentFile, diff --git a/plugins/package-managers/sbt/src/main/kotlin/Sbt.kt b/plugins/package-managers/sbt/src/main/kotlin/Sbt.kt index 46d3bf32af981..3442ce2360d30 100644 --- a/plugins/package-managers/sbt/src/main/kotlin/Sbt.kt +++ b/plugins/package-managers/sbt/src/main/kotlin/Sbt.kt @@ -154,7 +154,7 @@ class Sbt( fun runSbt(vararg command: String) = suppressInput { - run(workingDir, *getSbtOptions(sbtVersion, javaHome).toTypedArray(), *command) + run(workingDir, *getSbtOptions(sbtVersion, javaHome).toTypedArray(), *command).requireSuccess() } // Get the list of project names. diff --git a/plugins/package-managers/stack/src/main/kotlin/Stack.kt b/plugins/package-managers/stack/src/main/kotlin/Stack.kt index 9368dd10d9d82..130adc75b23ce 100644 --- a/plugins/package-managers/stack/src/main/kotlin/Stack.kt +++ b/plugins/package-managers/stack/src/main/kotlin/Stack.kt @@ -111,7 +111,7 @@ class Stack( // Delete any left-overs from interrupted stack runs. workingDir.resolve(".stack-work").safeDeleteRecursively() - return run(workingDir, *command) + return run(workingDir, *command).requireSuccess() } private fun listDependencies(workingDir: File, scope: String): List { diff --git a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt index 8c83823bb9aca..c1b05f4e3ccf8 100644 --- a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt +++ b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt @@ -164,7 +164,7 @@ class SwiftPm( "show-dependencies", "--format", "json" - ).stdout + ).requireSuccess().stdout return parseSwiftPackage(result) } diff --git a/plugins/version-control-systems/git/src/funTest/kotlin/GitFunTest.kt b/plugins/version-control-systems/git/src/funTest/kotlin/GitFunTest.kt index e42223be89d61..46733bbac7f89 100644 --- a/plugins/version-control-systems/git/src/funTest/kotlin/GitFunTest.kt +++ b/plugins/version-control-systems/git/src/funTest/kotlin/GitFunTest.kt @@ -86,7 +86,7 @@ class GitFunTest : WordSpec({ val revision = branches.getValue(branch) git.updateWorkingTree(workingTree, branch) - GitCommand.run("reset", "--hard", "HEAD~1", workingDir = repoDir) + GitCommand.run("reset", "--hard", "HEAD~1", workingDir = repoDir).requireSuccess() git.updateWorkingTree(workingTree, branch) shouldBeSuccess branch workingTree.getRevision() shouldBe revision diff --git a/plugins/version-control-systems/git/src/main/kotlin/Git.kt b/plugins/version-control-systems/git/src/main/kotlin/Git.kt index 1f77eec9d153d..8a3fc61f60cf5 100644 --- a/plugins/version-control-systems/git/src/main/kotlin/Git.kt +++ b/plugins/version-control-systems/git/src/main/kotlin/Git.kt @@ -242,7 +242,7 @@ class Git : VersionControlSystem(GitCommand) { }.mapCatching { fetchResult -> // TODO: Migrate this to JGit once sparse checkout (https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772) is // implemented. Also see the "reset" call below. - GitCommand.run("checkout", revision, workingDir = workingTree.getRootPath()) + GitCommand.run("checkout", revision, workingDir = workingTree.getRootPath()).requireSuccess() // In case of a non-fixed revision (branch or tag) reset the working tree to ensure that the previously // fetched changes are applied. @@ -267,6 +267,7 @@ class Git : VersionControlSystem(GitCommand) { } GitCommand.run("reset", "--hard", resolvedRevision, workingDir = workingTree.getRootPath()) + .requireSuccess() } revision @@ -292,7 +293,8 @@ class Git : VersionControlSystem(GitCommand) { } } - private fun WorkingTree.runGit(vararg args: String) = GitCommand.run(*args, workingDir = workingDir) + private fun WorkingTree.runGit(vararg args: String) = + GitCommand.run(*args, workingDir = workingDir).requireSuccess() } /** diff --git a/plugins/version-control-systems/git/src/main/kotlin/GitRepo.kt b/plugins/version-control-systems/git/src/main/kotlin/GitRepo.kt index 26cdcb7e28498..b6d1c9a4bd1e7 100644 --- a/plugins/version-control-systems/git/src/main/kotlin/GitRepo.kt +++ b/plugins/version-control-systems/git/src/main/kotlin/GitRepo.kt @@ -238,6 +238,6 @@ class GitRepo : VersionControlSystem(GitRepoCommand) { // interpreter. As of repo version 2.4, Python 3.6 is required also on Windows. ProcessCapture(targetDir, "py", "-3", repo.absolutePath, *args).requireSuccess() } else { - GitRepoCommand.run(targetDir, *args) + GitRepoCommand.run(targetDir, *args).requireSuccess() } } diff --git a/plugins/version-control-systems/mercurial/src/main/kotlin/Mercurial.kt b/plugins/version-control-systems/mercurial/src/main/kotlin/Mercurial.kt index 613ab0e117b1b..602996cc5b379 100644 --- a/plugins/version-control-systems/mercurial/src/main/kotlin/Mercurial.kt +++ b/plugins/version-control-systems/mercurial/src/main/kotlin/Mercurial.kt @@ -71,7 +71,8 @@ class Mercurial : VersionControlSystem(MercurialCommand) { extensionsList += MERCURIAL_SPARSE_EXTENSION } - MercurialCommand.run(targetDir, "init") + MercurialCommand.run(targetDir, "init").requireSuccess() + targetDir.resolve(".hg/hgrc").writeText( """ [paths] @@ -88,6 +89,7 @@ class Mercurial : VersionControlSystem(MercurialCommand) { val globPatterns = getSparseCheckoutGlobPatterns() + "${vcs.path}/**" MercurialCommand.run(targetDir, "debugsparse", *globPatterns.flatMap { listOf("-I", it) }.toTypedArray()) + .requireSuccess() } return getWorkingTree(targetDir) @@ -98,7 +100,7 @@ class Mercurial : VersionControlSystem(MercurialCommand) { // To safe network bandwidth, only pull exactly the revision we want. Do not use "-u" to update the // working tree just yet, as Mercurial would only update if new changesets were pulled. But that might // not be the case if the requested revision is already available locally. - MercurialCommand.run(workingTree.getRootPath(), "pull", "-r", revision) + MercurialCommand.run(workingTree.getRootPath(), "pull", "-r", revision).requireSuccess() // TODO: Implement updating of subrepositories. diff --git a/plugins/version-control-systems/mercurial/src/main/kotlin/MercurialWorkingTree.kt b/plugins/version-control-systems/mercurial/src/main/kotlin/MercurialWorkingTree.kt index 6004f6ec2e5bd..702eeff23758c 100644 --- a/plugins/version-control-systems/mercurial/src/main/kotlin/MercurialWorkingTree.kt +++ b/plugins/version-control-systems/mercurial/src/main/kotlin/MercurialWorkingTree.kt @@ -36,14 +36,15 @@ internal class MercurialWorkingTree(workingDir: File, vcsType: VcsType) : Workin override fun isShallow() = false - override fun getRemoteUrl() = MercurialCommand.run(workingDir, "paths", "default").stdout.trimEnd() + override fun getRemoteUrl() = MercurialCommand.run(workingDir, "paths", "default").requireSuccess().stdout.trimEnd() - override fun getRevision() = MercurialCommand.run(workingDir, "--debug", "id", "-i").stdout.trimEnd() + override fun getRevision() = + MercurialCommand.run(workingDir, "--debug", "id", "-i").requireSuccess().stdout.trimEnd() - override fun getRootPath() = File(MercurialCommand.run(workingDir, "root").stdout.trimEnd()) + override fun getRootPath() = File(MercurialCommand.run(workingDir, "root").requireSuccess().stdout.trimEnd()) override fun listRemoteBranches(): List { - val branches = MercurialCommand.run(workingDir, "branches").stdout.trimEnd() + val branches = MercurialCommand.run(workingDir, "branches").requireSuccess().stdout.trimEnd() return branches.lines().map { it.substringBefore(' ') }.sorted() @@ -52,8 +53,8 @@ internal class MercurialWorkingTree(workingDir: File, vcsType: VcsType) : Workin override fun listRemoteTags(): List { // Mercurial does not have the concept of global remote tags. Its "regular tags" are defined per // branch as part of the committed ".hgtags" file. See https://stackoverflow.com/a/2059189/1127485. - MercurialCommand.run(workingDir, "pull", "-r", "default") - val tags = MercurialCommand.run(workingDir, "cat", "-r", "default", ".hgtags").stdout.trimEnd() + MercurialCommand.run(workingDir, "pull", "-r", "default").requireSuccess() + val tags = MercurialCommand.run(workingDir, "cat", "-r", "default", ".hgtags").requireSuccess().stdout.trimEnd() return tags.lines().map { it.substringAfterLast(' ') }.sorted() diff --git a/utils/common/src/main/kotlin/CommandLineTool.kt b/utils/common/src/main/kotlin/CommandLineTool.kt index 4ac73c5915ed7..bcf462cf81466 100644 --- a/utils/common/src/main/kotlin/CommandLineTool.kt +++ b/utils/common/src/main/kotlin/CommandLineTool.kt @@ -73,7 +73,7 @@ interface CommandLineTool { *args, workingDir = workingDir, environment = environment - ).requireSuccess() + ) /** * Run the command in the [workingDir] directory with arguments as specified by [args]. @@ -85,7 +85,7 @@ interface CommandLineTool { * Get the version of the command by parsing its output. */ fun getVersion(workingDir: File? = null): String { - val version = run(workingDir, *getVersionArguments().splitOnWhitespace().toTypedArray()) + val version = run(workingDir, *getVersionArguments().splitOnWhitespace().toTypedArray()).requireSuccess() // Some tools actually report the version to stderr, so try that as a fallback. val versionString = sequenceOf(version.stdout, version.stderr).map {