Skip to content

Commit 287ac90

Browse files
Xtansianknize
andauthored
[Bug] Fix Build Metadata (opensearch-project#7817)
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. Signed-off-by: Nicholas Walter Knize <[email protected]> Co-authored-by: Nicholas Walter Knize <[email protected]> Co-authored-by: Thomas Farr <[email protected]>
1 parent 777924f commit 287ac90

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

+5-3
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

+3-1
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)