diff --git a/.classpath b/.classpath index 71e8cc1449a..e02d606907f 100644 --- a/.classpath +++ b/.classpath @@ -2,9 +2,14 @@ - - - - + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ef277e5a261..c4ce3cc4399 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,15 @@ -#Thu Jan 10 10:50:38 PST 2008 +#Tue Jul 26 14:48:34 CDT 2011 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 diff --git a/app/build.xml b/app/build.xml index 458df0698fd..173933fe9f0 100644 --- a/app/build.xml +++ b/app/build.xml @@ -44,7 +44,7 @@ encoding="UTF-8" includeAntRuntime="false" debug="true" - classpath="../core/core.jar; ${env.JAVA_HOME}/lib/tools.jar; lib/ant.jar; lib/ant-launcher.jar; lib/apple.jar; lib/ecj.jar; lib/jna.jar; lib/RXTXcomm.jar" /> + classpath="../core/core.jar; ${env.JAVA_HOME}/lib/tools.jar; lib/ant.jar; lib/ant-launcher.jar; lib/apple.jar; lib/ecj.jar; lib/jna.jar; lib/RXTXcomm.jar; lib/gson.jar; lib/httpclient.jar; lib/httpcore.jar; lib/commons-logging.jar; lib/commons-codec.jar; lib/egit.jar" /> diff --git a/app/lib/commons-codec.jar b/app/lib/commons-codec.jar new file mode 100644 index 00000000000..458d432da88 Binary files /dev/null and b/app/lib/commons-codec.jar differ diff --git a/app/lib/commons-logging.jar b/app/lib/commons-logging.jar new file mode 100644 index 00000000000..1deef144cb1 Binary files /dev/null and b/app/lib/commons-logging.jar differ diff --git a/app/lib/egit.jar b/app/lib/egit.jar new file mode 100644 index 00000000000..7a2fb763f10 Binary files /dev/null and b/app/lib/egit.jar differ diff --git a/app/lib/gson.jar b/app/lib/gson.jar new file mode 100644 index 00000000000..acd16c0646b Binary files /dev/null and b/app/lib/gson.jar differ diff --git a/app/lib/httpclient.jar b/app/lib/httpclient.jar new file mode 100644 index 00000000000..c845ef96104 Binary files /dev/null and b/app/lib/httpclient.jar differ diff --git a/app/lib/httpcore.jar b/app/lib/httpcore.jar new file mode 100644 index 00000000000..a357c076c48 Binary files /dev/null and b/app/lib/httpcore.jar differ diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 0dba54f300a..f5894a1f381 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1014,6 +1014,19 @@ public void actionPerformed(ActionEvent actionevent) { } } } + // DV - added this to get current board, maybe there's a better way? + public String getCurrentBoard() { + //System.out.println("rebuilding boards menu"); + for (Target target : targetsTable.values()) { + for (String board : target.getBoards().keySet()) { + if (target.getName().equals(Preferences.get("target")) && + board.equals(Preferences.get("board"))) { + return target.getBoards().get(board).get("name"); + } + } + } + return ""; + } public void rebuildBurnBootloaderMenu(JMenu menu) { diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 3d8bd405bad..803fb9f8528 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -34,6 +34,7 @@ import java.io.*; import java.net.*; import java.util.*; +import java.util.List; import java.util.zip.*; import javax.swing.*; @@ -41,6 +42,11 @@ import javax.swing.text.*; import javax.swing.undo.*; +import org.eclipse.egit.github.core.Gist; +import org.eclipse.egit.github.core.GistFile; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.service.GistService; + import gnu.io.*; /** @@ -145,6 +151,8 @@ public class Editor extends JFrame implements RunnerListener { Runnable stopHandler; Runnable exportHandler; Runnable exportAppHandler; + Runnable sendToGitHubHandler; + Runnable retrieveFromGitHubHandler; public Editor(Base ibase, String path, int[] location) { @@ -1362,13 +1370,16 @@ protected void updateRedoState() { public void setHandlers(Runnable runHandler, Runnable presentHandler, - Runnable stopHandler, - Runnable exportHandler, Runnable exportAppHandler) { + Runnable stopHandler, Runnable exportHandler, + Runnable exportAppHandler, Runnable sendToGitHubHandler, + Runnable retrieveFromGitHubHandler) { this.runHandler = runHandler; this.presentHandler = presentHandler; this.stopHandler = stopHandler; this.exportHandler = exportHandler; this.exportAppHandler = exportAppHandler; + this.sendToGitHubHandler = sendToGitHubHandler; + this.retrieveFromGitHubHandler = retrieveFromGitHubHandler; } @@ -1378,6 +1389,8 @@ public void resetHandlers() { stopHandler = new DefaultStopHandler(); exportHandler = new DefaultExportHandler(); exportAppHandler = new DefaultExportAppHandler(); + sendToGitHubHandler = new DefaultSendToGitHubHandler(); + retrieveFromGitHubHandler = new DefaultRetrieveFromGitHubHandler(); } @@ -2275,11 +2288,196 @@ synchronized public void handleExport(final boolean verbose) { //if (!handleExportCheckModified()) return; toolbar.activate(EditorToolbar.EXPORT); console.clear(); + statusNotice("Uploading to I/O Board..."); - new Thread(verbose ? exportAppHandler : exportHandler).start(); } + + // DV: this is the added code for sending to a github gist + + synchronized public void handleRetrieve() { + toolbar.activate(EditorToolbar.RETRIEVE); + console.clear(); + + statusNotice("Retrieving Source"); + new Thread(retrieveFromGitHubHandler).start(); + } + + + public String findSerialNumber() { + if (Base.isMacOS()) { + String getUsbArgs[] = new String[2]; + getUsbArgs[0]="system_profiler"; + getUsbArgs[1]="SPUSBDataType"; + try{ + Process process = new ProcessBuilder(getUsbArgs).start(); + InputStream is = process.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String line; + + boolean foundArduino=false; + boolean foundSerial=false; + int serialNumPosition; + while ((line = br.readLine()) != null && !foundSerial) { + if(line.indexOf("Arduino") > 0 || line.indexOf("FT232R") > 0){ + foundArduino=true; + } + if(foundArduino){ + serialNumPosition = line.indexOf("Serial Number"); + if(serialNumPosition > 0){ + foundSerial=true; + return line.substring((serialNumPosition+15)); + } + } + } + if(foundSerial==false){ + return ""; + } + } + catch(IOException e){ + System.out.println(e.getMessage()); + } + } + return ""; + } + + class DefaultSendToGitHubHandler implements Runnable { + public void run() { + String serialNumber=findSerialNumber(); + if (!serialNumber.isEmpty()){ + uploadToGitHub(serialNumber); + statusNotice("Source sent to github"); + }else{ + System.out.println("Could not find your board, make sure it's plugged into USB."); + statusNotice(""); + } + } + + private void uploadToGitHub(String serialNumber) { + GitHubClient client = new GitHubClient().setCredentials("arduinoboard", "1knowmysource"); + GistService service = new GistService(client); + GistFile file = new GistFile(); + Gist gist = new Gist(); + + try{ + List gists = service.getGists("arduinoboard"); + Boolean foundMatchingGist=false; + //for (Gist gist : gists) { + for (int i = gists.size(); --i >= 0;){ //backwards so the first one found is the oldest one + gist = (Gist)gists.get(i); + if(gist.getDescription().contains(serialNumber)){ //found the last matching gist + if(foundMatchingGist==true){ //if one has already been found then an extra was made in error and needs to be cleaned up + //delete the spurious gist + service.deleteGist(gist.getId()); + }else{ + //edit the current gist + file.setContent(sketch.getCurrentCode().getProgram()); + String filename = new String(sketch.getCurrentCode().getPrettyName()+".pde"); +<<<<<<< HEAD + //remove old files (get rid of this feature if we want to save multiple projects) +======= + //remove old files +>>>>>>> ec8b02761443c32a6bb28a17edf90a236b106422 + for (String key : gist.getFiles().keySet()) { + if(!key.equals(filename)){ + service.updateGist(gist.setFiles(Collections.singletonMap(key, new GistFile()))); + } + } + + gist.setFiles(Collections.singletonMap(filename, file)); + service.updateGist(gist); +<<<<<<< HEAD + System.out.println(new String("You can find the source online at: " + gist.getHtmlUrl())); +======= +>>>>>>> ec8b02761443c32a6bb28a17edf90a236b106422 + foundMatchingGist=true; + } + } + } + if(foundMatchingGist==false){ //if no gist exists for the board + gist = new Gist().setDescription(new String("The file that is currently on an "+base.getCurrentBoard() + " with a serial number of "+serialNumber)); + gist.setPublic(true); //this should be an option in the future, but keep in mind these cannot be edited + file.setContent(sketch.getCurrentCode().getProgram()); + gist.setFiles(Collections.singletonMap(new String(sketch.getCurrentCode().getPrettyName()+".pde"), file)); + gist = service.createGist(gist); +<<<<<<< HEAD + System.out.println(new String("You can find the source online at: " + gist.getHtmlUrl())); + + } +======= + + } + System.out.println(new String("You can find the source online at: " + gist.getHtmlUrl())); +>>>>>>> ec8b02761443c32a6bb28a17edf90a236b106422 + }catch(IOException e){ + System.out.println(e.getMessage()); + } + } + } + + class DefaultRetrieveFromGitHubHandler implements Runnable { + public void run() { + String serialNumber; + try { + int timeout = 2000; + InetAddress address = InetAddress.getByName("api.github.com"); + if (address.isReachable(timeout)){ + serialNumber=findSerialNumber(); + if (!serialNumber.isEmpty()){ + retrieveFromGitHub(serialNumber); + }else{ + System.out.println("Could not find your board, make sure it's plugged into USB."); + statusNotice(""); + } + }else{ + System.out.println("github service is unavailable, cannot retrieve source."); + statusNotice(""); + } + } catch (Exception e) { + System.out.println("You are not connected to the internet, cannot retrieve source."); + statusNotice(""); + } + toolbar.deactivate(EditorToolbar.RETRIEVE); + } + + private void retrieveFromGitHub(String serialNumber) { + GitHubClient client = new GitHubClient().setCredentials("arduinoboard", "1knowmysource"); + GistService service = new GistService(client); + GistFile file = new GistFile(); + Gist gist = new Gist(); + + try{ + List gists = service.getGists("arduinoboard"); + Boolean foundMatchingGist=false; + //for (Gist gist : gists) { + for (int i = gists.size(); --i >= 0;){ //backwards so the first one found is the oldest one + gist = (Gist)gists.get(i); + if(gist.getDescription().contains(serialNumber)){ //found the last matching gist + if(foundMatchingGist==true){ //if one has already been found then an extra was made in error and needs to be cleaned up + //delete the spurious gist + service.deleteGist(gist.getId()); + }else{ + statusNotice("Found Source"); + gist=service.getGist(gist.getId());//get it again because the other capture only gets the meta-data + setText(gist.getFiles().get(gist.getFiles().keySet().iterator().next()).getContent()); //gets the first sketch, puts it in the window + foundMatchingGist=true; + } + } + } + if(foundMatchingGist==false){ //if no gist exists for the board + System.out.println("No source was found for this board."); + statusNotice(""); + } + }catch(IOException e){ + System.out.println(e.getMessage()); + statusNotice(""); + } + } + } + + // DAM: in Arduino, this is upload class DefaultExportHandler implements Runnable { public void run() { @@ -2292,7 +2490,23 @@ public void run() { boolean success = sketch.exportApplet(false); if (success) { - statusNotice("Done uploading."); + //this is where the github code starts + try { + int timeout = 2000; + InetAddress address = InetAddress.getByName("api.github.com"); + if (address.isReachable(timeout)){ + statusNotice("Done uploading, sending source to github..."); + new Thread(sendToGitHubHandler).start(); + }else{ + statusNotice("Done uploading."); + System.out.println("github service is unavailable, source will not be sent."); + System.out.println("Make sure to save locally!"); + } + } catch (Exception e) { + statusNotice("Done uploading."); + System.out.println("You are not connected to the internet, source will not be sent."); + System.out.println("Make sure to save locally!"); + } } else { // error message will already be visible } diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 74ef71f94d8..60a4f50d494 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -37,12 +37,12 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key /** Rollover titles for each button. */ static final String title[] = { - "Verify", "Stop", "New", "Open", "Save", "Upload", "Serial Monitor" + "Verify", "Stop", "New", "Open", "Save", "Retrieve Source", "Upload", "Serial Monitor" }; /** Titles for each button when the shift key is pressed. */ static final String titleShift[] = { - "Verify (w/ Verbose Output)", "Stop", "New Editor Window", "Open in Another Window", "Save", "Upload (w/ Verbose Output)", "Serial Monitor" + "Verify (w/ Verbose Output)", "Stop", "New Editor Window", "Open in Another Window", "Save", "Retrieve Source", "Upload (w/ Verbose Output)", "Serial Monitor" }; static final int BUTTON_COUNT = title.length; @@ -62,9 +62,10 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key static final int NEW = 2; static final int OPEN = 3; static final int SAVE = 4; - static final int EXPORT = 5; + static final int RETRIEVE = 5; + static final int EXPORT = 6; - static final int SERIAL = 6; + static final int SERIAL = 7; static final int INACTIVE = 0; static final int ROLLOVER = 1; @@ -109,6 +110,7 @@ public EditorToolbar(Editor editor, JMenu menu) { which[buttonCount++] = NEW; which[buttonCount++] = OPEN; which[buttonCount++] = SAVE; + which[buttonCount++] = RETRIEVE; which[buttonCount++] = EXPORT; which[buttonCount++] = SERIAL; @@ -168,7 +170,7 @@ public void paintComponent(Graphics screen) { int offsetX = 3; for (int i = 0; i < buttonCount; i++) { x1[i] = offsetX; - if (i == 2 || i == 6) x1[i] += BUTTON_GAP; + if (i == 2 || i == 7) x1[i] += BUTTON_GAP; x2[i] = x1[i] + BUTTON_WIDTH; offsetX = x2[i]; } @@ -335,6 +337,10 @@ public void mousePressed(MouseEvent e) { case SAVE: editor.handleSave(false); break; + + case RETRIEVE: + editor.handleRetrieve(); + break; case EXPORT: editor.handleExport(e.isShiftDown()); diff --git a/build/build.xml b/build/build.xml index d6e00e2bd0f..c8f3bcfa711 100644 --- a/build/build.xml +++ b/build/build.xml @@ -28,6 +28,12 @@ + + + + + + diff --git a/build/macosx/template.app/Contents/Info.plist b/build/macosx/template.app/Contents/Info.plist index f9dc41c24c2..c9d218b26b3 100755 --- a/build/macosx/template.app/Contents/Info.plist +++ b/build/macosx/template.app/Contents/Info.plist @@ -1,112 +1,94 @@ - - - - CFBundleName - Arduino - - - CFBundleGetInfoString - 0022 - CFBundleVersion - 0022 - CFBundleShortVersionString - 0022 - - - CFBundleAllowMixedLocalizations - true - CFBundleExecutable - JavaApplicationStub - CFBundleDevelopmentRegion - English - CFBundlePackageType - APPL - CFBundleSignature - Pde1 - CFBundleInfoDictionaryVersion - 6.0 - CFBundleIconFile - processing.icns - CFBundleIdentifier - cc.arduino.Arduino - CFBundleDocumentTypes - - - CFBundleTypeExtensions - - pde - java - - CFBundleTypeIconFile - pde.icns - CFBundleTypeName - Processing Source File - CFBundleTypeMIMETypes - - text/plain - - CFBundleTypeOSTypes - - TEXT - - CFBundleTypeRole - Editor - - - Java - - VMOptions - - -Xms128M - -Xmx256M - - - MainClass - processing.app.Base - - JVMVersion - 1.5* - - ClassPath - - $JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/RXTXcomm.jar - - JVMArchs - - - i386 - ppc - - - - Properties - - - javaroot - $JAVAROOT - - - apple.laf.useScreenMenuBar - true - - apple.awt.showGrowBox - false - com.apple.smallTabs + + + + CFBundleName + Arduino + CFBundleGetInfoString + 0022 + CFBundleVersion + 0022 + CFBundleShortVersionString + 0022 + CFBundleAllowMixedLocalizations true - apple.awt.Antialiasing - false - apple.awt.TextAntialiasing - true - com.apple.hwaccel - true - apple.awt.use-file-dialog-packages - false - apple.awt.graphics.UseQuartz - true - - - + CFBundleExecutable + JavaApplicationStub + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleSignature + Pde1 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleIconFile + processing.icns + CFBundleIdentifier + cc.arduino.Arduino + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + pde + java + + CFBundleTypeIconFile + pde.icns + CFBundleTypeName + Processing Source File + CFBundleTypeMIMETypes + + text/plain + + CFBundleTypeOSTypes + + TEXT + + CFBundleTypeRole + Editor + + + Java + + VMOptions + + -Xms128M + -Xmx256M + + MainClass + processing.app.Base + JVMVersion + 1.5* + ClassPath + $JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/RXTXcomm.jar:$JAVAROOT/commons-codec.jar:$JAVAROOT/commons-logging.jar:$JAVAROOT/egit.jar:$JAVAROOT/gson.jar:$JAVAROOT/httpclient.jar:$JAVAROOT/httpcore.jar + JVMArchs + + i386 + ppc + + Properties + + javaroot + $JAVAROOT + apple.laf.useScreenMenuBar + true + apple.awt.showGrowBox + false + com.apple.smallTabs + true + apple.awt.Antialiasing + false + apple.awt.TextAntialiasing + true + com.apple.hwaccel + true + apple.awt.use-file-dialog-packages + false + apple.awt.graphics.UseQuartz + true + + + diff --git a/build/shared/lib/theme/buttons.gif b/build/shared/lib/theme/buttons.gif index 7cc33ceaf38..723eef99dde 100644 Binary files a/build/shared/lib/theme/buttons.gif and b/build/shared/lib/theme/buttons.gif differ