Added a compatibleVersions field to properties,contrib

And the appropriate parsing of the field
This commit is contained in:
joelmoniz
2014-07-28 03:04:22 +04:00
committed by Joel Moniz
parent 424f50b1fe
commit 93b3110783
4 changed files with 116 additions and 4 deletions
@@ -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);
}
@@ -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; // <paragraph length description for site>
protected int version; // 102
protected String prettyVersion; // "1.0.2"
protected long lastUpdated; // 1402805757
protected long lastUpdated; // 1402805757
protected TreeMap<Integer, Integer> 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<Integer, Integer> 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<Integer, Integer> 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
* </br>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.
* </br>&emsp;&emsp;&emsp;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.</br>&emsp;&emsp;&emsp;The example above would return a
* TreeMap with the <key,value> pairs
* <222,222>, <225,225>, <227,229>,
* </br>&emsp;&emsp;&emsp;<230,(present_release_number)>.
*/
static TreeMap<Integer, Integer> parseCompatibleVersions(String compVerStr)
throws NumberFormatException {
if (compVerStr == null || compVerStr.equals(""))
return null;
String[] ranges = compVerStr.split(",");
TreeMap<Integer, Integer> compatibleTM = new TreeMap<Integer, Integer>();
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;
}
}
@@ -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);
@@ -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.