mirror of
https://github.com/alibaba/DataX.git
synced 2025-05-02 15:12:22 +08:00
不依赖于user.dir环境变量,所以插件加载工厂便没有意义了
This commit is contained in:
parent
7ee35629a0
commit
03cfbfa2f7
@ -1,9 +0,0 @@
|
|||||||
package com.alibaba.datax.core.util.container;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fuyouj
|
|
||||||
* ClassLoader 抽象类的具体实现类,用于在运行时反射加载插件
|
|
||||||
*/
|
|
||||||
public class PluginClassLoader extends ClassLoader{
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package com.alibaba.datax.core.util.container;
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.datax.common.constant.PluginType;
|
|
||||||
import com.alibaba.datax.common.exception.DataXException;
|
|
||||||
import com.alibaba.datax.common.util.Configuration;
|
|
||||||
import com.alibaba.datax.core.util.FrameworkErrorCode;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginLoader简单工厂
|
|
||||||
* @author fuyouj
|
|
||||||
*/
|
|
||||||
public class PluginLoaderFactory {
|
|
||||||
|
|
||||||
private static final String JAR_LOADER = "jarLoader";
|
|
||||||
private static final String PLUGIN_LOADER = "pluginLoader";
|
|
||||||
|
|
||||||
public static ClassLoader create(Configuration pluginDescConf, PluginType pluginType, String pluginName) {
|
|
||||||
|
|
||||||
check(pluginDescConf, pluginType, pluginName);
|
|
||||||
|
|
||||||
String loadType = pluginDescConf.getString("loadType");
|
|
||||||
|
|
||||||
if (JAR_LOADER.equalsIgnoreCase(loadType)) {
|
|
||||||
String path = pluginDescConf.getString("path");
|
|
||||||
return new JarLoader(new String[]{path});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PLUGIN_LOADER.equalsIgnoreCase(loadType)){
|
|
||||||
return new PluginClassLoader();
|
|
||||||
}
|
|
||||||
throw DataXException.asDataXException(
|
|
||||||
FrameworkErrorCode.RUNTIME_ERROR,
|
|
||||||
String.format(
|
|
||||||
"%s插件[%s]无法加载,不支持的loadType,请检查程序代码",
|
|
||||||
pluginType, pluginName));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void check(Configuration pluginDescConf, PluginType pluginType, String pluginName) {
|
|
||||||
|
|
||||||
String loadType = pluginDescConf.getString("loadType");
|
|
||||||
if (StringUtils.isBlank(loadType)){
|
|
||||||
throw DataXException.asDataXException(
|
|
||||||
FrameworkErrorCode.RUNTIME_ERROR,
|
|
||||||
String.format(
|
|
||||||
"%s插件[%s]无法加载,没有指定的loadType!",
|
|
||||||
pluginType, pluginName));
|
|
||||||
}
|
|
||||||
|
|
||||||
String pluginPath = pluginDescConf.getString("path");
|
|
||||||
if (StringUtils.isBlank(pluginPath) && JAR_LOADER.equalsIgnoreCase(loadType)) {
|
|
||||||
throw DataXException.asDataXException(
|
|
||||||
FrameworkErrorCode.RUNTIME_ERROR,
|
|
||||||
String.format(
|
|
||||||
"%s插件[%s]路径非法!",
|
|
||||||
pluginType, pluginName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.alibaba.datax.example;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@code Author} FuYouJ
|
|
||||||
* {@code Date} 2023/7/29 18:23
|
|
||||||
*/
|
|
||||||
|
|
||||||
public abstract class ExampleTestTemplate {
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void fixWorkingDirectory(){
|
|
||||||
String property = System.getProperty("user.dir");
|
|
||||||
File file = new File(property);
|
|
||||||
File parentFile = file.getParentFile();
|
|
||||||
System.setProperty("user.dir",parentFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user