@@ -32,14 +32,16 @@ public final class Reckoner {
32
32
private final VcsInventorySupplier inventorySupplier ;
33
33
private final Function <VcsInventory , Optional <String >> scopeCalc ;
34
34
private final BiFunction <VcsInventory , Version , Optional <String >> stageCalc ;
35
+ private final Scope defaultInferredScope ;
35
36
private final Set <String > stages ;
36
37
private final String defaultStage ;
37
38
38
- private Reckoner (Clock clock , VcsInventorySupplier inventorySupplier , Function <VcsInventory , Optional <String >> scopeCalc , BiFunction <VcsInventory , Version , Optional <String >> stageCalc , Set <String > stages , String defaultStage ) {
39
+ private Reckoner (Clock clock , VcsInventorySupplier inventorySupplier , Function <VcsInventory , Optional <String >> scopeCalc , BiFunction <VcsInventory , Version , Optional <String >> stageCalc , Scope defaultInferredScope , Set <String > stages , String defaultStage ) {
39
40
this .clock = clock ;
40
41
this .inventorySupplier = inventorySupplier ;
41
42
this .scopeCalc = scopeCalc ;
42
43
this .stageCalc = stageCalc ;
44
+ this .defaultInferredScope = defaultInferredScope ;
43
45
this .stages = stages ;
44
46
this .defaultStage = defaultStage ;
45
47
}
@@ -83,7 +85,7 @@ private Version reckonNormal(VcsInventory inventory) {
83
85
logger .debug ("Using provided scope value: {}" , scope );
84
86
} else {
85
87
Optional <Scope > inferredScope = Scope .infer (inventory .getBaseNormal (), inventory .getBaseVersion ());
86
- scope = inferredScope .orElse (Scope . MINOR );
88
+ scope = inferredScope .orElse (defaultInferredScope );
87
89
logger .debug ("Inferred scope from base version: {}" , scope );
88
90
}
89
91
@@ -154,6 +156,7 @@ public static final class Builder {
154
156
private VcsInventorySupplier inventorySupplier ;
155
157
private Function <VcsInventory , Optional <String >> scopeCalc ;
156
158
private BiFunction <VcsInventory , Version , Optional <String >> stageCalc ;
159
+ private Scope defaultInferredScope = Scope .MINOR ;
157
160
private Set <String > stages ;
158
161
private String defaultStage ;
159
162
@@ -174,10 +177,22 @@ Builder vcs(VcsInventorySupplier inventorySupplier) {
174
177
* @return this builder
175
178
*/
176
179
public Builder git (Repository repo ) {
180
+ return git (repo , null );
181
+ }
182
+
183
+ /**
184
+ * Use the given JGit repository to infer the state of Git.
185
+ *
186
+ * @param repo repository that the version should be inferred from
187
+ * @param tagParser a parser used to find versions from tag names
188
+ * @return this builder
189
+ */
190
+ public Builder git (Repository repo , VersionTagParser tagParser ) {
177
191
if (repo == null ) {
178
192
this .inventorySupplier = () -> new VcsInventory (null , false , null , null , null , 0 , Collections .emptySet (), Collections .emptySet ());
179
193
} else {
180
- this .inventorySupplier = new GitInventorySupplier (repo );
194
+ var realParser = Optional .ofNullable (tagParser ).orElse (VersionTagParser .getDefault ());
195
+ this .inventorySupplier = new GitInventorySupplier (repo , realParser );
181
196
}
182
197
return this ;
183
198
}
@@ -193,6 +208,11 @@ public Builder scopeCalc(Function<VcsInventory, Optional<String>> scopeCalc) {
193
208
return this ;
194
209
}
195
210
211
+ public Builder defaultInferredScope (Scope defaultInferredScope ) {
212
+ this .defaultInferredScope = defaultInferredScope ;
213
+ return this ;
214
+ }
215
+
196
216
/**
197
217
* Use the given stages as valid options during inference.
198
218
*
@@ -248,9 +268,10 @@ public Reckoner build() {
248
268
Clock clock = Optional .ofNullable (this .clock ).orElseGet (Clock ::systemUTC );
249
269
Objects .requireNonNull (inventorySupplier , "Must provide a vcs." );
250
270
Objects .requireNonNull (scopeCalc , "Must provide a scope supplier." );
271
+ Objects .requireNonNull (defaultInferredScope , "Must provide a default inferred scope" );
251
272
Objects .requireNonNull (stages , "Must provide set of stages." );
252
273
Objects .requireNonNull (stageCalc , "Must provide a stage supplier." );
253
- return new Reckoner (clock , inventorySupplier , scopeCalc , stageCalc , stages , defaultStage );
274
+ return new Reckoner (clock , inventorySupplier , scopeCalc , stageCalc , defaultInferredScope , stages , defaultStage );
254
275
}
255
276
}
256
277
}
0 commit comments