Skip to content

Commit f07299a

Browse files
committed
Reduce scope and expect all configuration through TOML file (#7)
Also includes: - Migration of nulls from JetBrains to jSpecify. - Major API changes. Known issues: - Changelog generation is currently broken.
1 parent dd6970d commit f07299a

16 files changed

Lines changed: 147 additions & 161 deletions

File tree

‎build.gradle‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ configurations {
3232

3333
dependencies {
3434
// Static Analysis
35-
compileOnly libs.nulls
35+
api libs.annotations.jspecify
36+
compileOnly libs.annotations.jetbrains
3637

3738
// Git
3839
implementation libs.jgit

‎gitversion-cli/src/main/java/net/minecraftforge/gitver/cli/Main.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ The root directory to use (ideally containing the .git directory).
129129
} else if (options.has(jsonO)) {
130130
result = version.toJson();
131131
} else {
132-
result = version.getTagOffset();
132+
result = version.get();
133133
}
134134

135135
if (output != null)

‎settings.gradle‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ dependencyResolutionManagement {
4444
library 'slf4j', 'org.slf4j', 'slf4j-simple' version '1.7.36'
4545

4646
// Static Analysis
47-
library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2'
47+
library 'annotations-jspecify', 'org.jspecify', 'jspecify' version '1.0.1'
48+
library 'annotations-jetbrains', 'org.jetbrains', 'annotations' version '26.1.0'
4849
}
4950
//@formatter:on
5051
}

‎src/main/java/module-info.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
* Copyright (c) Forge Development LLC
33
* SPDX-License-Identifier: LGPL-2.1-only
44
*/
5+
import org.jspecify.annotations.NullMarked;
6+
7+
@NullMarked
58
module net.minecraftforge.gitver {
69
exports net.minecraftforge.gitver.api;
710

811
requires org.tomlj;
912
requires org.eclipse.jgit;
1013

1114
requires com.google.gson;
15+
requires transitive org.jspecify;
1216
requires static org.jetbrains.annotations;
1317
}

‎src/main/java/net/minecraftforge/gitver/api/GitVersion.java‎

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66

77
import net.minecraftforge.gitver.internal.GitVersionImpl;
88
import net.minecraftforge.gitver.internal.GitVersionInternal;
9-
import org.jetbrains.annotations.NotNullByDefault;
10-
import org.jetbrains.annotations.Nullable;
11-
import org.jetbrains.annotations.UnknownNullability;
129
import org.jetbrains.annotations.Unmodifiable;
10+
import org.jspecify.annotations.NonNull;
11+
import org.jspecify.annotations.NullUnmarked;
12+
import org.jspecify.annotations.Nullable;
1313

1414
import java.io.File;
1515
import java.io.Serializable;
1616
import java.util.Collection;
1717
import 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

‎src/main/java/net/minecraftforge/gitver/api/GitVersionConfig.java‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package net.minecraftforge.gitver.api;
66

77
import net.minecraftforge.gitver.internal.GitVersionConfigInternal;
8-
import org.jetbrains.annotations.Nullable;
9-
import org.jetbrains.annotations.UnknownNullability;
8+
import org.jspecify.annotations.NonNull;
9+
import org.jspecify.annotations.NullMarked;
10+
import org.jspecify.annotations.NullUnmarked;
11+
import org.jspecify.annotations.Nullable;
1012
import org.tomlj.Toml;
1113

1214
import java.io.File;
@@ -19,6 +21,7 @@
1921
*
2022
* @see Project
2123
*/
24+
@NullUnmarked
2225
public sealed interface GitVersionConfig permits GitVersionConfigInternal {
2326
/**
2427
* Gets the project at the given path.
@@ -29,18 +32,18 @@ public sealed interface GitVersionConfig permits GitVersionConfigInternal {
2932
@Nullable Project getProject(@Nullable String path);
3033

3134
/** @return All projects, including the root project. */
32-
Collection<Project> getAllProjects();
35+
@NonNull Collection<Project> getAllProjects();
3336

3437
/**
3538
* Validates this configuration by ensuring that all declared subprojects exist from the given root.
3639
*
3740
* @param root The root to validate from
3841
* @throws IllegalArgumentException If a subproject path does not exist
3942
*/
40-
void validate(@UnknownNullability File root) throws IllegalArgumentException;
43+
void validate(File root) throws IllegalArgumentException;
4144

4245
/** @return Any errors made during the config TOML parsing */
43-
List<? extends RuntimeException> errors();
46+
@NonNull List<? extends RuntimeException> errors();
4447

4548
/**
4649
* Attempts to parse the given config file into a {@link GitVersionConfig} using {@linkplain Toml TOMLJ}. If it
@@ -49,13 +52,16 @@ public sealed interface GitVersionConfig permits GitVersionConfigInternal {
4952
* @param config The config file
5053
* @return The parsed config, or an empty config if the file does not exist
5154
*/
52-
static GitVersionConfig parse(@UnknownNullability File config) {
55+
static @NonNull GitVersionConfig parse(File config) {
5356
return GitVersionConfigInternal.parse(config);
5457
}
5558

59+
@NullMarked
5660
sealed interface Project permits GitVersionConfigInternal.Project {
5761
String getPath();
5862

63+
String[] getBranches();
64+
5965
String[] getIncludePaths();
6066

6167
String[] getExcludePaths();

‎src/main/java/net/minecraftforge/gitver/api/package-info.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: LGPL-2.1-only
44
*/
55
// TODO [Git Version] Documentation
6-
@NotNullByDefault
6+
@NullMarked
77
package net.minecraftforge.gitver.api;
88

9-
import org.jetbrains.annotations.NotNullByDefault;
9+
import org.jspecify.annotations.NullMarked;

‎src/main/java/net/minecraftforge/gitver/internal/GitChangelog.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import org.eclipse.jgit.api.Git;
88
import org.eclipse.jgit.api.errors.GitAPIException;
99
import org.eclipse.jgit.revwalk.RevCommit;
10-
import org.jetbrains.annotations.Nullable;
10+
import org.jspecify.annotations.Nullable;
1111

1212
import java.io.IOException;
13-
import java.util.ArrayList;
1413
import java.util.Collections;
1514
import java.util.HashSet;
1615
import java.util.Objects;

‎src/main/java/net/minecraftforge/gitver/internal/GitUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.eclipse.jgit.revwalk.filter.RevFilter;
2020
import org.eclipse.jgit.transport.RemoteConfig;
2121
import org.eclipse.jgit.util.StringUtils;
22-
import org.jetbrains.annotations.Nullable;
22+
import org.jspecify.annotations.Nullable;
2323

2424
import java.io.File;
2525
import java.io.IOException;

0 commit comments

Comments
 (0)