Skip to content

Commit a6519e6

Browse files
authored
Merge pull request #236 from J3fftw1/chore/pull-version-from-blob-build
2 parents 99381b2 + 92c83e4 commit a6519e6

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

dough-updater/src/main/java/io/github/bakedlibs/dough/updater/AbstractPluginUpdater.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.bukkit.Bukkit;
1212
import org.bukkit.plugin.Plugin;
1313

14+
import io.github.bakedlibs.dough.versions.PrefixedVersion;
1415
import io.github.bakedlibs.dough.versions.Version;
1516

1617
abstract class AbstractPluginUpdater<V extends Version> implements PluginUpdater<V> {
@@ -79,4 +80,16 @@ protected void scheduleAsyncUpdateTask(@Nonnull UpdaterTask<V> task) {
7980
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, task);
8081
}
8182

83+
@ParametersAreNonnullByDefault
84+
@Nonnull
85+
protected static PrefixedVersion extractBuild(String prefix, Plugin plugin) {
86+
String pluginVersion = plugin.getDescription().getVersion();
87+
88+
if (pluginVersion.startsWith(prefix)) {
89+
int version = Integer.parseInt(pluginVersion.substring(prefix.length()).split(" ")[0], 10);
90+
return new PrefixedVersion(prefix, version);
91+
} else {
92+
throw new IllegalArgumentException("Not a valid build version: " + pluginVersion);
93+
}
94+
}
8295
}

dough-updater/src/main/java/io/github/bakedlibs/dough/updater/BlobBuildUpdater.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.net.URL;
1414
import java.util.logging.Level;
1515

16-
// TODO: add a way to get the current version.
1716
// TODO: checksum checking.
1817
public class BlobBuildUpdater extends AbstractPluginUpdater<PrefixedVersion> {
1918

@@ -28,7 +27,7 @@ public BlobBuildUpdater(@Nonnull Plugin plugin, @Nonnull File file, @Nonnull Str
2827
}
2928

3029
public BlobBuildUpdater(@Nonnull Plugin plugin, @Nonnull File file, @Nonnull String project, @Nonnull String releaseChannel) {
31-
super(plugin, file, new PrefixedVersion(releaseChannel, 0));
30+
super(plugin, file, extractBuild(releaseChannel + " - ", plugin));
3231

3332
this.project = project;
3433
this.releaseChannel = releaseChannel;
@@ -54,7 +53,7 @@ public UpdateInfo parse(String result) throws MalformedURLException, URISyntaxEx
5453
int latestVersion = data.get("build_id").getAsInt();
5554
URL downloadURL = new URI(data.get("file_download_url").getAsString()).toURL();
5655

57-
return new UpdateInfo(downloadURL, new PrefixedVersion(releaseChannel, latestVersion));
56+
return new UpdateInfo(downloadURL, new PrefixedVersion(releaseChannel + " - ", latestVersion));
5857
}
5958
});
6059
} catch (MalformedURLException | URISyntaxException e ) {

dough-updater/src/main/java/io/github/bakedlibs/dough/updater/GitHubBuildsUpdater.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.logging.Level;
77

88
import javax.annotation.Nonnull;
9-
import javax.annotation.ParametersAreNonnullByDefault;
109

1110
import org.bukkit.plugin.Plugin;
1211

@@ -34,18 +33,6 @@ public GitHubBuildsUpdater(@Nonnull Plugin plugin, @Nonnull File file, @Nonnull
3433
this.prefix = prefix;
3534
}
3635

37-
@ParametersAreNonnullByDefault
38-
private static @Nonnull PrefixedVersion extractBuild(String prefix, Plugin plugin) {
39-
String pluginVersion = plugin.getDescription().getVersion();
40-
41-
if (pluginVersion.startsWith(prefix)) {
42-
int version = Integer.parseInt(pluginVersion.substring(prefix.length()).split(" ")[0], 10);
43-
return new PrefixedVersion(prefix, version);
44-
} else {
45-
throw new IllegalArgumentException("Not a valid build version: " + pluginVersion);
46-
}
47-
}
48-
4936
@Override
5037
public void start() {
5138
try {

0 commit comments

Comments
 (0)