File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
main/java/processing/utils Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -2216,6 +2216,10 @@ static public InputStream getLibStream(String filename) throws IOException {
22162216 * @deprecated use processing.utils.Settings.getFolder() instead, this method will invoke AWT
22172217 */
22182218 static public File getSettingsFolder () {
2219+ var override = getSettingsOverride ();
2220+ if (override != null ) {
2221+ return override ;
2222+ }
22192223 try {
22202224 return processing .utils .Settings .getFolder ();
22212225 } catch (processing .utils .Settings .SettingsFolderException e ) {
Original file line number Diff line number Diff line change @@ -18,7 +18,10 @@ public static File getFolder() throws SettingsFolderException {
1818 }
1919
2020 private static File getFolderForPlatform () throws SettingsFolderException {
21- // TODO: Detect override file,
21+ var settingsOverride = System .getProperty ("processing.settings.folder" );
22+ if (settingsOverride != null && !settingsOverride .isEmpty ()) {
23+ return new File (settingsOverride );
24+ }
2225
2326 if (Platform .isWindows ()) {
2427 var options = new String []{
Original file line number Diff line number Diff line change 1+ import org .junit .jupiter .api .Test ;
2+ import processing .utils .Settings ;
3+
4+ import java .io .IOException ;
5+ import java .nio .file .Files ;
6+
7+ public class SettingsTest {
8+
9+ /**
10+ * Requesting the settings folder should create it if it doesn't exist
11+ */
12+ @ Test
13+ public void testSettingsFolder () {
14+ try {
15+ var folder = Settings .getFolder ();
16+ assert (folder .exists ());
17+ } catch (Settings .SettingsFolderException e ) {
18+ assert (false );
19+ }
20+ }
21+
22+ /**
23+ * Overriding the settings folder via system property should work
24+ */
25+ @ Test
26+ public void testOverrideFolder () throws IOException {
27+ var settings = Files .createTempDirectory ("settings_test" );
28+ System .setProperty ("processing.settings.folder" , settings .toString ());
29+
30+ try {
31+ var folder = Settings .getFolder ();
32+ assert (folder .toPath ().toString ().equals (settings .toString ()));
33+ } catch (Settings .SettingsFolderException e ) {
34+ assert (false );
35+ } finally {
36+ System .clearProperty ("processing.settings.folder" );
37+ Files .deleteIfExists (settings );
38+ }
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments