From 969f46198a671339bcd36c206d4a8d227835030c Mon Sep 17 00:00:00 2001 From: ynfeng Date: Fri, 26 Feb 2021 10:04:23 +0800 Subject: [PATCH] feat(psa): sub module content root detect. --- .../module1/src/main/java/Hello.java | 0 .../src/main/resources/application.yml | 0 .../module1/src/test/java/HelloTest.java | 0 .../src/test/resources/application.yml | 0 .../module2/src/main/java/Hello.java | 0 .../src/main/resources/application.yml | 0 .../module2/src/test/java/HelloTest.java | 0 .../src/test/resources/application.yml | 0 psa/src/jvm/maven_module.rs | 1 + psa/src/jvm/psa_jvm.rs | 42 ++++++++++++++++++- 10 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module1/src/main/java/Hello.java create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module1/src/main/resources/application.yml create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module1/src/test/java/HelloTest.java create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module1/src/test/resources/application.yml create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module2/src/main/java/Hello.java create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module2/src/main/resources/application.yml create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module2/src/test/java/HelloTest.java create mode 100644 _fixtures/projects/java/multi_mod_maven_project/module2/src/test/resources/application.yml diff --git a/_fixtures/projects/java/multi_mod_maven_project/module1/src/main/java/Hello.java b/_fixtures/projects/java/multi_mod_maven_project/module1/src/main/java/Hello.java new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module1/src/main/resources/application.yml b/_fixtures/projects/java/multi_mod_maven_project/module1/src/main/resources/application.yml new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module1/src/test/java/HelloTest.java b/_fixtures/projects/java/multi_mod_maven_project/module1/src/test/java/HelloTest.java new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module1/src/test/resources/application.yml b/_fixtures/projects/java/multi_mod_maven_project/module1/src/test/resources/application.yml new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module2/src/main/java/Hello.java b/_fixtures/projects/java/multi_mod_maven_project/module2/src/main/java/Hello.java new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module2/src/main/resources/application.yml b/_fixtures/projects/java/multi_mod_maven_project/module2/src/main/resources/application.yml new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module2/src/test/java/HelloTest.java b/_fixtures/projects/java/multi_mod_maven_project/module2/src/test/java/HelloTest.java new file mode 100644 index 00000000..e69de29b diff --git a/_fixtures/projects/java/multi_mod_maven_project/module2/src/test/resources/application.yml b/_fixtures/projects/java/multi_mod_maven_project/module2/src/test/resources/application.yml new file mode 100644 index 00000000..e69de29b diff --git a/psa/src/jvm/maven_module.rs b/psa/src/jvm/maven_module.rs index 0ed715a0..8829fed6 100644 --- a/psa/src/jvm/maven_module.rs +++ b/psa/src/jvm/maven_module.rs @@ -10,6 +10,7 @@ impl MavenModuleAnalyzer { fn detect_sub_modules(&self, module_path: &str, module: &mut Option) { let sub_modules = &mut self.analysis_sub_modules(module_path); module.as_mut().unwrap().add_sub_modules(sub_modules); + self.detect_content_root(module_path, module); } fn analysis_sub_modules(&self, module_path: &str) -> Vec { diff --git a/psa/src/jvm/psa_jvm.rs b/psa/src/jvm/psa_jvm.rs index e2a070b6..af51c1a4 100644 --- a/psa/src/jvm/psa_jvm.rs +++ b/psa/src/jvm/psa_jvm.rs @@ -125,7 +125,7 @@ mod tests { } #[test] - fn should_detect_project_model_content_root() { + fn should_detect_project_module_content_root() { let project = do_analysis(vec![ "_fixtures", "projects", @@ -173,6 +173,46 @@ mod tests { ); } + #[test] + fn should_detect_sub_module_content_root() { + let project = do_analysis(vec![ + "_fixtures", + "projects", + "java", + "multi_mod_maven_project", + ]); + + let modules = project.modules; + let project_module = modules.get(0).unwrap(); + let module1 = project_module.sub_modules.get(0).unwrap(); + let content_root = &module1.content_root; + + let expect_source_path = join_path(module1.path.as_str(), vec!["src", "main", "java"]); + assert_eq!( + content_root.source_root.get(0).unwrap().as_str(), + expect_source_path + ); + + let expect_test_source_root = join_path(module1.path.as_str(), vec!["src", "test", "java"]); + assert_eq!( + content_root.test_source_root.get(0).unwrap().as_str(), + expect_test_source_root.as_str() + ); + + let expect_test_source_root = join_path(module1.path.as_str(), vec!["src", "test", "java"]); + assert_eq!( + content_root.test_source_root.get(0).unwrap().as_str(), + expect_test_source_root.as_str() + ); + + let expect_test_resources_root = + join_path(module1.path.as_str(), vec!["src", "test", "resources"]); + assert_eq!( + content_root.test_resource_root.get(0).unwrap(), + expect_test_resources_root.as_str() + ); + } + fn do_analysis(path: Vec<&str>) -> Project { let mut project_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .parent()