mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-11 22:24:13 +01:00
Moving Library.SOURCE_CONTROL_FOLDERS into FileUtils.isSCCSOrHiddenFile #1619
This commit is contained in:
parent
2ada52623d
commit
6378c8c647
@ -1523,35 +1523,39 @@ public class Base {
|
|||||||
* should replace the sketch in the current window, or false when the
|
* should replace the sketch in the current window, or false when the
|
||||||
* sketch should open in a new window.
|
* sketch should open in a new window.
|
||||||
*/
|
*/
|
||||||
protected boolean addSketches(JMenu menu, File folder,
|
protected boolean addSketches(JMenu menu, File folder, final boolean replaceExisting) throws IOException {
|
||||||
final boolean replaceExisting) throws IOException {
|
|
||||||
if (folder == null)
|
if (folder == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// skip .DS_Store files, etc (this shouldn't actually be necessary)
|
|
||||||
if (!folder.isDirectory()) return false;
|
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 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
|
// Alphabetize files, since it's not always alpha order
|
||||||
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
|
Arrays.sort(files, new Comparator<File>() {
|
||||||
|
@Override
|
||||||
|
public int compare(File file, File file2) {
|
||||||
|
return file.getName().compareToIgnoreCase(file2.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
boolean ifound = false;
|
boolean ifound = false;
|
||||||
|
|
||||||
for (String name : list) {
|
for (File subfolder : files) {
|
||||||
if ((name.charAt(0) == '.') ||
|
if (FileUtils.isSCCSOrHiddenFile(subfolder)) {
|
||||||
name.equals("CVS")) continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
File subfolder = new File(folder, name);
|
|
||||||
if (!subfolder.isDirectory()) continue;
|
if (!subfolder.isDirectory()) continue;
|
||||||
|
|
||||||
if (addSketchesSubmenu(menu, name, subfolder, replaceExisting))
|
if (addSketchesSubmenu(menu, subfolder.getName(), subfolder, replaceExisting)) {
|
||||||
ifound = true;
|
ifound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ifound; // actually ignored, but..
|
return ifound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addSketchesSubmenu(JMenu menu, Library lib,
|
private boolean addSketchesSubmenu(JMenu menu, Library lib,
|
||||||
|
@ -38,6 +38,7 @@ import processing.app.I18n;
|
|||||||
import processing.app.Preferences;
|
import processing.app.Preferences;
|
||||||
import processing.app.Sketch;
|
import processing.app.Sketch;
|
||||||
import processing.app.SketchCode;
|
import processing.app.SketchCode;
|
||||||
|
import processing.app.helpers.FileUtils;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
import processing.app.helpers.ProcessUtils;
|
import processing.app.helpers.ProcessUtils;
|
||||||
import processing.app.helpers.StringReplacer;
|
import processing.app.helpers.StringReplacer;
|
||||||
@ -575,16 +576,19 @@ public class Compiler implements MessageConsumer {
|
|||||||
boolean recurse) {
|
boolean recurse) {
|
||||||
List<File> files = new ArrayList<File>();
|
List<File> files = new ArrayList<File>();
|
||||||
|
|
||||||
if (Library.SOURCE_CONTROL_FOLDERS.contains(folder.getName())) {
|
if (FileUtils.isSCCSOrHiddenFile(folder)) {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (folder.listFiles() == null)
|
File[] listFiles = folder.listFiles();
|
||||||
|
if (listFiles == null) {
|
||||||
return files;
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
for (File file : folder.listFiles()) {
|
for (File file : listFiles) {
|
||||||
if (file.getName().startsWith("."))
|
if (FileUtils.isSCCSOrHiddenFile(file)) {
|
||||||
continue; // skip hidden files
|
continue; // skip hidden files
|
||||||
|
}
|
||||||
|
|
||||||
if (file.getName().endsWith("." + extension))
|
if (file.getName().endsWith("." + extension))
|
||||||
files.add(file);
|
files.add(file);
|
||||||
|
@ -4,11 +4,14 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class FileUtils {
|
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("\\\\");
|
private static final Pattern BACKSLASH = Pattern.compile("\\\\");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,4 +166,8 @@ public class FileUtils {
|
|||||||
public static String getLinuxPathFrom(File file) {
|
public static String getLinuxPathFrom(File file) {
|
||||||
return BACKSLASH.matcher(file.getAbsolutePath()).replaceAll("/");
|
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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package processing.app.packages;
|
package processing.app.packages;
|
||||||
|
|
||||||
|
import processing.app.helpers.FileUtils;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -35,7 +36,6 @@ public class Library {
|
|||||||
private static final List<String> OPTIONAL_FILES = Arrays
|
private static final List<String> OPTIONAL_FILES = Arrays
|
||||||
.asList(new String[] { "keywords.txt", "library.properties" });
|
.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
|
* 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
|
// 3. check if root folder contains prohibited stuff
|
||||||
for (File file : libFolder.listFiles()) {
|
for (File file : libFolder.listFiles()) {
|
||||||
if (file.isDirectory()) {
|
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");
|
System.out.println("WARNING: Ignoring spurious " + file.getName() + " folder in '" + properties.get("name") + "' library");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ public class Library {
|
|||||||
res.folder = libFolder;
|
res.folder = libFolder;
|
||||||
res.srcFolder = libFolder;
|
res.srcFolder = libFolder;
|
||||||
res.name = libFolder.getName();
|
res.name = libFolder.getName();
|
||||||
res.architectures = Arrays.asList(new String[]{"*"});
|
res.architectures = Arrays.asList("*");
|
||||||
res.pre15Lib = true;
|
res.pre15Lib = true;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user