3333import java .util .Set ;
3434import java .util .regex .Pattern ;
3535
36+ import org .apache .maven .plugin .Mojo ;
3637import org .eclipse .jgit .api .Git ;
3738import org .eclipse .jgit .api .errors .GitAPIException ;
3839import org .eclipse .jgit .errors .IncorrectObjectTypeException ;
4546import org .jetbrains .annotations .NotNull ;
4647
4748import pl .project13 .jgit .dummy .DatedRevTag ;
48- import pl .project13 .maven .git .log .LoggerBridge ;
4949
5050import com .google .common .annotations .VisibleForTesting ;
5151import com .google .common .base .Function ;
5252import com .google .common .base .Predicate ;
53- import com .google .common .base .Throwables ;
5453import com .google .common .collect .Collections2 ;
5554import com .google .common .collect .Lists ;
5655
57- import static com .google .common .collect .Lists .newArrayList ;
5856import static com .google .common .collect .Lists .newLinkedList ;
59- import static com .google .common .collect .Maps .newHashMap ;
6057import static com .google .common .collect .Sets .newHashSet ;
6158
6259public class JGitCommon {
@@ -97,16 +94,16 @@ public Collection<String> getTags(Repository repo, final ObjectId headId) throws
9794 }
9895 }
9996
100- public String getClosestTagName (@ NotNull LoggerBridge loggerBridge , @ NotNull Repository repo ){
101- Map <ObjectId , List <DatedRevTag >> map = getClosestTagAsMap (loggerBridge , repo );
97+ public String getClosestTagName (@ NotNull Repository repo , @ NotNull Mojo mojo ){
98+ Map <ObjectId , List <DatedRevTag >> map = getClosestTagAsMap (repo , mojo );
10299 for (Map .Entry <ObjectId , List <DatedRevTag >> entry : map .entrySet ()){
103100 return trimFullTagName (entry .getValue ().get (0 ).tagName );
104101 }
105102 return "" ;
106103 }
107104
108- public String getClosestTagCommitCount (@ NotNull LoggerBridge loggerBridge , @ NotNull Repository repo , RevCommit headCommit ){
109- HashMap <ObjectId , List <String >> map = transformRevTagsMapToDateSortedTagNames (getClosestTagAsMap (loggerBridge , repo ));
105+ public String getClosestTagCommitCount (@ NotNull Repository repo , RevCommit headCommit , @ NotNull Mojo mojo ){
106+ HashMap <ObjectId , List <String >> map = transformRevTagsMapToDateSortedTagNames (getClosestTagAsMap (repo , mojo ));
110107 ObjectId obj = (ObjectId ) map .keySet ().toArray ()[0 ];
111108
112109 RevWalk walk = new RevWalk (repo );
@@ -117,11 +114,11 @@ public String getClosestTagCommitCount(@NotNull LoggerBridge loggerBridge,@NotNu
117114 return String .valueOf (distance );
118115 }
119116
120- private Map <ObjectId , List <DatedRevTag >> getClosestTagAsMap (@ NotNull LoggerBridge loggerBridge , @ NotNull Repository repo ){
117+ private Map <ObjectId , List <DatedRevTag >> getClosestTagAsMap (@ NotNull Repository repo , @ NotNull Mojo mojo ){
121118 Map <ObjectId , List <DatedRevTag >> mapWithClosestTagOnly = newHashMap ();
122119 boolean includeLightweightTags = true ;
123120 String matchPattern = ".*" ;
124- Map <ObjectId , List <DatedRevTag >> commitIdsToTags = getCommitIdsToTags (loggerBridge , repo ,includeLightweightTags ,matchPattern );
121+ Map <ObjectId , List <DatedRevTag >> commitIdsToTags = getCommitIdsToTags (repo , includeLightweightTags , matchPattern , mojo );
125122 LinkedHashMap <ObjectId , List <DatedRevTag >> sortedCommitIdsToTags = sortByDatedRevTag (commitIdsToTags );
126123
127124 for (Map .Entry <ObjectId , List <DatedRevTag >> entry : sortedCommitIdsToTags .entrySet ()){
@@ -154,7 +151,7 @@ public int compare(Map.Entry<ObjectId, List<DatedRevTag>> m1, Map.Entry<ObjectId
154151 return result ;
155152 }
156153
157- protected Map <ObjectId , List <DatedRevTag >> getCommitIdsToTags (@ NotNull LoggerBridge loggerBridge , @ NotNull Repository repo , boolean includeLightweightTags , String matchPattern ){
154+ protected Map <ObjectId , List <DatedRevTag >> getCommitIdsToTags (@ NotNull Repository repo , boolean includeLightweightTags , String matchPattern , @ NotNull Mojo mojo ){
158155 Map <ObjectId , List <DatedRevTag >> commitIdsToTags = newHashMap ();
159156
160157 RevWalk walk = new RevWalk (repo );
@@ -163,13 +160,13 @@ protected Map<ObjectId, List<DatedRevTag>> getCommitIdsToTags(@NotNull LoggerBri
163160
164161 List <Ref > tagRefs = Git .wrap (repo ).tagList ().call ();
165162 Pattern regex = Pattern .compile (matchPattern );
166- loggerBridge . log ( "Tag refs [" , tagRefs , "]" );
163+ mojo . getLog (). info ( "Tag refs [" + tagRefs + "]" );
167164
168165 for (Ref tagRef : tagRefs ) {
169166 walk .reset ();
170167 String name = tagRef .getName ();
171168 if (!regex .matcher (name ).matches ()) {
172- loggerBridge . log ( "Skipping tagRef with name [" , name , "] as it doesn't match [" , matchPattern , "]" );
169+ mojo . getLog (). info ( "Skipping tagRef with name [" + name + "] as it doesn't match [" + matchPattern + "]" );
173170 continue ;
174171 }
175172 ObjectId resolvedCommitId = repo .resolve (name );
@@ -178,7 +175,7 @@ protected Map<ObjectId, List<DatedRevTag>> getCommitIdsToTags(@NotNull LoggerBri
178175 try {
179176 final RevTag revTag = walk .parseTag (resolvedCommitId );
180177 ObjectId taggedCommitId = revTag .getObject ().getId ();
181- loggerBridge . log ( "Resolved tag [" , revTag .getTagName (), "] [" , revTag .getTaggerIdent (), "], points at [" , taggedCommitId , "] " );
178+ mojo . getLog (). info ( "Resolved tag [" + revTag .getTagName () + "] [" + revTag .getTaggerIdent () + "], points at [" + taggedCommitId + "] " );
182179
183180 // sometimes a tag, may point to another tag, so we need to unpack it
184181 while (isTagId (taggedCommitId )) {
@@ -195,7 +192,7 @@ protected Map<ObjectId, List<DatedRevTag>> getCommitIdsToTags(@NotNull LoggerBri
195192 // it's an lightweight tag! (yeah, really)
196193 if (includeLightweightTags ) {
197194 // --tags means "include lightweight tags"
198- loggerBridge . log ( "Including lightweight tag [" , name , "]" );
195+ mojo . getLog (). info ( "Including lightweight tag [" + name + "]" );
199196
200197 DatedRevTag datedRevTag = new DatedRevTag (resolvedCommitId , name );
201198
@@ -206,16 +203,16 @@ protected Map<ObjectId, List<DatedRevTag>> getCommitIdsToTags(@NotNull LoggerBri
206203 }
207204 }
208205 } catch (Exception ignored ) {
209- loggerBridge . error ( "Failed while parsing [" , tagRef , "] -- " , Throwables . getStackTraceAsString ( ignored ) );
206+ mojo . getLog (). info ( "Failed while parsing [" + tagRef + "] -- " , ignored );
210207 }
211208 }
212209
213210 for (Map .Entry <ObjectId , List <DatedRevTag >> entry : commitIdsToTags .entrySet ()) {
214- loggerBridge . log ( "key [" , entry .getKey (), "], tags => [" , entry .getValue (), "] " );
211+ mojo . getLog (). info ( "key [" + entry .getKey () + "], tags => [" + entry .getValue () + "] " );
215212 }
216213 return commitIdsToTags ;
217214 } catch (Exception e ) {
218- loggerBridge . log ( "Unable to locate tags\n [" , Throwables . getStackTraceAsString ( e ), "]" );
215+ mojo . getLog (). info ( "Unable to locate tags" , e );
219216 } finally {
220217 walk .close ();
221218 }
0 commit comments