|
|
@ -16,8 +16,11 @@ import org.slf4j.LoggerFactory;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.net.JarURLConnection;
|
|
|
|
import java.net.JarURLConnection;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
import java.security.CodeSource;
|
|
|
|
|
|
|
|
import java.security.ProtectionDomain;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
@ -57,25 +60,32 @@ public class CommonUtil {
|
|
|
|
return IoUtil.read(is, "UTF-8");
|
|
|
|
return IoUtil.read(is, "UTF-8");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取所有sql文件,并返回一个list集合
|
|
|
|
* 获取所有sql文件,并返回一个list集合
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static List<String> getAllSql() throws IOException {
|
|
|
|
public static List<String> getAllSql() throws IOException, URISyntaxException {
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
if (isRunInJar()) {
|
|
|
|
if (isRunInJar()) {
|
|
|
|
URL url = CommonUtil.class.getClassLoader().getResource("Sql/");
|
|
|
|
// 获取当前类的ProtectionDomain
|
|
|
|
String jarPath = url.toString().substring(0, url.toString().indexOf("!/") + 2);
|
|
|
|
ProtectionDomain domain = CommonUtil.class.getProtectionDomain();
|
|
|
|
URL jarURL = new URL(jarPath);
|
|
|
|
// 获取CodeSource
|
|
|
|
JarURLConnection jarCon = (JarURLConnection) jarURL.openConnection();
|
|
|
|
CodeSource source = domain.getCodeSource();
|
|
|
|
JarFile jarFile = jarCon.getJarFile();
|
|
|
|
// 获取Jar文件的URL
|
|
|
|
Enumeration<JarEntry> jarEntrys = jarFile.entries();
|
|
|
|
URL jarUrl = source.getLocation();
|
|
|
|
while (jarEntrys.hasMoreElements()) {
|
|
|
|
// 获取Jar文件的路径
|
|
|
|
JarEntry entry = jarEntrys.nextElement();
|
|
|
|
String jarPath = jarUrl.toURI().getSchemeSpecificPart();
|
|
|
|
String name = entry.getName();
|
|
|
|
// 打开Jar文件
|
|
|
|
if (name.startsWith("Sql/") && !entry.isDirectory()) {
|
|
|
|
JarFile jarFile = new JarFile(jarPath);
|
|
|
|
list.add(name);
|
|
|
|
// 遍历Jar中的所有条目
|
|
|
|
|
|
|
|
Enumeration<JarEntry> entries = jarFile.entries();
|
|
|
|
|
|
|
|
while (entries.hasMoreElements()) {
|
|
|
|
|
|
|
|
JarEntry entry = entries.nextElement();
|
|
|
|
|
|
|
|
// 检查条目是否是SQL文件
|
|
|
|
|
|
|
|
if (entry.getName().startsWith("Sql/") && entry.getName().toLowerCase().endsWith(".sql")) {
|
|
|
|
|
|
|
|
list.add(entry.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {//如果运行在文件系统中,直接加载sql文件
|
|
|
|
} else {//如果运行在文件系统中,直接加载sql文件
|
|
|
|