Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Hedtke, Moritz
AuD 2021 H05 Tests
Commits
04f940c5
Verified
Commit
04f940c5
authored
Jun 12, 2021
by
Daniel Mangold
Browse files
Switched to Semantic Versioning
parent
940b9152
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/h05/Utils.java
View file @
04f940c5
...
...
@@ -208,7 +208,7 @@ public class Utils {
Version
localVersion
=
new
Version
(
LOCAL_VERSION
),
remoteVersion
=
new
Version
(
remoteReader
.
readLine
());
if
(
remoteVersion
.
isNewerThan
(
localVersion
))
{
if
(
remoteVersion
.
compareTo
(
localVersion
)
>
0
)
{
System
.
out
.
println
(
"Update available! Local version: "
+
localVersion
+
" -- Remote version: "
+
remoteVersion
);
System
.
out
.
println
(
"Changelog: "
+
REPOSITORY_URL
+
"blob/master/changelog.md"
);
}
else
...
...
@@ -216,7 +216,7 @@ public class Utils {
for
(
String
line
=
remoteReader
.
readLine
();
(
CHECK_HASHES
||
(
AUTO_UPDATE
&&
remoteVersion
.
isNewerThan
(
localVersion
)))
&&
line
!=
null
&&
line
.
length
()
!=
0
;
(
CHECK_HASHES
||
(
AUTO_UPDATE
&&
remoteVersion
.
compareTo
(
localVersion
)
>
0
))
&&
line
!=
null
&&
line
.
length
()
!=
0
;
line
=
remoteReader
.
readLine
()
)
{
MessageDigest
messageDigest
=
MessageDigest
.
getInstance
(
"MD5"
);
...
...
@@ -299,29 +299,35 @@ public class Utils {
System
.
out
.
println
(
"unable to fetch file from repository"
);
}
private
static
class
Version
{
private
static
class
Version
implements
Comparable
<
Version
>
{
private
final
I
nt
eger
MAJOR_VERSION
,
MINOR_VERSION
;
private
final
i
nt
MAJOR_VERSION
,
MINOR_VERSION
,
PATCH_VERSION
;
private
Version
(
String
version
)
{
String
[]
versions
=
version
.
split
(
"\\."
);
MAJOR_VERSION
=
Integer
.
parseInt
(
versions
[
0
]);
MINOR_VERSION
=
Integer
.
parseInt
(
versions
[
1
]);
PATCH_VERSION
=
Integer
.
parseInt
(
versions
[
2
]);
}
/**
* Returns whether this Version is newer (higher version number) than the given one
* @param version the Version object to compare to
* @return {@code true} if this Version object is newer, {@code false} otherwise
*/
private
boolean
isNewerThan
(
Version
version
)
{
return
MAJOR_VERSION
>
version
.
MAJOR_VERSION
||
(
MAJOR_VERSION
.
equals
(
version
.
MAJOR_VERSION
)
&&
MINOR_VERSION
>
version
.
MINOR_VERSION
);
@Override
public
int
compareTo
(
Version
version
)
{
int
versionDiffMajor
=
MAJOR_VERSION
-
version
.
MAJOR_VERSION
,
versionDiffMinor
=
MINOR_VERSION
-
version
.
MINOR_VERSION
,
versionDiffPatch
=
PATCH_VERSION
-
version
.
PATCH_VERSION
;
if
(
versionDiffMajor
!=
0
)
return
versionDiffMajor
;
else
if
(
versionDiffMinor
!=
0
)
return
versionDiffMinor
;
else
return
versionDiffPatch
;
}
@Override
public
String
toString
()
{
return
MAJOR_VERSION
+
"."
+
MINOR_VERSION
;
return
MAJOR_VERSION
+
"."
+
MINOR_VERSION
+
"."
+
PATCH_VERSION
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment