1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +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

View File

@ -13,5 +13,6 @@
<classpathentry kind="lib" path="lib/jmdns-3.4.1.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,82 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages;
import processing.app.helpers.PreferencesMap;
public class BoardPort {
private String address;
private String protocol;
private String boardName;
private String label;
private PreferencesMap prefs;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getBoardName() {
return boardName;
}
public void setBoardName(String boardName) {
this.boardName = boardName;
}
public void setPrefs(PreferencesMap prefs) {
this.prefs = prefs;
}
public PreferencesMap getPrefs() {
return prefs;
}
public void setLabel(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
}

View File

@ -1,64 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages;
import processing.app.helpers.PreferencesMap;
import java.util.List;
public interface Discovery {
/**
* Set discovery preferences
*
* @param options
*/
public void setPreferences(PreferencesMap options);
/**
* Start discovery service
*
* @throws Exception
*/
public void start() throws Exception;
/**
* Stop discovery service
*/
public void stop() throws Exception;
/**
* Return the list of discovered ports.
*
* @return
*/
public List<BoardPort> discovery();
}

View File

@ -1,91 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages;
import cc.arduino.packages.discoverers.NetworkDiscovery;
import cc.arduino.packages.discoverers.SerialDiscovery;
import java.util.ArrayList;
import java.util.List;
import static processing.app.I18n._;
public class DiscoveryManager {
private final List<Discovery> discoverers;
public DiscoveryManager() {
discoverers = new ArrayList<Discovery>();
discoverers.add(new SerialDiscovery());
discoverers.add(new NetworkDiscovery());
// Start all discoverers
for (Discovery d : discoverers) {
try {
d.start();
} catch (Exception e) {
System.err.println(_("Error starting discovery method: ") + d.getClass());
e.printStackTrace();
}
}
Thread closeHook = new Thread(new Runnable() {
@Override
public void run() {
for (Discovery d : discoverers) {
try {
d.stop();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
});
Runtime.getRuntime().addShutdownHook(closeHook);
}
public List<BoardPort> discovery() {
List<BoardPort> res = new ArrayList<BoardPort>();
for (Discovery d : discoverers) {
res.addAll(d.discovery());
}
return res;
}
public BoardPort find(String address) {
for (BoardPort boardPort : discovery()) {
if (boardPort.getAddress().equals(address)) {
return boardPort;
}
}
return null;
}
}

View File

@ -1,164 +0,0 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Uploader - abstract uploading baseclass (common to both uisp and avrdude)
Part of the Arduino project - http://www.arduino.cc/
Copyright (c) 2004-05
Hernando Barragan
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 cc.arduino.packages;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.debug.MessageConsumer;
import processing.app.debug.MessageSiphon;
import processing.app.debug.RunnerException;
import processing.app.helpers.ProcessUtils;
import processing.app.helpers.StringUtils;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static processing.app.I18n._;
public abstract class Uploader implements MessageConsumer {
private static final List<String> STRINGS_TO_SUPPRESS;
private static final List<String> AVRDUDE_PROBLEMS;
static {
STRINGS_TO_SUPPRESS = Arrays.asList("Connecting to programmer:",
"Found programmer: Id = \"CATERIN\"; type = S",
"Software Version = 1.0; No Hardware Version given.",
"Programmer supports auto addr increment.",
"Programmer supports buffered memory access with buffersize=128 bytes.",
"Programmer supports the following devices:", "Device code: 0x44");
AVRDUDE_PROBLEMS = Arrays.asList("Programmer is not responding",
"programmer is not responding",
"protocol error", "avrdude: ser_open(): can't open device",
"avrdude: ser_drain(): read error",
"avrdude: ser_send(): write error",
"avrdude: error: buffered memory access not supported.");
}
protected final boolean verbose;
private String error;
protected boolean notFoundError;
protected boolean noUploadPort;
protected Uploader() {
this.verbose = PreferencesData.getBoolean("upload.verbose");
init(false);
}
protected Uploader(boolean nup) {
this.verbose = PreferencesData.getBoolean("upload.verbose");
init(nup);
}
private void init(boolean nup) {
this.error = null;
this.notFoundError = false;
this.noUploadPort = nup;
}
public abstract boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception;
public abstract boolean burnBootloader() throws Exception;
public boolean requiresAuthorization() {
return false;
}
public String getAuthorizationKey() {
return null;
}
protected boolean executeUploadCommand(Collection<String> command) throws Exception {
return executeUploadCommand(command.toArray(new String[command.size()]));
}
protected boolean executeUploadCommand(String command[]) throws Exception {
// Skip empty commands
if (command == null || command.length == 0)
return true;
notFoundError = false;
int result = -1;
try {
if (verbose) {
for (String c : command)
System.out.print(c + " ");
System.out.println();
}
Process process = ProcessUtils.exec(command);
new MessageSiphon(process.getInputStream(), this, 100);
new MessageSiphon(process.getErrorStream(), this, 100);
// wait for the process to finish.
result = process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
if (error != null) {
RunnerException exception = new RunnerException(error);
exception.hideStackTrace();
throw exception;
}
return result == 0;
}
public void message(String s) {
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
s = "";
}
System.err.print(s);
// ignore cautions
if (s.contains("Error")) {
notFoundError = true;
return;
}
if (notFoundError) {
error = I18n.format(_("the selected serial port {0} does not exist or your board is not connected"), s);
return;
}
if (s.contains("Device is not responding")) {
error = _("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
return;
}
if (StringUtils.stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
error = _("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
return;
}
if (s.contains("Expected signature")) {
error = _("Wrong microcontroller found. Did you select the right board from the Tools > Board menu?");
return;
}
}
}

View File

@ -1,49 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages;
import cc.arduino.packages.uploaders.SSHUploader;
import cc.arduino.packages.uploaders.SerialUploader;
import processing.app.debug.TargetBoard;
public class UploaderFactory {
public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadPort) {
if (noUploadPort)
return new SerialUploader(noUploadPort);
if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) {
return new SSHUploader(port);
}
return new SerialUploader();
}
}

View File

@ -1,196 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.discoverers;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Discovery;
import cc.arduino.packages.discoverers.network.*;
import processing.app.BaseNoGui;
import processing.app.helpers.NetUtils;
import processing.app.helpers.PreferencesMap;
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
import javax.jmdns.*;
import javax.jmdns.impl.DNSTaskStarter;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.packages.discoverers.network.NetworkTopologyListener {
private Timer timer;
private final List<BoardPort> ports;
private final Map<InetAddress, JmDNS> mappedJmDNSs;
public NetworkDiscovery() {
DNSTaskStarter.Factory.setClassDelegate(new ArduinoDNSTaskStarter());
this.ports = new ArrayList<BoardPort>();
this.mappedJmDNSs = new Hashtable<InetAddress, JmDNS>();
}
@Override
public List<BoardPort> discovery() {
List<BoardPort> ports = clonePortsList();
Iterator<BoardPort> iterator = ports.iterator();
while (iterator.hasNext()) {
try {
BoardPort board = iterator.next();
if (!NetUtils.isReachable(InetAddress.getByName(board.getAddress()), Integer.parseInt(board.getPrefs().get("port")))) {
iterator.remove();
}
} catch (UnknownHostException e) {
iterator.remove();
}
}
return ports;
}
private List<BoardPort> clonePortsList() {
synchronized (this) {
return new ArrayList<BoardPort>(this.ports);
}
}
@Override
public void setPreferences(PreferencesMap options) {
}
@Override
public void start() throws IOException {
this.timer = new Timer(this.getClass().getName() + " timer");
new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance()).start(timer);
}
@Override
public void stop() throws IOException {
timer.purge();
// we don't close each JmDNS instance as it's too slow
}
@Override
public void serviceAdded(ServiceEvent serviceEvent) {
String type = serviceEvent.getType();
String name = serviceEvent.getName();
JmDNS dns = serviceEvent.getDNS();
dns.requestServiceInfo(type, name);
ServiceInfo serviceInfo = dns.getServiceInfo(type, name);
if (serviceInfo != null) {
dns.requestServiceInfo(type, name);
}
}
@Override
public void serviceRemoved(ServiceEvent serviceEvent) {
String name = serviceEvent.getName();
synchronized (this) {
for (BoardPort port : ports) {
if (port.getBoardName().equals(name))
ports.remove(port);
}
}
}
@Override
public void serviceResolved(ServiceEvent serviceEvent) {
ServiceInfo info = serviceEvent.getInfo();
for (InetAddress inetAddress : info.getInet4Addresses()) {
String address = inetAddress.getHostAddress();
String name = serviceEvent.getName();
PreferencesMap prefs = null;
String board = null;
if (info.hasData()) {
prefs = new PreferencesMap();
board = info.getPropertyString("board");
prefs.put("board", board);
prefs.put("distro_version", info.getPropertyString("distro_version"));
}
prefs.put("port", "" + info.getPort());
String label = name + " at " + address;
if (board != null) {
String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
label += " (" + boardName + ")";
}
BoardPort port = new BoardPort();
port.setAddress(address);
port.setBoardName(name);
port.setProtocol("network");
port.setPrefs(prefs);
port.setLabel(label);
synchronized (this) {
removeDuplicateBoards(port);
ports.add(port);
}
}
}
private void removeDuplicateBoards(BoardPort newBoard) {
Iterator<BoardPort> iterator = ports.iterator();
while (iterator.hasNext()) {
BoardPort board = iterator.next();
if (newBoard.getAddress().equals(board.getAddress())) {
iterator.remove();
}
}
}
@Override
public void inetAddressAdded(InetAddress address) {
if (mappedJmDNSs.containsKey(address)) {
return;
}
try {
JmDNS jmDNS = JmDNS.create(address);
jmDNS.addServiceListener("_arduino._tcp.local.", this);
mappedJmDNSs.put(address, jmDNS);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void inetAddressRemoved(InetAddress address) {
JmDNS jmDNS = mappedJmDNSs.remove(address);
if (jmDNS != null) {
try {
jmDNS.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,81 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.discoverers;
import java.util.ArrayList;
import java.util.List;
import processing.app.BaseNoGui;
import processing.app.Platform;
import processing.app.Serial;
import processing.app.helpers.PreferencesMap;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Discovery;
public class SerialDiscovery implements Discovery {
@Override
public List<BoardPort> discovery() {
Platform os = BaseNoGui.getPlatform();
String devicesListOutput = os.preListAllCandidateDevices();
List<BoardPort> res = new ArrayList<BoardPort>();
List<String> ports = Serial.list();
for (String port : ports) {
String boardName = os.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput);
String label = port;
if (boardName != null)
label += " (" + boardName + ")";
BoardPort boardPort = new BoardPort();
boardPort.setAddress(port);
boardPort.setProtocol("serial");
boardPort.setBoardName(boardName);
boardPort.setLabel(label);
res.add(boardPort);
}
return res;
}
@Override
public void setPreferences(PreferencesMap options) {
}
@Override
public void start() {
}
@Override
public void stop() {
}
}

View File

@ -1,75 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.discoverers.network;
import javax.jmdns.NetworkTopologyDiscovery;
import java.net.InetAddress;
import java.util.*;
public class NetworkChecker extends TimerTask {
private final NetworkTopologyListener topologyListener;
private final NetworkTopologyDiscovery topology;
private Set<InetAddress> knownAddresses;
public NetworkChecker(NetworkTopologyListener topologyListener, NetworkTopologyDiscovery topology) {
super();
this.topologyListener = topologyListener;
this.topology = topology;
this.knownAddresses = Collections.synchronizedSet(new HashSet<InetAddress>());
}
public void start(Timer timer) {
timer.schedule(this, 0, 3000);
}
@Override
public void run() {
try {
InetAddress[] curentAddresses = topology.getInetAddresses();
Set<InetAddress> current = new HashSet<InetAddress>(curentAddresses.length);
for (InetAddress address : curentAddresses) {
current.add(address);
if (!knownAddresses.contains(address)) {
topologyListener.inetAddressAdded(address);
}
}
for (InetAddress address : knownAddresses) {
if (!current.contains(address)) {
topologyListener.inetAddressRemoved(address);
}
}
knownAddresses = current;
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,40 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.discoverers.network;
import java.net.InetAddress;
public interface NetworkTopologyListener {
void inetAddressAdded(InetAddress address);
void inetAddressRemoved(InetAddress address);
}

View File

@ -1,36 +0,0 @@
package cc.arduino.packages.ssh;
import com.jcraft.jsch.UserInfo;
public class NoInteractionUserInfo implements UserInfo {
private final String password;
public NoInteractionUserInfo(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public boolean promptYesNo(String str) {
return true;
}
public String getPassphrase() {
return password;
}
public boolean promptPassphrase(String message) {
return true;
}
public boolean promptPassword(String message) {
return true;
}
public void showMessage(String message) {
}
}

View File

@ -1,139 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.ssh;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.Session;
import java.io.*;
public class SCP extends SSH {
private Channel channel;
private OutputStream out;
private InputStream in;
public SCP(Session session) {
super(session);
}
public void open() throws IOException {
try {
channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("scp -t -r -d /");
out = channel.getOutputStream();
in = channel.getInputStream();
channel.connect();
ensureAcknowledged();
} catch (Exception e) {
close();
}
}
public void close() throws IOException {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
if (channel != null) {
channel.disconnect();
}
}
protected void ensureAcknowledged() throws IOException {
out.flush();
int b = in.read();
if (b == 0) return;
if (b == -1) return;
if (b == 1 || b == 2) {
StringBuilder sb = new StringBuilder();
sb.append("SCP error: ");
int c;
do {
c = in.read();
sb.append((char) c);
} while (c != '\n');
throw new IOException(sb.toString());
}
throw new IOException("Uknown SCP error: " + b);
}
public void sendFile(File localFile) throws IOException {
sendFile(localFile, localFile.getName());
}
public void sendFile(File localFile, String remoteFile) throws IOException {
out.write(("C0644 " + localFile.length() + " " + remoteFile + "\n").getBytes());
ensureAcknowledged();
FileInputStream fis = null;
try {
fis = new FileInputStream(localFile);
byte[] buf = new byte[4096];
while (true) {
int len = fis.read(buf, 0, buf.length);
if (len <= 0) break;
out.write(buf, 0, len);
}
// \0 terminates file
buf[0] = 0;
out.write(buf, 0, 1);
} finally {
if (fis != null) {
fis.close();
}
}
ensureAcknowledged();
}
public void startFolder(String folder) throws IOException {
out.write(("D0755 0 " + folder + "\n").getBytes());
ensureAcknowledged();
}
public void endFolder() throws IOException {
out.write("E\n".getBytes());
ensureAcknowledged();
}
}

View File

@ -1,114 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.ssh;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
public class SSH {
protected final Session session;
public SSH(Session session) {
this.session = session;
}
public boolean execSyncCommand(String command) throws JSchException, IOException {
return execSyncCommand(command, null, null);
}
public boolean execSyncCommand(String command, PrintStream stdoutConsumer, PrintStream stderrConsumer) throws JSchException, IOException {
InputStream stdout = null;
InputStream stderr = null;
Channel channel = null;
try {
channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
stdout = channel.getInputStream();
stderr = ((ChannelExec) channel).getErrStream();
channel.connect();
int exitCode = consumeOutputSyncAndReturnExitCode(channel, stdout, stdoutConsumer, stderr, stderrConsumer);
return exitCode == 0;
} finally {
if (stdout != null) {
stdout.close();
}
if (stderr != null) {
stderr.close();
}
if (channel != null) {
channel.disconnect();
}
}
}
protected int consumeOutputSyncAndReturnExitCode(Channel channel, InputStream stdout, PrintStream stdoutConsumer, InputStream stderr, PrintStream stderrConsumer) throws IOException {
byte[] tmp = new byte[102400];
while (true) {
consumeStream(tmp, stdout, stdoutConsumer);
consumeStream(tmp, stderr, stderrConsumer);
if (channel.isClosed()) {
return channel.getExitStatus();
}
try {
Thread.sleep(100);
} catch (Exception ee) {
// noop
}
}
}
protected void consumeStream(byte[] buffer, InputStream in, PrintStream out) throws IOException {
while (in.available() > 0) {
int length = in.read(buffer, 0, buffer.length);
if (length < 0) {
break;
}
if (out != null) {
out.print(new String(buffer, 0, length));
}
}
}
}

View File

@ -1,17 +0,0 @@
package cc.arduino.packages.ssh;
import cc.arduino.packages.BoardPort;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import java.io.IOException;
public interface SSHClientSetupChainRing {
/*
Chain is actually useless as default JSCH behaviour is to follow SSH Server authentication methods list
*/
Session setup(BoardPort port, JSch jSch) throws JSchException, IOException;
}

View File

@ -1,93 +0,0 @@
package cc.arduino.packages.ssh;
import cc.arduino.packages.BoardPort;
import com.jcraft.jsch.*;
import java.io.File;
import java.io.IOException;
public class SSHConfigFileSetup implements SSHClientSetupChainRing {
private final SSHClientSetupChainRing nextChainRing;
public SSHConfigFileSetup(SSHClientSetupChainRing nextChainRing) {
this.nextChainRing = nextChainRing;
}
public Session setup(BoardPort port, JSch jSch) throws JSchException, IOException {
String ipAddress = port.getAddress();
String hostname = port.getBoardName().contains(".local") ? port.getBoardName() : port.getBoardName() + ".local";
File sshFolder = new File(System.getProperty("user.home"), ".ssh");
File sshConfig = new File(sshFolder, "config");
if (!sshFolder.exists() || !sshConfig.exists()) {
if (nextChainRing != null) {
return nextChainRing.setup(port, jSch);
}
throw new JSchException("Unable to find a way to connect");
}
OpenSSHConfig configRepository = OpenSSHConfig.parseFile(sshConfig.getAbsolutePath());
jSch.setConfigRepository(new OpenSSHConfigWrapper(configRepository, ipAddress));
return jSch.getSession(hostname);
}
public static class OpenSSHConfigWrapper implements ConfigRepository {
private final OpenSSHConfig config;
private final String ipAddress;
public OpenSSHConfigWrapper(OpenSSHConfig config, String ipAddress) {
this.config = config;
this.ipAddress = ipAddress;
}
@Override
public Config getConfig(String host) {
return new ConfigWrapper(config.getConfig(host), ipAddress);
}
}
public static class ConfigWrapper implements ConfigRepository.Config {
private final ConfigRepository.Config config;
private final String ipAddress;
public ConfigWrapper(OpenSSHConfig.Config config, String ipAddress) {
this.config = config;
this.ipAddress = ipAddress;
}
@Override
public String getHostname() {
return ipAddress;
}
@Override
public String getUser() {
String user = config.getUser();
if (user != null) {
return user;
}
return "root";
}
@Override
public int getPort() {
return config.getPort();
}
@Override
public String getValue(String key) {
return config.getValue(key);
}
@Override
public String[] getValues(String key) {
return config.getValues(key);
}
}
}

View File

@ -1,21 +0,0 @@
package cc.arduino.packages.ssh;
import cc.arduino.packages.BoardPort;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import processing.app.PreferencesData;
public class SSHPwdSetup implements SSHClientSetupChainRing {
@Override
public Session setup(BoardPort port, JSch jSch) throws JSchException {
String ipAddress = port.getAddress();
Session session = jSch.getSession("root", ipAddress, 22);
session.setPassword(PreferencesData.get("runtime.pwd." + ipAddress));
return session;
}
}

View File

@ -1,194 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.uploaders;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.ssh.*;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.debug.RunnerException;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.StringUtils;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static processing.app.I18n._;
public class SSHUploader extends Uploader {
private static final List<String> FILES_NOT_TO_COPY = Arrays.asList(".DS_Store", ".Trash", "Thumbs.db", "__MACOSX");
private final BoardPort port;
public SSHUploader(BoardPort port) {
this.port = port;
}
public boolean requiresAuthorization() {
return true;
}
@Override
public String getAuthorizationKey() {
return "runtime.pwd." + port.getAddress();
}
@Override
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws RunnerException {
if (usingProgrammer) {
throw new RunnerException(_("Network upload using programmer not supported"));
}
Session session = null;
SCP scp = null;
try {
JSch jSch = new JSch();
SSHClientSetupChainRing sshClientSetupChain = new SSHConfigFileSetup(new SSHPwdSetup());
session = sshClientSetupChain.setup(port, jSch);
session.setUserInfo(new NoInteractionUserInfo(PreferencesData.get("runtime.pwd." + port.getAddress())));
session.connect(30000);
scp = new SCP(session);
SSH ssh = new SSH(session);
scpFiles(scp, ssh, sourcePath, buildPath, className, warningsAccumulator);
return runAVRDude(ssh);
} catch (JSchException e) {
String message = e.getMessage();
if ("Auth cancel".equals(message) || "Auth fail".equals(message)) {
return false;
}
if (e.getMessage().contains("Connection refused")) {
throw new RunnerException(I18n.format("Unable to connect to {0}", port.getAddress()));
}
throw new RunnerException(e);
} catch (Exception e) {
throw new RunnerException(e);
} finally {
if (scp != null) {
try {
scp.close();
} catch (IOException e) {
throw new RunnerException(e);
}
}
if (session != null) {
session.disconnect();
}
}
}
private boolean runAVRDude(SSH ssh) throws IOException, JSchException {
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences());
prefs.putAll(targetPlatform.getTool(prefs.get("upload.tool")));
String additionalParams = verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet");
boolean success = ssh.execSyncCommand("merge-sketch-with-bootloader.lua /tmp/sketch.hex", System.out, System.err);
ssh.execSyncCommand("kill-bridge");
success = success && ssh.execSyncCommand("run-avrdude /tmp/sketch.hex '" + additionalParams + "'", System.out, System.err);
return success;
}
private void scpFiles(SCP scp, SSH ssh, File sourcePath, String buildPath, String className, List<String> warningsAccumulator) throws JSchException, IOException {
try {
scp.open();
scp.startFolder("tmp");
scp.sendFile(new File(buildPath, className + ".hex"), "sketch.hex");
scp.endFolder();
if (canUploadWWWFiles(sourcePath, ssh, warningsAccumulator)) {
scp.startFolder("www");
scp.startFolder("sd");
scp.startFolder(sourcePath.getName());
recursiveSCP(new File(sourcePath, "www"), scp);
scp.endFolder();
scp.endFolder();
scp.endFolder();
}
} finally {
scp.close();
}
}
private boolean canUploadWWWFiles(File sourcePath, SSH ssh, List<String> warningsAccumulator) throws IOException, JSchException {
File www = new File(sourcePath, "www");
if (!www.exists() || !www.isDirectory()) {
return false;
}
if (!www.canExecute()) {
warningsAccumulator.add(_("Problem accessing files in folder ") + www);
return false;
}
if (!ssh.execSyncCommand("special-storage-available")) {
warningsAccumulator.add(_("Problem accessing board folder /www/sd"));
return false;
}
return true;
}
private void recursiveSCP(File from, SCP scp) throws IOException {
File[] files = from.listFiles();
if (files == null) {
return;
}
for (File file : files) {
if (!StringUtils.stringContainsOneOf(file.getName(), FILES_NOT_TO_COPY)) {
if (file.isDirectory() && file.canExecute()) {
scp.startFolder(file.getName());
recursiveSCP(file, scp);
scp.endFolder();
} else if (file.isFile() && file.canRead()) {
scp.sendFile(file);
}
}
}
}
@Override
public boolean burnBootloader() throws RunnerException {
throw new RunnerException("Can't burn bootloader via SSH");
}
}

View File

@ -1,340 +0,0 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
BasicUploader - generic command line uploader implementation
Part of the Arduino project - http://www.arduino.cc/
Copyright (c) 2004-05
Hernando Barragan
Copyright (c) 2012
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 cc.arduino.packages.uploaders;
import static processing.app.I18n._;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.Serial;
import processing.app.SerialException;
import processing.app.debug.RunnerException;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.StringReplacer;
import cc.arduino.packages.Uploader;
public class SerialUploader extends Uploader {
public SerialUploader()
{
super();
}
public SerialUploader(boolean noUploadPort)
{
super(noUploadPort);
}
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
// FIXME: Preferences should be reorganized
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences());
String tool = prefs.getOrExcept("upload.tool");
if (tool.contains(":")) {
String[] split = tool.split(":", 2);
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
tool = split[1];
}
prefs.putAll(targetPlatform.getTool(tool));
// if no protocol is specified for this board, assume it lacks a
// bootloader and upload using the selected programmer.
if (usingProgrammer || prefs.get("upload.protocol") == null) {
return uploadUsingProgrammer(buildPath, className);
}
if (noUploadPort)
{
prefs.put("build.path", buildPath);
prefs.put("build.project_name", className);
if (verbose)
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
else
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
boolean uploadResult;
try {
String pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
uploadResult = executeUploadCommand(cmd);
} catch (Exception e) {
throw new RunnerException(e);
}
return uploadResult;
}
// need to do a little dance for Leonardo and derivatives:
// open then close the port at the magic baudrate (usually 1200 bps) first
// to signal to the sketch that it should reset into bootloader. after doing
// this wait a moment for the bootloader to enumerate. On Windows, also must
// deal with the fact that the COM port number changes from bootloader to
// sketch.
String t = prefs.get("upload.use_1200bps_touch");
boolean doTouch = t != null && t.equals("true");
t = prefs.get("upload.wait_for_upload_port");
boolean waitForUploadPort = (t != null) && t.equals("true");
if (doTouch) {
String uploadPort = prefs.getOrExcept("serial.port");
try {
// Toggle 1200 bps on selected serial port to force board reset.
List<String> before = Serial.list();
if (before.contains(uploadPort)) {
if (verbose)
System.out.println(_("Forcing reset using 1200bps open/close on port ") + uploadPort);
Serial.touchPort(uploadPort, 1200);
}
Thread.sleep(400);
if (waitForUploadPort) {
// Scanning for available ports seems to open the port or
// otherwise assert DTR, which would cancel the WDT reset if
// it happened within 250 ms. So we wait until the reset should
// have already occured before we start scanning.
uploadPort = waitForUploadPort(uploadPort, before);
}
} catch (SerialException e) {
throw new RunnerException(e);
} catch (InterruptedException e) {
throw new RunnerException(e.getMessage());
}
prefs.put("serial.port", uploadPort);
if (uploadPort.startsWith("/dev/"))
prefs.put("serial.port.file", uploadPort.substring(5));
else
prefs.put("serial.port.file", uploadPort);
}
prefs.put("build.path", buildPath);
prefs.put("build.project_name", className);
if (verbose)
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
else
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
boolean uploadResult;
try {
// if (prefs.get("upload.disable_flushing") == null
// || prefs.get("upload.disable_flushing").toLowerCase().equals("false")) {
// flushSerialBuffer();
// }
String pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
uploadResult = executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
} catch (Exception e) {
throw new RunnerException(e);
}
try {
if (uploadResult && doTouch) {
String uploadPort = PreferencesData.get("serial.port");
if (waitForUploadPort) {
// For Due/Leonardo wait until the bootloader serial port disconnects and the
// sketch serial port reconnects (or timeout after a few seconds if the
// sketch port never comes back). Doing this saves users from accidentally
// opening Serial Monitor on the soon-to-be-orphaned bootloader port.
Thread.sleep(1000);
long started = System.currentTimeMillis();
while (System.currentTimeMillis() - started < 2000) {
List<String> portList = Serial.list();
if (portList.contains(uploadPort))
break;
Thread.sleep(250);
}
}
}
} catch (InterruptedException ex) {
// noop
}
return uploadResult;
}
private String waitForUploadPort(String uploadPort, List<String> before) throws InterruptedException, RunnerException {
// Wait for a port to appear on the list
int elapsed = 0;
while (elapsed < 10000) {
List<String> now = Serial.list();
List<String> diff = new ArrayList<String>(now);
diff.removeAll(before);
if (verbose) {
System.out.print("PORTS {");
for (String p : before)
System.out.print(p + ", ");
System.out.print("} / {");
for (String p : now)
System.out.print(p + ", ");
System.out.print("} => {");
for (String p : diff)
System.out.print(p + ", ");
System.out.println("}");
}
if (diff.size() > 0) {
String newPort = diff.get(0);
if (verbose)
System.out.println("Found upload port: " + newPort);
return newPort;
}
// Keep track of port that disappears
before = now;
Thread.sleep(250);
elapsed += 250;
// On Windows, it can take a long time for the port to disappear and
// come back, so use a longer time out before assuming that the
// selected
// port is the bootloader (not the sketch).
if (((!OSUtils.isWindows() && elapsed >= 500) || elapsed >= 5000) && now.contains(uploadPort)) {
if (verbose)
System.out.println("Uploading using selected port: " + uploadPort);
return uploadPort;
}
}
// Something happened while detecting port
throw new RunnerException(_("Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload."));
}
public boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
String programmer = PreferencesData.get("programmer");
if (programmer.contains(":")) {
String[] split = programmer.split(":", 2);
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
programmer = split[1];
}
PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences());
PreferencesMap programmerPrefs = targetPlatform.getProgrammer(programmer);
if (programmerPrefs == null)
throw new RunnerException(
_("Please select a programmer from Tools->Programmer menu"));
prefs.putAll(programmerPrefs);
prefs.putAll(targetPlatform.getTool(prefs.getOrExcept("program.tool")));
prefs.put("build.path", buildPath);
prefs.put("build.project_name", className);
if (verbose)
prefs.put("program.verbose", prefs.getOrExcept("program.params.verbose"));
else
prefs.put("program.verbose", prefs.getOrExcept("program.params.quiet"));
try {
// if (prefs.get("program.disable_flushing") == null
// || prefs.get("program.disable_flushing").toLowerCase().equals("false"))
// {
// flushSerialBuffer();
// }
String pattern = prefs.getOrExcept("program.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
return executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
} catch (Exception e) {
throw new RunnerException(e);
}
}
public boolean burnBootloader() throws Exception {
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
// Find preferences for the selected programmer
PreferencesMap programmerPrefs;
String programmer = PreferencesData.get("programmer");
if (programmer.contains(":")) {
String[] split = programmer.split(":", 2);
TargetPlatform platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
programmer = split[1];
programmerPrefs = platform.getProgrammer(programmer);
} else {
programmerPrefs = targetPlatform.getProgrammer(programmer);
}
if (programmerPrefs == null)
throw new RunnerException(
_("Please select a programmer from Tools->Programmer menu"));
// Build configuration for the current programmer
PreferencesMap prefs = PreferencesData.getMap();
prefs.putAll(BaseNoGui.getBoardPreferences());
prefs.putAll(programmerPrefs);
// Create configuration for bootloader tool
PreferencesMap toolPrefs = new PreferencesMap();
String tool = prefs.getOrExcept("bootloader.tool");
if (tool.contains(":")) {
String[] split = tool.split(":", 2);
TargetPlatform platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
tool = split[1];
toolPrefs.putAll(platform.getTool(tool));
if (toolPrefs.size() == 0)
throw new RunnerException(I18n.format(_("Could not find tool {0} from package {1}"), tool, split[0]));
}
toolPrefs.putAll(targetPlatform.getTool(tool));
if (toolPrefs.size() == 0)
throw new RunnerException(I18n.format(_("Could not find tool {0}"), tool));
// Merge tool with global configuration
prefs.putAll(toolPrefs);
if (verbose) {
prefs.put("erase.verbose", prefs.getOrExcept("erase.params.verbose"));
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.verbose"));
} else {
prefs.put("erase.verbose", prefs.getOrExcept("erase.params.quiet"));
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet"));
}
try {
String pattern = prefs.getOrExcept("erase.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
if (!executeUploadCommand(cmd))
return false;
pattern = prefs.getOrExcept("bootloader.pattern");
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
return executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
} catch (Exception e) {
throw new RunnerException(e);
}
}
}

View File

@ -1,977 +0,0 @@
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);
}
}

View File

@ -1,96 +0,0 @@
/*
* 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");
}
}

View File

@ -1,220 +0,0 @@
/* -*- 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);
}
}

View File

@ -1,214 +0,0 @@
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;
}
}

View File

@ -1,544 +0,0 @@
/* -*- 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;
}
*/

View File

@ -1,42 +0,0 @@
/* -*- 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);
}
}

View File

@ -1,38 +0,0 @@
/*
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);
}
}

View File

@ -1,355 +0,0 @@
/* 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;
}
}

View File

@ -1,246 +0,0 @@
/*
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;
}
}

View File

@ -1,266 +0,0 @@
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;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
/* -*- 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

@ -1,147 +0,0 @@
/* -*- 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

@ -1,161 +0,0 @@
/* -*- 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

@ -1,125 +0,0 @@
/* -*- 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

@ -1,132 +0,0 @@
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

@ -1,81 +0,0 @@
/* -*- 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

@ -1,194 +0,0 @@
/* -*- 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

@ -1,22 +0,0 @@
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);
}
}

View File

@ -1,38 +0,0 @@
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();
}
}

View File

@ -1,283 +0,0 @@
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;
}
}

View File

@ -1,259 +0,0 @@
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;
}
}

View File

@ -1,28 +0,0 @@
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
}
}
}
}
}

View File

@ -1,29 +0,0 @@
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;
}
}

View File

@ -1,103 +0,0 @@
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);
}
}

View File

@ -1,322 +0,0 @@
/*
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);
}
}

View File

@ -1,10 +0,0 @@
package processing.app.helpers;
@SuppressWarnings("serial")
public class PreferencesMapException extends Exception {
public PreferencesMapException(String message) {
super(message);
}
}

View File

@ -1,28 +0,0 @@
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();
}
}

View File

@ -1,102 +0,0 @@
/* -*- 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;
}
}

View File

@ -1,29 +0,0 @@
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);
}
}

View File

@ -1,19 +0,0 @@
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);
}

View File

@ -1,42 +0,0 @@
/*
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();
}
}

View File

@ -1,42 +0,0 @@
/*
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;
}
}

View File

@ -1,49 +0,0 @@
# 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.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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