Skip to content

Commit

Permalink
Update plugin compatibility check semantics for plugin version 2.0
Browse files Browse the repository at this point in the history
rundeckCompatibilityVersion and Rundeck-Plugin-Compatibility-Version now indicate the lowest version.  previously the major version number was strict, and now implies greater than or equal.
  • Loading branch information
gschueler committed Feb 11, 2022
1 parent 05be1be commit 6790e41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ public static PluginValidation.State validateTargetHostCompatibility(
public static PluginValidation.State validateRundeckCompatibility(
final List<String> errors,
final String rundeckCompatibilityVersion
) {
return validateRundeckCompatibility(errors, VersionConstants.VERSION, rundeckCompatibilityVersion);
}

public static PluginValidation.State validateRundeckCompatibility(
final List<String> errors,
final String rundeckVersion,
final String rundeckCompatibilityVersion
) {
if(rundeckCompatibilityVersion == null) {
errors.add("rundeckCompatibilityVersion cannot be null in metadata");
return PluginValidation.State.INVALID;
}
VersionCompare rundeckVer = VersionCompare.forString(VersionConstants.VERSION);
VersionCompare rundeckVer = VersionCompare.forString(rundeckVersion);
VersionCompare compatVer = VersionCompare.forString(rundeckCompatibilityVersion);
if(!compatVer.majString.equals(rundeckVer.majString)) {
String majString = compatVer.majString+"+";
if (!checkVer(rundeckVer.maj, majString)) {
errors.add(INCOMPATIBLE_PLUGIN_VER_MSG);
return PluginValidation.State.INCOMPATIBLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.dtolabs.rundeck.core.plugins

import com.dtolabs.rundeck.core.VersionConstants
import spock.lang.Specification
import spock.lang.Unroll

import java.lang.reflect.Field
import java.lang.reflect.Modifier
Expand Down Expand Up @@ -54,32 +55,30 @@ class PluginMetadataValidatorTest extends Specification {

}

@Unroll
def "ValidateRundeckCompatibility"() {
when:
def errors = []
Field field = VersionConstants.getDeclaredField("VERSION")
field.setAccessible(true);

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null,rundeckVersion)
PluginMetadataValidator.validateRundeckCompatibility(errors, compatVersion)
PluginMetadataValidator.validateRundeckCompatibility(errors, rundeckVersion, compatVersion)
String validation = errors.isEmpty() ? "compatible" : "incompatible"

then:
validation == expected

where:
rundeckVersion | compatVersion | expected
"3.0.0" | null | "incompatible"
"3.0.0" | "2.0" | "incompatible"
"3.0.0" | null | "incompatible"
"3.0.0" | "2.0" | "compatible"
"3.0.0" | "2.11.x" | "incompatible"
"2.11.0" | "3.0.x" | "incompatible"
"3.1.0" | "3.0.0+" | "compatible"
"3.0.5" | "3.1.0+" | "incompatible"
"3.0.0" | "3.0.5+" | "incompatible"
"4.0.0" | "3.0+" | "incompatible"
"4.0.0" | "3.0+" | "compatible"
"4.0.0" | "3.0" | "compatible"
"5.0.0" | "3.0+" | "compatible"
"5.0.0" | "4.0+" | "compatible"
"5.0.0" | "4.0" | "compatible"
"3.0.0" | "3.0.0" | "compatible"
"3.0.0" | "3.0.x" | "compatible"
"3.0.5" | "3.0.x" | "compatible"
Expand Down

0 comments on commit 6790e41

Please sign in to comment.