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

io.imqa.injector.AndroidBuildConfig Maven / Gradle / Ivy

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

import java.io.File;
import java.lang.reflect.Field;

import io.imqa.injector.util.BuildOption;
import io.imqa.injector.util.Logger;
import io.imqa.injector.util.PathBuilder;

public class AndroidBuildConfig {

	private String packageName = "";
	private String buildLocation = "";
	private String projectName = "";
	private String buildType = "";
	private Flavor flavor;
	private String[] packageLocationArr;

	public AndroidBuildConfig(String projectName, String buildType, Flavor flavor, String buildLocation, String[] packageLocationArr) {
		this.buildLocation = buildLocation;
		this.projectName = projectName;
		this.buildType = buildType;
		this.flavor = flavor;
		this.packageLocationArr = packageLocationArr;

		init();
	}

	private void init() {
		if (packageLocationArr != null && packageLocationArr.length > 0) {
			String configLocation = buildLocation;

			for (String packageLocation : packageLocationArr) {
				if (!new File(configLocation + "/" + packageLocation).isDirectory()) {
					break;
				}
				configLocation = (configLocation + "/" + packageLocation);
				packageName += packageLocation + "/";
			}
		} else {
            String buildConfigLocation = "/build/generated/source/buildConfig/";

			buildLocation = PathBuilder.getBuilder("./"+projectName)
					.addPath(buildConfigLocation)
					.addPath(flavor.flavorName)
					.addPath(buildType)
					.toString();

			Logger.d("BuildConfig location", buildLocation);
			this.packageName = findBuildConfig(new File(buildLocation));
			if (this.packageName.length() > 0)
			this.packageName = this.packageName.substring(0, this.packageName.indexOf(".BuildConfig.java"));
		}
	}

	private String findBuildConfig(File target) {
		String packageName = "";
		try {
			for (File item : target.listFiles()) {
				packageName += item.getName();
				if (item.isDirectory())
					return packageName += "." + findBuildConfig(item);
			}
		} catch (NullPointerException ne) {
			Logger.e("BuildConfig location", "File not exist");
		}
		return packageName;
	}

	public String getPackageName() {
		return this.packageName;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy