Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit 00d489e

Browse files
author
Explv
committed
Remove version from pom.xml. Now using a single version number store in the main script class. Display the version number in the GUI & in the log.
1 parent e87ac73 commit 00d489e

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
<groupId>org.explv.explv_osbot_manager</groupId>
88
<artifactId>explvs_aio</artifactId>
9-
<version>v3.1.12</version>
9+
10+
<!--
11+
The version is declared in the main script class. We do not define a version here to avoid
12+
having to update it in two places.
13+
-->
14+
<version>no-version</version>
15+
1016
<repositories>
1117
<repository>
1218
<id>local-repo</id>
@@ -100,6 +106,7 @@
100106
</descriptorRefs>
101107
<appendAssemblyId>false</appendAssemblyId>
102108
<outputDirectory>${user.home}/OSBot/Scripts/</outputDirectory>
109+
<finalName>explvs-aio</finalName>
103110
</configuration>
104111
<phase>package</phase>
105112
<goals>

src/main/java/gui/Gui.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import gui.task_list.TaskList;
77
import gui.utils.ColourScheme;
88
import org.json.simple.JSONObject;
9+
import script.AIO;
910
import tasks.Task;
1011
import tasks.TaskType;
1112
import util.file_managers.FontManager;
@@ -26,7 +27,7 @@ public class Gui {
2627

2728
public Gui() {
2829
gui = new JDialog();
29-
gui.setTitle("Explv's AIO");
30+
gui.setTitle("Explv's AIO " + AIO.VERSION);
3031
gui.setModal(true);
3132
gui.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
3233
gui.setBackground(ColourScheme.DIALOG_BACKGROUND_GREY);
@@ -39,7 +40,11 @@ public Gui() {
3940
titleLabel.setFont(FontManager.ROBOTO_REGULAR.deriveFont(Font.BOLD, 26));
4041
titleLabel.setForeground(ColourScheme.WHITE);
4142
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
42-
titleLabel.setText("<html><span color='#33b5e5'>Explv</span>'s AIO</html>");
43+
titleLabel.setText(
44+
String.format("<html><span color='#33b5e5'>Explv</span>'s AIO <span style='font-size:16'>%s</span></html>",
45+
AIO.VERSION
46+
)
47+
);
4348
mainPanel.add(titleLabel, BorderLayout.NORTH);
4449

4550
final JPanel controlsPanel = new StyledJPanel();

src/main/java/script/AIO.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@ScriptManifest(author = "Explv", name = "Explv's AIO " + AIO.VERSION, info = "AIO", version = 0, logo = "http://i.imgur.com/58Zz0fb.png")
2929
public class AIO extends Script {
3030

31-
static final String VERSION = "v3.1.12";
31+
public static final String VERSION = "v3.1.12";
3232

3333
private Gui gui;
3434
private Paint paint;
@@ -40,16 +40,17 @@ public class AIO extends Script {
4040

4141
@Override
4242
public void onStart() throws InterruptedException {
43-
VersionChecker versionChecker = new VersionChecker(VERSION);
43+
log("Current version: " + AIO.VERSION);
44+
log("Latest version: " + VersionChecker.getLatestVersion().orElse("not found!"));
4445

45-
if (!versionChecker.updateIsIgnored() && !versionChecker.isUpToDate()) {
46+
if (!VersionChecker.updateIsIgnored() && !VersionChecker.isUpToDate(AIO.VERSION)) {
4647
try {
4748
EventDispatchThreadRunner.runOnDispatchThread(
4849
() -> {
4950
int selectedOption = NewVersionDialog.showNewVersionDialog(getBot().getBotPanel());
5051

5152
if (selectedOption == 0) {
52-
versionChecker.ignoreUpdate();
53+
VersionChecker.ignoreUpdate();
5354
}
5455
},
5556
true

src/main/java/script/VersionChecker.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,30 @@ public class VersionChecker {
1717
public static final String GITHUB_RELEASES_URL = "https://github.com/Explv/Explvs-AIO/releases/";
1818
private static final String GITHUB_API_LATEST_RELEASE_URL = "https://api.github.com/repos/Explv/Explvs-AIO/releases/latest";
1919

20-
private final String currentVersion;
21-
private final String latestVersion;
20+
private static String latestVersion;
2221

23-
public VersionChecker(final String currentVersion) {
24-
this.currentVersion = currentVersion;
25-
latestVersion = getLatestVersion().orElse(currentVersion);
22+
public static Optional<String> getLatestVersion() {
23+
if (latestVersion == null) {
24+
latestVersion = getLatestVersionFromGitHub().orElse(null);
25+
}
26+
27+
return Optional.ofNullable(latestVersion);
28+
}
29+
30+
public static boolean updateIsIgnored() {
31+
String ignoreUpdateScriptVerProp = ScriptProperties.getProperty(ScriptProperties.IGNORE_UPDATE_SCRIPT_VER);
32+
return latestVersion.equals(ignoreUpdateScriptVerProp);
33+
}
34+
35+
public static void ignoreUpdate() {
36+
ScriptProperties.setProperty(ScriptProperties.IGNORE_UPDATE_SCRIPT_VER, latestVersion);
37+
}
38+
39+
public static boolean isUpToDate(final String currentVersion) {
40+
return currentVersion.equals(getLatestVersion().orElse(currentVersion));
2641
}
2742

28-
private static Optional<String> getLatestVersion() {
43+
private static Optional<String> getLatestVersionFromGitHub() {
2944
Optional<String> latestGitHubReleaseTagOpt = getLatestGitHubReleaseTag();
3045

3146
if (!latestGitHubReleaseTagOpt.isPresent()) {
@@ -65,17 +80,4 @@ private static Optional<JSONObject> getLatestGitHubReleaseJSON() {
6580
}
6681
return Optional.empty();
6782
}
68-
69-
public boolean updateIsIgnored() {
70-
String ignoreUpdateScriptVerProp = ScriptProperties.getProperty(ScriptProperties.IGNORE_UPDATE_SCRIPT_VER);
71-
return latestVersion.equals(ignoreUpdateScriptVerProp);
72-
}
73-
74-
public void ignoreUpdate() {
75-
ScriptProperties.setProperty(ScriptProperties.IGNORE_UPDATE_SCRIPT_VER, latestVersion);
76-
}
77-
78-
public boolean isUpToDate() {
79-
return currentVersion.equals(latestVersion);
80-
}
8183
}

0 commit comments

Comments
 (0)