21
21
import com .google .common .base .Optional ;
22
22
import com .google .common .base .Preconditions ;
23
23
24
- import org .apache .maven .plugin .Mojo ;
25
24
import org .eclipse .jgit .api .Git ;
26
25
import org .eclipse .jgit .api .GitCommand ;
27
26
import org .eclipse .jgit .api .Status ;
36
35
37
36
import pl .project13 .jgit .dummy .DatedRevTag ;
38
37
import pl .project13 .maven .git .GitDescribeConfig ;
38
+ import pl .project13 .maven .git .log .LoggerBridge ;
39
39
import pl .project13 .maven .git .util .Pair ;
40
40
41
41
import java .io .IOException ;
46
46
*/
47
47
public class DescribeCommand extends GitCommand <DescribeResult > {
48
48
49
- private Mojo mojo ;
49
+ private LoggerBridge log ;
50
50
private JGitCommon jGitCommon ;
51
51
52
52
// TODO not yet implemented options:
@@ -84,27 +84,23 @@ public class DescribeCommand extends GitCommand<DescribeResult> {
84
84
/**
85
85
* Creates a new describe command which interacts with a single repository
86
86
*
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
88
89
*/
89
90
@ 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 );
92
93
}
93
94
94
95
/**
95
96
* Creates a new describe command which interacts with a single repository
96
97
*
97
98
* @param repo the {@link org.eclipse.jgit.lib.Repository} this command should interact with
98
99
*/
99
- private DescribeCommand (Repository repo ) {
100
+ private DescribeCommand (Repository repo , @ NotNull LoggerBridge log ) {
100
101
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 ;
108
104
}
109
105
110
106
/**
@@ -117,7 +113,7 @@ public DescribeCommand withMojo(Mojo mojo) {
117
113
@ NotNull
118
114
public DescribeCommand always (boolean always ) {
119
115
this .alwaysFlag = always ;
120
- mojo . getLog (). info ("--always = " + always );
116
+ log . info ("--always = {}" , always );
121
117
return this ;
122
118
}
123
119
@@ -136,7 +132,7 @@ public DescribeCommand always(boolean always) {
136
132
public DescribeCommand forceLongFormat (@ Nullable Boolean forceLongFormat ) {
137
133
if (forceLongFormat != null && forceLongFormat ) {
138
134
this .forceLongFormat = true ;
139
- mojo . getLog (). info ("--long = " + true );
135
+ log . info ("--long = {}" , true );
140
136
}
141
137
return this ;
142
138
}
@@ -152,9 +148,9 @@ public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
152
148
@ NotNull
153
149
public DescribeCommand abbrev (@ Nullable Integer n ) {
154
150
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 ));
156
152
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 );
158
154
abbrev = n ;
159
155
}
160
156
return this ;
@@ -192,7 +188,7 @@ public DescribeCommand abbrev(@Nullable Integer n) {
192
188
public DescribeCommand tags (@ Nullable Boolean includeLightweightTagsInSearch ) {
193
189
if (includeLightweightTagsInSearch != null && includeLightweightTagsInSearch ) {
194
190
tagsFlag = includeLightweightTagsInSearch ;
195
- mojo . getLog (). info ("--tags = " + includeLightweightTagsInSearch );
191
+ log . info ("--tags = {}" , includeLightweightTagsInSearch );
196
192
}
197
193
return this ;
198
194
}
@@ -234,7 +230,7 @@ public DescribeCommand apply(@Nullable GitDescribeConfig config) {
234
230
@ NotNull
235
231
public DescribeCommand dirty (@ Nullable String dirtyMarker ) {
236
232
Optional <String > option = Optional .fromNullable (dirtyMarker );
237
- mojo . getLog (). info ("--dirty = " + option .or ("" ));
233
+ log . info ("--dirty = {}" , option .or ("" ));
238
234
this .dirtyOption = option ;
239
235
return this ;
240
236
}
@@ -250,7 +246,7 @@ public DescribeCommand dirty(@Nullable String dirtyMarker) {
250
246
public DescribeCommand match (@ Nullable String pattern ) {
251
247
if (!"*" .equals (pattern )) {
252
248
matchOption = Optional .fromNullable (pattern );
253
- mojo . getLog (). info ("--match =" + matchOption .or ("" ));
249
+ log . info ("--match = {}" , matchOption .or ("" ));
254
250
}
255
251
return this ;
256
252
}
@@ -272,7 +268,7 @@ public DescribeResult call() throws GitAPIException {
272
268
273
269
if (hasTags (headCommit , tagObjectIdToName ) && !forceLongFormat ) {
274
270
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 );
276
272
277
273
return new DescribeResult (tagName , dirty , dirtyOption );
278
274
}
@@ -345,7 +341,7 @@ boolean findDirtyState(Repository repo) throws GitAPIException {
345
341
&& status .getModified ().isEmpty ()
346
342
&& status .getConflicting ().isEmpty ());
347
343
348
- mojo . getLog (). info ("Repo is in dirty state [" + isDirty + "]" );
344
+ log . info ("Repo is in dirty state [{}]" , isDirty );
349
345
return isDirty ;
350
346
}
351
347
@@ -362,7 +358,7 @@ RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
362
358
RevCommit headCommit = walk .lookupCommit (headId );
363
359
walk .dispose ();
364
360
365
- mojo . getLog (). info ("HEAD is [" + headCommit .getName () + "] " );
361
+ log . info ("HEAD is [{}]" , headCommit .getName ());
366
362
return headCommit ;
367
363
} catch (IOException ex ) {
368
364
throw new RuntimeException ("Unable to obtain HEAD commit!" , ex );
@@ -372,9 +368,9 @@ RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
372
368
// git commit id -> its tag (or tags)
373
369
private Map <ObjectId , List <String >> findTagObjectIds (@ NotNull Repository repo , boolean tagsFlag ) {
374
370
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 );
376
372
Map <ObjectId , List <String >> commitIdsToTagNames = jGitCommon .transformRevTagsMapToDateSortedTagNames (commitIdsToTags );
377
- mojo . getLog (). info ("Created map: [" + commitIdsToTagNames + "] " );
373
+ log . info ("Created map: [{}]" , commitIdsToTagNames );
378
374
379
375
return commitIdsToTagNames ;
380
376
}
@@ -388,5 +384,4 @@ private String createMatchPattern() {
388
384
matchOption .get ().replace ("*" , "\\ E.*\\ Q" ).replace ("?" , "\\ E.\\ Q" ) +
389
385
"\\ E$" ;
390
386
}
391
- }
392
-
387
+ }
0 commit comments