Skip to content

Commit

Permalink
Merge pull request #9676 from JabRef/unify-paths
Browse files Browse the repository at this point in the history
Streamline AppDirs paths
  • Loading branch information
Siedlerchr authored Mar 18, 2023
2 parents 1bba627 + 2e807d7 commit b8497e9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- 'Get full text' now also checks the file url. [#568](https://github.com/koppor/jabref/issues/568)
- JabRef writes a new backup file only if there is a change. Before, JabRef created a backup upon start. [#9679](https://github.com/JabRef/jabref/pull/9679)
- We refined the 'main directory not found' error message. [#9625](https://github.com/JabRef/jabref/pull/9625)
- We streamlined the paths for logs and backups: The parent path fragement is always `logs` or `backups`.
- Backups of libraries are not stored per JabRef version, but collected together.
- We modified the `Add Group` dialog to use the most recently selected group hierarchical context [#9141](https://github.com/JabRef/jabref/issues/9141)
- We improved the Medline importer to correctly import ISO dates for `revised`. [#9536](https://github.com/JabRef/jabref/issues/9536)

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/jabref/cli/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.client.RemoteClient;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.OS;
import org.jabref.migrations.PreferencesMigrations;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
Expand Down Expand Up @@ -90,10 +91,12 @@ public static void main(String[] args) {
* the log configuration programmatically anymore.
*/
private static void addLogToDisk() {
Path directory = Path.of(AppDirsFactory.getInstance().getUserLogDir(
"jabref",
new BuildInfo().version.toString(),
"org.jabref"));
Path directory = Path.of(AppDirsFactory.getInstance()
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"logs",
OS.APP_DIR_APP_AUTHOR))
.resolve(new BuildInfo().version.toString());
try {
Files.createDirectories(directory);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public BackupResolverDialog(Path originalPath) {
getDialogPane().setMinHeight(180);
getDialogPane().getButtonTypes().setAll(RESTORE_FROM_BACKUP, REVIEW_BACKUP, IGNORE_BACKUP);

Optional<Path> backupPathOpt = BackupFileUtil.getPathOfLatestExisingBackupFile(originalPath, BackupFileType.BACKUP);
Optional<Path> backupPathOpt = BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP);
String backupFilename = backupPathOpt.map(Path::getFileName).map(Path::toString).orElse(Localization.lang("File not found"));
String content = new StringBuilder()
.append(Localization.lang("A backup file for '%0' was found at [%1]",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/dialogs/BackupUIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static Optional<ParserResult> showReviewBackupDialog(DialogService dialo
// This will be modified by using the `DatabaseChangesResolverDialog`.
BibDatabaseContext originalDatabase = originalParserResult.getDatabaseContext();

Path backupPath = BackupFileUtil.getPathOfLatestExisingBackupFile(originalPath, BackupFileType.BACKUP).orElseThrow();
Path backupPath = BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP).orElseThrow();
BibDatabaseContext backupDatabase = OpenDatabase.loadDatabase(backupPath, importFormatPreferences, new DummyFileUpdateMonitor()).getDatabaseContext();

DatabaseChangeResolverFactory changeResolverFactory = new DatabaseChangeResolverFactory(dialogService, originalDatabase, preferencesService.getBibEntryPreferences());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static Path getBackupPathForNewBackup(Path originalPath) {
* Determines the most recent existing backup file name
*/
static Optional<Path> getLatestBackupPath(Path originalPath) {
return BackupFileUtil.getPathOfLatestExisingBackupFile(originalPath, BackupFileType.BACKUP);
return BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/util/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class OS {
public static final String NEWLINE = System.lineSeparator();

public static final String APP_DIR_APP_NAME = "JabRef";
public static final String APP_DIR_APP_NAME = "jabref";
public static final String APP_DIR_APP_AUTHOR = "org.jabref";

// File separator obtained from system
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Optional;

import org.jabref.logic.util.BackupFileType;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.OS;

import net.harawata.appdirs.AppDirsFactory;
Expand All @@ -25,11 +24,11 @@ private BackupFileUtil() {
}

public static Path getAppDataBackupDir() {
Path directory = Path.of(AppDirsFactory.getInstance().getUserDataDir(
OS.APP_DIR_APP_NAME,
new BuildInfo().version.toString(),
OS.APP_DIR_APP_AUTHOR))
.resolve("backups");
Path directory = Path.of(AppDirsFactory.getInstance()
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"backups",
OS.APP_DIR_APP_AUTHOR));
return directory;
}

Expand Down Expand Up @@ -72,7 +71,7 @@ public static Path getPathForNewBackupFileAndCreateDirectory(Path targetFile, Ba
*
* @param targetFile the full path of the file to backup
*/
public static Optional<Path> getPathOfLatestExisingBackupFile(Path targetFile, BackupFileType fileType) {
public static Optional<Path> getPathOfLatestExistingBackupFile(Path targetFile, BackupFileType fileType) {
// The code is similar to "getPathForNewBackupFileAndCreateDirectory"

String extension = "." + fileType.getExtensions().get(0);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ private JabRefPreferences() {

// SSL
defaults.put(TRUSTSTORE_PATH, Path.of(AppDirsFactory.getInstance()
.getUserDataDir(OS.APP_DIR_APP_NAME, "ssl", OS.APP_DIR_APP_AUTHOR))
.getUserDataDir(
OS.APP_DIR_APP_NAME,
"ssl",
OS.APP_DIR_APP_AUTHOR))
.resolve("truststore.jks").toString());

defaults.put(POS_X, 0);
Expand Down

0 comments on commit b8497e9

Please sign in to comment.