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

Moving Library.SOURCE_CONTROL_FOLDERS into FileUtils.isSCCSOrHiddenFile #1619

This commit is contained in:
Federico Fissore 2013-10-14 14:48:41 +02:00
parent 2ada52623d
commit 6378c8c647
4 changed files with 35 additions and 20 deletions

View File

@ -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<File>() {
@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,

View File

@ -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<File> files = new ArrayList<File>();
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);

View File

@ -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<String> 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()));
}
}

View File

@ -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<String> OPTIONAL_FILES = Arrays
.asList(new String[] { "keywords.txt", "library.properties" });
public static final List<String> 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;
}