Skip to content

Commit 4d3599b

Browse files
bitroncmaglie
authored andcommitted
Moved getBuildFolder() and related members/methods from Base to BaseNoGui.
1 parent 6d28e12 commit 4d3599b

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.*;
2828
import java.util.*;
2929
import java.util.List;
30-
import java.util.concurrent.ConcurrentHashMap;
3130

3231
import javax.swing.*;
3332

@@ -74,8 +73,6 @@ public class Base {
7473
// so that the errors while building don't show up again.
7574
boolean builtOnce;
7675

77-
static File buildFolder;
78-
7976
// classpath for all known libraries for p5
8077
// (both those in the p5/libs folder and those with lib subfolders
8178
// found in the sketchbook)
@@ -1610,20 +1607,7 @@ static public File getSettingsFile(String filename) {
16101607

16111608

16121609
static public File getBuildFolder() {
1613-
if (buildFolder == null) {
1614-
String buildPath = Preferences.get("build.path");
1615-
if (buildPath != null) {
1616-
buildFolder = absoluteFile(buildPath);
1617-
if (!buildFolder.exists())
1618-
buildFolder.mkdirs();
1619-
} else {
1620-
//File folder = new File(getTempFolder(), "build");
1621-
//if (!folder.exists()) folder.mkdirs();
1622-
buildFolder = createTempFolder("build");
1623-
buildFolder.deleteOnExit();
1624-
}
1625-
}
1626-
return buildFolder;
1610+
return BaseNoGui.getBuildFolder();
16271611
}
16281612

16291613

@@ -1635,18 +1619,7 @@ static public File getBuildFolder() {
16351619
* to avoid conflicts in multi-user environments. (Bug 177)
16361620
*/
16371621
static public File createTempFolder(String name) {
1638-
try {
1639-
File folder = File.createTempFile(name, null);
1640-
//String tempPath = ignored.getParent();
1641-
//return new File(tempPath);
1642-
folder.delete();
1643-
folder.mkdirs();
1644-
return folder;
1645-
1646-
} catch (Exception e) {
1647-
e.printStackTrace();
1648-
}
1649-
return null;
1622+
return BaseNoGui.createTempFolder(name);
16501623
}
16511624

16521625

app/src/processing/app/BaseNoGui.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class BaseNoGui {
4343
/** Set true if this a proper release rather than a numbered revision. */
4444
static public boolean RELEASE = false;
4545

46+
static File buildFolder;
47+
4648
// Current directory to use for relative paths specified on the
4749
// commandline
4850
static String currentDirectory = System.getProperty("user.dir");
@@ -97,6 +99,28 @@ static public int countLines(String what) {
9799
return count;
98100
}
99101

102+
/**
103+
* Get the path to the platform's temporary folder, by creating
104+
* a temporary temporary file and getting its parent folder.
105+
* <br/>
106+
* Modified for revision 0094 to actually make the folder randomized
107+
* to avoid conflicts in multi-user environments. (Bug 177)
108+
*/
109+
static public File createTempFolder(String name) {
110+
try {
111+
File folder = File.createTempFile(name, null);
112+
//String tempPath = ignored.getParent();
113+
//return new File(tempPath);
114+
folder.delete();
115+
folder.mkdirs();
116+
return folder;
117+
118+
} catch (Exception e) {
119+
e.printStackTrace();
120+
}
121+
return null;
122+
}
123+
100124
static public String getAvrBasePath() {
101125
String path = getHardwarePath() + File.separator + "tools" +
102126
File.separator + "avr" + File.separator + "bin" + File.separator;
@@ -106,6 +130,23 @@ static public String getAvrBasePath() {
106130
return path;
107131
}
108132

133+
static public File getBuildFolder() {
134+
if (buildFolder == null) {
135+
String buildPath = Preferences.get("build.path");
136+
if (buildPath != null) {
137+
buildFolder = absoluteFile(buildPath);
138+
if (!buildFolder.exists())
139+
buildFolder.mkdirs();
140+
} else {
141+
//File folder = new File(getTempFolder(), "build");
142+
//if (!folder.exists()) folder.mkdirs();
143+
buildFolder = createTempFolder("build");
144+
buildFolder.deleteOnExit();
145+
}
146+
}
147+
return buildFolder;
148+
}
149+
109150
static public PreferencesMap getBoardPreferences() {
110151
TargetBoard board = getTargetBoard();
111152

0 commit comments

Comments
 (0)