From 93b311078330d133ddfa07517e7f526276cbf26e Mon Sep 17 00:00:00 2001 From: joelmoniz Date: Mon, 28 Jul 2014 03:04:22 +0400 Subject: [PATCH] Added a compatibleVersions field to properties,contrib And the appropriate parsing of the field --- .../app/contrib/AvailableContribution.java | 21 ++++- .../processing/app/contrib/Contribution.java | 84 ++++++++++++++++++- .../contrib/ContributionManagerDialog.java | 2 +- .../app/contrib/LocalContribution.java | 13 ++- 4 files changed, 116 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/contrib/AvailableContribution.java b/app/src/processing/app/contrib/AvailableContribution.java index 39b1cb1b0..457c9f61b 100644 --- a/app/src/processing/app/contrib/AvailableContribution.java +++ b/app/src/processing/app/contrib/AvailableContribution.java @@ -1,4 +1,4 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* Part of the Processing project - http://processing.org @@ -61,6 +61,12 @@ class AvailableContribution extends Contribution { } catch (NumberFormatException e) { lastUpdated = 0; } + try { + compatibleVersions = parseCompatibleVersions(params.get("compatibleVersions")); + } + catch (NumberFormatException nfe) { + compatibleVersions = null; + } } @@ -287,6 +293,18 @@ class AvailableContribution extends Contribution { // System.err // .println("Please contact the author to fix it according to the guidelines."); } + + String compatibleVersions = properties.get("compatibleVersions"); + if (compatibleVersions != null && !compatibleVersions.isEmpty()) { + try { + parseCompatibleVersions(compatibleVersions); + } + catch (NumberFormatException nfe) { + compatibleVersions = getCompatibleVersionsStr(); + } + } + else + compatibleVersions = getCompatibleVersionsStr(); if (propFile.delete() && propFile.createNewFile() && propFile.setWritable(true)) { PrintWriter writer = PApplet.createWriter(propFile); @@ -300,6 +318,7 @@ class AvailableContribution extends Contribution { writer.println("version=" + version); writer.println("prettyVersion=" + prettyVersion); writer.println("lastUpdated=" + lastUpdated); + writer.println("compatibleVersions=" + compatibleVersions); if (getType() == ContributionType.EXAMPLES_PACKAGE) { writer.println("compatibleModesList=" + compatibleContribsList); } diff --git a/app/src/processing/app/contrib/Contribution.java b/app/src/processing/app/contrib/Contribution.java index 451ab7d4e..010d5db55 100644 --- a/app/src/processing/app/contrib/Contribution.java +++ b/app/src/processing/app/contrib/Contribution.java @@ -24,8 +24,11 @@ package processing.app.contrib; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.TreeMap; import processing.app.Language; +import processing.app.Base; import processing.core.PApplet; @@ -44,7 +47,8 @@ abstract public class Contribution { protected String paragraph; // protected int version; // 102 protected String prettyVersion; // "1.0.2" - protected long lastUpdated; // 1402805757 + protected long lastUpdated; // 1402805757 + protected TreeMap compatibleVersions; // 216,220,226-229 // "Sound" @@ -129,6 +133,42 @@ abstract public class Contribution { } + public String getCompatibleVersionsStr() { + if (compatibleVersions == null) + return ""; + StringBuilder sb = new StringBuilder(); + sb.append(""); + for (Map.Entry range : compatibleVersions.entrySet()) { + if (range.getKey() == range.getValue()) { + sb.append(range.getKey()); + sb.append(","); + } + else { + sb.append(range.getKey()); + sb.append("-"); + sb.append(range.getValue()); + } + } + sb.deleteCharAt(sb.length()-1); // delete last comma + return sb.toString(); + } + + + public TreeMap getCompatibleVersions() { + return compatibleVersions; + } + + + public boolean isCompatible(int versionNum) { + if (compatibleVersions != null) { + if (compatibleVersions.ceilingEntry(versionNum) != null + && versionNum <= compatibleVersions.ceilingEntry(versionNum).getValue()) + return true; + } + return false; + } + + abstract public ContributionType getType(); @@ -195,4 +235,46 @@ abstract public class Contribution { } return outgoing; } + + + /** + * @param compVerStr + *
A string consisting of a comma separated list of numbers. + * Ranges may be indicated by hyphens between 2 numbers. Open ranges + * may be indicated by leaving the right side of the last hyphen + * blank. + *
   For example, "222,225,227-229,230-" + * is valid. + * @return A TreeMap consisting of integer-integer key-value pairs that + * represent ranges for which the contribution has been + * tested.
   The example above would return a + * TreeMap with the pairs + * <222,222>, <225,225>, <227,229>, + *
   <230,(present_release_number)>. + */ + static TreeMap parseCompatibleVersions(String compVerStr) + throws NumberFormatException { + if (compVerStr == null || compVerStr.equals("")) + return null; + String[] ranges = compVerStr.split(","); + TreeMap compatibleTM = new TreeMap(); + for (String range : ranges) { + range = range.trim(); + if (range.indexOf("-") != -1) { + int key = Integer.parseInt(range.substring(0, range.indexOf("-")) + .trim()); + int value; + if (((range.indexOf("-") + 1) >= range.length()) + || range.substring(range.indexOf("-") + 1).trim().isEmpty()) { + value = Base.getRevision(); + } + else + value = Integer.parseInt(range.substring(range.indexOf("-") + 1) + .trim()); + compatibleTM.put(key, value); + } else + compatibleTM.put(Integer.parseInt(range), Integer.parseInt(range)); + } + return compatibleTM; + } } diff --git a/app/src/processing/app/contrib/ContributionManagerDialog.java b/app/src/processing/app/contrib/ContributionManagerDialog.java index 865676f41..7b5ea93ab 100644 --- a/app/src/processing/app/contrib/ContributionManagerDialog.java +++ b/app/src/processing/app/contrib/ContributionManagerDialog.java @@ -238,7 +238,7 @@ public class ContributionManagerDialog { @Override public void itemStateChanged(ItemEvent arg0) { - System.out.println("Here"); + System.out.println(Base.getRevision()); } }); filterPanel.add(compatibleContrib); diff --git a/app/src/processing/app/contrib/LocalContribution.java b/app/src/processing/app/contrib/LocalContribution.java index 1cedbd652..892cecfb3 100644 --- a/app/src/processing/app/contrib/LocalContribution.java +++ b/app/src/processing/app/contrib/LocalContribution.java @@ -74,17 +74,28 @@ public abstract class LocalContribution extends Contribution { System.err.println("The version number for the “" + name + "” library is not set properly."); System.err.println("Please contact the library author to fix it according to the guidelines."); } + prettyVersion = properties.get("prettyVersion"); + try { lastUpdated = Long.parseLong(properties.get("lastUpdated")); } catch (NumberFormatException e) { lastUpdated = 0; - // Better comment these out till all contribs have a lastUpdated // System.err.println("The last updated timestamp for the “" + name + "” library is not set properly."); // System.err.println("Please contact the library author to fix it according to the guidelines."); } + try { + compatibleVersions = parseCompatibleVersions(properties.get("compatibleVersions")); + } + catch (NumberFormatException nfe) { + compatibleVersions = null; + System.err + .println("The format of the compatibleVersions field is incorrect for " + + name); + } + } else { Base.log("No properties file at " + propertiesFile.getAbsolutePath()); // We'll need this to be set at a minimum.