Skip to content

Commit

Permalink
Move Git Object into ScriptingEngine for life-cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Harrington committed Jan 9, 2025
1 parent 80e7ae4 commit 18a4c50
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 139 deletions.
150 changes: 75 additions & 75 deletions src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudioMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,89 +662,90 @@ public void handle(Event event) {
orgCommits.setOnShowing(null);
gistFlag = false;
});
Repository repo = null;
Git git = null;
try {
ScriptingEngine.checkout(url, branchName);

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

ObjectId resolve = repo.resolve(branchName);
if (resolve != null) {
Iterable<RevCommit> commits = git.log().add(resolve).call();
ObjectId resolve = repo.resolve(branchName);
if (resolve != null) {
Iterable<RevCommit> commits = git.log().add(resolve).call();

List<RevCommit> commitsList = Lists.newArrayList(commits.iterator());
BowlerStudio.runLater(() -> {
try {
orgCommits.getItems()
.add(new MenuItem("On Branch " + ScriptingEngine.getBranch(url)));
} catch (Exception e) {
exp.uncaughtException(Thread.currentThread(), e);
}
orgCommits.getItems().add(new SeparatorMenuItem());
});
// RevCommit previous = null;
for (RevCommit commit : commitsList) {
String date = format.format(new Date(commit.getCommitTime() * 1000L));
String fullData = commit.getName() + "\r\n" + commit.getAuthorIdent().getName() + "\r\n"
+ date + "\r\n" + commit.getFullMessage() + "\r\n"
+ "---------------------------------------------------\r\n";// +
// previous==null?"":getDiffOfCommit(previous,commit, repo, git);

// previous = commit;
String string = date + " " + commit.getAuthorIdent().getName() + " "
+ commit.getShortMessage();
if (string.length() > 80)
string = string.substring(0, 80);
// MenuItem tmp = new MenuItem(string);
CustomMenuItem tmp = new CustomMenuItem(new Label(string));
Tooltip tooltip = new Tooltip(fullData);
Tooltip.install(tmp.getContent(), tooltip);
tmp.setOnAction(ev -> {
new Thread() {
public void run() {
com.neuronrobotics.sdk.common.Log.error("Selecting \r\n\r\n" + fullData);

String branch;
try {
branch = ScriptingEngine.getBranch(url);
} catch (Exception e1) {
branch = "newBranch";
}

String dateString = formatSimple
.format(new Date(commit.getCommitTime() * 1000L));
promptForNewBranch(branch + "-" + dateString,
"Creating Branch From Commit:\n\n" + fullData, newBranch -> {
new Thread() {
public void run() {
try {
String slugify = slugify(newBranch);
com.neuronrobotics.sdk.common.Log
.error("Creating " + slugify);
ScriptingEngine.setCommitContentsAsCurrent(url,
slugify, commit);
} catch (IOException e) {
exp.uncaughtException(Thread.currentThread(), e);
} catch (GitAPIException e) {
exp.uncaughtException(Thread.currentThread(), e);
List<RevCommit> commitsList = Lists.newArrayList(commits.iterator());
BowlerStudio.runLater(() -> {
try {
orgCommits.getItems()
.add(new MenuItem("On Branch " + ScriptingEngine.getBranch(url)));
} catch (Exception e) {
exp.uncaughtException(Thread.currentThread(), e);
}
orgCommits.getItems().add(new SeparatorMenuItem());
});
// RevCommit previous = null;
for (RevCommit commit : commitsList) {
String date = format.format(new Date(commit.getCommitTime() * 1000L));
String fullData = commit.getName() + "\r\n" + commit.getAuthorIdent().getName() + "\r\n"
+ date + "\r\n" + commit.getFullMessage() + "\r\n"
+ "---------------------------------------------------\r\n";// +
// previous==null?"":getDiffOfCommit(previous,commit, repo, git);

// previous = commit;
String string = date + " " + commit.getAuthorIdent().getName() + " "
+ commit.getShortMessage();
if (string.length() > 80)
string = string.substring(0, 80);
// MenuItem tmp = new MenuItem(string);
CustomMenuItem tmp = new CustomMenuItem(new Label(string));
Tooltip tooltip = new Tooltip(fullData);
Tooltip.install(tmp.getContent(), tooltip);
tmp.setOnAction(ev -> {
new Thread() {
public void run() {
com.neuronrobotics.sdk.common.Log.error("Selecting \r\n\r\n" + fullData);

String branch;
try {
branch = ScriptingEngine.getBranch(url);
} catch (Exception e1) {
branch = "newBranch";
}

String dateString = formatSimple
.format(new Date(commit.getCommitTime() * 1000L));
promptForNewBranch(branch + "-" + dateString,
"Creating Branch From Commit:\n\n" + fullData, newBranch -> {
new Thread() {
public void run() {
try {
String slugify = slugify(newBranch);
com.neuronrobotics.sdk.common.Log
.error("Creating " + slugify);
ScriptingEngine.setCommitContentsAsCurrent(url,
slugify, commit);
} catch (IOException e) {
exp.uncaughtException(Thread.currentThread(), e);
} catch (GitAPIException e) {
exp.uncaughtException(Thread.currentThread(), e);
}
}
}
}.start();
});
}.start();
});

}
}.start();
}
}.start();

});
BowlerStudio.runLater(() -> {
orgCommits.getItems().add(tmp);
});
});
BowlerStudio.runLater(() -> {
orgCommits.getItems().add(tmp);
});
}
}
}
});



BowlerStudio.runLater(() -> {
orgCommits.hide();
Expand All @@ -763,7 +764,6 @@ public void run() {
} catch (Throwable e) {
exp.uncaughtException(Thread.currentThread(), e);
}
ScriptingEngine.closeGit(git);
}).start();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,34 +695,33 @@ private void setUpFile(File f) {
// }
langaugeType = ScriptingEngine.getLangaugesMap().get(langType);
// ScriptingEngine.setLastFile(f);
Git git = null;

try {
git = ScriptingEngine.locateGit(currentFile);
remote = git.getRepository().getConfig().getString("remote", "origin", "url");
String findLocalPath = ScriptingEngine.findLocalPath(f, git);
ScriptingEngine.closeGit(git);
BowlerStudio.runLater(() -> {
// fileListBox.setMinWidth(remote.getBytes().length*10);
fileListBox.setText(remote);
fileListBox.setTooltip(new Tooltip(remote));
// fileListBox.res
ScriptingEngine.locateGit(currentFile,git->{
remote = git.getRepository().getConfig().getString("remote", "origin", "url");
String findLocalPath = ScriptingEngine.findLocalPath(f, git);
BowlerStudio.runLater(() -> {
// fileListBox.setMinWidth(remote.getBytes().length*10);
fileListBox.setText(remote);
fileListBox.setTooltip(new Tooltip(remote));
// fileListBox.res

fileNameBox.setText(findLocalPath);
fileNameBox.setTooltip(new Tooltip(findLocalPath));
// These values are display only, so if hte user tries to change them, they
// reset
// the use of text field for static dats is so the user cna copy the vlaues and
// use them in their scritpts
fileNameBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileNameBox.setText(findLocalPath);
fileNameBox.setTooltip(new Tooltip(findLocalPath));
// These values are display only, so if hte user tries to change them, they
// reset
// the use of text field for static dats is so the user cna copy the vlaues and
// use them in their scritpts
fileNameBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileNameBox.setText(findLocalPath);
});
fileListBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileListBox.setText(remote);
});
});
fileListBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileListBox.setText(remote);
});

});

} catch (Exception e1) {
ScriptingEngine.closeGit(git);
BowlerStudio.runLater(() -> {
fileListBox.setText("none");
fileListBox.setMinWidth(40);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public abstract class EclipseExternalEditor implements IExternalEditor {

protected Button advanced;
private File dir;

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

try {
Git locateGit = ScriptingEngine.locateGit(file);
Repository repository = locateGit.getRepository();
File dir = repository.getWorkTree();
ScriptingEngine.closeGit(locateGit);
ScriptingEngine.locateGit(file,git->{
Repository repository = git.getRepository();
dir = repository.getWorkTree();
});
String remoteURL = ScriptingEngine.locateGitUrlString(file);
String branch = ScriptingEngine.getBranch(remoteURL);

Expand Down
67 changes: 30 additions & 37 deletions src/main/java/com/neuronrobotics/nrconsole/util/CommitWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,61 +28,61 @@
import javafx.util.Pair;

public class CommitWidget {
public static void commit(File currentFile, String code){
if(code!=null)
if(code.length()<1){
public static void commit(File currentFile, String code) {
if (code != null)
if (code.length() < 1) {
Log.error("COmmit failed with no code to commit");
return;
}
BowlerStudio.runLater(() ->{
BowlerStudio.runLater(() -> {
// Create the custom dialog.
Dialog<Pair<String, String>> dialog = new Dialog<>();
dialog.setTitle("Commit message Dialog");
dialog.setHeaderText("Enter a commit message to publish changes");



// Set the button types.
ButtonType loginButtonType = new ButtonType("Publish", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

// Create the username and password labels and fields.
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));

TextField username = new TextField();
username.setPromptText("60 character description");
TextArea password = new TextArea();
password.setPrefRowCount(5);
password.setPrefColumnCount(40);
password.setPromptText("Full Sentences describing explanation");

grid.add(new Label("What did you change?"), 0, 0);
grid.add(username, 1, 0);
grid.add(new Label("Why did you change it?"), 0, 1);
grid.add(password, 1, 1);

// Enable/Disable login button depending on whether a username was entered.
Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
loginButton.setDisable(true);

// Do some validation (using the Java 8 lambda syntax).
username.textProperty().addListener((observable, oldValue, newValue) -> {
loginButton.setDisable(newValue.trim().length()<5);
loginButton.setDisable(newValue.trim().length() < 5);
});

dialog.getDialogPane().setContent(grid);

// Request focus on the username field by default.
BowlerStudio.runLater(() -> username.requestFocus());

// Convert the result to a username-password-pair when the login button is clicked.

// Convert the result to a username-password-pair when the login button is
// clicked.
dialog.setResultConverter(dialogButton -> {
if (dialogButton == loginButtonType) {
return new Pair<>(username.getText(), password.getText());
}
return null;
if (dialogButton == loginButtonType) {
return new Pair<>(username.getText(), password.getText());
}
return null;
});
if (OSUtil.isOSX()) {
Modality mode = Modality.NONE;
Expand All @@ -104,32 +104,25 @@ public static void commit(File currentFile, String code){
Optional<Pair<String, String>> result = dialog.showAndWait();
com.neuronrobotics.sdk.common.Log.error("Commit Dialog finished");
dialog.close();
com.neuronrobotics.sdk.common.Log.error("Result: "+result);
com.neuronrobotics.sdk.common.Log.error("Result: " + result);
result.ifPresent(commitBody -> {
new Thread(){
public void run(){
new Thread() {
public void run() {
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());

String message = commitBody.getKey()+"\n\n"+commitBody.getValue();

Git git=null;
String message = commitBody.getKey() + "\n\n" + commitBody.getValue();
try {
git = ScriptingEngine.locateGit(currentFile);
String remote= git.getRepository().getConfig().getString("remote", "origin", "url");
String relativePath = ScriptingEngine.findLocalPath(currentFile,git);
ScriptingEngine.closeGit(git);
String remote = ScriptingEngine.locateGitUrl(currentFile);
String relativePath = ScriptingEngine.findLocalPath(currentFile);
ScriptingEngine.pull(remote);
ScriptingEngine.pushCodeToGit(remote,ScriptingEngine.getFullBranch(remote), relativePath, code, message,true);
ScriptingEngine.pushCodeToGit(remote, ScriptingEngine.getFullBranch(remote), relativePath,
code, message, true);
} catch (Exception e1) {
// Auto-generated catch block
e1.printStackTrace();
if(git!=null)
ScriptingEngine.closeGit(git);

}
}
}.start();
}
}.start();
});
});
}
Expand Down

0 comments on commit 18a4c50

Please sign in to comment.