-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf!: make the plugin compatible with Gradle's configuration cache (#…
…677) * build(kotlin): enable context receivers via compiler args Signed-off-by: Maksym Moroz <maksymmoroz@duck.com> * feat: make GitSemVer configuration cache compatible Use ValueSource APIs for running external processes in a cacheable way Signed-off-by: Maksym Moroz <maksymmoroz@duck.com> * feat!: lift project from extension for configuration cache compatibility Referring to project instance from task action is a bad practice in general and a compilation error with configuration cache. By lifting project out it's possible to pass only actually needed values like projectDir and logger. This change also highlighted the fact project version is getting mutated inside the extension in a side effect-like way. Signed-off-by: Maksym Moroz <maksymmoroz@duck.com> * Revert "build(kotlin): enable context receivers via compiler args" This reverts commit 00fa181. --------- Signed-off-by: Maksym Moroz <maksymmoroz@duck.com>
- Loading branch information
1 parent
8505839
commit 75396a7
Showing
3 changed files
with
185 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/org/danilopianini/gradle/gitsemver/source/GitCommandValueSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.danilopianini.gradle.gitsemver.source | ||
|
||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.ValueSource | ||
import org.gradle.api.provider.ValueSourceParameters | ||
import org.gradle.process.ExecOperations | ||
import java.io.ByteArrayOutputStream | ||
import java.io.File | ||
import java.nio.charset.Charset | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Value source for reading results of external git commands. | ||
*/ | ||
abstract class GitCommandValueSource : ValueSource<String, Parameters> { | ||
|
||
/** | ||
* Execution operations instance to execute external process. | ||
*/ | ||
@get:Inject | ||
abstract val execOperations: ExecOperations | ||
|
||
override fun obtain(): String { | ||
val output = ByteArrayOutputStream() | ||
|
||
execOperations.exec { | ||
it.apply { | ||
commandLine = parameters.commands.get() | ||
workingDir = parameters.directory.get() | ||
standardOutput = output | ||
isIgnoreExitValue = true | ||
} | ||
} | ||
return String(output.toByteArray(), Charset.defaultCharset()) | ||
} | ||
} | ||
|
||
/** | ||
* Parameters for passing down git command list. | ||
*/ | ||
interface Parameters : ValueSourceParameters { | ||
|
||
/** | ||
* List of commands to execute in an external process. | ||
*/ | ||
val commands: ListProperty<String> | ||
|
||
/** | ||
* Working directory to execute external process in. | ||
*/ | ||
val directory: Property<File> | ||
} |