Search in sources :

Example 1 with PluginVersionConstraint

use of org.graylog2.contentpacks.model.constraints.PluginVersionConstraint in project graylog2-server by Graylog2.

the class PluginVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof PluginVersionConstraint) {
            final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            boolean result = false;
            for (Semver pluginVersion : pluginVersions) {
                if (requiredVersion.isSatisfiedBy(pluginVersion)) {
                    result = true;
                }
            }
            ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, result);
            fulfilledConstraints.add(constraintCheckResult);
        }
    }
    return fulfilledConstraints.build();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Requirement(com.vdurmont.semver4j.Requirement) ImmutableSet(com.google.common.collect.ImmutableSet) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Semver(com.vdurmont.semver4j.Semver)

Example 2 with PluginVersionConstraint

use of org.graylog2.contentpacks.model.constraints.PluginVersionConstraint in project graylog2-server by Graylog2.

the class PluginVersionConstraint method of.

public static PluginVersionConstraint of(PluginMetaData pluginMetaData) {
    final Version version = pluginMetaData.getVersion();
    final String versionString = version.toString().replace("-SNAPSHOT", "");
    final Requirement requirement = Requirement.buildNPM(">=" + versionString);
    return builder().pluginId(pluginMetaData.getUniqueId()).version(requirement).build();
}
Also used : Requirement(com.vdurmont.semver4j.Requirement) Version(org.graylog2.plugin.Version)

Example 3 with PluginVersionConstraint

use of org.graylog2.contentpacks.model.constraints.PluginVersionConstraint in project graylog2-server by Graylog2.

the class GraylogVersionConstraintCheckerTest method checkConstraints.

@Test
public void checkConstraints() {
    final GraylogVersionConstraintChecker constraintChecker = new GraylogVersionConstraintChecker("1.0.0");
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^1.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    final Set<ConstraintCheckResult> result = constraintChecker.checkConstraints(requiredConstraints);
    assertThat(result.stream().allMatch(c -> c.fulfilled())).isTrue();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Example 4 with PluginVersionConstraint

use of org.graylog2.contentpacks.model.constraints.PluginVersionConstraint in project graylog2-server by Graylog2.

the class GraylogVersionConstraintCheckerTest method checkConstraintsFails.

@Test
public void checkConstraintsFails() {
    final GraylogVersionConstraintChecker constraintChecker = new GraylogVersionConstraintChecker("1.0.0");
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    final Set<ConstraintCheckResult> result = constraintChecker.checkConstraints(requiredConstraints);
    assertThat(result.stream().allMatch(c -> !c.fulfilled())).isTrue();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Example 5 with PluginVersionConstraint

use of org.graylog2.contentpacks.model.constraints.PluginVersionConstraint in project graylog2-server by Graylog2.

the class PluginVersionConstraintCheckerTest method checkConstraints.

@Test
public void checkConstraints() {
    final TestPluginMetaData pluginMetaData = new TestPluginMetaData();
    final PluginVersionConstraintChecker constraintChecker = new PluginVersionConstraintChecker(Collections.singleton(pluginMetaData));
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    assertThat(constraintChecker.checkConstraints(requiredConstraints).stream().allMatch(c -> c.fulfilled())).isTrue();
}
Also used : PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Aggregations

Constraint (org.graylog2.contentpacks.model.constraints.Constraint)6 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)6 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)4 Test (org.junit.Test)4 Requirement (com.vdurmont.semver4j.Requirement)3 ConstraintCheckResult (org.graylog2.contentpacks.model.constraints.ConstraintCheckResult)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Semver (com.vdurmont.semver4j.Semver)2 Version (org.graylog2.plugin.Version)1