From d77450376e59e6f4abaf35f067ff267fec7d0d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=8F=E7=9A=84=E5=A4=A7=E8=82=A5?= <11911839@mail.sustech.edu.cn> Date: Sat, 26 Mar 2022 18:50:39 +0800 Subject: [PATCH] Fix changelog and version parsing (#8578) * Fix for issue 8563 * Update CHANGELOG.md Co-authored-by: Christoph * Fix typos * Fix test name Co-authored-by: Christoph Co-authored-by: Oliver Kopp --- CHANGELOG.md | 2 + src/main/java/org/jabref/gui/JabRefFrame.java | 4 +- .../java/org/jabref/logic/util/Version.java | 38 ++++++++++++++----- .../org/jabref/logic/util/VersionTest.java | 30 ++++++++++++++- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 645797bfd79..9dfda9b4902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Added - We added an extra option when right-clicking an entry in the Entry List to copy either the DOI or the DOI url. +- We improved the version check to take also beta version into account and now redirect to the right changelog for the version - We added two new web and fulltext fetchers: SemanticScholar and ResearchGate ### Changed @@ -34,6 +35,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue when reading non-UTF-8 encoded. When no encoding header is present, the encoding is now detected from the file content (and the preference option is disregarded) [#8417](https://github.com/JabRef/jabref/issues/8417) - We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448) - We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513) +- We fixed an issue where opening the changelog from withing JabRef led to a 404 error [#8563](https://github.com/JabRef/jabref/issues/8563) - We fixed an issue where not all found unlinked local files were imported correctly due to some race condition. [#8444](https://github.com/JabRef/jabref/issues/8444) - We fixed an issue where Merge entries dialog exceeds screen boundaries. diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 3d774c3eab1..7c33904a81e 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -565,7 +565,7 @@ public LibraryTab getLibraryTabAt(int i) { */ public List getLibraryTabs() { return tabbedPane.getTabs().stream() - .filter(LibraryTab.class::isInstance) + .filter(LibraryTab.class::isInstance) .map(LibraryTab.class::cast) .collect(Collectors.toList()); } @@ -892,7 +892,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), factory.createMenuItem(StandardActions.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/")), - factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md")) + factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/main/CHANGELOG.md")) ), factory.createMenuItem(StandardActions.ABOUT, new AboutAction()) ); diff --git a/src/main/java/org/jabref/logic/util/Version.java b/src/main/java/org/jabref/logic/util/Version.java index 567fdbb8403..336f68e05d0 100644 --- a/src/main/java/org/jabref/logic/util/Version.java +++ b/src/main/java/org/jabref/logic/util/Version.java @@ -27,7 +27,7 @@ public class Version { private static final Version UNKNOWN_VERSION = new Version(); - private final static Pattern VERSION_PATTERN = Pattern.compile("(?\\d+)(\\.(?\\d+))?(\\.(?\\d+))?(?-alpha|-beta)?(?-?dev)?.*"); + private final static Pattern VERSION_PATTERN = Pattern.compile("(?\\d+)(\\.(?\\d+))?(\\.(?\\d+))?(?-alpha|-beta)?(?\\d+)?(?-?dev)?.*"); private final static Pattern CI_SUFFIX_PATTERN = Pattern.compile("-ci\\.\\d+"); private static final String JABREF_GITHUB_RELEASES = "https://api.github.com/repos/JabRef/JabRef/releases"; @@ -37,6 +37,7 @@ public class Version { private int minor = -1; private int patch = -1; private DevelopmentStage developmentStage = DevelopmentStage.UNKNOWN; + private int developmentNum = -1; private boolean isDevelopmentVersion; /** @@ -75,6 +76,10 @@ public static Version parse(String version) { String versionStageString = matcher.group("stage"); parsedVersion.developmentStage = versionStageString == null ? DevelopmentStage.STABLE : DevelopmentStage.parse(versionStageString); + + String stageNumString = matcher.group("num"); + parsedVersion.developmentNum = stageNumString == null ? 0 : Integer.parseInt(stageNumString); + parsedVersion.isDevelopmentVersion = matcher.group("dev") != null; } catch (NumberFormatException e) { LOGGER.warn("Invalid version string used: " + version, e); @@ -138,8 +143,13 @@ public boolean isNewerThan(Version otherVersion) { if (this.developmentStage.isMoreStableThan(otherVersion.developmentStage)) { return true; } else if (this.developmentStage == otherVersion.developmentStage) { - // if the stage is equal check if this version is in development and the other is not - return !this.isDevelopmentVersion && otherVersion.isDevelopmentVersion; + // if the development stage are equal compare the development number + if (this.getDevelopmentNum() > otherVersion.getDevelopmentNum()) { + return true; + } else if (this.getDevelopmentNum() == otherVersion.getDevelopmentNum()) { + // if the stage is equal check if this version is in development and the other is not + return !this.isDevelopmentVersion && otherVersion.isDevelopmentVersion; + } } } } @@ -148,8 +158,7 @@ public boolean isNewerThan(Version otherVersion) { } /** - * Checks if this version should be updated to one of the given ones. - * Ignoring the other Version if this one is Stable and the other one is not. + * Checks if this version should be updated to one of the given ones. Ignoring the other Version if this one is Stable and the other one is not. * * @return The version this one should be updated to, or an empty Optional */ @@ -165,8 +174,7 @@ public Optional shouldBeUpdatedTo(List availableVersions) { } /** - * Checks if this version should be updated to the given one. - * Ignoring the other Version if this one is Stable and the other one is not. + * Checks if this version should be updated to the given one. Ignoring the other Version if this one is Stable and the other one is not. * * @return True if this version should be updated to the given one */ @@ -197,6 +205,10 @@ public int getPatch() { return patch; } + public int getDevelopmentNum() { + return developmentNum; + } + public boolean isDevelopmentVersion() { return isDevelopmentVersion; } @@ -206,7 +218,7 @@ public boolean isDevelopmentVersion() { */ public String getChangelogUrl() { if (isDevelopmentVersion) { - return "https://github.com/JabRef/jabref/blob/master/CHANGELOG.md#unreleased"; + return "https://github.com/JabRef/jabref/blob/main/CHANGELOG.md#unreleased"; } else { StringBuilder changelogLink = new StringBuilder() .append("https://github.com/JabRef/jabref/blob/v") @@ -221,8 +233,14 @@ public String getChangelogUrl() { } changelogLink - .append(this.developmentStage.stage) - .append("/CHANGELOG.md"); + .append(this.developmentStage.stage); + + if (this.getDevelopmentNum() != 0) { + changelogLink + .append(this.getDevelopmentNum()); + } + + changelogLink.append("/CHANGELOG.md"); return changelogLink.toString(); } diff --git a/src/test/java/org/jabref/logic/util/VersionTest.java b/src/test/java/org/jabref/logic/util/VersionTest.java index 438225fa712..5e04e7d234a 100644 --- a/src/test/java/org/jabref/logic/util/VersionTest.java +++ b/src/test/java/org/jabref/logic/util/VersionTest.java @@ -193,6 +193,20 @@ public void versionNotNewerPatch() { assertFalse(older.isNewerThan(newer)); } + @Test + public void versionNewerDevelopmentNumber() { + Version older = Version.parse("4.2-beta1"); + Version newer = Version.parse("4.2-beta2"); + assertFalse(older.isNewerThan(newer)); + } + + @Test + public void versionNotNewerThanSameVersionWithBeta() { + Version version1 = Version.parse("4.2-beta2"); + Version version2 = Version.parse("4.2-beta2"); + assertFalse(version2.isNewerThan(version1)); + } + @Test public void equalVersionsNotNewer() { Version version1 = Version.parse("4.2.2"); @@ -203,13 +217,25 @@ public void equalVersionsNotNewer() { @Test public void changelogOfDevelopmentVersionWithDash() { Version version = Version.parse("4.0-dev"); - assertEquals("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md#unreleased", version.getChangelogUrl()); + assertEquals("https://github.com/JabRef/jabref/blob/main/CHANGELOG.md#unreleased", version.getChangelogUrl()); } @Test public void changelogOfDevelopmentVersionWithoutDash() { Version version = Version.parse("3.7dev"); - assertEquals("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md#unreleased", version.getChangelogUrl()); + assertEquals("https://github.com/JabRef/jabref/blob/main/CHANGELOG.md#unreleased", version.getChangelogUrl()); + } + + @Test + public void changelogOfDevelopmentStageSubNumber() { + Version version1 = Version.parse("4.0"); + Version version2 = Version.parse("4.0-beta"); + Version version3 = Version.parse("4.0-beta2"); + Version version4 = Version.parse("4.0-beta3"); + assertEquals("https://github.com/JabRef/jabref/blob/v4.0/CHANGELOG.md", version1.getChangelogUrl()); + assertEquals("https://github.com/JabRef/jabref/blob/v4.0-beta/CHANGELOG.md", version2.getChangelogUrl()); + assertEquals("https://github.com/JabRef/jabref/blob/v4.0-beta2/CHANGELOG.md", version3.getChangelogUrl()); + assertEquals("https://github.com/JabRef/jabref/blob/v4.0-beta3/CHANGELOG.md", version4.getChangelogUrl()); } @Test