-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathktnew
executable file
·220 lines (162 loc) · 3.76 KB
/
ktnew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env ruby
KOTLIN_VERSION = '1.3.30'.freeze
COROUTINE_VERSION='1.2.0'.freeze
name = ARGV[0] || 'test-kotlin'
def sh(cmd)
puts cmd
ret = system cmd
raise 'error' unless ret
end
################################################################################
sh "mkdir #{name}"
%w[resources kotlin].each do |x|
sh "mkdir -p #{name}/src/main/#{x}"
end
sh "cd #{name}; gradle init"
build_content = <<-eos
buildscript {
ext {
kotlinVersion = '#{KOTLIN_VERSION}'
coroutineVersion = '#{COROUTINE_VERSION}'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
//maven {
// url "http://www.haoshuju.net:8078/"
//}
jcenter()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
//compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion"
testCompile "junit:junit:4.12"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
}
mainClassName = 'demo.MainKt'
defaultTasks 'run'
kotlin {
//experimental {
// coroutines 'enable'
//}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
eos
File.write "#{name}/build.gradle", build_content
main_content = <<-eos
package demo
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
println("Hello, Kotlin")
runBlocking {
val jobs = List(1_000) {
launch {
delay(1000L)
print(".")
}
}
jobs.forEach { it.join() }
}
}
eos
sh "mkdir -p #{name}/src/main/kotlin/demo"
sh "mkdir -p #{name}/src/main/java"
sh "mkdir -p #{name}/src/main/resources"
File.write "#{name}/src/main/kotlin/demo/Main.kt", main_content
################################################################
test_content = <<-eos
package demo
import org.junit.Test
import kotlin.test.assertEquals
class TestDemo {
@Test
fun testDemo() {
assertEquals(1 + 1, 2)
}
}
eos
sh "mkdir -p #{name}/src/test/kotlin/demo"
File.write "#{name}/src/test/kotlin/demo/TestDemo.kt", test_content
################################################################
gp_content = <<-eos
kotlin.incremental=true
kotlin.code.style=official
eos
File.write "#{name}/gradle.properties", gp_content
gitignore_content = <<-eos
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
# !gradle-wrapper.jar
# Cache of project
.gradletasknamecache
.idea
*.iml
.settings
.classpath
.project
bin/
.vscode/
target/
*.pyc
eos
File.write "#{name}/.gitignore", gitignore_content
## fabfile
content = <<-eos
# -*- coding: utf-8 -*-
from fabric.api import *
def run():
"""run"""
local('./gradlew run')
def dev():
"""dev"""
local('watchexec -r "./gradlew run -no-daemon"')
def clean():
"""clean"""
local('./gradlew clean')
eos
File.write("#{name}/fabfile.py", content)
content = <<-eos
task :default do
sh 'rake -T'
end
desc 'run'
task :run do
sh './gradlew run'
end
desc 'dev'
task :dev do
sh 'watchexec -r "./gradlew run -no-daemon"'
end
desc 'clean'
task :clean do
sh './gradlew clean'
end
eos
File.write("#{name}/Rakefile", content)
sh "cd #{name}; tree"
puts "cd #{name}"