/**
* 自定义环境配置
*/
public class SwitchENV {
/**
* 运行环境
*/
private Env env;
/**
* hsf环境
*/
private String hsfVersion;
/**
* 目标机器
*/
private String targetIp;
/**
* 环境名称
*/
private String envName;
public SwitchENV(String envName) {
Properties prop = new Properties();
// TODO: 本地自动化测试切换环境专用
if (envName == null) {
envName = "pre1";
}
switch (envName) {
case "online": {
InputStream in = SwitchENV.class.getClassLoader().getResourceAsStream(
"config/application-online.properties");
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
env = Env.ONLINE;
break;
}
case "pre1": {
InputStream in = SwitchENV.class.getClassLoader().getResourceAsStream(
"config/application-pre1.properties");
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
env = Env.PREPARE;
break;
}
case "pre2": {
InputStream in = SwitchENV.class.getClassLoader().getResourceAsStream(
"config/application-pre2.properties");
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
env = Env.PREPARE;
break;
}
case "pre3": {
InputStream in = SwitchENV.class.getClassLoader().getResourceAsStream(
"config/application-pre3.properties");
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
env = Env.PREPARE;
break;
}
default:
try {
throw new Exception("环境变量输入错误!");
} catch (Exception e) {
e.printStackTrace();
}
break;
}
hsfVersion = prop.getProperty("hsfVersion").trim();
targetIp= prop.getProperty("targetIp").trim();
this.envName = envName;
}
public Env getEnv() {
return env;
}
public String getHsfVersion() {
return hsfVersion;
}
public String getTargetIp() {
return targetIp;
}
public String getEnvName() {
return envName;
}
}