mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Split IDE into 2 projects.
BEWARE: HIGHLY EXPERIMENTAL BRANCH
This commit is contained in:
977
arduino-core/src/processing/app/BaseNoGui.java
Normal file
977
arduino-core/src/processing/app/BaseNoGui.java
Normal file
@ -0,0 +1,977 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||
import org.apache.commons.logging.impl.NoOpLog;
|
||||
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.Uploader;
|
||||
|
||||
import processing.app.debug.Compiler;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
import processing.app.helpers.BasicUserNotifier;
|
||||
import processing.app.helpers.CommandlineParser;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.UserNotifier;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.packages.Library;
|
||||
import processing.app.packages.LibraryList;
|
||||
|
||||
public class BaseNoGui {
|
||||
|
||||
public static final int REVISION = 158;
|
||||
/** This might be replaced by main() if there's a lib/version.txt file. */
|
||||
static String VERSION_NAME = "0158";
|
||||
/** Set true if this a proper release rather than a numbered revision. */
|
||||
static public boolean RELEASE = false;
|
||||
|
||||
static File buildFolder;
|
||||
|
||||
// Current directory to use for relative paths specified on the
|
||||
// commandline
|
||||
static String currentDirectory = System.getProperty("user.dir");
|
||||
|
||||
private static DiscoveryManager discoveryManager = new DiscoveryManager();
|
||||
|
||||
// these are static because they're used by Sketch
|
||||
static private File examplesFolder;
|
||||
static private File toolsFolder;
|
||||
|
||||
// maps #included files to their library folder
|
||||
public static Map<String, Library> importToLibraryTable;
|
||||
|
||||
// maps library name to their library folder
|
||||
static private LibraryList libraries;
|
||||
|
||||
static private List<File> librariesFolders;
|
||||
|
||||
static UserNotifier notifier = new BasicUserNotifier();
|
||||
|
||||
static public Map<String, TargetPackage> packages;
|
||||
|
||||
static Platform platform;
|
||||
|
||||
static File portableFolder = null;
|
||||
|
||||
static final String portableSketchbookFolder = "sketchbook";
|
||||
|
||||
// Returns a File object for the given pathname. If the pathname
|
||||
// is not absolute, it is interpreted relative to the current
|
||||
// directory when starting the IDE (which is not the same as the
|
||||
// current working directory!).
|
||||
static public File absoluteFile(String path) {
|
||||
if (path == null) return null;
|
||||
|
||||
File file = new File(path);
|
||||
if (!file.isAbsolute()) {
|
||||
file = new File(currentDirectory, path);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of lines in a file by counting the number of newline
|
||||
* characters inside a String (and adding 1).
|
||||
*/
|
||||
static public int countLines(String what) {
|
||||
int count = 1;
|
||||
for (char c : what.toCharArray()) {
|
||||
if (c == '\n') count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the platform's temporary folder, by creating
|
||||
* a temporary temporary file and getting its parent folder.
|
||||
* <br/>
|
||||
* Modified for revision 0094 to actually make the folder randomized
|
||||
* to avoid conflicts in multi-user environments. (Bug 177)
|
||||
*/
|
||||
static public File createTempFolder(String name) {
|
||||
try {
|
||||
File folder = File.createTempFile(name, null);
|
||||
//String tempPath = ignored.getParent();
|
||||
//return new File(tempPath);
|
||||
folder.delete();
|
||||
folder.mkdirs();
|
||||
return folder;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static public String getAvrBasePath() {
|
||||
String path = getHardwarePath() + File.separator + "tools" +
|
||||
File.separator + "avr" + File.separator + "bin" + File.separator;
|
||||
if (OSUtils.isLinux() && !(new File(path)).exists()) {
|
||||
return ""; // use distribution provided avr tools if bundled tools missing
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
static public File getBuildFolder() {
|
||||
if (buildFolder == null) {
|
||||
String buildPath = PreferencesData.get("build.path");
|
||||
if (buildPath != null) {
|
||||
buildFolder = absoluteFile(buildPath);
|
||||
if (!buildFolder.exists())
|
||||
buildFolder.mkdirs();
|
||||
} else {
|
||||
//File folder = new File(getTempFolder(), "build");
|
||||
//if (!folder.exists()) folder.mkdirs();
|
||||
buildFolder = createTempFolder("build");
|
||||
buildFolder.deleteOnExit();
|
||||
}
|
||||
}
|
||||
return buildFolder;
|
||||
}
|
||||
|
||||
static public PreferencesMap getBoardPreferences() {
|
||||
TargetBoard board = getTargetBoard();
|
||||
|
||||
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
||||
for (String menuId : board.getMenuIds()) {
|
||||
String entry = PreferencesData.get("custom_" + menuId);
|
||||
if (board.hasMenu(menuId) && entry != null &&
|
||||
entry.startsWith(board.getId())) {
|
||||
String selectionId = entry.substring(entry.indexOf("_") + 1);
|
||||
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
|
||||
prefs.put("name", prefs.get("name") + ", " +
|
||||
board.getMenuLabel(menuId, selectionId));
|
||||
}
|
||||
}
|
||||
return prefs;
|
||||
}
|
||||
|
||||
static public File getContentFile(String name) {
|
||||
String path = System.getProperty("user.dir");
|
||||
|
||||
// Get a path to somewhere inside the .app folder
|
||||
if (OSUtils.isMacOS()) {
|
||||
// <key>javaroot</key>
|
||||
// <string>$JAVAROOT</string>
|
||||
String javaroot = System.getProperty("javaroot");
|
||||
if (javaroot != null) {
|
||||
path = javaroot;
|
||||
}
|
||||
}
|
||||
File working = new File(path);
|
||||
return new File(working, name);
|
||||
}
|
||||
|
||||
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
||||
return getTargetPlatform(pack, PreferencesData.get("target_platform"));
|
||||
}
|
||||
|
||||
static public File getDefaultSketchbookFolder() {
|
||||
if (getPortableFolder() != null)
|
||||
return new File(getPortableFolder(), getPortableSketchbookFolder());
|
||||
|
||||
File sketchbookFolder = null;
|
||||
try {
|
||||
sketchbookFolder = getPlatform().getDefaultSketchbookFolder();
|
||||
} catch (Exception e) { }
|
||||
|
||||
return sketchbookFolder;
|
||||
}
|
||||
|
||||
public static DiscoveryManager getDiscoveryManager() {
|
||||
return discoveryManager;
|
||||
}
|
||||
|
||||
static public File getExamplesFolder() {
|
||||
return examplesFolder;
|
||||
}
|
||||
|
||||
static public String getExamplesPath() {
|
||||
return examplesFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
static public File getHardwareFolder() {
|
||||
// calculate on the fly because it's needed by Preferences.init() to find
|
||||
// the boards.txt and programmers.txt preferences files (which happens
|
||||
// before the other folders / paths get cached).
|
||||
return getContentFile("hardware");
|
||||
}
|
||||
|
||||
static public String getHardwarePath() {
|
||||
return getHardwareFolder().getAbsolutePath();
|
||||
}
|
||||
|
||||
static public LibraryList getLibraries() {
|
||||
return libraries;
|
||||
}
|
||||
|
||||
static public List<File> getLibrariesPath() {
|
||||
return librariesFolders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an InputStream for a file inside the Processing lib folder.
|
||||
*/
|
||||
static public InputStream getLibStream(String filename) throws IOException {
|
||||
return new FileInputStream(new File(getContentFile("lib"), filename));
|
||||
}
|
||||
|
||||
static public Platform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
static public File getPortableFolder() {
|
||||
return portableFolder;
|
||||
}
|
||||
|
||||
static public String getPortableSketchbookFolder() {
|
||||
return portableSketchbookFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get a File object for the specified filename inside
|
||||
* the settings folder.
|
||||
* For now, only used by Preferences to get the preferences.txt file.
|
||||
* @param filename A file inside the settings folder.
|
||||
* @return filename wrapped as a File object inside the settings folder
|
||||
*/
|
||||
static public File getSettingsFile(String filename) {
|
||||
return new File(getSettingsFolder(), filename);
|
||||
}
|
||||
|
||||
static public File getSettingsFolder() {
|
||||
if (getPortableFolder() != null)
|
||||
return getPortableFolder();
|
||||
|
||||
File settingsFolder = null;
|
||||
|
||||
String preferencesPath = PreferencesData.get("settings.path");
|
||||
if (preferencesPath != null) {
|
||||
settingsFolder = absoluteFile(preferencesPath);
|
||||
|
||||
} else {
|
||||
try {
|
||||
settingsFolder = getPlatform().getSettingsFolder();
|
||||
} catch (Exception e) {
|
||||
showError(_("Problem getting data folder"),
|
||||
_("Error getting the Arduino data folder."), e);
|
||||
}
|
||||
}
|
||||
|
||||
// create the folder if it doesn't exist already
|
||||
if (!settingsFolder.exists()) {
|
||||
if (!settingsFolder.mkdirs()) {
|
||||
showError(_("Settings issues"),
|
||||
_("Arduino cannot run because it could not\n" +
|
||||
"create a folder to store your settings."), null);
|
||||
}
|
||||
}
|
||||
return settingsFolder;
|
||||
}
|
||||
|
||||
static public File getSketchbookFolder() {
|
||||
if (portableFolder != null)
|
||||
return new File(portableFolder, PreferencesData.get("sketchbook.path"));
|
||||
return absoluteFile(PreferencesData.get("sketchbook.path"));
|
||||
}
|
||||
|
||||
static public File getSketchbookHardwareFolder() {
|
||||
return new File(getSketchbookFolder(), "hardware");
|
||||
}
|
||||
|
||||
static public File getSketchbookLibrariesFolder() {
|
||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
||||
if (!libdir.exists()) {
|
||||
try {
|
||||
libdir.mkdirs();
|
||||
File readme = new File(libdir, "readme.txt");
|
||||
FileWriter freadme = new FileWriter(readme);
|
||||
freadme.write(_("For information on installing libraries, see: " +
|
||||
"http://arduino.cc/en/Guide/Libraries\n"));
|
||||
freadme.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return libdir;
|
||||
}
|
||||
|
||||
static public String getSketchbookPath() {
|
||||
// Get the sketchbook path, and make sure it's set properly
|
||||
String sketchbookPath = PreferencesData.get("sketchbook.path");
|
||||
|
||||
// If a value is at least set, first check to see if the folder exists.
|
||||
// If it doesn't, warn the user that the sketchbook folder is being reset.
|
||||
if (sketchbookPath != null) {
|
||||
File sketchbookFolder;
|
||||
if (getPortableFolder() != null)
|
||||
sketchbookFolder = new File(getPortableFolder(), sketchbookPath);
|
||||
else
|
||||
sketchbookFolder = absoluteFile(sketchbookPath);
|
||||
if (!sketchbookFolder.exists()) {
|
||||
showWarning(_("Sketchbook folder disappeared"),
|
||||
_("The sketchbook folder no longer exists.\n" +
|
||||
"Arduino will switch to the default sketchbook\n" +
|
||||
"location, and create a new sketchbook folder if\n" +
|
||||
"necessary. Arduino will then stop talking about\n" +
|
||||
"himself in the third person."), null);
|
||||
sketchbookPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
return sketchbookPath;
|
||||
}
|
||||
|
||||
public static TargetBoard getTargetBoard() {
|
||||
String boardId = PreferencesData.get("board");
|
||||
return getTargetPlatform().getBoard(boardId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific TargetPackage
|
||||
*
|
||||
* @param packageName
|
||||
* @return
|
||||
*/
|
||||
static public TargetPackage getTargetPackage(String packageName) {
|
||||
return packages.get(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected TargetPlatform.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform() {
|
||||
String packageName = PreferencesData.get("target_package");
|
||||
String platformName = PreferencesData.get("target_platform");
|
||||
return getTargetPlatform(packageName, platformName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific TargetPlatform searching Package/Platform
|
||||
*
|
||||
* @param packageName
|
||||
* @param platformName
|
||||
* @return
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform(String packageName,
|
||||
String platformName) {
|
||||
TargetPackage p = packages.get(packageName);
|
||||
if (p == null)
|
||||
return null;
|
||||
return p.get(platformName);
|
||||
}
|
||||
|
||||
static public File getToolsFolder() {
|
||||
return toolsFolder;
|
||||
}
|
||||
|
||||
static public String getToolsPath() {
|
||||
return toolsFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
static public LibraryList getUserLibs() {
|
||||
if (libraries == null)
|
||||
return new LibraryList();
|
||||
return libraries.filterLibrariesInSubfolder(getSketchbookFolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a folder, return a list of the header files in that folder (but not
|
||||
* the header files in its sub-folders, as those should be included from
|
||||
* within the header files at the top-level).
|
||||
*/
|
||||
static public String[] headerListFromIncludePath(File path) throws IOException {
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h"));
|
||||
if (list == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static public void init(String[] args) {
|
||||
getPlatform().init();
|
||||
|
||||
String sketchbookPath = getSketchbookPath();
|
||||
|
||||
// If no path is set, get the default sketchbook folder for this platform
|
||||
if (sketchbookPath == null) {
|
||||
if (BaseNoGui.getPortableFolder() != null)
|
||||
PreferencesData.set("sketchbook.path", getPortableSketchbookFolder());
|
||||
else
|
||||
showError(_("No sketchbook"), _("Sketchbook path not defined"), null);
|
||||
}
|
||||
|
||||
BaseNoGui.initPackages();
|
||||
|
||||
// Setup board-dependent variables.
|
||||
onBoardOrPortChange();
|
||||
|
||||
CommandlineParser parser = CommandlineParser.newCommandlineParser(args);
|
||||
|
||||
for (String path: parser.getFilenames()) {
|
||||
// Correctly resolve relative paths
|
||||
File file = absoluteFile(path);
|
||||
|
||||
// Fix a problem with systems that use a non-ASCII languages. Paths are
|
||||
// being passed in with 8.3 syntax, which makes the sketch loader code
|
||||
// unhappy, since the sketch folder naming doesn't match up correctly.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=1089
|
||||
if (OSUtils.isWindows()) {
|
||||
try {
|
||||
file = file.getCanonicalFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!parser.isVerifyOrUploadMode() && !parser.isGetPrefMode())
|
||||
showError(_("Mode not supported"), _("Only --verify, --upload or --get-pref are supported"), null);
|
||||
|
||||
if (!parser.isForceSavePrefs())
|
||||
PreferencesData.setDoSave(false);
|
||||
if (!file.exists()) {
|
||||
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
|
||||
// Open failure is fatal in upload/verify mode
|
||||
showError(null, mess, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the preferences. For GUI mode, this happens in the quit
|
||||
// handler, but for other modes we should also make sure to save
|
||||
// them.
|
||||
PreferencesData.save();
|
||||
|
||||
if (parser.isVerifyOrUploadMode()) {
|
||||
// Set verbosity for command line build
|
||||
PreferencesData.set("build.verbose", "" + parser.isDoVerboseBuild());
|
||||
PreferencesData.set("upload.verbose", "" + parser.isDoVerboseUpload());
|
||||
|
||||
// Make sure these verbosity preferences are only for the
|
||||
// current session
|
||||
PreferencesData.setDoSave(false);
|
||||
|
||||
if (parser.isUploadMode()) {
|
||||
|
||||
if (parser.getFilenames().size() != 1)
|
||||
{
|
||||
showError(_("Multiple files not supported"), _("The --upload option supports only one file at a time"), null);
|
||||
}
|
||||
|
||||
List<String> warningsAccumulator = new LinkedList<String>();
|
||||
boolean success = false;
|
||||
try {
|
||||
// costruttore di Editor carica lo sketch usando handleOpenInternal() che fa
|
||||
// la new di Sketch che chiama load() nel suo costruttore
|
||||
// In questo punto questo si traduce in:
|
||||
// SketchData data = new SketchData(file);
|
||||
// File tempBuildFolder = getBuildFolder();
|
||||
// data.load();
|
||||
SketchData data = new SketchData(absoluteFile(parser.getFilenames().get(0)));
|
||||
File tempBuildFolder = getBuildFolder();
|
||||
data.load();
|
||||
|
||||
// Sketch.exportApplet()
|
||||
// - chiama Sketch.prepare() che chiama Sketch.ensureExistence()
|
||||
// - chiama Sketch.build(verbose=false) che chiama Sketch.ensureExistence(), imposta il progressListener e chiama Compiler.build()
|
||||
// - chiama Sketch.upload() (cfr. dopo...)
|
||||
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
|
||||
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
|
||||
showMessage(_("Done compiling"), _("Done compiling"));
|
||||
|
||||
// - chiama Sketch.upload() ... to be continued ...
|
||||
Uploader uploader = Compiler.getUploaderByPreferences(parser.isNoUploadPort());
|
||||
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) showError(_("..."), _("..."), null);
|
||||
try {
|
||||
success = Compiler.upload(data, uploader, tempBuildFolder.getAbsolutePath(), suggestedClassName, parser.isDoUseProgrammer(), parser.isNoUploadPort(), warningsAccumulator);
|
||||
showMessage(_("Done uploading"), _("Done uploading"));
|
||||
} finally {
|
||||
if (uploader.requiresAuthorization() && !success) {
|
||||
PreferencesData.remove(uploader.getAuthorizationKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
showError(_("Error while verifying/uploading"), _("An error occurred while verifying/uploading the sketch"), e);
|
||||
}
|
||||
for (String warning : warningsAccumulator) {
|
||||
System.out.print(_("Warning"));
|
||||
System.out.print(": ");
|
||||
System.out.println(warning);
|
||||
}
|
||||
if (!success) showError(_("Error while uploading"), _("An error occurred while uploading the sketch"), null);
|
||||
} else {
|
||||
|
||||
for (String path : parser.getFilenames())
|
||||
{
|
||||
try {
|
||||
// costruttore di Editor carica lo sketch usando handleOpenInternal() che fa
|
||||
// la new di Sketch che chiama load() nel suo costruttore
|
||||
// In questo punto questo si traduce in:
|
||||
// SketchData data = new SketchData(file);
|
||||
// File tempBuildFolder = getBuildFolder();
|
||||
// data.load();
|
||||
SketchData data = new SketchData(absoluteFile(path));
|
||||
File tempBuildFolder = getBuildFolder();
|
||||
data.load();
|
||||
|
||||
// metodo Sketch.prepare() chiama Sketch.ensureExistence()
|
||||
// Sketch.build(verbose) chiama Sketch.ensureExistence() e poi imposta il progressListener e, finalmente, chiama Compiler.build()
|
||||
// In questo punto questo si traduce in:
|
||||
// if (!data.getFolder().exists()) showError(...);
|
||||
// String ... = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, verbose);
|
||||
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
|
||||
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
|
||||
showMessage(_("Done compiling"), _("Done compiling"));
|
||||
} catch (Exception e) {
|
||||
showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No errors exit gracefully
|
||||
System.exit(0);
|
||||
}
|
||||
else if (parser.isGetPrefMode()) {
|
||||
String value = PreferencesData.get(parser.getGetPref(), null);
|
||||
if (value != null) {
|
||||
System.out.println(value);
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.exit(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void initLogger() {
|
||||
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName());
|
||||
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
|
||||
}
|
||||
|
||||
static public void initPackages() {
|
||||
packages = new HashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
if (packages.size() == 0) {
|
||||
System.out.println(_("No valid configured cores found! Exiting..."));
|
||||
System.exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
static protected void initPlatform() {
|
||||
try {
|
||||
Class<?> platformClass = Class.forName("processing.app.Platform");
|
||||
if (OSUtils.isMacOS()) {
|
||||
platformClass = Class.forName("processing.app.macosx.Platform");
|
||||
} else if (OSUtils.isWindows()) {
|
||||
platformClass = Class.forName("processing.app.windows.Platform");
|
||||
} else if (OSUtils.isLinux()) {
|
||||
platformClass = Class.forName("processing.app.linux.Platform");
|
||||
}
|
||||
platform = (Platform) platformClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
showError(_("Problem Setting the Platform"),
|
||||
_("An unknown error occurred while trying to load\n" +
|
||||
"platform-specific code for your machine."), e);
|
||||
}
|
||||
}
|
||||
|
||||
static public void initPortableFolder() {
|
||||
// Portable folder
|
||||
portableFolder = getContentFile("portable");
|
||||
if (!portableFolder.exists())
|
||||
portableFolder = null;
|
||||
}
|
||||
|
||||
static public void initVersion() {
|
||||
try {
|
||||
File versionFile = getContentFile("lib/version.txt");
|
||||
if (versionFile.exists()) {
|
||||
String version = PApplet.loadStrings(versionFile)[0];
|
||||
if (!version.equals(VERSION_NAME) && !version.equals("${version}")) {
|
||||
VERSION_NAME = version;
|
||||
RELEASE = true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// help 3rd party installers find the correct hardware path
|
||||
PreferencesData.set("last.ide." + VERSION_NAME + ".hardwarepath", getHardwarePath());
|
||||
PreferencesData.set("last.ide." + VERSION_NAME + ".daterun", "" + (new Date()).getTime() / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the name is valid for a Processing sketch.
|
||||
*/
|
||||
static public boolean isSanitaryName(String name) {
|
||||
return sanitizeName(name).equals(name);
|
||||
}
|
||||
|
||||
static protected void loadHardware(File folder) {
|
||||
if (!folder.isDirectory()) return;
|
||||
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null) return;
|
||||
|
||||
// alphabetize list, since it's not always alpha order
|
||||
// replaced hella slow bubble sort with this feller for 0093
|
||||
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (String target : list) {
|
||||
// Skip reserved 'tools' folder.
|
||||
if (target.equals("tools"))
|
||||
continue;
|
||||
File subfolder = new File(folder, target);
|
||||
|
||||
try {
|
||||
packages.put(target, new TargetPackage(target, subfolder));
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println("WARNING: Error loading hardware folder " + target);
|
||||
System.out.println(" " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the contents of a file as a string.
|
||||
*/
|
||||
static public String loadFile(File file) throws IOException {
|
||||
String[] contents = PApplet.loadStrings(file);
|
||||
if (contents == null) return null;
|
||||
return PApplet.join(contents, "\n");
|
||||
}
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
if (args.length == 0)
|
||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||
|
||||
initPlatform();
|
||||
|
||||
initPortableFolder();
|
||||
|
||||
initParameters(args);
|
||||
|
||||
init(args);
|
||||
}
|
||||
|
||||
static public void onBoardOrPortChange() {
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform == null)
|
||||
return;
|
||||
|
||||
// Calculate paths for libraries and examples
|
||||
examplesFolder = getContentFile("examples");
|
||||
toolsFolder = getContentFile("tools");
|
||||
|
||||
File platformFolder = targetPlatform.getFolder();
|
||||
librariesFolders = new ArrayList<File>();
|
||||
librariesFolders.add(getContentFile("libraries"));
|
||||
String core = getBoardPreferences().get("build.core");
|
||||
if (core.contains(":")) {
|
||||
String referencedCore = core.split(":")[0];
|
||||
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
|
||||
if (referencedPlatform != null) {
|
||||
File referencedPlatformFolder = referencedPlatform.getFolder();
|
||||
librariesFolders.add(new File(referencedPlatformFolder, "libraries"));
|
||||
}
|
||||
}
|
||||
librariesFolders.add(new File(platformFolder, "libraries"));
|
||||
librariesFolders.add(getSketchbookLibrariesFolder());
|
||||
|
||||
// Scan for libraries in each library folder.
|
||||
// Libraries located in the latest folders on the list can override
|
||||
// other libraries with the same name.
|
||||
try {
|
||||
scanAndUpdateLibraries(librariesFolders);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), _("Error loading libraries"), e);
|
||||
}
|
||||
|
||||
populateImportToLibraryTable();
|
||||
}
|
||||
|
||||
static public void populateImportToLibraryTable() {
|
||||
// Populate importToLibraryTable
|
||||
importToLibraryTable = new HashMap<String, Library>();
|
||||
for (Library lib : getLibraries()) {
|
||||
try {
|
||||
String headers[] = headerListFromIncludePath(lib.getSrcFolder());
|
||||
for (String header : headers) {
|
||||
Library old = importToLibraryTable.get(header);
|
||||
if (old != null) {
|
||||
// If a library was already found with this header, keep
|
||||
// it if the library's name matches the header name.
|
||||
String name = header.substring(0, header.length() - 2);
|
||||
if (old.getFolder().getPath().endsWith(name))
|
||||
continue;
|
||||
}
|
||||
importToLibraryTable.put(header, lib);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n
|
||||
.format("Unable to list header files in {0}", lib.getSrcFolder()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void initParameters(String args[]) {
|
||||
String preferencesFile = null;
|
||||
|
||||
// Do a first pass over the commandline arguments, the rest of them
|
||||
// will be processed by the Base constructor. Note that this loop
|
||||
// does not look at the last element of args, to prevent crashing
|
||||
// when no parameter was specified to an option. Later, Base() will
|
||||
// then show an error for these.
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
if (args[i].equals("--preferences-file")) {
|
||||
++i;
|
||||
preferencesFile = args[i];
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--curdir")) {
|
||||
i++;
|
||||
currentDirectory = args[i];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
PreferencesData.init(absoluteFile(preferencesFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively remove all files within a directory,
|
||||
* used with removeDir(), or when the contents of a dir
|
||||
* should be removed, but not the directory itself.
|
||||
* (i.e. when cleaning temp files from lib/build)
|
||||
*/
|
||||
static public void removeDescendants(File dir) {
|
||||
if (!dir.exists()) return;
|
||||
|
||||
String files[] = dir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
File dead = new File(dir, files[i]);
|
||||
if (!dead.isDirectory()) {
|
||||
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
|
||||
if (!dead.delete()) {
|
||||
// temporarily disabled
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dead));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
removeDir(dead);
|
||||
//dead.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all files in a directory and the directory itself.
|
||||
*/
|
||||
static public void removeDir(File dir) {
|
||||
if (dir.exists()) {
|
||||
removeDescendants(dir);
|
||||
if (!dir.delete()) {
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a sanitized name that fits our standards for likely to work.
|
||||
* <p/>
|
||||
* Java classes have a wider range of names that are technically allowed
|
||||
* (supposedly any Unicode name) than what we support. The reason for
|
||||
* going more narrow is to avoid situations with text encodings and
|
||||
* converting during the process of moving files between operating
|
||||
* systems, i.e. uploading from a Windows machine to a Linux server,
|
||||
* or reading a FAT32 partition in OS X and using a thumb drive.
|
||||
* <p/>
|
||||
* This helper function replaces everything but A-Z, a-z, and 0-9 with
|
||||
* underscores. Also disallows starting the sketch name with a digit.
|
||||
*/
|
||||
static public String sanitizeName(String origName) {
|
||||
char c[] = origName.toCharArray();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
// can't lead with a digit, so start with an underscore
|
||||
if ((c[0] >= '0') && (c[0] <= '9')) {
|
||||
buffer.append('_');
|
||||
}
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
if (((c[i] >= '0') && (c[i] <= '9')) ||
|
||||
((c[i] >= 'a') && (c[i] <= 'z')) ||
|
||||
((c[i] >= 'A') && (c[i] <= 'Z')) ||
|
||||
((i > 0) && (c[i] == '-')) ||
|
||||
((i > 0) && (c[i] == '.'))) {
|
||||
buffer.append(c[i]);
|
||||
} else {
|
||||
buffer.append('_');
|
||||
}
|
||||
}
|
||||
// let's not be ridiculous about the length of filenames.
|
||||
// in fact, Mac OS 9 can handle 255 chars, though it can't really
|
||||
// deal with filenames longer than 31 chars in the Finder.
|
||||
// but limiting to that for sketches would mean setting the
|
||||
// upper-bound on the character limit here to 25 characters
|
||||
// (to handle the base name + ".class")
|
||||
if (buffer.length() > 63) {
|
||||
buffer.setLength(63);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Spew the contents of a String object out to a file.
|
||||
*/
|
||||
static public void saveFile(String str, File file) throws IOException {
|
||||
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
|
||||
PApplet.saveStrings(temp, new String[] { str });
|
||||
if (file.exists()) {
|
||||
boolean result = file.delete();
|
||||
if (!result) {
|
||||
throw new IOException(
|
||||
I18n.format(
|
||||
_("Could not remove old version of {0}"),
|
||||
file.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
boolean result = temp.renameTo(file);
|
||||
if (!result) {
|
||||
throw new IOException(
|
||||
I18n.format(
|
||||
_("Could not replace {0}"),
|
||||
file.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
static public void scanAndUpdateLibraries(List<File> folders) throws IOException {
|
||||
libraries = scanLibraries(folders);
|
||||
}
|
||||
|
||||
static public LibraryList scanLibraries(List<File> folders) throws IOException {
|
||||
LibraryList res = new LibraryList();
|
||||
for (File folder : folders)
|
||||
res.addOrReplaceAll(scanLibraries(folder));
|
||||
return res;
|
||||
}
|
||||
|
||||
static public LibraryList scanLibraries(File folder) throws IOException {
|
||||
LibraryList res = new LibraryList();
|
||||
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null)
|
||||
return res;
|
||||
|
||||
for (String libName : list) {
|
||||
File subfolder = new File(folder, libName);
|
||||
if (!isSanitaryName(libName)) {
|
||||
String mess = I18n.format(_("The library \"{0}\" cannot be used.\n"
|
||||
+ "Library names must contain only basic letters and numbers.\n"
|
||||
+ "(ASCII only and no spaces, and it cannot start with a number)"),
|
||||
libName);
|
||||
showMessage(_("Ignoring bad library name"), mess);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Library lib = Library.create(subfolder);
|
||||
// (also replace previously found libs with the same name)
|
||||
if (lib != null)
|
||||
res.addOrReplace(lib);
|
||||
} catch (IOException e) {
|
||||
System.out.println(I18n.format(_("Invalid library found in {0}: {1}"),
|
||||
subfolder, e.getMessage()));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static public void selectBoard(TargetBoard targetBoard) {
|
||||
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
|
||||
TargetPackage targetPackage = targetPlatform.getContainerPackage();
|
||||
|
||||
PreferencesData.set("target_package", targetPackage.getId());
|
||||
PreferencesData.set("target_platform", targetPlatform.getId());
|
||||
PreferencesData.set("board", targetBoard.getId());
|
||||
|
||||
File platformFolder = targetPlatform.getFolder();
|
||||
PreferencesData.set("runtime.platform.path", platformFolder.getAbsolutePath());
|
||||
PreferencesData.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
public static void selectSerialPort(String port) {
|
||||
PreferencesData.set("serial.port", port);
|
||||
if (port.startsWith("/dev/"))
|
||||
PreferencesData.set("serial.port.file", port.substring(5));
|
||||
else
|
||||
PreferencesData.set("serial.port.file", port);
|
||||
}
|
||||
|
||||
public static void setBuildFolder(File newBuildFolder) {
|
||||
buildFolder = newBuildFolder;
|
||||
}
|
||||
|
||||
static public void showError(String title, String message, int exit_code) {
|
||||
showError(title, message, null, exit_code);
|
||||
}
|
||||
|
||||
static public void showError(String title, String message, Throwable e) {
|
||||
notifier.showError(title, message, e, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message that's actually fatal to the program.
|
||||
* This is an error that can't be recovered. Use showWarning()
|
||||
* for errors that allow P5 to continue running.
|
||||
*/
|
||||
static public void showError(String title, String message, Throwable e, int exit_code) {
|
||||
notifier.showError(title, message, e, exit_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* "No cookie for you" type messages. Nothing fatal or all that
|
||||
* much of a bummer, but something to notify the user about.
|
||||
*/
|
||||
static public void showMessage(String title, String message) {
|
||||
notifier.showMessage(title, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-fatal error message with optional stack trace side dish.
|
||||
*/
|
||||
static public void showWarning(String title, String message, Exception e) {
|
||||
notifier.showWarning(title, message, e);
|
||||
}
|
||||
|
||||
}
|
96
arduino-core/src/processing/app/I18n.java
Normal file
96
arduino-core/src/processing/app/I18n.java
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* by Shigeru KANEMOTO at SWITCHSCIENCE.
|
||||
*
|
||||
* Extract strings to be translated by:
|
||||
* % xgettext -L Java --from-code=utf-8 -k_ -d Resources_ja *.java
|
||||
* Extract and merge by:
|
||||
* % xgettext -j -L Java --from-code=utf-8 -k_ -d Resources_ja *.java
|
||||
*
|
||||
* Edit "Resources_ja.po".
|
||||
* Convert to the properties file format by:
|
||||
* % msgcat -p Resources_ja.po > Resources_ja.properties
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class I18n {
|
||||
// start using current locale but still allow using the dropdown list later
|
||||
private static ResourceBundle i18n;
|
||||
|
||||
// prompt text stuff
|
||||
|
||||
static String PROMPT_YES;
|
||||
static String PROMPT_NO;
|
||||
static String PROMPT_CANCEL;
|
||||
static String PROMPT_OK;
|
||||
static String PROMPT_BROWSE;
|
||||
|
||||
static protected void init(String language) throws MissingResourceException {
|
||||
String[] languageParts = language.split("_");
|
||||
Locale locale = Locale.getDefault();
|
||||
// both language and country
|
||||
if (languageParts.length == 2) {
|
||||
locale = new Locale(languageParts[0], languageParts[1]);
|
||||
// just language
|
||||
} else if (languageParts.length == 1 && !"".equals(languageParts[0])) {
|
||||
locale = new Locale(languageParts[0]);
|
||||
}
|
||||
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
|
||||
Locale.setDefault(locale);
|
||||
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", Locale.getDefault());
|
||||
PROMPT_YES = _("Yes");
|
||||
PROMPT_NO = _("No");
|
||||
PROMPT_CANCEL = _("Cancel");
|
||||
PROMPT_OK = _("OK");
|
||||
PROMPT_BROWSE = _("Browse");
|
||||
}
|
||||
|
||||
public static String _(String s) {
|
||||
String res;
|
||||
try {
|
||||
if (i18n == null)
|
||||
res = s;
|
||||
else
|
||||
res = i18n.getString(s);
|
||||
} catch (MissingResourceException e) {
|
||||
res = s;
|
||||
}
|
||||
|
||||
// The single % is the arguments selector in .PO files.
|
||||
// We must put double %% inside the translations to avoid
|
||||
// getting .PO processing in the way.
|
||||
res = res.replace("%%", "%");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String format(String fmt, Object... args) {
|
||||
// Single quote is used to escape curly bracket arguments.
|
||||
|
||||
// - Prevents strings fixed at translation time to be fixed again
|
||||
fmt = fmt.replace("''", "'");
|
||||
// - Replace ' with the escaped version ''
|
||||
fmt = fmt.replace("'", "''");
|
||||
|
||||
return MessageFormat.format(fmt, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
* <p/>
|
||||
* This method is an hack to extract words with gettext tool.
|
||||
*/
|
||||
protected static void unusedStrings() {
|
||||
// These phrases are defined in the "platform.txt".
|
||||
_("Arduino AVR Boards");
|
||||
_("Arduino ARM (32-bits) Boards");
|
||||
|
||||
// This word is defined in the "boards.txt".
|
||||
_("Processor");
|
||||
}
|
||||
}
|
220
arduino-core/src/processing/app/Platform.java
Normal file
220
arduino-core/src/processing/app/Platform.java
Normal file
@ -0,0 +1,220 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2008 Ben Fry and Casey Reas
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
|
||||
/**
|
||||
* Used by Base for platform-specific tweaking, for instance finding the
|
||||
* sketchbook location using the Windows registry, or OS X event handling.
|
||||
*
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
*
|
||||
* These methods throw vanilla-flavored Exceptions, so that error handling
|
||||
* occurs inside Base.
|
||||
*
|
||||
* There is currently no mechanism for adding new platforms, as the setup is
|
||||
* not automated. We could use getProperty("os.arch") perhaps, but that's
|
||||
* debatable (could be upper/lowercase, have spaces, etc.. basically we don't
|
||||
* know if name is proper Java package syntax.)
|
||||
*/
|
||||
public class Platform {
|
||||
|
||||
|
||||
/**
|
||||
* Set the default L & F. While I enjoy the bounty of the sixteen possible
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* just this one particular case, I'm being spoiled by those engineers
|
||||
* at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
|
||||
* and overweight. So instead, I'll pretend that I'm not offered eleven dozen
|
||||
* ways to report to the user exactly what went wrong, and I'll bundle them
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* care about is whether things worked or not. And even then, I don't care.
|
||||
*
|
||||
* @throws Exception Just like I said.
|
||||
*/
|
||||
public void setLookAndFeel() throws Exception {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// otherwise make a .processing directory int the user's home dir
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File dataFolder = new File(home, ".arduino15");
|
||||
return dataFolder;
|
||||
|
||||
/*
|
||||
try {
|
||||
Class clazz = Class.forName("processing.app.macosx.ThinkDifferent");
|
||||
Method m = clazz.getMethod("getLibraryFolder", new Class[] { });
|
||||
String libraryPath = (String) m.invoke(null, new Object[] { });
|
||||
//String libraryPath = BaseMacOS.getLibraryFolder();
|
||||
File libraryFolder = new File(libraryPath);
|
||||
dataFolder = new File(libraryFolder, "Processing");
|
||||
|
||||
} catch (Exception e) {
|
||||
showError("Problem getting data folder",
|
||||
"Error getting the Processing data folder.", e);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @throws Exception
|
||||
*/
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
Runtime.getRuntime().exec(new String[] { launcher, url });
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
return PreferencesData.get("launcher") != null;
|
||||
}
|
||||
|
||||
|
||||
public void openFolder(File file) throws Exception {
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
String folder = file.getAbsolutePath();
|
||||
Runtime.getRuntime().exec(new String[] { launcher, folder });
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
}
|
||||
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String preListAllCandidateDevices() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String readVIDPID) {
|
||||
for (TargetPackage targetPackage : packages.values()) {
|
||||
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
||||
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
||||
List<String> vids = new LinkedList<String>(board.getPreferences().subTree("vid").values());
|
||||
if (!vids.isEmpty()) {
|
||||
List<String> pids = new LinkedList<String>(board.getPreferences().subTree("pid").values());
|
||||
for (int i = 0; i< vids.size(); i++) {
|
||||
String vidPid = vids.get(i) + "_" + pids.get(i);
|
||||
if (vidPid.toUpperCase().equals(readVIDPID)) {
|
||||
return board.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) {
|
||||
for (TargetPackage targetPackage : packages.values()) {
|
||||
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
||||
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
||||
if (boardId.equals(board.getId())) {
|
||||
return board.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
public interface CLibrary extends Library {
|
||||
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
|
||||
int setenv(String name, String value, int overwrite);
|
||||
String getenv(String name);
|
||||
int unsetenv(String name);
|
||||
int putenv(String string);
|
||||
}
|
||||
|
||||
|
||||
public void setenv(String variable, String value) {
|
||||
CLibrary clib = CLibrary.INSTANCE;
|
||||
clib.setenv(variable, value, 1);
|
||||
}
|
||||
|
||||
|
||||
public String getenv(String variable) {
|
||||
CLibrary clib = CLibrary.INSTANCE;
|
||||
return clib.getenv(variable);
|
||||
}
|
||||
|
||||
|
||||
public int unsetenv(String variable) {
|
||||
CLibrary clib = CLibrary.INSTANCE;
|
||||
return clib.unsetenv(variable);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return PConstants.platformNames[PConstants.OTHER];
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
protected void showLauncherWarning() {
|
||||
BaseNoGui.showWarning(_("No launcher available"),
|
||||
_("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"),
|
||||
null);
|
||||
}
|
||||
}
|
214
arduino-core/src/processing/app/PreferencesData.java
Normal file
214
arduino-core/src/processing/app/PreferencesData.java
Normal file
@ -0,0 +1,214 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
|
||||
public class PreferencesData {
|
||||
|
||||
static final String PREFS_FILE = "preferences.txt";
|
||||
|
||||
// data model
|
||||
|
||||
static PreferencesMap defaults;
|
||||
static PreferencesMap prefs = new PreferencesMap();
|
||||
static File preferencesFile;
|
||||
static boolean doSave = true;
|
||||
|
||||
|
||||
static public void init(File file) {
|
||||
if (file != null)
|
||||
preferencesFile = file;
|
||||
else
|
||||
preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE);
|
||||
|
||||
// start by loading the defaults, in case something
|
||||
// important was deleted from the user prefs
|
||||
try {
|
||||
prefs.load(BaseNoGui.getLibStream("preferences.txt"));
|
||||
} catch (IOException e) {
|
||||
BaseNoGui.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
File hardwareFolder = BaseNoGui.getHardwareFolder();
|
||||
prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION);
|
||||
|
||||
// clone the hash table
|
||||
defaults = new PreferencesMap(prefs);
|
||||
|
||||
if (preferencesFile.exists()) {
|
||||
// load the previous preferences file
|
||||
try {
|
||||
prefs.load(preferencesFile);
|
||||
} catch (IOException ex) {
|
||||
BaseNoGui.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
// load the I18n module for internationalization
|
||||
try {
|
||||
I18n.init(get("editor.languages.current"));
|
||||
} catch (MissingResourceException e) {
|
||||
I18n.init("en");
|
||||
set("editor.languages.current", "en");
|
||||
}
|
||||
|
||||
// set some other runtime constants (not saved on preferences file)
|
||||
set("runtime.os", PConstants.platformNames[PApplet.platform]);
|
||||
|
||||
fixPreferences();
|
||||
}
|
||||
|
||||
private static void fixPreferences() {
|
||||
String baud = get("serial.debug_rate");
|
||||
if ("14400".equals(baud) || "28800".equals(baud) || "38400".equals(baud)) {
|
||||
set("serial.debug_rate", "9600");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public String[] loadStrings(InputStream input) {
|
||||
try {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(input, "UTF-8"));
|
||||
|
||||
String lines[] = new String[100];
|
||||
int lineCount = 0;
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (lineCount == lines.length) {
|
||||
String temp[] = new String[lineCount << 1];
|
||||
System.arraycopy(lines, 0, temp, 0, lineCount);
|
||||
lines = temp;
|
||||
}
|
||||
lines[lineCount++] = line;
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (lineCount == lines.length) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
// resize array to appropriate amount for these lines
|
||||
String output[] = new String[lineCount];
|
||||
System.arraycopy(lines, 0, output, 0, lineCount);
|
||||
return output;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("Error inside loadStrings()");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static protected void save() {
|
||||
if (!doSave)
|
||||
return;
|
||||
|
||||
// on startup, don't worry about it
|
||||
// this is trying to update the prefs for who is open
|
||||
// before Preferences.init() has been called.
|
||||
if (preferencesFile == null) return;
|
||||
|
||||
// Fix for 0163 to properly use Unicode when writing preferences.txt
|
||||
PrintWriter writer = PApplet.createWriter(preferencesFile);
|
||||
|
||||
String[] keys = prefs.keySet().toArray(new String[0]);
|
||||
Arrays.sort(keys);
|
||||
for (String key: keys) {
|
||||
if (key.startsWith("runtime."))
|
||||
continue;
|
||||
writer.println(key + "=" + prefs.get(key));
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
static public String get(String attribute) {
|
||||
return prefs.get(attribute);
|
||||
}
|
||||
|
||||
static public String get(String attribute, String defaultValue) {
|
||||
String value = get(attribute);
|
||||
return (value == null) ? defaultValue : value;
|
||||
}
|
||||
|
||||
public static boolean has(String key) {
|
||||
return prefs.containsKey(key);
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
prefs.remove(key);
|
||||
}
|
||||
|
||||
static public String getDefault(String attribute) {
|
||||
return defaults.get(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void set(String attribute, String value) {
|
||||
prefs.put(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public void unset(String attribute) {
|
||||
prefs.remove(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public boolean getBoolean(String attribute) {
|
||||
return prefs.getBoolean(attribute);
|
||||
}
|
||||
|
||||
|
||||
static public void setBoolean(String attribute, boolean value) {
|
||||
prefs.putBoolean(attribute, value);
|
||||
}
|
||||
|
||||
|
||||
static public int getInteger(String attribute) {
|
||||
return Integer.parseInt(get(attribute));
|
||||
}
|
||||
|
||||
|
||||
static public void setInteger(String key, int value) {
|
||||
set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
// get a copy of the Preferences
|
||||
static public PreferencesMap getMap()
|
||||
{
|
||||
return new PreferencesMap(prefs);
|
||||
}
|
||||
|
||||
// Decide wether changed preferences will be saved. When value is
|
||||
// false, Preferences.save becomes a no-op.
|
||||
static public void setDoSave(boolean value)
|
||||
{
|
||||
doSave = value;
|
||||
}
|
||||
}
|
544
arduino-core/src/processing/app/Serial.java
Normal file
544
arduino-core/src/processing/app/Serial.java
Normal file
@ -0,0 +1,544 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
PSerial - class for serial port goodness
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004 Ben Fry & Casey Reas
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General
|
||||
Public License along with this library; if not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortEvent;
|
||||
import jssc.SerialPortEventListener;
|
||||
import jssc.SerialPortException;
|
||||
import processing.app.debug.MessageConsumer;
|
||||
|
||||
|
||||
public class Serial implements SerialPortEventListener {
|
||||
|
||||
//PApplet parent;
|
||||
|
||||
// properties can be passed in for default values
|
||||
// otherwise defaults to 9600 N81
|
||||
|
||||
// these could be made static, which might be a solution
|
||||
// for the classloading problem.. because if code ran again,
|
||||
// the static class would have an object that could be closed
|
||||
|
||||
SerialPort port;
|
||||
|
||||
int rate;
|
||||
int parity;
|
||||
int databits;
|
||||
int stopbits;
|
||||
boolean monitor = false;
|
||||
|
||||
byte buffer[] = new byte[32768];
|
||||
int bufferIndex;
|
||||
int bufferLast;
|
||||
|
||||
MessageConsumer consumer;
|
||||
|
||||
public Serial(boolean monitor) throws SerialException {
|
||||
this(PreferencesData.get("serial.port"),
|
||||
PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
public Serial() throws SerialException {
|
||||
this(PreferencesData.get("serial.port"),
|
||||
PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public Serial(int irate) throws SerialException {
|
||||
this(PreferencesData.get("serial.port"), irate,
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public Serial(String iname, int irate) throws SerialException {
|
||||
this(iname, irate, PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public Serial(String iname) throws SerialException {
|
||||
this(iname, PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue());
|
||||
}
|
||||
|
||||
public static boolean touchPort(String iname, int irate) throws SerialException {
|
||||
SerialPort serialPort = new SerialPort(iname);
|
||||
try {
|
||||
serialPort.openPort();
|
||||
serialPort.setParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||||
serialPort.closePort();
|
||||
return true;
|
||||
} catch (SerialPortException e) {
|
||||
throw new SerialException(I18n.format(_("Error touching serial port ''{0}''."), iname), e);
|
||||
} finally {
|
||||
if (serialPort.isOpened()) {
|
||||
try {
|
||||
serialPort.closePort();
|
||||
} catch (SerialPortException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits) throws SerialException {
|
||||
//if (port != null) port.close();
|
||||
//this.parent = parent;
|
||||
//parent.attach(this);
|
||||
|
||||
this.rate = irate;
|
||||
|
||||
parity = SerialPort.PARITY_NONE;
|
||||
if (iparity == 'E') parity = SerialPort.PARITY_EVEN;
|
||||
if (iparity == 'O') parity = SerialPort.PARITY_ODD;
|
||||
|
||||
this.databits = idatabits;
|
||||
|
||||
stopbits = SerialPort.STOPBITS_1;
|
||||
if (istopbits == 1.5f) stopbits = SerialPort.STOPBITS_1_5;
|
||||
if (istopbits == 2) stopbits = SerialPort.STOPBITS_2;
|
||||
|
||||
try {
|
||||
port = new SerialPort(iname);
|
||||
port.openPort();
|
||||
port.setParams(rate, databits, stopbits, parity, true, true);
|
||||
port.addEventListener(this);
|
||||
} catch (Exception e) {
|
||||
throw new SerialException(I18n.format(_("Error opening serial port ''{0}''."), iname), e);
|
||||
}
|
||||
|
||||
if (port == null) {
|
||||
throw new SerialNotFoundException(I18n.format(_("Serial port ''{0}'' not found. Did you select the right one from the Tools > Serial Port menu?"), iname));
|
||||
}
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
//parent.registerCall(this, DISPOSE);
|
||||
}
|
||||
|
||||
public void dispose() throws IOException {
|
||||
if (port != null) {
|
||||
try {
|
||||
if (port.isOpened()) {
|
||||
port.closePort(); // close the port
|
||||
}
|
||||
} catch (SerialPortException e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
port = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(MessageConsumer consumer) {
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public synchronized void serialEvent(SerialPortEvent serialEvent) {
|
||||
if (serialEvent.isRXCHAR()) {
|
||||
try {
|
||||
byte[] buf = port.readBytes(serialEvent.getEventValue());
|
||||
if (buf.length > 0) {
|
||||
if (bufferLast == buffer.length) {
|
||||
byte temp[] = new byte[bufferLast << 1];
|
||||
System.arraycopy(buffer, 0, temp, 0, bufferLast);
|
||||
buffer = temp;
|
||||
}
|
||||
if (monitor) {
|
||||
System.out.print(new String(buf));
|
||||
}
|
||||
if (this.consumer != null) {
|
||||
this.consumer.message(new String(buf));
|
||||
}
|
||||
}
|
||||
} catch (SerialPortException e) {
|
||||
errorMessage("serialEvent", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that have been read from serial
|
||||
* and are waiting to be dealt with by the user.
|
||||
*/
|
||||
public synchronized int available() {
|
||||
return (bufferLast - bufferIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ignore all the bytes read so far and empty the buffer.
|
||||
*/
|
||||
public synchronized void clear() {
|
||||
bufferLast = 0;
|
||||
bufferIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a number between 0 and 255 for the next byte that's
|
||||
* waiting in the buffer.
|
||||
* Returns -1 if there was no byte (although the user should
|
||||
* first check available() to see if things are ready to avoid this)
|
||||
*/
|
||||
public synchronized int read() {
|
||||
if (bufferIndex == bufferLast) return -1;
|
||||
|
||||
int outgoing = buffer[bufferIndex++] & 0xff;
|
||||
if (bufferIndex == bufferLast) { // rewind
|
||||
bufferIndex = 0;
|
||||
bufferLast = 0;
|
||||
}
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next byte in the buffer as a char.
|
||||
* Returns -1, or 0xffff, if nothing is there.
|
||||
*/
|
||||
public synchronized char readChar() {
|
||||
if (bufferIndex == bufferLast) return (char) (-1);
|
||||
return (char) read();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a byte array of anything that's in the serial buffer.
|
||||
* Not particularly memory/speed efficient, because it creates
|
||||
* a byte array on each read, but it's easier to use than
|
||||
* readBytes(byte b[]) (see below).
|
||||
*/
|
||||
public synchronized byte[] readBytes() {
|
||||
if (bufferIndex == bufferLast) return null;
|
||||
|
||||
int length = bufferLast - bufferIndex;
|
||||
byte outgoing[] = new byte[length];
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab whatever is in the serial buffer, and stuff it into a
|
||||
* byte buffer passed in by the user. This is more memory/time
|
||||
* efficient than readBytes() returning a byte[] array.
|
||||
* <p/>
|
||||
* Returns an int for how many bytes were read. If more bytes
|
||||
* are available than can fit into the byte array, only those
|
||||
* that will fit are read.
|
||||
*/
|
||||
public synchronized int readBytes(byte outgoing[]) {
|
||||
if (bufferIndex == bufferLast) return 0;
|
||||
|
||||
int length = bufferLast - bufferIndex;
|
||||
if (length > outgoing.length) length = outgoing.length;
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex += length;
|
||||
if (bufferIndex == bufferLast) {
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads from the serial port into a buffer of bytes up to and
|
||||
* including a particular character. If the character isn't in
|
||||
* the serial buffer, then 'null' is returned.
|
||||
*/
|
||||
public synchronized byte[] readBytesUntil(int interesting) {
|
||||
if (bufferIndex == bufferLast) return null;
|
||||
byte what = (byte) interesting;
|
||||
|
||||
int found = -1;
|
||||
for (int k = bufferIndex; k < bufferLast; k++) {
|
||||
if (buffer[k] == what) {
|
||||
found = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == -1) return null;
|
||||
|
||||
int length = found - bufferIndex + 1;
|
||||
byte outgoing[] = new byte[length];
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads from the serial port into a buffer of bytes until a
|
||||
* particular character. If the character isn't in the serial
|
||||
* buffer, then 'null' is returned.
|
||||
* <p/>
|
||||
* If outgoing[] is not big enough, then -1 is returned,
|
||||
* and an error message is printed on the console.
|
||||
* If nothing is in the buffer, zero is returned.
|
||||
* If 'interesting' byte is not in the buffer, then 0 is returned.
|
||||
*/
|
||||
public synchronized int readBytesUntil(int interesting, byte outgoing[]) {
|
||||
if (bufferIndex == bufferLast) return 0;
|
||||
byte what = (byte) interesting;
|
||||
|
||||
int found = -1;
|
||||
for (int k = bufferIndex; k < bufferLast; k++) {
|
||||
if (buffer[k] == what) {
|
||||
found = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == -1) return 0;
|
||||
|
||||
int length = found - bufferIndex + 1;
|
||||
if (length > outgoing.length) {
|
||||
System.err.println(
|
||||
I18n.format(
|
||||
_("readBytesUntil() byte buffer is too small for the {0}" +
|
||||
" bytes up to and including char {1}"),
|
||||
length,
|
||||
interesting
|
||||
)
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
//byte outgoing[] = new byte[length];
|
||||
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
||||
|
||||
bufferIndex += length;
|
||||
if (bufferIndex == bufferLast) {
|
||||
bufferIndex = 0; // rewind
|
||||
bufferLast = 0;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whatever has been read from the serial port so far
|
||||
* as a String. It assumes that the incoming characters are ASCII.
|
||||
* <p/>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*/
|
||||
public synchronized String readString() {
|
||||
if (bufferIndex == bufferLast) return null;
|
||||
return new String(readBytes());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combination of readBytesUntil and readString. See caveats in
|
||||
* each function. Returns null if it still hasn't found what
|
||||
* you're looking for.
|
||||
* <p/>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*/
|
||||
public synchronized String readStringUntil(int interesting) {
|
||||
byte b[] = readBytesUntil(interesting);
|
||||
if (b == null) return null;
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This will handle both ints, bytes and chars transparently.
|
||||
*/
|
||||
public void write(int what) { // will also cover char
|
||||
try {
|
||||
port.writeInt(what & 0xff);
|
||||
} catch (SerialPortException e) {
|
||||
errorMessage("write", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(byte bytes[]) {
|
||||
try {
|
||||
port.writeBytes(bytes);
|
||||
} catch (SerialPortException e) {
|
||||
errorMessage("write", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write a String to the output. Note that this doesn't account
|
||||
* for Unicode (two bytes per char), nor will it send UTF8
|
||||
* characters.. It assumes that you mean to send a byte buffer
|
||||
* (most often the case for networking and serial i/o) and
|
||||
* will only use the bottom 8 bits of each char in the string.
|
||||
* (Meaning that internally it uses String.getBytes)
|
||||
* <p/>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*/
|
||||
public void write(String what) {
|
||||
write(what.getBytes());
|
||||
}
|
||||
|
||||
public void setDTR(boolean state) {
|
||||
try {
|
||||
port.setDTR(state);
|
||||
} catch (SerialPortException e) {
|
||||
errorMessage("setDTR", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRTS(boolean state) {
|
||||
try {
|
||||
port.setRTS(state);
|
||||
} catch (SerialPortException e) {
|
||||
errorMessage("setRTS", e);
|
||||
}
|
||||
}
|
||||
|
||||
static public List<String> list() {
|
||||
return Arrays.asList(SerialPortList.getPortNames());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* General error reporting, all corraled here just in case
|
||||
* I think of something slightly more intelligent to do.
|
||||
*/
|
||||
static public void errorMessage(String where, Throwable e) {
|
||||
System.err.println(I18n.format(_("Error inside Serial.{0}()"), where));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
class SerialMenuListener implements ItemListener {
|
||||
//public SerialMenuListener() { }
|
||||
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
int count = serialMenu.getItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
((CheckboxMenuItem)serialMenu.getItem(i)).setState(false);
|
||||
}
|
||||
CheckboxMenuItem item = (CheckboxMenuItem)e.getSource();
|
||||
item.setState(true);
|
||||
String name = item.getLabel();
|
||||
//System.out.println(item.getLabel());
|
||||
PdeBase.properties.put("serial.port", name);
|
||||
//System.out.println("set to " + get("serial.port"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
protected Vector buildPortList() {
|
||||
// get list of names for serial ports
|
||||
// have the default port checked (if present)
|
||||
Vector list = new Vector();
|
||||
|
||||
//SerialMenuListener listener = new SerialMenuListener();
|
||||
boolean problem = false;
|
||||
|
||||
// if this is failing, it may be because
|
||||
// lib/javax.comm.properties is missing.
|
||||
// java is weird about how it searches for java.comm.properties
|
||||
// so it tends to be very fragile. i.e. quotes in the CLASSPATH
|
||||
// environment variable will hose things.
|
||||
try {
|
||||
//System.out.println("building port list");
|
||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||||
while (portList.hasMoreElements()) {
|
||||
CommPortIdentifier portId =
|
||||
(CommPortIdentifier) portList.nextElement();
|
||||
//System.out.println(portId);
|
||||
|
||||
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
||||
//if (portId.getName().equals(port)) {
|
||||
String name = portId.getName();
|
||||
//CheckboxMenuItem mi =
|
||||
//new CheckboxMenuItem(name, name.equals(defaultName));
|
||||
|
||||
//mi.addItemListener(listener);
|
||||
//serialMenu.add(mi);
|
||||
list.addElement(name);
|
||||
}
|
||||
}
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
e.printStackTrace();
|
||||
problem = true;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("exception building serial menu");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//if (serialMenu.getItemCount() == 0) {
|
||||
//System.out.println("dimming serial menu");
|
||||
//serialMenu.setEnabled(false);
|
||||
//}
|
||||
|
||||
// only warn them if this is the first time
|
||||
if (problem && PdeBase.firstTime) {
|
||||
JOptionPane.showMessageDialog(this, //frame,
|
||||
"Serial port support not installed.\n" +
|
||||
"Check the readme for instructions\n" +
|
||||
"if you need to use the serial port. ",
|
||||
"Serial Port Warning",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
42
arduino-core/src/processing/app/SerialException.java
Normal file
42
arduino-core/src/processing/app/SerialException.java
Normal file
@ -0,0 +1,42 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Copyright (c) 2007 David A. Mellis
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SerialException extends IOException {
|
||||
public SerialException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SerialException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SerialException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SerialException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
38
arduino-core/src/processing/app/SerialNotFoundException.java
Normal file
38
arduino-core/src/processing/app/SerialNotFoundException.java
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (c) 2007 David A. Mellis
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SerialNotFoundException extends SerialException {
|
||||
public SerialNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SerialNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SerialNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SerialNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
355
arduino-core/src/processing/app/SerialPortList.java
Normal file
355
arduino-core/src/processing/app/SerialPortList.java
Normal file
@ -0,0 +1,355 @@
|
||||
/* jSSC (Java Simple Serial Connector) - serial port communication library.
|
||||
* (C) Alexey Sokolov (scream3r), 2010-2014.
|
||||
*
|
||||
* Patched for Arduino by Cristian Maglie.
|
||||
*
|
||||
* This file is part of jSSC.
|
||||
*
|
||||
* jSSC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* jSSC 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If you use jSSC in public project you can inform me about this by e-mail,
|
||||
* of course if you want it.
|
||||
*
|
||||
* e-mail: scream3r.org@gmail.com
|
||||
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
|
||||
*/
|
||||
package processing.app;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import jssc.SerialNativeInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author scream3r
|
||||
*/
|
||||
public class SerialPortList {
|
||||
|
||||
private static SerialNativeInterface serialInterface;
|
||||
private static final Pattern PORTNAMES_REGEXP;
|
||||
private static final String PORTNAMES_PATH;
|
||||
|
||||
static {
|
||||
serialInterface = new SerialNativeInterface();
|
||||
switch (SerialNativeInterface.getOsType()) {
|
||||
case SerialNativeInterface.OS_LINUX: {
|
||||
PORTNAMES_REGEXP = Pattern.compile("(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO)[0-9]{1,3}");
|
||||
PORTNAMES_PATH = "/dev/";
|
||||
break;
|
||||
}
|
||||
case SerialNativeInterface.OS_SOLARIS: {
|
||||
PORTNAMES_REGEXP = Pattern.compile("[0-9]*|[a-z]*");
|
||||
PORTNAMES_PATH = "/dev/term/";
|
||||
break;
|
||||
}
|
||||
case SerialNativeInterface.OS_MAC_OS_X: {
|
||||
PORTNAMES_REGEXP = Pattern.compile("(tty|cu)\\..*");
|
||||
PORTNAMES_PATH = "/dev/";
|
||||
break;
|
||||
}
|
||||
case SerialNativeInterface.OS_WINDOWS: {
|
||||
PORTNAMES_REGEXP = Pattern.compile("");
|
||||
PORTNAMES_PATH = "";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
PORTNAMES_REGEXP = null;
|
||||
PORTNAMES_PATH = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//since 2.1.0 -> Fully rewrited port name comparator
|
||||
private static final Comparator<String> PORTNAMES_COMPARATOR = new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String valueA, String valueB) {
|
||||
|
||||
if(valueA.equalsIgnoreCase(valueB)){
|
||||
return valueA.compareTo(valueB);
|
||||
}
|
||||
|
||||
int minLength = Math.min(valueA.length(), valueB.length());
|
||||
|
||||
int shiftA = 0;
|
||||
int shiftB = 0;
|
||||
|
||||
for(int i = 0; i < minLength; i++){
|
||||
char charA = valueA.charAt(i - shiftA);
|
||||
char charB = valueB.charAt(i - shiftB);
|
||||
if(charA != charB){
|
||||
if(Character.isDigit(charA) && Character.isDigit(charB)){
|
||||
int[] resultsA = getNumberAndLastIndex(valueA, i - shiftA);
|
||||
int[] resultsB = getNumberAndLastIndex(valueB, i - shiftB);
|
||||
|
||||
if(resultsA[0] != resultsB[0]){
|
||||
return resultsA[0] - resultsB[0];
|
||||
}
|
||||
|
||||
if(valueA.length() < valueB.length()){
|
||||
i = resultsA[1];
|
||||
shiftB = resultsA[1] - resultsB[1];
|
||||
}
|
||||
else {
|
||||
i = resultsB[1];
|
||||
shiftA = resultsB[1] - resultsA[1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(Character.toLowerCase(charA) - Character.toLowerCase(charB) != 0){
|
||||
return Character.toLowerCase(charA) - Character.toLowerCase(charB);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return valueA.compareToIgnoreCase(valueB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate port <b>index/number</b> from <b>startIndex</b> to the number end. For example:
|
||||
* for port name <b>serial-123-FF</b> you should invoke this method with <b>startIndex = 7</b>
|
||||
*
|
||||
* @return If port <b>index/number</b> correctly evaluated it value will be returned<br>
|
||||
* <b>returnArray[0] = index/number</b><br>
|
||||
* <b>returnArray[1] = stopIndex</b><br>
|
||||
*
|
||||
* If incorrect:<br>
|
||||
* <b>returnArray[0] = -1</b><br>
|
||||
* <b>returnArray[1] = startIndex</b><br>
|
||||
*
|
||||
* For this name <b>serial-123-FF</b> result is:
|
||||
* <b>returnArray[0] = 123</b><br>
|
||||
* <b>returnArray[1] = 10</b><br>
|
||||
*/
|
||||
private int[] getNumberAndLastIndex(String str, int startIndex) {
|
||||
String numberValue = "";
|
||||
int[] returnValues = {-1, startIndex};
|
||||
for(int i = startIndex; i < str.length(); i++){
|
||||
returnValues[1] = i;
|
||||
char c = str.charAt(i);
|
||||
if(Character.isDigit(c)){
|
||||
numberValue += c;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
returnValues[0] = Integer.valueOf(numberValue);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
//Do nothing
|
||||
}
|
||||
return returnValues;
|
||||
}
|
||||
};
|
||||
//<-since 2.1.0
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system using default settings:<br>
|
||||
*
|
||||
* <b>Search path</b><br>
|
||||
* Windows - ""(always ignored)<br>
|
||||
* Linux - "/dev/"<br>
|
||||
* Solaris - "/dev/term/"<br>
|
||||
* MacOSX - "/dev/"<br>
|
||||
*
|
||||
* <b>RegExp</b><br>
|
||||
* Windows - ""<br>
|
||||
* Linux - "(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm)[0-9]{1,3}"<br>
|
||||
* Solaris - "[0-9]*|[a-z]*"<br>
|
||||
* MacOSX - "tty.(serial|usbserial|usbmodem).*"<br>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
* with <b>zero</b> length will be returned (since jSSC-0.8 in previous versions null will be returned)
|
||||
*/
|
||||
public static String[] getPortNames() {
|
||||
return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, PORTNAMES_COMPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system located on searchPath
|
||||
*
|
||||
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
|
||||
* The default search paths:<br>
|
||||
* Linux, MacOSX: <b>/dev/</b><br>
|
||||
* Solaris: <b>/dev/term/</b><br>
|
||||
* Windows: <b>this parameter ingored</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(String searchPath) {
|
||||
return getPortNames(searchPath, PORTNAMES_REGEXP, PORTNAMES_COMPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system matched pattern
|
||||
*
|
||||
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(Pattern pattern) {
|
||||
return getPortNames(PORTNAMES_PATH, pattern, PORTNAMES_COMPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system matched pattern
|
||||
*
|
||||
* @param comparator Comparator for sotring port names <b>(not null)</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(Comparator<String> comparator) {
|
||||
return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, comparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system located on searchPath, matched pattern
|
||||
*
|
||||
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
|
||||
* The default search paths:<br>
|
||||
* Linux, MacOSX: <b>/dev/</b><br>
|
||||
* Solaris: <b>/dev/term/</b><br>
|
||||
* Windows: <b>this parameter ingored</b>
|
||||
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(String searchPath, Pattern pattern) {
|
||||
return getPortNames(searchPath, pattern, PORTNAMES_COMPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system located on searchPath and sorted by comparator
|
||||
*
|
||||
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
|
||||
* The default search paths:<br>
|
||||
* Linux, MacOSX: <b>/dev/</b><br>
|
||||
* Solaris: <b>/dev/term/</b><br>
|
||||
* Windows: <b>this parameter ingored</b>
|
||||
* @param comparator Comparator for sotring port names <b>(not null)</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(String searchPath, Comparator<String> comparator) {
|
||||
return getPortNames(searchPath, PORTNAMES_REGEXP, comparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system matched pattern and sorted by comparator
|
||||
*
|
||||
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
|
||||
* @param comparator Comparator for sotring port names <b>(not null)</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(Pattern pattern, Comparator<String> comparator) {
|
||||
return getPortNames(PORTNAMES_PATH, pattern, comparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system located on searchPath, matched pattern and sorted by comparator
|
||||
*
|
||||
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
|
||||
* The default search paths:<br>
|
||||
* Linux, MacOSX: <b>/dev/</b><br>
|
||||
* Solaris: <b>/dev/term/</b><br>
|
||||
* Windows: <b>this parameter ingored</b>
|
||||
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
|
||||
* @param comparator Comparator for sotring port names <b>(not null)</b>
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(String searchPath, Pattern pattern, Comparator<String> comparator) {
|
||||
if(searchPath == null || pattern == null || comparator == null){
|
||||
return new String[]{};
|
||||
}
|
||||
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_WINDOWS){
|
||||
return getWindowsPortNames(pattern, comparator);
|
||||
}
|
||||
return getUnixBasedPortNames(searchPath, pattern, comparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get serial port names in Windows
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
private static String[] getWindowsPortNames(Pattern pattern, Comparator<String> comparator) {
|
||||
String[] portNames = serialInterface.getSerialPortNames();
|
||||
if(portNames == null){
|
||||
return new String[]{};
|
||||
}
|
||||
TreeSet<String> ports = new TreeSet<String>(comparator);
|
||||
for(String portName : portNames){
|
||||
if(pattern.matcher(portName).find()){
|
||||
ports.add(portName);
|
||||
}
|
||||
}
|
||||
return ports.toArray(new String[ports.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Universal method for getting port names of _nix based systems
|
||||
*/
|
||||
private static String[] getUnixBasedPortNames(String searchPath, Pattern pattern, Comparator<String> comparator) {
|
||||
searchPath = (searchPath.equals("") ? searchPath : (searchPath.endsWith("/") ? searchPath : searchPath + "/"));
|
||||
String[] returnArray = new String[]{};
|
||||
File dir = new File(searchPath);
|
||||
if(dir.exists() && dir.isDirectory()){
|
||||
File[] files = dir.listFiles();
|
||||
if(files.length > 0){
|
||||
TreeSet<String> portsTree = new TreeSet<String>(comparator);
|
||||
for(File file : files){
|
||||
String fileName = file.getName();
|
||||
if(!file.isDirectory() && !file.isFile() && pattern.matcher(fileName).find()){
|
||||
String portName = searchPath + fileName;
|
||||
// For linux ttyS0..31 serial ports check existence by opening each of them
|
||||
if (fileName.startsWith("ttyS")) {
|
||||
long portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
|
||||
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){
|
||||
continue;
|
||||
}
|
||||
else if(portHandle != SerialNativeInterface.ERR_PORT_BUSY) {
|
||||
serialInterface.closePort(portHandle);
|
||||
}
|
||||
}
|
||||
portsTree.add(portName);
|
||||
}
|
||||
}
|
||||
returnArray = portsTree.toArray(returnArray);
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
}
|
246
arduino-core/src/processing/app/SketchCode.java
Normal file
246
arduino-core/src/processing/app/SketchCode.java
Normal file
@ -0,0 +1,246 @@
|
||||
/*
|
||||
SketchCode - data class for a single file inside a sketch
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
/**
|
||||
* Represents a single tab of a sketch.
|
||||
*/
|
||||
public class SketchCode {
|
||||
|
||||
/** Pretty name (no extension), not the full file name */
|
||||
private String prettyName;
|
||||
|
||||
/** File object for where this code is located */
|
||||
private File file;
|
||||
|
||||
/** Text of the program text for this tab */
|
||||
private String program;
|
||||
|
||||
private boolean modified;
|
||||
|
||||
/** where this code starts relative to the concat'd code */
|
||||
private int preprocOffset;
|
||||
|
||||
private Object metadata;
|
||||
|
||||
public SketchCode(File file) {
|
||||
init(file, null);
|
||||
}
|
||||
|
||||
public SketchCode(File file, Object metadata) {
|
||||
init(file, metadata);
|
||||
}
|
||||
|
||||
private void init(File file, Object metadata) {
|
||||
this.file = file;
|
||||
this.metadata = metadata;
|
||||
|
||||
makePrettyName();
|
||||
|
||||
try {
|
||||
load();
|
||||
} catch (IOException e) {
|
||||
System.err.println(
|
||||
I18n.format(_("Error while loading code {0}"), file.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void makePrettyName() {
|
||||
prettyName = file.getName();
|
||||
int dot = prettyName.lastIndexOf('.');
|
||||
prettyName = prettyName.substring(0, dot);
|
||||
}
|
||||
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
protected boolean fileExists() {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
|
||||
protected boolean fileReadOnly() {
|
||||
return !file.canWrite();
|
||||
}
|
||||
|
||||
|
||||
protected boolean deleteFile(File tempBuildFolder) {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File[] compiledFiles = tempBuildFolder.listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().startsWith(getFileName());
|
||||
}
|
||||
});
|
||||
for (File compiledFile : compiledFiles) {
|
||||
compiledFile.delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected boolean renameTo(File what) {
|
||||
boolean success = file.renameTo(what);
|
||||
if (success) {
|
||||
file = what;
|
||||
makePrettyName();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
protected void copyTo(File dest) throws IOException {
|
||||
BaseNoGui.saveFile(program, dest);
|
||||
}
|
||||
|
||||
|
||||
public String getFileName() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
|
||||
public String getPrettyName() {
|
||||
return prettyName;
|
||||
}
|
||||
|
||||
|
||||
public boolean isExtension(String... extensions) {
|
||||
return isExtension(Arrays.asList(extensions));
|
||||
}
|
||||
|
||||
public boolean isExtension(List<String> extensions) {
|
||||
return FileUtils.hasExtension(file, extensions);
|
||||
}
|
||||
|
||||
|
||||
public String getProgram() {
|
||||
return program;
|
||||
}
|
||||
|
||||
|
||||
public void setProgram(String replacement) {
|
||||
program = replacement;
|
||||
}
|
||||
|
||||
|
||||
public int getLineCount() {
|
||||
return BaseNoGui.countLines(program);
|
||||
}
|
||||
|
||||
|
||||
public void setModified(boolean modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
public void setPreprocOffset(int preprocOffset) {
|
||||
this.preprocOffset = preprocOffset;
|
||||
}
|
||||
|
||||
|
||||
public int getPreprocOffset() {
|
||||
return preprocOffset;
|
||||
}
|
||||
|
||||
|
||||
public void addPreprocOffset(int extra) {
|
||||
preprocOffset += extra;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/**
|
||||
* Load this piece of code from a file.
|
||||
*/
|
||||
public void load() throws IOException {
|
||||
program = BaseNoGui.loadFile(file);
|
||||
|
||||
if (program.indexOf('\uFFFD') != -1) {
|
||||
System.err.println(
|
||||
I18n.format(
|
||||
_("\"{0}\" contains unrecognized characters." +
|
||||
"If this code was created with an older version of Arduino," +
|
||||
"you may need to use Tools -> Fix Encoding & Reload to update" +
|
||||
"the sketch to use UTF-8 encoding. If not, you may need to" +
|
||||
"delete the bad characters to get rid of this warning."),
|
||||
file.getName()
|
||||
)
|
||||
);
|
||||
System.err.println();
|
||||
}
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save this piece of code, regardless of whether the modified
|
||||
* flag is set or not.
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
// TODO re-enable history
|
||||
//history.record(s, SketchHistory.SAVE);
|
||||
|
||||
BaseNoGui.saveFile(program, file);
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save this file to another location, used by Sketch.saveAs()
|
||||
*/
|
||||
public void saveAs(File newFile) throws IOException {
|
||||
BaseNoGui.saveFile(program, newFile);
|
||||
}
|
||||
|
||||
|
||||
public Object getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
||||
public void setMetadata(Object metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
266
arduino-core/src/processing/app/SketchData.java
Normal file
266
arduino-core/src/processing/app/SketchData.java
Normal file
@ -0,0 +1,266 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SketchData {
|
||||
|
||||
/** main pde file for this sketch. */
|
||||
private File primaryFile;
|
||||
|
||||
/** folder that contains this sketch */
|
||||
private File folder;
|
||||
|
||||
/** data folder location for this sketch (may not exist yet) */
|
||||
private File dataFolder;
|
||||
|
||||
/** code folder location for this sketch (may not exist yet) */
|
||||
private File codeFolder;
|
||||
|
||||
/**
|
||||
* Name of sketch, which is the name of main file (without .pde or .java
|
||||
* extension)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private List<SketchCode> codes = new ArrayList<SketchCode>();
|
||||
|
||||
private static final Comparator<SketchCode> CODE_DOCS_COMPARATOR = new Comparator<SketchCode>() {
|
||||
@Override
|
||||
public int compare(SketchCode x, SketchCode y) {
|
||||
return x.getFileName().compareTo(y.getFileName());
|
||||
}
|
||||
};
|
||||
|
||||
SketchData(File file) {
|
||||
primaryFile = file;
|
||||
|
||||
// get the name of the sketch by chopping .pde or .java
|
||||
// off of the main file name
|
||||
String mainFilename = primaryFile.getName();
|
||||
int suffixLength = getDefaultExtension().length() + 1;
|
||||
name = mainFilename.substring(0, mainFilename.length() - suffixLength);
|
||||
|
||||
folder = new File(file.getParent());
|
||||
//System.out.println("sketch dir is " + folder);
|
||||
}
|
||||
|
||||
static public File checkSketchFile(File file) {
|
||||
// check to make sure that this .pde file is
|
||||
// in a folder of the same name
|
||||
String fileName = file.getName();
|
||||
File parent = file.getParentFile();
|
||||
String parentName = parent.getName();
|
||||
String pdeName = parentName + ".pde";
|
||||
File altPdeFile = new File(parent, pdeName);
|
||||
String inoName = parentName + ".ino";
|
||||
File altInoFile = new File(parent, inoName);
|
||||
|
||||
if (pdeName.equals(fileName) || inoName.equals(fileName))
|
||||
return file;
|
||||
|
||||
if (altPdeFile.exists())
|
||||
return altPdeFile;
|
||||
|
||||
if (altInoFile.exists())
|
||||
return altInoFile;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the list of files.
|
||||
* <P>
|
||||
* Generally this is only done once, rather than
|
||||
* each time a change is made, because otherwise it gets to be
|
||||
* a nightmare to keep track of what files went where, because
|
||||
* not all the data will be saved to disk.
|
||||
* <P>
|
||||
* This also gets called when the main sketch file is renamed,
|
||||
* because the sketch has to be reloaded from a different folder.
|
||||
* <P>
|
||||
* Another exception is when an external editor is in use,
|
||||
* in which case the load happens each time "run" is hit.
|
||||
*/
|
||||
protected void load() throws IOException {
|
||||
codeFolder = new File(folder, "code");
|
||||
dataFolder = new File(folder, "data");
|
||||
|
||||
// get list of files in the sketch folder
|
||||
String list[] = folder.list();
|
||||
|
||||
// reset these because load() may be called after an
|
||||
// external editor event. (fix for 0099)
|
||||
// codeDocs = new SketchCodeDoc[list.length];
|
||||
clearCodeDocs();
|
||||
// data.setCodeDocs(codeDocs);
|
||||
|
||||
List<String> extensions = getExtensions();
|
||||
|
||||
for (String filename : list) {
|
||||
// Ignoring the dot prefix files is especially important to avoid files
|
||||
// with the ._ prefix on Mac OS X. (You'll see this with Mac files on
|
||||
// non-HFS drives, i.e. a thumb drive formatted FAT32.)
|
||||
if (filename.startsWith(".")) continue;
|
||||
|
||||
// Don't let some wacko name a directory blah.pde or bling.java.
|
||||
if (new File(folder, filename).isDirectory()) continue;
|
||||
|
||||
// figure out the name without any extension
|
||||
String base = filename;
|
||||
// now strip off the .pde and .java extensions
|
||||
for (String extension : extensions) {
|
||||
if (base.toLowerCase().endsWith("." + extension)) {
|
||||
base = base.substring(0, base.length() - (extension.length() + 1));
|
||||
|
||||
// Don't allow people to use files with invalid names, since on load,
|
||||
// it would be otherwise possible to sneak in nasty filenames. [0116]
|
||||
if (BaseNoGui.isSanitaryName(base)) {
|
||||
addCode(new SketchCode(new File(folder, filename)));
|
||||
} else {
|
||||
System.err.println(I18n.format("File name {0} is invalid: ignored", filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getCodeCount() == 0)
|
||||
throw new IOException(_("No valid code files found"));
|
||||
|
||||
// move the main class to the first tab
|
||||
// start at 1, if it's at zero, don't bother
|
||||
for (SketchCode code : getCodes()) {
|
||||
//if (code[i].file.getName().equals(mainFilename)) {
|
||||
if (code.getFile().equals(primaryFile)) {
|
||||
moveCodeToFront(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// sort the entries at the top
|
||||
sortCode();
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
for (SketchCode code : getCodes()) {
|
||||
if (code.isModified())
|
||||
code.save();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCodeCount() {
|
||||
return codes.size();
|
||||
}
|
||||
|
||||
public SketchCode[] getCodes() {
|
||||
return codes.toArray(new SketchCode[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default extension for this editor setup.
|
||||
*/
|
||||
public String getDefaultExtension() {
|
||||
return "ino";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String[] array of proper extensions.
|
||||
*/
|
||||
public List<String> getExtensions() {
|
||||
return Arrays.asList("ino", "pde", "c", "cpp", "h");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file object for the primary .pde of this sketch.
|
||||
*/
|
||||
public File getPrimaryFile() {
|
||||
return primaryFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns path to the main .pde file for this sketch.
|
||||
*/
|
||||
public String getMainFilePath() {
|
||||
return primaryFile.getAbsolutePath();
|
||||
//return code[0].file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public void addCode(SketchCode sketchCode) {
|
||||
codes.add(sketchCode);
|
||||
}
|
||||
|
||||
public void moveCodeToFront(SketchCode codeDoc) {
|
||||
codes.remove(codeDoc);
|
||||
codes.add(0, codeDoc);
|
||||
}
|
||||
|
||||
protected void replaceCode(SketchCode newCode) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code.getFileName().equals(newCode.getFileName())) {
|
||||
codes.set(codes.indexOf(code), newCode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void sortCode() {
|
||||
if (codes.size() < 2)
|
||||
return;
|
||||
SketchCode first = codes.remove(0);
|
||||
Collections.sort(codes, CODE_DOCS_COMPARATOR);
|
||||
codes.add(0, first);
|
||||
}
|
||||
|
||||
public SketchCode getCode(int i) {
|
||||
return codes.get(i);
|
||||
}
|
||||
|
||||
protected void removeCode(SketchCode which) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code == which) {
|
||||
codes.remove(code);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.err.println("removeCode: internal error.. could not find code");
|
||||
}
|
||||
|
||||
public int indexOfCode(SketchCode who) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code == who)
|
||||
return codes.indexOf(code);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void clearCodeDocs() {
|
||||
codes.clear();
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public File getCodeFolder() {
|
||||
return codeFolder;
|
||||
}
|
||||
}
|
1254
arduino-core/src/processing/app/debug/Compiler.java
Normal file
1254
arduino-core/src/processing/app/debug/Compiler.java
Normal file
File diff suppressed because it is too large
Load Diff
42
arduino-core/src/processing/app/debug/MessageConsumer.java
Normal file
42
arduino-core/src/processing/app/debug/MessageConsumer.java
Normal file
@ -0,0 +1,42 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-06 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
|
||||
/**
|
||||
* Interface for dealing with parser/compiler output.
|
||||
* <P>
|
||||
* Different instances of MessageStream need to do different things with
|
||||
* messages. In particular, a stream instance used for parsing output from
|
||||
* the compiler compiler has to interpret its messages differently than one
|
||||
* parsing output from the runtime.
|
||||
* <P>
|
||||
* Classes which consume messages and do something with them
|
||||
* should implement this interface.
|
||||
*/
|
||||
public interface MessageConsumer {
|
||||
|
||||
public void message(String s);
|
||||
|
||||
}
|
147
arduino-core/src/processing/app/debug/MessageSiphon.java
Normal file
147
arduino-core/src/processing/app/debug/MessageSiphon.java
Normal file
@ -0,0 +1,147 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-06 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.SocketException;
|
||||
|
||||
/**
|
||||
* Slurps up messages from compiler.
|
||||
*/
|
||||
public class MessageSiphon implements Runnable {
|
||||
|
||||
private final Reader streamReader;
|
||||
private final MessageConsumer consumer;
|
||||
|
||||
private Thread thread;
|
||||
private boolean canRun;
|
||||
// Data is processed line-by-line if possible, but if this is non-zero
|
||||
// then a partial line is also processed if no line end is received
|
||||
// within this many milliseconds.
|
||||
private int lineTimeout;
|
||||
|
||||
public MessageSiphon(InputStream stream, MessageConsumer consumer) {
|
||||
this(stream, consumer, 0);
|
||||
}
|
||||
|
||||
public MessageSiphon(InputStream stream, MessageConsumer consumer, int lineTimeout) {
|
||||
this.streamReader = new InputStreamReader(stream);
|
||||
this.consumer = consumer;
|
||||
this.canRun = true;
|
||||
this.lineTimeout = lineTimeout;
|
||||
|
||||
thread = new Thread(this);
|
||||
// don't set priority too low, otherwise exceptions won't
|
||||
// bubble up in time (i.e. compile errors have a weird delay)
|
||||
//thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.setPriority(Thread.MAX_PRIORITY - 1);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
// process data until we hit EOF; this will happily block
|
||||
// (effectively sleeping the thread) until new data comes in.
|
||||
// when the program is finally done, null will come through.
|
||||
//
|
||||
StringBuilder currentLine = new StringBuilder();
|
||||
long lineStartTime = 0;
|
||||
while (canRun) {
|
||||
// First, try to read as many characters as possible. Take care
|
||||
// not to block when:
|
||||
// 1. lineTimeout is nonzero, and
|
||||
// 2. we have some characters buffered already
|
||||
while (lineTimeout == 0 || currentLine.length() == 0 || streamReader.ready()) {
|
||||
int c = streamReader.read();
|
||||
if (c == -1)
|
||||
return; // EOF
|
||||
if (!canRun)
|
||||
return;
|
||||
|
||||
// Keep track of the line start time
|
||||
if (currentLine.length() == 0)
|
||||
lineStartTime = System.nanoTime();
|
||||
|
||||
// Store the character line
|
||||
currentLine.append((char)c);
|
||||
|
||||
if (c == '\n') {
|
||||
// We read a full line, pass it on
|
||||
consumer.message(currentLine.toString());
|
||||
currentLine.setLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
// No more characters available. Wait until lineTimeout
|
||||
// milliseconds have passed since the start of the line and then
|
||||
// try reading again. If the time has already passed, then just
|
||||
// pass on the characters read so far.
|
||||
long passed = (System.nanoTime() - lineStartTime) / 1000;
|
||||
if (passed < this.lineTimeout) {
|
||||
Thread.sleep(this.lineTimeout - passed);
|
||||
continue;
|
||||
}
|
||||
|
||||
consumer.message(currentLine.toString());
|
||||
currentLine.setLength(0);
|
||||
}
|
||||
//EditorConsole.systemOut.println("messaging thread done");
|
||||
} catch (NullPointerException npe) {
|
||||
// Fairly common exception during shutdown
|
||||
} catch (SocketException e) {
|
||||
// socket has been close while we were wainting for data. nothing to see here, move along
|
||||
} catch (Exception e) {
|
||||
// On Linux and sometimes on Mac OS X, a "bad file descriptor"
|
||||
// message comes up when closing an applet that's run externally.
|
||||
// That message just gets supressed here..
|
||||
String mess = e.getMessage();
|
||||
if ((mess != null) &&
|
||||
(mess.indexOf("Bad file descriptor") != -1)) {
|
||||
//if (e.getMessage().indexOf("Bad file descriptor") == -1) {
|
||||
//System.err.println("MessageSiphon err " + e);
|
||||
//e.printStackTrace();
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
thread = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until the MessageSiphon thread is complete.
|
||||
public void join() throws java.lang.InterruptedException {
|
||||
// Grab a temp copy in case another thread nulls the "thread"
|
||||
// member variable
|
||||
Thread t = thread;
|
||||
if (t != null) t.join();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.canRun = false;
|
||||
}
|
||||
|
||||
}
|
161
arduino-core/src/processing/app/debug/RunnerException.java
Normal file
161
arduino-core/src/processing/app/debug/RunnerException.java
Normal file
@ -0,0 +1,161 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
|
||||
/**
|
||||
* An exception with a line number attached that occurs
|
||||
* during either compile time or run time.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class RunnerException extends Exception {
|
||||
protected String message;
|
||||
protected int codeIndex;
|
||||
protected int codeLine;
|
||||
protected int codeColumn;
|
||||
protected boolean showStackTrace;
|
||||
|
||||
|
||||
public RunnerException(String message) {
|
||||
this(message, true);
|
||||
}
|
||||
|
||||
public RunnerException(String message, boolean showStackTrace) {
|
||||
this(message, -1, -1, -1, showStackTrace);
|
||||
}
|
||||
|
||||
public RunnerException(String message, int file, int line) {
|
||||
this(message, file, line, -1, true);
|
||||
}
|
||||
|
||||
|
||||
public RunnerException(String message, int file, int line, int column) {
|
||||
this(message, file, line, column, true);
|
||||
}
|
||||
|
||||
|
||||
public RunnerException(String message, int file, int line, int column,
|
||||
boolean showStackTrace) {
|
||||
this.message = message;
|
||||
this.codeIndex = file;
|
||||
this.codeLine = line;
|
||||
this.codeColumn = column;
|
||||
this.showStackTrace = showStackTrace;
|
||||
}
|
||||
|
||||
|
||||
public RunnerException(Exception e) {
|
||||
super(e);
|
||||
this.showStackTrace = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getMessage() in Throwable, so that I can set
|
||||
* the message text outside the constructor.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public int getCodeIndex() {
|
||||
return codeIndex;
|
||||
}
|
||||
|
||||
|
||||
public void setCodeIndex(int index) {
|
||||
codeIndex = index;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasCodeIndex() {
|
||||
return codeIndex != -1;
|
||||
}
|
||||
|
||||
|
||||
public int getCodeLine() {
|
||||
return codeLine;
|
||||
}
|
||||
|
||||
|
||||
public void setCodeLine(int line) {
|
||||
this.codeLine = line;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasCodeLine() {
|
||||
return codeLine != -1;
|
||||
}
|
||||
|
||||
|
||||
public void setCodeColumn(int column) {
|
||||
this.codeColumn = column;
|
||||
}
|
||||
|
||||
|
||||
public int getCodeColumn() {
|
||||
return codeColumn;
|
||||
}
|
||||
|
||||
|
||||
public void showStackTrace() {
|
||||
showStackTrace = true;
|
||||
}
|
||||
|
||||
|
||||
public void hideStackTrace() {
|
||||
showStackTrace = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Nix the java.lang crap out of an exception message
|
||||
* because it scares the children.
|
||||
* <P>
|
||||
* This function must be static to be used with super()
|
||||
* in each of the constructors above.
|
||||
*/
|
||||
/*
|
||||
static public final String massage(String msg) {
|
||||
if (msg.indexOf("java.lang.") == 0) {
|
||||
//int dot = msg.lastIndexOf('.');
|
||||
msg = msg.substring("java.lang.".length());
|
||||
}
|
||||
return msg;
|
||||
//return (dot == -1) ? msg : msg.substring(dot+1);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void printStackTrace() {
|
||||
if (showStackTrace) {
|
||||
super.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
125
arduino-core/src/processing/app/debug/Sizer.java
Normal file
125
arduino-core/src/processing/app/debug/Sizer.java
Normal file
@ -0,0 +1,125 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Sizer - computes the size of a .hex file
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2006 David A. Mellis
|
||||
Copyright (c) 2011 Cristian Maglie <c.maglie@bug.st>
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.ProcessUtils;
|
||||
import processing.app.helpers.StringReplacer;
|
||||
|
||||
public class Sizer implements MessageConsumer {
|
||||
private long textSize;
|
||||
private long dataSize;
|
||||
private long eepromSize;
|
||||
private RunnerException exception;
|
||||
private PreferencesMap prefs;
|
||||
private String firstLine;
|
||||
private Pattern textPattern;
|
||||
private Pattern dataPattern;
|
||||
private Pattern eepromPattern;
|
||||
|
||||
public Sizer(PreferencesMap _prefs) {
|
||||
prefs = _prefs;
|
||||
textPattern = Pattern.compile(prefs.get("recipe.size.regex"));
|
||||
dataPattern = null;
|
||||
String pref = prefs.get("recipe.size.regex.data");
|
||||
if (pref != null)
|
||||
dataPattern = Pattern.compile(pref);
|
||||
eepromPattern = null;
|
||||
pref = prefs.get("recipe.size.regex.eeprom");
|
||||
if (pref != null)
|
||||
eepromPattern = Pattern.compile(pref);
|
||||
}
|
||||
|
||||
public long[] computeSize() throws RunnerException {
|
||||
|
||||
int r = 0;
|
||||
try {
|
||||
String pattern = prefs.get("recipe.size.pattern");
|
||||
String cmd[] = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
|
||||
exception = null;
|
||||
textSize = -1;
|
||||
dataSize = -1;
|
||||
eepromSize = -1;
|
||||
Process process = ProcessUtils.exec(cmd);
|
||||
MessageSiphon in = new MessageSiphon(process.getInputStream(), this);
|
||||
MessageSiphon err = new MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
boolean running = true;
|
||||
while(running) {
|
||||
try {
|
||||
in.join();
|
||||
err.join();
|
||||
r = process.waitFor();
|
||||
running = false;
|
||||
} catch (InterruptedException intExc) { }
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// The default Throwable.toString() never returns null, but apparently
|
||||
// some sub-class has overridden it to do so, thus we need to check for
|
||||
// it. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166589459
|
||||
exception = new RunnerException(
|
||||
(e.toString() == null) ? e.getClass().getName() + r : e.toString() + r);
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
throw exception;
|
||||
|
||||
if (textSize == -1)
|
||||
throw new RunnerException(firstLine);
|
||||
|
||||
return new long[] { textSize, dataSize, eepromSize };
|
||||
}
|
||||
|
||||
public void message(String s) {
|
||||
if (firstLine == null)
|
||||
firstLine = s;
|
||||
Matcher textMatcher = textPattern.matcher(s.trim());
|
||||
if (textMatcher.matches()) {
|
||||
if (textSize < 0)
|
||||
textSize = 0;
|
||||
textSize += Long.parseLong(textMatcher.group(1));
|
||||
}
|
||||
if(dataPattern != null) {
|
||||
Matcher dataMatcher = dataPattern.matcher(s.trim());
|
||||
if (dataMatcher.matches()) {
|
||||
if (dataSize < 0)
|
||||
dataSize = 0;
|
||||
dataSize += Long.parseLong(dataMatcher.group(1));
|
||||
}
|
||||
}
|
||||
if(eepromPattern != null) {
|
||||
Matcher eepromMatcher = eepromPattern.matcher(s.trim());
|
||||
if (eepromMatcher.matches()) {
|
||||
if (eepromSize < 0)
|
||||
eepromSize = 0;
|
||||
eepromSize += Long.parseLong(eepromMatcher.group(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
132
arduino-core/src/processing/app/debug/TargetBoard.java
Normal file
132
arduino-core/src/processing/app/debug/TargetBoard.java
Normal file
@ -0,0 +1,132 @@
|
||||
package processing.app.debug;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import static processing.app.I18n.format;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
public class TargetBoard {
|
||||
|
||||
private String id;
|
||||
private PreferencesMap prefs;
|
||||
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
|
||||
private TargetPlatform containerPlatform;
|
||||
|
||||
/**
|
||||
* Create a TargetBoard based on preferences passed as argument.
|
||||
*
|
||||
* @param _prefs
|
||||
* @return
|
||||
*/
|
||||
public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) {
|
||||
containerPlatform = parent;
|
||||
id = _id;
|
||||
prefs = new PreferencesMap(_prefs);
|
||||
|
||||
// Setup sub-menus
|
||||
PreferencesMap menus = prefs.firstLevelMap().get("menu");
|
||||
if (menus != null)
|
||||
menuOptions = menus.firstLevelMap();
|
||||
|
||||
// Auto generate build.board if not set
|
||||
if (!prefs.containsKey("build.board")) {
|
||||
String board = containerPlatform.getId() + "_" + id;
|
||||
board = board.toUpperCase();
|
||||
prefs.put("build.board", board);
|
||||
System.out
|
||||
.println(format(
|
||||
_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
|
||||
containerPlatform.getContainerPackage().getId(),
|
||||
containerPlatform.getId(), id, board));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the board.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return prefs.get("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier of the board
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full preferences map of the board with a given identifier
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PreferencesMap getPreferences() {
|
||||
return prefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the board has a sub menu.
|
||||
*
|
||||
* @param menuId
|
||||
* The menu ID to check
|
||||
* @return
|
||||
*/
|
||||
public boolean hasMenu(String menuId) {
|
||||
return menuOptions.containsKey(menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options available on a specific menu
|
||||
*
|
||||
* @param menuId
|
||||
* The menu ID
|
||||
* @return
|
||||
*/
|
||||
public PreferencesMap getMenuLabels(String menuId) {
|
||||
return menuOptions.get(menuId).topLevelMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label of the specified option in the specified menu
|
||||
*
|
||||
* @param menuId
|
||||
* The menu ID
|
||||
* @param selectionId
|
||||
* The option ID
|
||||
* @return
|
||||
*/
|
||||
public String getMenuLabel(String menuId, String selectionId) {
|
||||
return getMenuLabels(menuId).get(selectionId);
|
||||
}
|
||||
|
||||
public Set<String> getMenuIds() {
|
||||
return menuOptions.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration parameters to override (as a PreferenceMap) when
|
||||
* the specified option in the specified menu is selected
|
||||
*
|
||||
* @param menuId
|
||||
* The menu ID
|
||||
* @param selectionId
|
||||
* The option ID
|
||||
* @return
|
||||
*/
|
||||
public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
|
||||
return menuOptions.get(menuId).subTree(selectionId);
|
||||
}
|
||||
|
||||
public TargetPlatform getContainerPlatform() {
|
||||
return containerPlatform;
|
||||
}
|
||||
|
||||
}
|
81
arduino-core/src/processing/app/debug/TargetPackage.java
Normal file
81
arduino-core/src/processing/app/debug/TargetPackage.java
Normal file
@ -0,0 +1,81 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
/*
|
||||
TargetPackage - Represents a hardware package
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2011 Cristian Maglie
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.debug;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.I18n;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
|
||||
public class TargetPackage {
|
||||
|
||||
private String id;
|
||||
|
||||
Map<String, TargetPlatform> platforms = new LinkedHashMap<String, TargetPlatform>();
|
||||
|
||||
public TargetPackage(String _id, File _folder) throws TargetPlatformException {
|
||||
id = _id;
|
||||
|
||||
File[] folders = _folder.listFiles(new OnlyDirs());
|
||||
if (folders == null)
|
||||
return;
|
||||
|
||||
for (File subFolder : folders) {
|
||||
if (!subFolder.exists() || !subFolder.canRead())
|
||||
continue;
|
||||
String arch = subFolder.getName();
|
||||
try {
|
||||
TargetPlatform platform = new TargetPlatform(arch, subFolder, this);
|
||||
platforms.put(arch, platform);
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (platforms.size() == 0) {
|
||||
throw new TargetPlatformException(I18n
|
||||
.format(_("No valid hardware definitions found in folder {0}."),
|
||||
_folder.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, TargetPlatform> getPlatforms() {
|
||||
return platforms;
|
||||
}
|
||||
|
||||
public Collection<TargetPlatform> platforms() {
|
||||
return platforms.values();
|
||||
}
|
||||
|
||||
public TargetPlatform get(String platform) {
|
||||
return platforms.get(platform);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
194
arduino-core/src/processing/app/debug/TargetPlatform.java
Normal file
194
arduino-core/src/processing/app/debug/TargetPlatform.java
Normal file
@ -0,0 +1,194 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
/*
|
||||
TargetPlatform - Represents a hardware platform
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2009 David A. Mellis
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.debug;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import static processing.app.I18n.format;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
public class TargetPlatform {
|
||||
|
||||
private String id;
|
||||
private File folder;
|
||||
private TargetPackage containerPackage;
|
||||
|
||||
/**
|
||||
* Contains preferences for every defined board
|
||||
*/
|
||||
private Map<String, TargetBoard> boards = new LinkedHashMap<String, TargetBoard>();
|
||||
private TargetBoard defaultBoard;
|
||||
|
||||
/**
|
||||
* Contains preferences for every defined programmer
|
||||
*/
|
||||
private Map<String, PreferencesMap> programmers = new LinkedHashMap<String, PreferencesMap>();
|
||||
|
||||
/**
|
||||
* Contains preferences for platform
|
||||
*/
|
||||
private PreferencesMap preferences = new PreferencesMap();
|
||||
|
||||
/**
|
||||
* Contains labels for top level menus
|
||||
*/
|
||||
private PreferencesMap customMenus = new PreferencesMap();
|
||||
|
||||
public TargetPlatform(String _name, File _folder, TargetPackage parent)
|
||||
throws TargetPlatformException {
|
||||
|
||||
id = _name;
|
||||
folder = _folder;
|
||||
containerPackage = parent;
|
||||
|
||||
// If there is no boards.txt, this is not a valid 1.5 hardware folder
|
||||
File boardsFile = new File(folder, "boards.txt");
|
||||
if (!boardsFile.exists() || !boardsFile.canRead())
|
||||
throw new TargetPlatformException(
|
||||
format(_("Could not find boards.txt in {0}. Is it pre-1.5?"),
|
||||
folder.getAbsolutePath()));
|
||||
|
||||
// Load boards
|
||||
try {
|
||||
Map<String, PreferencesMap> boardsPreferences = new PreferencesMap(
|
||||
boardsFile).firstLevelMap();
|
||||
|
||||
// Create custom menus for this platform
|
||||
PreferencesMap menus = boardsPreferences.get("menu");
|
||||
if (menus != null)
|
||||
customMenus = menus.topLevelMap();
|
||||
boardsPreferences.remove("menu");
|
||||
|
||||
// Create boards
|
||||
Set<String> boardIDs = boardsPreferences.keySet();
|
||||
for (String id : boardIDs) {
|
||||
PreferencesMap preferences = boardsPreferences.get(id);
|
||||
TargetBoard board = new TargetBoard(id, preferences, this);
|
||||
boards.put(id, board);
|
||||
}
|
||||
if (!boardIDs.isEmpty()) {
|
||||
PreferencesMap preferences = boardsPreferences.get(boardIDs.iterator().next());
|
||||
defaultBoard = new TargetBoard(id, preferences, this);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TargetPlatformException(format(_("Error loading {0}"),
|
||||
boardsFile.getAbsolutePath()), e);
|
||||
}
|
||||
|
||||
File platformsFile = new File(folder, "platform.txt");
|
||||
try {
|
||||
if (platformsFile.exists() && platformsFile.canRead()) {
|
||||
preferences.load(platformsFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TargetPlatformException(
|
||||
format(_("Error loading {0}"), platformsFile.getAbsolutePath()), e);
|
||||
}
|
||||
|
||||
// Allow overriding values in platform.txt. This allows changing
|
||||
// platform.txt (e.g. to use a system-wide toolchain), without
|
||||
// having to modify platform.txt (which, when running from git,
|
||||
// prevents files being marked as changed).
|
||||
File localPlatformsFile = new File(folder, "platform.local.txt");
|
||||
try {
|
||||
if (localPlatformsFile.exists() && localPlatformsFile.canRead()) {
|
||||
preferences.load(localPlatformsFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TargetPlatformException(
|
||||
format(_("Error loading {0}"), localPlatformsFile.getAbsolutePath()), e);
|
||||
}
|
||||
|
||||
File progFile = new File(folder, "programmers.txt");
|
||||
try {
|
||||
if (progFile.exists() && progFile.canRead()) {
|
||||
PreferencesMap prefs = new PreferencesMap();
|
||||
prefs.load(progFile);
|
||||
programmers = prefs.firstLevelMap();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TargetPlatformException(format(_("Error loading {0}"), progFile
|
||||
.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public Map<String, TargetBoard> getBoards() {
|
||||
return boards;
|
||||
}
|
||||
|
||||
public PreferencesMap getCustomMenus() {
|
||||
return customMenus;
|
||||
}
|
||||
|
||||
public Set<String> getCustomMenuIds() {
|
||||
return customMenus.keySet();
|
||||
}
|
||||
|
||||
public Map<String, PreferencesMap> getProgrammers() {
|
||||
return programmers;
|
||||
}
|
||||
|
||||
public PreferencesMap getProgrammer(String programmer) {
|
||||
return getProgrammers().get(programmer);
|
||||
}
|
||||
|
||||
public PreferencesMap getTool(String tool) {
|
||||
return getPreferences().subTree("tools").subTree(tool);
|
||||
}
|
||||
|
||||
public PreferencesMap getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
public TargetBoard getBoard(String boardId) {
|
||||
if (boards.containsKey(boardId)) {
|
||||
return boards.get(boardId);
|
||||
}
|
||||
return defaultBoard;
|
||||
}
|
||||
|
||||
public TargetPackage getContainerPackage() {
|
||||
return containerPackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "TargetPlatform: name=" + id + " boards={\n";
|
||||
for (String boardId : boards.keySet())
|
||||
res += " " + boardId + " = " + boards.get(boardId) + "\n";
|
||||
return res + "}";
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package processing.app.debug;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class TargetPlatformException extends Exception {
|
||||
|
||||
public TargetPlatformException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TargetPlatformException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
}
|
||||
|
||||
public TargetPlatformException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public TargetPlatformException(Throwable arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class BasicUserNotifier extends UserNotifier {
|
||||
|
||||
/**
|
||||
* Show an error message that's actually fatal to the program.
|
||||
* This is an error that can't be recovered. Use showWarning()
|
||||
* for errors that allow P5 to continue running.
|
||||
*/
|
||||
public void showError(String title, String message, Throwable e, int exit_code) {
|
||||
if (title == null) title = _("Error");
|
||||
|
||||
System.err.println(title + ": " + message);
|
||||
|
||||
if (e != null) e.printStackTrace();
|
||||
System.exit(exit_code);
|
||||
}
|
||||
|
||||
public void showMessage(String title, String message) {
|
||||
if (title == null) title = _("Message");
|
||||
|
||||
System.out.println(title + ": " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-fatal error message with optional stack trace side dish.
|
||||
*/
|
||||
public void showWarning(String title, String message, Exception e) {
|
||||
if (title == null) title = _("Warning");
|
||||
|
||||
System.out.println(title + ": " + message);
|
||||
|
||||
if (e != null) e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
283
arduino-core/src/processing/app/helpers/CommandlineParser.java
Normal file
283
arduino-core/src/processing/app/helpers/CommandlineParser.java
Normal file
@ -0,0 +1,283 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
public class CommandlineParser {
|
||||
|
||||
protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF };
|
||||
|
||||
private ACTION action = ACTION.GUI;
|
||||
private boolean doVerboseBuild = false;
|
||||
private boolean doVerboseUpload = false;
|
||||
private boolean doUseProgrammer = false;
|
||||
private boolean noUploadPort = false;
|
||||
private boolean forceSavePrefs = false;
|
||||
private String getPref = null;
|
||||
private List<String> filenames = new LinkedList<String>();
|
||||
|
||||
public static CommandlineParser newCommandlineParser(String[] args) {
|
||||
return new CommandlineParser(args);
|
||||
}
|
||||
|
||||
private CommandlineParser(String[] args) {
|
||||
parseArguments(args);
|
||||
checkAction();
|
||||
}
|
||||
|
||||
private void parseArguments(String[] args) {
|
||||
// Map of possible actions and corresponding options
|
||||
final Map<String, ACTION> actions = new HashMap<String, ACTION>();
|
||||
actions.put("--verify", ACTION.VERIFY);
|
||||
actions.put("--upload", ACTION.UPLOAD);
|
||||
actions.put("--get-pref", ACTION.GET_PREF);
|
||||
|
||||
// Check if any files were passed in on the command line
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
ACTION a = actions.get(args[i]);
|
||||
if (a != null) {
|
||||
if (action != ACTION.GUI && action != ACTION.NOOP) {
|
||||
String[] valid = actions.keySet().toArray(new String[0]);
|
||||
String mess = I18n.format(_("Can only pass one of: {0}"), PApplet.join(valid, ", "));
|
||||
BaseNoGui.showError(null, mess, 3);
|
||||
}
|
||||
if (a == ACTION.GET_PREF) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --get-pref"), 3);
|
||||
getPref = args[i];
|
||||
}
|
||||
action = a;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--verbose") || args[i].equals("-v")) {
|
||||
doVerboseBuild = true;
|
||||
doVerboseUpload = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--verbose-build")) {
|
||||
doVerboseBuild = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--verbose-upload")) {
|
||||
doVerboseUpload = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--useprogrammer")) {
|
||||
doUseProgrammer = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--nouploadport")) {
|
||||
noUploadPort = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--board")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --board"), 3);
|
||||
processBoardArgument(args[i]);
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--port")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --port"), 3);
|
||||
BaseNoGui.selectSerialPort(args[i]);
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--curdir")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --curdir"), 3);
|
||||
// Argument should be already processed by Base.main(...)
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--buildpath")) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
BaseNoGui.showError(null, "Argument required for --buildpath", 3);
|
||||
}
|
||||
File buildFolder = new File(args[i]);
|
||||
if (!buildFolder.exists()) {
|
||||
BaseNoGui.showError(null, "The build path doesn't exist", 3);
|
||||
}
|
||||
if (!buildFolder.isDirectory()) {
|
||||
BaseNoGui.showError(null, "The build path is not a folder", 3);
|
||||
}
|
||||
BaseNoGui.setBuildFolder(buildFolder);
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--pref")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --pref"), 3);
|
||||
processPrefArgument(args[i]);
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--save-prefs")) {
|
||||
forceSavePrefs = true;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--preferences-file")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --preferences-file"), 3);
|
||||
// Argument should be already processed by Base.main(...)
|
||||
continue;
|
||||
}
|
||||
if (args[i].startsWith("--"))
|
||||
BaseNoGui.showError(null, I18n.format(_("unknown option: {0}"), args[i]), 3);
|
||||
|
||||
filenames.add(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAction() {
|
||||
if ((action == ACTION.UPLOAD || action == ACTION.VERIFY) && filenames.size() != 1)
|
||||
BaseNoGui.showError(null, _("Must specify exactly one sketch file"), 3);
|
||||
|
||||
if ((action == ACTION.NOOP || action == ACTION.GET_PREF) && filenames.size() != 0)
|
||||
BaseNoGui.showError(null, _("Cannot specify any sketch files"), 3);
|
||||
|
||||
if ((action != ACTION.UPLOAD && action != ACTION.VERIFY) && (doVerboseBuild || doVerboseUpload))
|
||||
BaseNoGui.showError(null, _("--verbose, --verbose-upload and --verbose-build can only be used together with --verify or --upload"), 3);
|
||||
}
|
||||
|
||||
private void processBoardArgument(String selectBoard) {
|
||||
// No board selected? Nothing to do
|
||||
if (selectBoard == null)
|
||||
return;
|
||||
|
||||
String[] split = selectBoard.split(":", 4);
|
||||
|
||||
if (split.length < 3) {
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
|
||||
}
|
||||
|
||||
TargetPackage targetPackage = BaseNoGui.getTargetPackage(split[0]);
|
||||
if (targetPackage == null) {
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Unknown package"), split[0]), 3);
|
||||
}
|
||||
|
||||
TargetPlatform targetPlatform = targetPackage.get(split[1]);
|
||||
if (targetPlatform == null) {
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), 3);
|
||||
}
|
||||
|
||||
TargetBoard targetBoard = targetPlatform.getBoard(split[2]);
|
||||
if (targetBoard == null) {
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Unknown board"), split[2]), 3);
|
||||
}
|
||||
|
||||
BaseNoGui.selectBoard(targetBoard);
|
||||
|
||||
if (split.length > 3) {
|
||||
String[] options = split[3].split(",");
|
||||
for (String option : options) {
|
||||
String[] keyValue = option.split("=", 2);
|
||||
|
||||
if (keyValue.length != 2)
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), 3);
|
||||
String key = keyValue[0].trim();
|
||||
String value = keyValue[1].trim();
|
||||
|
||||
if (!targetBoard.hasMenu(key))
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), 3);
|
||||
if (targetBoard.getMenuLabel(key, value) == null)
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
|
||||
|
||||
PreferencesData.set("custom_" + key, targetBoard.getId() + "_" + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processPrefArgument(String arg) {
|
||||
String[] split = arg.split("=", 2);
|
||||
if (split.length != 2 || split[0].isEmpty())
|
||||
BaseNoGui.showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), 3);
|
||||
|
||||
PreferencesData.set(split[0], split[1]);
|
||||
}
|
||||
|
||||
public boolean isDoVerboseBuild() {
|
||||
return doVerboseBuild;
|
||||
}
|
||||
|
||||
public boolean isDoVerboseUpload() {
|
||||
return doVerboseUpload;
|
||||
}
|
||||
|
||||
public boolean isForceSavePrefs() {
|
||||
return forceSavePrefs;
|
||||
}
|
||||
|
||||
public String getGetPref() {
|
||||
return getPref;
|
||||
}
|
||||
|
||||
public List<String> getFilenames() {
|
||||
return filenames;
|
||||
}
|
||||
|
||||
public boolean isGetPrefMode() {
|
||||
return action == ACTION.GET_PREF;
|
||||
}
|
||||
|
||||
public boolean isGuiMode() {
|
||||
return action == ACTION.GUI;
|
||||
}
|
||||
|
||||
public boolean isNoOpMode() {
|
||||
return action == ACTION.NOOP;
|
||||
}
|
||||
|
||||
public boolean isUploadMode() {
|
||||
return action == ACTION.UPLOAD;
|
||||
}
|
||||
|
||||
public boolean isVerifyMode() {
|
||||
return action == ACTION.VERIFY;
|
||||
}
|
||||
|
||||
public boolean isVerifyOrUploadMode() {
|
||||
return isVerifyMode() || isUploadMode();
|
||||
}
|
||||
|
||||
public boolean isDoUseProgrammer() {
|
||||
return doUseProgrammer;
|
||||
}
|
||||
|
||||
public boolean isNoUploadPort() {
|
||||
return noUploadPort;
|
||||
}
|
||||
|
||||
}
|
259
arduino-core/src/processing/app/helpers/FileUtils.java
Normal file
259
arduino-core/src/processing/app/helpers/FileUtils.java
Normal file
@ -0,0 +1,259 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
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("\\\\");
|
||||
|
||||
/**
|
||||
* Checks, whether the child directory is a subdirectory of the base directory.
|
||||
*
|
||||
* @param base the base directory.
|
||||
* @param child the suspected child directory.
|
||||
* @return true, if the child is a subdirectory of the base directory.
|
||||
*/
|
||||
public static boolean isSubDirectory(File base, File child) {
|
||||
try {
|
||||
base = base.getCanonicalFile();
|
||||
child = child.getCanonicalFile();
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File parentFile = child;
|
||||
while (parentFile != null) {
|
||||
if (base.equals(parentFile)) {
|
||||
return true;
|
||||
}
|
||||
parentFile = parentFile.getParentFile();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void copyFile(File source, File dest) throws IOException {
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fis = new FileInputStream(source);
|
||||
fos = new FileOutputStream(dest);
|
||||
byte[] buf = new byte[4096];
|
||||
int readBytes = -1;
|
||||
while ((readBytes = fis.read(buf, 0, buf.length)) != -1) {
|
||||
fos.write(buf, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(File sourceFolder, File destFolder) throws IOException {
|
||||
for (File file : sourceFolder.listFiles()) {
|
||||
File destFile = new File(destFolder, file.getName());
|
||||
if (file.isDirectory()) {
|
||||
if (!destFile.mkdir()) {
|
||||
throw new IOException("Unable to create folder: " + destFile);
|
||||
}
|
||||
copy(file, destFile);
|
||||
} else {
|
||||
copyFile(file, destFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void recursiveDelete(File file) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
for (File current : file.listFiles()) {
|
||||
if (current.isDirectory()) {
|
||||
recursiveDelete(current);
|
||||
} else {
|
||||
current.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
|
||||
public static File createTempFolder() throws IOException {
|
||||
File tmpFolder = new File(System.getProperty("java.io.tmpdir"), "arduino_" + new Random().nextInt(1000000));
|
||||
if (!tmpFolder.mkdir()) {
|
||||
throw new IOException("Unable to create temp folder " + tmpFolder);
|
||||
}
|
||||
return tmpFolder;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 file.isHidden() || file.getName().charAt(0) == '.' || (file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName()));
|
||||
}
|
||||
|
||||
public static String readFileToString(File file) throws IOException {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given file has any of the given extensions.
|
||||
* @param file
|
||||
* File whose name to look at
|
||||
* @param extensions
|
||||
* Extensions to consider (just the extension, without the
|
||||
* 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<String> extensions) {
|
||||
String pieces[] = file.getName().split("\\.");
|
||||
if (pieces.length < 2)
|
||||
return false;
|
||||
|
||||
String extension = pieces[pieces.length - 1];
|
||||
|
||||
return extensions.contains(extension.toLowerCase());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively find all files in a folder with the specified
|
||||
* extension. Excludes hidden files and folders and
|
||||
* source control folders.
|
||||
*
|
||||
* @param folder
|
||||
* Folder to look into
|
||||
* @param recursive
|
||||
* <b>true</b> will recursively find all files in sub-folders
|
||||
* @param extensions
|
||||
* A list of file extensions to search (just the extension,
|
||||
* without the dot). Should all be lowercase, case
|
||||
* insensitive matching is used. If no extensions are
|
||||
* passed, all files are returned.
|
||||
* @return
|
||||
*/
|
||||
public static List<File> listFiles(File folder, boolean recursive,
|
||||
String... extensions) {
|
||||
return listFiles(folder, recursive, Arrays.asList(extensions));
|
||||
}
|
||||
|
||||
public static List<File> listFiles(File folder, boolean recursive,
|
||||
List<String> extensions) {
|
||||
List<File> result = new ArrayList<File>();
|
||||
|
||||
for (File file : folder.listFiles()) {
|
||||
if (isSCCSOrHiddenFile(file))
|
||||
continue;
|
||||
|
||||
if (file.isDirectory()) {
|
||||
if (recursive)
|
||||
result.addAll(listFiles(file, true, extensions));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (extensions.isEmpty() || hasExtension(file, extensions))
|
||||
result.add(file);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
28
arduino-core/src/processing/app/helpers/NetUtils.java
Normal file
28
arduino-core/src/processing/app/helpers/NetUtils.java
Normal file
@ -0,0 +1,28 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
public abstract class NetUtils {
|
||||
|
||||
public static boolean isReachable(InetAddress address, int port) {
|
||||
Socket socket = null;
|
||||
try {
|
||||
socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(address, port), 100);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
arduino-core/src/processing/app/helpers/OSUtils.java
Normal file
29
arduino-core/src/processing/app/helpers/OSUtils.java
Normal file
@ -0,0 +1,29 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
public class OSUtils {
|
||||
|
||||
/**
|
||||
* returns true if running on windows.
|
||||
*/
|
||||
static public boolean isWindows() {
|
||||
//return PApplet.platform == PConstants.WINDOWS;
|
||||
return System.getProperty("os.name").indexOf("Windows") != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* true if running on linux.
|
||||
*/
|
||||
static public boolean isLinux() {
|
||||
//return PApplet.platform == PConstants.LINUX;
|
||||
return System.getProperty("os.name").indexOf("Linux") != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if Processing is running on a Mac OS X machine.
|
||||
*/
|
||||
static public boolean isMacOS() {
|
||||
//return PApplet.platform == PConstants.MACOSX;
|
||||
return System.getProperty("os.name").indexOf("Mac") != -1;
|
||||
}
|
||||
|
||||
}
|
103
arduino-core/src/processing/app/helpers/PreferencesHelper.java
Normal file
103
arduino-core/src/processing/app/helpers/PreferencesHelper.java
Normal file
@ -0,0 +1,103 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
public abstract class PreferencesHelper {
|
||||
|
||||
// /**
|
||||
// * Create a Color with the value of the specified key. The format of the color
|
||||
// * should be an hexadecimal number of 6 digit, eventually prefixed with a '#'.
|
||||
// *
|
||||
// * @param name
|
||||
// * @return A Color object or <b>null</b> if the key is not found or the format
|
||||
// * is wrong
|
||||
// */
|
||||
// static public Color getColor(PreferencesMap prefs, String name) {
|
||||
// Color parsed = parseColor(prefs.get(name));
|
||||
// if (parsed != null)
|
||||
// return parsed;
|
||||
// return Color.GRAY; // set a default
|
||||
// }
|
||||
//
|
||||
//
|
||||
// static public void setColor(PreferencesMap prefs, String attr, Color what) {
|
||||
// putColor(prefs, attr, what);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// static public Font getFontWithDefault(PreferencesMap prefs, PreferencesMap defaults, String attr) {
|
||||
// Font font = getFont(prefs, attr);
|
||||
// if (font == null) {
|
||||
// String value = defaults.get(attr);
|
||||
// prefs.put(attr, value);
|
||||
// font = getFont(prefs, attr);
|
||||
// }
|
||||
// return font;
|
||||
// }
|
||||
//
|
||||
// static public SyntaxStyle getStyle(PreferencesMap prefs, String what) {
|
||||
// String str = prefs.get("editor." + what + ".style");
|
||||
//
|
||||
// StringTokenizer st = new StringTokenizer(str, ",");
|
||||
//
|
||||
// String s = st.nextToken();
|
||||
// if (s.indexOf("#") == 0) s = s.substring(1);
|
||||
// Color color = Color.DARK_GRAY;
|
||||
// try {
|
||||
// color = new Color(Integer.parseInt(s, 16));
|
||||
// } catch (Exception e) { }
|
||||
//
|
||||
// s = st.nextToken();
|
||||
// boolean bold = (s.indexOf("bold") != -1);
|
||||
// boolean italic = (s.indexOf("italic") != -1);
|
||||
// boolean underlined = (s.indexOf("underlined") != -1);
|
||||
//
|
||||
// return new SyntaxStyle(color, italic, bold, underlined);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Set the value of the specified key based on the Color passed as parameter.
|
||||
*
|
||||
* @param attr
|
||||
* @param color
|
||||
*/
|
||||
public static void putColor(PreferencesMap prefs, String attr, Color color) {
|
||||
prefs.put(attr, "#" + String.format("%06x", color.getRGB() & 0xffffff));
|
||||
}
|
||||
|
||||
public static Color parseColor(String v) {
|
||||
try {
|
||||
if (v.indexOf("#") == 0)
|
||||
v = v.substring(1);
|
||||
return new Color(Integer.parseInt(v, 16));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Font getFont(PreferencesMap prefs, String key) {
|
||||
String value = prefs.get(key);
|
||||
if (value == null)
|
||||
return null;
|
||||
String[] split = value.split(",");
|
||||
if (split.length != 3)
|
||||
return null;
|
||||
|
||||
String name = split[0];
|
||||
int style = Font.PLAIN;
|
||||
if (split[1].contains("bold"))
|
||||
style |= Font.BOLD;
|
||||
if (split[1].contains("italic"))
|
||||
style |= Font.ITALIC;
|
||||
int size;
|
||||
try {
|
||||
// ParseDouble handle numbers with decimals too
|
||||
size = (int) Double.parseDouble(split[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
// for wrong formatted size pick the default
|
||||
size = 12;
|
||||
}
|
||||
return new Font(name, style, size);
|
||||
}
|
||||
}
|
322
arduino-core/src/processing/app/helpers/PreferencesMap.java
Normal file
322
arduino-core/src/processing/app/helpers/PreferencesMap.java
Normal file
@ -0,0 +1,322 @@
|
||||
/*
|
||||
PreferencesMap - A Map<String, String> with some useful features
|
||||
to handle preferences.
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2014 Cristian Maglie
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
|
||||
public PreferencesMap(Map<String, String> table) {
|
||||
super(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a PreferencesMap and load the content of the file passed as
|
||||
* argument.
|
||||
*
|
||||
* Is equivalent to:
|
||||
*
|
||||
* <pre>
|
||||
* PreferencesMap map = new PreferencesMap();
|
||||
* map.load(file);
|
||||
* </pre>
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public PreferencesMap(File file) throws IOException {
|
||||
super();
|
||||
load(file);
|
||||
}
|
||||
|
||||
public PreferencesMap() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a property list file and put kev/value pairs into the Map
|
||||
*
|
||||
* @param file
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(File file) throws IOException {
|
||||
load(new FileInputStream(file));
|
||||
}
|
||||
|
||||
protected String processPlatformSuffix(String key, String suffix, boolean isCurrentPlatform) {
|
||||
if (key == null)
|
||||
return null;
|
||||
// Key does not end with the given suffix? Process as normal
|
||||
if (!key.endsWith(suffix))
|
||||
return key;
|
||||
// Not the current platform? Ignore this key
|
||||
if (!isCurrentPlatform)
|
||||
return null;
|
||||
// Strip the suffix from the key
|
||||
return key.substring(0, key.length() - suffix.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a property list stream and put key/value pairs into the Map
|
||||
*
|
||||
* @param input
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(InputStream input) throws IOException {
|
||||
String[] lines = PApplet.loadStrings(input);
|
||||
for (String line : lines) {
|
||||
if (line.length() == 0 || line.charAt(0) == '#')
|
||||
continue;
|
||||
|
||||
int equals = line.indexOf('=');
|
||||
if (equals != -1) {
|
||||
String key = line.substring(0, equals).trim();
|
||||
String value = line.substring(equals + 1).trim();
|
||||
|
||||
key = processPlatformSuffix(key, ".linux", OSUtils.isLinux());
|
||||
key = processPlatformSuffix(key, ".windows", OSUtils.isWindows());
|
||||
key = processPlatformSuffix(key, ".macosx", OSUtils.isMacOS());
|
||||
|
||||
if (key != null)
|
||||
put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PreferenceMap that contains all the top level pairs of the
|
||||
* current mapping. E.g. the folowing mapping:<br />
|
||||
*
|
||||
* <pre>
|
||||
* Map (
|
||||
* alpha = Alpha
|
||||
* alpha.some.keys = v1
|
||||
* alpha.other.keys = v2
|
||||
* beta = Beta
|
||||
* beta.some.keys = v3
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* will generate the following result:
|
||||
*
|
||||
* <pre>
|
||||
* Map (
|
||||
* alpha = Alpha
|
||||
* beta = Beta
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PreferencesMap topLevelMap() {
|
||||
PreferencesMap res = new PreferencesMap();
|
||||
for (String key : keySet()) {
|
||||
if (key.contains("."))
|
||||
continue;
|
||||
res.put(key, get(key));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Map<String, PreferenceMap> where keys are the first level of
|
||||
* the current mapping. Top level pairs are discarded. E.g. the folowing
|
||||
* mapping:<br />
|
||||
*
|
||||
* <pre>
|
||||
* Map (
|
||||
* alpha = Alpha
|
||||
* alpha.some.keys = v1
|
||||
* alpha.other.keys = v2
|
||||
* beta = Beta
|
||||
* beta.some.keys = v3
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* will generate the following result:
|
||||
*
|
||||
* <pre>
|
||||
* alpha = Map(
|
||||
* some.keys = v1
|
||||
* other.keys = v2
|
||||
* )
|
||||
* beta = Map(
|
||||
* some.keys = v3
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, PreferencesMap> firstLevelMap() {
|
||||
Map<String, PreferencesMap> res = new LinkedHashMap<String, PreferencesMap>();
|
||||
for (String key : keySet()) {
|
||||
int dot = key.indexOf('.');
|
||||
if (dot == -1)
|
||||
continue;
|
||||
|
||||
String parent = key.substring(0, dot);
|
||||
String child = key.substring(dot + 1);
|
||||
|
||||
if (!res.containsKey(parent))
|
||||
res.put(parent, new PreferencesMap());
|
||||
res.get(parent).put(child, get(key));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PreferenceMap using a subtree of the current mapping. Top
|
||||
* level pairs are ignored. E.g. with the following mapping:<br />
|
||||
*
|
||||
* <pre>
|
||||
* Map (
|
||||
* alpha = Alpha
|
||||
* alpha.some.keys = v1
|
||||
* alpha.other.keys = v2
|
||||
* beta = Beta
|
||||
* beta.some.keys = v3
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* a call to createSubTree("alpha") will generate the following result:
|
||||
*
|
||||
* <pre>
|
||||
* Map(
|
||||
* some.keys = v1
|
||||
* other.keys = v2
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public PreferencesMap subTree(String parent) {
|
||||
PreferencesMap res = new PreferencesMap();
|
||||
parent += ".";
|
||||
int parentLen = parent.length();
|
||||
for (String key : keySet()) {
|
||||
if (key.startsWith(parent))
|
||||
res.put(key.substring(parentLen), get(key));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public String toString(String indent) {
|
||||
String res = indent + "{\n";
|
||||
SortedSet<String> treeSet = new TreeSet<String>(keySet());
|
||||
for (String k : treeSet)
|
||||
res += indent + k + " = " + get(k) + "\n";
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value to which the specified key is mapped, or throws a
|
||||
* PreferencesMapException if not found
|
||||
*
|
||||
* @param k
|
||||
* the key whose associated value is to be returned
|
||||
* @return the value to which the specified key is mapped
|
||||
* @throws PreferencesMapException
|
||||
*/
|
||||
public String getOrExcept(String k) throws PreferencesMapException {
|
||||
String r = get(k);
|
||||
if (r == null)
|
||||
throw new PreferencesMapException(k);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new File instance by converting the value of the key into an
|
||||
* abstract pathname. If the the given key doesn't exists or his value is the
|
||||
* empty string, the result is <b>null</b>.
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public File getFile(String key) {
|
||||
if (!containsKey(key))
|
||||
return null;
|
||||
String path = get(key).trim();
|
||||
if (path.length() == 0)
|
||||
return null;
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new File instance by converting the value of the key into an
|
||||
* abstract pathname with the specified sub folder. If the the given key
|
||||
* doesn't exists or his value is the empty string, the result is <b>null</b>.
|
||||
*
|
||||
* @param key
|
||||
* @param subFolder
|
||||
* @return
|
||||
*/
|
||||
public File getFile(String key, String subFolder) {
|
||||
File file = getFile(key);
|
||||
if (file == null)
|
||||
return null;
|
||||
return new File(file, subFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the specified key as boolean.
|
||||
*
|
||||
* @param key
|
||||
* @return <b>true</b> if the value of the key is the string "true" (case
|
||||
* insensitive compared), <b>false</b> in any other case
|
||||
*/
|
||||
public boolean getBoolean(String key) {
|
||||
return new Boolean(get(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the specified key to the string <b>"true"</b> or
|
||||
* <b>"false"</b> based on value of the boolean parameter
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return <b>true</b> if the previous value of the key was the string "true"
|
||||
* (case insensitive compared), <b>false</b> in any other case
|
||||
*/
|
||||
public boolean putBoolean(String key, boolean value) {
|
||||
String prev = put(key, value ? "true" : "false");
|
||||
return new Boolean(prev);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PreferencesMapException extends Exception {
|
||||
|
||||
public PreferencesMapException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
28
arduino-core/src/processing/app/helpers/ProcessUtils.java
Normal file
28
arduino-core/src/processing/app/helpers/ProcessUtils.java
Normal file
@ -0,0 +1,28 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProcessUtils {
|
||||
|
||||
public static Process exec(String[] command) throws IOException {
|
||||
// No problems on linux and mac
|
||||
if (!OSUtils.isWindows()) {
|
||||
return Runtime.getRuntime().exec(command);
|
||||
}
|
||||
|
||||
// Brutal hack to workaround windows command line parsing.
|
||||
// http://stackoverflow.com/questions/5969724/java-runtime-exec-fails-to-escape-characters-properly
|
||||
// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
|
||||
// http://bugs.sun.com/view_bug.do?bug_id=6468220
|
||||
// http://bugs.sun.com/view_bug.do?bug_id=6518827
|
||||
String[] cmdLine = new String[command.length];
|
||||
for (int i = 0; i < command.length; i++)
|
||||
cmdLine[i] = command[i].replace("\"", "\\\"");
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmdLine);
|
||||
Map<String, String> env = pb.environment();
|
||||
env.put("CYGWIN", "nodosfilewarning");
|
||||
return pb.start();
|
||||
}
|
||||
}
|
102
arduino-core/src/processing/app/helpers/StringReplacer.java
Normal file
102
arduino-core/src/processing/app/helpers/StringReplacer.java
Normal file
@ -0,0 +1,102 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
/*
|
||||
StringReplacer - Utility class for expression formatting
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2011 Cristian Maglie
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StringReplacer {
|
||||
|
||||
public static String[] formatAndSplit(String src, Map<String, String> dict,
|
||||
boolean recursive) throws Exception {
|
||||
String res;
|
||||
|
||||
// Recursive replace with a max depth of 10 levels.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// Do a replace with dictionary
|
||||
res = StringReplacer.replaceFromMapping(src, dict);
|
||||
if (!recursive)
|
||||
break;
|
||||
if (res.equals(src))
|
||||
break;
|
||||
src = res;
|
||||
}
|
||||
|
||||
// Split the resulting string in arguments
|
||||
return quotedSplit(src, "\"'", false);
|
||||
}
|
||||
|
||||
public static String[] quotedSplit(String src, String quoteChars,
|
||||
boolean acceptEmptyArguments)
|
||||
throws Exception {
|
||||
List<String> res = new ArrayList<String>();
|
||||
String escapedArg = null;
|
||||
String escapingChar = null;
|
||||
for (String i : src.split(" ")) {
|
||||
if (escapingChar == null) {
|
||||
// If the first char is not an escape char..
|
||||
String first = null;
|
||||
if (i.length() > 0)
|
||||
first = i.substring(0, 1);
|
||||
if (first == null || !quoteChars.contains(first)) {
|
||||
if (i.trim().length() != 0 || acceptEmptyArguments)
|
||||
res.add(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
escapingChar = first;
|
||||
i = i.substring(1);
|
||||
escapedArg = "";
|
||||
}
|
||||
|
||||
if (!i.endsWith(escapingChar)) {
|
||||
escapedArg += i + " ";
|
||||
continue;
|
||||
}
|
||||
|
||||
escapedArg += i.substring(0, i.length() - 1);
|
||||
if (escapedArg.trim().length() != 0 || acceptEmptyArguments)
|
||||
res.add(escapedArg);
|
||||
escapingChar = null;
|
||||
}
|
||||
if (escapingChar != null)
|
||||
throw new Exception("Invalid quoting: no closing [" + escapingChar +
|
||||
"] char found.");
|
||||
return res.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static String replaceFromMapping(String src, Map<String, String> map) {
|
||||
return replaceFromMapping(src, map, "{", "}");
|
||||
}
|
||||
|
||||
public static String replaceFromMapping(String src, Map<String, String> map,
|
||||
String leftDelimiter,
|
||||
String rightDelimiter) {
|
||||
for (String k : map.keySet()) {
|
||||
String keyword = leftDelimiter + k + rightDelimiter;
|
||||
src = src.replace(keyword, map.get(k));
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
}
|
29
arduino-core/src/processing/app/helpers/StringUtils.java
Normal file
29
arduino-core/src/processing/app/helpers/StringUtils.java
Normal file
@ -0,0 +1,29 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
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
|
||||
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
|
||||
* <b>false</b> otherwise.
|
||||
*/
|
||||
public static boolean wildcardMatch(String input, String pattern) {
|
||||
String regex = pattern.replace("?", ".?").replace("*", ".*?");
|
||||
return input.matches(regex);
|
||||
}
|
||||
}
|
19
arduino-core/src/processing/app/helpers/UserNotifier.java
Normal file
19
arduino-core/src/processing/app/helpers/UserNotifier.java
Normal file
@ -0,0 +1,19 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
public abstract class UserNotifier {
|
||||
|
||||
public void showError(String title, String message, int exit_code) {
|
||||
showError(title, message, null, exit_code);
|
||||
}
|
||||
|
||||
public void showError(String title, String message, Throwable e) {
|
||||
showError(title, message, e, 1);
|
||||
}
|
||||
|
||||
public abstract void showError(String title, String message, Throwable e, int exit_code);
|
||||
|
||||
public abstract void showMessage(String title, String message);
|
||||
|
||||
public abstract void showWarning(String title, String message, Exception e);
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
OnlyDirs - FilenameFilter that accepts only directories (CVS, .svn,
|
||||
.DS_Store files are excluded as well)
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2011 Cristian Maglie
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.helpers.filefilters;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/**
|
||||
* This filter accepts only directories (excluding .DS_Store files, .svn
|
||||
* folders, etc)
|
||||
*
|
||||
* @author Cristian Maglie
|
||||
*/
|
||||
public class OnlyDirs implements FilenameFilter {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.charAt(0) == '.')
|
||||
return false;
|
||||
if (name.equals("CVS"))
|
||||
return false;
|
||||
return new File(dir, name).isDirectory();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
OnlyFilesWithExtension - FilenameFilter that accepts only files with a
|
||||
specific extension.
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2011 Cristian Maglie
|
||||
|
||||
This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.helpers.filefilters;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
public class OnlyFilesWithExtension implements FilenameFilter {
|
||||
|
||||
String extensions[];
|
||||
|
||||
public OnlyFilesWithExtension(String... ext) {
|
||||
extensions = ext;
|
||||
}
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
for (String ext : extensions)
|
||||
if (name.endsWith(ext))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
49
arduino-core/src/processing/app/i18n/README.md
Normal file
49
arduino-core/src/processing/app/i18n/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Internationalization Tools
|
||||
|
||||
by @sgk at SwitchScience.
|
||||
|
||||
## Reflect the source code change
|
||||
|
||||
Sometimes, the developers add/delete/modify the strings which should be translated. You have to reflect the source code change to your translation. This can be done as below given your language code `xx`.
|
||||
|
||||
% ./update.sh xx
|
||||
|
||||
This will extract the up-to-date set of strings from the source code, set the translated strings from the current "`Resources_xx.po`" file, and then write back to "`Resources_xx.po`" file. If the developers delete/modify the strings, corresponding translated strings disappear from the file. You may want to do like this.
|
||||
|
||||
% git commit
|
||||
% ./update.sh xx
|
||||
% git diff Resrouces_xx.po
|
||||
% git add Resources_xx.po Resources_xx.properties
|
||||
% git commit
|
||||
|
||||
## Get the translated catalog from Transifex
|
||||
|
||||
You may want to retrieve the translation contribution from Transifex. This can be done as below given your language code `xx`.
|
||||
|
||||
% ./pull.sh xx
|
||||
|
||||
Translation strings for only strings already in "`Resources_xx.po`" file will be updated. If Transifex has translated strings which are not in "`Resources_xx.po`" file, the strings will not appear in the file.
|
||||
|
||||
If you want to retrieve the newly translated language which is not in the Git repository, you will want to do like this.
|
||||
|
||||
% cp Resources_en.po Resources_xx.po
|
||||
% ./pull.sh xx
|
||||
% more Resources_xx.po
|
||||
% git add Resources_xx.po Resources_xx.properties
|
||||
% git commit
|
||||
|
||||
## Send the translated catalog to Transifex
|
||||
|
||||
You can send the translated catalog file "`Resources_xx.po`" to Transifex using the following command line where `xx` is the language code.
|
||||
|
||||
% ./push.sh xx
|
||||
|
||||
Be aware that this will overwrite the current result on Transifex. You may want to do "./update.sh" and "./pull.sh" before doing "./push.sh".
|
||||
|
||||
## Select "all" languages
|
||||
|
||||
**For the comitter only.** For all above scripts, you can select all languages by specifying "-a" instead of language codes like this.
|
||||
|
||||
% ./update.sh -a
|
||||
|
||||
The "all" means all the languages currently in your working directory. This does not mean the languages on Transifex.
|
1875
arduino-core/src/processing/app/i18n/Resources_an.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_an.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_an.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_an.properties
Normal file
File diff suppressed because it is too large
Load Diff
1878
arduino-core/src/processing/app/i18n/Resources_ar.po
Normal file
1878
arduino-core/src/processing/app/i18n/Resources_ar.po
Normal file
File diff suppressed because it is too large
Load Diff
1302
arduino-core/src/processing/app/i18n/Resources_ar.properties
Normal file
1302
arduino-core/src/processing/app/i18n/Resources_ar.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_ast.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_ast.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_ast.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_ast.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_be.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_be.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_be.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_be.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_bg.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_bg.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_bg.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_bg.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_bs.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_bs.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_bs.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_bs.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_ca.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_ca.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_ca.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_ca.properties
Normal file
File diff suppressed because it is too large
Load Diff
1878
arduino-core/src/processing/app/i18n/Resources_cs_CZ.po
Normal file
1878
arduino-core/src/processing/app/i18n/Resources_cs_CZ.po
Normal file
File diff suppressed because it is too large
Load Diff
1302
arduino-core/src/processing/app/i18n/Resources_cs_CZ.properties
Normal file
1302
arduino-core/src/processing/app/i18n/Resources_cs_CZ.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_da_DK.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_da_DK.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_da_DK.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_da_DK.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_de_DE.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_de_DE.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_de_DE.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_de_DE.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_el_GR.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_el_GR.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_el_GR.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_el_GR.properties
Normal file
File diff suppressed because it is too large
Load Diff
1996
arduino-core/src/processing/app/i18n/Resources_en.po
Normal file
1996
arduino-core/src/processing/app/i18n/Resources_en.po
Normal file
File diff suppressed because it is too large
Load Diff
1389
arduino-core/src/processing/app/i18n/Resources_en.properties
Normal file
1389
arduino-core/src/processing/app/i18n/Resources_en.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_en_GB.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_en_GB.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_en_GB.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_en_GB.properties
Normal file
File diff suppressed because it is too large
Load Diff
1877
arduino-core/src/processing/app/i18n/Resources_es.po
Normal file
1877
arduino-core/src/processing/app/i18n/Resources_es.po
Normal file
File diff suppressed because it is too large
Load Diff
1301
arduino-core/src/processing/app/i18n/Resources_es.properties
Normal file
1301
arduino-core/src/processing/app/i18n/Resources_es.properties
Normal file
File diff suppressed because it is too large
Load Diff
1874
arduino-core/src/processing/app/i18n/Resources_et.po
Normal file
1874
arduino-core/src/processing/app/i18n/Resources_et.po
Normal file
File diff suppressed because it is too large
Load Diff
1298
arduino-core/src/processing/app/i18n/Resources_et.properties
Normal file
1298
arduino-core/src/processing/app/i18n/Resources_et.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_et_EE.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_et_EE.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_et_EE.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_et_EE.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_fa.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_fa.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_fa.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_fa.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_fi.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_fi.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_fi.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_fi.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_fil.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_fil.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_fil.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_fil.properties
Normal file
File diff suppressed because it is too large
Load Diff
1882
arduino-core/src/processing/app/i18n/Resources_fr.po
Normal file
1882
arduino-core/src/processing/app/i18n/Resources_fr.po
Normal file
File diff suppressed because it is too large
Load Diff
1306
arduino-core/src/processing/app/i18n/Resources_fr.properties
Normal file
1306
arduino-core/src/processing/app/i18n/Resources_fr.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_fr_CA.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_fr_CA.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_fr_CA.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_fr_CA.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_gl.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_gl.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_gl.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_gl.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_hi.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_hi.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_hi.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_hi.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_hr_HR.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_hr_HR.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_hr_HR.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_hr_HR.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_hu.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_hu.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_hu.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_hu.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_hy.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_hy.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_hy.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_hy.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_in.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_in.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_in.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_in.properties
Normal file
File diff suppressed because it is too large
Load Diff
1878
arduino-core/src/processing/app/i18n/Resources_it_IT.po
Normal file
1878
arduino-core/src/processing/app/i18n/Resources_it_IT.po
Normal file
File diff suppressed because it is too large
Load Diff
1302
arduino-core/src/processing/app/i18n/Resources_it_IT.properties
Normal file
1302
arduino-core/src/processing/app/i18n/Resources_it_IT.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_iw.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_iw.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_iw.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_iw.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_ja_JP.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_ja_JP.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_ja_JP.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_ja_JP.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_ka_GE.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_ka_GE.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_ka_GE.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_ka_GE.properties
Normal file
File diff suppressed because it is too large
Load Diff
1875
arduino-core/src/processing/app/i18n/Resources_ko_KR.po
Normal file
1875
arduino-core/src/processing/app/i18n/Resources_ko_KR.po
Normal file
File diff suppressed because it is too large
Load Diff
1299
arduino-core/src/processing/app/i18n/Resources_ko_KR.properties
Normal file
1299
arduino-core/src/processing/app/i18n/Resources_ko_KR.properties
Normal file
File diff suppressed because it is too large
Load Diff
1876
arduino-core/src/processing/app/i18n/Resources_lt_LT.po
Normal file
1876
arduino-core/src/processing/app/i18n/Resources_lt_LT.po
Normal file
File diff suppressed because it is too large
Load Diff
1300
arduino-core/src/processing/app/i18n/Resources_lt_LT.properties
Normal file
1300
arduino-core/src/processing/app/i18n/Resources_lt_LT.properties
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user