diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 87b342e53..f00169862 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1523,35 +1523,39 @@ public class Base { * should replace the sketch in the current window, or false when the * sketch should open in a new window. */ - protected boolean addSketches(JMenu menu, File folder, - final boolean replaceExisting) throws IOException { + protected boolean addSketches(JMenu menu, File folder, final boolean replaceExisting) throws IOException { if (folder == null) return false; - // skip .DS_Store files, etc (this shouldn't actually be necessary) if (!folder.isDirectory()) return false; - String[] list = folder.list(); + File[] files = folder.listFiles(); // If a bad folder or unreadable or whatever, this will come back null - if (list == null) return false; + if (files == null) return false; - // Alphabetize list, since it's not always alpha order - Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); + // Alphabetize files, since it's not always alpha order + Arrays.sort(files, new Comparator() { + @Override + public int compare(File file, File file2) { + return file.getName().compareToIgnoreCase(file2.getName()); + } + }); boolean ifound = false; - for (String name : list) { - if ((name.charAt(0) == '.') || - name.equals("CVS")) continue; + for (File subfolder : files) { + if (FileUtils.isSCCSOrHiddenFile(subfolder)) { + continue; + } - File subfolder = new File(folder, name); if (!subfolder.isDirectory()) continue; - if (addSketchesSubmenu(menu, name, subfolder, replaceExisting)) + if (addSketchesSubmenu(menu, subfolder.getName(), subfolder, replaceExisting)) { ifound = true; + } } - return ifound; // actually ignored, but.. + return ifound; } private boolean addSketchesSubmenu(JMenu menu, Library lib, diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index d9bf5f1f1..7cbba74c5 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -38,6 +38,7 @@ import processing.app.I18n; import processing.app.Preferences; import processing.app.Sketch; import processing.app.SketchCode; +import processing.app.helpers.FileUtils; import processing.app.helpers.PreferencesMap; import processing.app.helpers.ProcessUtils; import processing.app.helpers.StringReplacer; @@ -575,16 +576,19 @@ public class Compiler implements MessageConsumer { boolean recurse) { List files = new ArrayList(); - if (Library.SOURCE_CONTROL_FOLDERS.contains(folder.getName())) { + if (FileUtils.isSCCSOrHiddenFile(folder)) { return files; } - if (folder.listFiles() == null) + File[] listFiles = folder.listFiles(); + if (listFiles == null) { return files; + } - for (File file : folder.listFiles()) { - if (file.getName().startsWith(".")) + for (File file : listFiles) { + if (FileUtils.isSCCSOrHiddenFile(file)) { continue; // skip hidden files + } if (file.getName().endsWith("." + extension)) files.add(file); diff --git a/app/src/processing/app/helpers/FileUtils.java b/app/src/processing/app/helpers/FileUtils.java index e79da330d..f35a14918 100644 --- a/app/src/processing/app/helpers/FileUtils.java +++ b/app/src/processing/app/helpers/FileUtils.java @@ -4,11 +4,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import java.util.Random; import java.util.regex.Pattern; public class FileUtils { + private static final List SOURCE_CONTROL_FOLDERS = Arrays.asList("CVS", "RCS", ".git", ".svn", ".hg", ".bzr"); private static final Pattern BACKSLASH = Pattern.compile("\\\\"); /** @@ -163,4 +166,8 @@ public class FileUtils { public static String getLinuxPathFrom(File file) { return BACKSLASH.matcher(file.getAbsolutePath()).replaceAll("/"); } + + public static boolean isSCCSOrHiddenFile(File file) { + return file.isHidden() || file.getName().charAt(0) == '.' || (file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName())); + } } diff --git a/app/src/processing/app/packages/Library.java b/app/src/processing/app/packages/Library.java index 4aed14acb..839377448 100644 --- a/app/src/processing/app/packages/Library.java +++ b/app/src/processing/app/packages/Library.java @@ -1,5 +1,6 @@ package processing.app.packages; +import processing.app.helpers.FileUtils; import processing.app.helpers.PreferencesMap; import java.io.File; @@ -35,7 +36,6 @@ public class Library { private static final List OPTIONAL_FILES = Arrays .asList(new String[] { "keywords.txt", "library.properties" }); - public static final List SOURCE_CONTROL_FOLDERS = Arrays.asList(new String[]{"CSV", "RCS", ".git", ".svn", ".hq", ".bzr"}); /** * Scans inside a folder and create a Library object out of it. Automatically @@ -77,7 +77,7 @@ public class Library { // 3. check if root folder contains prohibited stuff for (File file : libFolder.listFiles()) { if (file.isDirectory()) { - if (SOURCE_CONTROL_FOLDERS.contains(file.getName())) { + if (FileUtils.isSCCSOrHiddenFile(file)) { System.out.println("WARNING: Ignoring spurious " + file.getName() + " folder in '" + properties.get("name") + "' library"); continue; } @@ -130,7 +130,7 @@ public class Library { res.folder = libFolder; res.srcFolder = libFolder; res.name = libFolder.getName(); - res.architectures = Arrays.asList(new String[]{"*"}); + res.architectures = Arrays.asList("*"); res.pre15Lib = true; return res; }