11
11
12
12
13
13
public class Library extends LocalContribution {
14
- static final String [] platformNames = PConstants .platformNames ;
14
+ // static final String[] platformNames = PConstants.platformNames;
15
+
16
+ static StringDict newToOld = new StringDict (new String [][] {
17
+ { "macos-x86_64" , "macosx" },
18
+ { "windows-amd64" , "windows64" },
19
+ { "linux-amd64" , "linux64" },
20
+ { "linux-arm" , "linux-armv6hf" },
21
+ { "linux-aarch64" , "linux-arm64" }
22
+ });
15
23
16
24
protected File libraryFolder ; // shortname/library
17
25
protected File examplesFolder ; // shortname/examples
@@ -30,21 +38,22 @@ public class Library extends LocalContribution {
30
38
/** Per-platform exports for this library. */
31
39
Map <String , String []> exportList ;
32
40
33
- /** Applet exports (cross-platform by definition). */
34
- String [] appletExportList ;
35
-
36
41
/** Android exports (single platform for now, may not exist). */
37
42
String [] androidExportList ;
38
43
39
- /** True if there are separate 32/64 bit for the specified platform index. */
40
- boolean [] multipleArch = new boolean [platformNames .length ];
44
+ // /** True if there are separate 32/64 bit for the specified platform index. */
45
+ // boolean[] multipleArch = new boolean[platformNames.length];
46
+ // Map<String, Boolean> multipleArch = new HashMap<>();
41
47
42
48
/**
43
49
* For runtime, the native library path for this platform. e.g. on Windows 64,
44
50
* this might be the windows64 subfolder with the library.
45
51
*/
46
52
String nativeLibraryPath ;
47
53
54
+ // /** True if */
55
+ // boolean variants;
56
+
48
57
static public final String propertiesFileName = "library.properties" ;
49
58
50
59
/**
@@ -59,25 +68,24 @@ public class Library extends LocalContribution {
59
68
* explicitly listing all possible architectures, and so that
60
69
* macos-blah as well as and macosx will be handled properly.
61
70
*/
62
- static FilenameFilter standardFilter = new FilenameFilter () {
63
- public boolean accept (File dir , String name ) {
64
- // skip .DS_Store files, .svn folders, etc
65
- if (name .charAt (0 ) == '.' ) return false ;
66
- // ha, the sftp library still has one [fry 220121]
67
- if (name .equals ("CVS" )) return false ;
68
- if (name .equals ("export.txt" )) return false ;
69
-
70
- File file = new File (dir , name );
71
- if (file .isDirectory ()) {
72
- if (name .startsWith ("macos" ) ||
73
- name .startsWith ("windows" ) ||
74
- name .startsWith ("linux" ) ||
75
- name .startsWith ("android" )) {
76
- return false ;
77
- }
71
+ static FilenameFilter libraryFolderFilter = (dir , name ) -> {
72
+ // skip .DS_Store files, .svn folders, etc
73
+ if (name .charAt (0 ) == '.' ) return false ;
74
+ // ha, the sftp library still has one [fry 220121]
75
+ if (name .equals ("CVS" )) return false ;
76
+ if (name .equals ("export.txt" )) return false ;
77
+
78
+ File file = new File (dir , name );
79
+ if (file .isDirectory ()) {
80
+ //noinspection RedundantIfStatement
81
+ if (name .startsWith ("macos" ) ||
82
+ name .startsWith ("windows" ) ||
83
+ name .startsWith ("linux" )) {
84
+ //name.startsWith("android")) { // no libraries use this
85
+ return false ;
78
86
}
79
- return true ;
80
87
}
88
+ return true ;
81
89
};
82
90
83
91
static FilenameFilter jarFilter = (dir , name ) -> {
@@ -122,66 +130,94 @@ private Library(File folder, String groupName) {
122
130
* Handles all the Java-specific parsing for library handling.
123
131
*/
124
132
protected void handle () {
125
- File exportSettings = new File (libraryFolder , "export.txt" );
126
- StringDict exportTable = exportSettings .exists () ?
127
- Util .readSettings (exportSettings ) : new StringDict ();
128
-
129
- exportList = new HashMap <>();
130
-
131
- // get the list of files just in the library root
132
- String [] baseList = libraryFolder .list (standardFilter );
133
- // System.out.println("Loading " + name + "...");
134
- // PApplet.println(baseList);
133
+ handleNative ();
134
+ handleExports ();
135
+ }
135
136
136
- String appletExportStr = exportTable .get ("applet" );
137
- if (appletExportStr != null ) {
138
- appletExportList = PApplet .splitTokens (appletExportStr , ", " );
139
- } else {
140
- appletExportList = baseList ;
141
- }
142
137
143
- String androidExportStr = exportTable .get ("android" );
144
- if (androidExportStr != null ) {
145
- androidExportList = PApplet .splitTokens (androidExportStr , ", " );
146
- } else {
147
- androidExportList = baseList ;
148
- }
138
+ /**
139
+ * Identify nativeLibraryFolder location for the current platform.
140
+ */
141
+ private void handleNative () {
142
+ String variant = Platform .getVariant ();
149
143
150
- // for the host platform, need to figure out what's available
144
+ // use the root of the library folder as the default
151
145
File nativeLibraryFolder = libraryFolder ;
146
+
147
+ /*
152
148
String hostPlatform = Platform.getName();
153
- // System.out.println("1 native lib folder now " + nativeLibraryFolder);
154
149
// see if there's a 'windows', 'macosx', or 'linux' folder
155
150
File hostLibrary = new File(libraryFolder, hostPlatform);
156
151
if (hostLibrary.exists()) {
157
152
nativeLibraryFolder = hostLibrary;
158
153
}
159
- // System.out.println("2 native lib folder now " + nativeLibraryFolder);
160
- // check for bit-specific version, e.g. on windows, check if there
161
- // is a window32 or windows64 folder (on windows)
162
- hostLibrary =
163
- new File (libraryFolder , hostPlatform + Platform .getNativeBits ());
154
+ */
155
+
156
+ // see if there's a {platform}-{arch} folder
157
+ File hostLibrary = new File (libraryFolder , variant );
164
158
if (hostLibrary .exists ()) {
165
159
nativeLibraryFolder = hostLibrary ;
166
- }
167
- // System.out.println("3 native lib folder now " + nativeLibraryFolder);
168
160
169
- if (hostPlatform .equals ("linux" ) && System .getProperty ("os.arch" ).equals ("arm" )) {
170
- hostLibrary = new File (libraryFolder , "linux-armv6hf" );
171
- if (hostLibrary .exists ()) {
172
- nativeLibraryFolder = hostLibrary ;
173
- }
174
- }
175
- if (hostPlatform .equals ("linux" ) && System .getProperty ("os.arch" ).equals ("aarch64" )) {
176
- hostLibrary = new File (libraryFolder , "linux-arm64" );
177
- if (hostLibrary .exists ()) {
178
- nativeLibraryFolder = hostLibrary ;
161
+ } else {
162
+ // if not found, try the old-style naming
163
+ String oldName = newToOld .get (variant );
164
+ if (oldName != null ) {
165
+ hostLibrary = new File (libraryFolder , oldName );
166
+ if (hostLibrary .exists ()) {
167
+ nativeLibraryFolder = hostLibrary ;
168
+ }
179
169
}
180
170
}
181
171
182
172
// save that folder for later use
183
173
nativeLibraryPath = nativeLibraryFolder .getAbsolutePath ();
174
+ }
175
+
184
176
177
+ private void handleExports () {
178
+ /*
179
+ File exportSettings = new File(libraryFolder, "export.txt");
180
+ StringDict exportTable = exportSettings.exists() ?
181
+ Util.readSettings(exportSettings) : new StringDict();
182
+ */
183
+
184
+ exportList = new HashMap <>();
185
+
186
+ // get the list of files just in the library root
187
+ String [] baseList = libraryFolder .list (libraryFolderFilter );
188
+
189
+ for (String variant : Platform .getSupportedVariants ().keys ()) {
190
+ File variantFolder = new File (libraryFolder , variant );
191
+ if (!variantFolder .exists ()) {
192
+ // check to see if old naming is in use
193
+ String oldName = newToOld .get (variant , null );
194
+ if (oldName != null ) {
195
+ variantFolder = new File (libraryFolder , variant );
196
+ if (variantFolder .exists ()) {
197
+ Messages .log ("Please update " + getName () + " for Processing 4. " +
198
+ variantFolder + " is the older naming scheme." );
199
+ }
200
+ }
201
+ }
202
+ if (variantFolder .exists ()) {
203
+ String [] entries = listPlatformEntries (libraryFolder , variant , baseList );
204
+ if (entries != null ) {
205
+ exportList .put (variant , entries );
206
+ }
207
+ }
208
+ }
209
+
210
+ /*
211
+ // not actually used in any libraries
212
+ String androidExportStr = exportTable.get("android");
213
+ if (androidExportStr != null) {
214
+ androidExportList = PApplet.splitTokens(androidExportStr, ", ");
215
+ } else {
216
+ androidExportList = baseList;
217
+ }
218
+ */
219
+
220
+ /*
185
221
// for each individual platform that this library supports, figure out what's around
186
222
for (int i = 1; i < platformNames.length; i++) {
187
223
String platformName = platformNames[i];
@@ -221,7 +257,8 @@ protected void handle() {
221
257
}
222
258
223
259
if (platformList32 != null || platformList64 != null || platformListArmv6hf != null || platformListArm64 != null) {
224
- multipleArch [i ] = true ;
260
+ //multipleArch[i] = true;
261
+ multipleArch.put(platformName, true);
225
262
}
226
263
227
264
// if there aren't any relevant imports specified or in their own folders,
@@ -249,6 +286,8 @@ protected void handle() {
249
286
}
250
287
}
251
288
}
289
+ */
290
+
252
291
// for (String p : exportList.keySet()) {
253
292
// System.out.println(p + " -> ");
254
293
// PApplet.println(exportList.get(p));
@@ -265,7 +304,7 @@ protected void handle() {
265
304
static String [] listPlatformEntries (File libraryFolder , String folderName , String [] baseList ) {
266
305
File folder = new File (libraryFolder , folderName );
267
306
if (folder .exists ()) {
268
- String [] entries = folder .list (standardFilter );
307
+ String [] entries = folder .list (( dir , name ) -> name . charAt ( 0 ) != '.' );
269
308
if (entries != null ) {
270
309
String [] outgoing = new String [entries .length + baseList .length ];
271
310
for (int i = 0 ; i < entries .length ; i ++) {
@@ -349,12 +388,11 @@ public String getJarPath() {
349
388
}
350
389
351
390
352
- // this prepends a colon so that it can be appended to other paths safely
391
+ // the returned value begins with File.pathSeparatorChar
392
+ // so that it can be appended to other paths safely
353
393
public String getClassPath () {
354
394
StringBuilder cp = new StringBuilder ();
355
395
356
- // PApplet.println(libraryFolder.getAbsolutePath());
357
- // PApplet.println(libraryFolder.list());
358
396
String [] jarHeads = libraryFolder .list (jarFilter );
359
397
if (jarHeads != null ) {
360
398
for (String jar : jarHeads ) {
@@ -372,7 +410,6 @@ public String getClassPath() {
372
410
}
373
411
}
374
412
}
375
- //cp.setLength(cp.length() - 1); // remove the last separator
376
413
return cp .toString ();
377
414
}
378
415
@@ -391,17 +428,16 @@ protected File[] wrapFiles(String[] list) {
391
428
}
392
429
393
430
431
+ /*
394
432
public File[] getApplicationExports(int platform, String variant) {
395
433
String[] list = getApplicationExportList(platform, variant);
396
434
return wrapFiles(list);
397
435
}
398
436
399
437
400
- /**
401
- * Returns the necessary exports for the specified platform.
402
- * If no 32 or 64-bit version of the exports exists, it returns the version
403
- * that doesn't specify bit depth.
404
- */
438
+ // * Returns the necessary exports for the specified platform.
439
+ // * If no 32 or 64-bit version of the exports exists, it returns the version
440
+ // * that doesn't specify bit depth.
405
441
public String[] getApplicationExportList(int platform, String variant) {
406
442
String platformName = PConstants.platformNames[platform];
407
443
if (variant.equals("32")) {
@@ -419,6 +455,11 @@ public String[] getApplicationExportList(int platform, String variant) {
419
455
}
420
456
return exportList.get(platformName);
421
457
}
458
+ */
459
+
460
+ public String [] getApplicationExportList (String variant ) {
461
+ return exportList .get (variant );
462
+ }
422
463
423
464
424
465
@ SuppressWarnings ("unused" )
@@ -427,11 +468,15 @@ public File[] getAndroidExports() {
427
468
}
428
469
429
470
471
+ /*
430
472
public boolean hasMultipleArch(int platform) {
431
- return multipleArch [platform ];
473
+ //return multipleArch[platform];
474
+ return multipleArch.getOrDefault(platform, false);
432
475
}
476
+ */
433
477
434
478
479
+ /*
435
480
public boolean supportsArch(int platform, String variant) {
436
481
// If this is a universal library, or has no natives, then we're good.
437
482
if (multipleArch[platform] == false) {
@@ -440,10 +485,26 @@ public boolean supportsArch(int platform, String variant) {
440
485
return getApplicationExportList(platform, variant) != null;
441
486
}
442
487
488
+ public boolean isUnsupported(int platform, String variant) {
489
+ // If this is a universal library, or has no natives, then we're good.
490
+ if (!multipleArch.containsKey(platformNames[platform])) {
491
+ return false;
492
+ }
493
+ return getApplicationExportList(platform, variant) == null;
494
+ }
495
+ */
496
+
497
+
498
+ public boolean isUnsupported (String variant ) {
499
+ return getApplicationExportList (variant ) == null ;
500
+ }
501
+
443
502
503
+ /*
444
504
static public boolean hasMultipleArch(int platform, List<Library> libraries) {
445
505
return libraries.stream().anyMatch(library -> library.hasMultipleArch(platform));
446
506
}
507
+ */
447
508
448
509
449
510
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
0 commit comments