2121import com .google .common .base .Optional ;
2222import com .google .common .base .Preconditions ;
2323
24- import org .apache .maven .plugin .Mojo ;
2524import org .eclipse .jgit .api .Git ;
2625import org .eclipse .jgit .api .GitCommand ;
2726import org .eclipse .jgit .api .Status ;
3635
3736import pl .project13 .jgit .dummy .DatedRevTag ;
3837import pl .project13 .maven .git .GitDescribeConfig ;
38+ import pl .project13 .maven .git .log .LoggerBridge ;
3939import pl .project13 .maven .git .util .Pair ;
4040
4141import java .io .IOException ;
4646 */
4747public class DescribeCommand extends GitCommand <DescribeResult > {
4848
49- private Mojo mojo ;
49+ private LoggerBridge log ;
5050 private JGitCommon jGitCommon ;
5151
5252// TODO not yet implemented options:
@@ -84,27 +84,23 @@ public class DescribeCommand extends GitCommand<DescribeResult> {
8484 /**
8585 * Creates a new describe command which interacts with a single repository
8686 *
87- * @param repo the {@link org.eclipse.jgit.lib.Repository} this command should interact with
87+ * @param repo the {@link Repository} this command should interact with
88+ * @param log logger bridge to direct logs to
8889 */
8990 @ NotNull
90- public static DescribeCommand on (Repository repo ) {
91- return new DescribeCommand (repo );
91+ public static DescribeCommand on (Repository repo , LoggerBridge log ) {
92+ return new DescribeCommand (repo , log );
9293 }
9394
9495 /**
9596 * Creates a new describe command which interacts with a single repository
9697 *
9798 * @param repo the {@link org.eclipse.jgit.lib.Repository} this command should interact with
9899 */
99- private DescribeCommand (Repository repo ) {
100+ private DescribeCommand (Repository repo , @ NotNull LoggerBridge log ) {
100101 super (repo );
101- this .jGitCommon = new JGitCommon ();
102- }
103-
104- @ NotNull
105- public DescribeCommand withMojo (Mojo mojo ) {
106- this .mojo = mojo ;
107- return this ;
102+ this .jGitCommon = new JGitCommon (log );
103+ this .log = log ;
108104 }
109105
110106 /**
@@ -117,7 +113,7 @@ public DescribeCommand withMojo(Mojo mojo) {
117113 @ NotNull
118114 public DescribeCommand always (boolean always ) {
119115 this .alwaysFlag = always ;
120- mojo . getLog (). info ("--always = " + always );
116+ log . info ("--always = {}" , always );
121117 return this ;
122118 }
123119
@@ -136,7 +132,7 @@ public DescribeCommand always(boolean always) {
136132 public DescribeCommand forceLongFormat (@ Nullable Boolean forceLongFormat ) {
137133 if (forceLongFormat != null && forceLongFormat ) {
138134 this .forceLongFormat = true ;
139- mojo . getLog (). info ("--long = " + true );
135+ log . info ("--long = {}" , true );
140136 }
141137 return this ;
142138 }
@@ -152,9 +148,9 @@ public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
152148 @ NotNull
153149 public DescribeCommand abbrev (@ Nullable Integer n ) {
154150 if (n != null ) {
155- Preconditions .checkArgument (n < 41 , String .format ("N (commit abbres length) must be < 41. (Was:[%s])" , n ));
151+ Preconditions .checkArgument (n < 41 , String .format ("N (commit abbrev length) must be < 41. (Was:[%s])" , n ));
156152 Preconditions .checkArgument (n >= 0 , String .format ("N (commit abbrev length) must be positive! (Was [%s])" , n ));
157- mojo . getLog (). info ("--abbrev = " + n );
153+ log . info ("--abbrev = {}" , n );
158154 abbrev = n ;
159155 }
160156 return this ;
@@ -192,7 +188,7 @@ public DescribeCommand abbrev(@Nullable Integer n) {
192188 public DescribeCommand tags (@ Nullable Boolean includeLightweightTagsInSearch ) {
193189 if (includeLightweightTagsInSearch != null && includeLightweightTagsInSearch ) {
194190 tagsFlag = includeLightweightTagsInSearch ;
195- mojo . getLog (). info ("--tags = " + includeLightweightTagsInSearch );
191+ log . info ("--tags = {}" , includeLightweightTagsInSearch );
196192 }
197193 return this ;
198194 }
@@ -234,7 +230,7 @@ public DescribeCommand apply(@Nullable GitDescribeConfig config) {
234230 @ NotNull
235231 public DescribeCommand dirty (@ Nullable String dirtyMarker ) {
236232 Optional <String > option = Optional .fromNullable (dirtyMarker );
237- mojo . getLog (). info ("--dirty = " + option .or ("" ));
233+ log . info ("--dirty = {}" , option .or ("" ));
238234 this .dirtyOption = option ;
239235 return this ;
240236 }
@@ -250,7 +246,7 @@ public DescribeCommand dirty(@Nullable String dirtyMarker) {
250246 public DescribeCommand match (@ Nullable String pattern ) {
251247 if (!"*" .equals (pattern )) {
252248 matchOption = Optional .fromNullable (pattern );
253- mojo . getLog (). info ("--match =" + matchOption .or ("" ));
249+ log . info ("--match = {}" , matchOption .or ("" ));
254250 }
255251 return this ;
256252 }
@@ -272,7 +268,7 @@ public DescribeResult call() throws GitAPIException {
272268
273269 if (hasTags (headCommit , tagObjectIdToName ) && !forceLongFormat ) {
274270 String tagName = tagObjectIdToName .get (headCommit ).iterator ().next ();
275- mojo . getLog (). info ("The commit we're on is a Tag ([" + tagName + " ]) and forceLongFormat == false, returning." );
271+ log . info ("The commit we're on is a Tag ([{} ]) and forceLongFormat == false, returning." , tagName );
276272
277273 return new DescribeResult (tagName , dirty , dirtyOption );
278274 }
@@ -345,7 +341,7 @@ boolean findDirtyState(Repository repo) throws GitAPIException {
345341 && status .getModified ().isEmpty ()
346342 && status .getConflicting ().isEmpty ());
347343
348- mojo . getLog (). info ("Repo is in dirty state [" + isDirty + "]" );
344+ log . info ("Repo is in dirty state [{}]" , isDirty );
349345 return isDirty ;
350346 }
351347
@@ -362,7 +358,7 @@ RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
362358 RevCommit headCommit = walk .lookupCommit (headId );
363359 walk .dispose ();
364360
365- mojo . getLog (). info ("HEAD is [" + headCommit .getName () + "] " );
361+ log . info ("HEAD is [{}]" , headCommit .getName ());
366362 return headCommit ;
367363 } catch (IOException ex ) {
368364 throw new RuntimeException ("Unable to obtain HEAD commit!" , ex );
@@ -372,9 +368,9 @@ RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
372368 // git commit id -> its tag (or tags)
373369 private Map <ObjectId , List <String >> findTagObjectIds (@ NotNull Repository repo , boolean tagsFlag ) {
374370 String matchPattern = createMatchPattern ();
375- Map <ObjectId , List <DatedRevTag >> commitIdsToTags = jGitCommon .getCommitIdsToTags (repo , tagsFlag , matchPattern , mojo );
371+ Map <ObjectId , List <DatedRevTag >> commitIdsToTags = jGitCommon .getCommitIdsToTags (repo , tagsFlag , matchPattern );
376372 Map <ObjectId , List <String >> commitIdsToTagNames = jGitCommon .transformRevTagsMapToDateSortedTagNames (commitIdsToTags );
377- mojo . getLog (). info ("Created map: [" + commitIdsToTagNames + "] " );
373+ log . info ("Created map: [{}]" , commitIdsToTagNames );
378374
379375 return commitIdsToTagNames ;
380376 }
@@ -388,5 +384,4 @@ private String createMatchPattern() {
388384 matchOption .get ().replace ("*" , "\\ E.*\\ Q" ).replace ("?" , "\\ E.\\ Q" ) +
389385 "\\ E$" ;
390386 }
391- }
392-
387+ }
0 commit comments