@@ -15,52 +15,52 @@ val logger = LoggerFactory.getLogger("buildSrc")
15
15
* Maven and gradle repositories.
16
16
*/
17
17
sealed class Repo (val name : String , val url : String ) {
18
- object Central : Repo(
19
- name = " Maven Central" ,
20
- url = " https://repo1.maven.org/maven2/"
21
- )
22
-
23
- object OssrhSnapshots : Repo(
24
- name = " Sonatype OSSRH Snapshots" ,
25
- url = " https://oss.sonatype.org/content/repositories/snapshots/"
26
- )
27
-
28
- object OssrhStaging : Repo(
29
- name = " Sonatype OSSRH Staging" ,
30
- url = " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
31
- )
32
-
33
- object OssrhReleases : Repo(
34
- name = " Sonatype OSSRH Releases" ,
35
- url = " https://oss.sonatype.org/content/repositories/releases/"
36
- )
37
-
38
- object OssrhPublic : Repo(
39
- name = " Sonatype OSSRH Public" ,
40
- url = " https://oss.sonatype.org/content/groups/public/"
41
- )
42
-
43
- object GradlePlugins : Repo(
44
- name = " Gradle Plugin" ,
45
- url = " https://plugins.gradle.org/m2/"
46
- )
47
-
48
- object Jetbrains : Repo(
49
- name = " Jetbrains Dev" ,
50
- url = " https://packages.jetbrains.team/maven/p/ui/dev"
51
- )
18
+ object Central : Repo(
19
+ name = " Maven Central" ,
20
+ url = " https://repo1.maven.org/maven2/"
21
+ )
22
+
23
+ object OssrhSnapshots : Repo(
24
+ name = " Sonatype OSSRH Snapshots" ,
25
+ url = " https://oss.sonatype.org/content/repositories/snapshots/"
26
+ )
27
+
28
+ object OssrhStaging : Repo(
29
+ name = " Sonatype OSSRH Staging" ,
30
+ url = " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
31
+ )
32
+
33
+ object OssrhReleases : Repo(
34
+ name = " Sonatype OSSRH Releases" ,
35
+ url = " https://oss.sonatype.org/content/repositories/releases/"
36
+ )
37
+
38
+ object OssrhPublic : Repo(
39
+ name = " Sonatype OSSRH Public" ,
40
+ url = " https://oss.sonatype.org/content/groups/public/"
41
+ )
42
+
43
+ object GradlePlugins : Repo(
44
+ name = " Gradle Plugin" ,
45
+ url = " https://plugins.gradle.org/m2/"
46
+ )
47
+
48
+ object Jetbrains : Repo(
49
+ name = " Jetbrains Dev" ,
50
+ url = " https://packages.jetbrains.team/maven/p/ui/dev"
51
+ )
52
52
}
53
53
54
54
/* *
55
55
* Check if it's a non stable (RC) version.
56
56
*/
57
57
val String .isNonStable: Boolean
58
- get() {
59
- val stableKeyword = listOf (" RELEASE" , " FINAL" , " GA" ).any { toUpperCase().contains(it) }
60
- val regex = " ^[0-9,.v-]+(-r)?$" .toRegex()
61
- val isStable = stableKeyword || regex.matches(this )
62
- return isStable.not ()
63
- }
58
+ get() {
59
+ val stableKeyword = listOf (" RELEASE" , " FINAL" , " GA" ).any { toUpperCase().contains(it) }
60
+ val regex = " ^[0-9,.v-]+(-r)?$" .toRegex()
61
+ val isStable = stableKeyword || regex.matches(this )
62
+ return isStable.not ()
63
+ }
64
64
65
65
/* *
66
66
* Checks if the project has snapshot version.
@@ -71,87 +71,89 @@ fun Project.hasSnapshotVersion() = version.toString().endsWith("SNAPSHOT", true)
71
71
* Returns the JDK install path provided by the [JavaToolchainService]
72
72
*/
73
73
val Project .javaToolchainPath
74
- get(): String {
75
- val javaToolchains = extensions.getByName(" javaToolchains" ) as JavaToolchainService
76
- return javaToolchains.launcherFor {
77
- languageVersion.set(JavaLanguageVersion .of(javaVersion))
78
- }.orNull
79
- ?.metadata
80
- ?.installationPath?.toString()
81
- ? : error(" Requested JDK version ($javaVersion ) is not available." )
82
- }
74
+ get(): String {
75
+ val javaToolchains = extensions.getByName(" javaToolchains" ) as JavaToolchainService
76
+ return javaToolchains.launcherFor {
77
+ languageVersion.set(JavaLanguageVersion .of(javaVersion))
78
+ }.orNull
79
+ ?.metadata
80
+ ?.installationPath?.toString()
81
+ ? : error(" Requested JDK version ($javaVersion ) is not available." )
82
+ }
83
83
84
84
/* *
85
85
* Returns the application `run` command.
86
86
*/
87
87
fun Project.appRunCmd (jarPath : Path , args : List <String >): String {
88
- val path = projectDir.toPath().relativize(jarPath)
89
- val newLine = System .lineSeparator()
90
- val lineCont = """ \""" // Bash line continuation
91
- val indent = " \t "
92
- println ()
93
- return args.joinToString(
94
- prefix = """
95
- To Run the app,
88
+ val path = projectDir.toPath().relativize(jarPath)
89
+ val newLine = System .lineSeparator()
90
+ val lineCont = """ \""" // Bash line continuation
91
+ val indent = " \t "
92
+ println ()
93
+ return args.joinToString(
94
+ prefix = """
95
+ To Run the app,
96
96
${' $' } java -jar $lineCont $newLine
97
97
""" .trimIndent(),
98
- postfix = " $newLine$indent$path " ,
99
- separator = newLine,
100
- ) {
101
- // Escape the globstar
102
- " $indent$it $lineCont " .replace(" *" , """ \*""" )
103
- }
98
+ postfix = " $newLine$indent$path " ,
99
+ separator = newLine,
100
+ ) {
101
+ // Escape the globstar
102
+ " $indent$it $lineCont "
103
+ .replace(" *" , """ \*""" )
104
+ .replace(" \" " , " \\\" " )
105
+ }
104
106
}
105
107
106
108
/* *
107
109
* Returns the current OS name.
108
110
*/
109
111
val os by lazy {
110
- val os = System .getProperty(" os.name" )
111
- when {
112
- os.equals(" Mac OS X" , ignoreCase = true ) -> " macos"
113
- os.startsWith(" Win" , ignoreCase = true ) -> " windows"
114
- os.startsWith(" Linux" , ignoreCase = true ) -> " linux"
115
- else -> error(" Unsupported OS: $os " )
116
- }
112
+ val os = System .getProperty(" os.name" )
113
+ when {
114
+ os.equals(" Mac OS X" , ignoreCase = true ) -> " macos"
115
+ os.startsWith(" Win" , ignoreCase = true ) -> " windows"
116
+ os.startsWith(" Linux" , ignoreCase = true ) -> " linux"
117
+ else -> error(" Unsupported OS: $os " )
118
+ }
117
119
}
118
120
119
121
/* *
120
122
* System property delegate
121
123
*/
122
124
@Suppress(" IMPLICIT_CAST_TO_ANY" )
123
125
inline fun <reified T > sysProp (): ReadOnlyProperty <Any ?, T > =
124
- ReadOnlyProperty { _, property ->
125
- val propVal = System .getProperty(property.name, " " )
126
- val propVals = propVal.split(" ," , " " ).filter { it.isNotBlank() }
127
-
128
- val kType = typeOf<T >()
129
- when (kType) {
130
- typeOf<String >() -> propVal
131
- typeOf<Int >() -> propVal.toInt()
132
- typeOf<Boolean >() -> propVal.toBoolean()
133
- typeOf<Long >() -> propVal.toLong()
134
- typeOf<Double >() -> propVal.toDouble()
135
- typeOf<List <String >>() -> propVals
136
- typeOf<List <Int >>() -> propVals.map { it.toInt() }
137
- typeOf<List <Long >>() -> propVals.map { it.toLong() }
138
- typeOf<List <Double >>() -> propVals.map { it.toDouble() }
139
- typeOf<List <Boolean >>() -> propVals.map { it.toBoolean() }
140
- else -> error(" '${property.name} ' system property type ($kType ) is not supported!" )
141
- } as T
142
- }
126
+ ReadOnlyProperty { _, property ->
127
+ val propVal = System .getProperty(property.name, " " )
128
+ val propVals = propVal.split(" ," , " " ).filter { it.isNotBlank() }
129
+
130
+ val kType = typeOf<T >()
131
+ when (kType) {
132
+ typeOf<String >() -> propVal
133
+ typeOf<Int >() -> propVal.toInt()
134
+ typeOf<Boolean >() -> propVal.toBoolean()
135
+ typeOf<Long >() -> propVal.toLong()
136
+ typeOf<Double >() -> propVal.toDouble()
137
+ typeOf<List <String >>() -> propVals
138
+ typeOf<List <Int >>() -> propVals.map { it.toInt() }
139
+ typeOf<List <Long >>() -> propVals.map { it.toLong() }
140
+ typeOf<List <Double >>() -> propVals.map { it.toDouble() }
141
+ typeOf<List <Boolean >>() -> propVals.map { it.toBoolean() }
142
+ else -> error(" '${property.name} ' system property type ($kType ) is not supported!" )
143
+ } as T
144
+ }
143
145
144
146
/* *
145
147
* Find the file ends with given [format] under the directory.
146
148
*/
147
149
fun File.findPkg (format : String? ) = when (format != null ) {
148
- true -> walk().firstOrNull { it.isFile && it.name.endsWith(format, ignoreCase = true ) }
149
- else -> null
150
+ true -> walk().firstOrNull { it.isFile && it.name.endsWith(format, ignoreCase = true ) }
151
+ else -> null
150
152
}
151
153
152
154
/* *
153
155
* Add a Github action output if it's running on an Action runner.
154
156
*/
155
157
fun ghActionOutput (name : String , value : Any ) {
156
- if (System .getenv(" GITHUB_ACTIONS" ).toBoolean()) println (" ::set-output name=$name ::$value " )
158
+ if (System .getenv(" GITHUB_ACTIONS" ).toBoolean()) println (" ::set-output name=$name ::$value " )
157
159
}
0 commit comments