Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 195 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import java.util.regex.Pattern
import groovy.json.JsonSlurper

import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
classpath "org.apache.httpcomponents:httpmime:4.5.1"
}
}

Expand All @@ -13,11 +26,12 @@ plugins {
}

apply plugin: 'net.minecraftforge.gradle.forge'

//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.

version = "1.5.6"
group = "com.blakebr0.extendedcrafting"
archivesBaseName = "ExtendedCrafting-1.12.2"
group = "omnifactorydevs.extendedcrafting" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
version = getRewrittenVersion()
archivesBaseName = project_artifact_name

sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
Expand All @@ -27,10 +41,12 @@ compileJava {
minecraft {
version = "1.12.2-14.23.5.2847"
runDir = "run"
replace '${version}', project.version

mappings = "snapshot_20171003"
makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

replace "GRADLE:VERSION", project.version
replace "GRADLE:MODNAME", project_fancy_name
}

repositories {
Expand Down Expand Up @@ -71,15 +87,182 @@ processResources {
}
}

task copyExamples {
def scripts = new File(minecraft.runDir, "scripts")
scripts.mkdirs()
scripts.eachFile {
file -> file.delete()
/*
Fetches the last tag associated with the current branch.
*/
def getLastTag() {
return run("git describe --abbrev=0 --tags " +
(System.env["TRAVIS_TAG"] ? run("git rev-list --tags --skip=1 --max-count=1") : "")
)
}

/*
Runs a command and returns the output.
*/
def run(command) {
def process = command.execute()
def outputStream = new StringBuffer();
def errorStream = new StringBuffer();
process.waitForProcessOutput(outputStream, errorStream)

errorStream.toString().with {
if (it) {
throw new GradleException("Error executing ${command}:\n> ${it}")
}
}

return outputStream.toString().trim()
}

/*
Rewrites the version.
*/
def getRewrittenVersion () {
def lastTag = getLastTag()

if (System.env['TRAVIS_TAG']) {
return System.env['TRAVIS_TAG']
} else {
def commitNo = run "git rev-list ${lastTag}..HEAD --count"

return lastTag + "." + commitNo
}
}

task generateChangelog {
onlyIf {
System.env['TRAVIS']
}

doLast {
/*
Create a comprehensive changelog.
*/
def lastTag = getLastTag()

def changelog = (run([
"git"
, "log"
, "--date=format:%d %b %Y"
, "--pretty=%s - **%an** (%ad)"
, "${lastTag}..HEAD"
]))

if (changelog) {
changelog = "Changes since ${lastTag}:\n${("\n" + changelog).replaceAll("\n", "\n• ")}"
}

def f = new File("build/tmp/changelog.md")
f.write(changelog ?: "", "UTF-8")
}
new File("tests").eachFileRecurse {
file -> if(file.isFile()) new File(scripts, file.getName()) << file.text
}

compileJava.dependsOn generateChangelog

task deployCurseForge {
doLast {
def final CURSEFORGE_ENDPOINT = "https://minecraft.curseforge.com/"

/*
Helper function for checking environmental variables.
*/
def final checkVariables = { variables ->
for (vari in variables) {
if (!System.env[vari]) {
throw new GradleException("Environmental variable ${vari} is unset")
}
}
}

checkVariables([
'CURSEFORGE_API_TOKEN', 'CURSEFORGE_PROJECT_ID'
])

/*
Helper function for fetching JSON data.
*/
def final fetch = { url, headers = null ->
def connection = new URL(url).openConnection();
connection.setRequestProperty("X-Api-Token", System.env["CURSEFORGE_API_TOKEN"])
if (headers != null) {
for (header in headers) {
connection.setRequestProperty(headers[1], headers[2])
}
}

def code = connection.getResponseCode()
if (code == 200) {
return new JsonSlurper().parseText(connection.getInputStream().getText())
} else {
throw new GradleException("Fetch failed with code ${code} (${url})")
}
}

/*
Fetch the list of Minecraft versions from CurseForge.
*/
def targetVersion = project.minecraft.version
def version = fetch(CURSEFORGE_ENDPOINT + "api/game/versions").with {
def v = it.find { it.name == targetVersion }

if (!v) {
throw new GradleException("Version ${project.minecraft.version} not found on CurseForge")
}

return v
}

/*
Fill the papers for CurseForge.
*/
def metadata = new groovy.json.JsonBuilder().with {
def versions = [ version.id ]

/*
CurseForge is dumb, so we'll have to prepend two spaces
to each newline. This is disgusting, but it works.
*/
def log = new File("build/tmp/changelog.md")
.getText("UTF-8")
.replaceAll("\n", " \n")

def root = it {
changelog log
changelogType "markdown"

releaseType System.env['TRAVIS_TAG'] ? "release" : "beta"
gameVersions versions

// Defined in gradle.properties
displayName "${project_fancy_name} ${project.version}"
}

if (project_curseforge_dependencies) {
def data = new JsonSlurper().parseText(project_curseforge_dependencies)

root << [relations: [ projects: data ]]
}

return it.toString()
}

/*
Upload the artifact to CurseForge.
*/
new HTTPBuilder(CURSEFORGE_ENDPOINT).request(Method.POST) { req ->
requestContentType = "multipart/form-data"
headers["X-Api-Token"] = System.env["CURSEFORGE_API_TOKEN"]
uri.path = "api/projects/${System.env["CURSEFORGE_PROJECT_ID"]}/upload-file"

req.entity = new MultipartEntityBuilder().with {
addPart("file", new FileBody(
new File("${project.jar.destinationDir}/${project.jar.archiveName}")
))
addPart("metadata", new StringBody(metadata))

return it.build()
}
}
}
}

runClient.dependsOn(tasks.copyExamples)
12 changes: 11 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.jvmargs=-Xmx3G

# Deployment
project_artifact_name = ExtendedCrafting-Omnifactory-Edition
project_fancy_name = Extended Crafting: Omnifactory Edition
project_curseforge_dependencies = [\
{\
"slug": "cucumber",\
"type": "requiredDependency"\
}\
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
public class ExtendedCrafting {

public static final String MOD_ID = "extendedcrafting";
public static final String NAME = "Extended Crafting";
public static final String VERSION = "${version}";
public static final String NAME = "GRADLE:MODNAME";
public static final String VERSION = "GRADLE:VERSION";
public static final String GUI_FACTORY = "com.blakebr0.extendedcrafting.config.GuiFactory";
public static final String DEPENDENCIES = "required-after:cucumber@[1.1.2,)";

Expand Down