blob: 7eb4625e4938dd1613c87d7c550410fb29508bfd [file] [log] [blame] [raw]
buildscript {
dependencies {
classpath 'org.jdom:jdom2:2.0.6'
classpath 'org.ow2.asm:asm:5.1'
classpath 'org.ow2.asm:asm-commons:5.1'
classpath 'commons-io:commons-io:2.5'
classpath 'org.apache.ant:ant:1.9.7'
classpath 'org.codehaus.plexus:plexus-utils:3.0.24'
classpath 'org.vafer:jdependency:1.1'
classpath files('gradle/plugins/shadowPlugin.jar')
}
repositories {
mavenCentral()
}
}
plugins {
id 'java'
}
apply plugin: com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
tasks.withType(AbstractCompile) {
classpath += configurations.shadow
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
group 'protocolsupport'
version '4.29-dev'
sourceCompatibility = 1.8
import java.text.MessageFormat
import java.text.MessageFormat
File dlDepsDirC = new File('dllibsc')
dlDepsDirC.mkdirs()
File dlDepsDirS = new File('dllibss')
dlDepsDirS.mkdirs()
def dlDepsC = [
new Tuple(
'https://yivesmirror.com/files/spigot/spigot-1.12.2-R0.1-SNAPSHOT-b1609.jar',
'spigot-1.12.2-1.jar'
),
new Tuple(
'https://repo.glowstone.net/repository/snapshots/net/glowstone/glowstone/2018.2.0-SNAPSHOT/glowstone-2018.2.0-20180209.231901-7.jar',
'glowstone-1.12.2-1.jar'
)
]
def dlDepsS = [
]
void dlDeps(def dlDeps, File dlDepsDir) {
def dlDepsNames = new HashSet<String>()
dlDeps.each({
String dlDepUrl = it[0]
File dlDepFile = new File(dlDepsDir, it[1])
dlDepsNames.add(dlDepFile.getName())
if (!dlDepFile.exists()) {
logger.lifecycle(MessageFormat.format("Downloading {0} from {1}", dlDepFile.getName(), dlDepUrl))
ant.get(src: dlDepUrl, dest: dlDepFile)
} else {
logger.lifecycle(MessageFormat.format("Skipping download of {0} because it already exists", dlDepFile.getName()))
}
})
dlDepsDir.listFiles().findAll({ !dlDepsNames.contains(it.getName()) }).each({
logger.lifecycle(MessageFormat.format("Deleting old dllib {0}", it.getName()))
it.delete()
})
}
task updateLibs(type: DefaultTask) {doLast{
dlDeps(dlDepsC, dlDepsDirC)
dlDeps(dlDepsS, dlDepsDirS)
}}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['resources']
}
}
test {
java {
srcDirs = ['tests']
}
}
}
repositories {
mavenCentral()
}
dependencies {
shadow files('buildprocessor/BuildProcessor.jar')
shadow fileTree(dir: dlDepsDirC, include: '*.jar')
compile fileTree(dir: dlDepsDirS, include: '*.jar')
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.1.1'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
File genDir = new File('gen')
genDir.deleteDir()
genDir.mkdirs()
task generateLocaleList(type: DefaultTask) {doLast{
File langsListFile = new File(genDir, "resources/i18n/languages")
langsListFile.getParentFile().mkdirs()
langsListFile.createNewFile()
new PrintWriter(langsListFile).withCloseable({ writer ->
new File(sourceSets.main.resources.srcDirs.iterator().next(), "resources/i18n").list()
.each({
String[] split = it.split("[.]");
if (split.length == 2 && split[1].equals("lang")) {
writer.println(split[0])
}
})
})
}}
task generateInfo(type: DefaultTask) {doLast{
Properties properties = new Properties()
properties.setProperty("buildtime", new Date().format("yyyy.MM.dd 'at' HH:mm:ss z"))
properties.setProperty("buildhost", System.getProperty("protocolsupport.buildhost", "unknown"))
properties.setProperty("buildnumber", System.getProperty("protocolsupport.buildnumber", "unknown"))
File buildInfoFile = new File(genDir, "resources/buildinfo")
buildInfoFile.getParentFile().mkdirs()
buildInfoFile.createNewFile()
new FileOutputStream(buildInfoFile).withCloseable({ properties.store(it, "Build info") })
}}
shadowJar {
doFirst {
new File(destinationDir, archiveName).delete()
}
from sourceSets.main.java.srcDirs
from 'LICENSE'
from genDir
minimizeJar = true
destinationDir = file('target')
archiveName = 'ProtocolSupport.jar'
exclude 'META-INF/**'
relocate 'org.apache', 'protocolsupport.libs.org.apache'
relocate 'it.unimi.dsi.fastutil', 'protocolsupport.libs.it.unimi.dsi.fastutil'
relocate 'com.google.gson', 'protocolsupport.libs.com.google.gson'
}
compileJava.dependsOn(clean)
compileJava.dependsOn(updateLibs)
compileJava.finalizedBy(test)
jar.enabled = false
jar.finalizedBy(shadowJar)
shadowJar.dependsOn(generateInfo)
shadowJar.dependsOn(generateLocaleList)