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

Git Integration and UI Improvements #12252

Open
wants to merge 93 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
094252c
l'ajout de la classe BackUpManagerJGit
nawalchahboune Oct 23, 2024
d0f6346
l'ajout de la classe BackUpManagerJGit
nawalchahboune Oct 23, 2024
7fd8f89
Merge remote-tracking branch 'origin/main'
nawalchahboune Oct 23, 2024
9ab37a2
l'ajout de la classe BackUpManagerJGit
nawalchahboune Oct 23, 2024
d8812ef
Add the class JGIT
Nov 6, 2024
af50c7c
first git implementation, not tested
Nov 6, 2024
e72d408
ajout de la methide backupGitDiffers
nawalchahboune Nov 6, 2024
d427e05
Added Pop up to choose backup
Nov 6, 2024
0737f48
adding methods 06/11
nawalchahboune Nov 6, 2024
f68236f
methods aded and changed : retrieveCommitDetails , retreiveCommits
nawalchahboune Nov 7, 2024
129d175
I start switching French comments to English
ilias-lwa3r Nov 11, 2024
b82682a
finish switching comments from French to English
ilias-lwa3r Nov 11, 2024
34a2889
Added table
Nov 12, 2024
b299e5f
Navigation through dialogs implemented
Nov 13, 2024
d2b3619
some modif
nawalchahboune Nov 19, 2024
d84fcab
some modif
nawalchahboune Nov 19, 2024
54fa60a
fix some issues
nawalchahboune Nov 19, 2024
9a8e615
adding date details
nawalchahboune Nov 19, 2024
62a8beb
Merge branch 'UI' into branch-1
Nov 19, 2024
df21a4d
Merge branch 'branch-1' of https://github.com/khola22/jabref into bra…
Nov 19, 2024
0f9fcb9
Revert "Merge branch 'branch-1' of https://github.com/khola22/jabref …
Nov 19, 2024
7b6ee3f
Reapply "Merge branch 'branch-1' of https://github.com/khola22/jabref…
Nov 19, 2024
b67b2d9
minor fixes
Nov 20, 2024
3f9584e
Minor Synthax fixes
Nov 20, 2024
76b6f92
supression de classe BackupManagerJGit
nawalchahboune Nov 20, 2024
fc94296
differenciation BackupManagerOld et BackupManager
nawalchahboune Nov 20, 2024
d6df47a
Corrected errors related to BackupManagerGit class
Nov 26, 2024
9a07077
Start tests
Nov 26, 2024
9c86a64
OpenDatabaseAction adapted
Nov 27, 2024
fa42e86
Start adapting SaveDatabaseAction.java and LibraryTab.java
Nov 27, 2024
be482cd
Classes adapted, except for UI
Nov 27, 2024
2797c01
UI update
Nov 27, 2024
27f7c47
Merge branch 'branch-1' of https://github.com/khola22/jabref into bra…
Nov 27, 2024
d070e67
Starting tests
Nov 27, 2024
528fe03
Starting tests
Nov 27, 2024
d40eadd
Merge remote-tracking branch 'origin/branch-1' into branch-1
Nov 27, 2024
11f65c7
first tests that are working
Nov 27, 2024
8ebb62a
All the tests for BackupManagerGit + Launcher working
Nov 28, 2024
562b285
Add some LOGGERS to BackupManagerGit.java
Nov 28, 2024
a2fa8b0
Adapted UI to BackupManagerGit for ChoiceDialog
Nov 29, 2024
1ad47a3
Adapted BackupUIManager to BackupManagerGit
Nov 29, 2024
a580032
Adapted Tests to UI adaptation
Nov 30, 2024
9a1c3a1
Added getter for name attribute of BackupEntry
Nov 30, 2024
1013c3c
Revert "Added getter for name attribute of BackupEntry"
Nov 30, 2024
4daf772
Final fix
Nov 30, 2024
ecad580
fixed the issue with detecting changes
Nov 30, 2024
c356375
Merge remote-tracking branch 'origin/branch-1' into branch-1
Nov 30, 2024
5d22a1a
editing the testRerieveCommitDetails test
nawalchahboune Nov 30, 2024
ae8583a
Fix the shutdown / usage of old BackupManager
Nov 30, 2024
44f4e17
correct path
Nov 30, 2024
19b0ef5
attempt to remove useless original path in some methods
nawalchahboune Dec 1, 2024
7f89d89
CORRECTING PATHS ! a clean launch (except for the 1st exception)
Dec 1, 2024
850e681
Merge remote-tracking branch 'origin/branch-1' into branch-1
Dec 1, 2024
119e5d0
Fixed the dialog of the 1st exception)
Dec 1, 2024
a7d271b
Fixed the infinite loops of commits
Dec 1, 2024
96c3239
Reversed backup list
Dec 1, 2024
5d0afe6
no more NULL for git initialization
Dec 1, 2024
7a48131
resolving prblm
nawalchahboune Dec 1, 2024
47d5238
Copying files to the backupdir logic
Dec 1, 2024
e881ce4
Add listeners
Dec 1, 2024
02fa1d1
Listeners detect changes but don't set needsBackup to true (I don't k…
Dec 1, 2024
c219a98
correct comment
Dec 2, 2024
5ae7407
Resolve the comment : Remove this here, we already have a newer versi…
Dec 2, 2024
ebe6f6b
Resolve the comment : delete this file (module-info.java), it's not n…
Dec 2, 2024
b0cc7f7
Adding BackupManagerGitTest class (with 5/5 passed tests)
nawalchahboune Dec 3, 2024
7085fc4
- Implement the unique file names in order to avoid conflicts when co…
Dec 4, 2024
3532d2e
The popup is available again
Dec 4, 2024
08b3c0c
Restore backup that functions
Dec 4, 2024
2c6da4b
Corrected retrieve commits / commits details
Dec 4, 2024
bca3558
Updated submodule abbrv.jabref.org
Dec 4, 2024
7e63aa2
Updated submodule csl-styles to latest commit
Dec 4, 2024
97caf34
Added support to review each change in a backup
Gillan0 Dec 4, 2024
b1c006e
Remove usage of BackupFileUtil in UI
Gillan0 Dec 4, 2024
aac4915
BackupResolverDialog.java doesn't use the old backup system anymore.
Dec 4, 2024
a292db3
change in CHANGELOG.md
Dec 5, 2024
7ae97d1
Updated submodule csl-locales to latest commit
Dec 5, 2024
5bbefcf
Merge branch 'main' into branch-1
khola22 Dec 5, 2024
70b123b
Update CHANGELOG.md
khola22 Dec 5, 2024
69ad0f3
CHANGELOG.md changes
Dec 5, 2024
a577ad9
Resolve comment on LibraryTab.java and BackupManagerGit.java
Dec 5, 2024
e55a831
Resolve comment on LibraryTab.java and BackupManagerGit.java
Dec 5, 2024
cf23e68
Resolve comment on BackupUIManager.java
Dec 5, 2024
61a1987
checkstyle
Dec 5, 2024
b515e51
Working Tests
Dec 5, 2024
8f06c80
Add missing submodule configuration
Dec 5, 2024
d3b6dd3
Apply OpenRewrite recipes
Dec 5, 2024
2a05da5
Correct Unit Tests
Dec 5, 2024
dbe6f2b
Added new UI text to JabRef_en.properties
Gillan0 Dec 6, 2024
3d13e22
Merge branch 'fix-localization-issues' into branch-1
Dec 6, 2024
e065399
Resolve comment on BackupManagerGitTest.java and
nawalchahboune Dec 7, 2024
01478c7
Resolve comments on insatantiation within mock
nawalchahboune Dec 13, 2024
e4ad25c
Merge branch 'main' into branch-1
khola22 Dec 13, 2024
da79d5d
Resolve comment about BackupUIManager.java
Dec 13, 2024
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jacoco {
dependencies {
// Include all jar-files in the 'lib' folder as dependencies
implementation fileTree(dir: 'lib', includes: ['*.jar'])

implementation 'org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r'
khola22 marked this conversation as resolved.
Show resolved Hide resolved
def pdfbox = "3.0.3"
implementation ("org.apache.pdfbox:pdfbox:$pdfbox") {
exclude group: 'commons-logging'
Expand Down
1 change: 1 addition & 0 deletions jabref
Submodule jabref added at 470597
8 changes: 8 additions & 0 deletions src/jmh/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
*
*/
/**
*
*/
module JabRef {
khola22 marked this conversation as resolved.
Show resolved Hide resolved
}
29 changes: 19 additions & 10 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.autosaveandbackup.AutosaveManager;
import org.jabref.gui.autosaveandbackup.BackupManager;
import org.jabref.gui.autosaveandbackup.BackupManagerGit;
import org.jabref.gui.collab.DatabaseChangeMonitor;
import org.jabref.gui.dialogs.AutosaveUiManager;
import org.jabref.gui.entryeditor.EntryEditor;
Expand Down Expand Up @@ -105,6 +105,7 @@
import com.tobiasdiez.easybind.Subscription;
import org.controlsfx.control.NotificationPane;
import org.controlsfx.control.action.Action;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -308,7 +309,7 @@ private void onDatabaseLoadingStarted() {
getMainTable().placeholderProperty().setValue(loadingLayout);
}

private void onDatabaseLoadingSucceed(ParserResult result) {
private void onDatabaseLoadingSucceed(ParserResult result) throws GitAPIException, IOException {
OpenDatabaseAction.performPostOpenActions(result, dialogService, preferences);
if (result.getChangedOnMigration()) {
this.markBaseChanged();
Expand Down Expand Up @@ -343,7 +344,7 @@ private void onDatabaseLoadingFailed(Exception ex) {
dialogService.showErrorDialogAndWait(title, content, ex);
}

private void setDatabaseContext(BibDatabaseContext bibDatabaseContext) {
private void setDatabaseContext(BibDatabaseContext bibDatabaseContext) throws GitAPIException, IOException {
TabPane tabPane = this.getTabPane();
if (tabPane == null) {
LOGGER.debug("User interrupted loading. Not showing any library.");
Expand All @@ -367,13 +368,13 @@ private void setDatabaseContext(BibDatabaseContext bibDatabaseContext) {
installAutosaveManagerAndBackupManager();
}

public void installAutosaveManagerAndBackupManager() {
public void installAutosaveManagerAndBackupManager() throws GitAPIException, IOException {
if (isDatabaseReadyForAutoSave(bibDatabaseContext)) {
AutosaveManager autosaveManager = AutosaveManager.start(bibDatabaseContext);
autosaveManager.registerListener(new AutosaveUiManager(this, dialogService, preferences, entryTypesManager));
}
if (isDatabaseReadyForBackup(bibDatabaseContext) && preferences.getFilePreferences().shouldCreateBackup()) {
BackupManager.start(this, bibDatabaseContext, Injector.instantiateModelOrService(BibEntryTypesManager.class), preferences);
BackupManagerGit.start(this, bibDatabaseContext, Injector.instantiateModelOrService(BibEntryTypesManager.class), preferences);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entryTypesManager is available as visible above. No need to inject.

}
}

Expand Down Expand Up @@ -753,7 +754,7 @@ private boolean confirmClose() {
}

if (buttonType.equals(discardChanges)) {
BackupManager.discardBackup(bibDatabaseContext, preferences.getFilePreferences().getBackupDirectory());
LOGGER.debug("Discarding changes");
return true;
}

Expand Down Expand Up @@ -801,9 +802,9 @@ private void onClosed(Event event) {
LOGGER.error("Problem when shutting down autosave manager", e);
}
try {
BackupManager.shutdown(bibDatabaseContext,
preferences.getFilePreferences().getBackupDirectory(),
preferences.getFilePreferences().shouldCreateBackup());
BackupManagerGit.shutdown(bibDatabaseContext,
preferences.getFilePreferences().shouldCreateBackup(),
preferences.getFilePreferences().getBackupDirectory());
} catch (RuntimeException e) {
LOGGER.error("Problem when shutting down backup manager", e);
}
Expand Down Expand Up @@ -1082,7 +1083,15 @@ public static LibraryTab createLibraryTab(BackgroundTask<ParserResult> dataLoadi

newTab.setDataLoadingTask(dataLoadingTask);
dataLoadingTask.onRunning(newTab::onDatabaseLoadingStarted)
.onSuccess(newTab::onDatabaseLoadingSucceed)
.onSuccess(result -> {
try {
newTab.onDatabaseLoadingSucceed(result);
} catch (Exception e) {
// We need to handle the exception.
// Handle the exception, e.g., log it or show an error dialog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

LOGGER.error("An error occurred while loading the database", e);
}
})
.onFailure(newTab::onDatabaseLoadingFailed)
.executeWith(taskExecutor);

Expand Down
42 changes: 27 additions & 15 deletions src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.jabref.model.metadata.SaveOrder;
import org.jabref.model.metadata.SelfContainedSaveOrder;

import com.google.common.eventbus.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -51,6 +50,7 @@
* rejects all redundant backup tasks. This class does not manage the .bak file which is created when opening a
* database.
*/

public class BackupManager {

private static final Logger LOGGER = LoggerFactory.getLogger(BackupManager.class);
Expand Down Expand Up @@ -107,10 +107,10 @@ static Optional<Path> getLatestBackupPath(Path originalPath, Path backupDir) {
* @param bibDatabaseContext Associated {@link BibDatabaseContext}
*/
public static BackupManager start(LibraryTab libraryTab, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager, CliPreferences preferences) {
BackupManager backupManager = new BackupManager(libraryTab, bibDatabaseContext, entryTypesManager, preferences);
backupManager.startBackupTask(preferences.getFilePreferences().getBackupDirectory());
runningInstances.add(backupManager);
return backupManager;
BackupManager BackupManager = new BackupManager(libraryTab, bibDatabaseContext, entryTypesManager, preferences);
BackupManager.startBackupTask(preferences.getFilePreferences().getBackupDirectory());
runningInstances.add(BackupManager);
return BackupManager;
}

/**
Expand All @@ -119,7 +119,7 @@ public static BackupManager start(LibraryTab libraryTab, BibDatabaseContext bibD
* @param bibDatabaseContext Associated {@link BibDatabaseContext}
*/
public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path backupDir) {
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.discardBackup(backupDir));
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(BackupManager -> BackupManager.discardBackup(backupDir));
}

/**
Expand All @@ -130,7 +130,7 @@ public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path bac
* @param backupDir The path to the backup directory
*/
public static void shutdown(BibDatabaseContext bibDatabaseContext, Path backupDir, boolean createBackup) {
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(backupDir, createBackup));
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(BackupManager -> BackupManager.shutdown(backupDir, createBackup));
runningInstances.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext);
}

Expand Down Expand Up @@ -237,6 +237,9 @@ void performBackup(Path backupPath) {
}
}

// l'ordre dans lequel les entrées BibTeX doivent être écrites dans le fichier de sauvegarde.
// Si l'utilisateur a trié la table d'affichage des entrées dans JabRef, cet ordre est récupéré.
// Sinon, un ordre par défaut est utilisé.
// code similar to org.jabref.gui.exporter.SaveDatabaseAction.saveDatabase
SelfContainedSaveOrder saveOrder = bibDatabaseContext
.getMetaData().getSaveOrder()
Expand All @@ -256,20 +259,26 @@ void performBackup(Path backupPath) {
}
})
.orElse(SaveOrder.getDefaultSaveOrder());

// Elle configure la sauvegarde, en indiquant qu'aucune sauvegarde supplémentaire (backup) ne doit être créée,
// que l'ordre de sauvegarde doit être celui défini, et que les entrées doivent être formatées selon les préférences
// utilisateur.
SelfContainedSaveConfiguration saveConfiguration = (SelfContainedSaveConfiguration) new SelfContainedSaveConfiguration()
.withMakeBackup(false)
.withSaveOrder(saveOrder)
.withReformatOnSave(preferences.getLibraryPreferences().shouldAlwaysReformatOnSave());

// "Clone" the database context
// We "know" that "only" the BibEntries might be changed during writing (see [org.jabref.logic.exporter.BibDatabaseWriter.savePartOfDatabase])
// Chaque entrée BibTeX (comme un article, livre, etc.) est clonée en utilisant la méthode clone().
// Cela garantit que les modifications faites pendant la sauvegarde n'affecteront pas l'entrée originale.
List<BibEntry> list = bibDatabaseContext.getDatabase().getEntries().stream()
.map(BibEntry::clone)
.map(BibEntry.class::cast)
.toList();
BibDatabase bibDatabaseClone = new BibDatabase(list);
BibDatabaseContext bibDatabaseContextClone = new BibDatabaseContext(bibDatabaseClone, bibDatabaseContext.getMetaData());

// Elle définit l'encodage à utiliser pour écrire le fichier. Cela garantit que les caractères spéciaux sont bien sauvegardés.
Charset encoding = bibDatabaseContext.getMetaData().getEncoding().orElse(StandardCharsets.UTF_8);
// We want to have successful backups only
// Thus, we do not use a plain "FileWriter", but the "AtomicFileWriter"
Expand Down Expand Up @@ -327,23 +336,25 @@ private void logIfCritical(Path backupPath, IOException e) {
}
}

@Subscribe
public synchronized void listen(@SuppressWarnings("unused") BibDatabaseContextChangedEvent event) {
public synchronized void listen(BibDatabaseContextChangedEvent event) {
if (!event.isFilteredOut()) {
this.needsBackup = true;
}
}

private void startBackupTask(Path backupDir) {
fillQueue(backupDir);
// remplie backupFilesQueue les files .sav de le meme bibl

executor.scheduleAtFixedRate(
// We need to determine the backup path on each action, because we use the timestamp in the filename
() -> determineBackupPathForNewBackup(backupDir).ifPresent(path -> this.performBackup(path)),
DELAY_BETWEEN_BACKUP_ATTEMPTS_IN_SECONDS,
DELAY_BETWEEN_BACKUP_ATTEMPTS_IN_SECONDS,
TimeUnit.SECONDS);
// We need to determine the backup path on each action, because we use the timestamp in the filename
() -> determineBackupPathForNewBackup(backupDir).ifPresent(path -> this.performBackup(path)),
DELAY_BETWEEN_BACKUP_ATTEMPTS_IN_SECONDS,
DELAY_BETWEEN_BACKUP_ATTEMPTS_IN_SECONDS,
TimeUnit.SECONDS);
}
// La méthode fillQueue(backupDir) est définie dans le code et son rôle est de lister et d'ajouter
// les fichiers de sauvegarde existants dans une file d'attente,

private void fillQueue(Path backupDir) {
if (!Files.exists(backupDir)) {
Expand All @@ -356,6 +367,7 @@ private void fillQueue(Path backupDir) {
List<Path> allSavFiles = Files.list(backupDir)
// just list the .sav belonging to the given targetFile
.filter(p -> p.getFileName().toString().startsWith(prefix))
// tous les files .sav commencerait par ce prefix
.sorted().toList();
backupFilesQueue.addAll(allSavFiles);
} catch (IOException e) {
Expand Down
Loading