|
@@ -24,8 +24,32 @@ import java.util.Map; |
|
|
public class IdeaUtil { |
|
|
public class IdeaUtil { |
|
|
//获取工程中的Module文件 |
|
|
//获取工程中的Module文件 |
|
|
public static Map<String, String> getModules(String ideaPath) { |
|
|
public static Map<String, String> getModules(String ideaPath) { |
|
|
|
|
|
File file = new File(ideaPath + "/pom.xml"); |
|
|
|
|
|
if (file.exists()) { |
|
|
|
|
|
return getModulesFromPom(ideaPath, file); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file = new File(ideaPath + "/.idea/modules.xml"); |
|
|
|
|
|
if (file.exists()) return getModulesFromModule(ideaPath, file); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, String> getModulesFromPom(String ideaPath, File file) { |
|
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
|
PomProject project = XmlUtil.readValue(file, PomProject.class); |
|
|
|
|
|
if (project == null || project.modules == null) return map; |
|
|
|
|
|
for (String module: project.modules) { |
|
|
|
|
|
File f = new File(ideaPath + "/" + module); |
|
|
|
|
|
String s = f.getName(); |
|
|
|
|
|
int i = s.lastIndexOf("."); |
|
|
|
|
|
if (i >= 0) s = s.substring(0, i); |
|
|
|
|
|
map.put(s, f.getAbsolutePath()); |
|
|
|
|
|
} |
|
|
|
|
|
return map; |
|
|
|
|
|
} |
|
|
|
|
|
public static Map<String, String> getModulesFromModule(String ideaPath, File file) { |
|
|
Map<String, String> map = new HashMap<>(); |
|
|
Map<String, String> map = new HashMap<>(); |
|
|
IdeaProject project = XmlUtil.readValue(new File(ideaPath + "/.idea/modules.xml"), IdeaProject.class); |
|
|
|
|
|
|
|
|
IdeaProject project = XmlUtil.readValue(file, IdeaProject.class); |
|
|
if (project == null || project.component == null || project.component.modules == null) return map; |
|
|
if (project == null || project.component == null || project.component.modules == null) return map; |
|
|
for (Module module: project.component.modules) { |
|
|
for (Module module: project.component.modules) { |
|
|
String s = module.filepath.replace("$PROJECT_DIR$", ideaPath); |
|
|
String s = module.filepath.replace("$PROJECT_DIR$", ideaPath); |
|
@@ -49,6 +73,16 @@ public class IdeaUtil { |
|
|
@Data |
|
|
@Data |
|
|
@JsonIgnoreProperties(ignoreUnknown = true) |
|
|
@JsonIgnoreProperties(ignoreUnknown = true) |
|
|
@JacksonXmlRootElement(localName = "project") |
|
|
@JacksonXmlRootElement(localName = "project") |
|
|
|
|
|
public static class PomProject { |
|
|
|
|
|
@JacksonXmlElementWrapper(localName = "modules") |
|
|
|
|
|
@JacksonXmlProperty(localName = "module") |
|
|
|
|
|
public List<String> modules; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Data |
|
|
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true) |
|
|
|
|
|
@JacksonXmlRootElement(localName = "project") |
|
|
public static class IdeaProject { |
|
|
public static class IdeaProject { |
|
|
private Component component; |
|
|
private Component component; |
|
|
|
|
|
|
|
|