-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.gradle
More file actions
219 lines (187 loc) · 7.28 KB
/
build.gradle
File metadata and controls
219 lines (187 loc) · 7.28 KB
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
/*
* BackpacksRemastered - remastered version of the popular Backpacks plugin
* Copyright (C) 2019 - 2020, Andrew Howard, <divisionind.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import com.divisionind.i18n.DiscoveredString
import com.divisionind.i18n.ExtractorPlugin
import com.divisionind.i18n.GoogleTranslator
import com.divisionind.i18n.api.FileScanUtils
import com.divisionind.i18n.api.StringDecider
import com.divisionind.i18n.api.corrector.RegexCorrectorMatcher
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.internal.os.OperatingSystem
import java.util.regex.Pattern
buildscript {
repositories {
maven {
url 'https://raw.githubusercontent.com/divisionind/maven/repo'
//url uri('../maven') // local repo for testing
}
}
dependencies {
classpath group: 'com.divisionind',
name: 'i18nExtractor',
version: '2019.0.8'
}
}
plugins {
id 'java'
}
apply plugin: ExtractorPlugin
def baseVersion = "2022.1.8"
def beta = true
def mcVersion = "1.17"
def runningServerPluginsDir = System.env.DEV_SERVER
group 'com.divisionind'
sourceCompatibility = 1.8
// returns hash of the current commit
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
// returns what commit this is in the entire history of the repo
def getGitCommitNum = { shash ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--count', shash
standardOutput = stdout
}
return stdout.toString().trim()
}
// gets the changes sense the specified short hash
def getGitChanges = { shash ->
def stdout = new ByteArrayOutputStream()
exec { // if this fails, try changing %h and %s to separate arguments
int lastReleaseInt
try {
lastReleaseInt = Integer.parseInt(getGitCommitNum(shash))
} catch (NumberFormatException e) {
lastReleaseInt = 0
}
commandLine 'git', 'log', '--pretty=format:* %h %s', '--max-count', "${Integer.parseInt(getGitCommitNum('HEAD'))-Integer.parseInt(getGitCommitNum(shash))}"
standardOutput = stdout
}
return stdout.toString().trim()
}
// what format the version info should take
version baseVersion + (beta ? "-beta.${getGitCommitNum('HEAD')}" : "")
// generates sources by replacing these strings (surrounded by @, e.g. @DivisionVersion@)
task generateSources(type: Copy) {
from 'src/main/java'
into "$buildDir/generated-src"
filter(ReplaceTokens, tokens: [
'DivisionVersion': project.version,
'DivisionGitHash': getGitHash(),
'DivisionGitComm': getGitCommitNum('HEAD')
])
}
// generates resources by replacing these strings (surrounded by @, e.g. @DivisionVersion@)
task generateResources(type: Copy) {
from 'src/main/resources'
into "$buildDir/generated-resources"
filter(ReplaceTokens, tokens: [
'DivisionVersion': project.version,
'DivisionGitHash': getGitHash(),
'DivisionGitComm': getGitCommitNum('HEAD')
])
}
internationalize {
sourcesDir file("$buildDir/generated-src")
sourceResources file("$buildDir/generated-resources")
bundleInitializerClasspath 'com.divisionind.bprm.Backpacks'
cacheDirectory file("$projectDir/.i18nExtractor")
File commandsFile = file("$sourcesDir/com/divisionind/bprm/commands")
Pattern colorPat = Pattern.compile("(?i)" + String.valueOf('&') + "[0-9A-FK-OR]")
stringDecider new StringDecider() {
@Override
boolean shouldAdd(DiscoveredString st) {
// exclude the names of backpacks from this (for now)
if (st.value == '&9Backpacks &7&l>>&r ' || st.value == '&aLinked' || st.value == 'Players=%s&BackpacksVersion=%s') {
return false
}
// return yes for any colored string
if (colorPat.matcher(st.value).results().count() > 0) return true
// these string values are not colored and would not be picked up for translation otherwise
if (st.locationFile.getParentFile().equals(commandsFile)) {
String prevLine = FileScanUtils.getLine(st.locationFile, st.line)
return prevLine.contains("String desc()")
}
}
}
// serializes color codes so they dont get messed with by the translator
translator = new GoogleTranslator(69, 10, new RegexCorrectorMatcher(colorPat),
new RegexCorrectorMatcher(Pattern.compile("0x%02x", Pattern.LITERAL)),
new RegexCorrectorMatcher(Pattern.compile("%.2f", Pattern.LITERAL)))
langs('es', 'it', 'fr', 'zh-CN', 'pl', 'de')
}
internationalize.dependsOn generateSources, generateResources
compileJava.dependsOn internationalize
processResources.dependsOn internationalize
compileJava.setSource("$buildDir/internationalized-src")
compileJava.dependsOn internationalize
processResources.from("$buildDir/internationalized-resources")
processResources.dependsOn internationalize
task makeJar(type: Jar) {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': version
}
baseName = project.name
with jar
}
task pack(dependsOn: ['clean', 'makeJar'])
makeJar.mustRunAfter clean
def sourceJar = "build/libs/${project.name}-${project.version}.jar"
def dstJar = runningServerPluginsDir == null ? null : "${runningServerPluginsDir}/${project.name}.jar"
task update {
doLast {
if (dstJar == null) {
println "Error updating server jar. System environment variable DEV_SERVER was not specified."
return
}
println "moving $sourceJar => $dstJar"
OperatingSystem os = OperatingSystem.current()
if (os.isWindows()) {
exec {
commandLine "wsl", '--', "mv", "$sourceJar", "$dstJar"
}
} else
if (os.isLinux()) {
exec {
commandLine 'mv', sourceJar, dstJar
}
} else {
println 'This OS does not support real-time plugin updating.'
return
}
println 'Updated plugin on running server. Reload it now to see the changes.'
}
}
update.dependsOn pack
repositories {
mavenCentral()
maven { url 'https://raw.githubusercontent.com/divisionind/maven/repo' }
maven { url 'https://jitpack.io' }
}
dependencies {
compileOnly group: 'org.bukkit', name: 'craftbukkit', version: mcVersion
compileOnly group: 'com.github.TechFortress', name: 'GriefPrevention', version: '16.13.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}