Skip to content

Commit

Permalink
feat(psa): base framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynfeng committed Feb 23, 2021
1 parent 054771a commit 9d5bfc0
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 8 deletions.
20 changes: 20 additions & 0 deletions psa/src/jvm/jvm_psa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::project_structure_analyzer::StructureAnalyzer;
use crate::psa_project::Project;

pub struct JvmProjectStructureAnalyzer {}

impl Default for JvmProjectStructureAnalyzer {
fn default() -> Self {
JvmProjectStructureAnalyzer {}
}
}

impl StructureAnalyzer for JvmProjectStructureAnalyzer {
fn analysis(&self, _project_path: &str) -> Project {
Project::new("test", "test/path")
}

fn is_related(&self) -> bool {
true
}
}
1 change: 1 addition & 0 deletions psa/src/jvm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod jvm_psa;
11 changes: 11 additions & 0 deletions psa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
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;
2 changes: 1 addition & 1 deletion psa/src/pas_content_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Default for ContentRoot {

#[cfg(test)]
mod tests {
use crate::pas_content_root::ContentRoot;
use crate::ContentRoot;

#[test]
fn should_add_various_roots() {
Expand Down
47 changes: 47 additions & 0 deletions psa/src/project_structure_analyzer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::jvm::jvm_psa::JvmProjectStructureAnalyzer;
use crate::psa_project::Project;

pub trait StructureAnalyzer {
fn analysis(&self, project_path: &str) -> Project;
fn is_related(&self) -> bool;
}

pub struct ProjectAnalyzer {
analyzers: Vec<Box<dyn StructureAnalyzer>>,
}

impl ProjectAnalyzer {
pub fn run(&self, path: &str) -> Vec<Project> {
let mut projects = Vec::new();
for analyzer in self.analyzers.iter() {
match analyzer.is_related() {
true => projects.push(analyzer.analysis(path)),
_ => continue,
}
}
projects
}
}

impl Default for ProjectAnalyzer {
fn default() -> Self {
ProjectAnalyzer {
analyzers: vec![Box::new(JvmProjectStructureAnalyzer::default())],
}
}
}

#[cfg(test)]
mod tests {
use crate::ProjectAnalyzer;

#[test]
fn should_run_analyzer() {
let analyzer = ProjectAnalyzer::default();

let projects = analyzer.run("");

assert_eq!(projects.len(), 1);
assert_eq!(projects.get(0).unwrap().name, "test".to_string())
}
}
2 changes: 1 addition & 1 deletion psa/src/psa_facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct Facet {

#[cfg(test)]
mod tests {
use crate::psa_facet::Facet;
use crate::Facet;

#[test]
fn should_create_facet() {
Expand Down
2 changes: 1 addition & 1 deletion psa/src/psa_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum LibraryScope {

#[cfg(test)]
mod tests {
use crate::psa_library::{Library, LibraryScope};
use crate::{Library, LibraryScope};

#[test]
fn should_create_library() {
Expand Down
4 changes: 1 addition & 3 deletions psa/src/psa_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl Module {

#[cfg(test)]
mod tests {
use crate::psa_facet::Facet;
use crate::psa_library::{Library, LibraryScope};
use crate::psa_module::Module;
use crate::{Facet, Library, LibraryScope, Module};

#[test]
fn should_create_module() {
Expand Down
3 changes: 1 addition & 2 deletions psa/src/psa_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ impl Project {

#[cfg(test)]
mod tests {
use crate::psa_module::Module;
use crate::psa_project::Project;
use crate::{Module, Project};

#[test]
fn should_create_project() {
Expand Down

0 comments on commit 9d5bfc0

Please sign in to comment.