2626public class CostBenefitCalculator {
2727
2828 private Report report ;
29- private String repositoryPath = null ;
29+ private String repositoryPath ;
30+ private final GitLogReader gitLogReader = new GitLogReader ();
31+ private Repository repository = null ;
3032
3133 public CostBenefitCalculator (String repositoryPath ) {
3234 this .repositoryPath = repositoryPath ;
35+
36+ log .info ("Initiating Cost Benefit calculation" );
37+ try {
38+ repository = gitLogReader .gitRepository (new File (repositoryPath ));
39+ for (String file :
40+ gitLogReader .listRepositoryContentsAtHEAD (repository ).keySet ()) {
41+ log .info ("Files at HEAD: {}" , file );
42+ }
43+ } catch (IOException e ) {
44+ log .error ("Failure to access Git repository" , e );
45+ }
3346 }
3447
3548 // copied from PMD's PmdTaskImpl.java and modified
@@ -55,24 +68,9 @@ public void runPmdAnalysis() throws IOException {
5568 }
5669
5770 public List <RankedDisharmony > calculateGodClassCostBenefitValues () {
58-
59- GitLogReader repositoryLogReader = new GitLogReader ();
60- Repository repository = null ;
61- log .info ("Initiating Cost Benefit calculation" );
62- try {
63- repository = repositoryLogReader .gitRepository (new File (repositoryPath ));
64- for (String file :
65- repositoryLogReader .listRepositoryContentsAtHEAD (repository ).keySet ()) {
66- log .info ("Files at HEAD: {}" , file );
67- }
68- } catch (IOException e ) {
69- log .error ("Failure to access Git repository" , e );
70- }
71-
72- // pass repo path here, not ByteArrayOutputStream
7371 List <GodClass > godClasses = getGodClasses ();
7472
75- List <ScmLogInfo > scmLogInfos = getRankedChangeProneness (repositoryLogReader , repository , godClasses );
73+ List <ScmLogInfo > scmLogInfos = getRankedChangeProneness (godClasses );
7674
7775 Map <String , ScmLogInfo > rankedLogInfosByPath =
7876 scmLogInfos .stream ().collect (Collectors .toMap (ScmLogInfo ::getPath , logInfo -> logInfo , (a , b ) -> b ));
@@ -116,15 +114,14 @@ private List<GodClass> getGodClasses() {
116114 return godClasses ;
117115 }
118116
119- <T extends Disharmony > List <ScmLogInfo > getRankedChangeProneness (
120- GitLogReader repositoryLogReader , Repository repository , List <T > disharmonies ) {
117+ <T extends Disharmony > List <ScmLogInfo > getRankedChangeProneness (List <T > disharmonies ) {
121118 List <ScmLogInfo > scmLogInfos = new ArrayList <>();
122119 log .info ("Calculating Change Proneness" );
123120 for (Disharmony disharmony : disharmonies ) {
124121 String path = disharmony .getFileName ();
125122 ScmLogInfo scmLogInfo = null ;
126123 try {
127- scmLogInfo = repositoryLogReader .fileLog (repository , path );
124+ scmLogInfo = gitLogReader .fileLog (repository , path );
128125 log .info ("Successfully fetched scmLogInfo for {}" , scmLogInfo .getPath ());
129126 } catch (GitAPIException | IOException e ) {
130127 log .error ("Error reading Git repository contents." , e );
@@ -138,25 +135,15 @@ <T extends Disharmony> List<ScmLogInfo> getRankedChangeProneness(
138135 }
139136 }
140137
141- ChangePronenessRanker changePronenessRanker = new ChangePronenessRanker (repository , repositoryLogReader );
138+ ChangePronenessRanker changePronenessRanker = new ChangePronenessRanker (repository , gitLogReader );
142139 changePronenessRanker .rankChangeProneness (scmLogInfos );
143140 return scmLogInfos ;
144141 }
145142
146143 public List <RankedDisharmony > calculateCBOCostBenefitValues () {
147-
148- GitLogReader repositoryLogReader = new GitLogReader ();
149- Repository repository = null ;
150- log .info ("Initiating Cost Benefit calculation" );
151- try {
152- repository = repositoryLogReader .gitRepository (new File (repositoryPath ));
153- } catch (IOException e ) {
154- log .error ("Failure to access Git repository" , e );
155- }
156-
157144 List <CBOClass > cboClasses = getCBOClasses ();
158145
159- List <ScmLogInfo > scmLogInfos = getRankedChangeProneness (repositoryLogReader , repository , cboClasses );
146+ List <ScmLogInfo > scmLogInfos = getRankedChangeProneness (cboClasses );
160147
161148 Map <String , ScmLogInfo > rankedLogInfosByPath =
162149 scmLogInfos .stream ().collect (Collectors .toMap (ScmLogInfo ::getPath , logInfo -> logInfo , (a , b ) -> b ));
0 commit comments