Search in sources :

Example 6 with Requirement

use of com.vdurmont.semver4j.Requirement in project graylog2-server by Graylog2.

the class SemverRequirementDeserializerTest method successfullyDeserializesNull.

@Test
public void successfullyDeserializesNull() throws IOException {
    final Requirement requirement = objectMapper.readValue("null", Requirement.class);
    assertThat(requirement).isNull();
}
Also used : Requirement(com.vdurmont.semver4j.Requirement) Test(org.junit.Test)

Example 7 with Requirement

use of com.vdurmont.semver4j.Requirement in project graylog2-server by Graylog2.

the class SemverRequirementSerializerTest method successfullySerializesRequirement.

@Test
public void successfullySerializesRequirement() throws JsonProcessingException {
    final Requirement requirement = Requirement.buildNPM("^1.3.7-rc.2+build.2.b8f12d7");
    final String s = objectMapper.writeValueAsString(requirement);
    assertThat(s).isEqualTo("\">=1.3.7-rc.2+build.2.b8f12d7 <2.0.0\"");
}
Also used : Requirement(com.vdurmont.semver4j.Requirement) Test(org.junit.Test)

Example 8 with Requirement

use of com.vdurmont.semver4j.Requirement in project graylog2-server by Graylog2.

the class PluginVersionConstraintChecker method ensureConstraints.

@Override
public Set<Constraint> ensureConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<Constraint> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof PluginVersionConstraint) {
            final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            for (Semver pluginVersion : pluginVersions) {
                if (requiredVersion.isSatisfiedBy(pluginVersion)) {
                    fulfilledConstraints.add(constraint);
                }
            }
        }
    }
    return fulfilledConstraints.build();
}
Also used : 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 9 with Requirement

use of com.vdurmont.semver4j.Requirement in project graylog2-server by Graylog2.

the class GraylogVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof GraylogVersionConstraint) {
            final GraylogVersionConstraint versionConstraint = (GraylogVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            final ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, requiredVersion.isSatisfiedBy(graylogVersion.withClearedSuffixAndBuild()));
            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) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)

Aggregations

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