Skip to content

Commit e0cf064

Browse files
opensearch-trigger-bot[bot]github-actions[bot]nknizeXtansia
authored
[Bug] Fix Build Metadata (#7817) (#7818)
Refactoring Build to core library broke the build metadata. Test coverage was insufficient to catch this bug. This commit fixes the build metadata and improves test coverage such that any unexpected metadata changes are caught. (cherry picked from commit 287ac90) Signed-off-by: Nicholas Walter Knize <nknize@apache.org> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Walter Knize <nknize@apache.org> Co-authored-by: Thomas Farr <tsfarr@amazon.com>
1 parent a0e32eb commit e0cf064

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

libs/core/src/main/java/org/opensearch/Build.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ public static Type fromDisplayName(final String displayName, final boolean stric
114114
// these are parsed at startup, and we require that we are able to recognize the values passed in by the startup scripts
115115
type = Type.fromDisplayName(System.getProperty("opensearch.distribution.type", "unknown"), true);
116116

117-
final String opensearchPrefix = distribution + "-" + Version.CURRENT;
117+
final String opensearchPrefix = distribution;
118118
final URL url = getOpenSearchCodeSourceLocation();
119119
final String urlStr = url == null ? "" : url.toString();
120120
if (urlStr.startsWith("file:/")
121-
&& (urlStr.endsWith(opensearchPrefix + ".jar")
122-
|| urlStr.matches("(.*)" + opensearchPrefix + "(-)?((alpha|beta|rc)[0-9]+)?(-SNAPSHOT)?.jar"))) {
121+
&& (urlStr.endsWith(opensearchPrefix + "-" + Version.CURRENT + ".jar")
122+
|| urlStr.matches(
123+
"(.*)" + opensearchPrefix + "(-)?(.*?)" + Version.CURRENT + "(-)?((alpha|beta|rc)[0-9]+)?(-SNAPSHOT)?.jar"
124+
))) {
123125
try (JarInputStream jar = new JarInputStream(FileSystemUtils.openFileURLStream(url))) {
124126
Manifest manifest = jar.getManifest();
125127
hash = manifest.getMainAttributes().getValue("Change");

server/src/test/java/org/opensearch/BuildTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ public void testJarMetadata() throws IOException {
6060
URL url = Build.getOpenSearchCodeSourceLocation();
6161
// throws exception if does not exist, or we cannot access it
6262
try (InputStream ignored = FileSystemUtils.openFileURLStream(url)) {}
63-
// these should never be null
63+
// these should never be null or "unknown"
6464
assertNotNull(Build.CURRENT.date());
65+
assertNotEquals(Build.CURRENT.date(), "unknown");
6566
assertNotNull(Build.CURRENT.hash());
67+
assertNotEquals(Build.CURRENT.hash(), "unknown");
6668
}
6769

6870
public void testIsProduction() {

0 commit comments

Comments
 (0)