66
77import net .minecraftforge .gitver .internal .GitVersionImpl ;
88import net .minecraftforge .gitver .internal .GitVersionInternal ;
9- import org .jetbrains .annotations .NotNullByDefault ;
10- import org .jetbrains .annotations .Nullable ;
11- import org .jetbrains .annotations .UnknownNullability ;
129import org .jetbrains .annotations .Unmodifiable ;
10+ import org .jspecify .annotations .NonNull ;
11+ import org .jspecify .annotations .NullUnmarked ;
12+ import org .jspecify .annotations .Nullable ;
1313
1414import java .io .File ;
1515import java .io .Serializable ;
1616import java .util .Collection ;
1717import java .util .List ;
18+ import java .util .function .Supplier ;
1819
1920/**
2021 * The heart of the GitVersion library. Information about how GitVersion operates can be found on the
2122 * <a href="https://github.com/MinecraftForge/GitVersion">path page</a>.
2223 */
23- public sealed interface GitVersion extends AutoCloseable permits GitVersionInternal {
24+ public sealed interface GitVersion extends Supplier < String >, AutoCloseable permits GitVersionInternal {
2425 /* BUILDER */
2526
2627 /**
@@ -41,40 +42,41 @@ static Builder builder() {
4142 * automatically from the project directory. If the git directory is not set, it will default to {@code .git} in the
4243 * root directory.
4344 */
45+ @ NullUnmarked
4446 sealed interface Builder permits GitVersionInternal .Builder {
4547 /**
4648 * Sets the git directory for the GitVersion instance. Ideally, this should be located in the root directory.
4749 *
4850 * @param gitDir The git directory
4951 * @return This builder
5052 */
51- Builder gitDir (@ UnknownNullability File gitDir );
53+ Builder gitDir (File gitDir );
5254
5355 /**
5456 * Sets the root directory for the GitVersion instance.
5557 *
5658 * @param root The root directory
5759 * @return This builder
5860 */
59- Builder root (@ UnknownNullability File root );
61+ Builder root (File root );
6062
6163 /**
6264 * Sets the project directory for the GitVersion instance.
6365 *
6466 * @param project The project directory
6567 * @return This builder
6668 */
67- Builder project (@ UnknownNullability File project );
69+ Builder project (File project );
6870
69- Builder config (@ UnknownNullability File config );
71+ Builder config (File config );
7072
7173 /**
7274 * Sets the config to use for the GitVersion instance.
7375 *
7476 * @param config The config
7577 * @return This builder
7678 */
77- Builder config (GitVersionConfig config );
79+ Builder config (@ NonNull GitVersionConfig config );
7880
7981 Builder strict (boolean strict );
8082
@@ -95,55 +97,17 @@ sealed interface Builder permits GitVersionInternal.Builder {
9597
9698 /**
9799 * Calculates a version number in the form
98- * <code>{@link GitVersionImpl.Info#getTag() tag}.{@link GitVersionImpl.Info#getOffset() offset}</code>.
100+ * <code>{@link GitVersionImpl.Info#getTag() tag}.{@link GitVersionImpl.Info#getOffset() offset}</code>. The default
101+ * GitVersion implementation will cache this version after it has been first queried.
99102 * <p>
100- * For example, if your current tag is {@code 1.0} and 5 commits have been made since the tagged commit, then the
101- * resulting version number will be {@code 1.0.5}.
103+ * If the {@code .gitversion.toml} config specifies branches, the current branch must match that within the branches
104+ * String array (or it must be a detached HEAD). If it doesn't match, <code>-{@link Info#getBranch(boolean) branch}</code>
105+ * will be appended to the version number.
102106 *
103- * @return The calculated version
107+ * @return The calculated version number.
104108 */
105- String getTagOffset ();
106-
107- /** @see #getTagOffsetBranch(Collection) */
108- String getTagOffsetBranch ();
109-
110- /** @see #getTagOffsetBranch(Collection) */
111- String getTagOffsetBranch (@ UnknownNullability String ... allowedBranches );
112-
113- /**
114- * Calculates a version number using {@link #getTagOffset()}. If the current branch is not included in the defined
115- * list of allowed branches, it will be appended to the version number. It is important to note that any instances
116- * of the forward-slash character ({@code /}) will be replaced with a hyphen ({@code -}).
117- * <p>
118- * For example, if your current tag is {@code 2.3}, 6 commits have been made since the tagged commit, and you are on
119- * a branch named {@literal "feature/cool-stuff"}, then the resulting version number will be
120- * {@code 2.3.6-feature-cool-stuff}.
121- *
122- * @param allowedBranches A list of allowed branches; the current branch is appended if not in this list
123- * @return The calculated version
124- * @see #getTagOffset()
125- */
126- String getTagOffsetBranch (@ UnknownNullability Collection <String > allowedBranches );
127-
128- /** @see #getMCTagOffsetBranch(String, Collection) */
129- String getMCTagOffsetBranch (@ UnknownNullability String mcVersion );
130-
131- /** @see #getMCTagOffsetBranch(String, Collection) */
132- String getMCTagOffsetBranch (String mcVersion , String ... allowedBranches );
133-
134- /**
135- * Calculates a version number using {@link #getTagOffsetBranch(String...)}, additionally prepending the given
136- * Minecraft version.
137- * <p>
138- * For example, if your current tag is {@code 5.0}, 2 commits have been made since the tagged commit, you are on a
139- * branch named {@literal "master"} which is included in the allowed branches, and the given Minecraft version is
140- * {@code 1.21.4}, then the resulting version number will be {@code 1.21.4-5.0.2}.
141- *
142- * @param mcVersion The minecraft version
143- * @param allowedBranches A list of allowed branches
144- * @return The calculated version
145- */
146- String getMCTagOffsetBranch (String mcVersion , Collection <String > allowedBranches );
109+ @ Override
110+ String get ();
147111
148112
149113 /* CHANGELOG */
@@ -190,8 +154,10 @@ sealed interface Builder permits GitVersionInternal.Builder {
190154 * Represents information about a git repository. This can be used to access other information when the standard
191155 * versioning methods in {@link GitVersion} do not suffice.
192156 */
193- @ NotNullByDefault
194157 sealed interface Info extends Serializable permits GitVersionInternal .Info {
158+ /** @return The calculated version */
159+ String getVersion ();
160+
195161 /** @return The current tag as described by the Git repository using the applied filters */
196162 String getTag ();
197163
@@ -239,6 +205,8 @@ sealed interface Info extends Serializable permits GitVersionInternal.Info {
239205 /** @return The tag prefix used when filtering tags */
240206 String getTagPrefix ();
241207
208+ @ Unmodifiable Collection <String > getBranches ();
209+
242210 /** @return The filters used when filtering tags (excluding the {@linkplain #getTagPrefix() tag prefix}) */
243211 @ Unmodifiable Collection <String > getFilters ();
244212
0 commit comments