Commit 84d69d03 authored by 孙长纪's avatar 孙长纪

修改module的根路径获取

parent ddb69831
......@@ -18,7 +18,7 @@ apply plugin: "idea"
apply plugin: "eclipse"
group = "cn.com.duiba"
version = "0.0.1"
version = "0.0.2"
sourceCompatibility = 1.8
targetCompatibility = 1.8
......
......@@ -5,35 +5,29 @@ import cn.com.duiba.mysql.generator.exceptions.DuibaGeneratorException;
import org.apache.commons.lang.StringUtils;
import java.io.File;
import java.net.URL;
public class PathUtils {
private PathUtils(){
//X Y
}
private PathUtils() {
//X Y
}
private static String getProjectHome(){
ClassLoader loader = PathUtils.class.getClassLoader();
URL url = loader.getResource("");
String file = url.getFile();
File testPath = new File(file);
return testPath.getParentFile().getParent();
}
private static String getProjectHome() {
return System.getProperty("user.dir");
}
/**
* 根据包名找到包的实际路径
* @param packageName 包名,例如:cn.com.duiba.shark.gitlab.dao
* @return 包的文件路径
*/
public static String getPathByPackage(String packageName, GeneratorConfig config){
if (StringUtils.isEmpty(packageName)){
throw new DuibaGeneratorException("包名不能为空");
}
if (StringUtils.isEmpty(config.getModuleName())) {
return "src/main/java/" + StringUtils.replace(packageName,"." ,"/");
} else {
return config.getModuleName() + File.separator + "src/main/java/" + StringUtils.replace(packageName,"." ,"/");
}
}
/**
* 根据包名找到包的实际路径
*
* @param packageName 包名,例如:cn.com.duiba.shark.gitlab.dao
* @return 包的文件路径
*/
public static String getPathByPackage(String packageName, GeneratorConfig config) {
if (StringUtils.isEmpty(packageName)) {
throw new DuibaGeneratorException("包名不能为空");
}
if (StringUtils.isEmpty(config.getModuleName())) {
return "src/main/java/" + StringUtils.replace(packageName, ".", "/");
}
return getProjectHome()+File.separator+config.getModuleName() + File.separator + "src/main/java/" + StringUtils.replace(packageName, ".", "/");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment