Search in sources :

Example 1 with Requirement

use of com.vdurmont.semver4j.Requirement 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 Requirement

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

the class GraylogVersionConstraintChecker method ensureConstraints.

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

Example 3 with Requirement

use of com.vdurmont.semver4j.Requirement 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 4 with Requirement

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

the class GraylogVersionConstraint method of.

public static GraylogVersionConstraint of(Version version) {
    final String versionString = version.toString().replace("-SNAPSHOT", "");
    final Requirement requirement = Requirement.buildNPM(">=" + versionString);
    return builder().version(requirement).build();
}
Also used : Requirement(com.vdurmont.semver4j.Requirement)

Example 5 with Requirement

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

the class SemverRequirementDeserializerTest method successfullyDeserializesString.

@Test
public void successfullyDeserializesString() throws IOException {
    final Requirement requirement = objectMapper.readValue("\"^1.3.7-rc.2+build.2.b8f12d7\"", Requirement.class);
    assertThat(requirement).isEqualTo(Requirement.buildNPM("^1.3.7-rc.2+build.2.b8f12d7"));
}
Also used : Requirement(com.vdurmont.semver4j.Requirement) Test(org.junit.Test)

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