Skip to content

Commit

Permalink
Migrate from using JSR 305 to JSpecify for null checking. Remove depe…
Browse files Browse the repository at this point in the history
…ndency on JSR 305 and add dependency on JSpecify.
  • Loading branch information
baron1405 committed Oct 25, 2024
1 parent 91b4168 commit c15a77f
Show file tree
Hide file tree
Showing 30 changed files with 105 additions and 110 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ plugins {
alias(libs.plugins.versions)
}

version = ProjectVersion("4.5.1", BuildType.snapshot)
version = ProjectVersion("5.0.0", BuildType.snapshot)
group = "org.cthing"
description = "Parses version numbers, ranges and constraints in a variety of formats."

Expand All @@ -41,9 +41,9 @@ java {
}

dependencies {
api(libs.jsr305)
api(libs.jspecify)

implementation(libs.cthingAnnots)
compileOnly(libs.cthingAnnots)

testImplementation(libs.junitApi)
testImplementation(libs.junitParams)
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ versions = { id = "com.github.ben-manes.versions", version = "0.51.0" }

[libraries]
assertJ = "org.assertj:assertj-core:3.26.3"
cthingAnnots = "org.cthing:cthing-annotations:1.0.0"
jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
cthingAnnots = "org.cthing:cthing-annotations:2.0.0"
jspecify = "org.jspecify:jspecify:1.0.0"
junitApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junitEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junitLauncher = "org.junit.platform:junit-platform-launcher:1.11.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.annotation.Nullable;
import org.jspecify.annotations.Nullable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.Serial;

import javax.annotation.Nullable;
import org.jspecify.annotations.Nullable;


/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cthing/versionparser/VersionRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Optional;
import java.util.function.Supplier;

import javax.annotation.Nullable;
import org.jspecify.annotations.Nullable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import java.util.Set;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import org.cthing.versionparser.AbstractVersion;
import org.cthing.versionparser.Version;
import org.jspecify.annotations.Nullable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Version handling according to the <a href="https://calver.org">Calendar Versioning</a> specification.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.calver;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
3 changes: 1 addition & 2 deletions src/main/java/org/cthing/versionparser/gem/GemVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.cthing.versionparser.AbstractVersion;
import org.cthing.versionparser.Version;
import org.cthing.versionparser.VersionParsingException;
import org.jspecify.annotations.Nullable;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cthing/versionparser/gem/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* <a href="https://rubygems.org/">RubyGems</a> version handling.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.gem;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
import java.util.Map;
import java.util.Objects;

import javax.annotation.Nullable;

import org.cthing.versionparser.AbstractVersion;
import org.cthing.versionparser.Version;
import org.jspecify.annotations.Nullable;


/**
Expand Down Expand Up @@ -61,7 +60,7 @@ public final class GradleVersion extends AbstractVersion {
"sp", QUALIFIER_SP);

private final List<String> components;
private final List<Long> numericParts;
private final List<@Nullable Long> numericParts;
private final GradleVersion baseVersion;
private final boolean preRelease;

Expand Down Expand Up @@ -123,7 +122,7 @@ public List<String> getComponents() {
*
* @return All numeric components of this version.
*/
public List<Long> getNumericParts() {
public List<@Nullable Long> getNumericParts() {
return this.numericParts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* <a href="https://gadle.org">Gradle</a> version handling.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.gradle;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
4 changes: 2 additions & 2 deletions src/main/java/org/cthing/versionparser/java/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Represents a version of the Java language.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.java;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
3 changes: 1 addition & 2 deletions src/main/java/org/cthing/versionparser/maven/MvnVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
import java.util.Objects;
import java.util.TreeMap;

import javax.annotation.Nullable;

import org.cthing.versionparser.AbstractVersion;
import org.cthing.versionparser.Version;
import org.jspecify.annotations.Nullable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* <a href="https://maven.apache.org">Maven</a> version handling.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.maven;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import org.cthing.annotations.NoCoverageGenerated;
import org.cthing.versionparser.semver.SemanticVersion;
import org.jspecify.annotations.Nullable;

import static org.cthing.versionparser.npm.ConstraintComponent.Operator.EQ;
import static org.cthing.versionparser.npm.ConstraintComponent.Operator.GT;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cthing/versionparser/npm/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* <a href="https://www.npmjs.com">NPM</a> version handling.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.npm;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
4 changes: 2 additions & 2 deletions src/main/java/org/cthing/versionparser/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Representations of version numbers and dependency version constraints. See the README.md file for information
* on using this library.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import org.cthing.versionparser.AbstractVersion;
import org.cthing.versionparser.Version;
import org.cthing.versionparser.VersionParsingException;
import org.jspecify.annotations.Nullable;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Version handling according to the <a href="https://semver.org/">Semantic Versioning 2.0</a> specification.
*/
@PackageNonnullByDefault
@NullMarked
package org.cthing.versionparser.semver;

import org.cthing.annotations.PackageNonnullByDefault;
import org.jspecify.annotations.NullMarked;
20 changes: 10 additions & 10 deletions src/test/java/org/cthing/versionparser/VersionRangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package org.cthing.versionparser;

import javax.annotation.Nullable;

import org.assertj.core.api.Assertions;
import org.cthing.versionparser.maven.MvnVersionScheme;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -19,8 +19,8 @@ public class VersionRangeTest {
@Test
public void testConstructionOpenRange() {
final VersionRange range = new VersionRange(null, null, false, false);
assertThat(range.getMinVersion()).isNull();
assertThat(range.getMaxVersion()).isNull();
Assertions.<@Nullable Version>assertThat(range.getMinVersion()).isNull();
Assertions.<@Nullable Version>assertThat(range.getMaxVersion()).isNull();
assertThat(range.isMinIncluded()).isFalse();
assertThat(range.isMaxIncluded()).isFalse();
assertThat(range.isAny()).isTrue();
Expand All @@ -32,8 +32,8 @@ public void testConstructionOpenRange() {
public void testConstructionSingleVersion() {
final Version version = version("1.2.3");
final VersionRange range = new VersionRange(version, version, true, true);
assertThat(range.getMinVersion()).isEqualTo(version);
assertThat(range.getMaxVersion()).isEqualTo(version);
Assertions.<@Nullable Version>assertThat(range.getMinVersion()).isEqualTo(version);
Assertions.<@Nullable Version>assertThat(range.getMaxVersion()).isEqualTo(version);
assertThat(range.isMinIncluded()).isTrue();
assertThat(range.isMaxIncluded()).isTrue();
assertThat(range.isAny()).isFalse();
Expand All @@ -46,8 +46,8 @@ public void testConstructionFull() {
final Version version1 = version("1.2.3");
final Version version2 = version("3.0");
VersionRange range = new VersionRange(version1, version2, true, false);
assertThat(range.getMinVersion()).isEqualTo(version1);
assertThat(range.getMaxVersion()).isEqualTo(version2);
Assertions.<@Nullable Version>assertThat(range.getMinVersion()).isEqualTo(version1);
Assertions.<@Nullable Version>assertThat(range.getMaxVersion()).isEqualTo(version2);
assertThat(range.isMinIncluded()).isTrue();
assertThat(range.isMaxIncluded()).isFalse();
assertThat(range.isAny()).isFalse();
Expand All @@ -56,8 +56,8 @@ public void testConstructionFull() {

final Version version3 = version("1.2.3");
range = new VersionRange(version3, version3, false, false);
assertThat(range.getMinVersion()).isEqualTo(version3);
assertThat(range.getMaxVersion()).isEqualTo(version3);
Assertions.<@Nullable Version>assertThat(range.getMinVersion()).isEqualTo(version3);
Assertions.<@Nullable Version>assertThat(range.getMaxVersion()).isEqualTo(version3);
assertThat(range.isMinIncluded()).isFalse();
assertThat(range.isMaxIncluded()).isFalse();
assertThat(range.isAny()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testEquality(final String format1, final String version1, final Stri
}

@Test
@SuppressWarnings({ "EqualsWithItself", "AssertBetweenInconvertibleTypes" })
@SuppressWarnings("EqualsWithItself")
public void testEquality2() throws VersionParsingException {
final CalendarVersion version = CalendarVersionScheme.parse("YYYY.WW", "2023.50");
assertThat(version).isEqualTo(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.util.Optional;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.util.Optional;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.assertj.core.api.Assertions;
import org.cthing.versionparser.Version;
import org.cthing.versionparser.VersionConstraint;
import org.cthing.versionparser.VersionParsingException;
import org.cthing.versionparser.VersionRange;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
Expand Down Expand Up @@ -56,14 +56,14 @@ public void testParseConstraint(final String constraint, final String constraint
assertThat(versionConstraint.isWeak()).isFalse();
final VersionRange versionRange = versionConstraint.getRanges().get(0);
if (minRep == null) {
assertThat(versionRange.getMinVersion()).isNull();
Assertions.<@Nullable Version>assertThat(versionRange.getMinVersion()).isNull();
} else {
assertThat(versionRange.getMinVersion()).hasToString(minRep);
Assertions.<@Nullable Version>assertThat(versionRange.getMinVersion()).hasToString(minRep);
}
if (maxRep == null) {
assertThat(versionRange.getMaxVersion()).isNull();
Assertions.<@Nullable Version>assertThat(versionRange.getMaxVersion()).isNull();
} else {
assertThat(versionRange.getMaxVersion()).hasToString(maxRep);
Assertions.<@Nullable Version>assertThat(versionRange.getMaxVersion()).hasToString(maxRep);
}
assertThat(versionRange.isMinIncluded()).isEqualTo(minIncluded);
assertThat(versionRange.isMaxIncluded()).isEqualTo(maxIncluded);
Expand All @@ -75,8 +75,8 @@ public void testParseEmpty() throws VersionParsingException {
assertThat(versionConstraint).hasToString("[0,)");
assertThat(versionConstraint.isWeak()).isFalse();
final VersionRange versionRange = versionConstraint.getRanges().get(0);
assertThat(versionRange.getMinVersion()).hasToString("0");
assertThat(versionRange.getMaxVersion()).isNull();
Assertions.<@Nullable Version>assertThat(versionRange.getMinVersion()).hasToString("0");
Assertions.<@Nullable Version>assertThat(versionRange.getMaxVersion()).isNull();
assertThat(versionRange.isMinIncluded()).isTrue();
assertThat(versionRange.isMaxIncluded()).isFalse();
}
Expand All @@ -89,13 +89,13 @@ public void testParseNotEqual() throws VersionParsingException {
final List<VersionRange> ranges = versionConstraint.getRanges();
assertThat(ranges).hasSize(2);
final VersionRange versionRange1 = ranges.get(0);
assertThat(versionRange1.getMinVersion()).isNull();
assertThat(versionRange1.getMaxVersion()).hasToString("1");
Assertions.<@Nullable Version>assertThat(versionRange1.getMinVersion()).isNull();
Assertions.<@Nullable Version>assertThat(versionRange1.getMaxVersion()).hasToString("1");
assertThat(versionRange1.isMinIncluded()).isFalse();
assertThat(versionRange1.isMaxIncluded()).isFalse();
final VersionRange versionRange2 = ranges.get(1);
assertThat(versionRange2.getMinVersion()).hasToString("1");
assertThat(versionRange2.getMaxVersion()).isNull();
Assertions.<@Nullable Version>assertThat(versionRange2.getMinVersion()).hasToString("1");
Assertions.<@Nullable Version>assertThat(versionRange2.getMaxVersion()).isNull();
assertThat(versionRange2.isMinIncluded()).isFalse();
assertThat(versionRange2.isMaxIncluded()).isFalse();
}
Expand Down
Loading

0 comments on commit c15a77f

Please sign in to comment.