Skip to content

Commit c283d56

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents d19a519 + 2d4cec0 commit c283d56

6 files changed

Lines changed: 253 additions & 16 deletions

File tree

.travis.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
language: java
2+
3+
before_cache:
4+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
5+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
6+
cache:
7+
directories:
8+
- $HOME/.gradle/caches/
9+
- $HOME/.gradle/wrapper/
10+
- ./build/tmp/
11+
12+
git:
13+
depth: false
14+
15+
deploy:
16+
# Deploy release to CurseForge
17+
- provider: script
18+
edge: true
19+
skip_cleanup: true
20+
script: ./gradlew deployCurseForge
21+
on:
22+
all_branches: true
23+
condition: $TRAVIS_BRANCH =~ ^(master|[0-9]+\.[0-9]+\.[0-9]+.*?)$
24+
25+
# Deploy release to GitHub (release)
26+
- provider: releases
27+
edge: true
28+
skip_cleanup: true
29+
file_glob: true
30+
file: build/libs/**/*
31+
token: "$GITHUB_TOKEN"
32+
release_notes_file: build/tmp/changelog.md
33+
overwrite: true
34+
on:
35+
tags: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Extended Crafting [![](http://cf.way2muchnoise.eu/full_268387_downloads.svg)](https://minecraft.curseforge.com/projects/extended-crafting)
1+
# Extended Crafting: Omnifactory Edition [![](http://cf.way2muchnoise.eu/full_398267_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/extended-crafting-omnifactory-edition)
22
Adds some new ways to craft items, as well as extra crafting items and utilities.

build.gradle

Lines changed: 204 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
import java.util.regex.Pattern
2+
import groovy.json.JsonSlurper
3+
4+
import org.apache.http.entity.mime.MultipartEntityBuilder;
5+
import org.apache.http.entity.mime.content.FileBody;
6+
import org.apache.http.entity.mime.content.StringBody;
7+
import groovyx.net.http.ContentType
8+
import groovyx.net.http.HTTPBuilder
9+
import groovyx.net.http.Method
10+
111
buildscript {
212
repositories {
313
jcenter()
414
maven { url = "http://files.minecraftforge.net/maven" }
15+
maven { url "https://plugins.gradle.org/m2/" }
516
}
617
dependencies {
718
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
19+
classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
20+
classpath "org.apache.httpcomponents:httpmime:4.5.1"
821
}
922
}
1023

@@ -13,11 +26,12 @@ plugins {
1326
}
1427

1528
apply plugin: 'net.minecraftforge.gradle.forge'
29+
1630
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
1731

18-
version = "1.5.6"
19-
group = "com.blakebr0.extendedcrafting"
20-
archivesBaseName = "ExtendedCrafting-1.12.2"
32+
group = "omnifactorydevs.extendedcrafting" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
33+
version = getRewrittenVersion()
34+
archivesBaseName = project_artifact_name
2135

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

3245
mappings = "snapshot_20171003"
3346
makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
47+
48+
replace "GRADLE:VERSION", project.version
49+
replace "GRADLE:MODNAME", project_fancy_name
3450
}
3551

3652
repositories {
@@ -71,15 +87,191 @@ processResources {
7187
}
7288
}
7389

74-
task copyExamples {
75-
def scripts = new File(minecraft.runDir, "scripts")
76-
scripts.mkdirs()
77-
scripts.eachFile {
78-
file -> file.delete()
90+
/*
91+
Fetches the last tag associated with the current branch.
92+
*/
93+
def getLastTag() {
94+
return run("git describe --abbrev=0 --tags " +
95+
(System.env["TRAVIS_TAG"] ? run("git rev-list --tags --skip=1 --max-count=1") : "")
96+
)
97+
}
98+
99+
/*
100+
Runs a command and returns the output.
101+
*/
102+
def run(command) {
103+
def process = command.execute()
104+
def outputStream = new StringBuffer();
105+
def errorStream = new StringBuffer();
106+
process.waitForProcessOutput(outputStream, errorStream)
107+
108+
errorStream.toString().with {
109+
if (it) {
110+
throw new GradleException("Error executing ${command}:\n> ${it}")
111+
}
79112
}
80-
new File("tests").eachFileRecurse {
81-
file -> if(file.isFile()) new File(scripts, file.getName()) << file.text
113+
114+
return outputStream.toString().trim()
115+
}
116+
117+
/*
118+
Rewrites the version.
119+
*/
120+
def getRewrittenVersion () {
121+
def lastTag = getLastTag()
122+
123+
if (System.env['TRAVIS_TAG']) {
124+
return System.env['TRAVIS_TAG']
125+
} else {
126+
def commitNo = run "git rev-list ${lastTag}..HEAD --count"
127+
128+
return lastTag + "." + commitNo
129+
}
130+
}
131+
132+
task generateChangelog {
133+
onlyIf {
134+
System.env['TRAVIS']
135+
}
136+
137+
doLast {
138+
/*
139+
Create a comprehensive changelog.
140+
*/
141+
def lastTag = getLastTag()
142+
143+
def changelog = (run([
144+
"git"
145+
, "log"
146+
, "--date=format:%d %b %Y"
147+
, "--pretty=%s - **%an** (%ad)"
148+
, "${lastTag}..HEAD"
149+
].plus(
150+
/*
151+
Collect relevant directories only, them being:
152+
* ./src/main/java
153+
* ./src/main/resources
154+
*/
155+
sourceSets.main.java.srcDirs
156+
.plus(sourceSets.main.resources.srcDirs)
157+
.collect { [ "--", it ] }
158+
).flatten()))
159+
160+
if (changelog) {
161+
changelog = "Changes since ${lastTag}:\n${("\n" + changelog).replaceAll("\n", "\n* ")}"
162+
}
163+
164+
def f = new File("build/tmp/changelog.md")
165+
f.write(changelog ?: "", "UTF-8")
82166
}
83167
}
84168

85-
runClient.dependsOn(tasks.copyExamples)
169+
compileJava.dependsOn generateChangelog
170+
171+
task deployCurseForge {
172+
doLast {
173+
def final CURSEFORGE_ENDPOINT = "https://minecraft.curseforge.com/"
174+
175+
/*
176+
Helper function for checking environmental variables.
177+
*/
178+
def final checkVariables = { variables ->
179+
for (vari in variables) {
180+
if (!System.env[vari]) {
181+
throw new GradleException("Environmental variable ${vari} is unset")
182+
}
183+
}
184+
}
185+
186+
checkVariables([
187+
'CURSEFORGE_API_TOKEN', 'CURSEFORGE_PROJECT_ID'
188+
])
189+
190+
/*
191+
Helper function for fetching JSON data.
192+
*/
193+
def final fetch = { url, headers = null ->
194+
def connection = new URL(url).openConnection();
195+
connection.setRequestProperty("X-Api-Token", System.env["CURSEFORGE_API_TOKEN"])
196+
if (headers != null) {
197+
for (header in headers) {
198+
connection.setRequestProperty(headers[1], headers[2])
199+
}
200+
}
201+
202+
def code = connection.getResponseCode()
203+
if (code == 200) {
204+
return new JsonSlurper().parseText(connection.getInputStream().getText())
205+
} else {
206+
throw new GradleException("Fetch failed with code ${code} (${url})")
207+
}
208+
}
209+
210+
/*
211+
Fetch the list of Minecraft versions from CurseForge.
212+
*/
213+
def targetVersion = project.minecraft.version
214+
def version = fetch(CURSEFORGE_ENDPOINT + "api/game/versions").with {
215+
def v = it.find { it.name == targetVersion }
216+
217+
if (!v) {
218+
throw new GradleException("Version ${project.minecraft.version} not found on CurseForge")
219+
}
220+
221+
return v
222+
}
223+
224+
/*
225+
Fill the papers for CurseForge.
226+
*/
227+
def metadata = new groovy.json.JsonBuilder().with {
228+
def versions = [ version.id ]
229+
230+
/*
231+
CurseForge is dumb, so we'll have to prepend two spaces
232+
to each newline. This is disgusting, but it works.
233+
*/
234+
def log = new File("build/tmp/changelog.md")
235+
.getText("UTF-8")
236+
.replaceAll("\n", " \n")
237+
.replaceAll("\n\\*", "\n")
238+
239+
def root = it {
240+
changelog log
241+
changelogType "markdown"
242+
243+
releaseType System.env['TRAVIS_TAG'] ? "release" : "beta"
244+
gameVersions versions
245+
246+
// Defined in gradle.properties
247+
displayName "${project_fancy_name} ${project.version}"
248+
}
249+
250+
if (project_curseforge_dependencies) {
251+
def data = new JsonSlurper().parseText(project_curseforge_dependencies)
252+
253+
root << [relations: [ projects: data ]]
254+
}
255+
256+
return it.toString()
257+
}
258+
259+
/*
260+
Upload the artifact to CurseForge.
261+
*/
262+
new HTTPBuilder(CURSEFORGE_ENDPOINT).request(Method.POST) { req ->
263+
requestContentType = "multipart/form-data"
264+
headers["X-Api-Token"] = System.env["CURSEFORGE_API_TOKEN"]
265+
uri.path = "api/projects/${System.env["CURSEFORGE_PROJECT_ID"]}/upload-file"
266+
267+
req.entity = new MultipartEntityBuilder().with {
268+
addPart("file", new FileBody(
269+
new File("${project.jar.destinationDir}/${project.jar.archiveName}")
270+
))
271+
addPart("metadata", new StringBody(metadata))
272+
273+
return it.build()
274+
}
275+
}
276+
}
277+
}

gradle.properties

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
22
# This is required to provide enough memory for the Minecraft decompilation process.
3-
org.gradle.jvmargs=-Xmx3G
3+
org.gradle.jvmargs=-Xmx3G
4+
5+
# Deployment
6+
project_artifact_name = ExtendedCrafting-Omnifactory-Edition
7+
project_fancy_name = Extended Crafting: Omnifactory Edition
8+
project_curseforge_dependencies = [\
9+
{\
10+
"slug": "cucumber",\
11+
"type": "requiredDependency"\
12+
}\
13+
]

gradlew

100644100755
File mode changed.

src/main/java/com/blakebr0/extendedcrafting/ExtendedCrafting.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
public class ExtendedCrafting {
2020

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

0 commit comments

Comments
 (0)