From bcc47d82d2d9b8b861e4c6040019d85d7a8e5fba Mon Sep 17 00:00:00 2001 From: Matthias Held Date: Thu, 26 Nov 2020 18:05:32 +0100 Subject: [PATCH] fix reading buffer running full, bump version --- CHANGELOG.md | 4 ++ README.md | 4 +- build.gradle.kts | 2 +- src/main/kotlin/io/wusa/GitCommandRunner.kt | 3 +- .../SemverGitPluginKotlinFunctionalTest.kt | 40 +++++++++++++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bab9be..d7a5a0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.3.5] +### Fixed +- Fix large process outputs could lead to a timeout in the command runner due to the reading buffer running full and blocking the process. + ## [2.3.4] ### Fixed - Remove debug statements. diff --git a/README.md b/README.md index d53d6dc..a6c9fbf 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Gradle 2.1 and higher ``` plugins { - id("io.wusa.semver-git-plugin").version("2.3.4") + id("io.wusa.semver-git-plugin").version("2.3.5") } ``` @@ -25,7 +25,7 @@ buildscript { } } dependencies { - classpath 'io.wusa:semver-git-plugin:2.3.4' + classpath 'io.wusa:semver-git-plugin:2.3.5' } } diff --git a/build.gradle.kts b/build.gradle.kts index 8ef0c81..3418fb7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "io.wusa" -version = "2.3.4" +version = "2.3.5" dependencies { implementation(kotlin("stdlib-jdk8")) diff --git a/src/main/kotlin/io/wusa/GitCommandRunner.kt b/src/main/kotlin/io/wusa/GitCommandRunner.kt index 9d68b7d..eb19b48 100644 --- a/src/main/kotlin/io/wusa/GitCommandRunner.kt +++ b/src/main/kotlin/io/wusa/GitCommandRunner.kt @@ -8,8 +8,9 @@ class GitCommandRunner { companion object { fun execute(projectDir: File, args: Array): String { val process = startGitProcess(args, projectDir) + val output = readProcessOutput(process) waitForGitProcess(process) - if (processFinishedWithoutErrors(process)) return readProcessOutput(process) + if (processFinishedWithoutErrors(process)) return output throw GitException("Executing git command failed with " + process.exitValue()) } diff --git a/src/test/kotlin/io/wusa/SemverGitPluginKotlinFunctionalTest.kt b/src/test/kotlin/io/wusa/SemverGitPluginKotlinFunctionalTest.kt index ec7dd8e..c2b2189 100644 --- a/src/test/kotlin/io/wusa/SemverGitPluginKotlinFunctionalTest.kt +++ b/src/test/kotlin/io/wusa/SemverGitPluginKotlinFunctionalTest.kt @@ -729,4 +729,44 @@ class SemverGitPluginKotlinFunctionalTest : FunctionalBaseTest() { println(result.output) Assertions.assertTrue(result.output.contains("Version: 2.0.43-dirty-SNAPSHOT")) } + + @Test + fun `issue-61 large process outputs leads to timeouts`() { + val testProjectDirectory = createTempDir() + val buildFile = File(testProjectDirectory, "build.gradle.kts") + buildFile.writeText(""" + import io.wusa.Info + import io.wusa.TagType + + plugins { + id("io.wusa.semver-git-plugin") + } + + semver { + tagPrefix = "" + tagType = TagType.ANNOTATED + branches { + branch { + regex = ".+" + incrementer = "CONVENTIONAL_COMMITS_INCREMENTER" + formatter = Transformer{ info:Info -> "${'$'}{info.version.major}.${'$'}{info.version.minor}.${'$'}{info.version.patch}" } + } + } + } + """) + val git = initializeGitWithoutBranchAnnotated(testProjectDirectory, "2.0.42") + for (x in 0..600) { + val dirty = File(testProjectDirectory, "dirty_$x.file") + dirty.writeText("dirty") + } + git.add().addFilepattern(".").call() + + val result = gradleRunner + .withProjectDir(testProjectDirectory) + .withArguments("showInfo") + .withPluginClasspath() + .build() + println(result.output) + Assertions.assertTrue(result.output.contains("Version: 2.0.43-dirty-SNAPSHOT")) + } }