From 64e1bfef3617887df1c28c0350f0d74ab3c976e2 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 3 Nov 2016 10:36:52 -0400 Subject: [PATCH] clean up this maze of pretty version handling --- app/src/processing/app/Base.java | 2 +- .../app/contrib/AvailableContribution.java | 27 ++++++++++--------- .../processing/app/contrib/Contribution.java | 8 +++++- .../app/contrib/ContributionListing.java | 5 ++-- .../processing/app/contrib/DetailPanel.java | 11 ++++---- .../app/contrib/LocalContribution.java | 13 +++++---- .../processing/app/contrib/StatusPanel.java | 16 ++++++----- .../app/contrib/UpdateListPanel.java | 4 +-- todo.txt | 5 ++++ 9 files changed, 52 insertions(+), 39 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d246006ce..33d456d38 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -823,7 +823,7 @@ public class Base { String entry = c.getTypeName() + "=" + PApplet.urlEncode(String.format("name=%s\nurl=%s\nrevision=%d\nversion=%s", c.getName(), c.getUrl(), - c.getVersion(), c.getPrettyVersion())); + c.getVersion(), c.getBenignVersion())); entries.append(entry); } String joined = diff --git a/app/src/processing/app/contrib/AvailableContribution.java b/app/src/processing/app/contrib/AvailableContribution.java index 7d15eafb3..c36cffa8a 100644 --- a/app/src/processing/app/contrib/AvailableContribution.java +++ b/app/src/processing/app/contrib/AvailableContribution.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2013-15 The Processing Foundation + Copyright (c) 2013-16 The Processing Foundation Copyright (c) 2011-12 Ben Fry and Casey Reas This program is free software; you can redistribute it and/or modify @@ -49,9 +49,9 @@ public class AvailableContribution extends Contribution { imports = parseImports(params); name = params.get("name"); authors = params.get("authors"); - if (authors == null) { - authors = params.get("authorList"); - } +// if (authors == null) { +// authors = params.get("authorList"); +// } url = params.get("url"); sentence = params.get("sentence"); paragraph = params.get("paragraph"); @@ -62,6 +62,9 @@ public class AvailableContribution extends Contribution { } prettyVersion = params.get("prettyVersion"); + if (prettyVersion != null && prettyVersion.length() == 0) { + prettyVersion = null; + } String lastUpdatedStr = params.get("lastUpdated"); if (lastUpdatedStr != null) { @@ -231,9 +234,6 @@ public class AvailableContribution extends Contribution { * manager. However, it also ensures that valid fields in the properties file * aren't overwritten, since the properties file may be more recent than the * contributions.txt file. - * - * @param propFile - * @return */ public boolean writePropertiesFile(File propFile) { try { @@ -256,9 +256,9 @@ public class AvailableContribution extends Contribution { StringList importsList = parseImports(properties); String authors = properties.get(AUTHORS_PROPERTY); - if (authors == null) { - authors = properties.get("authorList"); // before 3.0a11 - } +// if (authors == null) { +// authors = properties.get("authorList"); // before 3.0a11 +// } if (authors == null || authors.isEmpty()) { authors = getAuthorList(); } @@ -283,13 +283,14 @@ public class AvailableContribution extends Contribution { version = Integer.parseInt(properties.get("version")); } catch (NumberFormatException e) { version = getVersion(); - System.err.println("The version number for “" + name + "” is not set properly."); + System.err.println("The version number for “" + name + "” is not a number."); System.err.println("Please contact the author to fix it according to the guidelines."); } String prettyVersion = properties.get("prettyVersion"); - if (prettyVersion == null || prettyVersion.isEmpty()) - prettyVersion = getPrettyVersion(); + if (prettyVersion != null && prettyVersion.isEmpty()) { + prettyVersion = null; + } String compatibleContribsList = null; if (getType() == ContributionType.EXAMPLES) { diff --git a/app/src/processing/app/contrib/Contribution.java b/app/src/processing/app/contrib/Contribution.java index 67c58789c..22a6e718a 100644 --- a/app/src/processing/app/contrib/Contribution.java +++ b/app/src/processing/app/contrib/Contribution.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2013-15 The Processing Foundation + Copyright (c) 2013-16 The Processing Foundation Copyright (c) 2011-12 Ben Fry and Casey Reas This program is free software; you can redistribute it and/or modify @@ -164,6 +164,12 @@ abstract public class Contribution { } + // returns prettyVersion, or "" if null + public String getBenignVersion() { + return (prettyVersion != null) ? prettyVersion : ""; + } + + // 1402805757 public long getLastUpdated() { return lastUpdated; diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index cf35ff628..5bae8d694 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2013-15 The Processing Foundation + Copyright (c) 2013-16 The Processing Foundation Copyright (c) 2011-12 Ben Fry and Casey Reas This program is free software; you can redistribute it and/or modify @@ -500,7 +500,7 @@ public class ContributionListing { } - protected String getLatestVersion(Contribution contribution) { + protected String getLatestPrettyVersion(Contribution contribution) { Contribution newestContrib = getAvailableContribution(contribution); if (newestContrib == null) { return null; @@ -509,7 +509,6 @@ public class ContributionListing { } - protected boolean hasDownloadedLatestList() { return listDownloaded; } diff --git a/app/src/processing/app/contrib/DetailPanel.java b/app/src/processing/app/contrib/DetailPanel.java index 4cf327165..69adc841e 100644 --- a/app/src/processing/app/contrib/DetailPanel.java +++ b/app/src/processing/app/contrib/DetailPanel.java @@ -460,9 +460,9 @@ class DetailPanel extends JPanel { } desc.append(" "); - String version = contrib.getPrettyVersion(); - if (version != null) { - desc.append(version); + String prettyVersion = contrib.getPrettyVersion(); + if (prettyVersion != null) { + desc.append(prettyVersion); } desc.append("
"); @@ -493,8 +493,9 @@ class DetailPanel extends JPanel { if (lastUpdatedUTC != 0) { DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); Date lastUpdatedDate = new Date(lastUpdatedUTC); - if (version != null && !version.isEmpty()) + if (prettyVersion != null) { desc.append(", "); + } desc.append("Last Updated on " + dateFormatter.format(lastUpdatedDate)); } @@ -510,7 +511,7 @@ class DetailPanel extends JPanel { // versionText.append("To finish an update, reinstall this contribution after restarting."); ; } else { - String latestVersion = contribListing.getLatestVersion(contrib); + String latestVersion = contribListing.getLatestPrettyVersion(contrib); if (latestVersion != null) { versionText.append("New version (" + latestVersion + ") available."); } else { diff --git a/app/src/processing/app/contrib/LocalContribution.java b/app/src/processing/app/contrib/LocalContribution.java index e2d27c9c4..0bfa6a988 100644 --- a/app/src/processing/app/contrib/LocalContribution.java +++ b/app/src/processing/app/contrib/LocalContribution.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2013-15 The Processing Foundation + Copyright (c) 2013-16 The Processing Foundation Copyright (c) 2011-12 Ben Fry and Casey Reas This program is free software; you can redistribute it and/or modify @@ -72,9 +72,9 @@ public abstract class LocalContribution extends Contribution { } // changing to 'authors' in 3.0a11 authors = properties.get(AUTHORS_PROPERTY); - if (authors == null) { - authors = properties.get("authorList"); - } +// if (authors == null) { +// authors = properties.get("authorList"); +// } url = properties.get("url"); sentence = properties.get("sentence"); paragraph = properties.get("paragraph"); @@ -86,10 +86,9 @@ public abstract class LocalContribution extends Contribution { System.err.println("Please contact the library author to fix it according to the guidelines."); } - // Use the version number if they've left the prettyVersion field blank prettyVersion = properties.get("prettyVersion"); - if (prettyVersion == null || prettyVersion.length() == 0) { - prettyVersion = Integer.toString(version); + if (prettyVersion != null && prettyVersion.length() == 0) { + prettyVersion = null; } try { diff --git a/app/src/processing/app/contrib/StatusPanel.java b/app/src/processing/app/contrib/StatusPanel.java index a048be660..4ad400d28 100644 --- a/app/src/processing/app/contrib/StatusPanel.java +++ b/app/src/processing/app/contrib/StatusPanel.java @@ -249,13 +249,13 @@ class StatusPanel extends JPanel { !panel.updateInProgress); String latestVersion = - contributionListing.getLatestVersion(panel.getContrib()); + contributionListing.getLatestPrettyVersion(panel.getContrib()); String currentVersion = panel.getContrib().getPrettyVersion(); - installButton.setEnabled(!panel.getContrib().isInstalled() - && contributionListing.hasDownloadedLatestList() - && panel.getContrib().isCompatible(Base.getRevision()) - && !panel.installInProgress); + installButton.setEnabled(!panel.getContrib().isInstalled() && + contributionListing.hasDownloadedLatestList() && + panel.getContrib().isCompatible(Base.getRevision()) && + !panel.installInProgress); if (panel.getContrib().isCompatible(Base.getRevision())) { if (installButton.isEnabled()) { @@ -285,9 +285,12 @@ class StatusPanel extends JPanel { latestVersion = "Update"; } + // why was this here? [fry 161103] + /* if (currentVersion == null) { currentVersion = ""; } + */ if (updateButton.isEnabled()) { updateButton.setText(latestVersion); @@ -295,8 +298,7 @@ class StatusPanel extends JPanel { updateButton.setText("Update"); } - removeButton.setEnabled(panel.getContrib().isInstalled() - && !panel.removeInProgress); + removeButton.setEnabled(panel.getContrib().isInstalled() && !panel.removeInProgress); progressPanel.add(panel.installProgressBar); progressPanel.setVisible(false); updateLabel.setVisible(true); diff --git a/app/src/processing/app/contrib/UpdateListPanel.java b/app/src/processing/app/contrib/UpdateListPanel.java index d03216a07..0995eb157 100644 --- a/app/src/processing/app/contrib/UpdateListPanel.java +++ b/app/src/processing/app/contrib/UpdateListPanel.java @@ -209,8 +209,8 @@ public class UpdateListPanel extends ListPanel { icon, "" + fontFace + entry.getName() + "", name, - entry.getPrettyVersion(), - contributionTab.contribListing.getLatestVersion(entry) + entry.getBenignVersion(), + contributionTab.contribListing.getLatestPrettyVersion(entry) }); } UpdateContributionTab tab = (UpdateContributionTab) contributionTab; diff --git a/todo.txt b/todo.txt index e3eb5e9dd..44c687d21 100755 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,11 @@ 0255 (3.2.3 or 3.3) X if prettyVersion is blank (or null?), just use version (Firmata) + // Use the version number if they've left the prettyVersion field blank + if (prettyVersion == null || prettyVersion.length() == 0) { + prettyVersion = Integer.toString(version); + } + contribs _ 'version' should be x.y or x.y.z, not some extra long string