Skip to content
Commits on Source (17)
......@@ -105,7 +105,7 @@ Generate Release:
artifacts: false
- job: secret_detection
artifacts: false
image: ghcr.io/griefed/gitlab-ci-cd:2.0.4
image: ghcr.io/griefed/gitlab-ci-cd:2.0.5
script:
- npx semantic-release
rules:
......@@ -155,7 +155,7 @@ Build Release:
Publish Maven Artifacts:
stage: Build Release
image: ghcr.io/griefed/baseimage-ubuntu-jdk-8:2.0.7
image: ghcr.io/griefed/baseimage-ubuntu-jdk-8:2.0.8
before_script:
- echo "**** Running in $CI_JOB_ID ****"
- echo "**** Java location ****"
......@@ -175,7 +175,7 @@ Publish Maven Artifacts:
Inform About Release:
stage: Build Release
image: ghcr.io/griefed/gitlab-ci-cd:2.0.4
image: ghcr.io/griefed/gitlab-ci-cd:2.0.5
needs:
- job: Build Release
artifacts: false
......
## [1.1.0](https://git.griefed.de/Griefed/VersionChecker/compare/1.0.8...1.1.0) (2022-04-17)
### 📔 Docs
* **Examples:** Provide an example for the usage of the new Update-object in the README and expand sourceTar and sourceTarBz2 methods descriptions on when they are available. ([9af7137](https://git.griefed.de/Griefed/VersionChecker/commit/9af7137a16eeed543795426c2825867bf400e398))
### 🚀 Features
* **Update acquisition:** Acquire an instance of Update via `check(...)` which contains information about the available update, such as the version, description, sources, assets(if any), release date and url to the release. ([d20f1c7](https://git.griefed.de/Griefed/VersionChecker/commit/d20f1c7ef362222a5d061a47e0a12f278ad2f160))
### Other
* **deps:** update dependency com.fasterxml.jackson.core:jackson-databind to v2.13.2.2 ([93e475d](https://git.griefed.de/Griefed/VersionChecker/commit/93e475d5b18114c42c452e417ed1c270cad9ead6))
* **deps:** update dependency ghcr.io/griefed/baseimage-ubuntu-jdk-8 to v2.0.8 ([cc83427](https://git.griefed.de/Griefed/VersionChecker/commit/cc83427d8a7e618e5e282cdd081d259724ae8f75))
* **deps:** update dependency ghcr.io/griefed/gitlab-ci-cd to v2.0.5 ([92e8fcc](https://git.griefed.de/Griefed/VersionChecker/commit/92e8fcc0a8772b5af985b44568f8f08c889745e7))
* **deps:** update dependency gradle to v7.4.2 ([09c1c5a](https://git.griefed.de/Griefed/VersionChecker/commit/09c1c5ad3be80b9b945b41a0655eabe965c91931))
### [1.0.8](https://git.griefed.de/Griefed/VersionChecker/compare/1.0.7...1.0.8) (2022-03-23)
......
......@@ -61,10 +61,54 @@ implementation 'de.griefed:versionchecker:$VERSION'
For available versions, see the [sonatype repo](https://search.maven.org/artifact/de.griefed/versionchecker/)
# Example
# Examples
See [UpdateCheckerTests](src/test/java/de/griefed/versionchecker/UpdateCheckerTests.java)
The simplest way to acquire update information is to call `.check(...)` of your GitHub- or GitHubChecker instances with your current version.
This will return an instance of [Update](https://github.com/Griefed/VersionChecker/blob/main/src/main/java/de/griefed/versionchecker/Update.java) which contains
details about the available update. It is wrapped in an Optional, so you can conveniently check via `.isPresent()` if an update is available.
Once an instance of [Update](https://github.com/Griefed/VersionChecker/blob/main/src/main/java/de/griefed/versionchecker/Update.java) has been retrieved,
you can access information about it via any of the available methods.
Example:
```java
GitHubChecker GITHUB = new GitHubChecker("Griefed/ServerPackCreator");
Optional<Update> gitHubUpdate = GITHUB.check("3.0.1",false);
if (gitHubUpdate.isPresent()) {
// Gets the version of this update as a String.
gitHubUpdate.get().version();
// Check whether the update has a description
if (gitHubUpdate.get().description().isPresent()) {
// Get the description
gitHubUpdate.get().description().get();
}
// Get the url to the release page of this update
gitHubUpdate.get().url();
// Get the date at which this update has been released.
gitHubUpdate.get().releaseDate();
// Check if the update has any assets attached to it
if (gitHubUpdate.get().assets().isPresent()) {
// Get the available assets of this update
gitHubUpdate.get().assets().get();
}
// Get the available source-archives of this update
gitHubUpdate.get().sources();
}
```
```java
public class UpdateChecker {
......
......@@ -40,7 +40,7 @@ sourceSets {
dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.17.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
implementation 'org.jetbrains:annotations:23.0.0'
......
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
/*
* MIT License
*
* Copyright (c) 2022 Griefed
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.griefed.versionchecker;
/**
* Archive types available throughout GitLab or GitHub releases.
* @author Griefed
*/
public enum ArchiveType {
/**
* Indicates that a given archive has the <code>.zip</code>-format.
*/
ZIP,
/**
* Indicates that a given archive has the <code>.tar.gz</code>-format.
*/
TAR_GZ,
/**
* Indicates that a given archive has the <code>.tar.bz2</code>-format.
*/
TAR_BZ2,
/**
* Indicates that a given archive has the <code>.tar</code>-format.
*/
TAR
}
......@@ -24,7 +24,19 @@
package de.griefed.versionchecker;
public enum Comparison {
/**
* Used to determine whether two given versions are the same.
*/
EQUAL,
/**
* Used to determine whether a given version is newer.
*/
NEW,
/**
* Used to determine whether a given version is the same or newer.
*/
EQUAL_OR_NEW
}
......@@ -21,20 +21,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.griefed.versionchecker.github;
package de.griefed.versionchecker;
import com.fasterxml.jackson.databind.JsonNode;
import de.griefed.versionchecker.Comparison;
import org.jetbrains.annotations.NotNull;
import de.griefed.versionchecker.VersionChecker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* Check a given GitHub repository for updates.<br>
......@@ -69,6 +69,19 @@ public class GitHubChecker extends VersionChecker {
this.GITHUB_API_LATEST = new URL("https://api.github.com/repos/" + gitHubUserRepository + "/releases/latest");
}
/**
* Constructs a GitHub checker with the given <code>user/repository</code> combination to allow for version checks as
* well as version and URL acquisition.
* @author Griefed
* @param user {@link String} GitHub user and owner of the repository.
* @param repository {@link String} GitHub repository owned by the aforementioned user.
* @throws MalformedURLException Thrown if the resulting URL is malformed or otherwise invalid.
*/
public GitHubChecker(@NotNull String user, @NotNull String repository) throws MalformedURLException {
this.GITHUB_API = new URL("https://api.github.com/repos/" + user + "/" + repository + "/releases");
this.GITHUB_API_LATEST = new URL("https://api.github.com/repos/" + user + "/" + repository + "/releases/latest");
}
/**
* Refresh this GitHub-instance. Refreshes repository information, the latest version, as well as a list of all available
* versions.
......@@ -85,6 +98,91 @@ public class GitHubChecker extends VersionChecker {
return this;
}
/**
* Check whether an update/newer version is available for the given version. If you want to check for PreReleases, too,
* then make sure to pass <code>true</code> for <code>checkForPreReleases</code>.
* @author Griefed
* @param currentVersion String. The current version of the app.
* @param checkForPreReleases Boolean. <code>false</code> if you do not want to check for PreReleases. <code>true</code>
* if you want to check for PreReleases as well.
* @return {@link Update}-instance, wrapped in an {@link Optional}, contianing information about the available update.
*/
@Override
public Optional<Update> check(@NotNull String currentVersion, boolean checkForPreReleases) {
LOG.debug("Current version: " + currentVersion);
try {
String newVersion = isUpdateAvailable(currentVersion, checkForPreReleases);
if (!newVersion.equals("up_to_date")) {
String description = "N/A";
LocalDate releaseDate = null;
List<ReleaseAsset> assets = new ArrayList<>();
List<Source> sources = new ArrayList<>();
for (JsonNode release : repository) {
if (release.get("tag_name").asText().equals(newVersion)) {
description = release.get("body").asText();
releaseDate = LocalDate.parse(release.get("published_at").asText()
.substring(0,release.get("published_at").asText().lastIndexOf("T"))
);
for (JsonNode asset : release.get("assets")) {
assets.add(
new ReleaseAsset(
asset.get("name").asText(),
new URL(asset.get("browser_download_url").asText())
)
);
}
sources.add(
new Source(
ArchiveType.TAR_GZ,
new URL(release.get("tarball_url").asText())
)
);
sources.add(
new Source(
ArchiveType.ZIP,
new URL(release.get("zipball_url").asText())
)
);
break;
}
}
return Optional.of(
new Update(
newVersion,
description,
new URL(getDownloadUrl(newVersion)),
releaseDate,
assets,
sources
)
);
}
} catch (NumberFormatException ex) {
LOG.error("A version could not be parsed into integers.", ex);
} catch (MalformedURLException ex) {
LOG.error("URL could not be created.",ex);
}
return Optional.empty();
}
/**
* Gather a list of all available versions for the given repository.
* @author Griefed
......@@ -193,7 +291,11 @@ public class GitHubChecker extends VersionChecker {
* @author Griefed
* @param requestedVersion String. The version you want to retrieve the asset download URLs for.
* @return List String. A list of download URLs for the assets of the given tag/version.
* @deprecated The aim of VersionChecker is not to browse a given repository, but to check for availability of updates,
* and if an update is available, work from there. See {@link #check(String, boolean)} which returns an instance of
* {@link Update}. This provides everything you need.
*/
@Deprecated
@Override
public List<String> getAssetsDownloadUrls(@NotNull String requestedVersion) {
......
......@@ -21,20 +21,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.griefed.versionchecker.gitlab;
package de.griefed.versionchecker;
import com.fasterxml.jackson.databind.JsonNode;
import de.griefed.versionchecker.Comparison;
import org.jetbrains.annotations.NotNull;
import de.griefed.versionchecker.VersionChecker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* Check a given GitLab repository for updates.<br>
......@@ -68,6 +68,18 @@ public class GitLabChecker extends VersionChecker {
this.GITLAB_API = new URL(repositoryUrl);
}
/**
* Constructs a GitLab checker with the given GitLab-URL to allow for version checks as well as version and URL
* acquisition.
* @author Griefed
* @param repositoryUrl {@link URL}. The full /api/v4-GitLab-repository-URL you want to check. Examples:<br>
* <code>https://gitlab.com/api/v4/projects/32677538/releases</code><br>
* <code>https://git.griefed.de/api/v4/projects/63/releases</code>
*/
public GitLabChecker(@NotNull URL repositoryUrl) {
this.GITLAB_API = repositoryUrl;
}
/**
* Refresh this GitLab-instance. Refreshes repository information and the list of all available versions.
* @author Griefed
......@@ -82,6 +94,105 @@ public class GitLabChecker extends VersionChecker {
return this;
}
/**
* Check whether an update/newer version is available for the given version. If you want to check for PreReleases, too,
* then make sure to pass <code>true</code> for <code>checkForPreReleases</code>.
* @author Griefed
* @param currentVersion String. The current version of the app.
* @param checkForPreReleases Boolean. <code>false</code> if you do not want to check for PreReleases. <code>true</code>
* if you want to check for PreReleases as well.
* @return {@link Update}-instance, wrapped in an {@link Optional}, contianing information about the available update.
*/
@Override
public Optional<Update> check(@NotNull String currentVersion, boolean checkForPreReleases) {
LOG.debug("Current version: " + currentVersion);
try {
String newVersion = isUpdateAvailable(currentVersion, checkForPreReleases);
if (!newVersion.equals("up_to_date")) {
String description = "N/A";
LocalDate releaseDate = null;
List<ReleaseAsset> assets = new ArrayList<>();
List<Source> sources = new ArrayList<>();
for (JsonNode release : repository) {
if (release.get("tag_name").asText().equals(newVersion)) {
description = release.get("description").asText();
releaseDate = LocalDate.parse(release.get("released_at").asText()
.substring(0, release.get("released_at").asText().lastIndexOf("T"))
);
for (JsonNode asset : release.get("assets").get("links")) {
assets.add(
new ReleaseAsset(
asset.get("name").asText(),
new URL(asset.get("direct_asset_url").asText())
)
);
}
for (JsonNode source : release.get("assets").get("sources")) {
ArchiveType type = null;
switch (source.get("format").asText()) {
case "zip":
type = ArchiveType.ZIP;
break;
case "tar.gz":
type = ArchiveType.TAR_GZ;
break;
case "tar.bz2":
type = ArchiveType.TAR_BZ2;
break;
case "tar":
type = ArchiveType.TAR;
break;
}
sources.add(
new Source(
type,
new URL(source.get("url").asText())
)
);
}
break;
}
}
return Optional.of(
new Update(
newVersion,
description,
new URL(getDownloadUrl(newVersion)),
releaseDate,
assets,
sources
)
);
}
} catch (NumberFormatException ex) {
LOG.error("A version could not be parsed into integers.", ex);
} catch (MalformedURLException ex) {
LOG.error("URL could not be created.",ex);
}
return Optional.empty();
}
/**
* Gather a list of all available versions for the given repository.
* @author Griefed
......@@ -205,7 +316,11 @@ public class GitLabChecker extends VersionChecker {
* @author Griefed
* @param requestedVersion String. The version you want to retrieve the asset download URLs for.
* @return List String. A list of download URLs for the assets of the given tag/version.
* @deprecated The aim of VersionChecker is not to browse a given repository, but to check for availability of updates,
* and if an update is available, work from there. See {@link #check(String, boolean)} which returns an instance of
* {@link Update}. This provides everything you need.
*/
@Deprecated
@Override
public List<String> getAssetsDownloadUrls(@NotNull String requestedVersion) {
......
/*
* MIT License
*
* Copyright (c) 2022 Griefed
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.griefed.versionchecker;
import java.net.URL;
/**
* A release asset is usually some form of compiled program or library.
* @author Griefed
*/
public class ReleaseAsset {
private final String ASSET_NAME;
private final URL ASSET_URL;
/**
* Create a new release asset from an asset name and the {@link URL} to said asset download.
* @author Griefed
* @param assetName {@link String} Asset name.
* @param assetURL {@link URL} Asset download URL.
*/
public ReleaseAsset(String assetName, URL assetURL) {
this.ASSET_NAME = assetName;
this.ASSET_URL = assetURL;
}
/**
* Get the name of this asset. Usually a filename.
* @author Griefed
* @return {@link String} The name of this asset. Usually a filename.
*/
public String name() {
return ASSET_NAME;
}
/**
* Get the download-{@link URL} to this asset.
* @author Griefed
* @return Download-{@link URL} to this asset.
*/
public URL url() {
return ASSET_URL;
}
}
/*
* MIT License
*
* Copyright (c) 2022 Griefed
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.griefed.versionchecker;
import java.net.URL;
/**
* A source-archive is the source code of the repository for the tag of the parent-release. It represents the state of the
* code at the time of the release.
* @author Griefed
*/
public class Source {
private final ArchiveType ARCHIVE_TYPE;
private final URL ARCHIVE_URL;
/**
* Create a new source from an {@link ArchiveType} and the download-{@link URL} to this archive.
* @author Griefed
* @param archiveType {@link ArchiveType} Archive type of this source.
* @param archiveURL {@link URL} Download url for this source.
*/
public Source(ArchiveType archiveType, URL archiveURL) {
this.ARCHIVE_TYPE = archiveType;
this.ARCHIVE_URL = archiveURL;
}
/**
* Get the {@link ArchiveType} of this source.
* @author Griefed
* @return {@link ArchiveType} of this source.
*/
public ArchiveType type() {
return ARCHIVE_TYPE;
}
/**
* Get the download-{@link URL} for this source.
* @author Griefed
* @return Download-{@link URL} for this source.
*/
public URL url() {
return ARCHIVE_URL;
}
}
/*
* MIT License
*
* Copyright (c) 2022 Griefed
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.griefed.versionchecker;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.net.URL;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
/**
* An instance of Update contains information about the release which is considered an update to the version which was used
* to acquire this Update-instance.<br>
* It gives you access to:<br>
* - The version.<br>
* - The description (release description as shown on release pages on GitLab or GitHub).<br>
* - The {@link URL} to this release for visiting it in your browser.<br>
* - The {@link LocalDate} at which this release was published/release.<br>
* - A list of {@link ReleaseAsset}, if any.<br>
* - A list of {@link Source}.
* @author Griefed
*/
public class Update {
private final String VERSION;
private final String DESCRIPTION;
private final URL LINK;
private final LocalDate RELEASE_DATE;
private final List<ReleaseAsset> ASSETS;
private final List<Source> SOURCES;
/**
* Create a new Update-instance.
* @author Griefed
* @param version {@link String} The version of this update/release.
* @param description {@link String} The description (release description as shown on release pages on GitLab or GitHub), of this release/update.
* @param link {@link URL} The URL to this release for visiting it in your browser.
* @param releaseDate {@link LocalDate} The date at which this release was published/release.
* @param assets {@link ReleaseAsset}-list. Available release-assets for this update/release, if any.
* @param sources {@link Source}-list. Available source-archives for this update/release.
*/
public Update(@NotNull String version,
@Nullable String description,
@NotNull URL link,
@NotNull LocalDate releaseDate,
@Nullable List<ReleaseAsset> assets,
@NotNull List<Source> sources) {
this.VERSION = version;
this.DESCRIPTION = description;
this.LINK = link;
this.RELEASE_DATE = releaseDate;
this.ASSETS = assets;
this.SOURCES = sources;
}
/**
* Get the version of this update/release.
* @author Griefed
* @return {@link String} The version of this update/release.
*/
public String version() {
return VERSION;
}
/**
* Get the description of this update/release, wrapped in an {@link Optional}.
* @author Griefed
* @return {@link String} The description of this update/release, wrapped in an {@link Optional}.
*/
public Optional<String> description() {
return Optional.ofNullable(DESCRIPTION);
}
/**
* Get the {@link URL} to this release for use in your browser.
* @author Griefed
* @return {@link URL} to this release for use in your browser.
*/
public URL url() {
return LINK;
}
/**
* Get the {@link LocalDate} at which this release was published.
* @author Griefed
* @return {@link LocalDate} at which this release was published.
*/
public LocalDate releaseDate() {
return RELEASE_DATE;
}
/**
* Get the {@link ReleaseAsset}-list of available assets for this update/release, wrapped in an {@link Optional}.
* @author Griefed
* @return {@link ReleaseAsset}-list of available assets for this update/release, wrapped in an {@link Optional}.
*/
public Optional<List<ReleaseAsset>> assets() {
return Optional.ofNullable(ASSETS);
}
/**
* Get the {@link Source}-list of available source-archives for this update/release.
* @author Griefed
* @return {@link Source}-list of available source-archives for this update/release.
*/
public List<Source> sources() {
return SOURCES;
}
/**
* Get the ZIP-archive-source of this update.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#ZIP} of this update.
*/
public Source sourceZip() {
for (Source source : SOURCES) {
if (source.type() == ArchiveType.ZIP) {
return source;
}
}
return null;
}
/**
* Get the tar.gz-archive-source of this update.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#TAR_GZ} of this update.
*/
public Source sourceTarGz() {
for (Source source : SOURCES) {
if (source.type() == ArchiveType.TAR_GZ) {
return source;
}
}
return null;
}
/**
* Get the tar-archive-source of this update. A tar-archive is usually only available for GitLab updates. GitHub typically
* only provides zip- and tar.gz-archives.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#TAR} of this update, wrapped in an {@link Optional}.
*/
public Optional<Source> sourceTar() {
for (Source source : SOURCES) {
if (source.type() == ArchiveType.TAR) {
return Optional.of(source);
}
}
return Optional.empty();
}
/**
* Get the tar.bz2-archive-source of this update. A tar.bz2-archive is usually only available for GitLab updates. GitHub typically
* only provides zip- and tar.gz-archives.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#TAR_BZ2} of this update, wrapped in an {@link Optional}.
*/
public Optional<Source> sourceTarBz2() {
for (Source source : SOURCES) {
if (source.type() == ArchiveType.TAR_BZ2) {
return Optional.of(source);
}
}
return Optional.empty();
}
/**
* Get a specific release-asset for a given name of said release.
* @author Griefed
* @param releaseName {@link String} The name of the release asset.
* @return {@link ReleaseAsset} for the given name, wrapped in an {@link Optional}.
*/
public Optional<ReleaseAsset> getReleaseAsset(@NotNull String releaseName) {
if (ASSETS == null) {
return Optional.empty();
}
for (ReleaseAsset releaseAsset : ASSETS) {
if (releaseAsset.name().equals(releaseName)) {
return Optional.of(releaseAsset);
}
}
return Optional.empty();
}
}
......@@ -35,6 +35,7 @@ import java.io.InputStreamReader;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* Baseclass from wich GitHub and GitLab checks extend. This class mainly provides the logic for comparing versions against
......@@ -89,7 +90,7 @@ public abstract class VersionChecker {
* if you want to check for PreReleases as well.
* @return String. Returns the available update version. If no update is available, then <code>up_to_date</code> is returned.
*/
private String isUpdateAvailable(@NotNull String currentVersion, boolean checkForPreReleases) {
protected String isUpdateAvailable(@NotNull String currentVersion, boolean checkForPreReleases) {
if (checkForPreReleases) {
if (isNewBetaAvailable(currentVersion)) {
......@@ -507,6 +508,8 @@ public abstract class VersionChecker {
protected abstract void setRepository() throws IOException;
@Deprecated
public abstract List<String> getAssetsDownloadUrls(@NotNull String version);
public abstract Optional<Update> check(@NotNull String currentVersion, boolean checkForPreReleases);
}
\ No newline at end of file
package de.griefed.versionchecker;
import de.griefed.versionchecker.github.GitHubChecker;
import de.griefed.versionchecker.gitlab.GitLabChecker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Assertions;
......@@ -17,16 +15,11 @@ public class UpdateCheckerTests {
private GitLabChecker GITGRIEFED;
private GitLabChecker GITLAB;
//private GitHubChecker tests;
public UpdateCheckerTests() throws IOException {
this.GITHUB = new GitHubChecker("Griefed/ServerPackCreator");
this.GITLAB = new GitLabChecker("https://gitlab.com/api/v4/projects/32677538/releases");
this.GITGRIEFED = new GitLabChecker("https://git.griefed.de/api/v4/projects/63/releases");
//this.tests = new GitHubChecker("Griefed/Action_tests");
//this.tests.refresh();
}
@Test
......@@ -126,13 +119,16 @@ public class UpdateCheckerTests {
String latest = GITHUB.latestVersion(false);
String latestPre = GITHUB.latestVersion(true);
System.out.println("latest = " + latest);
System.out.println("latestPre = " + latestPre);
System.out.println("Old version should return the newest regular release, whilst not checking for pre-releases.");
Assertions.assertEquals(
latest,
checkForUpdate(
"2.0.0",
false
).split(";")[0]);
).split(";")[0]);
System.out.println("Old version should return the newest pre-release release, whilst checking for pre-releases, too.");
Assertions.assertEquals(
......@@ -140,7 +136,7 @@ public class UpdateCheckerTests {
checkForUpdate(
"2.0.0",
true
).split(";")[0]);
).split(";")[0]);
......@@ -150,7 +146,7 @@ public class UpdateCheckerTests {
checkForUpdate(
"2.0.0-alpha.2",
false
).split(";")[0]);
).split(";")[0]);
System.out.println("Old alpha should return the newest alpha/beta, whilst checking for pre-releases, too.");
Assertions.assertEquals(
......@@ -158,7 +154,7 @@ public class UpdateCheckerTests {
checkForUpdate(
"2.0.0-alpha.2",
true
).split(";")[0]);
).split(";")[0]);
......@@ -168,7 +164,7 @@ public class UpdateCheckerTests {
checkForUpdate(
"2.0.0-beta.2",
false
).split(";")[0]);
).split(";")[0]);
System.out.println("Old beta should return the newest alpha/beta, whilst checking for pre-releases, too.");
Assertions.assertEquals(
......@@ -176,18 +172,9 @@ public class UpdateCheckerTests {
checkForUpdate(
"2.0.0-beta.2",
true
).split(";")[0]);
).split(";")[0]);
System.out.println("Old beta, but newer than the newest regular release, should return no available updates, whilst not checking for pre-releases.");
Assertions.assertEquals(
"No updates available.",
checkForUpdate(
"3.0.0-beta.2",
false
)
);
System.out.println("Old beta, but newer than the newest regular release, should the latest available alpha/beta, whilst checking for pre-releases, too.");
Assertions.assertEquals(
......@@ -195,26 +182,17 @@ public class UpdateCheckerTests {
checkForUpdate(
"3.0.0-beta.2",
true
).split(";")[0]);
).split(";")[0]);
System.out.println("Old beta, but newer than the newest regular release, should return no available updates, whilst not checking for pre-releases.");
Assertions.assertEquals(
"No updates available.",
checkForUpdate(
"3.0.0-alpha.2",
false
)
);
System.out.println("Old alpha, but newer than the newest regular release, should return the newest alpha/beta, whilst checking for pre-releases, too.");
Assertions.assertEquals(
latestPre,
checkForUpdate(
"3.0.0-alpha.2",
true
).split(";")[0]);
).split(";")[0]);
......@@ -304,7 +282,7 @@ public class UpdateCheckerTests {
checkForUpdate(
latest + "-beta.2",
false
).split(";")[0]);
).split(";")[0]);
System.out.println("Beta for latest version should return latest version as available update.");
Assertions.assertEquals(
......@@ -312,7 +290,7 @@ public class UpdateCheckerTests {
checkForUpdate(
latest + "-beta.2",
true
).split(";")[0]);
).split(";")[0]);
......@@ -322,7 +300,7 @@ public class UpdateCheckerTests {
checkForUpdate(
latest + "-alpha.12",
false
).split(";")[0]);
).split(";")[0]);
System.out.println("Alpha for latest version should return latest version as available update.");
Assertions.assertEquals(
......@@ -330,63 +308,72 @@ public class UpdateCheckerTests {
checkForUpdate(
latest + "-alpha.2",
true
).split(";")[0]);
/*System.out.println(tests.latestVersion(false));
System.out.println("Beta for latest version should return latest version as available update, whilst not checking for pre-releases.");
Assertions.assertEquals(
"1.2.5",
testChecker(
"1.2.5-beta.1",
false
).split(";")[0]);
System.out.println("Beta for latest version should return latest version as available update.");
Assertions.assertEquals(
"1.2.5",
testChecker(
"1.2.5-beta.1",
true
).split(";")[0]);
System.out.println("Update-instance from GitLab");
Assertions.assertTrue(GITLAB.check("2.0.0",false).isPresent());
Assertions.assertFalse(GITLAB.check(latest,false).isPresent());
Update gitLabUpdate = GITLAB.check("2.0.0",false).get();
Assertions.assertEquals(gitLabUpdate.version(), latest);
Assertions.assertNotNull(gitLabUpdate.description());
Assertions.assertNotNull(gitLabUpdate.url());
Assertions.assertNotNull(gitLabUpdate.releaseDate());
Assertions.assertNotEquals(0, gitLabUpdate.assets().get().size());
gitLabUpdate.assets().get().forEach(asset -> {
Assertions.assertNotNull(asset.name());
Assertions.assertNotNull(asset.url());
});
Assertions.assertTrue(gitLabUpdate.getReleaseAsset("ServerPackCreator-" + latest + ".exe").isPresent());
Assertions.assertTrue(gitLabUpdate.getReleaseAsset("ServerPackCreator-" + latest + ".jar").isPresent());
Assertions.assertNotEquals(0, gitLabUpdate.sources().size());
gitLabUpdate.sources().forEach(source -> {
Assertions.assertNotNull(source.type());
Assertions.assertNotNull(source.url());
});
Assertions.assertNotNull(gitLabUpdate.sourceZip());
Assertions.assertSame(gitLabUpdate.sourceZip().type(), ArchiveType.ZIP);
Assertions.assertNotNull(gitLabUpdate.sourceTarGz());
Assertions.assertSame(gitLabUpdate.sourceTarGz().type(), ArchiveType.TAR_GZ);
Assertions.assertTrue(gitLabUpdate.sourceTar().isPresent());
Assertions.assertSame(gitLabUpdate.sourceTar().get().type(), ArchiveType.TAR);
Assertions.assertTrue(gitLabUpdate.sourceTarBz2().isPresent());
Assertions.assertSame(gitLabUpdate.sourceTarBz2().get().type(), ArchiveType.TAR_BZ2);
System.out.println("Update-instance from GitHub");
Assertions.assertTrue(GITLAB.check("2.0.0",false).isPresent());
Assertions.assertFalse(GITLAB.check(latest,false).isPresent());
Update gitHubUpdate = GITHUB.check("2.0.0",false).get();
Assertions.assertEquals(gitHubUpdate.version(), latest);
Assertions.assertNotNull(gitHubUpdate.description());
Assertions.assertNotNull(gitHubUpdate.url());
Assertions.assertNotNull(gitHubUpdate.releaseDate());
Assertions.assertNotEquals(0, gitHubUpdate.assets().get().size());
gitHubUpdate.assets().get().forEach(asset -> {
Assertions.assertNotNull(asset.name());
Assertions.assertNotNull(asset.url());
});
Assertions.assertTrue(gitHubUpdate.getReleaseAsset("ServerPackCreator-" + latest + ".exe").isPresent());
Assertions.assertTrue(gitHubUpdate.getReleaseAsset("ServerPackCreator-" + latest + ".jar").isPresent());
Assertions.assertNotEquals(0, gitHubUpdate.sources().size());
gitHubUpdate.sources().forEach(source -> {
Assertions.assertNotNull(source.type());
Assertions.assertNotNull(source.url());
});
Assertions.assertNotNull(gitHubUpdate.sourceZip());
Assertions.assertSame(gitHubUpdate.sourceZip().type(), ArchiveType.ZIP);
Assertions.assertNotNull(gitHubUpdate.sourceTarGz());
Assertions.assertSame(gitHubUpdate.sourceTarGz().type(), ArchiveType.TAR_GZ);
Assertions.assertFalse(gitHubUpdate.sourceTar().isPresent());
Assertions.assertFalse(gitHubUpdate.sourceTarBz2().isPresent());
System.out.println("Alpha for latest version should return latest version as available update.");
Assertions.assertEquals(
"1.2.5",
testChecker(
"1.2.5-alpha.1",
false
).split(";")[0]);
System.out.println("Alpha for latest version should return latest version as available update.");
Assertions.assertEquals(
"1.2.5",
testChecker(
"1.2.5-alpha.1",
true
).split(";")[0]);*/
}
/*private String testChecker(String version, boolean pre) {
String updater = null;
// Check GitHub for the most recent release.
if (tests != null) {
// Check GitHub for new versions which are not pre-releases. Run with true to check pre-releases as well.
updater = tests.checkForUpdate(version, pre);
}
System.out.println("Check pre: " + pre );
System.out.println("Checked version: " + version);
System.out.println("Result: " + updater);
System.out.println();
return updater;
}*/
private String checkForUpdate(String version, boolean pre) {
String updater = null;
......