1313import org .hjug .git .GitLogReader ;
1414import org .hjug .git .RepositoryLogReader ;
1515import org .hjug .git .ScmLogInfo ;
16- import org .hjug .metrics .GodClass ;
17- import org .hjug .metrics .GodClassRanker ;
18- import org .hjug .metrics .PMDGodClassRuleRunner ;
16+ import org .hjug .metrics .*;
1917
2018@ Slf4j
2119public class CostBenefitCalculator {
@@ -31,7 +29,10 @@ public List<RankedDisharmony> calculateCostBenefitValues(String repositoryPath)
3129 log .error ("Failure to access Git repository" , e );
3230 }
3331
34- List <GodClass > godClasses = getGodClasses (repositoryLogReader , repository );
32+ Map <String , ByteArrayOutputStream > filesToScan = getFilesToScan (repositoryLogReader , repository );
33+
34+ List <GodClass > godClasses = getGodClasses (filesToScan );
35+ List <CBOClass > cboClasses = getCBOClasses (filesToScan );
3536
3637 List <ScmLogInfo > scmLogInfos = getRankedChangeProneness (repositoryLogReader , repository , godClasses );
3738
@@ -67,17 +68,10 @@ List<ScmLogInfo> getRankedChangeProneness(
6768 return scmLogInfos ;
6869 }
6970
70- private List <GodClass > getGodClasses (RepositoryLogReader repositoryLogReader , Repository repository ) {
71- Map <String , ByteArrayOutputStream > filesToScan = new HashMap <>();
72- log .info ("Identifying God Classes from files in repository" );
73- try {
74- filesToScan = repositoryLogReader .listRepositoryContentsAtHEAD (repository );
75- } catch (IOException e ) {
76- log .error ("Error reading Git repository contents" , e );
77- }
78-
71+ private List <GodClass > getGodClasses (Map <String , ByteArrayOutputStream > filesToScan ) {
7972 PMDGodClassRuleRunner ruleRunner = new PMDGodClassRuleRunner ();
8073
74+ log .info ("Identifying God Classes from files in repository" );
8175 List <GodClass > godClasses = new ArrayList <>();
8276 for (Map .Entry <String , ByteArrayOutputStream > entry : filesToScan .entrySet ()) {
8377 String filePath = entry .getKey ();
@@ -92,4 +86,32 @@ private List<GodClass> getGodClasses(RepositoryLogReader repositoryLogReader, Re
9286 godClassRanker .rankGodClasses (godClasses );
9387 return godClasses ;
9488 }
89+
90+ private List <CBOClass > getCBOClasses (Map <String , ByteArrayOutputStream > filesToScan ) {
91+
92+ CBORuleRunner ruleRunner = new CBORuleRunner ();
93+
94+ log .info ("Identifying highly coupled classes from files in repository" );
95+ List <CBOClass > cboClasses = new ArrayList <>();
96+ for (Map .Entry <String , ByteArrayOutputStream > entry : filesToScan .entrySet ()) {
97+ String filePath = entry .getKey ();
98+ ByteArrayOutputStream value = entry .getValue ();
99+
100+ ByteArrayInputStream inputStream = new ByteArrayInputStream (value .toByteArray ());
101+ Optional <CBOClass > godClassOptional = ruleRunner .runCBOClassRule (filePath , inputStream );
102+ godClassOptional .ifPresent (cboClasses ::add );
103+ }
104+
105+ return cboClasses ;
106+ }
107+
108+ private Map <String , ByteArrayOutputStream > getFilesToScan (RepositoryLogReader repositoryLogReader , Repository repository ) {
109+ Map <String , ByteArrayOutputStream > filesToScan = new HashMap <>();
110+ try {
111+ filesToScan = repositoryLogReader .listRepositoryContentsAtHEAD (repository );
112+ } catch (IOException e ) {
113+ log .error ("Error reading Git repository contents" , e );
114+ }
115+ return filesToScan ;
116+ }
95117}
0 commit comments