Skip to content

Commit f41dc69

Browse files
author
Federico Fissore
committed
Refactored Uploader.stringContainsOneOf and StringMatchers.wildcardMatch into StringUitils
SSHUploader: filtered out some platform specific files
1 parent 92ee034 commit f41dc69

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

app/src/cc/arduino/packages/Uploader.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import processing.app.debug.MessageConsumer;
3232
import processing.app.debug.MessageSiphon;
3333
import processing.app.debug.RunnerException;
34+
import processing.app.helpers.StringUtils;
3435

3536
import java.io.File;
3637
import java.util.Arrays;
@@ -60,15 +61,6 @@ public abstract class Uploader implements MessageConsumer {
6061
"avrdude: error: buffered memory access not supported.");
6162
}
6263

63-
private static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
64-
for (String string : listOfStrings) {
65-
if (input.contains(string)) {
66-
return true;
67-
}
68-
}
69-
return false;
70-
}
71-
7264
private String error;
7365
protected boolean verbose;
7466
protected boolean notFoundError;
@@ -126,7 +118,7 @@ protected boolean executeUploadCommand(String command[]) throws RunnerException
126118

127119
public void message(String s) {
128120
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
129-
if (!verbose && stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
121+
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
130122
s = "";
131123
}
132124

@@ -145,7 +137,7 @@ public void message(String s) {
145137
error = _("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
146138
return;
147139
}
148-
if (stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
140+
if (StringUtils.stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
149141
error = _("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
150142
return;
151143
}

app/src/cc/arduino/packages/uploaders/SSHUploader.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
import processing.app.debug.RunnerException;
1414
import processing.app.debug.TargetPlatform;
1515
import processing.app.helpers.PreferencesMap;
16+
import processing.app.helpers.StringUtils;
1617

1718
import java.io.File;
1819
import java.io.IOException;
20+
import java.util.Arrays;
21+
import java.util.List;
1922
import java.util.regex.Matcher;
2023

2124
import static processing.app.I18n._;
2225

2326
public class SSHUploader extends Uploader {
2427

28+
private static final List<String> FILES_NOT_TO_COPY = Arrays.asList(".DS_Store", ".Trash", "Thumbs.db", "__MACOSX");
29+
2530
private final String ipAddress;
2631

2732
public SSHUploader(String port) {
@@ -142,12 +147,14 @@ private void recursiveSCP(File from, SCP scp) throws IOException {
142147
}
143148

144149
for (File file : files) {
145-
if (file.isDirectory() && file.canExecute()) {
146-
scp.startFolder(file.getName());
147-
recursiveSCP(file, scp);
148-
scp.endFolder();
149-
} else if (file.isFile() && file.canRead()) {
150-
scp.sendFile(file);
150+
if (!StringUtils.stringContainsOneOf(file.getName(), FILES_NOT_TO_COPY)) {
151+
if (file.isDirectory() && file.canExecute()) {
152+
scp.startFolder(file.getName());
153+
recursiveSCP(file, scp);
154+
scp.endFolder();
155+
} else if (file.isFile() && file.canRead()) {
156+
scp.sendFile(file);
157+
}
151158
}
152159
}
153160
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package processing.app.helpers;
22

3-
public class StringMatchers {
3+
import java.util.List;
4+
5+
public class StringUtils {
6+
7+
public static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
8+
for (String string : listOfStrings) {
9+
if (input.contains(string)) {
10+
return true;
11+
}
12+
}
13+
return false;
14+
}
415

516
/**
617
* Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
718
* "*" and "?" globs to match any-char-sequence and any-char respectively.
8-
*
9-
* @param input
10-
* The string to be checked
11-
* @param pattern
12-
* The pattern to match
19+
*
20+
* @param input The string to be checked
21+
* @param pattern The pattern to match
1322
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
1423
* <b>false</b> otherwise.
1524
*/
1625
public static boolean wildcardMatch(String input, String pattern) {
1726
String regex = pattern.replace("?", ".?").replace("*", ".*?");
1827
return input.matches(regex);
1928
}
20-
2129
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Comparator;
1010
import java.util.List;
1111

12-
import static processing.app.helpers.StringMatchers.wildcardMatch;
12+
import static processing.app.helpers.StringUtils.wildcardMatch;
1313

1414
public class Library {
1515

0 commit comments

Comments
 (0)