Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.github.vlsi.gradle.gettext

import org.gradle.api.DefaultTask
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Input
import org.gradle.kotlin.dsl.property
Expand All @@ -31,4 +32,7 @@ abstract class BaseGettextTask @Inject constructor(

@get:Inject
protected abstract val execOperations: ExecOperations

@get:Inject
protected abstract val fileSystemOperations: FileSystemOperations
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.github.vlsi.gradle.gettext

import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.IgnoreEmptyDirectories
Expand All @@ -32,6 +34,7 @@ import org.gradle.kotlin.dsl.setProperty
import javax.inject.Inject

abstract class GettextTask @Inject constructor(
layout: ProjectLayout,
objects: ObjectFactory
) : BaseGettextEditTask(objects) {
@Input
Expand All @@ -55,20 +58,24 @@ abstract class GettextTask @Inject constructor(

@OutputFile
val outputPot = objects.fileProperty()
.convention(project.layout.buildDirectory.file("gettext/$name/messages.pot"))
.convention(layout.buildDirectory.file("gettext/$name/messages.pot"))

@get:Internal
protected abstract val inputFilesList: RegularFileProperty

@get:Internal
protected abstract val projectDir: DirectoryProperty

init {
executable.convention("xgettext")
inputFilesList.set(project.layout.buildDirectory.file("gettext/$name/input_files.txt"))
inputFilesList.set(layout.buildDirectory.file("gettext/$name/input_files.txt"))
projectDir.set(layout.projectDirectory)
}

@TaskAction
fun run() {
val inputFilesList = this.inputFilesList.get().asFile
val baseDir = project.projectDir
val baseDir = projectDir.get().asFile
inputFilesList.writer().buffered().use { f ->
sourceFiles.files.forEach {
f.append(it.relativeTo(baseDir).path).append(System.lineSeparator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.github.vlsi.gradle.gettext

import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.FileType
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Input
Expand Down Expand Up @@ -63,7 +64,9 @@ abstract class MsgAttribTask @Inject constructor(
val outFile = File(outDir, po.file.name)
if (po.changeType == ChangeType.REMOVED) {
logger.debug("Removing output {}", outFile)
project.delete(outFile)
fileSystemOperations.delete {
delete(outFile)
}
continue
}
logger.debug("Processing {} with {} {}", po.file, cmd, arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import java.nio.charset.Charset
import javax.inject.Inject

abstract class MsgFmtTask @Inject constructor(
objects: ObjectFactory
objects: ObjectFactory,
) : BaseGettextTask(objects) {
@InputFiles
@Incremental
Expand Down Expand Up @@ -96,11 +96,15 @@ abstract class MsgFmtTask @Inject constructor(
val outFile = File(outDir, outputName)
if (po.changeType == ChangeType.REMOVED) {
logger.debug("Removing output {}", outFile)
project.delete(outFile)
fileSystemOperations.delete {
delete(outFile)
}
continue
}
logger.debug("Processing {} with {} {}", po.file, cmd, arg)
project.delete(tmpDir)
fileSystemOperations.delete {
delete(tmpDir)
}
tmpDir.mkdirs()
execOperations.exec {
executable = cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ abstract class MsgMergeTask @Inject constructor(
val outFile = File(outDir, po.file.name)
if (po.changeType == ChangeType.REMOVED) {
logger.debug("Removing output {}", outFile)
project.delete(outFile)
fileSystemOperations.delete {
delete(outFile)
}
continue
}
logger.debug("Processing {} with {} {}", po.file, cmd, arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.ProjectLayout
import org.gradle.api.internal.artifacts.DefaultModuleIdentifier
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -97,8 +99,10 @@ enum class ErrorLanguage {
KOTLIN, GROOVY, ENGLISH
}

open class GatherLicenseTask @Inject constructor(
objectFactory: ObjectFactory,
abstract class GatherLicenseTask @Inject constructor(
layout: ProjectLayout,
private val objectFactory: ObjectFactory,
private val fileSystemOperations: FileSystemOperations,
private val workerExecutor: WorkerExecutor
) : DefaultTask() {
init {
Expand Down Expand Up @@ -169,14 +173,14 @@ open class GatherLicenseTask @Inject constructor(

@OutputDirectory
val licenseDir = objectFactory.directoryProperty().convention(
project.layout.buildDirectory.dir("licenses/$name")
layout.buildDirectory.dir("licenses/$name")
)

@InputFiles
@Optional
@PathSensitive(PathSensitivity.RELATIVE)
val extraLicenseDir = objectFactory.directoryProperty().convention(
project.layout.projectDirectory.dir("licenses")
layout.projectDirectory.dir("licenses")
)

// Used in test
Expand Down Expand Up @@ -445,7 +449,9 @@ open class GatherLicenseTask @Inject constructor(
val outDir = outDirectoryName + if (outDirectoryName.endsWith(".jar")) ".contents" else ""
val artLicenseTexts = File(licenseTextDir, outDir)
if (artLicenseTexts.isDirectory) {
project.delete(artLicenseTexts)
fileSystemOperations.delete {
delete(artLicenseTexts)
}
}
val licenseOverride = licenseOverrides[compId]

Expand All @@ -470,7 +476,7 @@ open class GatherLicenseTask @Inject constructor(
}

if (licenseFiles != null) {
project.copy {
fileSystemOperations.copy {
into(artLicenseTexts)
from(licenseFiles)
}
Expand Down Expand Up @@ -582,7 +588,7 @@ open class GatherLicenseTask @Inject constructor(
continue
}
val bestLicenses =
project.fileTree(licenseDir) {
objectFactory.fileTree().from(licenseDir).matching {
include("**")
}.flatMap { f ->
// For each file take best 5 predictions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,42 @@ import com.github.vlsi.gradle.release.jgit.dsl.useRun
import org.ajoberstar.grgit.Grgit
import org.eclipse.jgit.api.Git
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.gradle.kotlin.dsl.property
import javax.inject.Inject

abstract class DefaultGitTask : DefaultTask() {
@Internal
val repository = project.objects.property<GitConfig>()
@get:Inject
protected abstract val layout: ProjectLayout

@Internal
val repositoryLocation = project.objects.directoryProperty()
.convention(project.layout.buildDirectory.dir(repository.map { it.name }))
@get:Internal
abstract val repository: Property<GitConfig>

@get:Internal
abstract val repositoryLocation: DirectoryProperty

@get:Internal
abstract val rootDir: DirectoryProperty

@get:Internal
protected val grgit = project.property("grgit") as Grgit

init {
// Never up to date
outputs.upToDateWhen { false }
repositoryLocation.convention(
layout.buildDirectory.dir(repository.map { it.name })
)
rootDir.set(project.rootProject.layout.projectDirectory)
}

protected fun <R> jgit(action: Git.() -> R): R {
val location = repositoryLocation.get().asFile
if (location != project.rootDir) {
if (location != rootDir.get().asFile) {
return Git.open(location).useRun(action)
}
val grgit = project.property("grgit") as Grgit
return grgit.repository.jgit.use(action)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package com.github.vlsi.gradle.release

import com.github.vlsi.gradle.release.jgit.dsl.*
import org.eclipse.jgit.api.errors.EmptyCommitException
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.property

open class GitCommitAndPush : DefaultGitTask() {
@Input
val commitMessage = project.objects.property<String>()
abstract class GitCommitAndPush : DefaultGitTask() {
@get:Input
abstract val commitMessage: Property<String>

@TaskAction
fun execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ package com.github.vlsi.gradle.release

import com.github.vlsi.gradle.release.jgit.dsl.tag
import org.eclipse.jgit.lib.Constants
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.property

open class GitCreateTagTask : DefaultGitTask() {
@Input
val tag = project.objects.property<String>()
abstract class GitCreateTagTask : DefaultGitTask() {
@get:Input
abstract val tag : Property<String>

@Input
@Optional
val taggedRef = project.objects.property<String>()
@get:Input
@get:Optional
abstract val taggedRef : Property<String>

init {
onlyIf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.eclipse.jgit.util.FileUtils
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

open class GitPrepareRepo : DefaultGitTask() {
abstract class GitPrepareRepo : DefaultGitTask() {
// Tell Gradle the directory is output, so it does not clean it on Gradle upgrades
@OutputDirectory
val outputDir = repositoryLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import com.github.vlsi.gradle.release.jgit.dsl.updateRemoteParams
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.transport.RefSpec
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.listProperty

open class GitPushTask : DefaultGitTask() {
@Input
val refSpecs = project.objects.listProperty<RefSpec>()
abstract class GitPushTask : DefaultGitTask() {
@get:Input
abstract val refSpecs : ListProperty<RefSpec>

fun tag(tagName: String) {
val ref = Constants.R_TAGS + tagName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@
package com.github.vlsi.gradle.release

import com.github.vlsi.gradle.release.svn.LsDepth
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.the
import org.gradle.work.InputChanges

abstract class PromoteSvnRelease : SvnmuccTask() {
@get:Input
abstract val useCpWorkaround : Property<Boolean>

init {
outputs.upToDateWhen { false }
useCpWorkaround.convention(true)
}

@Input
val useCpWorkaround = project.objects.property<Boolean>().convention(true)

private val ext = project.the<ReleaseExtension>()

override fun message() =
project.the<ReleaseExtension>().run {
releaseExtension.run {
"Promoting ${componentName.get()} ${rcTag.get()} -> ${releaseTag.get()} to release area"
}

override fun operations(inputChanges: InputChanges): List<SvnOperation> {
return mutableListOf<SvnOperation>().apply {
val svnDist = ext.svnDist
val svnDist = releaseExtension.svnDist
val stageFolder = svnDist.stageFolder.get()
val releaseFolder = svnDist.releaseFolder.get()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ open class ReleaseExtension @Inject constructor(
val validateNexusCredentials =
project.validate { nexus.credentials }.toMutableList()

protected val grgit = project.property("grgit") as Grgit

val validateBeforeBuildingReleaseArtifacts = mutableListOf(Runnable {
if (allowUncommittedChanges.get()) {
return@Runnable
}
val grgit = project.property("grgit") as Grgit
val jgit = grgit.repository.jgit
jgit.status().call().apply {
if (!hasUncommittedChanges()) {
Expand Down Expand Up @@ -323,7 +324,7 @@ open class GitConfig @Inject constructor(

open class Credentials @Inject constructor(
val name: String,
private val ext: ReleaseExtension,
ext: ReleaseExtension,
objects: ObjectFactory
) {
operator fun invoke(action: Credentials.() -> Unit) = apply { action() }
Expand All @@ -344,7 +345,7 @@ open class Credentials @Inject constructor(
fun password(project: Project, required: Boolean = false): String? {
val property = password.get()
val value = project.stringProperty(property, required)
project.logger.debug("Using password from property {}", property, value?.let { "***" })
project.logger.debug("Using password from property {}", property)
return value
}
}
Expand Down
Loading
Loading