Commit 5370a9b0 authored by Matyáš Latner's avatar Matyáš Latner

#17 Download and upload SNAPSHOT assets package for developing

 * gradle task for uploading SNAPSHOT assets package
 * using SNAPSHOT assets package only in devel build type and DEV versions
parent 4bc45224
......@@ -153,7 +153,7 @@ task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets]) {
if (!dir.name.equals('common')) {
task("${name}_${dir.name}", type: Zip) {
archiveName = dir.getName() + ".zip"
archiveName = dir.getName() + "_SNAPSHOT.zip"
destinationDir = rootProject.ext.assetsPackDir
from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
}.execute()
......@@ -162,26 +162,30 @@ task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets]) {
}
}
task uploadAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum', 'zipAssets']) {
task processAssets(dependsOn: [':util:checksum:runChecksum', ':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]}_${assetsChecksum[fileNameParts[0]]}.${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"
if (project.hasProperty('TABLEXIA_ASSETS_SERVER_USER') && project.hasProperty('TABLEXIA_ASSETS_SERVER_URL')) {
def data = new URL(ASSETS_DOWNLOAD_URL).getText()
rootProject.ext.assetsPackDir.eachFile() { file ->
String fileName = file.getName()
String[] fileNameParts = fileName.split("_SNAPSHOT\\.");
String packageName = "${fileNameParts[0]}_${assetsChecksum[fileNameParts[0]]}.${fileNameParts[1]}";
boolean isProductionVersion = project.hasProperty('TABLEXIA_ASSETS_UPLOAD_PRODUCTION') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD_PRODUCTION).booleanValue()
String uploadFileName = isProductionVersion ? packageName : fileName
if (!isProductionVersion || !data.contains(packageName)) {
println "AssetsUploader: UPLOADING FILE: ${uploadFileName}"
task ("${name}_${packageName}", type:Exec) {
workingDir "${rootProject.projectDir}"
commandLine './util/script/assetsUpload.sh', file, TABLEXIA_ASSETS_SERVER_USER, TABLEXIA_ASSETS_SERVER_URL, uploadFileName
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}.execute()
} else {
println "AssetsUploader: FILE: ${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
}
}
}
}
......@@ -296,7 +300,7 @@ project(":core") {
apply plugin: "java"
sourceSets.test.java.srcDirs = ["test/"]
tasks.processResources.dependsOn ':util:checksum:runChecksum'
tasks.processResources.dependsOn processAssets
dependencies {
compile project(":util:checksum")
......
......@@ -27,7 +27,8 @@ public class TablexiaSettings {
private static final String PREFERENCES_KEY = "cz.nic.tablexia.";
public static final String LOCALE_KEY = "locale";
private static final String IDE_BUILD_VERSION_NAME = "DEVEL";
private static final String IDE_BUILD_VERSION_NAME = "DEVEL";
public static final String DEV_VERSION_TYPE = "-DEV-";
private final BuildType BUILD_TYPE;
......
......@@ -43,8 +43,9 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
private static final int TABLEXIA_ASSETS_DOWNLOAD_TIMEOUT = 2500;
private static final String TABLEXIA_TRUST_KEYSTORE_NAME = "tablexiaTrustKeystore";
private static final String TABLEXIA_TRUST_KEYSTORE_PASSWORD = "tablexia";
public static final int DOWNLOAD_TRY_COUNT = 3;
private static final String SNAPSHOT_PACKAGE_NAME = "SNAPSHOT";
public static final int DOWNLOAD_TRY_COUNT = 3;
private static final Object LOCK = new Object();
......@@ -108,8 +109,20 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
FileHandle assetsPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(ZIP_FILES_STORAGE_TYPE, zipAssetsPackageName);
// check current package file and download it if it is necessary
boolean usedSnapshot = false;
prepareKeyStore();
if (!checkAndDownload(assetsPackageName)) {
if (TablexiaSettings.getInstance().getVersionName().contains(TablexiaSettings.DEV_VERSION_TYPE) || TablexiaSettings.getInstance().getBuildType() == TablexiaSettings.BuildType.DEVEL) {
Log.info(ZipAssetLoader.class, "Devel mode --> try to use SNAPSHOT assets package");
String snapshotAssetsPackageName = language + "_" + SNAPSHOT_PACKAGE_NAME;
String snapshotZipAssetsPackageName = snapshotAssetsPackageName + ZIP_FILE_EXTENSION;
if (checkAndDownload(snapshotAssetsPackageName)) {
usedSnapshot = true;
assetsPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(ZIP_FILES_STORAGE_TYPE, snapshotZipAssetsPackageName);
} else {
Log.err(getClass(), String.format("Cannot download assets package: %s", snapshotZipAssetsPackageName));
}
}
if (!usedSnapshot && !checkAndDownload(assetsPackageName)) {
error(getClass(), String.format("Cannot download assets package: %s", zipAssetsPackageName));
return null;
}
......
package cz.nic.tablexia.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
......
......@@ -39,7 +39,7 @@ task runAssetsArchivesChecksum(dependsOn: [classes, rootProject.tasks.zipAssets]
standardOutput = stdout
doLast {
(new File("${assetsPackDir.getAbsolutePath()}${fileName.split("\\.")[0]}.checksum")).write(stdout.toString().trim());
(new File("${assetsPackDir.getAbsolutePath()}/${fileName.split("\\.")[0]}.checksum")).write(stdout.toString().trim());
}
}.execute()
}
......
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