Skip to content

Commit

Permalink
[Bug] Fix Build Metadata (opensearch-project#7817)
Browse files Browse the repository at this point in the history
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 <nknize@apache.org>
Co-authored-by: Nicholas Walter Knize <nknize@apache.org>
Co-authored-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
3 people authored and austintlee committed Jun 2, 2023
1 parent a5317a1 commit 9e8ffd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions libs/core/src/main/java/org/opensearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ public static Type fromDisplayName(final String displayName, final boolean stric
// these are parsed at startup, and we require that we are able to recognize the values passed in by the startup scripts
type = Type.fromDisplayName(System.getProperty("opensearch.distribution.type", "unknown"), true);

final String opensearchPrefix = distribution + "-" + Version.CURRENT;
final String opensearchPrefix = distribution;
final URL url = getOpenSearchCodeSourceLocation();
final String urlStr = url == null ? "" : url.toString();
if (urlStr.startsWith("file:/")
&& (urlStr.endsWith(opensearchPrefix + ".jar")
|| urlStr.matches("(.*)" + opensearchPrefix + "(-)?((alpha|beta|rc)[0-9]+)?(-SNAPSHOT)?.jar"))) {
&& (urlStr.endsWith(opensearchPrefix + "-" + Version.CURRENT + ".jar")
|| urlStr.matches(
"(.*)" + opensearchPrefix + "(-)?(.*?)" + Version.CURRENT + "(-)?((alpha|beta|rc)[0-9]+)?(-SNAPSHOT)?.jar"
))) {
try (JarInputStream jar = new JarInputStream(FileSystemUtils.openFileURLStream(url))) {
Manifest manifest = jar.getManifest();
hash = manifest.getMainAttributes().getValue("Change");
Expand Down
4 changes: 3 additions & 1 deletion server/src/test/java/org/opensearch/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public void testJarMetadata() throws IOException {
URL url = Build.getOpenSearchCodeSourceLocation();
// throws exception if does not exist, or we cannot access it
try (InputStream ignored = FileSystemUtils.openFileURLStream(url)) {}
// these should never be null
// these should never be null or "unknown"
assertNotNull(Build.CURRENT.date());
assertNotEquals(Build.CURRENT.date(), "unknown");
assertNotNull(Build.CURRENT.hash());
assertNotEquals(Build.CURRENT.hash(), "unknown");
}

public void testIsProduction() {
Expand Down

0 comments on commit 9e8ffd2

Please sign in to comment.