From 4d3599b2c47044a627374d68ae4cc5d7680e1e72 Mon Sep 17 00:00:00 2001 From: Claudio Indellicati Date: Tue, 26 Aug 2014 19:14:45 +0200 Subject: [PATCH] Moved getBuildFolder() and related members/methods from Base to BaseNoGui. --- app/src/processing/app/Base.java | 31 ++------------------ app/src/processing/app/BaseNoGui.java | 41 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 914cd3487..20a4658aa 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -27,7 +27,6 @@ import java.awt.event.*; import java.io.*; import java.util.*; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; import javax.swing.*; @@ -74,8 +73,6 @@ public class Base { // so that the errors while building don't show up again. boolean builtOnce; - static File buildFolder; - // classpath for all known libraries for p5 // (both those in the p5/libs folder and those with lib subfolders // found in the sketchbook) @@ -1610,20 +1607,7 @@ public class Base { 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; + return BaseNoGui.getBuildFolder(); } @@ -1635,18 +1619,7 @@ public class Base { * 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; + return BaseNoGui.createTempFolder(name); } diff --git a/app/src/processing/app/BaseNoGui.java b/app/src/processing/app/BaseNoGui.java index d793108fb..43351af97 100644 --- a/app/src/processing/app/BaseNoGui.java +++ b/app/src/processing/app/BaseNoGui.java @@ -43,6 +43,8 @@ public class BaseNoGui { /** Set true if this a proper release rather than a numbered revision. */ static public boolean RELEASE = false; + static File buildFolder; + // Current directory to use for relative paths specified on the // commandline static String currentDirectory = System.getProperty("user.dir"); @@ -97,6 +99,28 @@ public class BaseNoGui { return count; } + /** + * Get the path to the platform's temporary folder, by creating + * a temporary temporary file and getting its parent folder. + *
+ * 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() { String path = getHardwarePath() + File.separator + "tools" + File.separator + "avr" + File.separator + "bin" + File.separator; @@ -106,6 +130,23 @@ public class BaseNoGui { 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() { TargetBoard board = getTargetBoard();