Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix **partial** 578 - Git integration #10422

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"java.configuration.updateBuildConfiguration": "automatic",
"java.format.settings.url": "/config/VSCode Code Style.xml",
"java.checkstyle.configuration": "${workspaceFolder}/config/checkstyle/checkstyle_reviewdog.xml",
"java.checkstyle.version": "10.3.4"
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ dependencies {
antlr4 'org.antlr:antlr4:4.13.1'
implementation 'org.antlr:antlr4-runtime:4.13.1'

implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.7.0.202309050840-r'
implementation(group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.7.0.202309050840-r')
implementation(group: 'org.eclipse.jgit', name: 'org.eclipse.jgit.ssh.apache', version: '6.7.0.202309050840-r')
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}

implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.15.2'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.15.2'
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@
requires org.antlr.antlr4.runtime;
requires org.libreoffice.uno;
requires de.saxsys.mvvmfx.validation;
requires org.eclipse.jgit.ssh.apache;
}
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) {
libraryTab.resetChangedProperties();
}
dialogService.notify(Localization.lang("Library saved"));

if (success) {
SaveGitDatabaseAction saveGit = new SaveGitDatabaseAction(targetPath);
saveGit.automaticUpdate();
}
return success;
} catch (SaveException ex) {
LOGGER.error(String.format("A problem occurred when trying to save the file %s", targetPath), ex);
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/jabref/gui/exporter/SaveGitDatabaseAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jabref.gui.exporter;

import java.io.IOException;
import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.logic.git.GitHandler;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SaveGitDatabaseAction {
static final Logger LOGGER = LoggerFactory.getLogger(GitHandler.class);
final Path filePath;
final String automaticCommitMsg = "Automatic update via JabRef";

public SaveGitDatabaseAction(Path filePath) {
this.filePath = filePath;
}

/**
* Handle JabRef git integration action
*
* @return true of false whether the action was successful or not
*/
public boolean automaticUpdate() {
try {
GitHandler git = new GitHandler(this.filePath.getParent());
git.createCommitWithSingleFileOnCurrentBranch(this.filePath.getFileName().toString(), automaticCommitMsg, false);
git.pushCommitsToRemoteRepository();
} catch (GitAPIException | IOException e) {
LOGGER.info("Failed to automatic git update");
}

return true;
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/jabref/gui/git/GitCredentials.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jabref.gui.git;

public class GitCredentials {
private String gitUsername;
private String gitPassword;

public GitCredentials() {
this.gitUsername = null;
this.gitPassword = null;
}

public GitCredentials(String gitUsername, String gitPassword) {
this.gitUsername = gitUsername;
this.gitPassword = gitPassword;
}

public void setGitUsername(String gitUsername) {
this.gitUsername = gitUsername;
}

public void setGitPassword(String gitPassword) {
this.gitPassword = gitPassword;
}

public String getGitPassword() {
return this.gitPassword;
}

public String getGitUsername() {
return this.gitUsername;
}
}
75 changes: 75 additions & 0 deletions src/main/java/org/jabref/gui/git/GitCredentialsDialogView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.jabref.gui.git;

import javafx.fxml.FXML;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.l10n.Localization;

import com.airhacks.afterburner.injection.Injector;

public class GitCredentialsDialogView extends BaseDialog<Void> {

@FXML private ButtonType copyVersionButton;
@FXML private TextArea textAreaVersions;
private DialogService dialogService;
private DialogPane pane;

private ButtonType acceptButton;
private ButtonType cancelButton;
private TextField inputGitUsername;
private PasswordField inputGitPassword;


public GitCredentialsDialogView() {
this.setTitle(Localization.lang("Git credentials"));
this.dialogService = Injector.instantiateModelOrService(DialogService.class);

this.pane = new DialogPane();
VBox vBox = new VBox();
this.inputGitUsername = new TextField();
this.inputGitPassword = new PasswordField();
this.acceptButton = new ButtonType(Localization.lang("Accept"), ButtonBar.ButtonData.APPLY);
this.cancelButton = new ButtonType(Localization.lang("Cancel"), ButtonBar.ButtonData.CANCEL_CLOSE);

vBox.getChildren().add(new Label(Localization.lang("Git username")));
vBox.getChildren().add(this.inputGitUsername);
vBox.getChildren().add(new Label(Localization.lang("Git password")));
vBox.getChildren().add(this.inputGitPassword);

this.pane.setContent(vBox);

}

public void showGitCredentialsDialog() {
dialogService.showCustomDialogAndWait(Localization.lang("Git credentials"), this.pane, this.acceptButton, this.cancelButton);
}

public GitCredentials getCredentials() {
dialogService.showCustomDialogAndWait(Localization.lang("Git credentials"), this.pane, this.acceptButton, this.cancelButton);
GitCredentials gitCredentials = new GitCredentials(this.inputGitUsername.getText(), this.inputGitPassword.getText());

return gitCredentials;
}

public String getGitPassword() {
return this.inputGitPassword.getText();
}

public String getGitUsername() {
return this.inputGitUsername.getText();
}

@FXML
private void initialize() {
this.setResizable(false);
}
}
51 changes: 51 additions & 0 deletions src/main/java/org/jabref/gui/git/GitPreferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jabref.gui.git;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class GitPreferences {
private StringProperty username;
private StringProperty password;

public GitPreferences(String username, String password) {
this.username = new SimpleStringProperty(username);
this.password = new SimpleStringProperty(password);
}

public GitPreferences(StringProperty username, StringProperty password) {
this.username = username;
this.password = password;
}

public StringProperty getUsernameProperty() {
return this.username;
}

public String getUsername() {
return this.username.get();
}

public StringProperty getPasswordProperty() {
return this.password;
}

public String getPassword() {
return this.password.get();
}

public void setPassword(StringProperty password) {
this.password = password;
}

public void setPassword(String password) {
this.password = new SimpleStringProperty(password);
}

public void setUsername(StringProperty username) {
this.username = username;
}

public void setUsername(String username) {
this.username = new SimpleStringProperty(username);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jabref.gui.preferences.external.ExternalTab;
import org.jabref.gui.preferences.externalfiletypes.ExternalFileTypesTab;
import org.jabref.gui.preferences.general.GeneralTab;
import org.jabref.gui.preferences.git.GitTab;
import org.jabref.gui.preferences.groups.GroupsTab;
import org.jabref.gui.preferences.journals.JournalAbbreviationsTab;
import org.jabref.gui.preferences.keybindings.KeyBindingsTab;
Expand Down Expand Up @@ -84,7 +85,8 @@ public PreferencesDialogViewModel(DialogService dialogService, PreferencesServic
new XmpPrivacyTab(),
new CustomImporterTab(),
new CustomExporterTab(),
new NetworkTab()
new NetworkTab(),
new GitTab()
);
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/jabref/gui/preferences/git/GitTab.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.PasswordField?>
<fx:root spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jabref.gui.preferences.git.GitTab">
<Label styleClass="titleHeader" text="%Git"/>
<Label styleClass="sectionHeader" text="%Credential"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<Label text="%Email"/>
<TextField fx:id="username" minWidth="150.0" HBox.hgrow="ALWAYS"/>
<Label text="%Password"/>
<PasswordField fx:id="password" minWidth="150.0" HBox.hgrow="ALWAYS"/>
</HBox>
</fx:root>
34 changes: 34 additions & 0 deletions src/main/java/org/jabref/gui/preferences/git/GitTab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.gui.preferences.git;

import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.logic.l10n.Localization;

import com.airhacks.afterburner.views.ViewLoader;

public class GitTab extends AbstractPreferenceTabView<GitTabViewModel> {

@FXML private TextField username;
@FXML private PasswordField password;

public GitTab() {
ViewLoader.view(this)
.root(this)
.load();
this.username.setText(preferencesService.getGitPreferences().getUsername());
this.password.setText(preferencesService.getGitPreferences().getPassword());
}

@Override
public String getTabName() {
return Localization.lang("Git");
}

@FXML
private void initialize() {
viewModel = new GitTabViewModel(preferencesService.getGitPreferences(), this.username, this.password);
}
}
58 changes: 58 additions & 0 deletions src/main/java/org/jabref/gui/preferences/git/GitTabViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.jabref.gui.preferences.git;

import java.util.List;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import org.jabref.gui.git.GitPreferences;
import org.jabref.gui.preferences.PreferenceTabViewModel;

public class GitTabViewModel implements PreferenceTabViewModel {

private StringProperty username = new SimpleStringProperty();
private StringProperty password = new SimpleStringProperty();
private GitPreferences gitPreferences;
@FXML private TextField usernameInputField;
@FXML private PasswordField passwordInputField;

public GitTabViewModel(GitPreferences gitPreferences, TextField usernameInputField, PasswordField passwordInputField) {
this.gitPreferences = gitPreferences;
this.usernameInputField = usernameInputField;
this.passwordInputField = passwordInputField;
}

@Override
public void setValues() {
// TEST
this.username.setValue(this.usernameInputField.getText());
this.password.setValue(this.passwordInputField.getText());
}

@Override
public void storeSettings() {
this.gitPreferences.setUsername(this.usernameInputField.getText());
this.gitPreferences.setPassword(this.passwordInputField.getText());
}

@Override
public boolean validateSettings() {
return PreferenceTabViewModel.super.validateSettings();
}

@Override
public List<String> getRestartWarnings() {
return PreferenceTabViewModel.super.getRestartWarnings();
}

public StringProperty getUsername() {
return this.username;
}

public StringProperty getPassword() {
return this.password;
}
}
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/logic/git/GitCredential.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jabref.logic.git;

public class GitCredential {
private final String username;
private final String password;

public GitCredential(String username, String password) {
this.username = username;
this.password = password;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}
}
Loading
Loading