Skip to content

Commit 18a4c50

Browse files
committed
Move Git Object into ScriptingEngine for life-cycle
1 parent 80e7ae4 commit 18a4c50

File tree

5 files changed

+132
-139
lines changed

5 files changed

+132
-139
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudioMenu.java

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -662,89 +662,90 @@ public void handle(Event event) {
662662
orgCommits.setOnShowing(null);
663663
gistFlag = false;
664664
});
665-
Repository repo = null;
666-
Git git = null;
667665
try {
668666
ScriptingEngine.checkout(url, branchName);
669667

670-
git = ScriptingEngine.openGit(url);
671-
repo = git.getRepository();
672-
// com.neuronrobotics.sdk.common.Log.error("Commits of branch: " + branchName);
673-
// com.neuronrobotics.sdk.common.Log.error("-------------------------------------");
668+
ScriptingEngine.openGit(url,git->{
669+
Repository repo = git.getRepository();
670+
// com.neuronrobotics.sdk.common.Log.error("Commits of branch: " + branchName);
671+
// com.neuronrobotics.sdk.common.Log.error("-------------------------------------");
674672

675-
ObjectId resolve = repo.resolve(branchName);
676-
if (resolve != null) {
677-
Iterable<RevCommit> commits = git.log().add(resolve).call();
673+
ObjectId resolve = repo.resolve(branchName);
674+
if (resolve != null) {
675+
Iterable<RevCommit> commits = git.log().add(resolve).call();
678676

679-
List<RevCommit> commitsList = Lists.newArrayList(commits.iterator());
680-
BowlerStudio.runLater(() -> {
681-
try {
682-
orgCommits.getItems()
683-
.add(new MenuItem("On Branch " + ScriptingEngine.getBranch(url)));
684-
} catch (Exception e) {
685-
exp.uncaughtException(Thread.currentThread(), e);
686-
}
687-
orgCommits.getItems().add(new SeparatorMenuItem());
688-
});
689-
// RevCommit previous = null;
690-
for (RevCommit commit : commitsList) {
691-
String date = format.format(new Date(commit.getCommitTime() * 1000L));
692-
String fullData = commit.getName() + "\r\n" + commit.getAuthorIdent().getName() + "\r\n"
693-
+ date + "\r\n" + commit.getFullMessage() + "\r\n"
694-
+ "---------------------------------------------------\r\n";// +
695-
// previous==null?"":getDiffOfCommit(previous,commit, repo, git);
696-
697-
// previous = commit;
698-
String string = date + " " + commit.getAuthorIdent().getName() + " "
699-
+ commit.getShortMessage();
700-
if (string.length() > 80)
701-
string = string.substring(0, 80);
702-
// MenuItem tmp = new MenuItem(string);
703-
CustomMenuItem tmp = new CustomMenuItem(new Label(string));
704-
Tooltip tooltip = new Tooltip(fullData);
705-
Tooltip.install(tmp.getContent(), tooltip);
706-
tmp.setOnAction(ev -> {
707-
new Thread() {
708-
public void run() {
709-
com.neuronrobotics.sdk.common.Log.error("Selecting \r\n\r\n" + fullData);
710-
711-
String branch;
712-
try {
713-
branch = ScriptingEngine.getBranch(url);
714-
} catch (Exception e1) {
715-
branch = "newBranch";
716-
}
717-
718-
String dateString = formatSimple
719-
.format(new Date(commit.getCommitTime() * 1000L));
720-
promptForNewBranch(branch + "-" + dateString,
721-
"Creating Branch From Commit:\n\n" + fullData, newBranch -> {
722-
new Thread() {
723-
public void run() {
724-
try {
725-
String slugify = slugify(newBranch);
726-
com.neuronrobotics.sdk.common.Log
727-
.error("Creating " + slugify);
728-
ScriptingEngine.setCommitContentsAsCurrent(url,
729-
slugify, commit);
730-
} catch (IOException e) {
731-
exp.uncaughtException(Thread.currentThread(), e);
732-
} catch (GitAPIException e) {
733-
exp.uncaughtException(Thread.currentThread(), e);
677+
List<RevCommit> commitsList = Lists.newArrayList(commits.iterator());
678+
BowlerStudio.runLater(() -> {
679+
try {
680+
orgCommits.getItems()
681+
.add(new MenuItem("On Branch " + ScriptingEngine.getBranch(url)));
682+
} catch (Exception e) {
683+
exp.uncaughtException(Thread.currentThread(), e);
684+
}
685+
orgCommits.getItems().add(new SeparatorMenuItem());
686+
});
687+
// RevCommit previous = null;
688+
for (RevCommit commit : commitsList) {
689+
String date = format.format(new Date(commit.getCommitTime() * 1000L));
690+
String fullData = commit.getName() + "\r\n" + commit.getAuthorIdent().getName() + "\r\n"
691+
+ date + "\r\n" + commit.getFullMessage() + "\r\n"
692+
+ "---------------------------------------------------\r\n";// +
693+
// previous==null?"":getDiffOfCommit(previous,commit, repo, git);
694+
695+
// previous = commit;
696+
String string = date + " " + commit.getAuthorIdent().getName() + " "
697+
+ commit.getShortMessage();
698+
if (string.length() > 80)
699+
string = string.substring(0, 80);
700+
// MenuItem tmp = new MenuItem(string);
701+
CustomMenuItem tmp = new CustomMenuItem(new Label(string));
702+
Tooltip tooltip = new Tooltip(fullData);
703+
Tooltip.install(tmp.getContent(), tooltip);
704+
tmp.setOnAction(ev -> {
705+
new Thread() {
706+
public void run() {
707+
com.neuronrobotics.sdk.common.Log.error("Selecting \r\n\r\n" + fullData);
708+
709+
String branch;
710+
try {
711+
branch = ScriptingEngine.getBranch(url);
712+
} catch (Exception e1) {
713+
branch = "newBranch";
714+
}
715+
716+
String dateString = formatSimple
717+
.format(new Date(commit.getCommitTime() * 1000L));
718+
promptForNewBranch(branch + "-" + dateString,
719+
"Creating Branch From Commit:\n\n" + fullData, newBranch -> {
720+
new Thread() {
721+
public void run() {
722+
try {
723+
String slugify = slugify(newBranch);
724+
com.neuronrobotics.sdk.common.Log
725+
.error("Creating " + slugify);
726+
ScriptingEngine.setCommitContentsAsCurrent(url,
727+
slugify, commit);
728+
} catch (IOException e) {
729+
exp.uncaughtException(Thread.currentThread(), e);
730+
} catch (GitAPIException e) {
731+
exp.uncaughtException(Thread.currentThread(), e);
732+
}
734733
}
735-
}
736-
}.start();
737-
});
734+
}.start();
735+
});
738736

739-
}
740-
}.start();
737+
}
738+
}.start();
741739

742-
});
743-
BowlerStudio.runLater(() -> {
744-
orgCommits.getItems().add(tmp);
745-
});
740+
});
741+
BowlerStudio.runLater(() -> {
742+
orgCommits.getItems().add(tmp);
743+
});
744+
}
746745
}
747-
}
746+
});
747+
748+
748749

749750
BowlerStudio.runLater(() -> {
750751
orgCommits.hide();
@@ -763,7 +764,6 @@ public void run() {
763764
} catch (Throwable e) {
764765
exp.uncaughtException(Thread.currentThread(), e);
765766
}
766-
ScriptingEngine.closeGit(git);
767767
}).start();
768768
}
769769
};

src/main/java/com/neuronrobotics/bowlerstudio/scripting/ScriptingFileWidget.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -695,34 +695,33 @@ private void setUpFile(File f) {
695695
// }
696696
langaugeType = ScriptingEngine.getLangaugesMap().get(langType);
697697
// ScriptingEngine.setLastFile(f);
698-
Git git = null;
698+
699699
try {
700-
git = ScriptingEngine.locateGit(currentFile);
701-
remote = git.getRepository().getConfig().getString("remote", "origin", "url");
702-
String findLocalPath = ScriptingEngine.findLocalPath(f, git);
703-
ScriptingEngine.closeGit(git);
704-
BowlerStudio.runLater(() -> {
705-
// fileListBox.setMinWidth(remote.getBytes().length*10);
706-
fileListBox.setText(remote);
707-
fileListBox.setTooltip(new Tooltip(remote));
708-
// fileListBox.res
700+
ScriptingEngine.locateGit(currentFile,git->{
701+
remote = git.getRepository().getConfig().getString("remote", "origin", "url");
702+
String findLocalPath = ScriptingEngine.findLocalPath(f, git);
703+
BowlerStudio.runLater(() -> {
704+
// fileListBox.setMinWidth(remote.getBytes().length*10);
705+
fileListBox.setText(remote);
706+
fileListBox.setTooltip(new Tooltip(remote));
707+
// fileListBox.res
709708

710-
fileNameBox.setText(findLocalPath);
711-
fileNameBox.setTooltip(new Tooltip(findLocalPath));
712-
// These values are display only, so if hte user tries to change them, they
713-
// reset
714-
// the use of text field for static dats is so the user cna copy the vlaues and
715-
// use them in their scritpts
716-
fileNameBox.textProperty().addListener((observable, oldValue, newValue) -> {
717709
fileNameBox.setText(findLocalPath);
710+
fileNameBox.setTooltip(new Tooltip(findLocalPath));
711+
// These values are display only, so if hte user tries to change them, they
712+
// reset
713+
// the use of text field for static dats is so the user cna copy the vlaues and
714+
// use them in their scritpts
715+
fileNameBox.textProperty().addListener((observable, oldValue, newValue) -> {
716+
fileNameBox.setText(findLocalPath);
717+
});
718+
fileListBox.textProperty().addListener((observable, oldValue, newValue) -> {
719+
fileListBox.setText(remote);
720+
});
718721
});
719-
fileListBox.textProperty().addListener((observable, oldValue, newValue) -> {
720-
fileListBox.setText(remote);
721-
});
722-
723722
});
723+
724724
} catch (Exception e1) {
725-
ScriptingEngine.closeGit(git);
726725
BowlerStudio.runLater(() -> {
727726
fileListBox.setText("none");
728727
fileListBox.setMinWidth(40);

src/main/java/com/neuronrobotics/bowlerstudio/scripting/external/EclipseExternalEditor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public abstract class EclipseExternalEditor implements IExternalEditor {
3838

3939
protected Button advanced;
40+
private File dir;
4041

4142
protected abstract void setUpEclipseProjectFiles(File dir, File project, String name)
4243
throws IOException, MalformedURLException;
@@ -82,10 +83,10 @@ public void launch(File file, Button advanced) {
8283
// String eclipseEXE = exeFile.getAbsolutePath();
8384

8485
try {
85-
Git locateGit = ScriptingEngine.locateGit(file);
86-
Repository repository = locateGit.getRepository();
87-
File dir = repository.getWorkTree();
88-
ScriptingEngine.closeGit(locateGit);
86+
ScriptingEngine.locateGit(file,git->{
87+
Repository repository = git.getRepository();
88+
dir = repository.getWorkTree();
89+
});
8990
String remoteURL = ScriptingEngine.locateGitUrlString(file);
9091
String branch = ScriptingEngine.getBranch(remoteURL);
9192

src/main/java/com/neuronrobotics/nrconsole/util/CommitWidget.java

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,61 +28,61 @@
2828
import javafx.util.Pair;
2929

3030
public class CommitWidget {
31-
public static void commit(File currentFile, String code){
32-
if(code!=null)
33-
if(code.length()<1){
31+
public static void commit(File currentFile, String code) {
32+
if (code != null)
33+
if (code.length() < 1) {
3434
Log.error("COmmit failed with no code to commit");
3535
return;
3636
}
37-
BowlerStudio.runLater(() ->{
37+
BowlerStudio.runLater(() -> {
3838
// Create the custom dialog.
3939
Dialog<Pair<String, String>> dialog = new Dialog<>();
4040
dialog.setTitle("Commit message Dialog");
4141
dialog.setHeaderText("Enter a commit message to publish changes");
42-
43-
42+
4443
// Set the button types.
4544
ButtonType loginButtonType = new ButtonType("Publish", ButtonData.OK_DONE);
4645
dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
47-
46+
4847
// Create the username and password labels and fields.
4948
GridPane grid = new GridPane();
5049
grid.setHgap(10);
5150
grid.setVgap(10);
5251
grid.setPadding(new Insets(20, 150, 10, 10));
53-
52+
5453
TextField username = new TextField();
5554
username.setPromptText("60 character description");
5655
TextArea password = new TextArea();
5756
password.setPrefRowCount(5);
5857
password.setPrefColumnCount(40);
5958
password.setPromptText("Full Sentences describing explanation");
60-
59+
6160
grid.add(new Label("What did you change?"), 0, 0);
6261
grid.add(username, 1, 0);
6362
grid.add(new Label("Why did you change it?"), 0, 1);
6463
grid.add(password, 1, 1);
65-
64+
6665
// Enable/Disable login button depending on whether a username was entered.
6766
Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
6867
loginButton.setDisable(true);
69-
68+
7069
// Do some validation (using the Java 8 lambda syntax).
7170
username.textProperty().addListener((observable, oldValue, newValue) -> {
72-
loginButton.setDisable(newValue.trim().length()<5);
71+
loginButton.setDisable(newValue.trim().length() < 5);
7372
});
74-
73+
7574
dialog.getDialogPane().setContent(grid);
76-
75+
7776
// Request focus on the username field by default.
7877
BowlerStudio.runLater(() -> username.requestFocus());
79-
80-
// Convert the result to a username-password-pair when the login button is clicked.
78+
79+
// Convert the result to a username-password-pair when the login button is
80+
// clicked.
8181
dialog.setResultConverter(dialogButton -> {
82-
if (dialogButton == loginButtonType) {
83-
return new Pair<>(username.getText(), password.getText());
84-
}
85-
return null;
82+
if (dialogButton == loginButtonType) {
83+
return new Pair<>(username.getText(), password.getText());
84+
}
85+
return null;
8686
});
8787
if (OSUtil.isOSX()) {
8888
Modality mode = Modality.NONE;
@@ -104,32 +104,25 @@ public static void commit(File currentFile, String code){
104104
Optional<Pair<String, String>> result = dialog.showAndWait();
105105
com.neuronrobotics.sdk.common.Log.error("Commit Dialog finished");
106106
dialog.close();
107-
com.neuronrobotics.sdk.common.Log.error("Result: "+result);
107+
com.neuronrobotics.sdk.common.Log.error("Result: " + result);
108108
result.ifPresent(commitBody -> {
109-
new Thread(){
110-
public void run(){
109+
new Thread() {
110+
public void run() {
111111
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
112-
113-
String message = commitBody.getKey()+"\n\n"+commitBody.getValue();
114-
115-
Git git=null;
112+
String message = commitBody.getKey() + "\n\n" + commitBody.getValue();
116113
try {
117-
git = ScriptingEngine.locateGit(currentFile);
118-
String remote= git.getRepository().getConfig().getString("remote", "origin", "url");
119-
String relativePath = ScriptingEngine.findLocalPath(currentFile,git);
120-
ScriptingEngine.closeGit(git);
114+
String remote = ScriptingEngine.locateGitUrl(currentFile);
115+
String relativePath = ScriptingEngine.findLocalPath(currentFile);
121116
ScriptingEngine.pull(remote);
122-
ScriptingEngine.pushCodeToGit(remote,ScriptingEngine.getFullBranch(remote), relativePath, code, message,true);
123-
117+
ScriptingEngine.pushCodeToGit(remote, ScriptingEngine.getFullBranch(remote), relativePath,
118+
code, message, true);
124119
} catch (Exception e1) {
125120
// Auto-generated catch block
126121
e1.printStackTrace();
127-
if(git!=null)
128-
ScriptingEngine.closeGit(git);
129122

130123
}
131-
}
132-
}.start();
124+
}
125+
}.start();
133126
});
134127
});
135128
}

0 commit comments

Comments
 (0)