1
1
package kotlinx.team.infra
2
2
3
3
import org.gradle.api.*
4
- import org.gradle.api.plugins.*
5
4
import java.io.*
6
5
7
6
class TeamCityConfiguration {
8
- var projectName: String? = null
9
7
var bintrayUser: String? = null
10
8
var bintrayToken: String? = null
11
9
@@ -25,7 +23,6 @@ fun Project.configureTeamCityLogging() {
25
23
}
26
24
27
25
fun Project.configureTeamCityConfigGenerator (teamcity : TeamCityConfiguration ) {
28
- val project = this
29
26
task<DefaultTask >(" setupTeamCity" ) {
30
27
group = " build setup"
31
28
description = " Generates TeamCity project build configuration scripts"
@@ -38,15 +35,11 @@ fun Project.configureTeamCityConfigGenerator(teamcity: TeamCityConfiguration) {
38
35
.replace(" <artifactId>resource</artifactId>" , " <artifactId>teamcity</artifactId>" )
39
36
}
40
37
copyResource(teamcityDir, " settings.kts" ) { text ->
41
- val projectName = teamcity.projectName ? : project.name.removeSuffix(" -package" )
42
- val projectVersion = project.version.toString()
43
38
val bintrayUser = teamcity.bintrayUser
44
39
? : throw KotlinInfrastructureException (" TeamCity configuration should specify `bintrayUser` parameter" )
45
40
val bintrayToken = teamcity.bintrayToken
46
41
? : throw KotlinInfrastructureException (" TeamCity configuration should specify `bintrayToken` parameter" )
47
42
text
48
- .replace(" <<PROJECT_VERSION>>" , projectVersion)
49
- .replace(" <<PROJECT_NAME>>" , projectName)
50
43
.replace(" <<BINTRAY_USER>>" , bintrayUser)
51
44
.replace(" <<BINTRAY_TOKEN>>" , bintrayToken)
52
45
.replace(" <<JDK>>" , teamcity.jdk)
@@ -55,13 +48,16 @@ fun Project.configureTeamCityConfigGenerator(teamcity: TeamCityConfiguration) {
55
48
}
56
49
}
57
50
58
- private inline fun copyResource (teamcityDir : File , file : String , transform : (String ) -> String = { it }) {
51
+ private inline fun copyResource (teamcityDir : File , file : String , override : Boolean = true, transform : (String ) -> String = { it }) {
59
52
val resource = InfraPlugin ::class .java.getResourceAsStream(" /teamcity/$file " )
60
53
? : throw KotlinInfrastructureException (" Cannot find resource for teamcity file $file " )
54
+ val destinationFile = teamcityDir.resolve(file)
55
+
56
+ if (! override && destinationFile.exists()) return
61
57
62
58
resource.bufferedReader().use { input ->
63
59
val text = input.readText().let (transform)
64
- teamcityDir.resolve(file) .writeText(text)
60
+ destinationFile .writeText(text)
65
61
}
66
62
}
67
63
0 commit comments