Skip to content

Commit

Permalink
Merge branch 'lib-toml' of https://github.com/cwperks/OpenSearch into…
Browse files Browse the repository at this point in the history
… lib-toml
  • Loading branch information
cwperks committed Oct 16, 2024
2 parents 11b496a + 06840e2 commit 8cc8f8b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
15 changes: 12 additions & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

import org.gradle.internal.jvm.Jvm
import org.gradle.util.GradleVersion
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;

plugins {
id 'java-gradle-plugin'
Expand Down Expand Up @@ -287,7 +293,8 @@ if (project != rootProject) {
}
}

// Define this here because we need it early.
// Define this here because we need it early. This reads in a toml file, extracts the section with the header
// [versions] and converts to a Java Properties object
class VersionPropertiesLoader {
static Properties loadBuildSrcVersion(File input) throws IOException {
Properties props = new Properties();
Expand All @@ -300,8 +307,10 @@ class VersionPropertiesLoader {
is.close()
}
props.forEach((key, value) -> {
String newValue = value.toString().replace("\"", "")
props.setProperty(key.toString(), newValue)
if (value != null && value instanceof String) {
String newValue = value.toString().replace("\"", "")
props.setProperty(key.toString(), newValue)
}
});
loadBuildSrcVersion(props, System.getProperties())
return props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -136,6 +138,37 @@ private static Properties getVersionProperties() {
return props;
}

private static void loadBuildSrcVersion(Properties loadedProps, Properties systemProperties) {
String opensearch = loadedProps.getProperty("opensearch");
if (opensearch == null) {
throw new IllegalStateException("OpenSearch version is missing from properties.");
}
if (opensearch.matches("[0-9]+\\.[0-9]+\\.[0-9]+") == false) {
throw new IllegalStateException("Expected opensearch version to be numbers only of the form X.Y.Z but it was: " + opensearch);
}
String qualifier = systemProperties.getProperty("build.version_qualifier", "");
if (qualifier.isEmpty() == false) {
if (qualifier.matches("(alpha|beta|rc)\\d+") == false) {
throw new IllegalStateException("Invalid qualifier: " + qualifier);
}
opensearch += "-" + qualifier;
}
final String buildSnapshotSystemProperty = systemProperties.getProperty("build.snapshot", "true");
switch (buildSnapshotSystemProperty) {
case "true":
opensearch += "-SNAPSHOT";
break;
case "false":
// do nothing
break;
default:
throw new IllegalArgumentException(
"build.snapshot was set to [" + buildSnapshotSystemProperty + "] but can only be unset or [true|false]"
);
}
loadedProps.put("opensearch", opensearch);
}

public static boolean isOpenSearchSnapshot() {
return opensearch.endsWith("-SNAPSHOT");
}
Expand Down

0 comments on commit 8cc8f8b

Please sign in to comment.