121 lines
3.8 KiB
Groovy
121 lines
3.8 KiB
Groovy
import org.apache.tools.ant.filters.ReplaceTokens
|
|
|
|
import java.security.MessageDigest
|
|
import java.util.jar.JarFile
|
|
import java.util.jar.Pack200
|
|
import java.util.zip.GZIPOutputStream
|
|
|
|
if (!hasProperty('mainClass')) {
|
|
ext.mainClass = 'org.jackhuang.hmcl.Main'
|
|
}
|
|
|
|
def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
|
|
if (buildnumber == null)
|
|
buildnumber = System.getenv("BUILD_NUMBER")
|
|
if (buildnumber == null)
|
|
buildnumber = "SNAPSHOT"
|
|
|
|
def versionroot = System.getenv("VERSION_ROOT")
|
|
if (versionroot == null)
|
|
versionroot = "3.1"
|
|
|
|
String mavenVersion = versionroot + '.' + buildnumber
|
|
version = mavenVersion
|
|
|
|
dependencies {
|
|
compile project(":HMCLCore")
|
|
compile rootProject.files("lib/JFoenix.jar")
|
|
}
|
|
|
|
task generateSources(type: Sync) {
|
|
from 'src/main/java'
|
|
into "$buildDir/generated-src"
|
|
filter(ReplaceTokens, tokens: [
|
|
'HELLO_MINECRAFT_LAUNCHER_VERSION_FOR_GRADLE_REPLACING': mavenVersion
|
|
])
|
|
}
|
|
|
|
compileJava.setSource "$buildDir/generated-src"
|
|
compileJava.dependsOn generateSources
|
|
|
|
configurations {
|
|
coreCompile.extendsFrom compile
|
|
coreRuntime.extendsFrom runtime
|
|
}
|
|
|
|
jar {
|
|
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
|
|
|
|
manifest {
|
|
attributes 'Created-By' : 'Copyright(c) 2013-2018 huangyuhui.',
|
|
'Main-Class' : mainClass,
|
|
'Multi-Release': "true"
|
|
}
|
|
|
|
doLast {
|
|
def messageDigest = MessageDigest.getInstance("SHA1")
|
|
archivePath.eachByte 1024 * 1024, { byte[] buf, int bytesRead ->
|
|
messageDigest.update(buf, 0, bytesRead)
|
|
}
|
|
def sha1Hex = new BigInteger(1, messageDigest.digest()).toString(16).padLeft(40, '0')
|
|
def fileEx = new File(project.buildDir, "libs/" + archivePath.getName() + ".sha1")
|
|
if (!fileEx.exists()) fileEx.createNewFile()
|
|
fileEx.append sha1Hex
|
|
}
|
|
}
|
|
|
|
processResources {
|
|
from(sourceSets.main.resources.srcDirs) {
|
|
exclude 'icon.icns'
|
|
}
|
|
}
|
|
|
|
task makePackGZ(dependsOn: jar) doLast {
|
|
ext {
|
|
jar.classifier = ''
|
|
makeExecutableinjar = jar.archivePath
|
|
jar.classifier = ''
|
|
makeExecutableoutjar = jar.archivePath
|
|
jar.classifier = ''
|
|
}
|
|
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".pack.gz")
|
|
def os = new GZIPOutputStream(new FileOutputStream(loc))
|
|
Pack200.newPacker().pack new JarFile(makeExecutableinjar), os
|
|
os.close()
|
|
|
|
def messageDigest = MessageDigest.getInstance("SHA1")
|
|
loc.eachByte 1024 * 1024, { byte[] buf, int bytesRead ->
|
|
messageDigest.update(buf, 0, bytesRead)
|
|
}
|
|
def sha1Hex = new BigInteger(1, messageDigest.digest()).toString(16).padLeft(40, '0')
|
|
def fileEx = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".pack.gz.sha1")
|
|
if (!fileEx.exists()) fileEx.createNewFile()
|
|
fileEx.append sha1Hex
|
|
}
|
|
|
|
task makeExecutable(dependsOn: jar) doLast {
|
|
ext {
|
|
jar.classifier = ''
|
|
makeExecutableinjar = jar.archivePath
|
|
jar.classifier = ''
|
|
makeExecutableoutjar = jar.archivePath
|
|
jar.classifier = ''
|
|
}
|
|
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length() - 4) + ".exe")
|
|
def fos = new FileOutputStream(loc)
|
|
def is = new FileInputStream(new File(project.buildDir, '../HMCLauncher.exe'))
|
|
int read
|
|
def bytes = new byte[8192]
|
|
while((read = is.read(bytes)) != -1)
|
|
fos.write(bytes, 0, read)
|
|
is.close()
|
|
is = new FileInputStream(makeExecutableoutjar)
|
|
while((read = is.read(bytes)) != -1)
|
|
fos.write(bytes, 0, read)
|
|
is.close()
|
|
fos.close()
|
|
|
|
}
|
|
|
|
build.dependsOn makePackGZ
|
|
build.dependsOn makeExecutable |