Skip to content
GitLab
Explore
Sign in
This is an archived project. Repository and other project resources are read-only.
Commits on Source (4)
test: Some more assertions for versions and URLs
· e3a5a8a7
Griefed
authored
Feb 04, 2022
e3a5a8a7
Merge remote-tracking branch 'origin/main'
· 46d58745
Griefed
authored
Feb 04, 2022
46d58745
docs: Improve documentation
· fffe5e8f
Griefed
authored
Feb 04, 2022
fffe5e8f
RELEASE: 1.0.5
· b7b4b304
semantic-release-bot
authored
Feb 04, 2022
b7b4b304
Hide whitespace changes
Inline
Side-by-side
.releaserc.yml
View file @
b7b4b304
...
...
@@ -42,7 +42,7 @@ analyzeCommits:
-
type
:
ci
# Changes to our CI configuration files and scripts
release
:
false
-
type
:
docs
# Documentation only changes
release
:
false
release
:
patch
-
type
:
feat
# A new feature
release
:
minor
-
type
:
fix
# A bug fix
...
...
CHANGELOG.md
View file @
b7b4b304
### [1.0.5](https://git.griefed.de/Griefed/VersionChecker/compare/1.0.4...1.0.5) (2022-02-04)
### 📔 Docs
*
Improve documentation (
[
fffe5e8
](
https://git.griefed.de/Griefed/VersionChecker/commit/fffe5e8f085ea05c4a2189119034dc695edd4553
)
)
### 🧪 Tests
*
Some more assertions for versions and URLs (
[
e3a5a8a
](
https://git.griefed.de/Griefed/VersionChecker/commit/e3a5a8a7c43a68ae998444732710f30106f7f340
)
)
### [1.0.4](https://git.griefed.de/Griefed/VersionChecker/compare/1.0.3...1.0.4) (2022-02-03)
...
...
src/main/java/de/griefed/versionchecker/VersionChecker.java
View file @
b7b4b304
...
...
@@ -38,7 +38,8 @@ import java.util.List;
/**
* Baseclass from wich GitHub and GitLab checks extend. This class mainly provides the logic for comparing versions against
* each other to find out which is newer.
* each other to find out which is newer. Extend from this class if you want to implement your own checkers, for platforms
* like Gitea or anything else.
* @author Griefed
*/
public
abstract
class
VersionChecker
{
...
...
@@ -271,8 +272,6 @@ public abstract class VersionChecker {
}
}
protected
abstract
List
<
String
>
allVersions
();
/**
* Get the latest beta release.
* @author Griefed
...
...
@@ -361,7 +360,16 @@ public abstract class VersionChecker {
return
response
.
toString
();
}
public
abstract
void
refresh
()
throws
IOException
;
protected
ObjectMapper
getObjectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
objectMapper
.
enable
(
DeserializationFeature
.
ACCEPT_SINGLE_VALUE_AS_ARRAY
);
return
objectMapper
;
}
protected
abstract
List
<
String
>
allVersions
();
public
abstract
VersionChecker
refresh
()
throws
IOException
;
protected
void
setAllVersions
()
{
this
.
allVersions
=
allVersions
();
...
...
@@ -379,11 +387,4 @@ public abstract class VersionChecker {
public
abstract
List
<
String
>
getAssetsDownloadUrls
(
@NotNull
String
version
);
protected
ObjectMapper
getObjectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
objectMapper
.
enable
(
DeserializationFeature
.
ACCEPT_SINGLE_VALUE_AS_ARRAY
);
return
objectMapper
;
}
}
\ No newline at end of file
src/main/java/de/griefed/versionchecker/github/GitHubChecker.java
View file @
b7b4b304
...
...
@@ -36,7 +36,7 @@ import java.util.ArrayList;
import
java.util.List
;
/**
* Check a given repository
, by a given user,
for updates.<br>
* Check a given
GitHub
repository for updates.<br>
* Versions are checked for semantic-release-formatting. Meaning tags must look like the following examples:<br>
* 2.0.0<br>
* 2.1.1<br>
...
...
@@ -57,9 +57,10 @@ public class GitHubChecker extends VersionChecker {
private
JsonNode
latest
;
/**
* Constructor for the GitHub checker. Checks a given GitHub repositories versions and latest version, if available.
* 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 gitHubUserRepository String. GitHub user/repository
combination. For example <code>Griefed/ServerPackCreator</code>
* @param gitHubUserRepository String. GitHub
<code>
user/repository
</code>-
combination. For example <code>Griefed/ServerPackCreator</code>
* @throws MalformedURLException Thrown if the resulting URL is malformed or otherwise invalid.
*/
public
GitHubChecker
(
@NotNull
String
gitHubUserRepository
)
throws
MalformedURLException
{
...
...
@@ -67,11 +68,20 @@ public class GitHubChecker extends VersionChecker {
this
.
GITHUB_API_LATEST
=
new
URL
(
"https://api.github.com/repos/"
+
gitHubUserRepository
+
"/releases/latest"
);
}
/**
* Refresh this GitHub-instance. Refreshes repository information, the latest version, as well as a list of all available
* versions.
* @author Griefed
* @throws IOException Exception thrown if {@link #setRepository()} or {@link #setLatest()} encounter an error.
* @return This GitHub-instance.
*/
@Override
public
void
refresh
()
throws
IOException
{
public
GitHubChecker
refresh
()
throws
IOException
{
setRepository
();
setLatest
();
setAllVersions
();
return
this
;
}
/**
...
...
@@ -146,12 +156,22 @@ public class GitHubChecker extends VersionChecker {
return
"No URL found."
;
}
/**
* Acquire this instances repository information and store it in a {@link JsonNode} for later use.
* @author Griefed
* @throws IOException Thrown if the repository can not be reached or any other unexpected error occurs.
*/
@Override
protected
void
setRepository
()
throws
IOException
{
this
.
repository
=
getObjectMapper
().
readTree
(
getResponse
(
GITHUB_API
));
}
/**
* Acquires the latest version for this instances repository.
* @author Griefed
* @throws IOException Thrown if the repository can not be reached or any other unexpected error occurs.
*/
private
void
setLatest
()
throws
IOException
{
this
.
latest
=
getObjectMapper
().
readTree
(
getResponse
(
GITHUB_API_LATEST
));
}
...
...
src/main/java/de/griefed/versionchecker/gitlab/GitLabChecker.java
View file @
b7b4b304
...
...
@@ -36,7 +36,7 @@ import java.util.ArrayList;
import
java.util.List
;
/**
* Check a given repository
, by a given user,
for updates.<br>
* Check a given
GitLab
repository for updates.<br>
* Versions are checked for semantic-release-formatting. Meaning tags must look like the following examples:<br>
* 2.0.0<br>
* 2.1.1<br>
...
...
@@ -55,8 +55,8 @@ public class GitLabChecker extends VersionChecker {
private
JsonNode
repository
;
/**
* Construct
or for the
GitLab checker
. Checks
the given GitLab
repositories version and tries to acquire the latest version,
*
if available
.
* Construct
s a
GitLab checker
with
the given GitLab
-URL to allow for version checks as well as version and URL
*
acquisition
.
* @author Griefed
* @param repositoryUrl String. The full /api/v4-GitLab-repository-URL you want to check. Examples:<br>
* <code>https://gitlab.com/api/v4/projects/32677538/releases</code><br>
...
...
@@ -67,10 +67,18 @@ public class GitLabChecker extends VersionChecker {
this
.
GITLAB_API
=
new
URL
(
repositoryUrl
);
}
/**
* Refresh this GitLab-instance. Refreshes repository information and the list of all available versions.
* @author Griefed
* @throws IOException Exception thrown if {@link #setRepository()} encounters an error.
* @return This GitLab-instance.
*/
@Override
public
void
refresh
()
throws
IOException
{
public
GitLabChecker
refresh
()
throws
IOException
{
setRepository
();
setAllVersions
();
return
this
;
}
/**
...
...
src/test/java/de/griefed/versionchecker/UpdateCheckerTests.java
View file @
b7b4b304
...
...
@@ -26,34 +26,56 @@ public class UpdateCheckerTests {
@Test
void
checkForUpdates
()
{
refresh
();
Assertions
.
assertEquals
(
"No updates available."
,
checkForUpdate
());
}
public
UpdateCheckerTests
refresh
()
{
try
{
this
.
GITHUB
.
refresh
();
Assertions
.
assertNotNull
(
this
.
GITHUB
.
refresh
()
)
;
}
catch
(
Exception
ex
)
{
LOG
.
error
(
"Error refreshing GitHub."
,
ex
);
this
.
GITHUB
=
null
;
}
try
{
this
.
GITLAB
.
refresh
();
Assertions
.
assertNotNull
(
this
.
GITLAB
.
refresh
()
)
;
}
catch
(
Exception
ex
)
{
LOG
.
error
(
"Error refreshing GitLab."
,
ex
);
this
.
GITLAB
=
null
;
}
try
{
this
.
GITGRIEFED
.
refresh
();
Assertions
.
assertNotNull
(
this
.
GITGRIEFED
.
refresh
()
)
;
}
catch
(
Exception
ex
)
{
LOG
.
error
(
"Error refreshing GitGriefed."
,
ex
);
this
.
GITGRIEFED
=
null
;
}
return
this
;
if
(
GITHUB
!=
null
)
{
Assertions
.
assertNotNull
(
GITHUB
.
latestVersion
(
false
));
Assertions
.
assertNotNull
(
GITHUB
.
latestVersion
(
true
));
Assertions
.
assertNotNull
(
GITHUB
.
latestAlpha
());
Assertions
.
assertNotNull
(
GITHUB
.
latestBeta
());
GITHUB
.
allVersions
();
Assertions
.
assertNotNull
(
GITHUB
.
getDownloadUrl
(
"2.1.1"
));
Assertions
.
assertNotNull
(
GITHUB
.
getAssetsDownloadUrls
(
"2.1.1"
));
}
if
(
GITLAB
!=
null
)
{
Assertions
.
assertNotNull
(
GITLAB
.
latestVersion
(
false
));
Assertions
.
assertNotNull
(
GITLAB
.
latestVersion
(
true
));
Assertions
.
assertNotNull
(
GITLAB
.
latestAlpha
());
Assertions
.
assertNotNull
(
GITLAB
.
latestBeta
());
Assertions
.
assertNotNull
(
GITLAB
.
getDownloadUrl
(
"2.1.1"
));
Assertions
.
assertNotNull
(
GITLAB
.
getAssetsDownloadUrls
(
"2.1.1"
));
}
if
(
GITGRIEFED
!=
null
)
{
Assertions
.
assertNotNull
(
GITGRIEFED
.
latestVersion
(
false
));
Assertions
.
assertNotNull
(
GITGRIEFED
.
latestVersion
(
true
));
Assertions
.
assertNotNull
(
GITGRIEFED
.
latestAlpha
());
Assertions
.
assertNotNull
(
GITGRIEFED
.
latestBeta
());
Assertions
.
assertNotNull
(
GITGRIEFED
.
getDownloadUrl
(
"2.1.1"
));
Assertions
.
assertNotNull
(
GITGRIEFED
.
getAssetsDownloadUrls
(
"2.1.1"
));
}
Assertions
.
assertNotNull
(
checkForUpdate
());
}
public
String
checkForUpdate
()
{
String
updater
=
"No updates available."
;
String
updater
=
null
;
// Check GitHub for the most recent release.
if
(
GITHUB
!=
null
)
{
...
...
@@ -63,7 +85,7 @@ public class UpdateCheckerTests {
}
if
(
GITGRIEFED
!=
null
)
{
if
(
GITGRIEFED
!=
null
&&
updater
!=
null
)
{
// After checking GitLab, and we did not get a version, check GitGriefed.
// Check GitGriefed for new versions which are not pre-releases. Run with true to check pre-releases as well.
...
...
@@ -79,7 +101,7 @@ public class UpdateCheckerTests {
}
if
(
GITLAB
!=
null
)
{
if
(
GITLAB
!=
null
&&
updater
!=
null
)
{
// After checking GitGriefed, and we did not get a version, check GitLab.
// Check GitLab for new versions which are not pre-releases. Run with true to check pre-releases as well.
...
...