1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-15 19:22:45 +03:00

Split IDE into 2 projects.

BEWARE: HIGHLY EXPERIMENTAL BRANCH
This commit is contained in:
Cristian Maglie
2014-09-23 17:31:46 +02:00
parent 2de206cccd
commit ba8eadeeb5
274 changed files with 5903 additions and 4826 deletions

File diff suppressed because it is too large Load Diff

View 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);
}

View 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;
}
}

View 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();
}
}
}

View 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));
}
}
}
}

View 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;
}
}

View 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;
}
}

View 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 + "}";
}
}

View File

@@ -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);
}
}