Skip to content

Commit 6da4bd0

Browse files
author
Jonathan Feinberg
committed
Reformat
1 parent 80a00c4 commit 6da4bd0

38 files changed

+1074
-1026
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jycessing;
22

33
public enum DisplayType {
4-
WINDOWED, PRESENTATION;
4+
WINDOWED,
5+
PRESENTATION;
56
}

runtime/src/jycessing/IOUtil.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,31 @@ public static String readText(final Path path) throws IOException {
4848

4949
/**
5050
* Recursively deletes the given directory or file.
51+
*
5152
* @param target Path of file to be deleted.
5253
* @throws IOException
5354
*/
5455
public static void rm(final Path target) throws IOException {
55-
Files.walkFileTree(target, new SimpleFileVisitor<Path>() {
56-
@Override
57-
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
58-
throws IOException {
59-
Files.delete(file);
60-
return CONTINUE;
61-
}
56+
Files.walkFileTree(
57+
target,
58+
new SimpleFileVisitor<Path>() {
59+
@Override
60+
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
61+
throws IOException {
62+
Files.delete(file);
63+
return CONTINUE;
64+
}
6265

63-
@Override
64-
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
65-
throws IOException {
66-
if (exc != null) {
67-
throw exc;
68-
}
69-
Files.delete(dir);
70-
return CONTINUE;
71-
}
72-
});
66+
@Override
67+
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
68+
throws IOException {
69+
if (exc != null) {
70+
throw exc;
71+
}
72+
Files.delete(dir);
73+
return CONTINUE;
74+
}
75+
});
7376
}
7477

7578
public static void copy(final Path src, final Path target) throws IOException {

runtime/src/jycessing/LibraryImporter.java

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@
3434

3535
/**
3636
* {@link LibraryImporter} contributes the add_library function to processing.py.
37-
*
38-
* <p>add_library causes the given Processing library (all of its jar files and
39-
* library subdirectories potentially containing native code) to be added to the
40-
* system {@link ClassLoader}, the native code search path, and the Jython sys.path.
41-
* It then generates import statements bringing all top-level classes available
42-
* in the main library jar file into the sketch's namespace.
43-
*
44-
* <p>Note: Once jar files and directories have been added in this fashion to the
45-
* classloader and native lib search path, they're good and stuck there. In practice,
46-
* this hasn't presented any difficulty. But it's good to keep in mind.
37+
*
38+
* <p>add_library causes the given Processing library (all of its jar files and library
39+
* subdirectories potentially containing native code) to be added to the system {@link ClassLoader},
40+
* the native code search path, and the Jython sys.path. It then generates import statements
41+
* bringing all top-level classes available in the main library jar file into the sketch's
42+
* namespace.
43+
*
44+
* <p>Note: Once jar files and directories have been added in this fashion to the classloader and
45+
* native lib search path, they're good and stuck there. In practice, this hasn't presented any
46+
* difficulty. But it's good to keep in mind.
4747
*/
4848
class LibraryImporter {
4949
private static void log(final String msg) {
@@ -75,26 +75,27 @@ public LibraryImporter(final List<File> libdirs, final InteractiveConsole interp
7575
this.interp = interp;
7676

7777
// Define the add_library function in the sketch interpreter.
78-
final PyStringMap builtins = (PyStringMap)interp.getSystemState().getBuiltins();
79-
builtins.__setitem__("add_library", new PyObject() {
80-
@Override
81-
public PyObject __call__(final PyObject[] args, final String[] kws) {
82-
log("Adding library " + args[0].asString());
83-
addLibrary(args[0].asString());
84-
return Py.None;
85-
}
86-
});
78+
final PyStringMap builtins = (PyStringMap) interp.getSystemState().getBuiltins();
79+
builtins.__setitem__(
80+
"add_library",
81+
new PyObject() {
82+
@Override
83+
public PyObject __call__(final PyObject[] args, final String[] kws) {
84+
log("Adding library " + args[0].asString());
85+
addLibrary(args[0].asString());
86+
return Py.None;
87+
}
88+
});
8789
}
8890

8991
/**
90-
* Locate the library in the library folder "libName", find what
91-
* it exports for the current platform, and add exports to the
92-
* system classpath, the system native library path, and jython's
92+
* Locate the library in the library folder "libName", find what it exports for the current
93+
* platform, and add exports to the system classpath, the system native library path, and jython's
9394
* sys.path.
94-
*
95-
* Then, go through the main jar file of the library and import
96-
* all of its publicly exposed classes.
97-
*
95+
*
96+
* <p>Then, go through the main jar file of the library and import all of its publicly exposed
97+
* classes.
98+
*
9899
* @param libName The name of the library to import
99100
*/
100101
protected void addLibrary(final String libName) {
@@ -158,13 +159,12 @@ protected void addLibrary(final String libName) {
158159
}
159160

160161
/**
161-
* Find all of the resources a library requires on this platform.
162-
* See https://github.com/processing/processing/wiki/Library-Basics.
163-
*
164-
* First, finds the library.
165-
* Second, tries to parse export.txt, and follow its instructions.
162+
* Find all of the resources a library requires on this platform. See
163+
* https://github.com/processing/processing/wiki/Library-Basics.
164+
*
165+
* <p>First, finds the library. Second, tries to parse export.txt, and follow its instructions.
166166
* Third, tries to understand folder structure, and export according to that.
167-
*
167+
*
168168
* @param libName The name of the library to add.
169169
* @return The list of files we need to import.
170170
*/
@@ -215,8 +215,11 @@ private List<File> findResourcesFromExportTxt(final File contentsDir) {
215215
if (resource.exists()) {
216216
resources.add(resource);
217217
} else {
218-
log(resourceName + " is mentioned in " + exportTxt.getAbsolutePath()
219-
+ "but doesn't actually exist. Moving on.");
218+
log(
219+
resourceName
220+
+ " is mentioned in "
221+
+ exportTxt.getAbsolutePath()
222+
+ "but doesn't actually exist. Moving on.");
220223
continue;
221224
}
222225
}
@@ -249,23 +252,25 @@ private List<File> findResourcesFromDirectoryStructure(final File contentsDir) {
249252
}
250253

251254
// Find multi-platform stuff; always do this
252-
final File[] commonResources = contentsDir.listFiles(new FileFilter() {
253-
@Override
254-
public boolean accept(final File file) {
255-
return !file.isDirectory();
256-
}
257-
});
255+
final File[] commonResources =
256+
contentsDir.listFiles(
257+
new FileFilter() {
258+
@Override
259+
public boolean accept(final File file) {
260+
return !file.isDirectory();
261+
}
262+
});
258263
for (final File resource : commonResources) {
259264
resources.add(resource);
260265
}
261266
return resources;
262267
}
263268

264269
/**
265-
* Parse an export.txt file to figure out what we need to load for this platform.
266-
* This is all duplicated from processing.app.Library / processing.app.Base,
267-
* but we don't have the PDE around at runtime so we can't use them.
268-
*
270+
* Parse an export.txt file to figure out what we need to load for this platform. This is all
271+
* duplicated from processing.app.Library / processing.app.Base, but we don't have the PDE around
272+
* at runtime so we can't use them.
273+
*
269274
* @param exportTxt The export.txt file; must exist.
270275
*/
271276
private Map<String, String[]> parseExportTxt(final File exportTxt) throws Exception {
@@ -290,14 +295,14 @@ private Map<String, String[]> parseExportTxt(final File exportTxt) throws Except
290295
}
291296

292297
/**
293-
* Use a brittle and egregious hack to forcibly add the given jar file to the
294-
* system classloader.
298+
* Use a brittle and egregious hack to forcibly add the given jar file to the system classloader.
299+
*
295300
* @param jar The jar to add to the system classloader.
296301
*/
297302
private void addJarToClassLoader(final File jar) {
298303
try {
299304
final URL url = jar.toURI().toURL();
300-
final URLClassLoader ucl = (URLClassLoader)ClassLoader.getSystemClassLoader();
305+
final URLClassLoader ucl = (URLClassLoader) ClassLoader.getSystemClassLoader();
301306
// Linear search for url. It's ok for this to be slow.
302307
for (final URL existing : ucl.getURLs()) {
303308
if (existing.equals(url)) {
@@ -308,28 +313,29 @@ private void addJarToClassLoader(final File jar) {
308313
final Method addUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
309314
addUrl.setAccessible(true);
310315
addUrl.invoke(ucl, url);
311-
} catch (NoSuchMethodException | SecurityException | IllegalAccessException
312-
| IllegalArgumentException | InvocationTargetException | MalformedURLException e) {
316+
} catch (NoSuchMethodException
317+
| SecurityException
318+
| IllegalAccessException
319+
| IllegalArgumentException
320+
| InvocationTargetException
321+
| MalformedURLException e) {
313322
throw new RuntimeException(e);
314323
}
315324
}
316325

317326
/**
318-
* Add the given path to the list of paths searched for DLLs (as in those
319-
* loaded by loadLibrary). A hack, which depends on the presence of a
320-
* particular field in ClassLoader. Known to work on all recent Sun JVMs and
321-
* OS X.
327+
* Add the given path to the list of paths searched for DLLs (as in those loaded by loadLibrary).
328+
* A hack, which depends on the presence of a particular field in ClassLoader. Known to work on
329+
* all recent Sun JVMs and OS X.
322330
*
323-
* <p>
324-
* See <a href="http://forums.sun.com/thread.jspa?threadID=707176">this
325-
* thread</a>.
331+
* <p>See <a href="http://forums.sun.com/thread.jspa?threadID=707176">this thread</a>.
326332
*/
327333
private void addDirectoryToNativeSearchPath(final File dllDir) {
328334
final String newPath = dllDir.getAbsolutePath();
329335
try {
330336
final Field field = ClassLoader.class.getDeclaredField("usr_paths");
331337
field.setAccessible(true);
332-
final String[] paths = (String[])field.get(null);
338+
final String[] paths = (String[]) field.get(null);
333339
for (final String path : paths) {
334340
if (newPath.equals(path)) {
335341
return;
@@ -340,13 +346,16 @@ private void addDirectoryToNativeSearchPath(final File dllDir) {
340346
field.set(null, tmp);
341347
log("Added " + newPath + " to java.library.path.");
342348
} catch (final Exception e) {
343-
System.err.println("While attempting to add " + newPath
344-
+ " to the processing.py library search path: " + e.getClass().getSimpleName() + "--"
345-
+ e.getMessage());
349+
System.err.println(
350+
"While attempting to add "
351+
+ newPath
352+
+ " to the processing.py library search path: "
353+
+ e.getClass().getSimpleName()
354+
+ "--"
355+
+ e.getMessage());
346356
}
347357
}
348358

349-
350359
private static final Pattern validPythonIdentifier = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*");
351360

352361
/*
@@ -357,9 +366,9 @@ private void addDirectoryToNativeSearchPath(final File dllDir) {
357366
com.foo.Banana$1.class
358367
com.foo.Banana$2.class
359368
com.bar.Kiwi.class
360-
369+
361370
then we'll generate these import statements:
362-
371+
363372
from com.foo import Banana
364373
from com.bar import Kiwi
365374
*/

runtime/src/jycessing/MixedModeError.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ public MixedModeError() {
88
public MixedModeError(final String message, final String fileName, final int line) {
99
super(message, fileName, line);
1010
}
11-
1211
}

0 commit comments

Comments
 (0)