FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/Library.java at master · botbit/processing · GitHub
botbit
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Library.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
540 lines (436 loc) · 17.7 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Library.java
Copy path
File metadata and controls
540 lines (436 loc) · 17.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
package
processing
.
app
;
import
java
.
io
.*;
import
java
.
util
.*;
import
processing
.
app
.
contrib
.*;
import
processing
.
core
.*;
public
class
Library
extends
LocalContribution
{
static
final
String
[]
platformNames
=
PConstants
.
platformNames
;
//protected File folder; // /path/to/shortname
protected
File
libraryFolder
;
// shortname/library
protected
File
examplesFolder
;
// shortname/examples
protected
File
referenceFile
;
// shortname/reference/index.html
/**
* Subfolder for grouping libraries in a menu. Basic subfolder support
* is provided so that some organization can be done in the import menu.
* (This is the replacement for the "library compilation" type.)
*/
protected
String
group
;
/** Packages provided by this library. */
String
[]
packageList
;
/** Per-platform exports for this library. */
HashMap
<
String
,
String
[]>
exportList
;
/** Applet exports (cross-platform by definition). */
String
[]
appletExportList
;
/** Android exports (single platform for now, may not exist). */
String
[]
androidExportList
;
/** True if there are separate 32/64 bit for the specified platform index. */
boolean
[]
multipleArch
=
new
boolean
[
platformNames
.
length
];
/**
* For runtime, the native library path for this platform. e.g. on Windows 64,
* this might be the windows64 subfolder with the library.
*/
String
nativeLibraryPath
;
static
public
final
String
propertiesFileName
=
"library.properties"
;
/**
* Filter to pull out just files and none of the platform-specific
* directories, and to skip export.txt. As of 2.0a2, other directories are
* included, because we need things like the 'plugins' subfolder w/ video.
*/
static
FilenameFilter
standardFilter
=
new
FilenameFilter
() {
public
boolean
accept
(
File
dir
,
String
name
) {
// skip .DS_Store files, .svn folders, etc
if
(
name
.
charAt
(
0
) ==
'.'
)
return
false
;
if
(
name
.
equals
(
"CVS"
))
return
false
;
if
(
name
.
equals
(
"export.txt"
))
return
false
;
File
file
=
new
File
(
dir
,
name
);
// return (!file.isDirectory());
if
(
file
.
isDirectory
()) {
if
(
name
.
equals
(
"macosx"
))
return
false
;
if
(
name
.
equals
(
"macosx32"
))
return
false
;
if
(
name
.
equals
(
"macosx64"
))
return
false
;
if
(
name
.
equals
(
"windows"
))
return
false
;
if
(
name
.
equals
(
"windows32"
))
return
false
;
if
(
name
.
equals
(
"windows64"
))
return
false
;
if
(
name
.
equals
(
"linux"
))
return
false
;
if
(
name
.
equals
(
"linux32"
))
return
false
;
if
(
name
.
equals
(
"linux64"
))
return
false
;
if
(
name
.
equals
(
"android"
))
return
false
;
}
return
true
;
}
};
static
FilenameFilter
jarFilter
=
new
FilenameFilter
() {
public
boolean
accept
(
File
dir
,
String
name
) {
if
(
name
.
charAt
(
0
) ==
'.'
)
return
false
;
// skip ._blah.jar crap on OS X
if
(
new
File
(
dir
,
name
).
isDirectory
())
return
false
;
String
lc
=
name
.
toLowerCase
();
return
lc
.
endsWith
(
".jar"
) ||
lc
.
endsWith
(
".zip"
);
}
};
static
public
Library
load
(
File
folder
) {
try
{
return
new
Library
(
folder
);
// } catch (IgnorableException ig) {
// Base.log(ig.getMessage());
}
catch
(
Error
err
) {
// Handles UnsupportedClassVersionError and others
err
.
printStackTrace
();
}
catch
(
Exception
ex
) {
ex
.
printStackTrace
();
}
return
null
;
}
public
Library
(
File
folder
) {
this
(
folder
,
null
);
}
private
Library
(
File
folder
,
String
groupName
) {
super
(
folder
);
this
.
group
=
groupName
;
libraryFolder
=
new
File
(
folder
,
"library"
);
examplesFolder
=
new
File
(
folder
,
"examples"
);
referenceFile
=
new
File
(
folder
,
"reference/index.html"
);
File
exportSettings
=
new
File
(
libraryFolder
,
"export.txt"
);
Map
<
String
,
String
>
exportTable
=
exportSettings
.
exists
() ?
Base
.
readSettings
(
exportSettings
) :
new
HashMap
<
String
,
String
>();
exportList
=
new
HashMap
<
String
,
String
[]>();
// get the list of files just in the library root
String
[]
baseList
=
libraryFolder
.
list
(
standardFilter
);
// System.out.println("Loading " + name + "...");
// PApplet.println(baseList);
String
appletExportStr
=
exportTable
.
get
(
"applet"
);
if
(
appletExportStr
!=
null
) {
appletExportList
=
PApplet
.
splitTokens
(
appletExportStr
,
", "
);
}
else
{
appletExportList
=
baseList
;
}
String
androidExportStr
=
exportTable
.
get
(
"android"
);
if
(
androidExportStr
!=
null
) {
androidExportList
=
PApplet
.
splitTokens
(
androidExportStr
,
", "
);
}
else
{
androidExportList
=
baseList
;
}
// for the host platform, need to figure out what's available
File
nativeLibraryFolder
=
libraryFolder
;
String
hostPlatform
=
Base
.
getPlatformName
();
// System.out.println("1 native lib folder now " + nativeLibraryFolder);
// see if there's a 'windows', 'macosx', or 'linux' folder
File
hostLibrary
=
new
File
(
libraryFolder
,
hostPlatform
);
if
(
hostLibrary
.
exists
()) {
nativeLibraryFolder
=
hostLibrary
;
}
// System.out.println("2 native lib folder now " + nativeLibraryFolder);
// check for bit-specific version, e.g. on windows, check if there
// is a window32 or windows64 folder (on windows)
hostLibrary
=
new
File
(
libraryFolder
,
hostPlatform
+
Base
.
getNativeBits
());
if
(
hostLibrary
.
exists
()) {
nativeLibraryFolder
=
hostLibrary
;
}
// System.out.println("3 native lib folder now " + nativeLibraryFolder);
// save that folder for later use
nativeLibraryPath
=
nativeLibraryFolder
.
getAbsolutePath
();
// for each individual platform that this library supports, figure out what's around
for
(
int
i
=
1
;
i
<
platformNames
.
length
;
i
++) {
String
platformName
=
platformNames
[
i
];
String
platformName32
=
platformName
+
"32"
;
String
platformName64
=
platformName
+
"64"
;
// First check for things like 'application.macosx=' or 'application.windows32' in the export.txt file.
// These will override anything in the platform-specific subfolders.
String
platformAll
=
exportTable
.
get
(
"application."
+
platformName
);
String
[]
platformList
=
platformAll
==
null
?
null
:
PApplet
.
splitTokens
(
platformAll
,
", "
);
String
platform32
=
exportTable
.
get
(
"application."
+
platformName
+
"32"
);
String
[]
platformList32
=
platform32
==
null
?
null
:
PApplet
.
splitTokens
(
platform32
,
", "
);
String
platform64
=
exportTable
.
get
(
"application."
+
platformName
+
"64"
);
String
[]
platformList64
=
platform64
==
null
?
null
:
PApplet
.
splitTokens
(
platform64
,
", "
);
// If nothing specified in the export.txt entries, look for the platform-specific folders.
if
(
platformAll
==
null
) {
platformList
=
listPlatformEntries
(
libraryFolder
,
platformName
,
baseList
);
}
if
(
platform32
==
null
) {
platformList32
=
listPlatformEntries
(
libraryFolder
,
platformName32
,
baseList
);
}
if
(
platform64
==
null
) {
platformList64
=
listPlatformEntries
(
libraryFolder
,
platformName64
,
baseList
);
}
if
(
platformList32
!=
null
||
platformList64
!=
null
) {
multipleArch
[
i
] =
true
;
}
// if there aren't any relevant imports specified or in their own folders,
// then use the baseList (root of the library folder) as the default.
if
(
platformList
==
null
&&
platformList32
==
null
&&
platformList64
==
null
) {
exportList
.
put
(
platformName
,
baseList
);
}
else
{
// once we've figured out which side our bread is buttered on, save it.
// (also concatenate the list of files in the root folder as well
if
(
platformList
!=
null
) {
exportList
.
put
(
platformName
,
platformList
);
}
if
(
platformList32
!=
null
) {
exportList
.
put
(
platformName32
,
platformList32
);
}
if
(
platformList64
!=
null
) {
exportList
.
put
(
platformName64
,
platformList64
);
}
}
}
// for (String p : exportList.keySet()) {
// System.out.println(p + " -> ");
// PApplet.println(exportList.get(p));
// }
// get the path for all .jar files in this code folder
packageList
=
Base
.
packageListFromClassPath
(
getClassPath
());
}
/**
* List who's inside a windows64, macosx, linux32, etc folder.
*/
static
String
[]
listPlatformEntries
(
File
libraryFolder
,
String
folderName
,
String
[]
baseList
) {
File
folder
=
new
File
(
libraryFolder
,
folderName
);
if
(
folder
.
exists
()) {
String
[]
entries
=
folder
.
list
(
standardFilter
);
if
(
entries
!=
null
) {
String
[]
outgoing
=
new
String
[
entries
.
length
+
baseList
.
length
];
for
(
int
i
=
0
;
i
<
entries
.
length
;
i
++) {
outgoing
[
i
] =
folderName
+
"/"
+
entries
[
i
];
}
// Copy the base libraries in there as well
System
.
arraycopy
(
baseList
,
0
,
outgoing
,
entries
.
length
,
baseList
.
length
);
return
outgoing
;
}
}
return
null
;
}
static
protected
HashMap
<
String
,
Object
>
packageWarningMap
=
new
HashMap
<
String
,
Object
>();
/**
* Add the packages provided by this library to the master list that maps
* imports to specific libraries.
* @param importToLibraryTable mapping from package names to Library objects
*/
// public void addPackageList(HashMap<String,Library> importToLibraryTable) {
public
void
addPackageList
(
HashMap
<
String
,
ArrayList
<
Library
>>
importToLibraryTable
) {
// PApplet.println(packages);
for
(
String
pkg
:
packageList
) {
// pw.println(pkg + "\t" + libraryFolder.getAbsolutePath());
// PApplet.println(pkg + "\t" + getName());
// Library library = importToLibraryTable.get(pkg);
ArrayList
<
Library
>
libraries
=
importToLibraryTable
.
get
(
pkg
);
if
(
libraries
==
null
) {
libraries
=
new
ArrayList
<
Library
>();
importToLibraryTable
.
put
(
pkg
,
libraries
);
}
else
{
if
(
Base
.
DEBUG
) {
System
.
err
.
println
(
"The library found in"
);
System
.
err
.
println
(
getPath
());
System
.
err
.
println
(
"conflicts with"
);
for
(
Library
library
:
libraries
) {
System
.
err
.
println
(
library
.
getPath
());
}
System
.
err
.
println
(
"which already define(s) the package "
+
pkg
);
System
.
err
.
println
(
"If you have a line in your sketch that reads"
);
System
.
err
.
println
(
"import "
+
pkg
+
".*;"
);
System
.
err
.
println
(
"Then you'll need to first remove one of those libraries."
);
System
.
err
.
println
();
}
}
libraries
.
add
(
this
);
}
}
public
boolean
hasExamples
() {
return
examplesFolder
.
exists
();
}
public
File
getExamplesFolder
() {
return
examplesFolder
;
}
public
String
getGroup
() {
return
group
;
}
public
String
getPath
() {
return
folder
.
getAbsolutePath
();
}
public
String
getLibraryPath
() {
return
libraryFolder
.
getAbsolutePath
();
}
public
String
getJarPath
() {
//return new File(folder, "library/" + name + ".jar").getAbsolutePath();
return
new
File
(
libraryFolder
,
folder
.
getName
() +
".jar"
).
getAbsolutePath
();
}
// this prepends a colon so that it can be appended to other paths safely
public
String
getClassPath
() {
StringBuilder
cp
=
new
StringBuilder
();
// PApplet.println(libraryFolder.getAbsolutePath());
// PApplet.println(libraryFolder.list());
String
[]
jarHeads
=
libraryFolder
.
list
(
jarFilter
);
for
(
String
jar
:
jarHeads
) {
cp
.
append
(
File
.
pathSeparatorChar
);
cp
.
append
(
new
File
(
libraryFolder
,
jar
).
getAbsolutePath
());
}
jarHeads
=
new
File
(
nativeLibraryPath
).
list
(
jarFilter
);
for
(
String
jar
:
jarHeads
) {
cp
.
append
(
File
.
pathSeparatorChar
);
cp
.
append
(
new
File
(
nativeLibraryPath
,
jar
).
getAbsolutePath
());
}
//cp.setLength(cp.length() - 1); // remove the last separator
return
cp
.
toString
();
}
public
String
getNativePath
() {
// PApplet.println("native lib folder " + nativeLibraryPath);
return
nativeLibraryPath
;
}
// public String[] getAppletExports() {
// return appletExportList;
// }
protected
File
[]
wrapFiles
(
String
[]
list
) {
File
[]
outgoing
=
new
File
[
list
.
length
];
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++) {
outgoing
[
i
] =
new
File
(
libraryFolder
,
list
[
i
]);
}
return
outgoing
;
}
/**
* Applet exports don't go by platform, since by their nature applets are
* meant to be cross-platform. Technically, you could have a situation where
* you want to export applet code for different platforms, but it's too
* obscure a case that we're not interested in supporting it.
*/
public
File
[]
getAppletExports
() {
return
wrapFiles
(
appletExportList
);
}
public
File
[]
getApplicationExports
(
int
platform
,
int
bits
) {
String
[]
list
=
getApplicationExportList
(
platform
,
bits
);
return
wrapFiles
(
list
);
}
/**
* Returns the necessary exports for the specified platform.
* If no 32 or 64-bit version of the exports exists, it returns the version
* that doesn't specify bit depth.
*/
public
String
[]
getApplicationExportList
(
int
platform
,
int
bits
) {
String
platformName
=
PConstants
.
platformNames
[
platform
];
if
(
bits
==
32
) {
String
[]
pieces
=
exportList
.
get
(
platformName
+
"32"
);
if
(
pieces
!=
null
)
return
pieces
;
}
else
if
(
bits
==
64
) {
String
[]
pieces
=
exportList
.
get
(
platformName
+
"64"
);
if
(
pieces
!=
null
)
return
pieces
;
}
return
exportList
.
get
(
platformName
);
}
public
File
[]
getAndroidExports
() {
return
wrapFiles
(
androidExportList
);
}
// public boolean hasMultiplePlatforms() {
// return false;
// }
public
boolean
hasMultipleArch
(
int
platform
) {
return
multipleArch
[
platform
];
}
public
boolean
supportsArch
(
int
platform
,
int
bits
) {
// If this is a universal library, or has no natives, then we're good.
if
(
multipleArch
[
platform
] ==
false
) {
return
true
;
}
return
getApplicationExportList
(
platform
,
bits
) !=
null
;
}
// static boolean hasMultipleArch(String platformName, ArrayList<LibraryFolder> libraries) {
// int platform = Base.getPlatformIndex(platformName);
static
public
boolean
hasMultipleArch
(
int
platform
,
ArrayList
<
Library
>
libraries
) {
for
(
Library
library
:
libraries
) {
if
(
library
.
hasMultipleArch
(
platform
)) {
return
true
;
}
}
return
false
;
}
// for sorting
// public int compareTo(Object o) {
// return prettyName.compareTo(((LibraryFolder) o).prettyName);
// }}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static
protected
FilenameFilter
junkFolderFilter
=
new
FilenameFilter
() {
public
boolean
accept
(
File
dir
,
String
name
) {
// skip .DS_Store files, .svn folders, etc
if
(
name
.
charAt
(
0
) ==
'.'
)
return
false
;
if
(
name
.
equals
(
"CVS"
))
return
false
;
return
(
new
File
(
dir
,
name
).
isDirectory
());
}
};
static
public
ArrayList
<
File
>
discover
(
File
folder
) {
ArrayList
<
File
>
libraries
=
new
ArrayList
<
File
>();
discover
(
folder
,
libraries
);
return
libraries
;
}
static
public
void
discover
(
File
folder
,
ArrayList
<
File
>
libraries
) {
String
[]
list
=
folder
.
list
(
junkFolderFilter
);
// if a bad folder or something like that, this might come back null
if
(
list
!=
null
) {
// alphabetize list, since it's not always alpha order
// replaced hella slow bubble sort with this feller for 0093
Arrays
.
sort
(
list
,
String
.
CASE_INSENSITIVE_ORDER
);
for
(
String
potentialName
:
list
) {
File
baseFolder
=
new
File
(
folder
,
potentialName
);
File
libraryFolder
=
new
File
(
baseFolder
,
"library"
);
File
libraryJar
=
new
File
(
libraryFolder
,
potentialName
+
".jar"
);
// If a .jar file of the same prefix as the folder exists
// inside the 'library' subfolder of the sketch
if
(
libraryJar
.
exists
()) {
String
sanityCheck
=
Sketch
.
sanitizeName
(
potentialName
);
if
(
sanityCheck
.
equals
(
potentialName
)) {
libraries
.
add
(
baseFolder
);
}
else
{
String
mess
=
"The library
\"
"
+
potentialName
+
"
\"
cannot be used.
\n
"
+
"Library names must contain only basic letters and numbers.
\n
"
+
"(ASCII only and no spaces, and it cannot start with a number)"
;
Base
.
showMessage
(
"Ignoring bad library name"
,
mess
);
continue
;
}
}
}
}
}
static
protected
ArrayList
<
Library
>
list
(
File
folder
) {
ArrayList
<
Library
>
libraries
=
new
ArrayList
<
Library
>();
list
(
folder
,
libraries
);
return
libraries
;
}
static
protected
void
list
(
File
folder
,
ArrayList
<
Library
>
libraries
) {
ArrayList
<
File
>
librariesFolders
=
new
ArrayList
<
File
>();
discover
(
folder
,
librariesFolders
);
for
(
File
baseFolder
:
librariesFolders
) {
libraries
.
add
(
new
Library
(
baseFolder
));
}
String
[]
list
=
folder
.
list
(
junkFolderFilter
);
if
(
list
!=
null
) {
for
(
String
subfolderName
:
list
) {
File
subfolder
=
new
File
(
folder
,
subfolderName
);
if
(!
librariesFolders
.
contains
(
subfolder
)) {
ArrayList
<
File
>
discoveredLibFolders
=
new
ArrayList
<
File
>();
discover
(
subfolder
,
discoveredLibFolders
);
for
(
File
discoveredFolder
:
discoveredLibFolders
) {
libraries
.
add
(
new
Library
(
discoveredFolder
,
subfolderName
));
}
}
}
}
}
public
ContributionType
getType
() {
return
ContributionType
.
LIBRARY
;
}
/**
* Returns the object stored in the referenceFile field, which contains an
* instance of the file object representing the index file of the reference
*
* @return referenceFile
*/
public
File
getReferenceIndexFile
() {
return
referenceFile
;
}
/**
* Tests whether the reference's index file indicated by referenceFile exists.
*
* @return true if and only if the file denoted by referenceFile exists; false
* otherwise.
*/
public
boolean
hasReference
() {
return
referenceFile
.
exists
();
}
}
Back
|
FazBrowse Home
|
New Git URL