-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathChangeScanner.java
More file actions
60 lines (48 loc) · 2.2 KB
/
ChangeScanner.java
File metadata and controls
60 lines (48 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.jabref.gui.collab;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChangeScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(ChangeScanner.class);
private final BibDatabaseContext database;
private final GuiPreferences preferences;
private final DatabaseChangeResolverFactory databaseChangeResolverFactory;
public ChangeScanner(BibDatabaseContext database,
DialogService dialogService,
GuiPreferences preferences,
StateManager stateManager) {
this.database = database;
this.preferences = preferences;
this.databaseChangeResolverFactory = new DatabaseChangeResolverFactory(dialogService, database, preferences, stateManager);
}
public List<DatabaseChange> scanForChanges() {
if (database.getDatabasePath().isEmpty()) {
return List.of();
}
try {
return scanForChanges(database.getDatabasePath().get());
} catch (IOException e) {
LOGGER.warn("Error while parsing changed file.", e);
return List.of();
}
}
public List<DatabaseChange> scanForChanges(Path fileToCompare) throws IOException {
ImportFormatPreferences importFormatPreferences = preferences.getImportFormatPreferences();
ParserResult result = OpenDatabase.loadDatabase(fileToCompare, importFormatPreferences, new DummyFileUpdateMonitor());
if (result.isInvalid() || result.isEmpty()) {
return List.of();
}
BibDatabaseContext databaseOnDisk = result.getDatabaseContext();
return DatabaseChangeList.compareAndGetChanges(database, databaseOnDisk, databaseChangeResolverFactory);
}
}