diff --git a/build.gradle b/build.gradle index 9f851307651f1..d1e13e739ee95 100644 --- a/build.gradle +++ b/build.gradle @@ -735,12 +735,12 @@ tasks.register('checkCompatibility', CheckCompatibilityTask) { } def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) { - destinationFile = file("buildSrc/${buildDir}/version.properties") + destinationFile = file("${buildDir}/version.properties") comment = 'Generated version properties' // properties(props) def libsTomlFile = file("gradle/libs.versions.toml") - def propertiesFile = file("buildSrc/${buildDir}/versions.properties") + def propertiesFile = file("${buildDir}/versions.properties") doLast { def properties = org.opensearch.gradle.VersionPropertiesGenerator.generateVersionProperties(libsTomlFile) @@ -753,8 +753,10 @@ def generateVersionProperties = tasks.register("generateVersionProperties", Writ } } -processResources { - from(generateVersionProperties) +if (project != rootProject) { + processResources { + from(generateVersionProperties) + } } allprojects { project -> diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 5a5502f7ce857..0f62b0124d3ed 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -57,7 +57,7 @@ if (project == rootProject) { // we update the version property to reflect if we are building a snapshot or a release build // we write this back out below to load it in the Build.java which will be shown in rest main action // to indicate this being a snapshot build or a release build. -Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('version.properties')) +Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('../gradle/libs.versions.toml')) version = props.getProperty("opensearch") //def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) { @@ -311,6 +311,10 @@ class VersionPropertiesLoader { } finally { is.close() } + props.forEach((key, value) -> { + String newValue = value.toString().replace("\"", "") + props.setProperty(key.toString(), newValue) + }); loadBuildSrcVersion(props, System.getProperties()) return props } diff --git a/buildSrc/generateVersionProperties.gradle b/buildSrc/generateVersionProperties.gradle deleted file mode 100644 index 0335937825938..0000000000000 --- a/buildSrc/generateVersionProperties.gradle +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -import org.tomlj.Toml - -task generateVersionProperties { - def tomlFile = file("gradle/libs.versions.toml") - def propertiesFile = file("build/generated/versions.properties") - - doLast { - def toml = Toml.parse(tomlFile.newReader()) - propertiesFile.withWriter('UTF-8') { writer -> - toml.getTable("versions").keySet().each { key -> - def version = toml.getString("versions.${key}") - writer.write("${key}=${version}\n") - } - } - } -} diff --git a/buildSrc/src/main/java/org/opensearch/gradle/VersionProperties.java b/buildSrc/src/main/java/org/opensearch/gradle/VersionProperties.java index dee195062a9a0..583f00ba4a766 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/VersionProperties.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/VersionProperties.java @@ -32,20 +32,17 @@ package org.opensearch.gradle; import org.apache.commons.lang3.StringUtils; -import org.tomlj.Toml; -import org.tomlj.TomlParseResult; -import org.tomlj.TomlTable; -import java.io.File; -import java.io.FileReader; 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; +import org.tomlj.Toml; +import org.tomlj.TomlParseResult; +import org.tomlj.TomlTable; + /** * Accessor for shared dependency versions used by opensearch, namely the opensearch and lucene versions. */ @@ -144,16 +141,6 @@ private static void flattenToml(TomlTable tomlTable, Properties properties, Stri } private static Properties getVersionProperties() { -// Properties props = new Properties(); -// try (InputStream propsStream = VersionProperties.class.getResourceAsStream("/version.properties")) { -// if (propsStream == null) { -// throw new IllegalStateException("/version.properties resource missing"); -// } -// props.load(propsStream); -// } catch (IOException e) { -// throw new IllegalStateException("Failed to load version properties", e); -// } - TomlParseResult toml = null; try { toml = Toml.parse(Path.of("gradle/libs.versions.toml")); @@ -161,14 +148,8 @@ private static Properties getVersionProperties() { throw new RuntimeException(e); } - // Convert TOML to Properties Properties properties = new Properties(); flattenToml(toml, properties, ""); - - System.out.println("properties: " + properties); - - // Now you can use properties as needed - properties.forEach((key, value) -> System.out.println(key + ": " + value)); return properties; } diff --git a/buildSrc/src/main/java/org/opensearch/gradle/VersionPropertiesGenerator.java b/buildSrc/src/main/java/org/opensearch/gradle/VersionPropertiesGenerator.java index 010627702f87b..5dd1ba913c8c1 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/VersionPropertiesGenerator.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/VersionPropertiesGenerator.java @@ -31,13 +31,13 @@ package org.opensearch.gradle; -import org.tomlj.Toml; -import org.tomlj.TomlParseResult; - import java.io.File; import java.io.FileReader; import java.util.Properties; +import org.tomlj.Toml; +import org.tomlj.TomlParseResult; + /** * Generator for shared dependency versions used by opensearch, namely the opensearch and lucene versions. */