1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Moved getBuildFolder() and related members/methods from Base to BaseNoGui.

This commit is contained in:
Claudio Indellicati 2014-08-26 19:14:45 +02:00 committed by Cristian Maglie
parent 6d28e12a41
commit 4d3599b2c4
2 changed files with 43 additions and 29 deletions

View File

@ -27,7 +27,6 @@ import java.awt.event.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.*; import javax.swing.*;
@ -74,8 +73,6 @@ public class Base {
// so that the errors while building don't show up again. // so that the errors while building don't show up again.
boolean builtOnce; boolean builtOnce;
static File buildFolder;
// classpath for all known libraries for p5 // classpath for all known libraries for p5
// (both those in the p5/libs folder and those with lib subfolders // (both those in the p5/libs folder and those with lib subfolders
// found in the sketchbook) // found in the sketchbook)
@ -1610,20 +1607,7 @@ public class Base {
static public File getBuildFolder() { static public File getBuildFolder() {
if (buildFolder == null) { return BaseNoGui.getBuildFolder();
String buildPath = Preferences.get("build.path");
if (buildPath != null) {
buildFolder = absoluteFile(buildPath);
if (!buildFolder.exists())
buildFolder.mkdirs();
} else {
//File folder = new File(getTempFolder(), "build");
//if (!folder.exists()) folder.mkdirs();
buildFolder = createTempFolder("build");
buildFolder.deleteOnExit();
}
}
return buildFolder;
} }
@ -1635,18 +1619,7 @@ public class Base {
* to avoid conflicts in multi-user environments. (Bug 177) * to avoid conflicts in multi-user environments. (Bug 177)
*/ */
static public File createTempFolder(String name) { static public File createTempFolder(String name) {
try { return BaseNoGui.createTempFolder(name);
File folder = File.createTempFile(name, null);
//String tempPath = ignored.getParent();
//return new File(tempPath);
folder.delete();
folder.mkdirs();
return folder;
} catch (Exception e) {
e.printStackTrace();
}
return null;
} }

View File

@ -43,6 +43,8 @@ public class BaseNoGui {
/** Set true if this a proper release rather than a numbered revision. */ /** Set true if this a proper release rather than a numbered revision. */
static public boolean RELEASE = false; static public boolean RELEASE = false;
static File buildFolder;
// Current directory to use for relative paths specified on the // Current directory to use for relative paths specified on the
// commandline // commandline
static String currentDirectory = System.getProperty("user.dir"); static String currentDirectory = System.getProperty("user.dir");
@ -97,6 +99,28 @@ public class BaseNoGui {
return count; return count;
} }
/**
* Get the path to the platform's temporary folder, by creating
* a temporary temporary file and getting its parent folder.
* <br/>
* Modified for revision 0094 to actually make the folder randomized
* to avoid conflicts in multi-user environments. (Bug 177)
*/
static public File createTempFolder(String name) {
try {
File folder = File.createTempFile(name, null);
//String tempPath = ignored.getParent();
//return new File(tempPath);
folder.delete();
folder.mkdirs();
return folder;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
static public String getAvrBasePath() { static public String getAvrBasePath() {
String path = getHardwarePath() + File.separator + "tools" + String path = getHardwarePath() + File.separator + "tools" +
File.separator + "avr" + File.separator + "bin" + File.separator; File.separator + "avr" + File.separator + "bin" + File.separator;
@ -106,6 +130,23 @@ public class BaseNoGui {
return path; return path;
} }
static public File getBuildFolder() {
if (buildFolder == null) {
String buildPath = Preferences.get("build.path");
if (buildPath != null) {
buildFolder = absoluteFile(buildPath);
if (!buildFolder.exists())
buildFolder.mkdirs();
} else {
//File folder = new File(getTempFolder(), "build");
//if (!folder.exists()) folder.mkdirs();
buildFolder = createTempFolder("build");
buildFolder.deleteOnExit();
}
}
return buildFolder;
}
static public PreferencesMap getBoardPreferences() { static public PreferencesMap getBoardPreferences() {
TargetBoard board = getTargetBoard(); TargetBoard board = getTargetBoard();