Skip to content

Commit

Permalink
Adjust with PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Oct 24, 2023
1 parent edcbc0b commit d84c7c6
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions server/src/main/java/org/elasticsearch/plugins/PluginsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,19 @@ public static List<Path> findPluginDirs(final Path rootPath) throws IOException
* Verify the given plugin is compatible with the current Elasticsearch installation.
*/
public static void verifyCompatibility(PluginDescriptor info) {
Matcher buildVersionMatcher = SemanticVersion.semanticPattern.matcher(Build.current().version());
final String currentVersion = Build.current().version();
Matcher buildVersionMatcher = SemanticVersion.semanticPattern.matcher(currentVersion);
// If we're not on a semantic version, assume plugins are compatible
if (buildVersionMatcher.matches()) {
SemanticVersion currentElasticsearchVersion;
SemanticVersion currentElasticsearchSemanticVersion;
try {
currentElasticsearchVersion = new SemanticVersion(
currentElasticsearchSemanticVersion = new SemanticVersion(
Integer.parseInt(buildVersionMatcher.group(1)),
Integer.parseInt(buildVersionMatcher.group(2)),
Integer.parseInt(buildVersionMatcher.group(3))
);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Couldn't parse integers from build version [" + Build.current().version() + "]", e);
throw new IllegalArgumentException("Couldn't parse integers from build version [" + currentVersion + "]", e);
}
if (info.isStable()) {
Matcher pluginEsVersionMatcher = SemanticVersion.semanticPattern.matcher(info.getElasticsearchVersion());
Expand All @@ -99,9 +100,9 @@ public static void verifyCompatibility(PluginDescriptor info) {
"Expected semantic version for plugin [" + info.getName() + "] but was [" + info.getElasticsearchVersion() + "]"
);
}
SemanticVersion pluginElasticsearchVersion;
SemanticVersion pluginElasticsearchSemanticVersion;
try {
pluginElasticsearchVersion = new SemanticVersion(
pluginElasticsearchSemanticVersion = new SemanticVersion(
Integer.parseInt(pluginEsVersionMatcher.group(1)),
Integer.parseInt(pluginEsVersionMatcher.group(2)),
Integer.parseInt(pluginEsVersionMatcher.group(3))
Expand All @@ -114,38 +115,38 @@ public static void verifyCompatibility(PluginDescriptor info) {
}

// case: Major version mismatch
if (pluginElasticsearchVersion.major != currentElasticsearchVersion.major) {
if (pluginElasticsearchSemanticVersion.major != currentElasticsearchSemanticVersion.major) {
throw new IllegalArgumentException(
"Stable Plugin ["
+ info.getName()
+ "] was built for Elasticsearch major version "
+ pluginElasticsearchVersion.major
+ pluginElasticsearchSemanticVersion.major
+ " but version "
+ Build.current().version()
+ currentVersion
+ " is running"
);
}

// case: stable plugin from the future
if (pluginElasticsearchVersion.after(currentElasticsearchVersion)) {
if (pluginElasticsearchSemanticVersion.after(currentElasticsearchSemanticVersion)) {
throw new IllegalArgumentException(
"Stable Plugin ["
+ info.getName()
+ "] was built for Elasticsearch version "
+ info.getElasticsearchVersion()
+ " but earlier version "
+ Build.current().version()
+ currentVersion
+ " is running"
);
}
} else if (info.getElasticsearchVersion().equals(currentElasticsearchVersion.toString()) == false) {
} else if (info.getElasticsearchVersion().equals(currentVersion) == false) {
throw new IllegalArgumentException(
"Plugin ["
+ info.getName()
+ "] was built for Elasticsearch version "
+ info.getElasticsearchVersion()
+ " but version "
+ Build.current().version()
+ currentVersion
+ " is running"
);
}
Expand Down

0 comments on commit d84c7c6

Please sign in to comment.