修改: 多模块路径获取错误修正

master
曹世达 6 months ago
parent 8621e4f244
commit bdfc250061

@ -10,12 +10,29 @@ public class PathUtils {
private static final String JAVA_FILE_SUFFIX = ".java";
public static String getProjectPath() {
return CONFIG.getString(CfgConsts.PROJECT_PATH_BASE);
public static String getProjectBasePath() {
return CONFIG.getString(CfgConsts.PROJECT_PATH_BASE).replaceAll("\\\\", "/");
}
public static String getJavaPath() {
String basePath = getProjectPath();
public static String getProjectName() {
return StrUtils.last(getProjectBasePath(), "/");
}
public static String getProjectPath(String moduleName) {
String projectBasePath = getProjectBasePath();
if (!isMultiModule()) {
return projectBasePath;
} else {
return projectBasePath + "/" + getProjectName() + "-" + moduleName;
}
}
public static boolean isMultiModule() {
return CONFIG.getBoolean(CfgConsts.MODULE_MULTIPLE);
}
public static String getJavaPath(String moduleName) {
String basePath = getProjectPath(moduleName);
String configPath = CONFIG.getString(CfgConsts.PROJECT_PATH_JAVA);
String defaultPath = CfgConsts.DEFAULT_PROJECT_PATH_JAVA;
String path = StrUtils.defaultIfBlank(configPath, defaultPath);
@ -27,10 +44,10 @@ public class PathUtils {
}
public static String getPackageBasePath(String moduleName) {
String basePath = getJavaPath();
String javaPath = getJavaPath(moduleName);
String packageName = CONFIG.getString(CfgConsts.PACKAGE_NAME_BASE);
String path = packageToPath(packageName);
return Paths.get(basePath, moduleName, path).toString();
String packagePath = packageToPath(packageName);
return Paths.get(javaPath, packagePath, moduleName).toString();
}
public static String getPathBasedPackage(
@ -42,15 +59,9 @@ public class PathUtils {
return Paths.get(basePath, path).toString();
}
public static boolean isMultiModule() {
return CONFIG.getBoolean(CfgConsts.MODULE_MULTIPLE);
}
public static String getModuleName(String configName, String defaultName) {
if (!isMultiModule()) {
return "";
}
return StrUtils.defaultIfBlank(configName, defaultName);
public static String getModuleName(String configModuleName, String defaultModuleName) {
return isMultiModule() ? StrUtils.defaultIfBlank(configModuleName, defaultModuleName) : "";
}
public static String getRepositoryModuleName() {
@ -71,54 +82,53 @@ public class PathUtils {
return getModuleName(configName, defaultName);
}
public static String getServicePackagePath() {
String moduleName = getServiceModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_SERVICE);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_MAPPER;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_SERVICE);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_MAPPER;
return getPathBasedPackage(moduleName, configName, defaultName);
}
public static String getControllerPackagePath() {
String moduleName = getControllerModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_CONTROLLER);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_CONTROLLER;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_CONTROLLER);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_CONTROLLER;
return getPathBasedPackage(moduleName, configName, defaultName);
}
public static String getViewPackagePath() {
String moduleName = getControllerModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_VIEW);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_VIEW;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_VIEW);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_VIEW;
return getPathBasedPackage(moduleName, configName, defaultName);
}
public static String getFormPackagePath() {
String moduleName = getControllerModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_FORM);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_FORM;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_FORM);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_FORM;
return getPathBasedPackage(moduleName, configName, defaultName);
}
public static String getQueryPackagePath() {
String moduleName = getControllerModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_QUERY);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_QUERY;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_QUERY);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_QUERY;
return getPathBasedPackage(moduleName, configName, defaultName);
}
public static String getPoPackagePath() {
String moduleName = getRepositoryModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_PO);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_PO;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_PO);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_PO;
return getPathBasedPackage(moduleName, configName, defaultName);
}
public static String getMapperPackagePath() {
String moduleName = getRepositoryModuleName();
String configPath = CONFIG.getString(CfgConsts.PACKAGE_NAME_MAPPER);
String defaultPath = CfgConsts.DEFAULT_PACKAGE_NAME_MAPPER;
return getPathBasedPackage(moduleName, configPath, defaultPath);
String configName = CONFIG.getString(CfgConsts.PACKAGE_NAME_MAPPER);
String defaultName = CfgConsts.DEFAULT_PACKAGE_NAME_MAPPER;
return getPathBasedPackage(moduleName, configName, defaultName);
}
private static String getFilename(String className, String suffix) {

@ -3,16 +3,22 @@ package space.caoshd.otone.util;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import space.caoshd.otone.tool.PropTools;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
public class VelocityUtils {
public static void render(
String beanName, Object bean, String templatePath, String outputPath
) {
PropTools propTools = new PropTools(PathConsts.VELOCITY_PROPERTIES_PATH);
Properties properties = propTools.getProperties();
Velocity.init(properties);
VelocityContext context = new VelocityContext();
context.put(beanName, bean);
@ -24,3 +30,4 @@ public class VelocityUtils {
}
}
}

@ -6,13 +6,19 @@ class PathUtilsTest {
@Test
void getProjectPath() {
String projectPath = PathUtils.getProjectPath();
String projectPath = PathUtils.getProjectBasePath();
System.out.println(projectPath);
}
@Test
void getProjectName() {
String projectName = PathUtils.getProjectName();
System.out.println(projectName);
}
@Test
void getJavaPath(){
String javaPath = PathUtils.getJavaPath();
String javaPath = PathUtils.getJavaPath("data");
System.out.println(javaPath);
}

Loading…
Cancel
Save