TechReborn/build.gradle

417 lines
11 KiB
Groovy
Raw Normal View History

2015-04-10 00:17:30 +02:00
buildscript {
2017-04-14 21:35:09 +02:00
repositories {
mavenCentral()
2018-09-02 14:57:41 +02:00
jcenter()
2017-02-13 11:34:36 +01:00
maven {
2017-04-14 21:35:09 +02:00
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
2017-04-14 21:35:09 +02:00
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
name = "CB Repo"
url = "http://chickenbones.net/maven"
}
2017-04-14 21:35:09 +02:00
}
dependencies {
2019-01-12 20:56:42 +01:00
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
2017-04-14 21:35:09 +02:00
classpath "gradle.plugin.net.minecrell:licenser:0.2.1"
2018-09-02 14:57:41 +02:00
classpath 'de.undercouch:gradle-download-task:3.4.3'
2019-01-12 20:56:42 +01:00
//classpath 'net.covers1624:GradleStuff:1.0-SNAPSHOT'
2017-04-14 21:35:09 +02:00
}
2015-04-10 00:17:30 +02:00
}
2019-01-12 20:56:42 +01:00
apply plugin: 'net.minecraftforge.gradle'
2015-04-10 00:17:30 +02:00
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: net.minecrell.gradle.licenser.Licenser
2018-09-02 14:57:41 +02:00
apply plugin: 'de.undercouch.download'
2019-01-12 20:56:42 +01:00
apply plugin: 'idea'
2019-02-20 21:12:36 +01:00
apply plugin: 'eclipse'
2019-01-12 20:56:42 +01:00
//apply plugin: 'net.covers1624.contained-deps'
2015-04-10 00:17:30 +02:00
2016-02-28 18:00:27 +01:00
sourceCompatibility = 1.8
targetCompatibility = 1.8
2015-11-24 20:37:15 +01:00
2015-04-10 10:43:45 +02:00
repositories {
2017-04-14 21:35:09 +02:00
maven {
name = "Modmuss50"
url = "http://maven.modmuss50.me/"
}
maven {
// JEI
name "JEI"
2017-04-14 21:35:09 +02:00
url "http://dvs1.progwml6.com/files/maven"
}
}
2018-09-16 22:52:02 +02:00
version = "3.0.0"
2015-12-30 18:23:45 +01:00
configurations {
2017-04-14 21:35:09 +02:00
shade
compile.extendsFrom shade
}
2015-12-30 18:23:45 +01:00
2015-04-10 00:17:30 +02:00
def ENV = System.getenv()
if (ENV.BUILD_NUMBER) {
2017-04-14 21:35:09 +02:00
version = version + "." + "${System.getenv().BUILD_NUMBER}"
2015-04-10 00:17:30 +02:00
}
minecraft {
2019-04-01 16:22:59 +02:00
mappings channel: 'snapshot', version: '20190401-1.13.2'
2019-01-12 20:56:42 +01:00
runs {
2019-02-20 21:27:03 +01:00
client {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
techreborn {
source sourceSets.main
}
2019-02-24 00:51:37 +01:00
if (findProject(':reborncore') != null) {
reborncore {
source project(":reborncore").sourceSets.main
}
}
2019-02-20 21:27:03 +01:00
}
2019-01-12 20:56:42 +01:00
}
2019-02-20 21:27:03 +01:00
server {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
techreborn {
source sourceSets.main
}
}
2019-01-12 20:56:42 +01:00
}
}
2015-04-10 00:17:30 +02:00
}
license {
2017-04-14 21:35:09 +02:00
header file('HEADER')
include '**/*.java'
ignoreFailures = true //Stops the build from failing if a file does not have a license header
}
2015-04-10 00:17:30 +02:00
group = 'TechReborn'
dependencies {
minecraft 'net.minecraftforge:forge:1.13.2-25.0.191'
2019-02-22 16:02:41 +01:00
if (findProject(':reborncore') != null) {
compile project(":reborncore")
} else {
compile 'RebornCore:RebornCore-1.13.2:+:dev'
}
2015-04-10 00:17:30 +02:00
}
2019-01-12 20:56:42 +01:00
processResources{
inputs.property 'version', project.version
2019-02-20 21:27:03 +01:00
inputs.property 'mcversion', '1.13.2'
2017-04-14 21:35:09 +02:00
2019-01-12 20:56:42 +01:00
from(sourceSets.main.resources.srcDirs) {
include 'META_INF/mods.toml'
2019-02-20 21:27:03 +01:00
expand 'version':project.version, 'mcversion': '1.13.2'
2019-01-12 20:56:42 +01:00
}
2017-04-14 21:35:09 +02:00
2019-01-12 20:56:42 +01:00
from(sourceSets.main.resources.srcDirs) {
exclude 'META_INF/mods.toml'
}
2017-06-20 19:54:45 +02:00
2019-01-12 20:56:42 +01:00
rename '(.+_at.cfg)', 'META-INF/$1'
}
2015-11-26 21:43:56 +01:00
2019-01-12 20:56:42 +01:00
// task deobfJar(type: Jar) {
// from sourceSets.main.output
// exclude "**/*.psd"
// classifier = 'dev'
// manifest {
// attributes 'FMLAT': 'techreborn_at.cfg'
// }
// }
2016-04-16 10:02:33 +02:00
2015-04-10 00:17:30 +02:00
2019-01-12 20:56:42 +01:00
// containedDeps {
// configuration = "shade"
// tasks = "jar"
// }
2015-04-10 00:17:30 +02:00
jar {
2017-04-14 21:35:09 +02:00
exclude "**/*.psd"
classifier = 'universal'
2019-01-12 20:56:42 +01:00
// manifest {
// attributes 'FMLAT': 'techreborn_at.cfg'
// }
from { crowdin.getDidWork() ? fileTree('build/translations').matching{exclude "**/en_US.lang"} : null}
dependsOn 'renameCrowdin'
2015-04-10 00:17:30 +02:00
}
2015-11-22 17:24:50 +01:00
//Triggers crowdin to export the latest translations
task crowdinExport() {
onlyIf {
2018-08-31 17:00:31 +02:00
project.hasProperty('crowdinKey')
}
doLast{
def apiKey = project.crowdinKey
def projectId = 'techreborn'
2018-08-31 17:00:31 +02:00
def response = new URL(sprintf('https://api.crowdin.com/api/project/%1$s/export?key=%2$s', [projectId, apiKey])).text
def metadata = new XmlParser().parseText(response)
project.logger.lifecycle("crowdin export status: " + metadata.@status)
}
}
2018-09-02 14:57:41 +02:00
task crowdin(type: Download, dependsOn: 'crowdinExport'){
src 'https://crowdin.com/backend/download/project/techreborn.zip'
dest file("build/translations.zip")
overwrite true
}
task cleanCrowdin(type: Delete){
delete 'build/translations'
}
//Renames the translation files to be all lower case
2018-09-02 14:57:41 +02:00
task renameCrowdin(type: Copy, dependsOn: ['crowdin', 'cleanCrowdin']){
mustRunAfter 'crowdin'
2018-09-02 14:57:41 +02:00
from zipTree(file("build/translations.zip"))
into file('build/translations')
rename {
String filename -> return filename.toLowerCase()
}
}
//import techreborn.build.GenerateResourcesTask
//task genResources(type: GenerateResourcesTask){
// outputDir = file("src/main/resources")
//}
2019-03-01 22:24:26 +01:00
publishing {
publications {
maven(MavenPublication) {
groupId 'TechReborn'
artifactId project.archivesBaseName
version project.version
2016-05-26 18:31:02 +02:00
from components.java
}
}
repositories {
maven {
url "http://mavenupload.modmuss50.me/"
2018-02-19 16:01:37 +01:00
if (project.hasProperty('mavenPass')) {
credentials {
username 'buildslave'
password project.getProperty('mavenPass')
}
2017-04-14 21:35:09 +02:00
}
}
}
}
2016-05-06 23:13:24 +02:00
2019-01-12 20:56:42 +01:00
// task signJar(type: SignJar, dependsOn: reobfJar) {
// onlyIf {
// project.hasProperty('keyStore')
// }
2017-04-14 21:35:09 +02:00
2019-01-12 20:56:42 +01:00
// if (project.hasProperty('keyStore')) {
// keyStore = project.keyStore
// alias = project.keyStoreAlias
// storePass = project.keyStorePass
// keyPass = project.keyStoreKeyPass
// inputFile = jar.archivePath
// outputFile = jar.archivePath
// }
2017-04-14 21:35:09 +02:00
2019-01-12 20:56:42 +01:00
// }
2017-04-13 11:11:10 +02:00
2019-01-12 20:56:42 +01:00
// build.dependsOn signJar
2017-04-13 11:11:10 +02:00
2019-01-12 20:56:42 +01:00
// apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/ideconfig.gradle'
2016-11-26 20:05:10 +01:00
2018-04-02 11:42:02 +02:00
import com.google.gson.JsonArray
2017-04-14 21:35:09 +02:00
import groovy.util.XmlSlurper
import org.apache.commons.io.FileUtils
2016-11-26 20:05:10 +01:00
2017-04-11 00:39:09 +02:00
task curseTools {
2017-04-11 01:21:30 +02:00
doLast {
2017-04-14 21:35:09 +02:00
def cacheFiles = new File(".gradle/curseTools")
if (!cacheFiles.exists()) {
cacheFiles.mkdirs()
}
2016-11-26 20:05:10 +01:00
2017-04-14 21:35:09 +02:00
def mavenMetadata = new File(cacheFiles, "maven-metadata.xml")
2016-11-26 20:05:10 +01:00
2017-04-14 21:35:09 +02:00
logger.lifecycle(":downloading curseTools metadata")
FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/CurseTools/CurseTools/maven-metadata.xml"), mavenMetadata)
2016-11-26 20:05:10 +01:00
2017-04-14 21:35:09 +02:00
def metadata = new XmlSlurper().parseText(FileUtils.readFileToString(mavenMetadata))
def curseToolsVersion = metadata.versioning.release
2016-11-26 20:05:10 +01:00
2017-04-14 21:35:09 +02:00
def curseTools = new File(cacheFiles, "${curseToolsVersion}.jar")
2016-11-26 20:05:10 +01:00
2017-04-14 21:35:09 +02:00
logger.lifecycle(":downloading CurseTools")
FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/CurseTools/CurseTools/${curseToolsVersion}/CurseTools-${curseToolsVersion}.jar"), curseTools)
2016-11-26 20:05:10 +01:00
2017-04-14 21:35:09 +02:00
logger.lifecycle(":launching CurseTools")
ant.java(jar: curseTools.getAbsolutePath(), fork: true, spawn: false) {
arg(value: jar.archivePath.getAbsolutePath())
arg(value: deobfJar.archivePath.getAbsolutePath())
arg(value: apiJar.archivePath.getAbsolutePath())
}
2017-04-11 01:21:30 +02:00
}
2017-01-15 16:14:05 +01:00
}
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import org.apache.commons.io.IOUtils
import java.util.zip.ZipFile
//Reads the new fml_cache_annotation file built into the jar file, to find all crafttweaker methods, and saves the data to a file
task mtDocGen {
doLast{
def inputFile = new File(jar.archivePath.getAbsolutePath())
println("Reading " + inputFile.getName() + " for crafttweaker documentation")
def jarFile = new ZipFile(inputFile)
def annotation_cache = jarFile.getEntry("META-INF/fml_cache_annotation.json")
def cache_json = IOUtils.toString(jarFile.getInputStream(annotation_cache), "UTF-8")
def jsonObject = new GsonBuilder().create().fromJson(cache_json, JsonObject.class)
def builder = new StringBuilder()
for(entry in jsonObject.entrySet()){
def clzz = entry.value.asJsonObject
if(!clzz.has("annotations")){
continue
}
def annoations = clzz.get("annotations").asJsonArray
for(annotation in annoations.toList()){
if(annotation.asJsonObject.get("type").asString.equals("METHOD") && annotation.asJsonObject.get("name").asString.equals("Lstanhebben/zenscript/annotations/ZenMethod;")){
def method = sanitsiseMethodName(annotation.asJsonObject.get("target").asString)
2018-04-02 11:42:02 +02:00
if(hasZenDoc(annotation, annoations)){
method = getZenDoc(annotation, annoations)
}
def zen_name = getZenMetName(clzz)
builder.append(zen_name + "." + method)
builder.append("\n")
}
}
}
def outputFile = new File(jar.archivePath.getAbsolutePath().replace(".jar", "-crafttweaker.txt"))
outputFile.write builder.toString()
println("Crafttweaker documentation saved to " + outputFile.name)
}
}
2018-04-02 11:42:02 +02:00
boolean hasZenDoc(JsonObject currentAnnotation, JsonArray annoations){
for(annotation in annoations.toList()){
if(annotation.asJsonObject.get("target").asString.equals(currentAnnotation.get("target").asString) && annotation.asJsonObject.get("name").asString.equals("Ltechreborn/compat/crafttweaker/ZenDocumentation;")){
return true
}
}
return false
}
String getZenDoc(JsonObject currentAnnotation, JsonArray annoations){
for(annotation in annoations.toList()){
if(annotation.asJsonObject.get("target").asString.equals(currentAnnotation.get("target").asString) && annotation.asJsonObject.get("name").asString.equals("Ltechreborn/compat/crafttweaker/ZenDocumentation;")){
def methodName = annotation.asJsonObject.get("target").asString.split("\\(")[0]
def methodParams = annotation.asJsonObject.get("value").asJsonObject.get("value").asString
if(!methodParams.startsWith("(")){
methodParams = "(" + methodParams
}
if(!methodParams.endsWith(")")){
methodParams = methodParams + ")"
}
return methodName + methodParams
}
}
return ""
}
//Gets the zenMethod class name from the class json object
String getZenMetName(JsonObject jsonObject){
def annoations = jsonObject.get("annotations").asJsonArray
for(annotation in annoations.toList()){
if(annotation.asJsonObject.get("type").asString.equals("CLASS") && annotation.asJsonObject.get("name").asString.equals("Lstanhebben/zenscript/annotations/ZenClass;")){
return annotation.asJsonObject.get("value").asJsonObject.get("value").asString
}
}
}
String sanitsiseMethodName(String methodSig){
def builder = new StringBuilder()
def name = methodSig.split("\\(")[0]
builder.append(name)
builder.append("(")
def methodArgs = methodSig.split("\\(")[1].split("\\)")[0].split(";")
for(arg in methodArgs){
def argSlit = arg.split("/")
def argStr = argSlit[argSlit.length -1]
//If a class is not in a package I assume its a primitive //TODO any suggestions for a better way to do this?
if(!arg.contains("/") && !arg.isEmpty()){
argStr = humanizeArg(argStr)
}
builder.append(argStr)
//Dont add the comma to the last arg
if(arg != methodArgs[methodArgs.length - 1]){
builder.append(",")
}
}
builder.append(")")
return builder.toString()
}
//Argumets that are java primitives do not use a freindly name, this method replaces them with something most people will understand
String humanizeArg(String arg){
def primitiveMap = [
Z: "Boolean",
B: "Byte",
C: "Char",
D: "Double",
F: "Float",
I: "Integer",
J: "Long",
L: "Object",
S: "Short"
]
def builder = new StringBuilder()
for(cha in arg.toCharArray()){
builder.append(primitiveMap.get(cha.toString().toUpperCase()))
builder.append(",")
}
//Removes the last ,
return builder.toString().substring(0, builder.toString().length() - 1)
}
2018-06-13 00:13:17 +02:00
task copyToLib(type: Copy) {
into "$buildDir/output/lib"
from configurations.runtime
}