com.github.javaclub.toolbox.conf.ConfUtils Maven / Gradle / Ivy
/*
* @(#)ConfUtils.java 2021-8-31
*
* Copyright (c) 2021. All Rights Reserved.
*
*/
package com.github.javaclub.toolbox.conf;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ClassUtils;
import com.github.javaclub.toolbox.ToolBox.ClassPath;
import com.github.javaclub.toolbox.ToolBox.Strings;
/**
* ConfUtils
*
* @author Gerald Chen
* @version $Id: ConfUtils.java 2021-8-31 12:19:11 Exp $
*/
public class ConfUtils {
private static final Logger log = LoggerFactory.getLogger(ConfUtils.class);
public static final String CONFIG_KEY_MASTER_AKS = "dingtalk.aks.master";
public static final String CONFIG_KEY_SLAVE_AKS = "dingtalk.aks.slave";
public static final String MC_SMS_API_URL = "mc.sms.webApiUrl";
public static final String APP_APOLLO_BOOTSTRAP_NAMESPACES = "apollo.bootstrap.namespaces";
public static final String FIRE_MONITORS_CLASS = "com.github.javaclub.monitor.FireMonitors";
public static final String MONITOR_DINGTALK_CLASS = "com.github.javaclub.monitor.util.DingTalkUtils";
public static final String CONFIGCNTER_DINGTALK_CLASS = "com.github.javaclub.configcenter.client.util.DingTalkUtils";
public static final String APOLLO_CONFIG_SERVICE_CLASS = "com.ctrip.framework.apollo.ConfigService";
public static final String APOLLO_LISTENER_CLASS = "com.ctrip.framework.apollo.ConfigChangeListener";
public static final String CONFIGCENTER_SERVICE_CLASS = "com.github.javaclub.configcenter.client.ConfigCenterClient";
private ConfUtils() { }
public static String getAppJarPath() {
// 格式形如: file:/xxx/../xxx/XX.jar!/BOOT-INF/classes!/
String path = ClassUtils.getDefaultClassLoader().getResource("").getPath();
// log.info("Current Application Jar classpath: {}", path);
if(path.indexOf(".jar!") <= -1) {
log.warn("Application Jar file cann't be found!");
return "";
}
String jarPrePath = Strings.substringBefore(path, ".jar!");
if(jarPrePath.startsWith("file:")) {
jarPrePath = jarPrePath.replace("file:", "");
}
return String.valueOf(jarPrePath + ".jar");
}
public static Set getClasspathArray() {
Set set = new HashSet();
Collection collects = ClassPath.forClassLoader(ClassUtils.getDefaultClassLoader());
if (null != collects && collects.size() > 0) {
for (URL url : collects) {
set.add(ClassPath.cleanPath(url));
}
}
// IDE本地跑的时候,读取当前工程classpath
String classpath = getCurrentPath();
set.add(classpath);
return set;
}
public static String getCurrentPath() {
String projectClasspath = ClassPath.defaultClassLoader().getResource(Strings.EMPTY).getPath();
return projectClasspath;
}
public static void main(String[] args) {
String txt = "DUBBO:kkApi:sayHello";
System.out.println(txt.replaceAll(":", "_"));
}
}