-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(psa): maven project sub modules analysis.
- Loading branch information
Showing
7 changed files
with
145 additions
and
69 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::path::Path; | ||
|
||
use walkdir::WalkDir; | ||
|
||
pub fn list_file_names<P: AsRef<Path>>(path: P) -> Vec<String> { | ||
let mut files = Vec::new(); | ||
let walk_dir = WalkDir::new(path); | ||
for dir_entry in walk_dir.max_depth(1).into_iter() { | ||
if dir_entry.is_err() { | ||
panic!("{}", dir_entry.err().unwrap()); | ||
} | ||
|
||
let entry = dir_entry.unwrap(); | ||
if entry.metadata().unwrap().is_file() { | ||
files.push(entry.file_name().to_os_string().into_string().unwrap()); | ||
} | ||
} | ||
files | ||
} | ||
|
||
pub fn list_dirs<P: AsRef<Path>>(path: P) -> Vec<String> { | ||
let mut dirs = Vec::new(); | ||
let walk_dir = WalkDir::new(path); | ||
for dir_entry in walk_dir | ||
.max_depth(1) | ||
.sort_by(|a, b| a.file_name().cmp(b.file_name())) | ||
.into_iter() | ||
{ | ||
if dir_entry.is_err() { | ||
panic!("{}", dir_entry.err().unwrap()); | ||
} | ||
|
||
let entry = dir_entry.unwrap(); | ||
if entry.metadata().unwrap().is_dir() { | ||
dirs.push(entry.path().display().to_string()) | ||
} | ||
} | ||
dirs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::path::Path; | ||
|
||
use crate::files::list_file_names; | ||
use crate::jvm::psa_jvm::ModuleAnalyzer; | ||
use crate::{Module, Project}; | ||
|
||
pub struct MavenModuleAnalyzer {} | ||
|
||
impl ModuleAnalyzer for MavenModuleAnalyzer { | ||
fn analysis(&self, module_path: &str) -> Option<Module> { | ||
let module_name = get_module_name(module_path); | ||
match has_build_file(module_path) { | ||
true => Some(Module::new(module_name.as_str(), module_path)), | ||
_ => None, | ||
} | ||
} | ||
|
||
fn is_related(&self, project: &Project) -> bool { | ||
project.project_type == "maven" | ||
} | ||
} | ||
|
||
fn has_build_file(module_path: &str) -> bool { | ||
let file_names = list_file_names(module_path); | ||
for file_name in file_names.iter() { | ||
return match file_name.as_str() { | ||
"pom.xml" => true, | ||
_ => continue, | ||
}; | ||
} | ||
false | ||
} | ||
|
||
fn get_module_name(project_path: &str) -> String { | ||
Path::new(project_path) | ||
.file_name() | ||
.unwrap() | ||
.to_os_string() | ||
.into_string() | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod maven_module; | ||
pub mod psa_jvm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
pub mod pas_content_root; | ||
pub mod project_structure_analyzer; | ||
pub mod psa_facet; | ||
pub mod psa_library; | ||
pub mod psa_module; | ||
pub mod psa_project; | ||
|
||
pub mod jvm; | ||
|
||
pub use pas_content_root::ContentRoot; | ||
pub use project_structure_analyzer::ProjectAnalyzer; | ||
pub use psa_facet::Facet; | ||
pub use psa_library::Library; | ||
pub use psa_library::LibraryScope; | ||
pub use psa_module::Module; | ||
pub use psa_project::Project; | ||
|
||
pub mod files; | ||
pub mod jvm; | ||
pub mod pas_content_root; | ||
pub mod project_structure_analyzer; | ||
pub mod psa_facet; | ||
pub mod psa_library; | ||
pub mod psa_module; | ||
pub mod psa_project; | ||
|
||
pub trait ProjectStructureAnalyzer { | ||
fn analysis(&self, project_path: &str) -> Project; | ||
fn is_related(&self, project_path: &str) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters