1
- import com.beust.klaxon.JsonObject
1
+ import groovy.json.JsonOutput
2
2
3
+ import java.nio.file.Path
3
4
import java.nio.file.Paths
4
5
import java.util.regex.Pattern
5
6
import java.util.stream.Collectors
@@ -19,7 +20,6 @@ buildscript {
19
20
// noinspection DifferentKotlinGradleVersion
20
21
classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion "
21
22
classpath " com.github.jengelman.gradle.plugins:shadow:$shadowJarVersion "
22
- classpath " com.beust:klaxon:5.2"
23
23
}
24
24
}
25
25
@@ -43,42 +43,54 @@ allprojects {
43
43
testCompile " org.jetbrains.kotlin:kotlin-test:$kotlinVersion "
44
44
}
45
45
46
- String artifactsPathStr = rootProject. findProperty(' artifactsPath' ) ?: ' artifacts'
47
- String buildCounterStr = rootProject. findProperty(' build.counter' ) ?: ' 100500'
48
- String buildNumber = rootProject. findProperty(' build.number' ) ?: ' '
49
- String installPath = rootProject. findProperty(' installPath' )
50
-
51
- ext. rootPath = rootDir. toPath()
52
- ext. packageName = ' kotlin-jupyter-kernel'
53
- ext. artifactsDir = rootPath. resolve(artifactsPathStr)
54
- ext. isProtectedBranch = isProtectedBranch()
55
- ext. versionFileName = " VERSION"
56
-
57
- ext. installPathLocal = installPath ? Paths . get(installPath) :
58
- Paths . get(System . properties[' user.home' ]. toString(), " .ipython" , " kernels" , " kotlin" )
59
- ext. distributionPath = rootPath. resolve(" distrib" )
60
- ext. distribBuildPath = rootPath. resolve(" distrib-build" )
61
- ext. logosPath = getSubDir(rootPath, " resources" , " logos" )
62
-
63
- String devAddition = isProtectedBranch ? ' ' : ' .dev1'
64
- String defaultBuildNumber = " $baseVersion . $buildCounterStr $devAddition "
65
- String buildNumberRegex = " [0-9]+(\\ .[0-9]+){3}(\\ .dev[0-9]+)?"
66
-
67
- if (! Pattern . matches(buildNumberRegex, buildNumber)) {
68
- def versionFile = artifactsDir. resolve(versionFileName). toFile()
69
- if (versionFile. exists()) {
70
- def lines = versionFile. readLines()
71
- assert ! lines. empty, " There should be at least one line in VERSION file"
72
- buildNumber = lines. first(). trim()
46
+ ext {
47
+ packageName = " kotlin-jupyter-kernel"
48
+ versionFileName = " VERSION"
49
+
50
+ String artifactsPathStr = rootProject. findProperty(' artifactsPath' ) ?: ' artifacts'
51
+ String installPath = rootProject. findProperty(' installPath' )
52
+
53
+ // noinspection GroovyAssignabilityCheck
54
+ rootPath = rootDir. toPath()
55
+ // noinspection GroovyAssignabilityCheck
56
+ artifactsDir = rootPath. resolve(artifactsPathStr)
57
+
58
+ // noinspection GroovyAssignabilityCheck
59
+ installPathLocal = installPath ? Paths . get(installPath) :
60
+ Paths . get(System . properties[' user.home' ]. toString(), " .ipython" , " kernels" , " kotlin" )
61
+ // noinspection GroovyAssignabilityCheck
62
+ distributionPath = rootPath. resolve(" distrib" )
63
+ // noinspection GroovyAssignabilityCheck
64
+ distribBuildPath = rootPath. resolve(" distrib-build" )
65
+ // noinspection GroovyAssignabilityCheck
66
+ logosPath = getSubDir(rootPath, " resources" , " logos" )
67
+
68
+ if (project == rootProject) {
69
+ ext. isProtectedBranch = isProtectedBranch()
70
+ String buildCounterStr = rootProject. findProperty(' build.counter' ) ?: ' 100500'
71
+ String buildNumber = rootProject. findProperty(' build.number' ) ?: ' '
72
+ String devAddition = isProtectedBranch ? ' ' : ' .dev1'
73
+ String defaultBuildNumber = " $baseVersion . $buildCounterStr $devAddition "
74
+ String buildNumberRegex = " [0-9]+(\\ .[0-9]+){3}(\\ .dev[0-9]+)?"
75
+
76
+ if (! Pattern . matches(buildNumberRegex, buildNumber)) {
77
+ def versionFile = artifactsDir. resolve(versionFileName). toFile()
78
+ if (versionFile. exists()) {
79
+ def lines = versionFile. readLines()
80
+ assert ! lines. empty, " There should be at least one line in VERSION file"
81
+ buildNumber = lines. first(). trim()
82
+ } else {
83
+ buildNumber = defaultBuildNumber
84
+ }
85
+ }
86
+
87
+ project. version = buildNumber
88
+ println (" ##teamcity[buildNumber '$version ']" )
73
89
} else {
74
- buildNumber = defaultBuildNumber
90
+ ext. isProtectedBranch = rootProject. isProtectedBranch
91
+ project. version = rootProject. version
75
92
}
76
- }
77
93
78
- project. version = buildNumber
79
- println (" ##teamcity[buildNumber '$version ']" )
80
-
81
- ext {
82
94
debugPort = 1044
83
95
debuggerConfig = " -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort " . toString()
84
96
@@ -207,24 +219,24 @@ static String makeTaskName(String prefix, Boolean local) {
207
219
return prefix + (local ? " Local" : " Distrib" )
208
220
}
209
221
210
- static void makeDirs (java.nio.file. Path path ) {
222
+ static void makeDirs (Path path ) {
211
223
File dir = path. toFile()
212
224
if (! dir. exists()) {
213
225
dir. mkdirs()
214
226
}
215
227
}
216
228
217
- static java.nio.file. Path getSubDir (java.nio.file. Path dir , String ... subDir ) {
229
+ static Path getSubDir (Path dir , String ... subDir ) {
218
230
def newDir = dir
219
231
for (s in subDir) {
220
232
newDir = newDir. resolve(s)
221
233
}
222
234
return newDir
223
235
}
224
236
225
- static void writeJson (Map<String , Object > json , java.nio.file. Path path ) {
226
- def jsonString = new JsonObject (json) . toJsonString( true , false )
227
- path. toFile(). write(jsonString , ' UTF-8' )
237
+ static void writeJson (Map<String , Object > json , Path path ) {
238
+ def str = JsonOutput . prettyPrint( JsonOutput . toJson(json) )
239
+ path. toFile(). write(str , ' UTF-8' )
228
240
}
229
241
230
242
void createCleanTasks () {
@@ -241,7 +253,7 @@ void createCleanTasks() {
241
253
createCleanTasks()
242
254
243
255
@SuppressWarnings (" unused" )
244
- void createInstallTasks (Boolean local , java.nio.file. Path specPath , java.nio.file. Path mainInstallPath ) {
256
+ void createInstallTasks (Boolean local , Path specPath , Path mainInstallPath ) {
245
257
def groupName = local ? localGroup : distribGroup
246
258
def cleanDirTask = getTasks(). getByName(makeTaskName(cleanInstallDirTaskPrefix, local))
247
259
def args = [type : Copy , dependsOn : cleanDirTask, group : groupName]
@@ -267,7 +279,7 @@ void createInstallTasks(Boolean local, java.nio.file.Path specPath, java.nio.fil
267
279
}
268
280
}
269
281
270
- String createTaskForSpecs (Boolean debug , Boolean local , String group , Task cleanDir , java.nio.file. Path specPath , java.nio.file. Path mainInstallPath ) {
282
+ String createTaskForSpecs (Boolean debug , Boolean local , String group , Task cleanDir , Path specPath , Path mainInstallPath ) {
271
283
String taskName = makeTaskName(debug ? " createDebugSpecs" : " createSpecs" , local)
272
284
task([group : group], taskName) {
273
285
dependsOn cleanDir, shadowJar
@@ -308,7 +320,7 @@ void createMainInstallTask(Boolean debug, Boolean local, String group, String sp
308
320
}
309
321
}
310
322
311
- void makeKernelSpec (java.nio.file. Path installPath , Boolean localInstall ) {
323
+ void makeKernelSpec (Path installPath , Boolean localInstall ) {
312
324
def argv = localInstall ?
313
325
Arrays . asList(" python" ,
314
326
installPath. resolve(runKernelPy). toString(),
@@ -329,7 +341,7 @@ void makeKernelSpec(java.nio.file.Path installPath, Boolean localInstall) {
329
341
}
330
342
}
331
343
332
- void makeJarArgs (java.nio.file. Path installPath , String kernelJarPath , List<String > classPath , String debuggerConfig = " " ) {
344
+ void makeJarArgs (Path installPath , String kernelJarPath , List<String > classPath , String debuggerConfig = " " ) {
333
345
writeJson([
334
346
" mainJar" : kernelJarPath,
335
347
" classPath" : classPath,
@@ -346,8 +358,6 @@ task copyRunKernelPy(type: Copy, dependsOn: cleanInstallDirLocal, group: localGr
346
358
347
359
createInstallTasks(true , installPathLocal, installPathLocal)
348
360
349
- task uninstall (dependsOn : cleanInstallDirLocal, group : localGroup) {
350
-
351
- }
361
+ task uninstall (dependsOn : cleanInstallDirLocal, group : localGroup)
352
362
353
363
apply from : ' distrib.gradle'
0 commit comments