forked from Cardshifter/Cardshifter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
201 lines (181 loc) · 5.97 KB
/
build.gradle
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
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import org.ajoberstar.grgit.Grgit
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.1'
classpath 'org.ajoberstar:gradle-git:1.2.0'
}
}
plugins {
id 'net.researchgate.release' version '2.1.2'
}
allprojects {
apply plugin: 'maven'
group = 'com.cardshifter'
version = properties.version
repositories {
mavenCentral()
mavenLocal()
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "http://www.zomis.net/maven" }
}
}
release {
failOnSnapshotDependencies = false
failOnPublishNeeded = false
revertOnFail = false
versionPropertyFile = 'gradle.properties'
}
def getMavenSettingsCredentials() {
String userHome = System.getProperty('user.home')
File mavenSettings = new File(userHome, '.m2/settings.xml')
if (!mavenSettings.exists()) {
return []
}
def xmlSlurper = new XmlSlurper()
def output = xmlSlurper.parse(mavenSettings)
return output."servers"."server"
}
def getCredentials() {
def entries = getMavenSettingsCredentials()
for (entry in entries) {
if (entry."id".text() == 'cardshifter-deploy') {
return [username: entry.username.text(), password: entry.password.text()]
}
}
return [username: 'invalid', password: 'invalid']
}
subprojects {
if (!it.name.contains('-api')) {
apply plugin: 'groovy'
sourceSets {
main {
java { srcDirs = [] }
groovy { srcDir "src/main/java" }
}
}
dependencies {
compile group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.4.3'
testCompile "junit:junit:4.11"
}
test {
testLogging {
events "failed"
exceptionFormat "short"
}
}
}
}
task copyResources(type: Copy) {
dependsOn ':cardshifter-fx:createShadowedJar'
dependsOn ':cardshifter-server:createShadowedJar'
from('extra-resources')
into("$project.buildDir/libs")
include('server.properties.example')
for (File mod : new File('extra-resources/decks').listFiles()) {
println 'Checking mod ' + mod.getName()
for (File deck : mod.listFiles()) {
def modName = mod.getName()
def deckName = deck.getName()
if (Character.isUpperCase(deck.getName().charAt(0))) {
println("Include decks/${modName}/${deckName}")
include("decks/${modName}/${deckName}")
} else {
println("Deck name does not start with capital letter, skipping: decks/${modName}/${deckName}")
}
}
}
include('mods/**')
}
task createVersionFile(type: Copy) {
from('extra-resources')
include('version.txt.template')
into("$project.buildDir/libs")
rename { 'version.txt' }
def repo = Grgit.open(project.file('.'))
expand([
date: DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDateTime.now()),
branchName: repo.branch.getCurrent().getName(),
commitHash: repo.log(maxCommits: 1)[0].id
])
}
task dist(type: Zip) {
dependsOn 'copyResources'
dependsOn 'createVersionFile'
String outputDateString = DateTimeFormatter.ofPattern("yyyyMMdd-HHmm").format(LocalDateTime.now());
classifier = outputDateString
from "$project.buildDir/libs"
}
configurations {
ftpAntTask
}
dependencies {
ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
module("commons-net:commons-net:1.4.1") {
dependencies "oro:oro:2.0.8:jar"
}
}
}
def javaModules() {
subprojects.findAll {!it.name.contains('-api')}
}
task ftpUpload << {
def creds = getCredentials()
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: "www.zomis.net", userid: creds["username"], password: creds["password"], remoteDir: "public_html/cardshifter.com/releases") {
fileset(dir: "$buildDir/distributions") {
include(name: "*.zip")
}
}
}
}
ftpUpload.dependsOn 'dist'
ftpUpload.dependsOn javaModules().test
task distAndTest(type: Zip) {
dependsOn 'copyResources'
// same as 'dist' but without the classifier
rename {
println it
it.replace('-all', '')
}
from "$project.buildDir/libs"
}
distAndTest.dependsOn javaModules().test
task snapshot << {
def files = new File("$project.buildDir/distributions").listFiles()
assert files.length == 1
def file = files[0]
println 'task output is ' + file
URL url = new URL('http://stats.zomis.net/GithubHookSEChatService/bot/jsonPost')
String fname = file.getName()
String downloadURL = 'http://www.cardshifter.com/releases/' + fname
Properties props = new Properties()
props.load(new FileInputStream("localbuildconf.properties"))
String apiKey = props.get('dugaApiKey')
assert apiKey : 'property "dugaApiKey" not found in "localbuildconf.properties"'
HttpURLConnection conn = url.openConnection()
def request = '{ "roomId":"16134", "apiKey":"' + apiKey +'",' +
'"text":"New Snapshot: [' + fname + '](' + downloadURL + ')" }'
byte[] postData = request.getBytes(StandardCharsets.UTF_8);
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
conn.setUseCaches(false);
new DataOutputStream(conn.getOutputStream()).withCloseable {
it.write(postData, 0, postData.length);
it.flush()
}
def is = conn.getInputStream();
println is.text
}
snapshot.dependsOn 'ftpUpload'