1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-29 18:52:13 +01:00

Refactored Uploader.stringContainsOneOf and StringMatchers.wildcardMatch into StringUitils

SSHUploader: filtered out some platform specific files
This commit is contained in:
Federico Fissore 2013-06-28 14:59:04 +02:00
parent 92ee034964
commit f41dc69c08
4 changed files with 32 additions and 25 deletions

View File

@ -31,6 +31,7 @@ import processing.app.Preferences;
import processing.app.debug.MessageConsumer;
import processing.app.debug.MessageSiphon;
import processing.app.debug.RunnerException;
import processing.app.helpers.StringUtils;
import java.io.File;
import java.util.Arrays;
@ -60,15 +61,6 @@ public abstract class Uploader implements MessageConsumer {
"avrdude: error: buffered memory access not supported.");
}
private static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
for (String string : listOfStrings) {
if (input.contains(string)) {
return true;
}
}
return false;
}
private String error;
protected boolean verbose;
protected boolean notFoundError;
@ -126,7 +118,7 @@ public abstract class Uploader implements MessageConsumer {
public void message(String s) {
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
if (!verbose && stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
s = "";
}
@ -145,7 +137,7 @@ public abstract class Uploader implements MessageConsumer {
error = _("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
return;
}
if (stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
if (StringUtils.stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
error = _("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
return;
}

View File

@ -13,15 +13,20 @@ import processing.app.Preferences;
import processing.app.debug.RunnerException;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.StringUtils;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import static processing.app.I18n._;
public class SSHUploader extends Uploader {
private static final List<String> FILES_NOT_TO_COPY = Arrays.asList(".DS_Store", ".Trash", "Thumbs.db", "__MACOSX");
private final String ipAddress;
public SSHUploader(String port) {
@ -142,12 +147,14 @@ public class SSHUploader extends Uploader {
}
for (File file : files) {
if (file.isDirectory() && file.canExecute()) {
scp.startFolder(file.getName());
recursiveSCP(file, scp);
scp.endFolder();
} else if (file.isFile() && file.canRead()) {
scp.sendFile(file);
if (!StringUtils.stringContainsOneOf(file.getName(), FILES_NOT_TO_COPY)) {
if (file.isDirectory() && file.canExecute()) {
scp.startFolder(file.getName());
recursiveSCP(file, scp);
scp.endFolder();
} else if (file.isFile() && file.canRead()) {
scp.sendFile(file);
}
}
}
}

View File

@ -1,15 +1,24 @@
package processing.app.helpers;
public class StringMatchers {
import java.util.List;
public class StringUtils {
public static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
for (String string : listOfStrings) {
if (input.contains(string)) {
return true;
}
}
return false;
}
/**
* Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
* "*" and "?" globs to match any-char-sequence and any-char respectively.
*
* @param input
* The string to be checked
* @param pattern
* The pattern to match
*
* @param input The string to be checked
* @param pattern The pattern to match
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
* <b>false</b> otherwise.
*/
@ -17,5 +26,4 @@ public class StringMatchers {
String regex = pattern.replace("?", ".?").replace("*", ".*?");
return input.matches(regex);
}
}

View File

@ -9,7 +9,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import static processing.app.helpers.StringMatchers.wildcardMatch;
import static processing.app.helpers.StringUtils.wildcardMatch;
public class Library {