All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.imqa.injector.ResourceManager.groovy Maven / Gradle / Ivy

There is a newer version: 2.25.11
Show newest version
package io.imqa.injector

import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.gradle.api.Project
import io.imqa.injector.util.Logger

public class ResourceManager {

    ResourceManager() {

    }

    IMQAOption getServiceOption(Project project) {
        IMQAOption result = null;
        if (project.buildDir.exists()) {
            File settingFile = new File(project.projectDir.getAbsolutePath() + "/" + "imqa-service.json");
            if (!settingFile.exists()) return result;
            InputStream is = settingFile.newDataInputStream()
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            String settingJson = new String(buffer, "UTF-8");

            Gson gson = new Gson();
            result = gson.fromJson(settingJson, IMQAOption.class);

            if (result != null)
                result.origin = new JsonParser().parse(settingJson).getAsJsonObject();
        }

        return result;
    }

    void setResValue(Project project, IMQAOption option) {
        project.android.buildTypes.all { buildType ->
            String imqaPreset = "imqa_"

            for (Map.Entry entry : option.origin.entrySet()) {
                if (entry.key.equals("runtime")
                    || exceptKey(entry.key)) continue;
                buildType.resValue "string", imqaPreset+entry.key, entry.value.getAsString()
            }

            JsonObject runtimeOption = option.origin.getAsJsonObject("runtime");
            for (Map.Entry entry : runtimeOption.entrySet()) {
                if (entry.value.toString().equals("")
                    || entry.value.toString().equals("null")
                    || entry.value.toString().equals("[]"))
                    continue;
                if (entry.key.equals("os_version_limit_list")
                    || entry.key.equals("app_version_limit_list")) {
                    def valueString = entry.value.toString().substring();
                    if (valueString.length() == 2) valueString = ""
                    else valueString = valueString.substring(1, valueString.length()-2);
                    buildType.resValue "string", imqaPreset+entry.key, valueString
                } else
                    buildType.resValue "string", imqaPreset+entry.key, entry.value.getAsString()
            }
        }
    }

    boolean exceptKey(String keyName) {
        return !(keyName.equals("project_key"));

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy