Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update semver library #244

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multiapps-mta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-mta/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
requires org.apache.commons.collections4;
requires org.apache.commons.io;
requires org.apache.commons.lang3;
requires semver4j;
requires org.semver4j;

requires static java.compiler;
requires static org.immutables.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@

import org.cloudfoundry.multiapps.common.ParsingException;
import org.cloudfoundry.multiapps.mta.Messages;
import org.cloudfoundry.multiapps.mta.parsers.PartialVersionConverter;

import com.vdurmont.semver4j.Semver;
import com.vdurmont.semver4j.Semver.SemverType;
import com.vdurmont.semver4j.SemverException;
import org.semver4j.Semver;
import org.semver4j.SemverException;

public class Version implements Comparable<Version> {

private static final PartialVersionConverter PARTIAL_VERSION_CONVERTER = new PartialVersionConverter();

private final Semver version;

private Version(Semver version) {
Expand All @@ -32,21 +27,12 @@ public int getPatch() {
return version.getPatch();
}

public String getBuild() {
return version.getBuild();
}

public String[] getSuffixTokens() {
return version.getSuffixTokens();
}

public static Version parseVersion(String versionString) {
try {
String fullVersionString = PARTIAL_VERSION_CONVERTER.convertToFullVersionString(versionString);
return new Version(new Semver(fullVersionString, SemverType.NPM));
} catch (SemverException e) {
throw new ParsingException(e, Messages.UNABLE_TO_PARSE_VERSION, versionString);
var version = Semver.coerce(versionString); //allows incomplete version strings like "3" or "3.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work with some strange version like 3.1.0+123123, because it might be breaking

if (version == null) {
throw new ParsingException(Messages.UNABLE_TO_PARSE_VERSION, versionString);
}
return new Version(version);
}

@Override
Expand All @@ -56,7 +42,7 @@ public int hashCode() {

@Override
public String toString() {
return version.getValue();
return version.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.cloudfoundry.multiapps.mta.model;

import java.util.function.Predicate;

public enum VersionRule {

SAME_HIGHER(VersionRule::isNotDowngrade),
Expand All @@ -8,22 +10,14 @@ public enum VersionRule {

ALL(VersionRule::isAny);

private interface VersionRuleValidator {
boolean allows(DeploymentType deploymentType);
}

private VersionRuleValidator versionRuleValidator;
private final Predicate<DeploymentType> versionRuleValidator;

VersionRule(VersionRuleValidator versionRuleValidator) {
VersionRule(Predicate<DeploymentType> versionRuleValidator) {
this.versionRuleValidator = versionRuleValidator;
}

public boolean allows(DeploymentType deploymentType) {
return versionRuleValidator.allows(deploymentType);
}

public static VersionRule value(String caseInsensitiveValue) {
return VersionRule.valueOf(caseInsensitiveValue.toUpperCase());
return versionRuleValidator.test(deploymentType);
}

private static boolean isNotDowngrade(DeploymentType deploymentType) {
Expand Down

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<commons-io.version>2.11.0</commons-io.version>
<slf4j.version>2.0.6</slf4j.version>
<snakeyaml.version>2.0</snakeyaml.version>
<semver4j.version>3.1.0</semver4j.version>
<semver4j.version>5.2.2</semver4j.version>
<immutables.version>2.8.8</immutables.version>
<jaxb-api.version>2.3.3</jaxb-api.version>
<jaxb-core.version>2.3.0.1</jaxb-core.version>
Expand Down Expand Up @@ -292,9 +292,9 @@
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.vdurmont/semver4j -->
<!-- https://mvnrepository.com/artifact/org.semver4j/semver4j -->
<dependency>
<groupId>com.vdurmont</groupId>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
<version>${semver4j.version}</version>
</dependency>
Expand Down
Loading