77import java .text .DateFormat ;
88import java .text .SimpleDateFormat ;
99import java .util .Date ;
10+ import java .util .List ;
1011
1112import reposense .util .Constants ;
1213
1314public class CommandRunner {
14-
1515 private static final DateFormat GIT_LOG_SINCE_DATE_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'00:00:00+08:00" );
1616 private static final DateFormat GIT_LOG_UNTIL_DATE_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'23:59:59+08:00" );
1717
1818 private static boolean isWindows = isWindows ();
1919
20- public static String gitLog (String root , Date sinceDate , Date untilDate ) {
20+ public static String gitLog (String root , Date sinceDate , Date untilDate , List < String > fileFormats ) {
2121 Path rootPath = Paths .get (root );
2222
2323 String command = "git log --no-merges " ;
24- command += getGitDateRangeArgs (sinceDate , untilDate );
25- command += " --pretty=format:\" %h|%aN|%ad|%s\" --date=iso --shortstat -- \" *.java\" -- \" *.adoc\" " ;
24+ command += convertToGitDateRangeArgs (sinceDate , untilDate );
25+ command += " --pretty=format:\" %h|%aN|%ad|%s\" --date=iso --shortstat" ;
26+ command += convertToGitFileFormatsArgs (fileFormats );
2627
2728 return runCommand (rootPath , command );
2829 }
@@ -59,7 +60,7 @@ public static String blameRaw(String root, String fileDirectory, Date sinceDate,
5960 Path rootPath = Paths .get (root );
6061
6162 String blameCommand = "git blame -w -C -C -M --line-porcelain" ;
62- blameCommand += getGitDateRangeArgs (sinceDate , untilDate );
63+ blameCommand += convertToGitDateRangeArgs (sinceDate , untilDate );
6364 blameCommand += " " + addQuote (fileDirectory );
6465 blameCommand += getAuthorFilterCommand ();
6566
@@ -139,7 +140,7 @@ private static String getAuthorFilterCommand() {
139140 /**
140141 * Returns the {@code String} command to specify the date range of commits to analyze for `git` commands.
141142 */
142- private static String getGitDateRangeArgs (Date sinceDate , Date untilDate ) {
143+ private static String convertToGitDateRangeArgs (Date sinceDate , Date untilDate ) {
143144 String gitDateRangeArgs = "" ;
144145
145146 if (sinceDate != null ) {
@@ -151,4 +152,18 @@ private static String getGitDateRangeArgs(Date sinceDate, Date untilDate) {
151152
152153 return gitDateRangeArgs ;
153154 }
155+
156+ /**
157+ * Returns the {@code String} command to specify the file formats to analyze for `git` commands.
158+ */
159+ private static String convertToGitFileFormatsArgs (List <String > fileFormats ) {
160+ StringBuilder gitFileFormatsArgsBuilder = new StringBuilder ();
161+
162+ final String cmdFormat = " -- " + addQuote ("*.%s" );
163+ fileFormats .stream ()
164+ .map (format -> String .format (cmdFormat , format ))
165+ .forEach (gitFileFormatsArgsBuilder ::append );
166+
167+ return gitFileFormatsArgsBuilder .toString ();
168+ }
154169}
0 commit comments