Added completely new build version system

This commit is contained in:
Anuken
2018-02-08 23:41:07 -05:00
parent 36afd9f140
commit 1f4a72d459
21 changed files with 210 additions and 128 deletions

View File

@@ -4,11 +4,45 @@ sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
project.ext.mainClassName = "io.anuke.mindustry.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets");
project.ext.assetsDir = new File("../core/assets")
def PACKR_DIR = "$System.env.PACKR_DIR"
def ICON_DIR = new File("core/assets/sprites/icon.icns")
ext.writeVersion = {
def pfile = new File('core/assets/version.properties')
def props = new Properties()
props.load(new FileInputStream(pfile))
String code = getBuildVersion()
props["name"] = appName
props["version"] = versionType
props["code"] = versionNumber
props["build"] = code
props.store(pfile.newWriter(), "Autogenerated file. Do not modify.")
}
ext.getPlatform = {
if (project.hasProperty("platform")) {
def lc = platform.toLowerCase()
if (lc == "windows64") {
return "windows64"
} else if (lc == "windows32") {
return "windows32"
} else if (lc == "linux") {
return "linux64"
} else if (lc == "mac") {
return "mac"
} else {
throw new InvalidUserDataException("Invalid platform. Set platform with -Pplatform=windows/linux/mac")
}
} else {
throw new InvalidUserDataException("No platform defined. Set platform with -Pplatform=windows/linux/mac")
}
}
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
@@ -30,80 +64,50 @@ task debug(dependsOn: classes, type: JavaExec) {
}
task dist(type: Jar) {
dependsOn classes
writeVersion()
from files(sourceSets.main.output.classesDirs)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
from files(project.assetsDir)
manifest {
attributes 'Main-Class': project.mainClassName
}
}
dist.dependsOn classes
task clearOut(type: Delete){
delete "packr-out/"
}
ext.getPlatform = {
if(project.gradle.startParameter.taskNames.size() == 0 || !project.gradle.startParameter.taskNames.first().contains("packr")) return;
if(!project.hasProperty("version")){
throw new InvalidUserDataException("No version set. Set version with -Pversion=name");
doLast {
delete "packr-out/"
}
if (project.hasProperty("platform")) {
def lc = platform.toLowerCase()
if(lc.equals("windows64")) {
return "windows64";
}else if(lc.equals("windows32")){
return "windows32";
}else if(lc.equals("linux")){
return "linux64";
}else if(lc.equals("mac")){
return "mac";
}else{
throw new InvalidUserDataException("Invalid platform. Set platform with -Pplatform=windows/linux/mac");
}
}else{
throw new InvalidUserDataException("No platform defined. Set platform with -Pplatform=windows/linux/mac");
}
}
ext.getDeployVersion = {
if(project.gradle.startParameter.taskNames.size() == 0 || !project.gradle.startParameter.taskNames.first().contains("packr")) return;
if(!project.hasProperty("deployversion")){
throw new InvalidUserDataException("No version set. Set version with -Pdeployversion=name");
}
return deployversion;
}
ext.getPackage = {
return project.ext.mainClassName.substring(0, project.ext.mainClassName.indexOf("desktop") - 1)
}
//note: call desktop:dist beforehand
task packrCmd(type: Exec) {
task packrCmd() {
copy{
into PACKR_DIR
from "build/libs/desktop-release.jar"
}
doLast {
commandLine "java", "-jar", PACKR_DIR+"packr.jar",
"--verbose",
"--bundle", getPackage(),
"--platform", getPlatform(),
"--executable", appName,
"--output", "packr-out/",
"--mainclass", project.ext.mainClassName,
"--jdk", PACKR_DIR+"jdk-"+getPlatform()+".zip",
"--icon", ICON_DIR.getAbsolutePath(),
"--classpath", "--", PACKR_DIR+"config.json"
copy {
into PACKR_DIR
from "build/libs/desktop-release.jar"
}
exec {
commandLine "java", "-jar", PACKR_DIR + "packr.jar",
"--verbose",
"--bundle", getPackage(),
"--platform", getPlatform(),
"--executable", appName,
"--output", "packr-out/",
"--mainclass", project.ext.mainClassName,
"--jdk", PACKR_DIR + "jdk-" + getPlatform() + ".zip",
"--icon", ICON_DIR.getAbsolutePath(),
"--classpath", "--", PACKR_DIR + "config.json"
}
}
}
task fixMac (type: Copy){
@@ -134,26 +138,27 @@ task fixWindows32 (type: Copy){
}
}
task packrZip(type: Zip) {
dependsOn "packrCmd"
finalizedBy "clearOut"
task packrZip() {
dependsOn "packrCmd"
finalizedBy "clearOut"
if(getPlatform().equals("mac")){
dependsOn "fixMac"
}
if(project.hasProperty("platform")) {
if(getPlatform().equals("windows32")){
dependsOn "fixWindows32"
}
from "packr-out/"
archiveName appName + "-" + getPlatform() + "-" + getDeployVersion() + ".zip"
destinationDir(file("packr-export"))
doLast{
delete{
delete "null/"
if (getPlatform() == "mac") {
dependsOn "fixMac"
}
if (getPlatform() == "windows32") {
dependsOn "fixWindows32"
}
task zip (type: Zip){
from "packr-out/"
archiveName "$appName-${getPlatform()}-${getVersionString()}.zip"
destinationDir(file("packr-export"))
}
finalizedBy 'zip'
}
}
@@ -167,7 +172,7 @@ eclipse {
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ])
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)