Skip to content

Commit 71e31bc

Browse files
committed
working to handle how compatibility check happens
1 parent 5b8c8b1 commit 71e31bc

File tree

8 files changed

+65
-21
lines changed

8 files changed

+65
-21
lines changed

app/src/processing/app/Base.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ void rebuildContribModes() {
773773
contribModes = new ArrayList<>();
774774
}
775775
File modesFolder = getSketchbookModesFolder();
776-
List<ModeContribution> contribModes = getContribModes();
776+
List<ModeContribution> knownList = getContribModes();
777777

778778
Map<File, ModeContribution> known = new HashMap<>();
779-
for (ModeContribution contrib : contribModes) {
779+
for (ModeContribution contrib : knownList) {
780780
known.put(contrib.getFolder(), contrib);
781781
}
782782
File[] potential = ContributionType.MODE.listCandidates(modesFolder);
@@ -1599,7 +1599,7 @@ protected Editor handleOpenInternal(String path, boolean untitled) {
15991599
"while opening a new editor window. Please report this.", t, true);
16001600
} else {
16011601
Messages.showTrace("Mode Problems",
1602-
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
1602+
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
16031603
"It may not be compatible with this version of Processing.\n" +
16041604
"Try updating the Mode or contact its author for a new version.", t, false);
16051605
}

app/src/processing/app/contrib/Contribution.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.HashSet;
2727
import java.util.Set;
2828

29+
import processing.app.Base;
2930
import processing.core.PApplet;
3031
import processing.data.StringDict;
3132
import processing.data.StringList;
@@ -189,8 +190,9 @@ public int getMaxRevision() {
189190
}
190191

191192

192-
public boolean isCompatible(int versionNum) {
193-
return ((maxRevision == 0 || versionNum <= maxRevision) && versionNum >= minRevision);
193+
public boolean isCompatible() {
194+
final int revisionNum = Base.getRevision();
195+
return ((maxRevision == 0 || revisionNum <= maxRevision) && revisionNum >= minRevision);
194196
}
195197

196198

@@ -245,6 +247,7 @@ public StringDict loadProperties(File contribFolder) {
245247
*/
246248

247249

250+
/*
248251
static public StringDict loadProperties(File contribFolder,
249252
ContributionType type) {
250253
File propertiesFile = new File(contribFolder, type.getPropertiesName());
@@ -253,6 +256,7 @@ static public StringDict loadProperties(File contribFolder,
253256
}
254257
return null;
255258
}
259+
*/
256260

257261

258262
/**

app/src/processing/app/contrib/ContributionListing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ public boolean hasUpdates(Contribution contrib) {
306306
if (contrib.isInstalled()) {
307307
Contribution available = findAvailableContribution(contrib);
308308
return available != null &&
309-
(available.getVersion() > contrib.getVersion() &&
310-
available.isCompatible(Base.getRevision()));
309+
available.getVersion() > contrib.getVersion() &&
310+
available.isCompatible();
311311
}
312312
return false;
313313
}

app/src/processing/app/contrib/ContributionType.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import processing.app.Messages;
3232
import processing.app.Util;
3333
import processing.app.ui.Editor;
34+
import processing.core.PApplet;
35+
import processing.data.StringDict;
3436

3537

3638
public enum ContributionType {
@@ -69,6 +71,17 @@ public String getPropertiesName() {
6971
}
7072

7173

74+
public StringDict loadProperties(File contribFolder) {
75+
File propertiesFile = new File(contribFolder, getPropertiesName());
76+
if (propertiesFile.exists()) {
77+
return Util.readSettings(propertiesFile, false);
78+
} else {
79+
System.err.println("Not found: " + propertiesFile);
80+
}
81+
return null;
82+
}
83+
84+
7285
public File createTempFolder() throws IOException {
7386
return Util.createTempFolder(toString(), "tmp", getSketchbookFolder());
7487
}
@@ -116,7 +129,35 @@ public File getSketchbookFolder() {
116129
public boolean isCandidate(File potential) {
117130
return (potential.isDirectory() &&
118131
new File(potential, toString()).exists() &&
119-
!isTempFolderName(potential.getName()));
132+
!isTempFolderName(potential.getName()) &&
133+
isCompatible(potential));
134+
}
135+
136+
137+
/**
138+
* Whether this contrib is compatible with this revision of Processing.
139+
*/
140+
private boolean isCompatible(File contribFolder) {
141+
StringDict properties = loadProperties(contribFolder);
142+
if (properties != null) {
143+
final int revisionNum = Base.getRevision();
144+
145+
int minRevision = 0;
146+
String minRev = properties.get("minRevision");
147+
if (minRev != null) {
148+
minRevision = PApplet.parseInt(minRev, 0);
149+
}
150+
151+
int maxRevision = 0;
152+
String maxRev = properties.get("maxRevision");
153+
if (maxRev != null) {
154+
maxRevision = PApplet.parseInt(maxRev, 0);
155+
}
156+
157+
return ((maxRevision == 0 || revisionNum <= maxRevision) && revisionNum >= minRevision);
158+
}
159+
// Maybe it's ok, maybe it's not. Don't know him; can't vouch for him.
160+
return true;
120161
}
121162

122163

app/src/processing/app/contrib/ExamplesContribution.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ static public List<ExamplesContribution> loadAll(File examplesFolder) {
6060
}
6161

6262

63-
static public boolean isCompatible(Base base, StringDict props) {
64-
return isCompatible(base.getActiveEditor().getMode(), props);
63+
static public boolean isModeCompatible(Base base, StringDict props) {
64+
return isModeCompatible(base.getActiveEditor().getMode(), props);
6565
}
6666

6767

6868
/**
6969
* Determine whether the example is compatible with the current Mode.
7070
* @return true if compatible with the Mode of the currently active editor
7171
*/
72-
static public boolean isCompatible(Mode mode, StringDict props) {
72+
static public boolean isModeCompatible(Mode mode, StringDict props) {
7373
String currentIdentifier = mode.getIdentifier();
7474
StringList compatibleList = parseModeList(props);
7575
if (compatibleList.size() == 0) {

app/src/processing/app/contrib/ListPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Component prepareRenderer(TableCellRenderer renderer, int row, int column
103103
if (rowValue instanceof SectionHeaderContribution) {
104104
c.setBackground(sectionColor);
105105
} else if (isRowSelected(row)) {
106-
if (((Contribution) rowValue).isCompatible(Base.getRevision())) {
106+
if (((Contribution) rowValue).isCompatible()) {
107107
c.setBackground(selectionColor);
108108
} else {
109109
c.setBackground(selectionColorIncompatible);
@@ -238,7 +238,7 @@ private static int getContributionStatusRank(Contribution c) {
238238
if (ContributionListing.getInstance().hasUpdates(c)) {
239239
pos = 2;
240240
}
241-
if (!c.isCompatible(Base.getRevision())) {
241+
if (!c.isCompatible()) {
242242
// This is weird because it means some grayed-out items will
243243
// show up before non-gray items. We probably need another
244244
// state icon for 'installed but incompatible' [fry 220116]
@@ -387,7 +387,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
387387
if (contribution instanceof SectionHeaderContribution) {
388388
// grouping color for libraries, modes, tools headers in updates panel
389389
label.setForeground(textColorIncompatible);
390-
} else if (contribution.isCompatible(Base.getRevision())) {
390+
} else if (contribution.isCompatible()) {
391391
label.setForeground(textColor);
392392
} else {
393393
label.setForeground(textColorIncompatible);
@@ -405,7 +405,7 @@ private void configureStatusColumnLabel(JLabel label, Contribution contribution)
405405
// float amount = detail.getProgressAmount();
406406
// icon = (amount == -1) ? downloadingIcon : renderProgressIcon(amount);
407407
} else if (contribution.isInstalled()) {
408-
if (!contribution.isCompatible(Base.getRevision())) {
408+
if (!contribution.isCompatible()) {
409409
icon = incompatibleIcon;
410410
} else if (ContributionListing.getInstance().hasUpdates(contribution)) {
411411
icon = updateAvailableIcon;

app/src/processing/app/contrib/StatusPanel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import processing.app.laf.PdeProgressBarUI;
4646
import processing.app.ui.Theme;
4747
import processing.app.ui.Toolkit;
48-
import processing.app.Base;
4948
import processing.app.Platform;
5049

5150

@@ -414,10 +413,10 @@ protected void applyDetail(StatusDetail detail) {
414413

415414
installButton.setEnabled(!contrib.isInstalled() &&
416415
listing.isDownloaded() &&
417-
contrib.isCompatible(Base.getRevision()) &&
416+
contrib.isCompatible() &&
418417
!detail.installInProgress);
419418

420-
if (contrib.isCompatible(Base.getRevision())) {
419+
if (contrib.isCompatible()) {
421420
if (installButton.isEnabled()) {
422421
if (latestVersion != null) {
423422
updateLabel.setText(latestVersion + " available");

app/src/processing/app/ui/ExamplesFrame.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import processing.app.Platform;
5858
import processing.app.Preferences;
5959
import processing.app.SketchReference;
60-
import processing.app.contrib.Contribution;
6160
import processing.app.contrib.ContributionManager;
6261
import processing.app.contrib.ContributionType;
6362
import processing.app.contrib.ExamplesContribution;
@@ -350,9 +349,10 @@ protected DefaultMutableTreeNode buildContribTree() {
350349
if (folders != null) {
351350
for (File sub : folders) {
352351
StringDict props =
353-
Contribution.loadProperties(sub, ContributionType.EXAMPLES);
352+
//Contribution.loadProperties(sub, ContributionType.EXAMPLES);
353+
ContributionType.EXAMPLES.loadProperties(sub);
354354
if (props != null) {
355-
if (ExamplesContribution.isCompatible(base, props)) {
355+
if (ExamplesContribution.isModeCompatible(base, props)) {
356356
DefaultMutableTreeNode subNode =
357357
new DefaultMutableTreeNode(props.get("name"));
358358
if (base.addSketches(subNode, sub, true)) {

0 commit comments

Comments
 (0)