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

修改module的根路径获取

parent ddb69831
...@@ -18,7 +18,7 @@ apply plugin: "idea" ...@@ -18,7 +18,7 @@ apply plugin: "idea"
apply plugin: "eclipse" apply plugin: "eclipse"
group = "cn.com.duiba" group = "cn.com.duiba"
version = "0.0.1" version = "0.0.2"
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
......
...@@ -5,35 +5,29 @@ import cn.com.duiba.mysql.generator.exceptions.DuibaGeneratorException; ...@@ -5,35 +5,29 @@ import cn.com.duiba.mysql.generator.exceptions.DuibaGeneratorException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import java.io.File; import java.io.File;
import java.net.URL;
public class PathUtils { public class PathUtils {
private PathUtils(){ private PathUtils() {
//X Y //X Y
} }
private static String getProjectHome(){ private static String getProjectHome() {
ClassLoader loader = PathUtils.class.getClassLoader(); return System.getProperty("user.dir");
URL url = loader.getResource(""); }
String file = url.getFile();
File testPath = new File(file);
return testPath.getParentFile().getParent();
}
/** /**
* 根据包名找到包的实际路径 * 根据包名找到包的实际路径
* @param packageName 包名,例如:cn.com.duiba.shark.gitlab.dao *
* @return 包的文件路径 * @param packageName 包名,例如:cn.com.duiba.shark.gitlab.dao
*/ * @return 包的文件路径
public static String getPathByPackage(String packageName, GeneratorConfig config){ */
if (StringUtils.isEmpty(packageName)){ public static String getPathByPackage(String packageName, GeneratorConfig config) {
throw new DuibaGeneratorException("包名不能为空"); if (StringUtils.isEmpty(packageName)) {
} throw new DuibaGeneratorException("包名不能为空");
if (StringUtils.isEmpty(config.getModuleName())) { }
return "src/main/java/" + StringUtils.replace(packageName,"." ,"/"); if (StringUtils.isEmpty(config.getModuleName())) {
} else { return "src/main/java/" + StringUtils.replace(packageName, ".", "/");
return config.getModuleName() + File.separator + "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