Skip to content

Commit

Permalink
Bump com.github.zafarkhaja:java-semver from 0.9.0 to 0.10.2 (#17925)
Browse files Browse the repository at this point in the history
* Bump com.github.zafarkhaja:java-semver from 0.9.0 to 0.10.2

Bumps [com.github.zafarkhaja:java-semver](https://github.com/zafarkhaja/jsemver) from 0.9.0 to 0.10.2.
- [Release notes](https://github.com/zafarkhaja/jsemver/releases)
- [Changelog](https://github.com/zafarkhaja/jsemver/blob/master/CHANGELOG.md)
- [Commits](zafarkhaja/jsemver@v0.9.0...v0.10.2)

---
updated-dependencies:
- dependency-name: com.github.zafarkhaja:java-semver
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* refactor all usages of deprecated java semver methods, remove unused code

* add changelog

* address review comments

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kay Roepke <[email protected]>
Co-authored-by: Bernd Ahlers <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 7b78dd7 commit be90077
Show file tree
Hide file tree
Showing 27 changed files with 109 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
*/
package org.graylog.storage.elasticsearch7;

import com.github.zafarkhaja.semver.Version;
import com.google.common.collect.ImmutableSet;
import jakarta.inject.Inject;
import org.graylog2.featureflag.FeatureFlags;
import org.graylog2.plugin.Plugin;
import org.graylog2.plugin.PluginMetaData;
import org.graylog2.plugin.PluginModule;
import org.graylog2.storage.SearchVersion;

import jakarta.inject.Inject;

import java.util.Collection;

import static org.graylog2.indexer.Constants.COMPOSABLE_INDEX_TEMPLATES_FEATURE;

public class Elasticsearch7Plugin implements Plugin {
public static final SearchVersion SUPPORTED_ES_VERSION = SearchVersion.elasticsearch(7, 0, 0);
public static final SearchVersion SUPPORTED_OPENSEARCH_VERSION = SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, com.github.zafarkhaja.semver.Version.forIntegers(1, 0, 0));
public static final SearchVersion SUPPORTED_OPENSEARCH_VERSION = SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, Version.of(1, 0, 0));

@Inject
private FeatureFlags featureFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void testElasticsearchVersionFetching() throws IOException {

assertThat(toTest.version())
.isNotEmpty()
.contains(SearchVersion.create(SearchVersion.Distribution.ELASTICSEARCH, Version.valueOf("7.10.2")));
.contains(SearchVersion.create(SearchVersion.Distribution.ELASTICSEARCH, Version.parse("7.10.2")));

}

Expand All @@ -71,7 +71,7 @@ void testOpensearchVersionFetching() throws IOException {

assertThat(toTest.version())
.isNotEmpty()
.contains(SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, Version.valueOf("1.3.1")));
.contains(SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, Version.parse("1.3.1")));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@
*/
package org.graylog.storage.opensearch2;

import com.github.zafarkhaja.semver.Version;
import com.google.common.collect.ImmutableSet;
import jakarta.inject.Inject;
import org.graylog2.featureflag.FeatureFlags;
import org.graylog2.plugin.Plugin;
import org.graylog2.plugin.PluginMetaData;
import org.graylog2.plugin.PluginModule;
import org.graylog2.storage.SearchVersion;

import jakarta.inject.Inject;

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.github.zafarkhaja.semver.Version.forIntegers;
import static org.graylog2.indexer.Constants.COMPOSABLE_INDEX_TEMPLATES_FEATURE;

public class OpenSearch2Plugin implements Plugin {
public static final Set<SearchVersion> SUPPORTED_OS_VERSIONS = ImmutableSet.of(
SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, forIntegers(2, 0, 0)),
SearchVersion.create(SearchVersion.Distribution.DATANODE, forIntegers(5, 0, 0))
SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, Version.of(2, 0, 0)),
SearchVersion.create(SearchVersion.Distribution.DATANODE, Version.of(5, 0, 0))
);

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void testElasticsearchVersionFetching() throws IOException {

assertThat(toTest.version())
.isNotEmpty()
.contains(SearchVersion.create(SearchVersion.Distribution.ELASTICSEARCH, Version.valueOf("7.10.2")));
.contains(SearchVersion.create(SearchVersion.Distribution.ELASTICSEARCH, Version.parse("7.10.2")));

}

Expand All @@ -71,7 +71,7 @@ void testOpensearchVersionFetching() throws IOException {

assertThat(toTest.version())
.isNotEmpty()
.contains(SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, Version.valueOf("1.3.1")));
.contains(SearchVersion.create(SearchVersion.Distribution.OPENSEARCH, Version.parse("1.3.1")));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.graylog.plugins.views.search.views;

import com.github.zafarkhaja.semver.Version;

import jakarta.inject.Singleton;

import java.net.URI;
Expand Down Expand Up @@ -47,7 +46,7 @@ public URI url() {

@Override
public Version version() {
return Version.valueOf("3.1.0");
return Version.parse("3.1.0");
}

@Override
Expand All @@ -57,9 +56,13 @@ public String description() {

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (this == obj) {
return true;
}

if (obj == null || getClass() != obj.getClass()) return false;
if (obj == null || getClass() != obj.getClass()) {
return false;
}

final EnterpriseMetadataSummary that = (EnterpriseMetadataSummary) obj;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public static PluginMetadataSummary create(
@JsonProperty("version") String version,
@JsonProperty("description") String description
) {
return new AutoValue_PluginMetadataSummary(uniqueId, name, author, url, Version.valueOf(version), description);
return new AutoValue_PluginMetadataSummary(uniqueId, name, author, url, Version.parse(version), description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class MongoDBVersionCheck {
private static final Logger LOG = LoggerFactory.getLogger(MongoDBVersionCheck.class);
private static final Version MINIMUM_MONGODB_VERSION = Version.forIntegers(5, 0);
private static final Version MINIMUM_MONGODB_VERSION = Version.of(5, 0);

public static Version getVersion(MongoClient mongoClient) {
final MongoDatabase adminDb = mongoClient.getDatabase("admin");
Expand All @@ -56,7 +56,7 @@ public static Version getVersion(MongoClient mongoClient) {
final int majorVersion = (int) versionArray.get(0);
final int minorVersion = (int) versionArray.get(1);
final int patchVersion = (int) versionArray.get(2);
return Version.forIntegers(majorVersion, minorVersion, patchVersion);
return Version.of(majorVersion, minorVersion, patchVersion);
} else {
LOG.warn("Couldn't retrieve MongoDB buildInfo");
return null;
Expand All @@ -68,7 +68,7 @@ public static Version getVersion(MongoClient mongoClient) {
}

public static void assertCompatibleVersion(Version mongoVersion) {
if (mongoVersion != null && mongoVersion.lessThan(MINIMUM_MONGODB_VERSION)) {
if (mongoVersion != null && mongoVersion.isLowerThan(MINIMUM_MONGODB_VERSION)) {
throw new PreflightCheckException(
StringUtils.f("You're running MongoDB %s but Graylog requires at least MongoDB %s. Please upgrade.",
mongoVersion, MINIMUM_MONGODB_VERSION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface NodeAdapter {

default Version parseVersion(String version) {
try {
return Version.valueOf(version);
return Version.parse(version);
} catch (Exception e) {
throw new ElasticsearchException("Unable to parse Elasticsearch version: " + version, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ public VersionDeserializer() {
public Version deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
switch (p.currentTokenId()) {
case JsonTokenId.ID_STRING:
final String str = p.getText().trim();
return Version.valueOf(str);
return Version.parse(p.getText().trim());
case JsonTokenId.ID_NUMBER_INT:
return Version.forIntegers(p.getIntValue());
return Version.of(p.getIntValue());
}
throw ctxt.wrongTokenException(p, handledType(), JsonToken.VALUE_STRING, "expected String or Number");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.graylog2.periodical;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.graylog2.configuration.IndexerHosts;
import org.graylog2.notifications.Notification;
import org.graylog2.notifications.NotificationService;
Expand All @@ -27,10 +29,6 @@
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import jakarta.inject.Inject;
import jakarta.inject.Named;

import java.net.URI;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -122,6 +120,6 @@ public void doRun() {
}

private boolean compatible(SearchVersion initialElasticsearchMajorVersion, SearchVersion version) {
return initialElasticsearchMajorVersion.version().getMajorVersion() == version.version().getMajorVersion();
return initialElasticsearchMajorVersion.version().majorVersion() == version.version().majorVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package org.graylog2.periodical;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.zafarkhaja.semver.Version;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.net.HttpHeaders;
import jakarta.inject.Inject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand All @@ -34,8 +36,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.inject.Inject;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -114,10 +114,10 @@ public void doRun() {
final VersionCheckResponse versionCheckResponse = objectMapper.readValue(response.body().byteStream(), VersionCheckResponse.class);

final VersionResponse version = versionCheckResponse.version;
final com.github.zafarkhaja.semver.Version reportedVersion = com.github.zafarkhaja.semver.Version.forIntegers(version.major, version.minor, version.patch);
final Version reportedVersion = Version.of(version.major, version.minor, version.patch);

LOG.debug("Version check reports current version: " + versionCheckResponse);
if (reportedVersion.greaterThan(ServerVersion.VERSION.getVersion())) {
if (reportedVersion.isHigherThan(ServerVersion.VERSION.getVersion())) {
LOG.debug("Reported version is higher than ours ({}). Writing notification.", ServerVersion.VERSION);

Notification notification = notificationService.buildNow()
Expand Down
91 changes: 27 additions & 64 deletions graylog2-server/src/main/java/org/graylog2/plugin/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,6 @@
public class Version implements Comparable<Version> {
private static final Logger LOG = LoggerFactory.getLogger(Version.class);

/**
* @deprecated Use {@link #getVersion()}
*/
@Deprecated
public final int major;
/**
* @deprecated Use {@link #getVersion()}
*/
@Deprecated
public final int minor;
/**
* @deprecated Use {@link #getVersion()}
*/
@Deprecated
public final int patch;
/**
* @deprecated Use {@link #getVersion()}
*/
@Deprecated
public final String additional;
/**
* @deprecated Use {@link #getVersion()}
*/
@Deprecated
public final String abbrevCommitSha;

private final com.github.zafarkhaja.semver.Version version;

/**
Expand Down Expand Up @@ -91,14 +65,6 @@ public Version(int major, int minor, int patch, String additional, String abbrev

public Version(com.github.zafarkhaja.semver.Version version) {
this.version = requireNonNull(version);

// Deprecated
this.major = version.getMajorVersion();
this.minor = version.getMinorVersion();
this.patch = version.getPatchVersion();
this.additional = version.getPreReleaseVersion();
this.abbrevCommitSha = version.getBuildMetadata();

}

/**
Expand All @@ -110,7 +76,7 @@ public Version(com.github.zafarkhaja.semver.Version version) {
* @return The {@link Version} instance built from the given parameters.
*/
public static Version from(int major, int minor, int patch) {
return new Version(com.github.zafarkhaja.semver.Version.forIntegers(major, minor, patch));
return new Version(com.github.zafarkhaja.semver.Version.of(major, minor, patch));
}

/**
Expand All @@ -133,22 +99,23 @@ public static Version from(int major, int minor, int patch, String preRelease) {
* @param minor The minor version component.
* @param patch The patch version component.
* @param preRelease The pre-release version component.
* @param buildMetadata Additional build metadata (e. g. the Git commit SHA).
* @param buildMetadata Additional build metadata (e.g. the Git commit SHA).
* @return The {@link Version} instance built from the given parameters.
*/
public static Version from(int major, int minor, int patch, String preRelease, String buildMetadata) {
public static Version from(long major, long minor, long patch, String preRelease, String buildMetadata) {
return new Version(buildSemVer(major, minor, patch, preRelease, buildMetadata));
}

private static com.github.zafarkhaja.semver.Version buildSemVer(int major, int minor, int patch, String preRelease, String buildMetadata) {
com.github.zafarkhaja.semver.Version version = com.github.zafarkhaja.semver.Version.forIntegers(major, minor, patch);
private static com.github.zafarkhaja.semver.Version buildSemVer(long major, long minor, long patch, String preRelease, String buildMetadata) {
final com.github.zafarkhaja.semver.Version.Builder builder = new com.github.zafarkhaja.semver.Version.Builder()
.setVersionCore(major, minor, patch);
if (!isNullOrEmpty(preRelease)) {
version = version.setPreReleaseVersion(preRelease);
builder.setPreReleaseVersion(preRelease);
}
if (!isNullOrEmpty(buildMetadata)) {
version = version.setBuildMetadata(buildMetadata);
builder.setBuildMetadata(buildMetadata);
}
return version;
return builder.build();
}

/**
Expand Down Expand Up @@ -231,12 +198,12 @@ public static Version fromClasspathProperties(@Nonnull Class<?> clazz, String pa
final Properties versionProperties = new Properties();
versionProperties.load(resource.openStream());

final com.github.zafarkhaja.semver.Version version = com.github.zafarkhaja.semver.Version.valueOf(versionProperties.getProperty(propertyName));
final int major = version.getMajorVersion();
final int minor = version.getMinorVersion();
final int patch = version.getPatchVersion();
final String qualifier = version.getPreReleaseVersion();
final String buildMetadata = version.getBuildMetadata();
final com.github.zafarkhaja.semver.Version version = com.github.zafarkhaja.semver.Version.parse(versionProperties.getProperty(propertyName));
final long major = version.majorVersion();
final long minor = version.minorVersion();
final long patch = version.patchVersion();
final String qualifier = version.preReleaseVersion().orElse("");
final String buildMetadata = version.buildMetadata().orElse("");

// If the version property already contains build metadata we want to use that instead of replacing it
// with the Git commit ID
Expand Down Expand Up @@ -287,26 +254,18 @@ public String toString() {
}

/**
* Check if this version is higher than the passed other version. Only taking major and minor version number in account.
*
* @param other {@link Version} to compare
*/
@Deprecated
public boolean greaterMinor(Version other) {
return other.major < this.major || other.major == this.major && other.minor < this.minor;
}

/**
* @see com.github.zafarkhaja.semver.Version#greaterThanOrEqualTo(com.github.zafarkhaja.semver.Version)
* @see com.github.zafarkhaja.semver.Version#isHigherThanOrEquivalentTo(com.github.zafarkhaja.semver.Version)
*/
public boolean sameOrHigher(Version other) {
if (isNullOrEmpty(version.getPreReleaseVersion())) {
return version.greaterThanOrEqualTo(other.getVersion());
if (isNullOrEmpty(version.preReleaseVersion().orElse(""))) {
return version.isHigherThanOrEquivalentTo(other.getVersion());
} else {
// If this is a pre-release version, use the major.minor.patch version for comparison with the other.
// This allows plugins to require a server version of 2.1.0 and it still gets loaded on a 2.1.0-beta.2 server.
// See: https://github.com/Graylog2/graylog2-server/issues/2462
return com.github.zafarkhaja.semver.Version.valueOf(version.getNormalVersion()).greaterThanOrEqualTo(other.getVersion());
String version1 = version.toStableVersion().toString();
com.github.zafarkhaja.semver.Version version2 = com.github.zafarkhaja.semver.Version.parse(version1);
return version2.isHigherThanOrEquivalentTo(other.getVersion());
}
}

Expand All @@ -315,8 +274,12 @@ public boolean sameOrHigher(Version other) {
*/
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

final Version that = (Version) o;
return version.equals(that.getVersion());
Expand Down
Loading

0 comments on commit be90077

Please sign in to comment.