Skip to content

Commit 15588f3

Browse files
committed
Added both options for overrides
- Added the previous settings override in base again - Added a system property to override the settings folder within tests
1 parent f472518 commit 15588f3

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

app/src/processing/app/Base.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

app/utils/src/main/java/processing/utils/Settings.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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[]{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

0 commit comments

Comments
 (0)