mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Replaced compatibleVersions field with mix/maxRevision fields
This commit is contained in:
@@ -49,11 +49,14 @@ class AvailableContribution extends Contribution {
|
||||
url = params.get("url");
|
||||
sentence = params.get("sentence");
|
||||
paragraph = params.get("paragraph");
|
||||
|
||||
String versionStr = params.get("version");
|
||||
if (versionStr != null) {
|
||||
version = PApplet.parseInt(versionStr, 0);
|
||||
}
|
||||
|
||||
prettyVersion = params.get("prettyVersion");
|
||||
|
||||
String lastUpdatedStr = params.get("lastUpdated");
|
||||
if (lastUpdatedStr != null)
|
||||
try {
|
||||
@@ -61,11 +64,15 @@ class AvailableContribution extends Contribution {
|
||||
} catch (NumberFormatException e) {
|
||||
lastUpdated = 0;
|
||||
}
|
||||
try {
|
||||
compatibleVersions = parseCompatibleVersions(params.get("compatibleVersions"));
|
||||
|
||||
String minRev = params.get("minRevision");
|
||||
if (minRev != null) {
|
||||
minRevision = PApplet.parseInt(minRev, 0);
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
compatibleVersions = null;
|
||||
|
||||
String maxRev = params.get("maxRevision");
|
||||
if (maxRev != null) {
|
||||
maxRevision = PApplet.parseInt(maxRev, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,18 +300,24 @@ 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();
|
||||
}
|
||||
|
||||
int minRev;
|
||||
try {
|
||||
minRev = Integer.parseInt(properties.get("minRevision"));
|
||||
} catch (NumberFormatException e) {
|
||||
minRev = getMinRevision();
|
||||
System.err.println("The minimum compatible revision for the “" + name
|
||||
+ "” contribution is not set properly. Assuming minimum revision 0.");
|
||||
}
|
||||
else
|
||||
compatibleVersions = getCompatibleVersionsStr();
|
||||
|
||||
int maxRev;
|
||||
try {
|
||||
maxRev = Integer.parseInt(properties.get("maxRevision"));
|
||||
} catch (NumberFormatException e) {
|
||||
maxRev = getMaxRevision();
|
||||
System.err.println("The maximum compatible revision for the “" + name
|
||||
+ "” contribution is not set properly. Assuming maximum revision INF.");
|
||||
}
|
||||
|
||||
if (propFile.delete() && propFile.createNewFile() && propFile.setWritable(true)) {
|
||||
PrintWriter writer = PApplet.createWriter(propFile);
|
||||
@@ -318,7 +331,8 @@ class AvailableContribution extends Contribution {
|
||||
writer.println("version=" + version);
|
||||
writer.println("prettyVersion=" + prettyVersion);
|
||||
writer.println("lastUpdated=" + lastUpdated);
|
||||
writer.println("compatibleVersions=" + compatibleVersions);
|
||||
writer.println("minRevision=" + minRev);
|
||||
writer.println("maxRevision=" + maxRev);
|
||||
if (getType() == ContributionType.EXAMPLES_PACKAGE) {
|
||||
writer.println("compatibleModesList=" + compatibleContribsList);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,8 @@ 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;
|
||||
|
||||
|
||||
@@ -47,8 +44,9 @@ 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 TreeMap<Integer, Integer> compatibleVersions; // 216,220,226-229
|
||||
protected long lastUpdated; // 1402805757
|
||||
protected int minRevision; // 0
|
||||
protected int maxRevision; // 227
|
||||
|
||||
|
||||
// "Sound"
|
||||
@@ -132,40 +130,19 @@ abstract public class Contribution {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
public String getCompatibleVersionsStr() {
|
||||
if (compatibleVersions == null)
|
||||
return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<Integer, Integer> range : compatibleVersions.entrySet()) {
|
||||
if (range.getKey().equals(range.getValue())) {
|
||||
sb.append(range.getKey());
|
||||
sb.append(",");
|
||||
}
|
||||
else {
|
||||
sb.append(range.getKey());
|
||||
sb.append("-");
|
||||
sb.append(range.getValue());
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.deleteCharAt(sb.length()-1); // delete last comma
|
||||
return sb.toString();
|
||||
// 0
|
||||
public int getMinRevision() {
|
||||
return minRevision;
|
||||
}
|
||||
|
||||
|
||||
public TreeMap<Integer, Integer> getCompatibleVersions() {
|
||||
return compatibleVersions;
|
||||
// 227
|
||||
public int getMaxRevision() {
|
||||
return maxRevision;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCompatible(int versionNum) {
|
||||
if (compatibleVersions != null) {
|
||||
if (compatibleVersions.floorEntry(versionNum) != null
|
||||
&& versionNum <= compatibleVersions.floorEntry(versionNum).getValue()) {
|
||||
return true; }
|
||||
}
|
||||
return false;
|
||||
return ((maxRevision == 0 || versionNum < maxRevision) && versionNum > minRevision);
|
||||
}
|
||||
|
||||
|
||||
@@ -235,46 +212,4 @@ 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>   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>   The example above would return a
|
||||
* TreeMap with the <key,value> pairs
|
||||
* <222,222>, <225,225>, <227,229>,
|
||||
* </br>   <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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public class ContributionManagerDialog {
|
||||
// the calling editor, so updates can be applied
|
||||
Editor editor;
|
||||
String category;
|
||||
String compatibleContribType;
|
||||
boolean isCompatibilityFilter;
|
||||
ContributionListing contribListing;
|
||||
|
||||
@@ -65,6 +66,7 @@ public class ContributionManagerDialog {
|
||||
if (type == null) {
|
||||
title = Language.text("contrib.manager_title.update");
|
||||
filter = ContributionType.createUpdateFilter();
|
||||
compatibleContribType = "Updates";
|
||||
} else {
|
||||
if (type == ContributionType.MODE)
|
||||
title = Language.text("contrib.manager_title.mode");
|
||||
@@ -74,6 +76,11 @@ public class ContributionManagerDialog {
|
||||
title = Language.text("contrib.manager_title.library");
|
||||
|
||||
filter = type.createFilter();
|
||||
|
||||
if (type == ContributionType.LIBRARY)
|
||||
compatibleContribType = "Libraries";
|
||||
else
|
||||
compatibleContribType = type.getTitle() + "s";
|
||||
}
|
||||
contribListing = ContributionListing.getInstance();
|
||||
contributionListPanel = new ContributionListPanel(this, filter);
|
||||
@@ -229,10 +236,6 @@ public class ContributionManagerDialog {
|
||||
filterPanel.add(filterField);
|
||||
|
||||
filterPanel.add(Box.createHorizontalStrut(5));
|
||||
|
||||
String compatibleContribType = title.substring(0, title.indexOf(" "))
|
||||
.equalsIgnoreCase("Library") ? "Libraries" : (title.substring(0, title
|
||||
.indexOf(" ")) + "s");
|
||||
|
||||
final JCheckBox compatibleContrib = new JCheckBox("Show Only Compatible " + compatibleContribType);
|
||||
compatibleContrib.addItemListener(new ItemListener() {
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.zip.*;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.core.PApplet;
|
||||
|
||||
|
||||
/**
|
||||
@@ -81,19 +82,20 @@ public abstract class LocalContribution extends Contribution {
|
||||
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"));
|
||||
|
||||
String minRev = properties.get("minRevision");
|
||||
if (minRev != null) {
|
||||
minRevision = PApplet.parseInt(minRev, 0);
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
compatibleVersions = null;
|
||||
System.err
|
||||
.println("The format of the compatibleVersions field is incorrect for "
|
||||
+ name);
|
||||
|
||||
String maxRev = properties.get("maxRevision");
|
||||
if (maxRev != null) {
|
||||
maxRevision = PApplet.parseInt(maxRev, 0);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user