Skip to content

Commit

Permalink
SpotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Oct 10, 2024
1 parent 92dd2c4 commit dacf648
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 55 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -753,8 +753,10 @@ def generateVersionProperties = tasks.register("generateVersionProperties", Writ
}
}

processResources {
from(generateVersionProperties)
if (project != rootProject) {
processResources {
from(generateVersionProperties)
}
}

allprojects { project ->
Expand Down
6 changes: 5 additions & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 0 additions & 24 deletions buildSrc/generateVersionProperties.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -144,31 +141,15 @@ 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"));
} catch (IOException e) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit dacf648

Please sign in to comment.