forked from github/dataease
perf(X-Pack): 数据源插件驱动相关
This commit is contained in:
parent
cd8b24ba42
commit
4c8dc204b3
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
|||||||
Subproject commit db1c81ee6199d7e7920eaa41dd3e8418cd17b5db
|
Subproject commit 1ae6324b4f22f14846ad2990bdaea0915be83c3e
|
@ -5,17 +5,58 @@ import io.dataease.extensions.datasource.factory.ProviderFactory;
|
|||||||
import io.dataease.extensions.datasource.provider.Provider;
|
import io.dataease.extensions.datasource.provider.Provider;
|
||||||
import io.dataease.extensions.datasource.vo.XpackPluginsDatasourceVO;
|
import io.dataease.extensions.datasource.vo.XpackPluginsDatasourceVO;
|
||||||
import io.dataease.license.utils.JsonUtil;
|
import io.dataease.license.utils.JsonUtil;
|
||||||
|
import io.dataease.license.utils.LogUtil;
|
||||||
import io.dataease.plugins.template.DataEasePlugin;
|
import io.dataease.plugins.template.DataEasePlugin;
|
||||||
import io.dataease.plugins.vo.DataEasePluginVO;
|
import io.dataease.plugins.vo.DataEasePluginVO;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author Junjun
|
* @Author Junjun
|
||||||
*/
|
*/
|
||||||
public abstract class DataEaseDatasourcePlugin extends Provider implements DataEasePlugin {
|
public abstract class DataEaseDatasourcePlugin extends Provider implements DataEasePlugin {
|
||||||
|
private final String FILE_PATH = "/opt/dataease2.0/drivers";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadPlugin() {
|
public void loadPlugin() {
|
||||||
XpackPluginsDatasourceVO datasourceConfig = getConfig();
|
XpackPluginsDatasourceVO datasourceConfig = getConfig();
|
||||||
ProviderFactory.loadPlugin(datasourceConfig.getType(), this);
|
ProviderFactory.loadPlugin(datasourceConfig.getType(), this);
|
||||||
|
try {
|
||||||
|
loadDriver();
|
||||||
|
} catch (Exception e) {
|
||||||
|
DEException.throwException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDriver() throws Exception {
|
||||||
|
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||||
|
URL[] urls = ((URLClassLoader) classLoader).getURLs();
|
||||||
|
String jarPath = urls[0].getPath();
|
||||||
|
JarFile jarFile = new JarFile(jarPath);
|
||||||
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
JarEntry entry = (JarEntry) entries.nextElement();
|
||||||
|
String name = entry.getName();
|
||||||
|
if (StringUtils.endsWith(name, ".jar")) {
|
||||||
|
InputStream inputStream = jarFile.getInputStream(entry);
|
||||||
|
File file = new File(FILE_PATH, name.substring(name.indexOf("/") + 1));
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = inputStream.read(bytes)) >= 0) {
|
||||||
|
outputStream.write(bytes, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public XpackPluginsDatasourceVO getConfig() {
|
public XpackPluginsDatasourceVO getConfig() {
|
||||||
@ -30,4 +71,25 @@ public abstract class DataEaseDatasourcePlugin extends Provider implements DataE
|
|||||||
vo.setIcon(pluginInfo.getIcon());
|
vo.setIcon(pluginInfo.getIcon());
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*@Override
|
||||||
|
public void unloadPlugin() {
|
||||||
|
try {
|
||||||
|
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||||
|
URL[] urls = ((URLClassLoader) classLoader).getURLs();
|
||||||
|
String jarPath = urls[0].getPath();
|
||||||
|
JarFile jarFile = new JarFile(jarPath);
|
||||||
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
JarEntry entry = (JarEntry) entries.nextElement();
|
||||||
|
String name = entry.getName();
|
||||||
|
if (StringUtils.endsWith(name, ".jar")) {
|
||||||
|
File file = new File(FILE_PATH, name.substring(name.indexOf("/") + 1));
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
DEException.throwException(e);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user