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

de.dagere.kopeme.AndroidConfiguration Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package de.dagere.kopeme;
import java.io.InputStream;

import com.fasterxml.jackson.databind.JsonNode;

import de.dagere.kopeme.junit.rule.annotations.KoPeMeConstants;

/**
 * Configuration class for Android projects to read environment variables, properties, etc
 * from a config.json file in src/main/resources.
 */
public class AndroidConfiguration {
    
    //  Configuration file name for Android projects inside main/src/resources folder.
    static final String ANDROID_CONFIG = "kopeme_config.json";

    public static String read(String fieldName) {
        ClassLoader classLoader = AndroidConfiguration.class.getClassLoader();
        InputStream inputStream = classLoader.getResourceAsStream(ANDROID_CONFIG);
        String fieldValue;
        try {
            JsonNode rootNode, fieldNode;
            rootNode = KoPeMeConstants.OBJECTMAPPER.readTree(inputStream);
            fieldNode = rootNode.get(fieldName);
            fieldValue = fieldNode.asText();
        } catch (Exception e) {
            fieldValue = null;
        }
        return fieldValue;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy