Skip to content

Commit

Permalink
Fix changelog and version parsing (#8578)
Browse files Browse the repository at this point in the history
* Fix for issue 8563

* Update CHANGELOG.md

Co-authored-by: Christoph <siedlerkiller@gmail.com>

* Fix typos

* Fix test name

Co-authored-by: Christoph <siedlerkiller@gmail.com>
Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
  • Loading branch information
3 people authored Mar 26, 2022
1 parent e9d3e67 commit d774503
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public LibraryTab getLibraryTabAt(int i) {
*/
public List<LibraryTab> getLibraryTabs() {
return tabbedPane.getTabs().stream()
.filter(LibraryTab.class::isInstance)
.filter(LibraryTab.class::isInstance)
.map(LibraryTab.class::cast)
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -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())
);
Expand Down
38 changes: 28 additions & 10 deletions src/main/java/org/jabref/logic/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Version {

private static final Version UNKNOWN_VERSION = new Version();

private final static Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)(\\.(?<minor>\\d+))?(\\.(?<patch>\\d+))?(?<stage>-alpha|-beta)?(?<dev>-?dev)?.*");
private final static Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)(\\.(?<minor>\\d+))?(\\.(?<patch>\\d+))?(?<stage>-alpha|-beta)?(?<num>\\d+)?(?<dev>-?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";
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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
*/
Expand All @@ -165,8 +174,7 @@ public Optional<Version> shouldBeUpdatedTo(List<Version> 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
*/
Expand Down Expand Up @@ -197,6 +205,10 @@ public int getPatch() {
return patch;
}

public int getDevelopmentNum() {
return developmentNum;
}

public boolean isDevelopmentVersion() {
return isDevelopmentVersion;
}
Expand All @@ -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")
Expand All @@ -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();
}
Expand Down
30 changes: 28 additions & 2 deletions src/test/java/org/jabref/logic/util/VersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down

0 comments on commit d774503

Please sign in to comment.