diff --git a/app/.classpath b/app/.classpath
index f32ff129bf7..b2cf4f4aa82 100644
--- a/app/.classpath
+++ b/app/.classpath
@@ -51,4 +51,7 @@
+
+
+
diff --git a/app/lib/org.eclipse.jgit-4.2.0.201601211800-r.jar b/app/lib/org.eclipse.jgit-4.2.0.201601211800-r.jar
new file mode 100644
index 00000000000..b04a780a554
Binary files /dev/null and b/app/lib/org.eclipse.jgit-4.2.0.201601211800-r.jar differ
diff --git a/app/lib/slf4j-api-1.7.20.jar b/app/lib/slf4j-api-1.7.20.jar
new file mode 100644
index 00000000000..eb2140f67de
Binary files /dev/null and b/app/lib/slf4j-api-1.7.20.jar differ
diff --git a/app/lib/slf4j-simple-1.7.20.jar b/app/lib/slf4j-simple-1.7.20.jar
new file mode 100644
index 00000000000..1a7a2cb1b22
Binary files /dev/null and b/app/lib/slf4j-simple-1.7.20.jar differ
diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java
index 8da903bcb2f..f4a852a0b01 100644
--- a/app/src/processing/app/Editor.java
+++ b/app/src/processing/app/Editor.java
@@ -79,10 +79,16 @@
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jgit.revwalk.*;
+
import static processing.app.I18n.tr;
import static processing.app.Theme.scale;
+
/**
* Main editor panel for the Processing Development Environment.
*/
@@ -199,11 +205,16 @@ public boolean test(Sketch sketch) {
Runnable exportHandler;
private Runnable exportAppHandler;
+ private File dirToGit = null;
+ private GitManager git = new GitManager();
+
+
public Editor(Base ibase, File file, int[] storedLocation, int[] defaultLocation, Platform platform) throws Exception {
super("Arduino");
this.base = ibase;
this.platform = platform;
+ dirToGit = file.getParentFile();
Base.setIcon(this);
@@ -356,7 +367,14 @@ public void windowDeactivated(WindowEvent e) {
// Open the document that was passed in
boolean loaded = handleOpenInternal(file);
- if (!loaded) sketch = null;
+ if (!loaded) {
+ sketch = null;
+ }
+ else
+ {
+ git.gitInit(dirToGit);
+ }
+
}
@@ -425,6 +443,7 @@ public boolean importData(JComponent src, Transferable transferable) {
}
private void setPlacement(int[] storedLocation, int[] defaultLocation) {
+
if (storedLocation.length > 5 && storedLocation[5] != 0) {
setExtendedState(storedLocation[5]);
setPlacement(defaultLocation);
@@ -467,7 +486,6 @@ protected int[] getPlacement() {
* with things in the Preferences window.
*/
public void applyPreferences() {
-
// apply the setting for 'use external editor'
boolean external = PreferencesData.getBoolean("editor.external");
@@ -570,9 +588,89 @@ public void menuSelected(MenuEvent e) {
menubar.add(toolsMenu);
menubar.add(buildHelpMenu());
+
+ menubar.add(buildGitMenu());
+
setJMenuBar(menubar);
}
+ private JMenu buildGitMenu()
+ {
+ JMenu gitMenu = new JMenu("Git");
+ gitMenu.setMnemonic(KeyEvent.VK_G);
+
+ JMenuItem commitItem = newJMenuItem("Commit", 'i');
+ commitItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(!validationUntitled()){
+
+ String commitTitle = JOptionPane.showInputDialog(new JFrame(),"Commit Label","Commit",1);
+ String result = "Commit aborted";
+ String whites = "^\\s*$";
+
+ if(commitTitle != null && !matchRegex(whites,commitTitle)){
+ result = git.gitCommit(commitTitle, dirToGit.listFiles());
+ }
+ System.out.println(result);
+ }
+ }
+ });
+
+ JMenuItem logItem = newJMenuItem("Show Log", 'g');
+ logItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(!validationUntitled()){
+ printGitLog(git.gitLog());
+ }
+
+
+ }
+ });
+
+
+ gitMenu.add(commitItem);
+ gitMenu.add(logItem);
+
+
+ return gitMenu;
+ }
+
+ private boolean validationUntitled(){
+ if(untitled){
+ System.out.println("the Files must be saved to use Git");
+ }
+ return untitled;
+ }
+
+ private void printGitLog(Iterable logs){
+ System.out.println("\nLog:");
+
+ try{
+ for (RevCommit log : logs)
+ {
+ System.out.println(log.toString());
+ System.out.println(log.getAuthorIdent());
+ System.out.println(log.getFullMessage());
+ System.out.println("\n");
+ }
+ }catch (NullPointerException ex)
+ {
+ System.out.println("There is no log to show");
+ }
+
+
+ }
+
+ private boolean matchRegex(String pattern, String line)
+ {
+ Pattern patternObj = Pattern.compile(pattern);
+ Matcher matchObj = patternObj.matcher(line);
+
+
+ return matchObj.find();
+ }
private JMenu buildFileMenu() {
JMenuItem item;
@@ -693,7 +791,7 @@ public void actionPerformed(ActionEvent e) {
}
return fileMenu;
}
-
+ ///limite
public void rebuildRecentSketchesMenu() {
recentSketchesMenu.removeAll();
for (JMenuItem recentSketchMenuItem : base.getRecentSketchesMenuItems()) {
@@ -741,13 +839,13 @@ public void actionPerformed(ActionEvent e) {
});
sketchMenu.add(item);
-// item = new JMenuItem("Stop");
-// item.addActionListener(new ActionListener() {
-// public void actionPerformed(ActionEvent e) {
-// handleStop();
-// }
-// });
-// sketchMenu.add(item);
+ // item = new JMenuItem("Stop");
+ // item.addActionListener(new ActionListener() {
+ // public void actionPerformed(ActionEvent e) {
+ // handleStop();
+ // }
+ // });
+ // sketchMenu.add(item);
sketchMenu.addSeparator();
@@ -1397,11 +1495,11 @@ public void actionPerformed(ActionEvent e) {
JMenuItem copyForumItem = newJMenuItemShift(tr("Copy for Forum"), 'C');
copyForumItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
-// SwingUtilities.invokeLater(new Runnable() {
-// public void run() {
+ // SwingUtilities.invokeLater(new Runnable() {
+ // public void run() {
new DiscourseFormat(Editor.this, false).show();
-// }
-// });
+ // }
+ // });
}
});
menu.add(copyForumItem);
@@ -1409,11 +1507,11 @@ public void actionPerformed(ActionEvent e) {
JMenuItem copyHTMLItem = newJMenuItemAlt(tr("Copy as HTML"), 'C');
copyHTMLItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
-// SwingUtilities.invokeLater(new Runnable() {
-// public void run() {
+ // SwingUtilities.invokeLater(new Runnable() {
+ // public void run() {
new DiscourseFormat(Editor.this, true).show();
-// }
-// });
+ // }
+ // });
}
});
menu.add(copyHTMLItem);
@@ -1695,18 +1793,18 @@ public void setText(String what) {
* Called to update the text but not switch to a different set of code
* (which would affect the undo manager).
*/
-// public void setText2(String what, int start, int stop) {
-// beginCompoundEdit();
-// textarea.setText(what);
-// endCompoundEdit();
-//
-// // make sure that a tool isn't asking for a bad location
-// start = Math.max(0, Math.min(start, textarea.getDocumentLength()));
-// stop = Math.max(0, Math.min(start, textarea.getDocumentLength()));
-// textarea.select(start, stop);
-//
-// textarea.requestFocus(); // get the caret blinking
-// }
+ // public void setText2(String what, int start, int stop) {
+ // beginCompoundEdit();
+ // textarea.setText(what);
+ // endCompoundEdit();
+ //
+ // // make sure that a tool isn't asking for a bad location
+ // start = Math.max(0, Math.min(start, textarea.getDocumentLength()));
+ // stop = Math.max(0, Math.min(start, textarea.getDocumentLength()));
+ // textarea.select(start, stop);
+ //
+ // textarea.requestFocus(); // get the caret blinking
+ // }
public String getSelectedText() {
@@ -1777,7 +1875,7 @@ protected void setCode(final SketchCodeDocument codeDoc) {
bl.printStackTrace();
}
// set up this guy's own undo manager
-// code.undo = new UndoManager();
+ // code.undo = new UndoManager();
codeDoc.setDocument(document);
}
@@ -2003,12 +2101,12 @@ public void run() {
* Implements Sketch → Stop, or pressing Stop on the toolbar.
*/
private void handleStop() { // called by menu or buttons
-// toolbar.activate(EditorToolbar.STOP);
+ // toolbar.activate(EditorToolbar.STOP);
internalCloseRunner();
toolbar.deactivateRun();
-// toolbar.deactivate(EditorToolbar.STOP);
+ // toolbar.deactivate(EditorToolbar.STOP);
// focus the PDE again after quitting presentation mode [toxi 030903]
toFront();
@@ -2299,6 +2397,8 @@ public boolean handleSaveAs() {
// the Save As method of the Sketch object, since that's the
// only one who knows whether something was renamed.
//sketchbook.rebuildMenusAsync();
+ dirToGit = sketch.getData().getDataFolder().getParentFile();
+ git.gitInit(dirToGit);
} else {
statusNotice(tr("Save Canceled."));
return false;
@@ -2794,10 +2894,10 @@ public void statusError(String what) {
*/
public void statusError(Exception e) {
e.printStackTrace();
-// if (e == null) {
-// System.err.println("Editor.statusError() was passed a null exception.");
-// return;
-// }
+ // if (e == null) {
+ // System.err.println("Editor.statusError() was passed a null exception.");
+ // return;
+ // }
if (e instanceof RunnerException) {
RunnerException re = (RunnerException) e;
@@ -2843,7 +2943,7 @@ public void statusError(Exception e) {
}
statusError(mess);
}
-// e.printStackTrace();
+ // e.printStackTrace();
}
diff --git a/app/src/processing/app/GitManager.java b/app/src/processing/app/GitManager.java
new file mode 100644
index 00000000000..80eabfb90d9
--- /dev/null
+++ b/app/src/processing/app/GitManager.java
@@ -0,0 +1,78 @@
+package processing.app;
+
+/**
+ * Created by carlos on 1/04/16.
+ */
+
+import java.io.IOException;
+import java.io.File;
+import org.eclipse.jgit.api.*;
+import org.eclipse.jgit.api.errors.*;
+import org.eclipse.jgit.revwalk.*;
+
+
+public class GitManager {
+ private Git git;
+
+ public String gitInit(File dirUrl)
+ {
+
+ try {
+ System.out.println(dirUrl.getAbsolutePath());
+ git = Git.init().setDirectory( dirUrl ).call();
+
+ } catch (Exception e) {
+ return "Something went wrong, check if you have git already installed ";
+ }
+
+ return "Git initialized successfully";
+
+ }
+
+ private boolean gitStage(File[] FilesToStage)
+ {
+ for(File f : FilesToStage)
+ {
+ try {
+ git.add().addFilepattern(f.getName()).call();
+ }catch(Exception e){
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ public String gitCommit(String coment, File[] fileToCommit)
+ {
+
+ if(gitStage(fileToCommit))
+ {
+ try{
+ git.commit().setMessage( coment ).call();
+ }catch(Exception e)
+ {
+ return "There was a problem while committing the files";
+ }
+ return "File Committed successfully";
+ }
+ else
+ {
+ return "There was a problem while staging the files";
+ }
+ }
+
+ public Iterable gitLog()
+ {
+ Iterable iterable = null;
+ try {
+
+ iterable = git.log().call();
+
+ }catch(GitAPIException ex)
+ { }
+
+ return iterable;
+ }
+
+}
diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java
index ecbd54938a6..72187790762 100644
--- a/app/src/processing/app/Sketch.java
+++ b/app/src/processing/app/Sketch.java
@@ -745,6 +745,7 @@ protected boolean saveAs() throws IOException {
// Make sure that it's not an untitled sketch
setUntitled(false);
+
// let Editor know that the save was successful
return true;
}
@@ -1415,5 +1416,7 @@ private static String checkName(String origName) {
return newName;
}
-
+ public SketchData getData() {
+ return data;
+ }
}
diff --git a/app/test/processing/app/GitTest.java b/app/test/processing/app/GitTest.java
new file mode 100644
index 00000000000..ee5a82bcb50
--- /dev/null
+++ b/app/test/processing/app/GitTest.java
@@ -0,0 +1,7 @@
+package processing.app;
+
+/**
+ * Created by carlos on 1/04/16.
+ */
+public class GitTest {
+}