diff --git a/.classpath b/.classpath
index eabc35c4180..4d3d2bcc0fb 100644
--- a/.classpath
+++ b/.classpath
@@ -27,6 +27,7 @@
+
diff --git a/app/lib/commons-lang3-3.3.2.jar b/app/lib/commons-lang3-3.3.2.jar
deleted file mode 100644
index 2ce08ae99d1..00000000000
Binary files a/app/lib/commons-lang3-3.3.2.jar and /dev/null differ
diff --git a/app/lib/commons-lang3-3.8.1.jar b/app/lib/commons-lang3-3.8.1.jar
new file mode 100644
index 00000000000..2c65ce67d5c
Binary files /dev/null and b/app/lib/commons-lang3-3.8.1.jar differ
diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
index 62ebfc2acaf..1195f94d229 100644
--- a/app/src/processing/app/Base.java
+++ b/app/src/processing/app/Base.java
@@ -1691,19 +1691,12 @@ public int compare(File file, File file2) {
});
boolean ifound = false;
-
for (File subfolder : files) {
- if (FileUtils.isSCCSOrHiddenFile(subfolder)) {
- continue;
- }
-
- if (!subfolder.isDirectory()) continue;
-
- if (addSketchesSubmenu(menu, subfolder.getName(), subfolder)) {
+ if (!FileUtils.isSCCSOrHiddenFile(subfolder) && subfolder.isDirectory()
+ && addSketchesSubmenu(menu, subfolder.getName(), subfolder)) {
ifound = true;
}
}
-
return ifound;
}
diff --git a/app/test/cc/arduino/packages/uploaders/MergeSketchWithUploaderTest.java b/app/test/cc/arduino/packages/uploaders/MergeSketchWithUploaderTest.java
index 384aa169deb..2f048b2a48b 100644
--- a/app/test/cc/arduino/packages/uploaders/MergeSketchWithUploaderTest.java
+++ b/app/test/cc/arduino/packages/uploaders/MergeSketchWithUploaderTest.java
@@ -35,18 +35,29 @@
import processing.app.helpers.FileUtils;
import java.io.File;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.List;
import static org.junit.Assert.assertEquals;
public class MergeSketchWithUploaderTest {
private File sketch;
+ private File bootloader;
@Before
public void setup() throws Exception {
- File originalSketch = new File(MergeSketchWithUploaderTest.class.getResource("/sketch.hex").getFile());
+ File originalSketch = getResourceFile("/sketch.hex");
sketch = new File(System.getProperty("java.io.tmpdir"), "sketch.hex");
FileUtils.copyFile(originalSketch, sketch);
+ removeCariageReturns(sketch);
+
+ File originalBootloader = getResourceFile("/optiboot_atmega328.hex");
+ bootloader = new File(System.getProperty("java.io.tmpdir"), "optiboot_atmega328.hex");
+ FileUtils.copyFile(originalBootloader, bootloader);
+ removeCariageReturns(bootloader);
}
@After
@@ -57,11 +68,24 @@ public void removeTmpFile() {
@Test
public void shouldMergeWithOptiboot() throws Exception {
assertEquals(11720, sketch.length());
+ assertEquals(1432, bootloader.length());
- File bootloader = new File(MergeSketchWithUploaderTest.class.getResource("/optiboot_atmega328.hex").getFile());
+ File bootloader = getResourceFile("/optiboot_atmega328.hex");
new MergeSketchWithBooloader().merge(sketch, bootloader);
assertEquals(13140, sketch.length());
}
+ private static File getResourceFile(String resourcePath) throws Exception {
+ return new File(URLDecoder.decode(
+ MergeSketchWithUploaderTest.class.getResource(resourcePath).getFile(), "UTF-8"));
+ }
+ private static void removeCariageReturns(File file) throws Exception {
+ List lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
+ StringBuilder contentBuilder = new StringBuilder();
+ for(String line : lines) {
+ contentBuilder.append(line).append('\n');
+ }
+ Files.write(file.toPath(), contentBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ }
}
diff --git a/app/test/processing/app/CommandLineTest.java b/app/test/processing/app/CommandLineTest.java
index c5fb7b8a156..9ac760b1fbb 100644
--- a/app/test/processing/app/CommandLineTest.java
+++ b/app/test/processing/app/CommandLineTest.java
@@ -139,10 +139,10 @@ public void testCommandLineVersion() throws Exception {
pr.waitFor();
Assertions.assertThat(pr.exitValue())
- .as("Process will finish with exit code 0 in --version")
- .isEqualTo(0);
+ .as("Process will finish with exit code 0 in --version")
+ .isEqualTo(0);
Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
- .matches("Arduino: \\d+\\.\\d+\\.\\d+.*\n");
+ .matches("Arduino: \\d+\\.\\d+\\.\\d+.*\r?\n");
}
@Test
@@ -156,7 +156,7 @@ public void testCommandLineMultipleAction() throws Exception {
pr.waitFor();
Assertions.assertThat(pr.exitValue())
- .as("Multiple Action will be rejected")
- .isEqualTo(3);
+ .as("Multiple Action will be rejected")
+ .isEqualTo(3);
}
}
diff --git a/app/test/processing/app/helpers/StringUtilsTest.java b/app/test/processing/app/helpers/StringUtilsTest.java
deleted file mode 100644
index 1ddbf51b35e..00000000000
--- a/app/test/processing/app/helpers/StringUtilsTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This file is part of Arduino.
- *
- * Arduino is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2015 Arduino LLC (http://www.arduino.cc/)
- */
-
-package processing.app.helpers;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class StringUtilsTest {
-
- @Test
- public void shouldJoinAnArray() {
- assertEquals("1 - 2 - 3", StringUtils.join(new String[]{"1", "2", "3"}, " - "));
- }
-}
diff --git a/arduino-core/.classpath b/arduino-core/.classpath
index e26f190087a..606a6e5ffef 100644
--- a/arduino-core/.classpath
+++ b/arduino-core/.classpath
@@ -16,7 +16,7 @@
-
+
diff --git a/arduino-core/lib/commons-lang3-3.3.2.jar b/arduino-core/lib/commons-lang3-3.3.2.jar
deleted file mode 100644
index 2ce08ae99d1..00000000000
Binary files a/arduino-core/lib/commons-lang3-3.3.2.jar and /dev/null differ
diff --git a/arduino-core/lib/commons-lang3-3.8.1.jar b/arduino-core/lib/commons-lang3-3.8.1.jar
new file mode 100644
index 00000000000..2c65ce67d5c
Binary files /dev/null and b/arduino-core/lib/commons-lang3-3.8.1.jar differ
diff --git a/arduino-core/src/cc/arduino/packages/Uploader.java b/arduino-core/src/cc/arduino/packages/Uploader.java
index f2e2126d54b..55ddd46e95a 100644
--- a/arduino-core/src/cc/arduino/packages/Uploader.java
+++ b/arduino-core/src/cc/arduino/packages/Uploader.java
@@ -37,35 +37,35 @@
import processing.app.debug.MessageConsumer;
import processing.app.debug.MessageSiphon;
import processing.app.helpers.ProcessUtils;
-import processing.app.helpers.StringUtils;
import java.io.File;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang3.StringUtils;
+
import static processing.app.I18n.tr;
public abstract class Uploader implements MessageConsumer {
- private static final List STRINGS_TO_SUPPRESS;
- private static final List AVRDUDE_PROBLEMS;
+ private static final String[] STRINGS_TO_SUPPRESS;
+ private static final String[] AVRDUDE_PROBLEMS;
static {
- STRINGS_TO_SUPPRESS = Arrays.asList("Connecting to programmer:",
+ STRINGS_TO_SUPPRESS = new String[] {"Connecting to programmer:",
"Found programmer: Id = \"CATERIN\"; type = S",
"Software Version = 1.0; No Hardware Version given.",
"Programmer supports auto addr increment.",
"Programmer supports buffered memory access with buffersize=128 bytes.",
- "Programmer supports the following devices:", "Device code: 0x44");
+ "Programmer supports the following devices:", "Device code: 0x44"};
- AVRDUDE_PROBLEMS = Arrays.asList("Programmer is not responding",
+ AVRDUDE_PROBLEMS = new String[] {"Programmer is not responding",
"programmer is not responding",
"protocol error", "avrdude: ser_open(): can't open device",
"avrdude: ser_drain(): read error",
"avrdude: ser_send(): write error",
- "avrdude: error: buffered memory access not supported.");
+ "avrdude: error: buffered memory access not supported."};
}
protected final boolean verbose;
@@ -155,7 +155,7 @@ public String getFailureMessage() {
@Override
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 && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
+ if (!verbose && StringUtils.containsAny(s, STRINGS_TO_SUPPRESS)) {
s = "";
}
@@ -175,7 +175,7 @@ public void message(String s) {
error = tr("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
return;
}
- if (StringUtils.stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
+ if (StringUtils.containsAny(s, AVRDUDE_PROBLEMS)) {
error = tr("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
return;
}
diff --git a/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java
index d37166699a0..3f7202fa6a9 100644
--- a/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java
+++ b/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java
@@ -36,6 +36,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonFactory;
@@ -48,7 +50,6 @@
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Discovery;
import processing.app.PreferencesData;
-import processing.app.helpers.StringUtils;
public class PluggableDiscovery implements Discovery {
diff --git a/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java b/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
index a6f34b265d2..bbab2bd7b09 100644
--- a/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
+++ b/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
@@ -29,19 +29,19 @@
package cc.arduino.packages.uploaders;
-import processing.app.helpers.FileUtils;
-
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.List;
public class MergeSketchWithBooloader {
public void merge(File sketch, File bootloader) throws IOException {
- List mergedSketch = FileUtils.readFileToListOfStrings(sketch);
+ List mergedSketch = Files.readAllLines(sketch.toPath(), StandardCharsets.UTF_8);
mergedSketch.remove(mergedSketch.size() - 1);
- mergedSketch.addAll(FileUtils.readFileToListOfStrings(bootloader));
+ mergedSketch.addAll(Files.readAllLines(bootloader.toPath(), StandardCharsets.UTF_8));
FileWriter writer = null;
try {
diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java
index cf6416c2f29..fb0eb3ffbd5 100644
--- a/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java
+++ b/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java
@@ -44,18 +44,23 @@
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.PreferencesMapException;
import processing.app.helpers.StringReplacer;
-import processing.app.helpers.StringUtils;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang3.StringUtils;
import static processing.app.I18n.tr;
public class SSHUploader extends Uploader {
- private static final List FILES_NOT_TO_COPY = Arrays.asList(".DS_Store", ".Trash", "Thumbs.db", "__MACOSX");
+ private static final Set FILES_NOT_TO_COPY =
+ Collections.unmodifiableSet(new HashSet(Arrays.asList(".DS_Store", ".Trash", "Thumbs.db", "__MACOSX")));
private final BoardPort port;
@@ -223,7 +228,7 @@ private void recursiveSCP(File from, SCP scp) throws IOException {
}
for (File file : files) {
- if (!StringUtils.stringContainsOneOf(file.getName(), FILES_NOT_TO_COPY)) {
+ if (!FILES_NOT_TO_COPY.contains(file.getName())) {
if (file.isDirectory() && file.canExecute()) {
scp.startFolder(file.getName());
recursiveSCP(file, scp);
diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java
index 0a58769712a..230ae63d4a5 100644
--- a/arduino-core/src/processing/app/BaseNoGui.java
+++ b/arduino-core/src/processing/app/BaseNoGui.java
@@ -485,8 +485,8 @@ static public void initPackages() throws Exception {
} catch (JsonProcessingException | SignatureVerificationFailedException e) {
File indexFile = indexer.getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
File indexSignatureFile = indexer.getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME + ".sig");
- FileUtils.deleteIfExists(indexFile);
- FileUtils.deleteIfExists(indexSignatureFile);
+ indexFile.delete();
+ indexSignatureFile.delete();
throw e;
}
indexer.syncWithFilesystem();
@@ -502,7 +502,7 @@ static public void initPackages() throws Exception {
librariesIndexer.parseIndex();
} catch (JsonProcessingException e) {
File librariesIndexFile = librariesIndexer.getIndexFile();
- FileUtils.deleteIfExists(librariesIndexFile);
+ librariesIndexFile.delete();
}
if (discoveryManager == null) {
diff --git a/arduino-core/src/processing/app/helpers/FileUtils.java b/arduino-core/src/processing/app/helpers/FileUtils.java
index b668d545e5f..9694a2f5b2a 100644
--- a/arduino-core/src/processing/app/helpers/FileUtils.java
+++ b/arduino-core/src/processing/app/helpers/FileUtils.java
@@ -2,16 +2,22 @@
import org.apache.commons.compress.utils.IOUtils;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.util.*;
-import java.util.regex.Pattern;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
public class FileUtils {
private static final List SOURCE_CONTROL_FOLDERS = Arrays.asList("CVS", "RCS", ".git", ".svn", ".hg", ".bzr");
- private static final Pattern BACKSLASH = Pattern.compile("\\\\");
/**
* Checks, whether the child directory is a subdirectory of the base directory.
@@ -109,75 +115,6 @@ public static File createTempFolder(File parent, String prefix, String suffix) t
return Files.createDirectories(Paths.get(parent.getAbsolutePath(), prefix + suffix)).toFile();
}
- //
- // Compute relative path to "target" from a directory "origin".
- //
- // If "origin" is not absolute, it is relative from the current directory.
- // If "target" is not absolute, it is relative from "origin".
- //
- // by Shigeru KANEMOTO at SWITCHSCIENCE.
- //
- public static String relativePath(String origin, String target) {
- try {
- origin = (new File(origin)).getCanonicalPath();
- File targetFile = new File(target);
- if (targetFile.isAbsolute())
- target = targetFile.getCanonicalPath();
- else
- target = (new File(origin, target)).getCanonicalPath();
- } catch (IOException e) {
- return null;
- }
-
- if (origin.equals(target)) {
- // origin and target is identical.
- return ".";
- }
-
- if (origin.equals(File.separator)) {
- // origin is root.
- return "." + target;
- }
-
- String prefix = "";
- String root = File.separator;
-
- if (System.getProperty("os.name").indexOf("Windows") != -1) {
- if (origin.startsWith("\\\\") || target.startsWith("\\\\")) {
- // Windows UNC path not supported.
- return null;
- }
-
- char originLetter = origin.charAt(0);
- char targetLetter = target.charAt(0);
- if (Character.isLetter(originLetter) && Character.isLetter(targetLetter)) {
- // Windows only
- if (originLetter != targetLetter) {
- // Drive letters differ
- return null;
- }
- }
-
- prefix = "" + originLetter + ':';
- root = prefix + File.separator;
- }
-
- String relative = "";
- while (!target.startsWith(origin + File.separator)) {
- origin = (new File(origin)).getParent();
- if (origin.equals(root))
- origin = prefix;
- relative += "..";
- relative += File.separator;
- }
-
- return relative + target.substring(origin.length() + 1);
- }
-
- public static String getLinuxPathFrom(File file) {
- return BACKSLASH.matcher(file.getAbsolutePath()).replaceAll("/");
- }
-
public static boolean isSCCSOrHiddenFile(File file) {
return isSCCSFolder(file) || isHiddenFile(file);
}
@@ -209,25 +146,6 @@ public static String readFileToString(File file, String encoding) throws IOExcep
}
}
- public static List readFileToListOfStrings(File file) throws IOException {
- List strings = new LinkedList<>();
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader(file));
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.replaceAll("\r", "").replaceAll("\n", "").replaceAll(" ", "");
- strings.add(line);
- }
- return strings;
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
-
-
/**
* Returns true if the given file has any of the given extensions.
*
@@ -236,10 +154,6 @@ public static List readFileToListOfStrings(File file) throws IOException
* dot). Should all be lowercase, case insensitive matching
* is used.
*/
- public static boolean hasExtension(File file, String... extensions) {
- return hasExtension(file, Arrays.asList(extensions));
- }
-
public static boolean hasExtension(File file, List extensions) {
String extension = splitFilename(file).extension;
return extensions.contains(extension.toLowerCase());
@@ -364,21 +278,4 @@ public static List listFiles(File folder, boolean recursive,
return result;
}
- public static File newFile(File parent, String... parts) {
- File result = parent;
- for (String part : parts) {
- result = new File(result, part);
- }
-
- return result;
- }
-
- public static boolean deleteIfExists(File file) {
- if (file == null) {
- return true;
- }
-
- return file.delete();
- }
-
}
diff --git a/arduino-core/src/processing/app/helpers/StringUtils.java b/arduino-core/src/processing/app/helpers/StringUtils.java
deleted file mode 100644
index d17e7022c7e..00000000000
--- a/arduino-core/src/processing/app/helpers/StringUtils.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package processing.app.helpers;
-
-import java.util.List;
-
-public class StringUtils {
-
- public static boolean stringContainsOneOf(String input, List listOfStrings) {
- for (String string : listOfStrings) {
- if (input.contains(string)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Tries to match input with pattern. 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
- * @return true if the input matches the pattern,
- * false otherwise.
- */
- public static boolean wildcardMatch(String input, String pattern) {
- String regex = pattern.replace("?", ".?").replace("*", ".*?");
- return input.matches(regex);
- }
-
- /**
- * Returns the string without trailing whitespace characters
- *
- * @param s
- * @return
- */
- public static String rtrim(String s) {
- int i = s.length() - 1;
- while (i >= 0 && Character.isWhitespace(s.charAt(i))) {
- i--;
- }
- return s.substring(0, i + 1);
- }
-
- public static String join(String[] arr, String separator) {
- StringBuffer sb = new StringBuffer();
- for (String s : arr) {
- sb.append(s).append(separator);
- }
- return sb.substring(0, sb.length() - separator.length());
- }
-}
diff --git a/build/windows/launcher/config.xml b/build/windows/launcher/config.xml
index 1855ed28dde..5d6ca6c1d65 100644
--- a/build/windows/launcher/config.xml
+++ b/build/windows/launcher/config.xml
@@ -33,7 +33,7 @@
%EXEDIR%/lib/commons-compress-1.8.jar
%EXEDIR%/lib/commons-exec-1.1.jar
%EXEDIR%/lib/commons-httpclient-3.1.jar
- %EXEDIR%/lib/commons-lang3-3.3.2.jar
+ %EXEDIR%/lib/commons-lang3-3.8.1.jar
%EXEDIR%/lib/commons-logging-1.0.4.jar
%EXEDIR%/lib/commons-net-3.3.jar
%EXEDIR%/lib/jackson-annotations-2.9.5.jar
diff --git a/build/windows/launcher/config_debug.xml b/build/windows/launcher/config_debug.xml
index 3a5ac7936e5..1ddae72736c 100644
--- a/build/windows/launcher/config_debug.xml
+++ b/build/windows/launcher/config_debug.xml
@@ -33,7 +33,7 @@
%EXEDIR%/lib/commons-compress-1.8.jar
%EXEDIR%/lib/commons-exec-1.1.jar
%EXEDIR%/lib/commons-httpclient-3.1.jar
- %EXEDIR%/lib/commons-lang3-3.3.2.jar
+ %EXEDIR%/lib/commons-lang3-3.8.1.jar
%EXEDIR%/lib/commons-logging-1.0.4.jar
%EXEDIR%/lib/commons-net-3.3.jar
%EXEDIR%/lib/jackson-annotations-2.9.5.jar