Skip to content

Commit bf0820f

Browse files
Support range semver for dependencies in plugin-descriptor.properties (#19939)
* DependenciesRangeSemver Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com> * spotlessApply Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com> * testCase Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com> * ChangeLog Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com> * correct changeLog Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com> --------- Signed-off-by: Aparajita Pandey <aparajita31pandey@gmail.com>
1 parent 022d594 commit bf0820f

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4646
- Pass registry of headers from ActionPlugin.getRestHeaders to ActionPlugin.getRestHandlerWrapper ([#19875](https://github.com/opensearch-project/OpenSearch/pull/19875))
4747
- Refactor the Condition.Stats and DirectoryFileTransferTracker.Stats class to use the Builder pattern instead of constructors ([#19862](https://github.com/opensearch-project/OpenSearch/pull/19862))
4848
- Refactor the RemoteTranslogTransferTracker.Stats and RemoteSegmentTransferTracker.Stats class to use the Builder pattern instead of constructors ([#19837](https://github.com/opensearch-project/OpenSearch/pull/19837))
49+
- Add RangeSemver for `dependencies` in `plugin-descriptor.properties` ([#19939](https://github.com/opensearch-project/OpenSearch/pull/19939))
4950

5051
### Fixed
5152
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))

libs/core/src/main/java/org/opensearch/semver/SemverRange.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@PublicApi(since = "2.13.0")
4444
public class SemverRange implements ToXContentFragment {
4545

46-
private static final Pattern RANGE_PATTERN = Pattern.compile("([\\[\\(])([\\d.]+)\\s*,\\s*([\\d.]+)([\\]\\)])");
46+
public static final Pattern RANGE_PATTERN = Pattern.compile("([\\[\\(])([\\d.]+)\\s*,\\s*([\\d.]+)([\\]\\)])");
4747

4848
private final Version rangeVersion;
4949
private final RangeOperator rangeOperator;

server/src/main/java/org/opensearch/plugins/PluginInfo.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
import java.util.function.Function;
6464
import java.util.stream.Collectors;
6565

66+
import static org.opensearch.semver.SemverRange.RANGE_PATTERN;
67+
6668
/**
6769
* An in-memory representation of the plugin descriptor.
6870
*
@@ -322,13 +324,17 @@ public static PluginInfo readFromProperties(final Path path) throws IOException
322324
if (dependenciesMap.keySet().stream().noneMatch(s -> s.equals("opensearch"))) {
323325
throw new IllegalArgumentException("Only opensearch is allowed to be specified as a plugin dependency: " + dependenciesMap);
324326
}
325-
String[] ranges = dependenciesMap.get("opensearch").split(",");
326-
if (ranges.length != 1) {
327+
String opensearchDependencyVersion = dependenciesMap.get("opensearch");
328+
String[] ranges = opensearchDependencyVersion.split(",");
329+
String opensearchVersion = ranges[0];
330+
if (RANGE_PATTERN.matcher(opensearchDependencyVersion).matches()) {
331+
opensearchVersion = opensearchDependencyVersion;
332+
} else if (ranges.length != 1) {
327333
throw new IllegalArgumentException(
328-
"Exactly one range is allowed to be specified in dependencies for the plugin [\" + name + \"]"
334+
"Exactly one range is allowed to be specified in dependencies for the plugin [" + name + "]"
329335
);
330336
}
331-
opensearchVersionRanges.add(SemverRange.fromString(ranges[0].trim()));
337+
opensearchVersionRanges.add(SemverRange.fromString(opensearchVersion.trim()));
332338
}
333339

334340
final String javaVersionString = propsMap.remove("java.version");

server/src/test/java/org/opensearch/plugins/PluginInfoTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,28 @@ public void testMultipleDependencies() throws Exception {
482482
assertThat(e.getMessage(), containsString("Exactly one dependency is allowed to be specified in plugin descriptor properties"));
483483
}
484484

485+
public void testRangeSemverOnDependencies() throws Exception {
486+
String opensearchRange = "[" + Version.V_2_0_0.toString() + "," + Version.V_3_0_0.toString() + ")";
487+
Path pluginDir = createTempDir().resolve("fake-plugin");
488+
PluginTestUtil.writePluginProperties(
489+
pluginDir,
490+
"description",
491+
"fake desc",
492+
"name",
493+
"my_plugin",
494+
"version",
495+
"1.0",
496+
"dependencies",
497+
"{opensearch:\"" + opensearchRange + "\" }",
498+
"java.version",
499+
System.getProperty("java.specification.version"),
500+
"classname",
501+
"FakePlugin"
502+
);
503+
PluginInfo pluginInfo = PluginInfo.readFromProperties(pluginDir);
504+
assertEquals(SemverRange.fromString(opensearchRange).toString(), pluginInfo.getOpenSearchVersionRangesString());
505+
}
506+
485507
public void testNonOpenSearchDependency() throws Exception {
486508
Path pluginDir = createTempDir().resolve("fake-plugin");
487509
PluginTestUtil.writePluginProperties(

0 commit comments

Comments
 (0)