Improve software updater
This commit is contained in:
parent
99913b6984
commit
cf860b3916
@ -1,5 +1,6 @@
|
||||
package net.sf.openrocket.communication;
|
||||
|
||||
import com.sun.istack.NotNull;
|
||||
import net.sf.openrocket.util.ArrayList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -7,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Class containing info about a GitHub release. All the info is stored in a JSON objects, retrieved using the GitHub
|
||||
@ -21,8 +23,8 @@ public class ReleaseInfo {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ReleaseInfo.class);
|
||||
|
||||
public ReleaseInfo(JsonObject obj) {
|
||||
this.obj = obj;
|
||||
public ReleaseInfo(@NotNull JsonObject obj) {
|
||||
this.obj = Objects.requireNonNull(obj, "JsonObject cannot be null");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,8 +32,6 @@ public class ReleaseInfo {
|
||||
* @return release name (e.g. "15.0.3")
|
||||
*/
|
||||
public String getReleaseName() {
|
||||
if (this.obj == null) return null;
|
||||
|
||||
String name = this.obj.get("tag_name").toString(); // Release label is encapsulated in the 'tag_name'-tag
|
||||
name = name.replaceAll("^\"+|\"+$", ""); // Remove double quotations in the beginning and end
|
||||
|
||||
@ -50,8 +50,9 @@ public class ReleaseInfo {
|
||||
* @return release notes (this is the text that explains a certain GitHub release)
|
||||
*/
|
||||
public String getReleaseNotes() {
|
||||
if (this.obj == null) return null;
|
||||
return this.obj.get("body").toString();
|
||||
String releaseNotes = this.obj.get("body").toString();
|
||||
releaseNotes = releaseNotes.replaceAll("^\"+|\"+$", ""); // Remove double quotations in the beginning and end
|
||||
return releaseNotes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,8 +60,9 @@ public class ReleaseInfo {
|
||||
* @return release URL (e.g. 'https://github.com/openrocket/openrocket/releases/tag/release-15.03')
|
||||
*/
|
||||
public String getReleaseURL() {
|
||||
if (this.obj == null) return null;
|
||||
return this.obj.get("html_url").toString();
|
||||
String releaseURL = this.obj.get("html_url").toString();
|
||||
releaseURL = releaseURL.replaceAll("^\"+|\"+$", ""); // Remove double quotations in the beginning and end
|
||||
return releaseURL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +70,6 @@ public class ReleaseInfo {
|
||||
* @return list of asset download URLs (e.g. 'https://github.com/openrocket/openrocket/releases/download/release-15.03/OpenRocket-15.03-installer.exe')
|
||||
*/
|
||||
public List<String> getAssetURLs() {
|
||||
if (this.obj == null) return null;
|
||||
List<String> assetURLs = new ArrayList<>();
|
||||
|
||||
JsonArray assets = this.obj.getJsonArray("assets");
|
||||
|
@ -282,10 +282,12 @@ public class UpdateInfoRetriever {
|
||||
* This function extracts all the release names that start with the specified preTag.
|
||||
* If preTag is null, the default release names without a pre-tag, starting with a number, are returned (e.g. '15.03').
|
||||
* @param names list of release names to filter
|
||||
* @param preTag pre-tag to filter the names on. If null, no special preTag filtering is applied
|
||||
* @param preTag pre-tag to filter the names on. If null, return all tags that start with a number
|
||||
* @return list of names starting with the preTag
|
||||
*/
|
||||
public List<String> filterReleasePreTag(List<String> names, String preTag) {
|
||||
public static List<String> filterReleasePreTag(List<String> names, String preTag) {
|
||||
if (names == null) return null;
|
||||
|
||||
List<String> filteredTags = new LinkedList<>();
|
||||
|
||||
// Filter out the names that are not related to the preTag
|
||||
@ -317,7 +319,7 @@ public class UpdateInfoRetriever {
|
||||
* @param tags filter tags
|
||||
* @return list of release names containing the filter tag
|
||||
*/
|
||||
public List<String> filterReleaseTags(List<String> names, String[] tags) {
|
||||
public static List<String> filterReleaseTags(List<String> names, String[] tags) {
|
||||
if (names == null) return null;
|
||||
if (tags == null) return names;
|
||||
return names.stream().filter(c -> Arrays.stream(tags)
|
||||
@ -330,7 +332,7 @@ public class UpdateInfoRetriever {
|
||||
* @param names list of release names to filter
|
||||
* @return list of release names that do not contain a devTag
|
||||
*/
|
||||
public List<String> filterOfficialRelease(List<String> names) {
|
||||
public static List<String> filterOfficialRelease(List<String> names) {
|
||||
if (names == null) return null;
|
||||
return names.stream().filter(c -> Arrays.stream(devTags.keySet().toArray(new String[0]))
|
||||
.noneMatch(c::contains)).collect(Collectors.toList());
|
||||
@ -346,7 +348,7 @@ public class UpdateInfoRetriever {
|
||||
* @param onlyOfficial bool to check whether to only include official (non-test) releases
|
||||
* @return latest JSON GitHub release object
|
||||
*/
|
||||
public JsonObject getLatestReleaseJSON(JsonArray jsonArr, String preTag, String[] tags, boolean onlyOfficial) throws UpdateCheckerException {
|
||||
public static JsonObject getLatestReleaseJSON(JsonArray jsonArr, String preTag, String[] tags, boolean onlyOfficial) throws UpdateCheckerException {
|
||||
if (jsonArr == null) return null;
|
||||
|
||||
JsonObject latestObj = null;
|
||||
|
@ -84,12 +84,10 @@ public class UpdateInfoDialog extends JDialog {
|
||||
|
||||
// Release notes
|
||||
String releaseNotes = release.getReleaseNotes();
|
||||
releaseNotes = releaseNotes.replaceAll("^\"|\"$", ""); // Remove leading and trailing quotations
|
||||
sb.append(MarkdownUtil.toHtml(releaseNotes)).append("<br><br>");
|
||||
|
||||
// GitHub link
|
||||
String releaseURL = release.getReleaseURL();
|
||||
releaseURL = releaseURL.replaceAll("^\"|\"$", ""); // Remove leading and trailing quotations
|
||||
sb.append(String.format("<a href='%s'>%s</a>", releaseURL, trans.get("update.dlg.updateAvailable.txtPane.readMore")));
|
||||
sb.append("</html>");
|
||||
textPane.addHyperlinkListener(new HyperlinkListener() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user