Skip to content

Commit 6378c8c

Browse files
author
Federico Fissore
committed
Moving Library.SOURCE_CONTROL_FOLDERS into FileUtils.isSCCSOrHiddenFile #1619
1 parent 2ada526 commit 6378c8c

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

app/src/processing/app/Base.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,35 +1523,39 @@ public void actionPerformed(ActionEvent actionevent) {
15231523
* should replace the sketch in the current window, or false when the
15241524
* sketch should open in a new window.
15251525
*/
1526-
protected boolean addSketches(JMenu menu, File folder,
1527-
final boolean replaceExisting) throws IOException {
1526+
protected boolean addSketches(JMenu menu, File folder, final boolean replaceExisting) throws IOException {
15281527
if (folder == null)
15291528
return false;
15301529

1531-
// skip .DS_Store files, etc (this shouldn't actually be necessary)
15321530
if (!folder.isDirectory()) return false;
15331531

1534-
String[] list = folder.list();
1532+
File[] files = folder.listFiles();
15351533
// If a bad folder or unreadable or whatever, this will come back null
1536-
if (list == null) return false;
1534+
if (files == null) return false;
15371535

1538-
// Alphabetize list, since it's not always alpha order
1539-
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
1536+
// Alphabetize files, since it's not always alpha order
1537+
Arrays.sort(files, new Comparator<File>() {
1538+
@Override
1539+
public int compare(File file, File file2) {
1540+
return file.getName().compareToIgnoreCase(file2.getName());
1541+
}
1542+
});
15401543

15411544
boolean ifound = false;
15421545

1543-
for (String name : list) {
1544-
if ((name.charAt(0) == '.') ||
1545-
name.equals("CVS")) continue;
1546+
for (File subfolder : files) {
1547+
if (FileUtils.isSCCSOrHiddenFile(subfolder)) {
1548+
continue;
1549+
}
15461550

1547-
File subfolder = new File(folder, name);
15481551
if (!subfolder.isDirectory()) continue;
15491552

1550-
if (addSketchesSubmenu(menu, name, subfolder, replaceExisting))
1553+
if (addSketchesSubmenu(menu, subfolder.getName(), subfolder, replaceExisting)) {
15511554
ifound = true;
1555+
}
15521556
}
15531557

1554-
return ifound; // actually ignored, but..
1558+
return ifound;
15551559
}
15561560

15571561
private boolean addSketchesSubmenu(JMenu menu, Library lib,

app/src/processing/app/debug/Compiler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import processing.app.Preferences;
3939
import processing.app.Sketch;
4040
import processing.app.SketchCode;
41+
import processing.app.helpers.FileUtils;
4142
import processing.app.helpers.PreferencesMap;
4243
import processing.app.helpers.ProcessUtils;
4344
import processing.app.helpers.StringReplacer;
@@ -575,16 +576,19 @@ static public List<File> findFilesInFolder(File folder, String extension,
575576
boolean recurse) {
576577
List<File> files = new ArrayList<File>();
577578

578-
if (Library.SOURCE_CONTROL_FOLDERS.contains(folder.getName())) {
579+
if (FileUtils.isSCCSOrHiddenFile(folder)) {
579580
return files;
580581
}
581582

582-
if (folder.listFiles() == null)
583+
File[] listFiles = folder.listFiles();
584+
if (listFiles == null) {
583585
return files;
586+
}
584587

585-
for (File file : folder.listFiles()) {
586-
if (file.getName().startsWith("."))
588+
for (File file : listFiles) {
589+
if (FileUtils.isSCCSOrHiddenFile(file)) {
587590
continue; // skip hidden files
591+
}
588592

589593
if (file.getName().endsWith("." + extension))
590594
files.add(file);

app/src/processing/app/helpers/FileUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import java.io.FileInputStream;
55
import java.io.FileOutputStream;
66
import java.io.IOException;
7+
import java.util.Arrays;
8+
import java.util.List;
79
import java.util.Random;
810
import java.util.regex.Pattern;
911

1012
public class FileUtils {
1113

14+
private static final List<String> SOURCE_CONTROL_FOLDERS = Arrays.asList("CVS", "RCS", ".git", ".svn", ".hg", ".bzr");
1215
private static final Pattern BACKSLASH = Pattern.compile("\\\\");
1316

1417
/**
@@ -163,4 +166,8 @@ public static String relativePath(String origin, String target) {
163166
public static String getLinuxPathFrom(File file) {
164167
return BACKSLASH.matcher(file.getAbsolutePath()).replaceAll("/");
165168
}
169+
170+
public static boolean isSCCSOrHiddenFile(File file) {
171+
return file.isHidden() || file.getName().charAt(0) == '.' || (file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName()));
172+
}
166173
}

app/src/processing/app/packages/Library.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package processing.app.packages;
22

3+
import processing.app.helpers.FileUtils;
34
import processing.app.helpers.PreferencesMap;
45

56
import java.io.File;
@@ -35,7 +36,6 @@ public class Library {
3536
private static final List<String> OPTIONAL_FILES = Arrays
3637
.asList(new String[] { "keywords.txt", "library.properties" });
3738

38-
public static final List<String> SOURCE_CONTROL_FOLDERS = Arrays.asList(new String[]{"CSV", "RCS", ".git", ".svn", ".hq", ".bzr"});
3939

4040
/**
4141
* Scans inside a folder and create a Library object out of it. Automatically
@@ -77,7 +77,7 @@ private static Library createLibrary(File libFolder) throws IOException {
7777
// 3. check if root folder contains prohibited stuff
7878
for (File file : libFolder.listFiles()) {
7979
if (file.isDirectory()) {
80-
if (SOURCE_CONTROL_FOLDERS.contains(file.getName())) {
80+
if (FileUtils.isSCCSOrHiddenFile(file)) {
8181
System.out.println("WARNING: Ignoring spurious " + file.getName() + " folder in '" + properties.get("name") + "' library");
8282
continue;
8383
}
@@ -130,7 +130,7 @@ private static Library createPre15Library(File libFolder) {
130130
res.folder = libFolder;
131131
res.srcFolder = libFolder;
132132
res.name = libFolder.getName();
133-
res.architectures = Arrays.asList(new String[]{"*"});
133+
res.architectures = Arrays.asList("*");
134134
res.pre15Lib = true;
135135
return res;
136136
}

0 commit comments

Comments
 (0)