Skip to content

Commit 36e68da

Browse files
committed
went in for import issues, did much housecleaning (fixes processing#3403)
1 parent 9c95dd9 commit 36e68da

14 files changed

Lines changed: 401 additions & 327 deletions

app/src/processing/app/Base.java

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import processing.app.contrib.*;
4646
import processing.core.*;
47+
import processing.data.StringDict;
4748
import processing.data.StringList;
4849

4950

@@ -2398,7 +2399,7 @@ static public byte[] loadBytesRaw(File file) throws IOException {
23982399
* Changed in 3.0a6 to return null (rather than empty hash) if no file,
23992400
* and changed return type to Map instead of HashMap.
24002401
*/
2401-
static public Map<String, String> readSettings(File inputFile) {
2402+
static public StringDict readSettings(File inputFile) {
24022403
if (!inputFile.exists()) {
24032404
if (DEBUG) System.err.println(inputFile + " does not exist.");
24042405
return null;
@@ -2416,13 +2417,13 @@ static public Map<String, String> readSettings(File inputFile) {
24162417
* Parse a String array that contains attribute/value pairs separated
24172418
* by = (the equals sign). The # (hash) symbol is used to denote comments.
24182419
* Comments can be anywhere on a line. Blank lines are ignored.
2419-
* In 3.0a6, no longer taking a blank HahMap as param; no cases in the main
2420+
* In 3.0a6, no longer taking a blank HashMap as param; no cases in the main
24202421
* PDE code of adding to a (Hash)Map. Also returning the Map instead of void.
24212422
* Both changes modify the method signature, but this was only used by the
24222423
* contrib classes.
24232424
*/
2424-
static public Map<String, String> readSettings(String filename, String[] lines) {
2425-
Map<String, String> settings = new HashMap<>();
2425+
static public StringDict readSettings(String filename, String[] lines) {
2426+
StringDict settings = new StringDict();
24262427
for (String line : lines) {
24272428
// Remove comments
24282429
int commentMarker = line.indexOf('#');
@@ -2442,7 +2443,7 @@ static public Map<String, String> readSettings(String filename, String[] lines)
24422443
} else {
24432444
String attr = line.substring(0, equals).trim();
24442445
String valu = line.substring(equals + 1).trim();
2445-
settings.put(attr, valu);
2446+
settings.set(attr, valu);
24462447
}
24472448
}
24482449
}
@@ -2797,8 +2798,9 @@ static public String contentsToClassPath(File folder) {
27972798
* @param path the input classpath
27982799
* @return array of possible package names
27992800
*/
2800-
static public String[] packageListFromClassPath(String path) {
2801-
Map<String, Object> map = new HashMap<String, Object>();
2801+
static public StringList packageListFromClassPath(String path) {
2802+
// Map<String, Object> map = new HashMap<String, Object>();
2803+
StringList list = new StringList();
28022804
String pieces[] =
28032805
PApplet.split(path, File.pathSeparatorChar);
28042806

@@ -2809,32 +2811,35 @@ static public String[] packageListFromClassPath(String path) {
28092811
if (pieces[i].toLowerCase().endsWith(".jar") ||
28102812
pieces[i].toLowerCase().endsWith(".zip")) {
28112813
//System.out.println("checking " + pieces[i]);
2812-
packageListFromZip(pieces[i], map);
2814+
packageListFromZip(pieces[i], list);
28132815

28142816
} else { // it's another type of file or directory
28152817
File dir = new File(pieces[i]);
28162818
if (dir.exists() && dir.isDirectory()) {
2817-
packageListFromFolder(dir, null, map);
2819+
packageListFromFolder(dir, null, list);
28182820
//importCount = magicImportsRecursive(dir, null,
28192821
// map);
28202822
//imports, importCount);
28212823
}
28222824
}
28232825
}
2824-
int mapCount = map.size();
2825-
String output[] = new String[mapCount];
2826-
int index = 0;
2827-
Set<String> set = map.keySet();
2828-
for (String s : set) {
2829-
output[index++] = s.replace('/', '.');
2826+
// int mapCount = map.size();
2827+
// String output[] = new String[mapCount];
2828+
// int index = 0;
2829+
// Set<String> set = map.keySet();
2830+
// for (String s : set) {
2831+
// output[index++] = s.replace('/', '.');
2832+
// }
2833+
// return output;
2834+
StringList outgoing = new StringList(list.size());
2835+
for (String item : list) {
2836+
outgoing.append(item.replace('/', '.'));
28302837
}
2831-
//System.arraycopy(imports, 0, output, 0, importCount);
2832-
//PApplet.printarr(output);
2833-
return output;
2838+
return outgoing;
28342839
}
28352840

28362841

2837-
static private void packageListFromZip(String filename, Map<String, Object> map) {
2842+
static private void packageListFromZip(String filename, StringList list) {
28382843
try {
28392844
ZipFile file = new ZipFile(filename);
28402845
Enumeration entries = file.entries();
@@ -2849,9 +2854,10 @@ static private void packageListFromZip(String filename, Map<String, Object> map)
28492854
if (slash == -1) continue;
28502855

28512856
String pname = name.substring(0, slash);
2852-
if (map.get(pname) == null) {
2853-
map.put(pname, new Object());
2854-
}
2857+
// if (map.get(pname) == null) {
2858+
// map.put(pname, new Object());
2859+
// }
2860+
list.appendUnique(pname);
28552861
}
28562862
}
28572863
}
@@ -2870,10 +2876,8 @@ static private void packageListFromZip(String filename, Map<String, Object> map)
28702876
* walk down into that folder and continue.
28712877
*/
28722878
static private void packageListFromFolder(File dir, String sofar,
2873-
Map<String, Object> map) {
2874-
//String imports[],
2875-
//int importCount) {
2876-
//System.err.println("checking dir '" + dir + "'");
2879+
StringList list) {
2880+
// Map<String, Object> map) {
28772881
boolean foundClass = false;
28782882
String files[] = dir.list();
28792883

@@ -2884,15 +2888,16 @@ static private void packageListFromFolder(File dir, String sofar,
28842888
if (sub.isDirectory()) {
28852889
String nowfar =
28862890
(sofar == null) ? files[i] : (sofar + "." + files[i]);
2887-
packageListFromFolder(sub, nowfar, map);
2891+
packageListFromFolder(sub, nowfar, list);
28882892
//System.out.println(nowfar);
28892893
//imports[importCount++] = nowfar;
28902894
//importCount = magicImportsRecursive(sub, nowfar,
28912895
// imports, importCount);
28922896
} else if (!foundClass) { // if no classes found in this folder yet
28932897
if (files[i].endsWith(".class")) {
28942898
//System.out.println("unique class: " + files[i] + " for " + sofar);
2895-
map.put(sofar, new Object());
2899+
// map.put(sofar, new Object());
2900+
list.appendUnique(sofar);
28962901
foundClass = true;
28972902
}
28982903
}

app/src/processing/app/Library.java

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import processing.app.contrib.*;
77
import processing.core.*;
8+
import processing.data.StringDict;
9+
import processing.data.StringList;
810

911

1012
public class Library extends LocalContribution {
@@ -23,7 +25,7 @@ public class Library extends LocalContribution {
2325
protected String group;
2426

2527
/** Packages provided by this library. */
26-
String[] packageList;
28+
StringList packageList;
2729

2830
/** Per-platform exports for this library. */
2931
HashMap<String,String[]> exportList;
@@ -113,8 +115,8 @@ private Library(File folder, String groupName) {
113115
referenceFile = new File(folder, "reference/index.html");
114116

115117
File exportSettings = new File(libraryFolder, "export.txt");
116-
Map<String, String> exportTable = exportSettings.exists() ?
117-
Base.readSettings(exportSettings) : new HashMap<String, String>();
118+
StringDict exportTable = exportSettings.exists() ?
119+
Base.readSettings(exportSettings) : new StringDict();
118120

119121
exportList = new HashMap<String, String[]>();
120122

@@ -437,23 +439,23 @@ public boolean accept(File dir, String name) {
437439
};
438440

439441

440-
static public ArrayList<File> discover(File folder) {
441-
ArrayList<File> libraries = new ArrayList<File>();
442-
discover(folder, libraries);
443-
return libraries;
444-
}
445-
446-
447-
static public void discover(File folder, ArrayList<File> libraries) {
448-
String[] list = folder.list(junkFolderFilter);
442+
static public List<File> discover(File folder) {
443+
List<File> libraries = new ArrayList<File>();
444+
// discover(folder, libraries);
445+
// return libraries;
446+
// }
447+
//
448+
//
449+
// static void discover(File folder, List<File> libraries) {
450+
String[] folderNames = folder.list(junkFolderFilter);
449451

450452
// if a bad folder or something like that, this might come back null
451-
if (list != null) {
453+
if (folderNames != null) {
452454
// alphabetize list, since it's not always alpha order
453455
// replaced hella slow bubble sort with this feller for 0093
454-
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
456+
Arrays.sort(folderNames, String.CASE_INSENSITIVE_ORDER);
455457

456-
for (String potentialName : list) {
458+
for (String potentialName : folderNames) {
457459
File baseFolder = new File(folder, potentialName);
458460
File libraryFolder = new File(baseFolder, "library");
459461
File libraryJar = new File(libraryFolder, potentialName + ".jar");
@@ -476,39 +478,45 @@ static public void discover(File folder, ArrayList<File> libraries) {
476478
}
477479
}
478480
}
479-
}
480-
481-
482-
static protected ArrayList<Library> list(File folder) {
483-
ArrayList<Library> libraries = new ArrayList<Library>();
484-
list(folder, libraries);
485481
return libraries;
486482
}
487483

488484

489-
static protected void list(File folder, ArrayList<Library> libraries) {
490-
ArrayList<File> librariesFolders = new ArrayList<File>();
491-
discover(folder, librariesFolders);
485+
static public List<Library> list(File folder) {
486+
List<Library> libraries = new ArrayList<Library>();
487+
// list(folder, libraries);
488+
// return libraries;
489+
// }
490+
//
491+
//
492+
// static void list(File folder, List<Library> libraries) {
493+
List<File> librariesFolders = new ArrayList<File>();
494+
librariesFolders.addAll(discover(folder));
492495

493496
for (File baseFolder : librariesFolders) {
494497
libraries.add(new Library(baseFolder));
495498
}
496499

497-
String[] list = folder.list(junkFolderFilter);
498-
if (list != null) {
499-
for (String subfolderName : list) {
500+
// Support libraries inside of one level of subfolders? I believe this was
501+
// the compromise for supporting library groups, but probably a bad idea
502+
// because it's not compatible with the Manager.
503+
String[] folderNames = folder.list(junkFolderFilter);
504+
if (folderNames != null) {
505+
for (String subfolderName : folderNames) {
500506
File subfolder = new File(folder, subfolderName);
501507

502508
if (!librariesFolders.contains(subfolder)) {
503-
ArrayList<File> discoveredLibFolders = new ArrayList<File>();
504-
discover(subfolder, discoveredLibFolders);
509+
// ArrayList<File> discoveredLibFolders = new ArrayList<File>();
510+
// discover(subfolder, discoveredLibFolders);
511+
List<File> discoveredLibFolders = discover(subfolder);
505512

506513
for (File discoveredFolder : discoveredLibFolders) {
507514
libraries.add(new Library(discoveredFolder, subfolderName));
508515
}
509516
}
510517
}
511518
}
519+
return libraries;
512520
}
513521

514522

app/src/processing/app/Mode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.awt.image.WritableRaster;
3030
import java.io.*;
3131
import java.util.*;
32+
import java.util.List;
3233

3334
import javax.swing.*;
3435
import javax.swing.border.Border;
@@ -76,8 +77,8 @@ public abstract class Mode {
7677

7778
protected File examplesContribFolder;
7879

79-
public ArrayList<Library> coreLibraries;
80-
public ArrayList<Library> contribLibraries;
80+
public List<Library> coreLibraries;
81+
public List<Library> contribLibraries;
8182

8283
/** Library folder for core. (Used for OpenGL in particular.) */
8384
protected Library coreLibrary;

0 commit comments

Comments
 (0)