Skip to content

Commit

Permalink
Revert "Version info from property file (#802)"
Browse files Browse the repository at this point in the history
This reverts commit 3ef2887.
  • Loading branch information
l-trotta committed Jul 4, 2024
1 parent 920a156 commit 12b7ab5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 50 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

allprojects {
group = "co.elastic.clients"
version = (File(project.rootDir, "config/version.txt").readText().trim() + "-SNAPSHOT")
// Release manager provides a $VERSION. If not present, it's a local or CI snapshot build.
version = System.getenv("VERSION") ?:
(File(project.rootDir, "config/version.txt").readText().trim() + "-SNAPSHOT")

repositories {
maven {
Expand Down
3 changes: 2 additions & 1 deletion java-client-serverless/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ checkstyle {
toolVersion = "10.16.0"
}

version = (File(project.rootDir, "config/version-serverless.txt").readText().trim() + "-SNAPSHOT")
// GitHub Maven repo doesn't like 1.0.0+20231031-SNAPSHOT
version = "1.0.0-20231031-SNAPSHOT"

signing {
sign(publishing.publications)
Expand Down

This file was deleted.

41 changes: 14 additions & 27 deletions java-client/src/main/java/co/elastic/clients/transport/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@

package co.elastic.clients.transport;

import co.elastic.clients.ApiClient;

import javax.annotation.Nullable;
import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;

/**
* This class represents a SemVer version, with an optional patch revision.
Expand All @@ -49,20 +45,20 @@ public static Version parse(String version) {
int hyphen = version.indexOf('-');
if (hyphen >= 0) {
// Has prerelease. May be followed buy build information
prerelease = version.substring(hyphen + 1);
prerelease = version.substring(hyphen+1);
version = version.substring(0, hyphen);

int plus = prerelease.indexOf('+');
if (plus >= 0) {
build = prerelease.substring(0, plus + 1);
build = prerelease.substring(0, plus+1);
prerelease = prerelease.substring(0, plus);
}
}

int plus = version.indexOf('+');
if (plus >= 0) {
// Has build information
build = version.substring(0, plus + 1);
build = version.substring(0, plus+1);
version = version.substring(0, plus);
}

Expand All @@ -72,7 +68,8 @@ public static Version parse(String version) {
int minor = (bits.length >= 2) ? Integer.parseInt(bits[1]) : 0;
int maintenance = (bits.length >= 3) ? Integer.parseInt(bits[2]) : -1;
return new Version(major, minor, maintenance, prerelease, build);
} catch (NumberFormatException ex) {
}
catch(NumberFormatException ex) {
return null;
}
}
Expand All @@ -81,8 +78,7 @@ public Version(int major, int minor, int maintenance, boolean isPreRelease) {
this(major, minor, maintenance, isPreRelease ? "p" : null, null);
}

public Version(int major, int minor, int maintenance, @Nullable String prerelease,
@Nullable String build) {
public Version(int major, int minor, int maintenance, @Nullable String prerelease, @Nullable String build) {
this.major = major;
this.minor = minor;
this.maintenance = maintenance;
Expand Down Expand Up @@ -112,10 +108,10 @@ public boolean equals(Object other) {
if (!(other instanceof Version)) return false;
Version that = (Version) other;
return (major == that.major &&
minor == that.minor &&
maintenance == that.maintenance &&
Objects.equals(prerelease, that.prerelease) &&
Objects.equals(build, that.build));
minor == that.minor &&
maintenance == that.maintenance &&
Objects.equals(prerelease, that.prerelease) &&
Objects.equals(build, that.build));
}

@Override
Expand Down Expand Up @@ -150,19 +146,10 @@ public String toString() {

static {
Version version = null;
InputStream in = ApiClient.class.getResourceAsStream("version.properties");
if (in != null) {
Properties properties = new Properties();
try {
properties.load(in);
String versionStr = properties.getProperty("version");
if (versionStr != null) {
version = Version.parse(versionStr);
}
} catch (Exception e) {
// Failed to parse version from file, trying from VersionInfo
version = Version.parse(VersionInfo.VERSION);
}
try {
version = Version.parse(VersionInfo.VERSION);
} catch (Exception e) {
// Failed to parse version
}
VERSION = version;
}
Expand Down

0 comments on commit 12b7ab5

Please sign in to comment.