FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

cleanup of some contrib code, refactoring a bit · SourceCode/processing@99effdc · GitHub

Repository navigation

Commit 99effdc

Browse files
committed
cleanup of some contrib code, refactoring a bit
1 parent 7735135 commit 99effdc

8 files changed

Lines changed: 58 additions & 51 deletions

File tree

‎app/src/processing/app/Base.java‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,24 +2309,34 @@ static public byte[] loadBytesRaw(File file) throws IOException {
23092309
/**
23102310
* Read from a file with a bunch of attribute/value pairs
23112311
* that are separated by = and ignore comments with #.
2312+
* Changed in 3.0a6 to return null (rather than empty hash) if no file,
2313+
* and changed return type to Map instead of HashMap.
23122314
*/
2313-
static public HashMap<String,String> readSettings(File inputFile) {
2314-
HashMap<String,String> outgoing = new HashMap<String,String>();
2315-
if (inputFile.exists()) {
2316-
String lines[] = PApplet.loadStrings(inputFile);
2317-
readSettings(inputFile.toString(), lines, outgoing);
2315+
static public Map<String, String> readSettings(File inputFile) {
2316+
if (!inputFile.exists()) {
2317+
System.err.println(inputFile + " does not exist.");
2318+
return null;
23182319
}
2319-
return outgoing;
2320+
String lines[] = PApplet.loadStrings(inputFile);
2321+
if (lines == null) {
2322+
System.err.println("Could not read " + inputFile);
2323+
return null;
2324+
}
2325+
return readSettings(inputFile.toString(), lines);
23202326
}
23212327

23222328

23232329
/**
23242330
* Parse a String array that contains attribute/value pairs separated
23252331
* by = (the equals sign). The # (hash) symbol is used to denote comments.
23262332
* Comments can be anywhere on a line. Blank lines are ignored.
2333+
* In 3.0a6, no longer taking a blank HahMap as param; no cases in the main
2334+
* PDE code of adding to a (Hash)Map. Also returning the Map instead of void.
2335+
* Both changes modify the method signature, but this was only used by the
2336+
* contrib classes.
23272337
*/
2328-
static public void readSettings(String filename, String[] lines,
2329-
HashMap<String, String> settings) {
2338+
static public Map<String, String> readSettings(String filename, String[] lines) {
2339+
Map<String, String> settings = new HashMap<>();
23302340
for (String line : lines) {
23312341
// Remove comments
23322342
int commentMarker = line.indexOf('#');
@@ -2350,6 +2360,7 @@ static public void readSettings(String filename, String[] lines,
23502360
}
23512361
}
23522362
}
2363+
return settings;
23532364
}
23542365

23552366

‎app/src/processing/app/Library.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private Library(File folder, String groupName) {
113113
referenceFile = new File(folder, "reference/index.html");
114114

115115
File exportSettings = new File(libraryFolder, "export.txt");
116-
HashMap<String,String> exportTable = Base.readSettings(exportSettings);
116+
Map<String,String> exportTable = Base.readSettings(exportSettings);
117117

118118
exportList = new HashMap<String, String[]>();
119119

‎app/src/processing/app/contrib/AvailableContribution.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
package processing.app.contrib;
2323

2424
import java.io.*;
25-
import java.util.HashMap;
2625
import java.util.List;
26+
import java.util.Map;
2727

2828
import processing.app.Base;
2929
import processing.app.Language;
@@ -38,7 +38,7 @@ class AvailableContribution extends Contribution {
3838
protected final String link; // Direct link to download the file
3939

4040

41-
public AvailableContribution(ContributionType type, HashMap<String, String> params) {
41+
public AvailableContribution(ContributionType type, Map<String, String> params) {
4242
this.type = type;
4343
this.link = params.get("download");
4444

@@ -231,7 +231,7 @@ public ContributionType getType() {
231231
*/
232232
public boolean writePropertiesFile(File propFile) {
233233
try {
234-
HashMap<String, String> properties = Base.readSettings(propFile);
234+
Map<String, String> properties = Base.readSettings(propFile);
235235

236236
String name = properties.get("name");
237237
if (name == null || name.isEmpty())

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected Set<String> getCategories(ContributionFilter filter) {
218218

219219

220220
protected List<Contribution> getFilteredLibraryList(String category, List<String> filters) {
221-
ArrayList<Contribution> filteredList =
221+
ArrayList<Contribution> filteredList =
222222
new ArrayList<Contribution>(allContributions);
223223

224224
Iterator<Contribution> it = filteredList.iterator();
@@ -310,9 +310,9 @@ private boolean hasProperty(Contribution contrib, String property) {
310310

311311

312312
protected List<Contribution> getCompatibleContributionList(List<Contribution> filteredLibraries, boolean filter) {
313-
ArrayList<Contribution> filteredList =
313+
ArrayList<Contribution> filteredList =
314314
new ArrayList<Contribution>(filteredLibraries);
315-
315+
316316
if (!filter)
317317
return filteredList;
318318

@@ -417,7 +417,7 @@ boolean hasUpdates() {
417417
}
418418
return false;
419419
}
420-
420+
421421
boolean hasUpdates(Base base) {
422422
for (ModeContribution m : base.getModeContribs())
423423
if (hasUpdates(m))
@@ -459,7 +459,7 @@ else if (latestVersion.toLowerCase().startsWith("v")) // For ketai library
459459
else
460460
return null;
461461
}
462-
462+
463463

464464

465465
boolean hasDownloadedLatestList() {
@@ -479,7 +479,7 @@ boolean hasListDownloadFailed() {
479479
// return s.toLowerCase().replaceAll("^\\p{Lower}", "");
480480
// }
481481

482-
482+
483483
// /**
484484
// * @return the proper, valid name of this category to be displayed in the UI
485485
// * (e.g. "Typography / Geometry"). "Unknown" if the category null.
@@ -508,40 +508,31 @@ ArrayList<AvailableContribution> parseContribList(File file) {
508508

509509
int start = 0;
510510
while (start < lines.length) {
511-
// // Only consider 'invalid' lines. These lines contain the type of
512-
// // software: library, tool, mode
513-
// if (!lines[start].contains("=")) {
514511
String type = lines[start];
515512
ContributionType contribType = ContributionType.fromName(type);
516513
if (contribType == null) {
517514
System.err.println("Error in contribution listing file on line " + (start+1));
518515
// Scan forward for the next blank line
519516
int end = ++start;
520-
while (end < lines.length && !lines[end].equals("")) {
517+
while (end < lines.length && lines[end].trim().length() != 0) {
521518
end++;
522519
}
523520
start = end + 1;
524-
continue;
525-
}
526521

527-
// Scan forward for the next blank line
528-
int end = ++start;
529-
while (end < lines.length && !lines[end].equals("")) {
530-
end++;
531-
}
522+
} else {
523+
// Scan forward for the next blank line
524+
int end = ++start;
525+
while (end < lines.length && lines[end].trim().length() != 0) {
526+
end++;
527+
}
532528

533-
int length = end - start;
534-
String[] contribLines = new String[length];
535-
System.arraycopy(lines, start, contribLines, 0, length);
529+
String[] contribLines = PApplet.subset(lines, start, end-start);
536530

537-
HashMap<String,String> contribParams = new HashMap<String,String>();
538-
Base.readSettings(file.getName(), contribLines, contribParams);
531+
Map<String, String> contribParams = Base.readSettings(file.getName(), contribLines);
539532

540-
outgoing.add(new AvailableContribution(contribType, contribParams));
541-
start = end + 1;
542-
// } else {
543-
// start++;
544-
// }
533+
outgoing.add(new AvailableContribution(contribType, contribParams));
534+
start = end + 1;
535+
}
545536
}
546537
}
547538
return outgoing;

‎app/src/processing/app/contrib/ContributionManager.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ else if (type.equalsIgnoreCase("libraries")) //putting this here, just in case
497497
propFileName = "libraries.properties";
498498

499499
for (File folder : markedForUpdate) {
500-
HashMap<String, String> properties = Base
501-
.readSettings(new File(folder, propFileName));
500+
Map<String, String> properties =
501+
Base.readSettings(new File(folder, propFileName));
502502
updateContribsNames.add(properties.get("name"));
503503
Base.removeDir(folder);
504504
}

‎app/src/processing/app/contrib/LocalContribution.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public abstract class LocalContribution extends Contribution {
4646
protected String id; // 1 (unique id for this library)
4747
protected int latestVersion; // 103
4848
protected File folder;
49-
protected HashMap<String, String> properties;
49+
protected Map<String, String> properties;
5050
protected ClassLoader loader;
5151
protected List<String> specifiedImports; // mylib,mylib.util;
5252

‎core/todo.txt‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ _ static mode (no setup() / draw()) broken
2121
_ https://github.com/processing/processing/issues/3130
2222
_ Sketch window dimensions off in Java2D
2323
_ https://github.com/processing/processing/issues/3129
24+
_ fix? https://github.com/processing/processing/pull/3162
2425

2526
earlier
2627
X size(640,360 , P3D) doesn't work properly
@@ -209,7 +210,17 @@ _ https://github.com/processing/processing/issues/2030
209210
_ NPE when using image() created with createGraphics(PGraphicsRetina2D)
210211
_ https://github.com/processing/processing/issues/2510
211212

213+
212214
decisions/misc
215+
_ async requests
216+
_ Request r = createRequest("http://p5.org/feed/13134.jpg");
217+
_ Request r = createRequest("http://p5.org/feed/13134.jpg", "callbackName");
218+
_ Request r = createRequest("http://p5.org/feed/13134, "callbackName", "jpg");
219+
_ implement callbacks for images and other loadXxxx() functions
220+
_ remove requestImage() and friends
221+
_ callback for requestImage()
222+
_ https://github.com/processing/processing/issues/680
223+
_ remove/update requestImage example
213224
_ use enums for constants
214225
_ https://github.com/processing/processing/issues/2778
215226
_ make join() work with Iterable?
@@ -312,6 +323,7 @@ _ add Double and Long versions of the classes?
312323

313324

314325

326+
315327
////////////////////////////////////////////////////////////////////
316328
////////////////////////////////////////////////////////////////////
317329
////////////////////////////////////////////////////////////////////
@@ -864,12 +876,3 @@ _ put a Hash<Something> class in there
864876
_ will this work to sort by the values?
865877
_ there was another concern as well..
866878
_ save() should probably come out of image, ja?
867-
_ async requests
868-
_ Request r = createRequest("http://p5.org/feed/13134.jpg");
869-
_ Request r = createRequest("http://p5.org/feed/13134.jpg", "callbackName");
870-
_ Request r = createRequest("http://p5.org/feed/13134, "callbackName", "jpg");
871-
_ implement callbacks for images and other loadXxxx() functions
872-
_ remove requestImage() and friends
873-
_ callback for requestImage()
874-
_ http://code.google.com/p/processing/issues/detail?id=641
875-
_ remove/update requestImage example

‎todo.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ X https://github.com/processing/processing/pull/3061
5454
X contributions.txt now gets deleted and recreated instead of overwritten
5555
X https://github.com/processing/processing/pull/3073
5656
X https://github.com/processing/processing/issues/2994
57+
X Contrib Manager does not stop parsing contribs.txt if an error exists
58+
X https://github.com/processing/processing/pull/3132
5759

5860
manindra
5961
X Fix for "Probably a ++ should go here" messages

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL