Commit e84267ee authored by Matyáš Latner's avatar Matyáš Latner

#17 Gradle task for automatic upload of assets packages to storage server

parent 40763d2d
......@@ -21,9 +21,17 @@ final assetsDirName = "assets"
final assetsSourceDirName = "src"
final assetsDestinationDirName = "dest"
final String ASSETS_DOWNLOAD_URL = "https://www.tablexia.cz/static/assets/"
System.setProperty("javax.net.ssl.trustStore", new File("${project(":android").projectDir.absolutePath}/assets/keystore/tablexiaTrustKeystore").getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "tablexia");
ext {
assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
assetsChecksum = [:]
assetsPackageChecksum = [:]
assetsPackDir = new File("${rootProject.buildDir}/${assetsDirName}/pack/")
}
allprojects {
......@@ -147,7 +155,7 @@ task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets]) {
if (!dir.name.equals('common')) {
task("${name}_${dir.name}", type: Zip) {
archiveName = dir.getName() + ".zip"
destinationDir = new File(project(":android").projectDir.absolutePath + "/${assetsDirName}")
destinationDir = rootProject.ext.assetsPackDir
from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
}.execute()
}
......@@ -155,6 +163,31 @@ task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets]) {
}
}
task uploadAssets(dependsOn: ':util:checksum:runAssetsArchivesChecksum') {
doLast {
def data = new URL(ASSETS_DOWNLOAD_URL).getText()
rootProject.ext.assetsPackDir.eachFile() { file ->
String fileName = file.getName()
String[] fileNameParts = fileName.split("\\.");
String packageName = "${fileNameParts[0]}_${assetsPackageChecksum[fileName]}.${fileNameParts[1]}";
if (!data.contains(packageName)) {
println "AssetsUploader: FILE: ${packageName} DO NOT EXISTS ON SERVER -> UPLOADING FILE"
task ("${name}_${fileName}", type:Exec) {
workingDir "${rootProject.projectDir}"
commandLine './util/script/assetsUpload.sh', file, TABLEXIA_ASSETS_SERVER_USER, TABLEXIA_ASSETS_SERVER_URL, packageName
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}.execute()
} else {
println "AssetsUploader: FILE: ${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
}
}
}
}
def getVersionNameFromGit() {
def stdout = new ByteArrayOutputStream()
exec {
......@@ -264,7 +297,6 @@ project(":core") {
apply plugin: "java"
sourceSets.test.java.srcDirs = ["test/"]
tasks.processResources.dependsOn zipAssets
dependencies {
compile project(":util:checksum")
......
......@@ -126,7 +126,7 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
private void prepareKeyStore() {
System.setProperty("javax.net.ssl.trustStore", TablexiaAbstractFileManager.getFileStoragePath(TablexiaAbstractFileManager.RootStorageType.INTERNAL, "keystore/tablexiaTrustKeystore"));
System.setProperty("javax.net.ssl.trustStorePassword","tablexia");
System.setProperty("javax.net.ssl.trustStorePassword", "tablexia");
}
public void download(final String fileName) {
......
......@@ -24,3 +24,23 @@ task runChecksum(dependsOn: [classes, rootProject.tasks.prepareSoundAssets, root
}
}
}
task runAssetsArchivesChecksum(dependsOn: [classes, rootProject.tasks.zipAssets]) {
doLast {
rootProject.ext.assetsPackDir.eachFile() { file ->
String fileName = file.getName()
task ("${name}_${fileName}", type: JavaExec) {
main = MAIN_CLASS
args = [file]
classpath sourceSets.main.output.classesDir
classpath += sourceSets.main.runtimeClasspath
def stdout = new ByteArrayOutputStream()
standardOutput = stdout
doLast {
rootProject.ext.assetsPackageChecksum[fileName] = stdout.toString().trim()
}
}.execute()
}
}
}
......@@ -15,24 +15,24 @@ public class Checksum {
System.out.println(getMd5OfDir(new File(args[0])));
}
public static String getMd5OfDir(File dir) throws NoSuchAlgorithmException, IOException {
StringBuilder checksumBuilder = new StringBuilder();
File[] files = dir.listFiles();
Arrays.sort(files,
public static String getMd5OfDir(File file) throws NoSuchAlgorithmException, IOException {
if (file.isDirectory()) {
StringBuilder checksumBuilder = new StringBuilder();
File[] files = file.listFiles();
Arrays.sort(files,
new Comparator<File>() {
public int compare(File a, File b) {
return a.getName().compareTo(b.getName());
}
});
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
for (int i = 0; i < files.length; i++) {
checksumBuilder.append(getMd5OfDir(files[i]));
} else {
checksumBuilder.append(getMd5OfFile(files[i]));
}
return getMD5OfString(checksumBuilder.toString());
} else {
return getMd5OfFile(file);
}
return getMD5OfString(checksumBuilder.toString());
}
public static String getMd5OfFile(File file) throws IOException, NoSuchAlgorithmException {
......
#!/bin/bash
scp $1 $2@$3/$4
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment