From 79e5106d5b4026d88df64624139b0924823a4c6c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 30 Apr 2020 00:43:03 +0200 Subject: [PATCH 1/4] Fixes #6357: File directory Bug was introduced in https://github.com/JabRef/jabref/commit/1b03f039aa4abf0812a3a8ae0ba248c08fdb39a3. --- .../org/jabref/gui/actions/ActionHelper.java | 2 +- .../org/jabref/gui/desktop/JabRefDesktop.java | 15 +-- .../gui/fieldeditors/LinkedFileViewModel.java | 4 +- .../LinkedFilesEditDialogViewModel.java | 2 +- .../gui/preferences/FileTabViewModel.java | 6 +- .../jabref/logic/layout/format/FileLink.java | 3 +- .../layout/format/FileLinkPreferences.java | 11 +- .../logic/layout/format/WrapFileLinks.java | 3 +- .../model/database/BibDatabaseContext.java | 107 +++++++----------- .../org/jabref/model/entry/LinkedFile.java | 2 +- .../org/jabref/model/groups/TexGroup.java | 8 +- .../model/metadata/FilePreferences.java | 30 ++--- .../org/jabref/model/metadata/MetaData.java | 2 +- .../org/jabref/model/util/FileHelper.java | 66 +++-------- .../jabref/preferences/JabRefPreferences.java | 13 +-- .../org/jabref/logic/layout/LayoutTest.java | 4 +- .../layout/format/WrapFileLinksTest.java | 46 ++++---- .../jabref/model/BibDatabaseContextTest.java | 42 ------- .../database/BibDatabaseContextTest.java | 107 +++++++++++++----- 19 files changed, 197 insertions(+), 276 deletions(-) delete mode 100644 src/test/java/org/jabref/model/BibDatabaseContextTest.java diff --git a/src/main/java/org/jabref/gui/actions/ActionHelper.java b/src/main/java/org/jabref/gui/actions/ActionHelper.java index 06f294de5d2..186e3666a5f 100644 --- a/src/main/java/org/jabref/gui/actions/ActionHelper.java +++ b/src/main/java/org/jabref/gui/actions/ActionHelper.java @@ -47,7 +47,7 @@ public static BooleanExpression isFilePresentForSelectedEntry(StateManager state return Bindings.createBooleanBinding(() -> { List files = stateManager.getSelectedEntries().get(0).getFiles(); if ((files.size() > 0) && stateManager.getActiveDatabase().isPresent()) { - Optional filename = FileHelper.expandFilename( + Optional filename = FileHelper.find( stateManager.getActiveDatabase().get(), files.get(0).getLink(), preferencesService.getFilePreferences()); diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 59c0dc0611d..a0fbe80b055 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -55,12 +55,12 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, String Field field = initialField; if (StandardField.PS.equals(field) || StandardField.PDF.equals(field)) { // Find the default directory for this field type: - List dir = databaseContext.getFileDirectories(field, Globals.prefs.getFilePreferences()); + List directories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()); - Optional file = FileHelper.expandFilename(link, dir); + Optional file = FileHelper.find(link, directories); // Check that the file exists: - if (!file.isPresent() || !Files.exists(file.get())) { + if (file.isEmpty() || !Files.exists(file.get())) { throw new IOException("File not found (" + field + "): '" + link + "'."); } link = file.get().toAbsolutePath().toString(); @@ -126,21 +126,16 @@ public static boolean openExternalFileAnyFormat(final BibDatabaseContext databas return true; } - Optional file = FileHelper.expandFilename(databaseContext, link, Globals.prefs.getFilePreferences()); + Optional file = FileHelper.find(databaseContext, link, Globals.prefs.getFilePreferences()); if (file.isPresent() && Files.exists(file.get())) { // Open the file: String filePath = file.get().toString(); openExternalFilePlatformIndependent(type, filePath); - return true; } else { // No file matched the name, try to open it directly using the given app openExternalFilePlatformIndependent(type, link); - return true; } - } - - public static boolean openExternalFileAnyFormat(Path file, final BibDatabaseContext databaseContext, final Optional type) throws IOException { - return openExternalFileAnyFormat(databaseContext, file.toString(), type); + return true; } private static void openExternalFilePlatformIndependent(Optional fileType, String filePath) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 62994a86a20..d349f896ebf 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -101,7 +101,7 @@ public LinkedFileViewModel(LinkedFile linkedFile, if (linkedFile.isOnlineLink()) { return true; } else { - Optional path = FileHelper.expandFilename(databaseContext, link, filePreferences); + Optional path = FileHelper.find(databaseContext, link, filePreferences); return path.isPresent() && Files.exists(path.get()); } }, @@ -192,7 +192,7 @@ public void open() { public void openFolder() { try { if (!linkedFile.isOnlineLink()) { - Optional resolvedPath = FileHelper.expandFilename( + Optional resolvedPath = FileHelper.find( databaseContext, linkedFile.getLink(), filePreferences); diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 1d2f80b11ff..c3b8dcbd63e 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -70,7 +70,7 @@ private void setExternalFileTypeByExtension(String link) { public void openBrowseDialog() { String fileText = link.get(); - Optional file = FileHelper.expandFilename(database, fileText, preferences.getFilePreferences()); + Optional file = FileHelper.find(database, fileText, preferences.getFilePreferences()); Path workingDir = file.orElse(preferences.getWorkingDir()); String fileName = Paths.get(fileText).getFileName().toString(); diff --git a/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java index 2346dd22983..f9afdda963c 100644 --- a/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java @@ -19,8 +19,6 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.DirectoryDialogConfiguration; import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.metadata.FilePreferences; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.NewLineSeparator; @@ -87,7 +85,7 @@ public void setValues() { selectedNewLineSeparatorProperty.setValue(preferences.getNewLineSeparator()); alwaysReformatBibProperty.setValue(preferences.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT)); - mainFileDirProperty.setValue(preferences.getAsOptional(StandardField.FILE.getName() + FilePreferences.DIR_SUFFIX).orElse("")); + mainFileDirProperty.setValue(preferences.getAsOptional(JabRefPreferences.MAIN_FILE_DIRECTORY).orElse("")); useBibLocationAsPrimaryProperty.setValue(preferences.getBoolean(JabRefPreferences.BIB_LOC_AS_PRIMARY_DIR)); if (preferences.getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY)) { // Flipped around autolinkUseRegexProperty.setValue(true); @@ -118,7 +116,7 @@ public void storeSettings() { preferences.setNewLineSeparator(selectedNewLineSeparatorProperty.getValue()); preferences.putBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT, alwaysReformatBibProperty.getValue()); - preferences.put(StandardField.FILE.getName() + FilePreferences.DIR_SUFFIX, mainFileDirProperty.getValue()); + preferences.put(JabRefPreferences.MAIN_FILE_DIRECTORY, mainFileDirProperty.getValue()); preferences.putBoolean(JabRefPreferences.BIB_LOC_AS_PRIMARY_DIR, useBibLocationAsPrimaryProperty.getValue()); preferences.putBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY, autolinkUseRegexProperty.getValue()); preferences.putBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY, autolinkFileExactBibtexProperty.getValue()); diff --git a/src/main/java/org/jabref/logic/layout/format/FileLink.java b/src/main/java/org/jabref/logic/layout/format/FileLink.java index 28aadfaea8b..6045aca1cd0 100644 --- a/src/main/java/org/jabref/logic/layout/format/FileLink.java +++ b/src/main/java/org/jabref/logic/layout/format/FileLink.java @@ -1,6 +1,7 @@ package org.jabref.logic.layout.format; import java.nio.file.Paths; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -55,7 +56,7 @@ public String format(String field) { // ugly hack, the export routine has set a global variable before // starting the export, which contains the database's file directory: if (prefs.getFileDirForDatabase() == null) { - dirs = prefs.getGeneratedDirForDatabase(); + dirs = Collections.singletonList(prefs.getMainFileDirectory()); } else { dirs = prefs.getFileDirForDatabase(); } diff --git a/src/main/java/org/jabref/logic/layout/format/FileLinkPreferences.java b/src/main/java/org/jabref/logic/layout/format/FileLinkPreferences.java index a34e7a6298d..99000174a74 100644 --- a/src/main/java/org/jabref/logic/layout/format/FileLinkPreferences.java +++ b/src/main/java/org/jabref/logic/layout/format/FileLinkPreferences.java @@ -4,15 +4,16 @@ public class FileLinkPreferences { - private final List generatedDirForDatabase; + private final String mainFileDirectory; private final List fileDirForDatabase; - public FileLinkPreferences(List generatedDirForDatabase, List fileDirForDatabase) { - this.generatedDirForDatabase = generatedDirForDatabase; + + public FileLinkPreferences(String mainFileDirectory, List fileDirForDatabase) { + this.mainFileDirectory = mainFileDirectory; this.fileDirForDatabase = fileDirForDatabase; } - public List getGeneratedDirForDatabase() { - return generatedDirForDatabase; + public String getMainFileDirectory() { + return mainFileDirectory; } public List getFileDirForDatabase() { diff --git a/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java b/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java index d66e016e3a0..f59d65f3324 100644 --- a/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java +++ b/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java @@ -2,6 +2,7 @@ import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -201,7 +202,7 @@ public String format(String field) { // ugly hack, the export routine has set a global variable before // starting the export, which contains the database's file directory: if ((prefs.getFileDirForDatabase() == null) || prefs.getFileDirForDatabase().isEmpty()) { - dirs = prefs.getGeneratedDirForDatabase(); + dirs = Collections.singletonList(prefs.getMainFileDirectory()); } else { dirs = prefs.getFileDirForDatabase(); } diff --git a/src/main/java/org/jabref/model/database/BibDatabaseContext.java b/src/main/java/org/jabref/model/database/BibDatabaseContext.java index 8866cdbbd15..0d8da113042 100644 --- a/src/main/java/org/jabref/model/database/BibDatabaseContext.java +++ b/src/main/java/org/jabref/model/database/BibDatabaseContext.java @@ -1,6 +1,5 @@ package org.jabref.model.database; -import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -14,8 +13,6 @@ import org.jabref.model.database.shared.DatabaseLocation; import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.FilePreferences; import org.jabref.model.metadata.MetaData; @@ -107,63 +104,34 @@ public boolean isBiblatexMode() { return getMode() == BibDatabaseMode.BIBLATEX; } - public List getFileDirectoriesAsPaths(FilePreferences preferences) { - // Filter for empty string, as this would be expanded to the jar-directory with Paths.get() - return getFileDirectories(preferences).stream() - .filter(s -> !s.isEmpty()) - .map(Paths::get) - .map(Path::toAbsolutePath) - .map(Path::normalize) - .collect(Collectors.toList()); - } - /** - * @deprecated use {@link #getFileDirectoriesAsPaths(FilePreferences)} instead - */ - @Deprecated - public List getFileDirectories(FilePreferences preferences) { - return getFileDirectories(StandardField.FILE, preferences); - } - - /** - * Returns the first existing file directory from {@link #getFileDirectories(FilePreferences)} - * - * @param preferences The FilePreferences - * @return Optional of Path - */ - public Optional getFirstExistingFileDir(FilePreferences preferences) { - return getFileDirectoriesAsPaths(preferences).stream().filter(Files::exists).findFirst(); - } - - /** - * Look up the directories set up for the given field type for this database. If no directory is set up, return that - * defined in global preferences. There can be up to three directory definitions for these files: the database's - * metadata can specify a general directory and/or a user-specific directory or the preferences can specify one.

- * The settings are prioritized in the following order and the first defined setting is used: + * Look up the directories set up for this database. + * There can be up to three directory definitions for these files: the database's + * metadata can specify a general directory and/or a user-specific directory, or the preferences can specify one. + *

+ * The settings are prioritized in the following order, and the first defined setting is used: *

    - *
  1. metadata
  2. - *
  3. user-specific directory
  4. + *
  5. user-specific metadata directory
  6. + *
  7. general metadata directory
  8. *
  9. preferences directory
  10. *
  11. BIB file directory
  12. *
* - * @param field The field * @param preferences The fileDirectory preferences - * @return The default directory for this field type. */ - public List getFileDirectories(Field field, FilePreferences preferences) { - List fileDirs = new ArrayList<>(); + public List getFileDirectoriesAsPaths(FilePreferences preferences) { + List fileDirs = new ArrayList<>(); - // 1. metadata user-specific directory + // 1. Metadata user-specific directory metaData.getUserFileDirectory(preferences.getUser()) .ifPresent(userFileDirectory -> fileDirs.add(getFileDirectoryPath(userFileDirectory))); - // 2. metadata general directory + // 2. Metadata general directory metaData.getDefaultFileDirectory() .ifPresent(metaDataDirectory -> fileDirs.add(getFileDirectoryPath(metaDataDirectory))); - // 3. preferences directory - preferences.getFileDirectory(field).ifPresent(path -> fileDirs.add(path.toAbsolutePath().toString())); + // 3. Preferences directory + preferences.getFileDirectory().ifPresent(fileDirs::add); // 4. BIB file directory getDatabasePath().ifPresent(dbPath -> { @@ -173,38 +141,47 @@ public List getFileDirectories(Field field, FilePreferences preferences) parentPath = Paths.get(System.getProperty("user.dir")); } Objects.requireNonNull(parentPath, "BibTeX database parent path is null"); - String parentDir = parentPath.toAbsolutePath().toString(); + // Check if we should add it as primary file dir (first in the list) or not: if (preferences.isBibLocationAsPrimary()) { - fileDirs.add(0, parentDir); + fileDirs.add(0, parentPath); } else { - fileDirs.add(parentDir); + fileDirs.add(parentPath); } }); - return fileDirs; + return fileDirs.stream().map(Path::toAbsolutePath).collect(Collectors.toList()); + } + + /** + * Returns the first existing file directory from {@link #getFileDirectories(FilePreferences)} + * + * @param preferences The FilePreferences + * @return Optional of Path + */ + public Optional getFirstExistingFileDir(FilePreferences preferences) { + return getFileDirectoriesAsPaths(preferences).stream().filter(Files::exists).findFirst(); } - private String getFileDirectoryPath(String directoryName) { - String dir = directoryName; + /** + * @deprecated use {@link #getFileDirectoriesAsPaths(FilePreferences)} instead + */ + @Deprecated + public List getFileDirectories(FilePreferences preferences) { + return getFileDirectoriesAsPaths(preferences).stream() + .map(directory -> directory.toAbsolutePath().toString()) + .collect(Collectors.toList()); + } + + private Path getFileDirectoryPath(String directoryName) { + Path directory = Path.of(directoryName); // If this directory is relative, we try to interpret it as relative to // the file path of this BIB file: Optional databaseFile = getDatabasePath(); - if (!new File(dir).isAbsolute() && databaseFile.isPresent()) { - Path relDir; - if (".".equals(dir)) { - // if dir is only "current" directory, just use its parent (== real current directory) as path - relDir = databaseFile.get().getParent(); - } else { - relDir = databaseFile.get().getParent().resolve(dir); - } - // If this directory actually exists, it is very likely that the - // user wants us to use it: - if (Files.exists(relDir)) { - dir = relDir.toString(); - } + if (!directory.isAbsolute() && databaseFile.isPresent()) { + return databaseFile.get().getParent().resolve(directory).normalize(); } - return dir; + return directory; } public DatabaseSynchronizer getDBMSSynchronizer() { diff --git a/src/main/java/org/jabref/model/entry/LinkedFile.java b/src/main/java/org/jabref/model/entry/LinkedFile.java index dac550e9ded..f06343a6e7a 100644 --- a/src/main/java/org/jabref/model/entry/LinkedFile.java +++ b/src/main/java/org/jabref/model/entry/LinkedFile.java @@ -188,7 +188,7 @@ public Optional findIn(List directories) { return Optional.empty(); } } else { - return FileHelper.expandFilenameAsPath(link.get(), directories); + return FileHelper.find(link.get(), directories); } } catch (InvalidPathException ex) { return Optional.empty(); diff --git a/src/main/java/org/jabref/model/groups/TexGroup.java b/src/main/java/org/jabref/model/groups/TexGroup.java index 9e47568a9e7..883e1d2c48f 100644 --- a/src/main/java/org/jabref/model/groups/TexGroup.java +++ b/src/main/java/org/jabref/model/groups/TexGroup.java @@ -23,12 +23,12 @@ public class TexGroup extends AbstractGroup implements FileUpdateListener { private static final Logger LOGGER = LoggerFactory.getLogger(TexGroup.class); - private Path filePath; + private final Path filePath; private Set keysUsedInAux = null; private final FileUpdateMonitor fileMonitor; - private AuxParser auxParser; + private final AuxParser auxParser; private final MetaData metaData; - private String user; + private final String user; TexGroup(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData, String user) { super(name, context); @@ -126,7 +126,7 @@ private Path relativize(Path path) { private Path expandPath(Path path) { List fileDirectories = getFileDirectoriesAsPaths(); - return FileHelper.expandFilenameAsPath(path.toString(), fileDirectories).orElse(path); + return FileHelper.find(path.toString(), fileDirectories).orElse(path); } private List getFileDirectoriesAsPaths() { diff --git a/src/main/java/org/jabref/model/metadata/FilePreferences.java b/src/main/java/org/jabref/model/metadata/FilePreferences.java index 52ae33fc63d..efeff249e51 100644 --- a/src/main/java/org/jabref/model/metadata/FilePreferences.java +++ b/src/main/java/org/jabref/model/metadata/FilePreferences.java @@ -1,30 +1,26 @@ package org.jabref.model.metadata; -import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Map; import java.util.Optional; -import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.StandardField; +import org.jabref.model.strings.StringUtil; public class FilePreferences { - public static final String DIR_SUFFIX = "Directory"; private final String user; - private final Map fieldFileDirectories; + private final String mainFileDirectory; private final boolean bibLocationAsPrimary; private final String fileNamePattern; private final String fileDirPattern; public FilePreferences(String user, - Map fieldFileDirectories, + String mainFileDirectory, boolean bibLocationAsPrimary, String fileNamePattern, String fileDirPattern) { this.user = user; - this.fieldFileDirectories = fieldFileDirectories; + this.mainFileDirectory = mainFileDirectory; this.bibLocationAsPrimary = bibLocationAsPrimary; this.fileNamePattern = fileNamePattern; this.fileDirPattern = fileDirPattern; @@ -34,24 +30,14 @@ public String getUser() { return user; } - public Optional getFileDirectory(Field field) { - try { - String value = fieldFileDirectories.get(field); - // filter empty paths - if ((value != null) && !value.isEmpty()) { - Path path = Paths.get(value); - return Optional.of(path); - } - return Optional.empty(); - } catch (InvalidPathException ex) { + public Optional getFileDirectory() { + if (StringUtil.isBlank(mainFileDirectory)) { return Optional.empty(); + } else { + return Optional.of(Paths.get(mainFileDirectory)); } } - public Optional getFileDirectory() { - return getFileDirectory(StandardField.FILE); - } - public boolean isBibLocationAsPrimary() { return bibLocationAsPrimary; } diff --git a/src/main/java/org/jabref/model/metadata/MetaData.java b/src/main/java/org/jabref/model/metadata/MetaData.java index a62b70285f4..7a11ec1fe5b 100644 --- a/src/main/java/org/jabref/model/metadata/MetaData.java +++ b/src/main/java/org/jabref/model/metadata/MetaData.java @@ -33,7 +33,7 @@ public class MetaData { public static final String DATABASE_TYPE = "databaseType"; public static final String GROUPSTREE = "grouping"; public static final String GROUPSTREE_LEGACY = "groupstree"; - public static final String FILE_DIRECTORY = "file" + FilePreferences.DIR_SUFFIX; + public static final String FILE_DIRECTORY = "fileDirectory"; public static final String PROTECTED_FLAG_META = "protectedFlag"; public static final String SELECTOR_META_PREFIX = "selector_"; diff --git a/src/main/java/org/jabref/model/util/FileHelper.java b/src/main/java/org/jabref/model/util/FileHelper.java index dba58b1fd21..83a6064ed66 100644 --- a/src/main/java/org/jabref/model/util/FileHelper.java +++ b/src/main/java/org/jabref/model/util/FileHelper.java @@ -6,15 +6,12 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Optional; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.FilePreferences; import org.apache.tika.config.TikaConfig; @@ -88,77 +85,40 @@ private static Optional detectExtension(InputStream is, Metadata metaDat * * * @param databaseContext The database this file belongs to. - * @param name The filename, may also be a relative path to the file + * @param fileName The filename, may also be a relative path to the file */ - public static Optional expandFilename(final BibDatabaseContext databaseContext, String name, FilePreferences filePreferences) { - // Find the default directory for this field type, if any: - List directories = databaseContext.getFileDirectories(StandardField.FILE, filePreferences); - // Include the standard "file" directory: - List fileDir = databaseContext.getFileDirectories(filePreferences); - - List searchDirectories = new ArrayList<>(); - for (String dir : directories) { - if (!searchDirectories.contains(dir)) { - searchDirectories.add(dir); - } - } - for (String aFileDir : fileDir) { - if (!searchDirectories.contains(aFileDir)) { - searchDirectories.add(aFileDir); - } - } - - return expandFilename(name, searchDirectories); + public static Optional find(final BibDatabaseContext databaseContext, String fileName, FilePreferences filePreferences) { + return find(fileName, databaseContext.getFileDirectoriesAsPaths(filePreferences)); } /** * Converts a relative filename to an absolute one, if necessary. Returns - * null if the file does not exist. + * an empty optional if the file does not exist. *

- * Will look in each of the given dirs starting from the beginning and + * Will look in each of the given directories starting from the beginning and * returning the first found file to match if any. - * - * @deprecated use {@link #expandFilenameAsPath(String, List)} instead */ - @Deprecated - public static Optional expandFilename(String name, List directories) { - for (String dir : directories) { - Optional result = expandFilename(name, Paths.get(dir)); - if (result.isPresent()) { - return result; - } - } - - return Optional.empty(); - } - - public static Optional expandFilenameAsPath(String name, List directories) { - for (Path directory : directories) { - Optional result = expandFilename(name, directory); - if (result.isPresent()) { - return result; - } - } - - return Optional.empty(); + public static Optional find(String fileName, List directories) { + return directories.stream() + .flatMap(directory -> find(fileName, directory).stream()) + .findFirst(); } /** * Converts a relative filename to an absolute one, if necessary. Returns * an empty optional if the file does not exist. */ - private static Optional expandFilename(String filename, Path directory) { - Objects.requireNonNull(filename); + public static Optional find(String fileName, Path directory) { + Objects.requireNonNull(fileName); Objects.requireNonNull(directory); - Path file = Paths.get(filename); // Explicitly check for an empty String, as File.exists returns true on that empty path, because it maps to the default jar location // if we then call toAbsoluteDir, it would always return the jar-location folder. This is not what we want here - if (filename.isEmpty()) { + if (fileName.isEmpty()) { return Optional.of(directory); } - Path resolvedFile = directory.resolve(file); + Path resolvedFile = directory.resolve(fileName); if (Files.exists(resolvedFile)) { return Optional.of(resolvedFile); } else { diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index d6fc664ba94..508c533e53f 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -214,6 +214,7 @@ public class JabRefPreferences implements PreferencesService { public static final String USE_DEFAULT_CONSOLE_APPLICATION = "useDefaultConsoleApplication"; public static final String USE_DEFAULT_FILE_BROWSER_APPLICATION = "userDefaultFileBrowserApplication"; public static final String FILE_BROWSER_COMMAND = "fileBrowserCommand"; + public static final String MAIN_FILE_DIRECTORY = "fileDirectory"; // Currently, it is not possible to specify defaults for specific entry types // When this should be made possible, the code to inspect is org.jabref.gui.preferences.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getCiteKeyPattern(); etc @@ -1200,12 +1201,10 @@ public void storeFileHistory(FileHistory history) { @Override public FilePreferences getFilePreferences() { - Map fieldDirectories = Stream.of(StandardField.FILE, StandardField.PDF, StandardField.PS) - .collect(Collectors.toMap(field -> field, field -> get(field.getName() + FilePreferences.DIR_SUFFIX, ""))); return new FilePreferences( getUser(), - fieldDirectories, - getBoolean(JabRefPreferences.BIB_LOC_AS_PRIMARY_DIR), + get(MAIN_FILE_DIRECTORY), + getBoolean(BIB_LOC_AS_PRIMARY_DIR), get(IMPORT_FILENAMEPATTERN), get(IMPORT_FILEDIRPATTERN)); } @@ -1341,10 +1340,10 @@ private NameFormatterPreferences getNameFormatterPreferences() { return new NameFormatterPreferences(getStringList(NAME_FORMATER_KEY), getStringList(NAME_FORMATTER_VALUE)); } - public FileLinkPreferences getFileLinkPreferences() { + private FileLinkPreferences getFileLinkPreferences() { return new FileLinkPreferences( - Collections.singletonList(get(StandardField.FILE.getName() + FilePreferences.DIR_SUFFIX)), - fileDirForDatabase); + get(MAIN_FILE_DIRECTORY), + fileDirForDatabase); } public JabRefPreferences storeVersionPreferences(VersionPreferences versionPreferences) { diff --git a/src/test/java/org/jabref/logic/layout/LayoutTest.java b/src/test/java/org/jabref/logic/layout/LayoutTest.java index 0702a8262cd..415b1573016 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutTest.java @@ -101,7 +101,7 @@ void HTMLCharsWithDotlessIAndTiled() throws IOException { } @Test - public void beginConditionals() throws IOException { + void beginConditionals() throws IOException { BibEntry entry = new BibEntry(StandardEntryType.Misc) .withField(StandardField.AUTHOR, "Author"); @@ -135,7 +135,7 @@ public void beginConditionals() throws IOException { @Test void wrapFileLinksExpandFile() throws IOException { when(layoutFormatterPreferences.getFileLinkPreferences()).thenReturn( - new FileLinkPreferences(Collections.emptyList(), Collections.singletonList("src/test/resources/pdfs/"))); + new FileLinkPreferences("", Collections.singletonList("src/test/resources/pdfs/"))); BibEntry entry = new BibEntry(StandardEntryType.Article); entry.addFile(new LinkedFile("Test file", "encrypted.pdf", "PDF")); diff --git a/src/test/java/org/jabref/logic/layout/format/WrapFileLinksTest.java b/src/test/java/org/jabref/logic/layout/format/WrapFileLinksTest.java index 09799d584b4..84f5562ced6 100644 --- a/src/test/java/org/jabref/logic/layout/format/WrapFileLinksTest.java +++ b/src/test/java/org/jabref/logic/layout/format/WrapFileLinksTest.java @@ -10,93 +10,93 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -public class WrapFileLinksTest { +class WrapFileLinksTest { private WrapFileLinks formatter; @BeforeEach - public void setUp() { - FileLinkPreferences preferences = new FileLinkPreferences(Collections.emptyList(), Collections.emptyList()); + void setUp() { + FileLinkPreferences preferences = new FileLinkPreferences("", Collections.emptyList()); formatter = new WrapFileLinks(preferences); } @Test - public void testEmpty() { + void testEmpty() { assertEquals("", formatter.format("")); } @Test - public void testNull() { + void testNull() { assertEquals("", formatter.format(null)); } - public void testNoFormatSetNonEmptyString() { + void testNoFormatSetNonEmptyString() { assertThrows(NullPointerException.class, () -> formatter.format("test.pdf")); } @Test - public void testFileExtension() { + void testFileExtension() { formatter.setArgument("\\x"); assertEquals("pdf", formatter.format("test.pdf")); } @Test - public void testFileExtensionNoExtension() { + void testFileExtensionNoExtension() { formatter.setArgument("\\x"); assertEquals("", formatter.format("test")); } @Test - public void testPlainTextString() { + void testPlainTextString() { formatter.setArgument("x"); assertEquals("x", formatter.format("test.pdf")); } @Test - public void testDescription() { + void testDescription() { formatter.setArgument("\\d"); assertEquals("Test file", formatter.format("Test file:test.pdf:PDF")); } @Test - public void testDescriptionNoDescription() { + void testDescriptionNoDescription() { formatter.setArgument("\\d"); assertEquals("", formatter.format("test.pdf")); } @Test - public void testType() { + void testType() { formatter.setArgument("\\f"); assertEquals("PDF", formatter.format("Test file:test.pdf:PDF")); } @Test - public void testTypeNoType() { + void testTypeNoType() { formatter.setArgument("\\f"); assertEquals("", formatter.format("test.pdf")); } @Test - public void testIterator() { + void testIterator() { formatter.setArgument("\\i"); assertEquals("1", formatter.format("Test file:test.pdf:PDF")); } @Test - public void testIteratorTwoItems() { + void testIteratorTwoItems() { formatter.setArgument("\\i\n"); assertEquals("1\n2\n", formatter.format("Test file:test.pdf:PDF;test2.pdf")); } @Test - public void testEndingBracket() { + void testEndingBracket() { formatter.setArgument("(\\d)"); assertEquals("(Test file)", formatter.format("Test file:test.pdf:PDF")); } @Test - public void testPath() throws IOException { - FileLinkPreferences preferences = new FileLinkPreferences(Collections.emptyList(), + void testPath() throws IOException { + FileLinkPreferences preferences = new FileLinkPreferences("", Collections.singletonList("src/test/resources/pdfs/")); formatter = new WrapFileLinks(preferences); formatter.setArgument("\\p"); @@ -105,8 +105,8 @@ public void testPath() throws IOException { } @Test - public void testPathFallBackToGeneratedDir() throws IOException { - FileLinkPreferences preferences = new FileLinkPreferences(Collections.singletonList("src/test/resources/pdfs/"), + void testPathFallBackToGeneratedDir() throws IOException { + FileLinkPreferences preferences = new FileLinkPreferences("src/test/resources/pdfs/", Collections.emptyList()); formatter = new WrapFileLinks(preferences); formatter.setArgument("\\p"); @@ -115,8 +115,8 @@ public void testPathFallBackToGeneratedDir() throws IOException { } @Test - public void testPathReturnsRelativePathIfNotFound() { - FileLinkPreferences preferences = new FileLinkPreferences(Collections.emptyList(), + void testPathReturnsRelativePathIfNotFound() { + FileLinkPreferences preferences = new FileLinkPreferences("", Collections.singletonList("src/test/resources/pdfs/")); formatter = new WrapFileLinks(preferences); formatter.setArgument("\\p"); @@ -124,7 +124,7 @@ public void testPathReturnsRelativePathIfNotFound() { } @Test - public void testRelativePath() { + void testRelativePath() { formatter.setArgument("\\r"); assertEquals("test.pdf", formatter.format("Test file:test.pdf:PDF")); } diff --git a/src/test/java/org/jabref/model/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/BibDatabaseContextTest.java deleted file mode 100644 index 1be4f0eb7da..00000000000 --- a/src/test/java/org/jabref/model/BibDatabaseContextTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.jabref.model; - -import org.jabref.model.database.BibDatabase; -import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.types.IEEETranEntryType; -import org.jabref.model.metadata.MetaData; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class BibDatabaseContextTest { - @Test - void testTypeBasedOnDefaultBiblatex() { - BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData()); - assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); - - bibDatabaseContext.setMode(BibDatabaseMode.BIBLATEX); - assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); - } - - @Test - void testTypeBasedOnDefaultBibtex() { - BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData()); - assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); - - bibDatabaseContext.setMode(BibDatabaseMode.BIBTEX); - assertEquals(BibDatabaseMode.BIBTEX, bibDatabaseContext.getMode()); - } - - @Test - void testTypeBasedOnInferredModeBiblatex() { - BibDatabase db = new BibDatabase(); - BibEntry e1 = new BibEntry(IEEETranEntryType.Electronic); - db.insertEntry(e1); - - BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(db); - assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); - } -} diff --git a/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java index 0c60cf2bbc1..449a17f8619 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java @@ -2,11 +2,13 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.Collections; -import java.util.List; -import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.types.IEEETranEntryType; import org.jabref.model.metadata.FilePreferences; +import org.jabref.model.metadata.MetaData; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,61 +17,104 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class BibDatabaseContextTest { +class BibDatabaseContextTest { private Path currentWorkingDir; - // Store the minimal preferences for the - // BibDatabaseContext.getFileDirectories(File, - // FilePreferences) incocation: private FilePreferences fileDirPrefs; @BeforeEach - public void setUp() { + void setUp() { fileDirPrefs = mock(FilePreferences.class); currentWorkingDir = Paths.get(System.getProperty("user.dir")); when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true); } @Test - public void getFileDirectoriesWithEmptyDbParent() { - BibDatabaseContext dbContext = new BibDatabaseContext(); - dbContext.setDatabasePath(Paths.get("biblio.bib")); - List fileDirectories = dbContext.getFileDirectories(StandardField.FILE, fileDirPrefs); - assertEquals(Collections.singletonList(currentWorkingDir.toString()), - fileDirectories); + void getFileDirectoriesWithEmptyDbParent() { + BibDatabaseContext database = new BibDatabaseContext(); + database.setDatabasePath(Paths.get("biblio.bib")); + assertEquals(Collections.singletonList(currentWorkingDir), + database.getFileDirectoriesAsPaths(fileDirPrefs)); } @Test - public void getFileDirectoriesWithRelativeDbParent() { + void getFileDirectoriesWithRelativeDbParent() { Path file = Paths.get("relative/subdir").resolve("biblio.bib"); - BibDatabaseContext dbContext = new BibDatabaseContext(); - dbContext.setDatabasePath(file); - List fileDirectories = dbContext.getFileDirectories(StandardField.FILE, fileDirPrefs); - assertEquals(Collections.singletonList(currentWorkingDir.resolve(file.getParent()).toString()), - fileDirectories); + BibDatabaseContext database = new BibDatabaseContext(); + database.setDatabasePath(file); + assertEquals(Collections.singletonList(currentWorkingDir.resolve(file.getParent())), + database.getFileDirectoriesAsPaths(fileDirPrefs)); } @Test - public void getFileDirectoriesWithRelativeDottedDbParent() { + void getFileDirectoriesWithRelativeDottedDbParent() { Path file = Paths.get("./relative/subdir").resolve("biblio.bib"); - BibDatabaseContext dbContext = new BibDatabaseContext(); - dbContext.setDatabasePath(file); - List fileDirectories = dbContext.getFileDirectories(StandardField.FILE, fileDirPrefs); - assertEquals(Collections.singletonList(currentWorkingDir.resolve(file.getParent()).toString()), - fileDirectories); + BibDatabaseContext database = new BibDatabaseContext(); + database.setDatabasePath(file); + assertEquals(Collections.singletonList(currentWorkingDir.resolve(file.getParent())), + database.getFileDirectoriesAsPaths(fileDirPrefs)); } @Test - public void getFileDirectoriesWithAbsoluteDbParent() { + void getFileDirectoriesWithAbsoluteDbParent() { Path file = Paths.get("/absolute/subdir").resolve("biblio.bib"); - BibDatabaseContext dbContext = new BibDatabaseContext(); - dbContext.setDatabasePath(file); - List fileDirectories = dbContext.getFileDirectories(StandardField.FILE, fileDirPrefs); - assertEquals(Collections.singletonList(currentWorkingDir.resolve(file.getParent()).toString()), - fileDirectories); + BibDatabaseContext database = new BibDatabaseContext(); + database.setDatabasePath(file); + assertEquals(Collections.singletonList(currentWorkingDir.resolve(file.getParent())), + database.getFileDirectoriesAsPaths(fileDirPrefs)); + } + + @Test + void getFileDirectoriesWithRelativeMetadata() { + Path file = Paths.get("/absolute/subdir").resolve("biblio.bib"); + + BibDatabaseContext database = new BibDatabaseContext(); + database.setDatabasePath(file); + database.getMetaData().setDefaultFileDirectory("..\\Literature\\"); + assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Paths.get("/absolute/Literature").toAbsolutePath()), + database.getFileDirectoriesAsPaths(fileDirPrefs)); + } + + @Test + void getFileDirectoriesWithMetadata() { + Path file = Paths.get("/absolute/subdir").resolve("biblio.bib"); + + BibDatabaseContext database = new BibDatabaseContext(); + database.setDatabasePath(file); + database.getMetaData().setDefaultFileDirectory("Literature\\"); + assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Paths.get("/absolute/subdir/Literature").toAbsolutePath()), + database.getFileDirectoriesAsPaths(fileDirPrefs)); + } + + @Test + void testTypeBasedOnDefaultBiblatex() { + BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData()); + assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); + + bibDatabaseContext.setMode(BibDatabaseMode.BIBLATEX); + assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); + } + + @Test + void testTypeBasedOnDefaultBibtex() { + BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData()); + assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); + + bibDatabaseContext.setMode(BibDatabaseMode.BIBTEX); + assertEquals(BibDatabaseMode.BIBTEX, bibDatabaseContext.getMode()); + } + + @Test + void testTypeBasedOnInferredModeBiblatex() { + BibDatabase db = new BibDatabase(); + BibEntry e1 = new BibEntry(IEEETranEntryType.Electronic); + db.insertEntry(e1); + + BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(db); + assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode()); } } From 885ddbb99e9a62b3e16fc75586871420aaf78fa3 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 30 Apr 2020 00:54:59 +0200 Subject: [PATCH 2/4] Fix tests --- .../org/jabref/model/database/BibDatabaseContextTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java index 449a17f8619..5730acdf804 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java @@ -74,7 +74,7 @@ void getFileDirectoriesWithRelativeMetadata() { BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); - database.getMetaData().setDefaultFileDirectory("..\\Literature\\"); + database.getMetaData().setDefaultFileDirectory("../Literature"); assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Paths.get("/absolute/Literature").toAbsolutePath()), database.getFileDirectoriesAsPaths(fileDirPrefs)); } @@ -85,7 +85,7 @@ void getFileDirectoriesWithMetadata() { BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); - database.getMetaData().setDefaultFileDirectory("Literature\\"); + database.getMetaData().setDefaultFileDirectory("Literature"); assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Paths.get("/absolute/subdir/Literature").toAbsolutePath()), database.getFileDirectoriesAsPaths(fileDirPrefs)); } From 4d6dffac64d40260f562896c224e4b77e3fb43d5 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 30 Apr 2020 10:56:30 +0200 Subject: [PATCH 3/4] Replace Paths.get --- .../org/jabref/cli/ArgumentProcessor.java | 11 +++--- .../java/org/jabref/cli/AuxCommandLine.java | 4 +- src/main/java/org/jabref/gui/JabRefFrame.java | 3 +- .../jabref/gui/auximport/FromAuxDialog.java | 6 +-- .../jabref/gui/copyfiles/CopyFilesAction.java | 3 +- .../gui/copyfiles/CopySingleFileAction.java | 9 ++--- .../java/org/jabref/gui/desktop/os/Linux.java | 3 +- .../jabref/gui/desktop/os/NativeDesktop.java | 3 +- .../java/org/jabref/gui/desktop/os/OSX.java | 3 +- .../org/jabref/gui/desktop/os/Windows.java | 11 +++--- .../CreateModifyExporterDialogViewModel.java | 3 +- .../FindUnlinkedFilesDialog.java | 5 +-- .../gui/fieldeditors/LinkedFileViewModel.java | 5 +-- .../LinkedFilesEditDialogViewModel.java | 5 +-- .../gui/groups/GroupDialogViewModel.java | 11 ++---- .../org/jabref/gui/importer/ImportAction.java | 3 +- .../ImportCustomizationDialogViewModel.java | 3 +- .../ManageJournalAbbreviationsViewModel.java | 3 +- .../LibraryPropertiesDialogViewModel.java | 3 +- .../DetectOpenOfficeInstallation.java | 3 +- .../gui/openoffice/OpenOfficePanel.java | 3 +- .../gui/preferences/FileTabViewModel.java | 5 +-- .../SharedDatabaseLoginDialogViewModel.java | 7 ++-- .../texparser/ParseLatexDialogViewModel.java | 9 ++--- .../util/DirectoryDialogConfiguration.java | 3 +- .../gui/util/FileDialogConfiguration.java | 3 +- .../java/org/jabref/gui/util/ThemeLoader.java | 5 +-- .../logic/auxparser/DefaultAuxParser.java | 3 +- .../logic/citationstyle/CitationStyle.java | 3 +- .../logic/cleanup/RelativePathsCleanup.java | 4 +- .../logic/cleanup/RenamePdfCleanup.java | 4 +- .../jabref/logic/exporter/XmpExporter.java | 5 +-- .../jabref/logic/importer/OpenDatabase.java | 3 +- .../importer/fileformat/CustomImporter.java | 5 +-- .../logic/importer/util/GroupsParser.java | 3 +- .../logic/importer/util/MetaDataParser.java | 3 +- .../jabref/logic/layout/format/FileLink.java | 4 +- .../logic/layout/format/WrapFileLinks.java | 4 +- .../openoffice/OpenOfficeFileSearch.java | 9 ++--- .../protectedterms/ProtectedTermsList.java | 3 +- .../logic/texparser/DefaultLatexParser.java | 3 +- .../logic/util/io/RegExpBasedFileFinder.java | 5 +-- .../org/jabref/logic/xmp/XmpUtilReader.java | 4 +- .../org/jabref/logic/xmp/XmpUtilWriter.java | 3 +- .../model/database/BibDatabaseContext.java | 3 +- .../org/jabref/model/entry/LinkedFile.java | 3 +- .../model/metadata/FilePreferences.java | 3 +- .../jabref/preferences/JabRefPreferences.java | 9 ++--- .../java/org/jabref/TestIconsProperties.java | 7 ++-- .../architecture/MainArchitectureTests.java | 3 +- .../MainArchitectureTestsWithArchUnit.java | 10 +++++ .../architecture/TestArchitectureTests.java | 3 +- .../org/jabref/cli/AuxCommandLineTest.java | 4 +- .../gui/util/FileDialogConfigurationTest.java | 3 +- .../autosaveandbackup/BackupManagerTest.java | 5 +-- .../jabref/logic/auxparser/AuxParserTest.java | 13 +++---- .../jabref/logic/bibtex/BibEntryAssert.java | 5 +-- .../logic/bst/BstPreviewLayoutTest.java | 12 +++--- .../exporter/BibTeXMLExporterTestFiles.java | 5 +-- .../exporter/BibtexDatabaseWriterTest.java | 17 ++++----- .../logic/exporter/DocBook5ExporterTest.java | 3 +- .../logic/exporter/GroupSerializerTest.java | 4 +- .../exporter/MSBibExportFormatTestFiles.java | 3 +- .../logic/exporter/ModsExportFormatTest.java | 3 +- .../exporter/ModsExportFormatTestFiles.java | 13 +++---- .../logic/exporter/XmpExporterTest.java | 5 +-- .../jabref/logic/importer/ImportDataTest.java | 13 +++---- .../ImportFormatReaderIntegrationTest.java | 7 ++-- .../ImportFormatReaderTestParameterless.java | 5 +-- .../logic/importer/OpenDatabaseTest.java | 8 ++-- .../fileformat/BiblioscapeImporterTest.java | 3 +- .../fileformat/BibtexImporterTest.java | 7 ++-- .../fileformat/CopacImporterTest.java | 3 +- .../fileformat/CustomImporterTest.java | 4 +- .../fileformat/EndnoteImporterTest.java | 9 ++--- .../fileformat/ImporterTestEngine.java | 5 +-- .../importer/fileformat/IsiImporterTest.java | 17 ++++----- .../fileformat/MedlinePlainImporterTest.java | 4 +- .../fileformat/MsBibImporterTest.java | 7 ++-- .../importer/fileformat/OvidImporterTest.java | 9 ++--- .../fileformat/PdfContentImporterTest.java | 5 +-- .../fileformat/PdfXmpImporterTest.java | 7 ++-- .../importer/fileformat/RISImporterTest.java | 3 +- .../logic/importer/util/GroupsParserTest.java | 4 +- .../l10n/LocalizationConsistencyTest.java | 5 +-- .../jabref/logic/l10n/LocalizationParser.java | 7 ++-- .../logic/openoffice/OOBibStyleTest.java | 6 +-- .../logic/openoffice/StyleLoaderTest.java | 16 ++++---- .../pdf/EntryAnnotationImporterTest.java | 3 +- .../logic/pdf/PdfAnnotationImporterTest.java | 34 ++++++++--------- .../ProtectedTermsLoaderTest.java | 12 +++--- .../logic/texparser/DefaultTexParserTest.java | 37 +++++++++---------- .../logic/texparser/LatexParserTest.java | 9 ++--- .../texparser/TexBibEntriesResolverTest.java | 17 ++++----- .../jabref/logic/util/io/FileHistoryTest.java | 26 ++++++------- .../jabref/logic/util/io/FileUtilTest.java | 33 ++++++++--------- .../util/io/RegExpBasedFileFinderTests.java | 19 +++++----- .../jabref/logic/xmp/XmpUtilReaderTest.java | 9 ++--- .../jabref/logic/xmp/XmpUtilWriterTest.java | 5 +-- .../database/BibDatabaseContextTest.java | 19 +++++----- .../org/jabref/model/groups/TexGroupTest.java | 7 ++-- .../jabref/model/strings/StringUtilTest.java | 3 +- 102 files changed, 325 insertions(+), 401 deletions(-) diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index fda5b35c0af..0df0c0f8dee 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -111,9 +110,9 @@ private static Optional importFile(String argument) { } } else { if (OS.WINDOWS) { - file = Paths.get(address); + file = Path.of(address); } else { - file = Paths.get(address.replace("~", System.getProperty("user.home"))); + file = Path.of(address.replace("~", System.getProperty("user.home"))); } } @@ -280,7 +279,7 @@ private boolean exportMatches(List loaded) { // We have an TemplateExporter instance: try { System.out.println(Localization.lang("Exporting") + ": " + data[1]); - exporter.get().export(databaseContext, Paths.get(data[1]), + exporter.get().export(databaseContext, Path.of(data[1]), databaseContext.getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), matches); } catch (Exception ex) { @@ -389,7 +388,7 @@ private void saveDatabase(BibDatabase newBase, String subName) { try { System.out.println(Localization.lang("Saving") + ": " + subName); SavePreferences prefs = Globals.prefs.loadForSaveFromPreferences(); - AtomicFileWriter fileWriter = new AtomicFileWriter(Paths.get(subName), prefs.getEncoding()); + AtomicFileWriter fileWriter = new AtomicFileWriter(Path.of(subName), prefs.getEncoding()); BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, prefs, Globals.entryTypesManager); databaseWriter.saveDatabase(new BibDatabaseContext(newBase)); @@ -441,7 +440,7 @@ private void exportFile(List loaded, String[] data) { } else { // We have an exporter: try { - exporter.get().export(pr.getDatabaseContext(), Paths.get(data[0]), + exporter.get().export(pr.getDatabaseContext(), Path.of(data[0]), pr.getDatabaseContext().getMetaData().getEncoding() .orElse(Globals.prefs.getDefaultEncoding()), pr.getDatabaseContext().getDatabase().getEntries()); diff --git a/src/main/java/org/jabref/cli/AuxCommandLine.java b/src/main/java/org/jabref/cli/AuxCommandLine.java index 3b09315ce15..00cb424fb54 100644 --- a/src/main/java/org/jabref/cli/AuxCommandLine.java +++ b/src/main/java/org/jabref/cli/AuxCommandLine.java @@ -1,6 +1,6 @@ package org.jabref.cli; -import java.nio.file.Paths; +import java.nio.file.Path; import org.jabref.gui.auximport.AuxParserResultViewModel; import org.jabref.logic.auxparser.DefaultAuxParser; @@ -23,7 +23,7 @@ public BibDatabase perform() { if (!auxFile.isEmpty() && (database != null)) { AuxParser auxParser = new DefaultAuxParser(database); - AuxParserResult result = auxParser.parse(Paths.get(auxFile)); + AuxParserResult result = auxParser.parse(Path.of(auxFile)); subDatabase = result.getGeneratedBibDatabase(); // print statistics System.out.println(new AuxParserResultViewModel(result).getInformation(true)); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index a6ab65e4d4f..ae79b4d341f 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -2,7 +2,6 @@ import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -320,7 +319,7 @@ public void setWindowTitle() { * The MacAdapter calls this method when a "BIB" file has been double-clicked from the Finder. */ public void openAction(String filePath) { - Path file = Paths.get(filePath); + Path file = Path.of(filePath); // all the logic is done in openIt. Even raising an existing panel getOpenDatabaseAction().openFile(file, true); } diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index d1043c6981d..7db6fe77f8c 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -1,6 +1,6 @@ package org.jabref.gui.auximport; -import java.nio.file.Paths; +import java.nio.file.Path; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -36,7 +36,7 @@ public class FromAuxDialog extends BaseDialog { private final DialogService dialogService; private final BasePanel basePanel; @FXML private ButtonType generateButtonType; - private Button generateButton; + private final Button generateButton; @FXML private TextField auxFileField; @FXML private ListView notFoundList; @@ -74,7 +74,7 @@ private void parseActionPerformed() { if ((auxName != null) && (refBase != null) && !auxName.isEmpty()) { AuxParser auxParser = new DefaultAuxParser(refBase); - auxParserResult = auxParser.parse(Paths.get(auxName)); + auxParserResult = auxParser.parse(Path.of(auxName)); notFoundList.getItems().setAll(auxParserResult.getUnresolvedKeys()); statusInfos.setText(new AuxParserResultViewModel(auxParserResult).getInformation(false)); diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java index a425631f2bd..d3fa80e837c 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java @@ -1,7 +1,6 @@ package org.jabref.gui.copyfiles; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Optional; @@ -47,7 +46,7 @@ public void execute() { List entries = stateManager.getSelectedEntries(); DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) + .withInitialDirectory(Path.of(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) .build(); Optional exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); exportPath.ifPresent(path -> { diff --git a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java index 60671662148..ada371cfc58 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java @@ -1,7 +1,6 @@ package org.jabref.gui.copyfiles; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import java.util.function.BiFunction; @@ -17,9 +16,9 @@ public class CopySingleFileAction { - private LinkedFile linkedFile; - private DialogService dialogService; - private BibDatabaseContext databaseContext; + private final LinkedFile linkedFile; + private final DialogService dialogService; + private final BibDatabaseContext databaseContext; private final BiFunction resolvePathFilename = (path, file) -> { return path.resolve(file.getFileName()); }; @@ -32,7 +31,7 @@ public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, public void copyFile() { DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) + .withInitialDirectory(Path.of(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) .build(); Optional exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); exportPath.ifPresent(this::copyFileToDestination); diff --git a/src/main/java/org/jabref/gui/desktop/os/Linux.java b/src/main/java/org/jabref/gui/desktop/os/Linux.java index dcd0252e677..ee1881af803 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Locale; import java.util.Optional; @@ -109,6 +108,6 @@ public String detectProgramPath(String programName, String directoryName) { @Override public Path getApplicationDirectory() { - return Paths.get("/usr/lib/"); + return Path.of("/usr/lib/"); } } diff --git a/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java b/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java index f4c2014384b..2f207851191 100644 --- a/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; public interface NativeDesktop { void openFile(String filePath, String fileType) throws IOException; @@ -35,6 +34,6 @@ public interface NativeDesktop { * @return the path to the user directory. */ default Path getUserDirectory() { - return Paths.get(System.getProperty("user.home")); + return Path.of(System.getProperty("user.home")); } } diff --git a/src/main/java/org/jabref/gui/desktop/os/OSX.java b/src/main/java/org/jabref/gui/desktop/os/OSX.java index 9abd006cdce..57f145f7460 100644 --- a/src/main/java/org/jabref/gui/desktop/os/OSX.java +++ b/src/main/java/org/jabref/gui/desktop/os/OSX.java @@ -4,7 +4,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import org.jabref.gui.externalfiletype.ExternalFileType; @@ -48,6 +47,6 @@ public String detectProgramPath(String programName, String directoryName) { @Override public Path getApplicationDirectory() { - return Paths.get("/Applications"); + return Path.of("/Applications"); } } diff --git a/src/main/java/org/jabref/gui/desktop/os/Windows.java b/src/main/java/org/jabref/gui/desktop/os/Windows.java index 00367d1b2c9..dce140cd155 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -3,14 +3,13 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; public class Windows implements NativeDesktop { - private static String DEFAULT_EXECUTABLE_EXTENSION = ".exe"; + private static final String DEFAULT_EXECUTABLE_EXTENSION = ".exe"; @Override public void openFile(String filePath, String fileType) throws IOException { @@ -32,9 +31,9 @@ public String detectProgramPath(String programName, String directoryName) { progFiles = System.getenv("ProgramFiles"); } if ((directoryName != null) && !directoryName.isEmpty()) { - return Paths.get(progFiles, directoryName, programName + DEFAULT_EXECUTABLE_EXTENSION).toString(); + return Path.of(progFiles, directoryName, programName + DEFAULT_EXECUTABLE_EXTENSION).toString(); } - return Paths.get(progFiles, programName + DEFAULT_EXECUTABLE_EXTENSION).toString(); + return Path.of(progFiles, programName + DEFAULT_EXECUTABLE_EXTENSION).toString(); } @Override @@ -42,14 +41,14 @@ public Path getApplicationDirectory() { String programDir = System.getenv("ProgramFiles"); if (programDir != null) { - return Paths.get(programDir); + return Path.of(programDir); } return getUserDirectory(); } @Override public void openFileWithApplication(String filePath, String application) throws IOException { - new ProcessBuilder(Paths.get(application).toString(), Paths.get(filePath).toString()).start(); + new ProcessBuilder(Path.of(application).toString(), Path.of(filePath).toString()).start(); } @Override diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index df1ab4ffbb8..0487fa357a3 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -1,7 +1,6 @@ package org.jabref.gui.exporter; import java.nio.file.Path; -import java.nio.file.Paths; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -55,7 +54,7 @@ public CreateModifyExporterDialogViewModel(ExporterViewModel exporter, DialogSer } public ExporterViewModel saveExporter() { - Path layoutFileDir = Paths.get(layoutFile.get()).getParent(); + Path layoutFileDir = Path.of(layoutFile.get()).getParent(); if (layoutFileDir != null) { String layoutFileDirString = layoutFileDir.toString(); preferences.setExportWorkingDirectory(layoutFileDirString); diff --git a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java index 66c707e156d..1b455afdbdd 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java @@ -6,7 +6,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Arrays; @@ -304,9 +303,9 @@ private void startSearch() { } private Path getSearchDirectory() { - Path directory = Paths.get(textfieldDirectoryPath.getText()); + Path directory = Path.of(textfieldDirectoryPath.getText()); if (Files.notExists(directory)) { - directory = Paths.get(System.getProperty("user.dir")); + directory = Path.of(System.getProperty("user.dir")); textfieldDirectoryPath.setText(directory.toAbsolutePath().toString()); } if (!Files.isDirectory(directory)) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index d349f896ebf..ca4af64148c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -4,7 +4,6 @@ import java.net.MalformedURLException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -216,7 +215,7 @@ public void renameToSuggestion() { public void askForNameAndRename() { String oldFile = this.linkedFile.getLink(); - Path oldFilePath = Paths.get(oldFile); + Path oldFilePath = Path.of(oldFile); Optional askedFileName = dialogService.showInputDialogWithDefaultAndWait(Localization.lang("Rename file"), Localization.lang("New Filename"), oldFilePath.getFileName().toString()); askedFileName.ifPresent(this::renameFileToName); } @@ -293,7 +292,7 @@ public void moveToDefaultDirectory() { * @return true if the suggested filename is same as current filename. */ public boolean isGeneratedNameSameAsOriginal() { - Path file = Paths.get(this.linkedFile.getLink()); + Path file = Path.of(this.linkedFile.getLink()); String currentFileName = file.getFileName().toString(); String suggestedFileName = this.linkedFileHandler.getSuggestedFileName(); diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index c3b8dcbd63e..9700fa841bf 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -1,7 +1,6 @@ package org.jabref.gui.filelist; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Optional; import java.util.regex.Pattern; @@ -73,7 +72,7 @@ public void openBrowseDialog() { Optional file = FileHelper.find(database, fileText, preferences.getFilePreferences()); Path workingDir = file.orElse(preferences.getWorkingDir()); - String fileName = Paths.get(fileText).getFileName().toString(); + String fileName = Path.of(fileText).getFileName().toString(); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .withInitialDirectory(workingDir) @@ -95,7 +94,7 @@ public void setValues(LinkedFile linkedFile) { if (linkedFile.isOnlineLink()) { link.setValue(linkedFile.getLink()); // Might be an URL } else { - link.setValue(relativize(Paths.get(linkedFile.getLink()))); + link.setValue(relativize(Path.of(linkedFile.getLink()))); } selectedExternalFileType.setValue(null); diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 2da487145e3..a5bc2d7c9af 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -99,7 +98,7 @@ public class GroupDialogViewModel { private Validator keywordSearchTermEmptyValidator; private Validator searchRegexValidator; private Validator searchSearchTermEmptyValidator; - private CompositeValidator validator = new CompositeValidator(); + private final CompositeValidator validator = new CompositeValidator(); private final DialogService dialogService; private final PreferencesService preferencesService; @@ -142,10 +141,8 @@ private void setupValidation() { return false; } - if ((editedGroup != null) && !editedGroup.getName().equals(name) && (groupsWithSameName > 0)) { - // Edit group, changed name to something that is already present - return false; - } + // Edit group, changed name to something that is already present + return (editedGroup == null) || editedGroup.getName().equals(name) || (groupsWithSameName <= 0); } return true; }, @@ -302,7 +299,7 @@ public AbstractGroup resultConverter(ButtonType button) { resultingGroup = TexGroup.create( groupName, groupHierarchySelectedProperty.getValue(), - Paths.get(texGroupFilePathProperty.getValue().trim()), + Path.of(texGroupFilePathProperty.getValue().trim()), new DefaultAuxParser(new BibDatabase()), Globals.getFileUpdateMonitor(), currentDatabase.getMetaData()); diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index 2c08c0e16ba..2b6bec6dc27 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -58,7 +57,7 @@ public ImportAction(JabRefFrame frame, boolean openInNew, Importer importer) { * @param filenames List of files to import */ public void automatedImport(List filenames) { - List files = filenames.stream().map(Paths::get).collect(Collectors.toList()); + List files = filenames.stream().map(Path::of).collect(Collectors.toList()); BackgroundTask task = BackgroundTask.wrap(() -> { List imports = doImport(files); // Ok, done. Then try to gather in all we have found. Since we might diff --git a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java index 8ab6ba58277..90ac43ee424 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.Optional; @@ -48,7 +47,7 @@ public ImportCustomizationDialogViewModel(PreferencesService preferences, Dialog * @return class name */ private static String pathToClass(String basePath, Path path) { - String className = FileUtil.relativize(path, Collections.singletonList(Paths.get(basePath))).toString(); + String className = FileUtil.relativize(path, Collections.singletonList(Path.of(basePath))).toString(); if (className != null) { int lastDot = className.lastIndexOf('.'); if (lastDot < 0) { diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java index 2835d0eff5f..2842f890161 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java @@ -3,7 +3,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -151,7 +150,7 @@ private void addList(String name, List abbreviations) { */ public void createFileObjects() { List externalFiles = abbreviationsPreferences.getExternalJournalLists(); - externalFiles.forEach(name -> openFile(Paths.get(name))); + externalFiles.forEach(name -> openFile(Path.of(name))); } /** diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java index f88df80f07d..555c70aede9 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java @@ -2,7 +2,6 @@ import java.nio.charset.Charset; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import java.util.Set; @@ -155,7 +154,7 @@ void storeSettings() { if (latexFileDirectory.isEmpty()) { newMetaData.clearLatexFileDirectory(preferences.getUser()); } else { - newMetaData.setLatexFileDirectory(preferences.getUser(), Paths.get(latexFileDirectory)); + newMetaData.setLatexFileDirectory(preferences.getUser(), Path.of(latexFileDirectory)); } if (libraryProtectedProperty.getValue()) { diff --git a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java index c4e8e47885a..117bcc9c5a7 100644 --- a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java +++ b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java @@ -2,7 +2,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Optional; @@ -76,7 +75,7 @@ private boolean autoDetectPaths() { */ private boolean checkAutoDetectedPaths(OpenOfficePreferences openOfficePreferences) { String executablePath = openOfficePreferences.getExecutablePath(); - return !StringUtil.isNullOrEmpty(executablePath) && Files.exists(Paths.get(executablePath)); + return !StringUtil.isNullOrEmpty(executablePath) && Files.exists(Path.of(executablePath)); } private boolean setOpenOfficePreferences(Path installDir) { diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 491653f3ad6..f23972e1a4d 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -5,7 +5,6 @@ import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -375,7 +374,7 @@ private void connect() { @Override protected OOBibBase call() throws Exception { updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); - List jarUrls = findOpenOfficeJars(Paths.get(ooPrefs.getInstallationPath())); + List jarUrls = findOpenOfficeJars(Path.of(ooPrefs.getInstallationPath())); return createBibBase(jarUrls); } diff --git a/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java index f9afdda963c..1da2e313031 100644 --- a/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/FileTabViewModel.java @@ -2,7 +2,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -61,7 +60,7 @@ public FileTabViewModel(DialogService dialogService, JabRefPreferences preferenc mainFileDirValidator = new FunctionBasedValidator<>( mainFileDirProperty, input -> { - Path path = Paths.get(mainFileDirProperty.getValue()); + Path path = Path.of(mainFileDirProperty.getValue()); return (Files.exists(path) && Files.isDirectory(path)); }, ValidationMessage.error(String.format("%s > %s > %s %n %n %s", @@ -146,7 +145,7 @@ public boolean validateSettings() { public void mainFileDirBrowse() { DirectoryDialogConfiguration dirDialogConfiguration = - new DirectoryDialogConfiguration.Builder().withInitialDirectory(Paths.get(mainFileDirProperty.getValue())).build(); + new DirectoryDialogConfiguration.Builder().withInitialDirectory(Path.of(mainFileDirProperty.getValue())).build(); dialogService.showDirectorySelectionDialog(dirDialogConfiguration) .ifPresent(f -> mainFileDirProperty.setValue(f.toString())); } diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java index 8fb16ee9f87..988ef5fcbd8 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java @@ -3,7 +3,6 @@ import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.security.GeneralSecurityException; import java.sql.SQLException; import java.util.List; @@ -93,7 +92,7 @@ public SharedDatabaseLoginDialogViewModel(JabRefFrame frame, DialogService dialo }); Predicate notEmpty = input -> (input != null) && !input.trim().isEmpty(); - Predicate fileExists = input -> Files.exists(Paths.get(input)); + Predicate fileExists = input -> Files.exists(Path.of(input)); Predicate notEmptyAndfilesExist = notEmpty.and(fileExists); databaseValidator = new FunctionBasedValidator<>(database, notEmpty, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("Library")))); @@ -144,7 +143,7 @@ private boolean openSharedDatabase(DBMSConnectionProperties connectionProperties } if (autosave.get()) { - Path localFilePath = Paths.get(folder.getValue()); + Path localFilePath = Path.of(folder.getValue()); if (Files.exists(localFilePath) && !Files.isDirectory(localFilePath)) { @@ -167,7 +166,7 @@ private boolean openSharedDatabase(DBMSConnectionProperties connectionProperties if (!folder.getValue().isEmpty()) { try { - new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager).saveAs(Paths.get(folder.getValue())); + new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager).saveAs(Path.of(folder.getValue())); } catch (Throwable e) { LOGGER.error("Error while saving the database", e); } diff --git a/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java index a5f6630a68a..0586d82dfaa 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java @@ -4,7 +4,6 @@ import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.function.Predicate; @@ -75,7 +74,7 @@ public ParseLatexDialogViewModel(BibDatabaseContext databaseContext, DialogServi this.searchInProgress = new SimpleBooleanProperty(false); this.successfulSearch = new SimpleBooleanProperty(false); - Predicate isDirectory = path -> Paths.get(path).toFile().isDirectory(); + Predicate isDirectory = path -> Path.of(path).toFile().isDirectory(); latexDirectoryValidator = new FunctionBasedValidator<>(latexFileDirectory, isDirectory, ValidationMessage.error(Localization.lang("Please enter a valid file path."))); } @@ -110,7 +109,7 @@ public BooleanProperty successfulSearchProperty() { public void browseButtonClicked() { DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(Paths.get(latexFileDirectory.get())).build(); + .withInitialDirectory(Path.of(latexFileDirectory.get())).build(); dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory -> { latexFileDirectory.set(selectedDirectory.toAbsolutePath().toString()); @@ -122,7 +121,7 @@ public void browseButtonClicked() { * Run a recursive search in a background task. */ public void searchButtonClicked() { - BackgroundTask.wrap(() -> searchDirectory(Paths.get(latexFileDirectory.get()))) + BackgroundTask.wrap(() -> searchDirectory(Path.of(latexFileDirectory.get()))) .onRunning(() -> { root.set(null); noFilesFound.set(true); @@ -205,7 +204,7 @@ public void parseButtonClicked() { BackgroundTask.wrap(() -> entriesResolver.resolve(new DefaultLatexParser().parse(fileList))) .onRunning(() -> searchInProgress.set(true)) .onFinished(() -> searchInProgress.set(false)) - .onSuccess(result -> new ParseLatexResultView(result, databaseContext, Paths.get(latexFileDirectory.get())).showAndWait()) + .onSuccess(result -> new ParseLatexResultView(result, databaseContext, Path.of(latexFileDirectory.get())).showAndWait()) .onFailure(dialogService::showErrorDialogAndWait) .executeWith(taskExecutor); } diff --git a/src/main/java/org/jabref/gui/util/DirectoryDialogConfiguration.java b/src/main/java/org/jabref/gui/util/DirectoryDialogConfiguration.java index d390676c4b5..3bb79a16192 100644 --- a/src/main/java/org/jabref/gui/util/DirectoryDialogConfiguration.java +++ b/src/main/java/org/jabref/gui/util/DirectoryDialogConfiguration.java @@ -2,7 +2,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; public class DirectoryDialogConfiguration { @@ -44,7 +43,7 @@ public Builder withInitialDirectory(Path directory) { } public Builder withInitialDirectory(String directory) { - withInitialDirectory(Paths.get(directory)); + withInitialDirectory(Path.of(directory)); return this; } } diff --git a/src/main/java/org/jabref/gui/util/FileDialogConfiguration.java b/src/main/java/org/jabref/gui/util/FileDialogConfiguration.java index c1e7d1b1f0d..cd15f6a7793 100644 --- a/src/main/java/org/jabref/gui/util/FileDialogConfiguration.java +++ b/src/main/java/org/jabref/gui/util/FileDialogConfiguration.java @@ -2,7 +2,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -84,7 +83,7 @@ public Builder withInitialDirectory(Path directory) { public Builder withInitialDirectory(String directory) { if (directory != null) { - withInitialDirectory(Paths.get(directory)); + withInitialDirectory(Path.of(directory)); } else { initialDirectory = null; } diff --git a/src/main/java/org/jabref/gui/util/ThemeLoader.java b/src/main/java/org/jabref/gui/util/ThemeLoader.java index 17065eb74a1..22cd37a4d28 100644 --- a/src/main/java/org/jabref/gui/util/ThemeLoader.java +++ b/src/main/java/org/jabref/gui/util/ThemeLoader.java @@ -6,7 +6,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Objects; import java.util.Optional; @@ -53,7 +52,7 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef LOGGER.info("Using css from VM option: " + cssVmArgument); URL cssVmUrl = null; try { - cssVmUrl = Paths.get(cssVmArgument).toUri().toURL(); + cssVmUrl = Path.of(cssVmArgument).toUri().toURL(); } catch (MalformedURLException e) { LOGGER.warn("Cannot load css " + cssVmArgument, e); } @@ -93,7 +92,7 @@ private void addAndWatchForChanges(Scene scene, URL cssFile, int index) { if (!cssUri.toString().contains("jrt")) { LOGGER.debug("CSS URI {}", cssUri); - Path cssPath = Paths.get(cssUri).toAbsolutePath(); + Path cssPath = Path.of(cssUri).toAbsolutePath(); LOGGER.info("Enabling live reloading of {}", cssPath); fileUpdateMonitor.addListenerForFile(cssPath, () -> { LOGGER.info("Reload css file {}", cssFile); diff --git a/src/main/java/org/jabref/logic/auxparser/DefaultAuxParser.java b/src/main/java/org/jabref/logic/auxparser/DefaultAuxParser.java index 60de2a294f7..ef638c445b3 100644 --- a/src/main/java/org/jabref/logic/auxparser/DefaultAuxParser.java +++ b/src/main/java/org/jabref/logic/auxparser/DefaultAuxParser.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -97,7 +96,7 @@ private void matchNestedAux(Path baseAuxFile, AuxParserResult result, List if (rootPath != null) { inputFile = rootPath.resolve(inputString); } else { - inputFile = Paths.get(inputString); + inputFile = Path.of(inputString); } if (!fileList.contains(inputFile)) { diff --git a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java index 99ddd023239..0051547eebc 100644 --- a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java +++ b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java @@ -9,7 +9,6 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -106,7 +105,7 @@ public static Optional createCitationStyleFromFile(final String s text = CSLUtils.readURLToString(url, StandardCharsets.UTF_8.toString()); } else { // if the url is null then the style is located outside the classpath - text = new String(Files.readAllBytes(Paths.get(styleFile)), StandardCharsets.UTF_8); + text = new String(Files.readAllBytes(Path.of(styleFile)), StandardCharsets.UTF_8); } return createCitationStyleFromSource(text, styleFile); } catch (NoSuchFileException e) { diff --git a/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java b/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java index 677d30bdf2a..c21c267650a 100644 --- a/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/RelativePathsCleanup.java @@ -1,6 +1,6 @@ package org.jabref.logic.cleanup; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -40,7 +40,7 @@ public List cleanup(BibEntry entry) { } else { // only try to transform local file path to relative one newFileName = FileUtil - .relativize(Paths.get(oldFileName), databaseContext.getFileDirectoriesAsPaths(filePreferences)) + .relativize(Path.of(oldFileName), databaseContext.getFileDirectoriesAsPaths(filePreferences)) .toString(); } LinkedFile newFileEntry = fileEntry; diff --git a/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java b/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java index 4016081e60b..a62a616da41 100644 --- a/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java @@ -1,7 +1,7 @@ package org.jabref.logic.cleanup; import java.io.IOException; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -38,7 +38,7 @@ public List cleanup(BibEntry entry) { boolean changed = false; for (LinkedFile file : files) { - if (onlyRelativePaths && Paths.get(file.getLink()).isAbsolute()) { + if (onlyRelativePaths && Path.of(file.getLink()).isAbsolute()) { continue; } diff --git a/src/main/java/org/jabref/logic/exporter/XmpExporter.java b/src/main/java/org/jabref/logic/exporter/XmpExporter.java index 59f7c445b6b..2c0e55e2b56 100644 --- a/src/main/java/org/jabref/logic/exporter/XmpExporter.java +++ b/src/main/java/org/jabref/logic/exporter/XmpExporter.java @@ -5,7 +5,6 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -57,9 +56,9 @@ public void export(BibDatabaseContext databaseContext, Path file, Charset encodi Path entryFile; String suffix = entry.getId() + "_" + entry.getField(InternalField.KEY_FIELD).orElse("null") + ".xmp"; if (file.getParent() == null) { - entryFile = Paths.get(suffix); + entryFile = Path.of(suffix); } else { - entryFile = Paths.get(file.getParent().toString() + "/" + suffix); + entryFile = Path.of(file.getParent().toString() + "/" + suffix); } this.writeBibToXmp(entryFile, Collections.singletonList(entry), encoding); } diff --git a/src/main/java/org/jabref/logic/importer/OpenDatabase.java b/src/main/java/org/jabref/logic/importer/OpenDatabase.java index d05900c92a5..f0faacd6f73 100644 --- a/src/main/java/org/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/org/jabref/logic/importer/OpenDatabase.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; @@ -36,7 +35,7 @@ private OpenDatabase() { @Deprecated public static ParserResult loadDatabase(String name, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor) { LOGGER.debug("Opening: " + name); - Path file = Paths.get(name); + Path file = Path.of(name); if (!Files.exists(file)) { ParserResult pr = ParserResult.fromErrorMessage(Localization.lang("File not found")); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java index 4b8ae55c65e..7c671d128a7 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java @@ -5,7 +5,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -24,10 +23,10 @@ public class CustomImporter extends Importer { private final String className; private final Path basePath; - private Importer importer; + private final Importer importer; public CustomImporter(String basePath, String className) throws ClassNotFoundException { - this.basePath = Paths.get(basePath); + this.basePath = Path.of(basePath); this.className = className; try { importer = load(this.basePath.toUri().toURL(), this.className); diff --git a/src/main/java/org/jabref/logic/importer/util/GroupsParser.java b/src/main/java/org/jabref/logic/importer/util/GroupsParser.java index 2b0044ba543..84c1f98ca1e 100644 --- a/src/main/java/org/jabref/logic/importer/util/GroupsParser.java +++ b/src/main/java/org/jabref/logic/importer/util/GroupsParser.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import org.jabref.logic.auxparser.DefaultAuxParser; @@ -128,7 +127,7 @@ private static AbstractGroup texGroupFromString(String string, FileUpdateMonitor String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR); GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken())); try { - Path path = Paths.get(tok.nextToken()); + Path path = Path.of(tok.nextToken()); try { TexGroup newGroup = TexGroup.create(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData); addGroupDetails(tok, newGroup); diff --git a/src/main/java/org/jabref/logic/importer/util/MetaDataParser.java b/src/main/java/org/jabref/logic/importer/util/MetaDataParser.java index ec50a7358e4..146bdf6eddc 100644 --- a/src/main/java/org/jabref/logic/importer/util/MetaDataParser.java +++ b/src/main/java/org/jabref/logic/importer/util/MetaDataParser.java @@ -4,7 +4,6 @@ import java.io.Reader; import java.io.StringReader; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -68,7 +67,7 @@ public MetaData parse(MetaData metaData, Map data, Character key } else if (entry.getKey().startsWith(MetaData.FILE_DIRECTORY + "Latex-")) { // The user name comes directly after "FILE_DIRECTORYLatex-" String user = entry.getKey().substring(MetaData.FILE_DIRECTORY.length() + 6); - Path path = Paths.get(getSingleItem(value)).normalize(); + Path path = Path.of(getSingleItem(value)).normalize(); metaData.setLatexFileDirectory(user, path); continue; } diff --git a/src/main/java/org/jabref/logic/layout/format/FileLink.java b/src/main/java/org/jabref/logic/layout/format/FileLink.java index 6045aca1cd0..4b55170f9d7 100644 --- a/src/main/java/org/jabref/logic/layout/format/FileLink.java +++ b/src/main/java/org/jabref/logic/layout/format/FileLink.java @@ -1,6 +1,6 @@ package org.jabref.logic.layout.format; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -61,7 +61,7 @@ public String format(String field) { dirs = prefs.getFileDirForDatabase(); } - return link.findIn(dirs.stream().map(Paths::get).collect(Collectors.toList())) + return link.findIn(dirs.stream().map(Path::of).collect(Collectors.toList())) .map(path -> path.normalize().toString()) .orElse(link.getLink()); diff --git a/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java b/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java index f59d65f3324..d7787238dbb 100644 --- a/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java +++ b/src/main/java/org/jabref/logic/layout/format/WrapFileLinks.java @@ -1,6 +1,6 @@ package org.jabref.logic.layout.format; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -207,7 +207,7 @@ public String format(String field) { dirs = prefs.getFileDirForDatabase(); } - String pathString = flEntry.findIn(dirs.stream().map(Paths::get).collect(Collectors.toList())) + String pathString = flEntry.findIn(dirs.stream().map(Path::of).collect(Collectors.toList())) .map(path -> path.toAbsolutePath().toString()) .orElse(flEntry.getLink()); diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java index 6a5302e8d7f..e9369087c4a 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficeFileSearch.java @@ -2,7 +2,6 @@ import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -55,26 +54,26 @@ private static List findWindowsOpenOfficeDirs() { // 64-bit program directory String progFiles = System.getenv("ProgramFiles"); if (progFiles != null) { - sourceList.add(Paths.get(progFiles)); + sourceList.add(Path.of(progFiles)); } // 32-bit program directory progFiles = System.getenv("ProgramFiles(x86)"); if (progFiles != null) { - sourceList.add(Paths.get(progFiles)); + sourceList.add(Path.of(progFiles)); } return findOpenOfficeDirectories(sourceList); } private static List findOSXOpenOfficeDirs() { - List sourceList = Collections.singletonList(Paths.get("/Applications")); + List sourceList = Collections.singletonList(Path.of("/Applications")); return findOpenOfficeDirectories(sourceList); } private static List findLinuxOpenOfficeDirs() { - List sourceList = Arrays.asList(Paths.get("/usr/lib"), Paths.get("/usr/lib64"), Paths.get("/opt")); + List sourceList = Arrays.asList(Path.of("/usr/lib"), Path.of("/usr/lib64"), Path.of("/opt")); return findOpenOfficeDirectories(sourceList); } diff --git a/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsList.java b/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsList.java index 5293cc40f69..4b4c09347e5 100644 --- a/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsList.java +++ b/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsList.java @@ -5,7 +5,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.List; import java.util.Objects; @@ -85,7 +84,7 @@ public boolean addProtectedTerm(String term, boolean create) { return false; } - Path p = Paths.get(location); + Path p = Path.of(location); String s = OS.NEWLINE + term; try (BufferedWriter writer = Files.newBufferedWriter(p, StandardCharsets.UTF_8, create ? StandardOpenOption.CREATE : StandardOpenOption.APPEND)) { diff --git a/src/main/java/org/jabref/logic/texparser/DefaultLatexParser.java b/src/main/java/org/jabref/logic/texparser/DefaultLatexParser.java index 5cc3aa7cae1..4e17777ab3d 100644 --- a/src/main/java/org/jabref/logic/texparser/DefaultLatexParser.java +++ b/src/main/java/org/jabref/logic/texparser/DefaultLatexParser.java @@ -10,7 +10,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -63,7 +62,7 @@ public LatexParserResult getLatexParserResult() { @Override public LatexParserResult parse(String citeString) { - matchCitation(Paths.get(""), 1, citeString); + matchCitation(Path.of(""), 1, citeString); return latexParserResult; } diff --git a/src/main/java/org/jabref/logic/util/io/RegExpBasedFileFinder.java b/src/main/java/org/jabref/logic/util/io/RegExpBasedFileFinder.java index 627a00edec9..e68132081ab 100644 --- a/src/main/java/org/jabref/logic/util/io/RegExpBasedFileFinder.java +++ b/src/main/java/org/jabref/logic/util/io/RegExpBasedFileFinder.java @@ -6,7 +6,6 @@ import java.nio.file.FileVisitOption; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collections; @@ -122,7 +121,7 @@ private List findFile(final BibEntry entry, final Path directory, final St String fileName = file; Path actualDirectory; if (fileName.startsWith("/")) { - actualDirectory = Paths.get("."); + actualDirectory = Path.of("."); fileName = fileName.substring(1); } else { actualDirectory = directory; @@ -148,7 +147,7 @@ private List findFile(final BibEntry entry, final Path directory, final St dirToProcess = expandBrackets(dirToProcess, entry, null, keywordDelimiter); if (dirToProcess.matches("^.:$")) { // Windows Drive Letter - actualDirectory = Paths.get(dirToProcess + '/'); + actualDirectory = Path.of(dirToProcess + '/'); continue; } if (".".equals(dirToProcess)) { // Stay in current directory diff --git a/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java b/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java index 1e37920ec3c..b294ec0e13b 100644 --- a/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java +++ b/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java @@ -1,10 +1,8 @@ package org.jabref.logic.xmp; import java.io.ByteArrayInputStream; -import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -50,7 +48,7 @@ public static List readRawXmp(Path path) throws IOException { * @return BibtexEntryies found in the PDF or an empty list */ public static List readXmp(String filename, XmpPreferences xmpPreferences) throws IOException { - return XmpUtilReader.readXmp(Paths.get(filename), xmpPreferences); + return XmpUtilReader.readXmp(Path.of(filename), xmpPreferences); } /** diff --git a/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java b/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java index a98660de29f..e2c62bc8424 100644 --- a/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java +++ b/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java @@ -6,7 +6,6 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -58,7 +57,7 @@ public class XmpUtilWriter { */ public static void writeXmp(String fileName, BibEntry entry, BibDatabase database, XmpPreferences xmpPreferences) throws IOException, TransformerException { - XmpUtilWriter.writeXmp(Paths.get(fileName), entry, database, xmpPreferences); + XmpUtilWriter.writeXmp(Path.of(fileName), entry, database, xmpPreferences); } /** diff --git a/src/main/java/org/jabref/model/database/BibDatabaseContext.java b/src/main/java/org/jabref/model/database/BibDatabaseContext.java index 0d8da113042..f6f56dc5bd7 100644 --- a/src/main/java/org/jabref/model/database/BibDatabaseContext.java +++ b/src/main/java/org/jabref/model/database/BibDatabaseContext.java @@ -2,7 +2,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -138,7 +137,7 @@ public List getFileDirectoriesAsPaths(FilePreferences preferences) { Objects.requireNonNull(dbPath, "dbPath is null"); Path parentPath = dbPath.getParent(); if (parentPath == null) { - parentPath = Paths.get(System.getProperty("user.dir")); + parentPath = Path.of(System.getProperty("user.dir")); } Objects.requireNonNull(parentPath, "BibTeX database parent path is null"); diff --git a/src/main/java/org/jabref/model/entry/LinkedFile.java b/src/main/java/org/jabref/model/entry/LinkedFile.java index f06343a6e7a..74df315442d 100644 --- a/src/main/java/org/jabref/model/entry/LinkedFile.java +++ b/src/main/java/org/jabref/model/entry/LinkedFile.java @@ -8,7 +8,6 @@ import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -180,7 +179,7 @@ public Optional findIn(List directories) { return Optional.empty(); } - Path file = Paths.get(link.get()); + Path file = Path.of(link.get()); if (file.isAbsolute() || directories.isEmpty()) { if (Files.exists(file)) { return Optional.of(file); diff --git a/src/main/java/org/jabref/model/metadata/FilePreferences.java b/src/main/java/org/jabref/model/metadata/FilePreferences.java index efeff249e51..e9274106a75 100644 --- a/src/main/java/org/jabref/model/metadata/FilePreferences.java +++ b/src/main/java/org/jabref/model/metadata/FilePreferences.java @@ -1,7 +1,6 @@ package org.jabref.model.metadata; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import org.jabref.model.strings.StringUtil; @@ -34,7 +33,7 @@ public Optional getFileDirectory() { if (StringUtil.isBlank(mainFileDirectory)) { return Optional.empty(); } else { - return Optional.of(Paths.get(mainFileDirectory)); + return Optional.of(Path.of(mainFileDirectory)); } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 508c533e53f..25ad2561325 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -12,7 +12,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1142,7 +1141,7 @@ private void purgeSeries(String prefix, int number) { * @param filename String File to export to */ public void exportPreferences(String filename) throws JabRefException { - exportPreferences(Paths.get(filename)); + exportPreferences(Path.of(filename)); } public void exportPreferences(Path file) throws JabRefException { @@ -1162,7 +1161,7 @@ public void exportPreferences(Path file) throws JabRefException { * or an IOException */ public void importPreferences(String filename) throws JabRefException { - importPreferences(Paths.get(filename)); + importPreferences(Path.of(filename)); } public void importPreferences(Path file) throws JabRefException { @@ -1190,7 +1189,7 @@ public String getWrappedUsername() { } public FileHistory getFileHistory() { - return new FileHistory(getStringList(RECENT_DATABASES).stream().map(Paths::get).collect(Collectors.toList())); + return new FileHistory(getStringList(RECENT_DATABASES).stream().map(Path::of).collect(Collectors.toList())); } public void storeFileHistory(FileHistory history) { @@ -1695,7 +1694,7 @@ public void storeSpecialFieldsPreferences(SpecialFieldsPreferences specialFields @Override public Path getWorkingDir() { - return Paths.get(get(WORKING_DIRECTORY)); + return Path.of(get(WORKING_DIRECTORY)); } @Override diff --git a/src/test/java/org/jabref/TestIconsProperties.java b/src/test/java/org/jabref/TestIconsProperties.java index a354ba65470..d8198ffd990 100644 --- a/src/test/java/org/jabref/TestIconsProperties.java +++ b/src/test/java/org/jabref/TestIconsProperties.java @@ -4,7 +4,6 @@ import java.io.Reader; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -28,7 +27,7 @@ public void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOEx // load properties Properties properties = new Properties(); - try (Reader reader = Files.newBufferedReader(Paths.get(iconsPropertiesPath))) { + try (Reader reader = Files.newBufferedReader(Path.of(iconsPropertiesPath))) { properties.load(reader); } assertFalse(properties.entrySet().isEmpty(), "There must be loaded properties after loading " + iconsPropertiesPath); @@ -38,7 +37,7 @@ public void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOEx String name = entry.getKey().toString(); String value = entry.getValue().toString(); - assertTrue(Files.exists(Paths.get(folder, value)), "Referenced image (" + name + " --> " + value + " does not exist in folder " + folder); + assertTrue(Files.exists(Path.of(folder, value)), "Referenced image (" + name + " --> " + value + " does not exist in folder " + folder); } // check that each image in the folder is referenced by a key @@ -47,7 +46,7 @@ public void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOEx imagesReferencedFromProperties.add(entry.getValue().toString()); } - try (Stream pathStream = Files.list(Paths.get(folder))) { + try (Stream pathStream = Files.list(Path.of(folder))) { List fileNamesInFolder = pathStream.map(p -> p.getFileName().toString()).collect(Collectors.toList()); fileNamesInFolder.removeAll(imagesReferencedFromProperties); assertEquals("[red.png]", fileNamesInFolder.toString(), "Images are in the folder that are unused"); diff --git a/src/test/java/org/jabref/architecture/MainArchitectureTests.java b/src/test/java/org/jabref/architecture/MainArchitectureTests.java index 042b72a6610..060896c560c 100644 --- a/src/test/java/org/jabref/architecture/MainArchitectureTests.java +++ b/src/test/java/org/jabref/architecture/MainArchitectureTests.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -89,7 +88,7 @@ void firstPackageIsIndependentOfSecondPackage(String firstPackage, String second Predicate isPackage = (s) -> s.startsWith("package " + firstPackage); - try (Stream pathStream = Files.walk(Paths.get("src/main/"))) { + try (Stream pathStream = Files.walk(Path.of("src/main/"))) { List files = pathStream .filter(p -> p.toString().endsWith(".java")) .filter(p -> { diff --git a/src/test/java/org/jabref/architecture/MainArchitectureTestsWithArchUnit.java b/src/test/java/org/jabref/architecture/MainArchitectureTestsWithArchUnit.java index a21e086e326..0ac0430258b 100644 --- a/src/test/java/org/jabref/architecture/MainArchitectureTestsWithArchUnit.java +++ b/src/test/java/org/jabref/architecture/MainArchitectureTestsWithArchUnit.java @@ -1,5 +1,7 @@ package org.jabref.architecture; +import java.nio.file.Paths; + import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchIgnore; @@ -58,4 +60,12 @@ public static void doNotUseAssertJ(JavaClasses classes) { public static void doNotUseJavaAWT(JavaClasses classes) { noClasses().should().accessClassesThat().resideInAPackage("java.awt..").check(classes); } + + @ArchTest + public static void doNotUsePaths(JavaClasses classes) { + noClasses().should() + .accessClassesThat() + .belongToAnyOf(Paths.class) + .check(classes); + } } diff --git a/src/test/java/org/jabref/architecture/TestArchitectureTests.java b/src/test/java/org/jabref/architecture/TestArchitectureTests.java index e7fe93d14fe..809143b0d03 100644 --- a/src/test/java/org/jabref/architecture/TestArchitectureTests.java +++ b/src/test/java/org/jabref/architecture/TestArchitectureTests.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -57,7 +56,7 @@ public void testsAreIndependent(String forbiddenPackage) throws IOException { Predicate isForbiddenPackage = (s) -> s.startsWith("import " + forbiddenPackage); Predicate isExceptionClass = (s) -> exceptions.stream().anyMatch(exception -> s.startsWith("class " + exception)); - try (Stream pathStream = Files.walk(Paths.get("src/test/"))) { + try (Stream pathStream = Files.walk(Path.of("src/test/"))) { List files = pathStream .filter(p -> p.toString().endsWith(".java")) .filter(p -> { diff --git a/src/test/java/org/jabref/cli/AuxCommandLineTest.java b/src/test/java/org/jabref/cli/AuxCommandLineTest.java index c366e54ffba..74531b9c5eb 100644 --- a/src/test/java/org/jabref/cli/AuxCommandLineTest.java +++ b/src/test/java/org/jabref/cli/AuxCommandLineTest.java @@ -6,7 +6,7 @@ import java.io.InputStreamReader; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; +import java.nio.file.Path; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParserResult; @@ -35,7 +35,7 @@ public void setUp() throws Exception { public void test() throws URISyntaxException, IOException { InputStream originalStream = AuxCommandLineTest.class.getResourceAsStream("origin.bib"); - File auxFile = Paths.get(AuxCommandLineTest.class.getResource("paper.aux").toURI()).toFile(); + File auxFile = Path.of(AuxCommandLineTest.class.getResource("paper.aux").toURI()).toFile(); try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) { ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader); diff --git a/src/test/java/org/jabref/gui/util/FileDialogConfigurationTest.java b/src/test/java/org/jabref/gui/util/FileDialogConfigurationTest.java index 5f608f0ef4a..008c8e53638 100644 --- a/src/test/java/org/jabref/gui/util/FileDialogConfigurationTest.java +++ b/src/test/java/org/jabref/gui/util/FileDialogConfigurationTest.java @@ -1,7 +1,6 @@ package org.jabref.gui.util; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import java.util.stream.Collectors; @@ -25,7 +24,7 @@ void testWithValidDirectoryString(@TempDir Path folder) { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .withInitialDirectory(tempFolder).build(); - assertEquals(Optional.of(Paths.get(tempFolder)), fileDialogConfiguration.getInitialDirectory()); + assertEquals(Optional.of(Path.of(tempFolder)), fileDialogConfiguration.getInitialDirectory()); } @Test diff --git a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java index 20f2410cc78..6195936ad35 100644 --- a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java +++ b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java @@ -1,7 +1,6 @@ package org.jabref.logic.autosaveandbackup; import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; @@ -13,9 +12,9 @@ public class BackupManagerTest { @Test public void autosaveFileNameIsCorrectlyGeneratedWithinTmpDirectory() { - Path bibPath = Paths.get("tmp", "test.bib"); + Path bibPath = Path.of("tmp", "test.bib"); Path savPath = BackupManager.getBackupPath(bibPath); - assertEquals(Paths.get("tmp", "test.bib.sav"), savPath); + assertEquals(Path.of("tmp", "test.bib.sav"), savPath); } @Test diff --git a/src/test/java/org/jabref/logic/auxparser/AuxParserTest.java b/src/test/java/org/jabref/logic/auxparser/AuxParserTest.java index b43c5796706..06187f889e0 100644 --- a/src/test/java/org/jabref/logic/auxparser/AuxParserTest.java +++ b/src/test/java/org/jabref/logic/auxparser/AuxParserTest.java @@ -6,7 +6,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import org.jabref.logic.importer.ImportFormatPreferences; @@ -43,7 +42,7 @@ void tearDown() { @Test void testNormal() throws URISyntaxException, IOException { InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib"); - Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI()); + Path auxFile = Path.of(AuxParserTest.class.getResource("paper.aux").toURI()); try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) { ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader); @@ -65,7 +64,7 @@ void testNormal() throws URISyntaxException, IOException { @Test void testNotAllFound() throws URISyntaxException, IOException { InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib"); - Path auxFile = Paths.get(AuxParserTest.class.getResource("badpaper.aux").toURI()); + Path auxFile = Path.of(AuxParserTest.class.getResource("badpaper.aux").toURI()); try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) { ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader); @@ -87,7 +86,7 @@ void testNotAllFound() throws URISyntaxException, IOException { @Test void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException { InputStream originalStream = AuxParserTest.class.getResourceAsStream("config.bib"); - Path auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI()); + Path auxFile = Path.of(AuxParserTest.class.getResource("paper.aux").toURI()); try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) { ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader); @@ -103,7 +102,7 @@ void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException @Test void testNestedAux() throws URISyntaxException, IOException { InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib"); - Path auxFile = Paths.get(AuxParserTest.class.getResource("nested.aux").toURI()); + Path auxFile = Path.of(AuxParserTest.class.getResource("nested.aux").toURI()); try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) { ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader); @@ -125,7 +124,7 @@ void testNestedAux() throws URISyntaxException, IOException { @Test void testCrossRef() throws URISyntaxException, IOException { InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib"); - Path auxFile = Paths.get(AuxParserTest.class.getResource("crossref.aux").toURI()); + Path auxFile = Path.of(AuxParserTest.class.getResource("crossref.aux").toURI()); try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) { ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader); @@ -147,7 +146,7 @@ void testCrossRef() throws URISyntaxException, IOException { @Test void testFileNotFound() { AuxParser auxParser = new DefaultAuxParser(new BibDatabase()); - AuxParserResult auxResult = auxParser.parse(Paths.get("unknownfile.aux")); + AuxParserResult auxResult = auxParser.parse(Path.of("unknownfile.aux")); assertFalse(auxResult.getGeneratedBibDatabase().hasEntries()); assertEquals(0, auxResult.getUnresolvedKeysCount()); diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryAssert.java b/src/test/java/org/jabref/logic/bibtex/BibEntryAssert.java index 9d4cc943661..4de24b84d50 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryAssert.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryAssert.java @@ -8,7 +8,6 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -125,7 +124,7 @@ public static void assertEquals(InputStream expectedIs, Path fileToImport, Impor public static void assertEquals(InputStream expectedIs, URL fileToImport, Importer importer) throws URISyntaxException, IOException { - assertEquals(expectedIs, Paths.get(fileToImport.toURI()), importer); + assertEquals(expectedIs, Path.of(fileToImport.toURI()), importer); } /** @@ -147,6 +146,6 @@ public static void assertEquals(List expected, Path fileToImport, Impo public static void assertEquals(List expected, URL fileToImport, Importer importer) throws URISyntaxException, IOException { - assertEquals(expected, Paths.get(fileToImport.toURI()), importer); + assertEquals(expected, Path.of(fileToImport.toURI()), importer); } } diff --git a/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java b/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java index 945d5294abe..5e051fcbaac 100644 --- a/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java +++ b/src/test/java/org/jabref/logic/bst/BstPreviewLayoutTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.bst; -import java.nio.file.Paths; +import java.nio.file.Path; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; @@ -14,11 +14,11 @@ class BstPreviewLayoutTest { - private BibDatabase bibDatabase = mock(BibDatabase.class); + private final BibDatabase bibDatabase = mock(BibDatabase.class); @Test public void generatePreviewForSimpleEntryUsingAbbr() throws Exception { - BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Paths.get(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "Oliver Kopp") .withField(StandardField.TITLE, "Thoughts on Development"); BibDatabase bibDatabase = mock(BibDatabase.class); @@ -28,7 +28,7 @@ public void generatePreviewForSimpleEntryUsingAbbr() throws Exception { @Test public void monthMayIsCorrectlyRendered() throws Exception { - BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Paths.get(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "Oliver Kopp") .withField(StandardField.TITLE, "Thoughts on Development") .withField(StandardField.MONTH, "#May#"); @@ -39,14 +39,14 @@ public void monthMayIsCorrectlyRendered() throws Exception { @Test public void generatePreviewForSliceTheoremPaperUsingAbbr() throws Exception { - BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Paths.get(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(BstPreviewLayoutTest.class.getResource("abbrv.bst").toURI())); String preview = bstPreviewLayout.generatePreview(getSliceTheoremPaper(), bibDatabase); assertEquals("T. Diez. Slice theorem for fréchet group actions and covariant symplectic field theory. May 2014.", preview); } @Test public void generatePreviewForSliceTheoremPaperUsingIEEE() throws Exception { - BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Paths.get(ClassLoader.getSystemResource("bst/IEEEtran.bst").toURI())); + BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(Path.of(ClassLoader.getSystemResource("bst/IEEEtran.bst").toURI())); String preview = bstPreviewLayout.generatePreview(getSliceTheoremPaper(), bibDatabase); assertEquals("T. Diez, \"Slice theorem for fréchet group actions and covariant symplectic field theory\" May 2014.", preview); } diff --git a/src/test/java/org/jabref/logic/exporter/BibTeXMLExporterTestFiles.java b/src/test/java/org/jabref/logic/exporter/BibTeXMLExporterTestFiles.java index a1513a6ee9f..2e8bfa1d5a5 100644 --- a/src/test/java/org/jabref/logic/exporter/BibTeXMLExporterTestFiles.java +++ b/src/test/java/org/jabref/logic/exporter/BibTeXMLExporterTestFiles.java @@ -6,7 +6,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -41,7 +40,7 @@ public class BibTeXMLExporterTestFiles { public BibtexImporter testImporter; public static Stream fileNames() throws IOException, URISyntaxException { - resourceDir = Paths.get(MSBibExportFormatTestFiles.class.getResource("BibTeXMLExporterTestArticle.bib").toURI()).getParent(); + resourceDir = Path.of(MSBibExportFormatTestFiles.class.getResource("BibTeXMLExporterTestArticle.bib").toURI()).getParent(); try (Stream stream = Files.list(resourceDir)) { return stream.map(n -> n.getFileName().toString()).filter(n -> n.endsWith(".bib")) @@ -72,7 +71,7 @@ public final void testPerformExport(String filename) throws IOException, SaveExc bibtexmlExportFormat.export(databaseContext, tempFile, charset, entries); Builder control = Input.from(Files.newInputStream(resourceDir.resolve(xmlFileName))); - Builder test = Input.from(Files.newInputStream(Paths.get(tempFilePath))); + Builder test = Input.from(Files.newInputStream(Path.of(tempFilePath))); assertThat(test, CompareMatcher.isSimilarTo(control) .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure()); diff --git a/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 2571926d578..6d3c6231aef 100644 --- a/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -7,7 +7,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -326,7 +325,7 @@ void writeCustomizedTypesInAlphabeticalOrder() throws Exception { @Test void roundtripWithArticleMonths() throws Exception { - Path testBibtexFile = Paths.get("src/test/resources/testbib/articleWithMonths.bib"); + Path testBibtexFile = Path.of("src/test/resources/testbib/articleWithMonths.bib"); Charset encoding = StandardCharsets.UTF_8; ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); @@ -340,7 +339,7 @@ void roundtripWithArticleMonths() throws Exception { @Test void roundtripWithComplexBib() throws Exception { - Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib"); + Path testBibtexFile = Path.of("src/test/resources/testbib/complex.bib"); Charset encoding = StandardCharsets.UTF_8; ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); @@ -354,7 +353,7 @@ void roundtripWithComplexBib() throws Exception { @Test void roundtripWithUserComment() throws Exception { - Path testBibtexFile = Paths.get("src/test/resources/testbib/bibWithUserComments.bib"); + Path testBibtexFile = Path.of("src/test/resources/testbib/bibWithUserComments.bib"); Charset encoding = StandardCharsets.UTF_8; ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); @@ -368,7 +367,7 @@ void roundtripWithUserComment() throws Exception { @Test void roundtripWithUserCommentAndEntryChange() throws Exception { - Path testBibtexFile = Paths.get("src/test/resources/testbib/bibWithUserComments.bib"); + Path testBibtexFile = Path.of("src/test/resources/testbib/bibWithUserComments.bib"); Charset encoding = StandardCharsets.UTF_8; ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); @@ -380,12 +379,12 @@ void roundtripWithUserCommentAndEntryChange() throws Exception { BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData()); databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries()); - assertEquals(Files.readString(Paths.get("src/test/resources/testbib/bibWithUserCommentAndEntryChange.bib"), encoding), stringWriter.toString()); + assertEquals(Files.readString(Path.of("src/test/resources/testbib/bibWithUserCommentAndEntryChange.bib"), encoding), stringWriter.toString()); } @Test void roundtripWithUserCommentBeforeStringAndChange() throws Exception { - Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib"); + Path testBibtexFile = Path.of("src/test/resources/testbib/complex.bib"); Charset encoding = StandardCharsets.UTF_8; ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); @@ -405,7 +404,7 @@ void roundtripWithUserCommentBeforeStringAndChange() throws Exception { @Test void roundtripWithUnknownMetaData() throws Exception { - Path testBibtexFile = Paths.get("src/test/resources/testbib/unknownMetaData.bib"); + Path testBibtexFile = Path.of("src/test/resources/testbib/unknownMetaData.bib"); Charset encoding = StandardCharsets.UTF_8; ParserResult result = new BibtexParser(importFormatPreferences, fileMonitor).parse(Importer.getReader(testBibtexFile, encoding)); @@ -547,7 +546,7 @@ void writeProtectedFlag() throws Exception { void writeFileDirectories() throws Exception { metaData.setDefaultFileDirectory("\\Literature\\"); metaData.setUserFileDirectory("defaultOwner-user", "D:\\Documents"); - metaData.setLatexFileDirectory("defaultOwner-user", Paths.get("D:\\Latex")); + metaData.setLatexFileDirectory("defaultOwner-user", Path.of("D:\\Latex")); databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList()); diff --git a/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java index d732c561bed..65cb06219ae 100644 --- a/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java @@ -5,7 +5,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; @@ -42,7 +41,7 @@ public class DocBook5ExporterTest { @BeforeEach void setUp() throws URISyntaxException { - xmlFile = Paths.get(DocBook5ExporterTest.class.getResource("Docbook5ExportFormat.xml").toURI()); + xmlFile = Path.of(DocBook5ExporterTest.class.getResource("Docbook5ExportFormat.xml").toURI()); List customFormats = new ArrayList<>(); LayoutFormatterPreferences layoutPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); diff --git a/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java b/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java index 0fd1b473e1e..4c1bc3147fb 100644 --- a/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java +++ b/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.exporter; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -117,7 +117,7 @@ void serializeSingleAutomaticPersonGroup() { @Test void serializeSingleTexGroup() throws Exception { - TexGroup group = TexGroup.createWithoutFileMonitoring("myTexGroup", GroupHierarchyType.INDEPENDENT, Paths.get("path", "To", "File"), new DefaultAuxParser(new BibDatabase()), new DummyFileUpdateMonitor(), new MetaData()); + TexGroup group = TexGroup.createWithoutFileMonitoring("myTexGroup", GroupHierarchyType.INDEPENDENT, Path.of("path", "To", "File"), new DefaultAuxParser(new BibDatabase()), new DummyFileUpdateMonitor(), new MetaData()); List serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group)); assertEquals(Collections.singletonList("0 TexGroup:myTexGroup;0;path/To/File;1;;;;"), serialization); } diff --git a/src/test/java/org/jabref/logic/exporter/MSBibExportFormatTestFiles.java b/src/test/java/org/jabref/logic/exporter/MSBibExportFormatTestFiles.java index 190d65a22f6..b5791ce3076 100644 --- a/src/test/java/org/jabref/logic/exporter/MSBibExportFormatTestFiles.java +++ b/src/test/java/org/jabref/logic/exporter/MSBibExportFormatTestFiles.java @@ -6,7 +6,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,7 +39,7 @@ public class MSBibExportFormatTestFiles { static Stream fileNames() throws IOException, URISyntaxException { // we have to point it to one existing file, otherwise it will return the default class path - resourceDir = Paths.get(MSBibExportFormatTestFiles.class.getResource("MsBibExportFormatTest1.bib").toURI()).getParent(); + resourceDir = Path.of(MSBibExportFormatTestFiles.class.getResource("MsBibExportFormatTest1.bib").toURI()).getParent(); try (Stream stream = Files.list(resourceDir)) { return stream.map(n -> n.getFileName().toString()) .filter(n -> n.endsWith(".bib")) diff --git a/src/test/java/org/jabref/logic/exporter/ModsExportFormatTest.java b/src/test/java/org/jabref/logic/exporter/ModsExportFormatTest.java index 65ae6465295..d205b4ce235 100644 --- a/src/test/java/org/jabref/logic/exporter/ModsExportFormatTest.java +++ b/src/test/java/org/jabref/logic/exporter/ModsExportFormatTest.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import org.jabref.logic.importer.ImportFormatPreferences; @@ -32,7 +31,7 @@ public void setUp() throws Exception { charset = StandardCharsets.UTF_8; modsExportFormat = new ModsExporter(); new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor()); - Paths.get(ModsExportFormatTest.class.getResource("ModsExportFormatTestAllFields.bib").toURI()); + Path.of(ModsExportFormatTest.class.getResource("ModsExportFormatTestAllFields.bib").toURI()); } @Test diff --git a/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java b/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java index a08598fea18..5820f344daa 100644 --- a/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java +++ b/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -39,7 +38,7 @@ public class ModsExportFormatTestFiles { private Path importFile; public static Stream fileNames() throws Exception { - resourceDir = Paths.get(MSBibExportFormatTestFiles.class.getResource("ModsExportFormatTestAllFields.bib").toURI()).getParent(); + resourceDir = Path.of(MSBibExportFormatTestFiles.class.getResource("ModsExportFormatTestAllFields.bib").toURI()).getParent(); System.out.println(resourceDir); try (Stream stream = Files.list(resourceDir)) { @@ -66,10 +65,10 @@ public void setUp(@TempDir Path testFolder) throws Exception { @ParameterizedTest @MethodSource("fileNames") public final void testPerformExport(String filename) throws Exception { - importFile = Paths.get(ModsExportFormatTestFiles.class.getResource(filename).toURI()); + importFile = Path.of(ModsExportFormatTestFiles.class.getResource(filename).toURI()); String xmlFileName = filename.replace(".bib", ".xml"); List entries = bibtexImporter.importDatabase(importFile, charset).getDatabase().getEntries(); - Path expectedFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI()); + Path expectedFile = Path.of(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI()); exporter.export(databaseContext, exportedFile, charset, entries); @@ -81,7 +80,7 @@ public final void testPerformExport(String filename) throws Exception { @ParameterizedTest @MethodSource("fileNames") public final void testExportAsModsAndThenImportAsMods(String filename) throws Exception { - importFile = Paths.get(ModsExportFormatTestFiles.class.getResource(filename).toURI()); + importFile = Path.of(ModsExportFormatTestFiles.class.getResource(filename).toURI()); List entries = bibtexImporter.importDatabase(importFile, charset).getDatabase().getEntries(); exporter.export(databaseContext, exportedFile, charset, entries); @@ -91,9 +90,9 @@ public final void testExportAsModsAndThenImportAsMods(String filename) throws Ex @ParameterizedTest @MethodSource("fileNames") public final void testImportAsModsAndExportAsMods(String filename) throws Exception { - importFile = Paths.get(ModsExportFormatTestFiles.class.getResource(filename).toURI()); + importFile = Path.of(ModsExportFormatTestFiles.class.getResource(filename).toURI()); String xmlFileName = filename.replace(".bib", ".xml"); - Path xmlFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI()); + Path xmlFile = Path.of(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI()); List entries = modsImporter.importDatabase(xmlFile, charset).getDatabase().getEntries(); diff --git a/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java b/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java index 120d27f8638..e636e1135cd 100644 --- a/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -135,7 +134,7 @@ public void writeMultipleEntriesInDifferentFiles(@TempDir Path testFolder) throw List lines = Files.readAllLines(file); assertEquals(Collections.emptyList(), lines); - Path fileTuring = Paths.get(file.getParent().toString(), entryTuring.getId() + "_null.xmp"); + Path fileTuring = Path.of(file.getParent().toString(), entryTuring.getId() + "_null.xmp"); String actualTuring = String.join("\n", Files.readAllLines(fileTuring)); // we are using \n to join, so we need it in the expected string as well, \r\n would fail String expectedTuring = " \n" + @@ -156,7 +155,7 @@ public void writeMultipleEntriesInDifferentFiles(@TempDir Path testFolder) throw assertEquals(expectedTuring, actualTuring); - Path fileArmbrust = Paths.get(file.getParent().toString(), entryArmbrust.getId() + "_Armbrust2010.xmp"); + Path fileArmbrust = Path.of(file.getParent().toString(), entryArmbrust.getId() + "_Armbrust2010.xmp"); String actualArmbrust = String.join("\n", Files.readAllLines(fileArmbrust)); // we are using \n to join, so we need it in the expected string as well, \r\n would fail String expectedArmbrust = " \n" + diff --git a/src/test/java/org/jabref/logic/importer/ImportDataTest.java b/src/test/java/org/jabref/logic/importer/ImportDataTest.java index 3a3fbb98c36..3aa278a5a42 100644 --- a/src/test/java/org/jabref/logic/importer/ImportDataTest.java +++ b/src/test/java/org/jabref/logic/importer/ImportDataTest.java @@ -2,7 +2,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; @@ -11,12 +10,12 @@ public class ImportDataTest { - public static final Path FILE_IN_DATABASE = Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/pdfInDatabase.pdf"); - public static final Path FILE_NOT_IN_DATABASE = Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/pdfNotInDatabase.pdf"); - public static final Path EXISTING_FOLDER = Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder"); - public static final Path NOT_EXISTING_FOLDER = Paths.get("notexistingfolder"); - public static final Path NOT_EXISTING_PDF = Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/null.pdf"); - public static final Path UNLINKED_FILES_TEST_BIB = Paths.get("src/test/resources/org/jabref/util/unlinkedFilesTestBib.bib"); + public static final Path FILE_IN_DATABASE = Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/pdfInDatabase.pdf"); + public static final Path FILE_NOT_IN_DATABASE = Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/pdfNotInDatabase.pdf"); + public static final Path EXISTING_FOLDER = Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder"); + public static final Path NOT_EXISTING_FOLDER = Path.of("notexistingfolder"); + public static final Path NOT_EXISTING_PDF = Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/null.pdf"); + public static final Path UNLINKED_FILES_TEST_BIB = Path.of("src/test/resources/org/jabref/util/unlinkedFilesTestBib.bib"); /** * Tests the testing environment. diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java index 0550e3b8ec3..ebeafccdae0 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java @@ -3,7 +3,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.stream.Stream; @@ -35,7 +34,7 @@ void setUp() { @ParameterizedTest @MethodSource("importFormats") void testImportUnknownFormat(String resource, String format, int count) throws Exception { - Path file = Paths.get(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); + Path file = Path.of(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); ImportFormatReader.UnknownFormatImport unknownFormat = reader.importUnknownFormat(file, new DummyFileUpdateMonitor()); assertEquals(count, unknownFormat.parserResult.getDatabase().getEntryCount()); } @@ -43,14 +42,14 @@ void testImportUnknownFormat(String resource, String format, int count) throws E @ParameterizedTest @MethodSource("importFormats") void testImportFormatFromFile(String resource, String format, int count) throws Exception { - Path file = Paths.get(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); + Path file = Path.of(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); assertEquals(count, reader.importFromFile(format, file).getDatabase().getEntries().size()); } @ParameterizedTest @MethodSource("importFormats") void testImportUnknownFormatFromString(String resource, String format, int count) throws Exception { - Path file = Paths.get(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); + Path file = Path.of(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); String data = new String(Files.readAllBytes(file), StandardCharsets.UTF_8); assertEquals(count, reader.importUnknownFormat(data).parserResult.getDatabase().getEntries().size()); } diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java index 9ddc2962ef0..3a6230a1701 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java @@ -2,7 +2,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.util.DummyFileUpdateMonitor; @@ -31,7 +30,7 @@ void setUp() { @Test void importUnknownFormatThrowsExceptionIfNoMatchingImporterWasFound() throws Exception { - Path file = Paths.get(ImportFormatReaderTestParameterless.class.getResource("fileformat/emptyFile.xml").toURI()); + Path file = Path.of(ImportFormatReaderTestParameterless.class.getResource("fileformat/emptyFile.xml").toURI()); assertThrows(ImportException.class, () -> reader.importUnknownFormat(file, fileMonitor)); } @@ -47,6 +46,6 @@ void importUnknownFormatThrowsExceptionIfDataIsNull() throws Exception { @Test void importFromFileWithUnknownFormatThrowsException() throws Exception { - assertThrows(ImportException.class, () -> reader.importFromFile("someunknownformat", Paths.get("somepath"))); + assertThrows(ImportException.class, () -> reader.importFromFile("someunknownformat", Path.of("somepath"))); } } diff --git a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java index ddc83596db2..10df92ac461 100644 --- a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java +++ b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java @@ -35,10 +35,10 @@ class OpenDatabaseTest { private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); OpenDatabaseTest() throws URISyntaxException { - bibNoHeader = Paths.get(OpenDatabaseTest.class.getResource("headerless.bib").toURI()); - bibWrongHeader = Paths.get(OpenDatabaseTest.class.getResource("wrong-header.bib").toURI()); - bibHeader = Paths.get(OpenDatabaseTest.class.getResource("encoding-header.bib").toURI()); - bibHeaderAndSignature = Paths.get(OpenDatabaseTest.class.getResource("jabref-header.bib").toURI()); + bibNoHeader = Path.of(OpenDatabaseTest.class.getResource("headerless.bib").toURI()); + bibWrongHeader = Path.of(OpenDatabaseTest.class.getResource("wrong-header.bib").toURI()); + bibHeader = Path.of(OpenDatabaseTest.class.getResource("encoding-header.bib").toURI()); + bibHeaderAndSignature = Path.of(OpenDatabaseTest.class.getResource("jabref-header.bib").toURI()); bibEncodingWithoutNewline = Paths .get(OpenDatabaseTest.class.getResource("encodingWithoutNewline.bib").toURI()); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java index 2ee415b14ab..5fa5ab65a1e 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java @@ -2,7 +2,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import org.jabref.logic.util.StandardFileType; @@ -44,7 +43,7 @@ public void testGetCLIID() { @Test public void testImportEntriesAbortion() throws Throwable { - Path file = Paths.get(BiblioscapeImporter.class.getResource("BiblioscapeImporterTestCorrupt.txt").toURI()); + Path file = Path.of(BiblioscapeImporter.class.getResource("BiblioscapeImporterTestCorrupt.txt").toURI()); assertEquals(Collections.emptyList(), importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries()); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java index d50c23875cd..27ab50eb6db 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java @@ -4,7 +4,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Optional; @@ -39,13 +38,13 @@ public void setUp() { @Test public void testIsRecognizedFormat() throws IOException, URISyntaxException { - Path file = Paths.get(BibtexImporterTest.class.getResource("BibtexImporter.examples.bib").toURI()); + Path file = Path.of(BibtexImporterTest.class.getResource("BibtexImporter.examples.bib").toURI()); assertTrue(importer.isRecognizedFormat(file, StandardCharsets.UTF_8)); } @Test public void testImportEntries() throws IOException, URISyntaxException { - Path file = Paths.get(BibtexImporterTest.class.getResource("BibtexImporter.examples.bib").toURI()); + Path file = Path.of(BibtexImporterTest.class.getResource("BibtexImporter.examples.bib").toURI()); List bibEntries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(4, bibEntries.size()); @@ -124,7 +123,7 @@ public void testGetDescription() { @Test public void testRecognizesDatabaseID() throws Exception { - Path file = Paths.get(BibtexImporterTest.class.getResource("AutosavedSharedDatabase.bib").toURI()); + Path file = Path.of(BibtexImporterTest.class.getResource("AutosavedSharedDatabase.bib").toURI()); String sharedDatabaseID = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getSharedDatabaseID().get(); assertEquals("13ceoc8dm42f5g1iitao3dj2ap", sharedDatabaseID); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTest.java index 262291911d8..9955c85fa76 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTest.java @@ -2,7 +2,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -35,7 +34,7 @@ public void testGetDescription() { @Test public void testImportEmptyEntries() throws Exception { - Path path = Paths.get(CopacImporterTest.class.getResource("Empty.txt").toURI()); + Path path = Path.of(CopacImporterTest.class.getResource("Empty.txt").toURI()); List entries = importer.importDatabase(path, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(Collections.emptyList(), entries); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/CustomImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/CustomImporterTest.java index 529d770234e..607cca2c61c 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/CustomImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/CustomImporterTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.importer.fileformat; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Arrays; import org.jabref.logic.importer.Importer; @@ -37,7 +37,7 @@ public void testGetClassName() { @Test public void testGetBasePath() { - assertEquals(Paths.get("src/main/java/org/jabref/logic/importer/fileformat/CopacImporter.java"), + assertEquals(Path.of("src/main/java/org/jabref/logic/importer/fileformat/CopacImporter.java"), importer.getBasePath()); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/EndnoteImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/EndnoteImporterTest.java index de1bb49f04e..78d2d54795f 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/EndnoteImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/EndnoteImporterTest.java @@ -7,7 +7,6 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -62,7 +61,7 @@ public void testIsRecognizedFormat() throws IOException, URISyntaxException { List list = Arrays.asList("Endnote.pattern.A.enw", "Endnote.pattern.E.enw", "Endnote.book.example.enw"); for (String string : list) { - Path file = Paths.get(EndnoteImporterTest.class.getResource(string).toURI()); + Path file = Path.of(EndnoteImporterTest.class.getResource(string).toURI()); assertTrue(importer.isRecognizedFormat(file, StandardCharsets.UTF_8)); } } @@ -74,14 +73,14 @@ public void testIsRecognizedFormatReject() throws IOException, URISyntaxExceptio "Endnote.pattern.no_enw", "empty.pdf", "annotated.pdf"); for (String string : list) { - Path file = Paths.get(EndnoteImporterTest.class.getResource(string).toURI()); + Path file = Path.of(EndnoteImporterTest.class.getResource(string).toURI()); assertFalse(importer.isRecognizedFormat(file, Charset.defaultCharset())); } } @Test public void testImportEntries0() throws IOException, URISyntaxException { - Path file = Paths.get(EndnoteImporterTest.class.getResource("Endnote.entries.enw").toURI()); + Path file = Path.of(EndnoteImporterTest.class.getResource("Endnote.entries.enw").toURI()); List bibEntries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(5, bibEntries.size()); @@ -141,7 +140,7 @@ public void testImportEntries1() throws IOException { @Test public void testImportEntriesBookExample() throws IOException, URISyntaxException { - Path file = Paths.get(EndnoteImporterTest.class.getResource("Endnote.book.example.enw").toURI()); + Path file = Path.of(EndnoteImporterTest.class.getResource("Endnote.book.example.enw").toURI()); List bibEntries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry entry = bibEntries.get(0); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java b/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java index 00e6b6aef81..010ad110236 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java @@ -5,7 +5,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -33,7 +32,7 @@ public class ImporterTestEngine { * @throws IOException if there is a problem when trying to read the files in the file system */ public static Collection getTestFiles(Predicate fileNamePredicate) throws IOException { - try (Stream stream = Files.list(Paths.get(TEST_RESOURCES))) { + try (Stream stream = Files.list(Path.of(TEST_RESOURCES))) { return stream .map(path -> path.getFileName().toString()) .filter(fileNamePredicate) @@ -61,7 +60,7 @@ public static void testImportEntries(Importer importer, String fileName, String private static Path getPath(String fileName) throws IOException { try { - return Paths.get(ImporterTestEngine.class.getResource(fileName).toURI()); + return Path.of(ImporterTestEngine.class.getResource(fileName).toURI()); } catch (URISyntaxException e) { throw new IOException(e); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java index e470436f40d..f71618c1afb 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java @@ -4,7 +4,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Optional; @@ -127,7 +126,7 @@ public void testProcessSubSup() { @Test public void testImportEntries1() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTest1.isi").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IsiImporterTest1.isi").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry entry = entries.get(0); @@ -148,7 +147,7 @@ public void testImportEntries1() throws IOException, URISyntaxException { @Test public void testImportEntries2() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTest2.isi").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IsiImporterTest2.isi").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry entry = entries.get(0); @@ -165,7 +164,7 @@ public void testImportEntries2() throws IOException, URISyntaxException { @Test public void testImportEntriesINSPEC() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTestInspec.isi").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IsiImporterTestInspec.isi").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry first = entries.get(0); @@ -202,7 +201,7 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { @Test public void testImportEntriesWOS() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTestWOS.isi").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IsiImporterTestWOS.isi").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry first = entries.get(0); @@ -258,7 +257,7 @@ public void testIsiAuthorConvert() { @Test public void testImportIEEEExport() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IEEEImport1.txt").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IEEEImport1.txt").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry entry = entries.get(0); @@ -281,7 +280,7 @@ public void testImportIEEEExport() throws IOException, URISyntaxException { @Test public void testIEEEImport() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IEEEImport1.txt").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IEEEImport1.txt").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry entry = entries.get(0); @@ -305,7 +304,7 @@ public void testIEEEImport() throws IOException, URISyntaxException { @Test public void testImportEntriesMedline() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTestMedline.isi").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IsiImporterTestMedline.isi").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry first = entries.get(0); @@ -341,7 +340,7 @@ public void testImportEntriesMedline() throws IOException, URISyntaxException { @Test public void testImportEntriesEmpty() throws IOException, URISyntaxException { - Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTestEmpty.isi").toURI()); + Path file = Path.of(IsiImporterTest.class.getResource("IsiImporterTestEmpty.isi").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java index df725f8d1e4..1a13480a197 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java @@ -146,7 +146,7 @@ void testImportSingleEntriesInSingleFiles() throws IOException, URISyntaxExcepti private void assertImportOfMedlineFileEqualsBibtexFile(String medlineFile, String bibtexFile) throws IOException, URISyntaxException { - Path file = Paths.get(MedlinePlainImporter.class.getResource(medlineFile).toURI()); + Path file = Path.of(MedlinePlainImporter.class.getResource(medlineFile).toURI()); try (InputStream nis = MedlinePlainImporter.class.getResourceAsStream(bibtexFile)) { List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); @@ -189,7 +189,7 @@ void testKeyWords() throws IOException { @Test void testWithNbibFile() throws IOException, URISyntaxException { - Path file = Paths.get(MedlinePlainImporter.class.getResource("NbibImporterTest.nbib").toURI()); + Path file = Path.of(MedlinePlainImporter.class.getResource("NbibImporterTest.nbib").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MsBibImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MsBibImporterTest.java index 56cfec29750..beaeb16c49f 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MsBibImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MsBibImporterTest.java @@ -4,7 +4,6 @@ import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -37,7 +36,7 @@ public final void testIsNotRecognizedFormat() throws Exception { List notAccepted = Arrays.asList("CopacImporterTest1.txt", "IsiImporterTest1.isi", "IsiImporterTestInspec.isi", "emptyFile.xml", "IsiImporterTestWOS.isi"); for (String s : notAccepted) { - Path file = Paths.get(MsBibImporter.class.getResource(s).toURI()); + Path file = Path.of(MsBibImporter.class.getResource(s).toURI()); assertFalse(testImporter.isRecognizedFormat(file, Charset.defaultCharset())); } } @@ -45,7 +44,7 @@ public final void testIsNotRecognizedFormat() throws Exception { @Test public final void testImportEntriesEmpty() throws IOException, URISyntaxException { MsBibImporter testImporter = new MsBibImporter(); - Path file = Paths.get(MsBibImporter.class.getResource("EmptyMsBib_Test.xml").toURI()); + Path file = Path.of(MsBibImporter.class.getResource("EmptyMsBib_Test.xml").toURI()); List entries = testImporter.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); assertEquals(Collections.emptyList(), entries); } @@ -53,7 +52,7 @@ public final void testImportEntriesEmpty() throws IOException, URISyntaxExceptio @Test public final void testImportEntriesNotRecognizedFormat() throws IOException, URISyntaxException { MsBibImporter testImporter = new MsBibImporter(); - Path file = Paths.get(MsBibImporter.class.getResource("CopacImporterTest1.txt").toURI()); + Path file = Path.of(MsBibImporter.class.getResource("CopacImporterTest1.txt").toURI()); List entries = testImporter.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); assertEquals(0, entries.size()); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/OvidImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/OvidImporterTest.java index b3ea3c95c33..695ca2e9d7b 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/OvidImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/OvidImporterTest.java @@ -5,7 +5,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -83,14 +82,14 @@ public void testIsRecognizedFormatRejected(String fileName) throws IOException, @Test public void testImportEmpty() throws IOException, URISyntaxException { - Path file = Paths.get(OvidImporter.class.getResource("Empty.txt").toURI()); + Path file = Path.of(OvidImporter.class.getResource("Empty.txt").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(Collections.emptyList(), entries); } @Test public void testImportEntries1() throws IOException, URISyntaxException { - Path file = Paths.get(OvidImporter.class.getResource("OvidImporterTest1.txt").toURI()); + Path file = Path.of(OvidImporter.class.getResource("OvidImporterTest1.txt").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(5, entries.size()); @@ -143,7 +142,7 @@ public void testImportEntries1() throws IOException, URISyntaxException { @Test public void testImportEntries2() throws IOException, URISyntaxException { - Path file = Paths.get(OvidImporter.class.getResource("OvidImporterTest2Invalid.txt").toURI()); + Path file = Path.of(OvidImporter.class.getResource("OvidImporterTest2Invalid.txt").toURI()); List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(Collections.emptyList(), entries); } @@ -152,7 +151,7 @@ public void testImportEntries2() throws IOException, URISyntaxException { public void testImportSingleEntries() throws IOException, URISyntaxException { for (int n = 3; n <= 7; n++) { - Path file = Paths.get(OvidImporter.class.getResource("OvidImporterTest" + n + ".txt").toURI()); + Path file = Path.of(OvidImporter.class.getResource("OvidImporterTest" + n + ".txt").toURI()); try (InputStream nis = OvidImporter.class.getResourceAsStream("OvidImporterTestBib" + n + ".bib")) { List entries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase() .getEntries(); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java index 6a1c7b2b2e4..2a8cacefe20 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTest.java @@ -2,7 +2,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -42,14 +41,14 @@ void testGetDescription() { @Test void doesNotHandleEncryptedPdfs() throws Exception { - Path file = Paths.get(PdfContentImporter.class.getResource("/pdfs/encrypted.pdf").toURI()); + Path file = Path.of(PdfContentImporter.class.getResource("/pdfs/encrypted.pdf").toURI()); List result = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(Collections.emptyList(), result); } @Test void importTwiceWorksAsExpected() throws Exception { - Path file = Paths.get(PdfContentImporter.class.getResource("/pdfs/minimal.pdf").toURI()); + Path file = Path.of(PdfContentImporter.class.getResource("/pdfs/minimal.pdf").toURI()); List result = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); BibEntry expected = new BibEntry(StandardEntryType.InProceedings); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfXmpImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfXmpImporterTest.java index 0c08ada81c6..d76c05b520a 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfXmpImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfXmpImporterTest.java @@ -4,7 +4,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Optional; import java.util.function.Predicate; @@ -56,14 +55,14 @@ public void testGetDescription() { @Test public void importEncryptedFileReturnsError() throws URISyntaxException { - Path file = Paths.get(PdfXmpImporterTest.class.getResource("/pdfs/encrypted.pdf").toURI()); + Path file = Path.of(PdfXmpImporterTest.class.getResource("/pdfs/encrypted.pdf").toURI()); ParserResult result = importer.importDatabase(file, StandardCharsets.UTF_8); assertTrue(result.hasWarnings()); } @Test public void testImportEntries() throws URISyntaxException { - Path file = Paths.get(PdfXmpImporterTest.class.getResource("annotated.pdf").toURI()); + Path file = Path.of(PdfXmpImporterTest.class.getResource("annotated.pdf").toURI()); List bibEntries = importer.importDatabase(file, StandardCharsets.UTF_8).getDatabase().getEntries(); assertEquals(1, bibEntries.size()); @@ -77,7 +76,7 @@ public void testImportEntries() throws URISyntaxException { @Test public void testIsRecognizedFormat() throws IOException, URISyntaxException { - Path file = Paths.get(PdfXmpImporterTest.class.getResource("annotated.pdf").toURI()); + Path file = Path.of(PdfXmpImporterTest.class.getResource("annotated.pdf").toURI()); assertTrue(importer.isRecognizedFormat(file, StandardCharsets.UTF_8)); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTest.java index 7e46c83d27f..c086370b0ae 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTest.java @@ -4,7 +4,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import org.jabref.logic.util.StandardFileType; @@ -45,7 +44,7 @@ public void testGetDescription() { @Test public void testIfNotRecognizedFormat() throws IOException, URISyntaxException { - Path file = Paths.get(RISImporterTest.class.getResource("RisImporterCorrupted.ris").toURI()); + Path file = Path.of(RISImporterTest.class.getResource("RisImporterCorrupted.ris").toURI()); assertFalse(importer.isRecognizedFormat(file, StandardCharsets.UTF_8)); } } diff --git a/src/test/java/org/jabref/logic/importer/util/GroupsParserTest.java b/src/test/java/org/jabref/logic/importer/util/GroupsParserTest.java index 07ca10e2234..2e514eb6d0c 100644 --- a/src/test/java/org/jabref/logic/importer/util/GroupsParserTest.java +++ b/src/test/java/org/jabref/logic/importer/util/GroupsParserTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.importer.util; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Arrays; import java.util.List; @@ -121,7 +121,7 @@ void fromStringParsesAutomaticPersonGroup() throws Exception { @Test void fromStringParsesTexGroup() throws Exception { - TexGroup expected = TexGroup.createWithoutFileMonitoring("myTexGroup", GroupHierarchyType.INDEPENDENT, Paths.get("path", "To", "File"), new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData); + TexGroup expected = TexGroup.createWithoutFileMonitoring("myTexGroup", GroupHierarchyType.INDEPENDENT, Path.of("path", "To", "File"), new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData); AbstractGroup parsed = GroupsParser.fromString("TexGroup:myTexGroup;0;path/To/File;1;;;;", ',', fileMonitor, metaData); assertEquals(expected, parsed); } diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java b/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java index f69d7469af0..f015e23f24c 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationConsistencyTest.java @@ -7,7 +7,6 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -41,7 +40,7 @@ void allFilesMustBeInLanguages() throws IOException { // e.g., "_en.properties", where is [JabRef, Menu] Pattern propertiesFile = Pattern.compile(String.format("%s_.{2,}.properties", bundle)); Set localizationFiles = new HashSet<>(); - try (DirectoryStream directoryStream = Files.newDirectoryStream(Paths.get("src/main/resources/l10n"))) { + try (DirectoryStream directoryStream = Files.newDirectoryStream(Path.of("src/main/resources/l10n"))) { for (Path fullPath : directoryStream) { String fileName = fullPath.getFileName().toString(); if (propertiesFile.matcher(fileName).matches()) { @@ -156,7 +155,7 @@ private static Language[] installedLanguages() { @ParameterizedTest @MethodSource("installedLanguages") void resourceBundleExists(Language language) { - Path messagesPropertyFile = Paths.get("src/main/resources").resolve(Localization.RESOURCE_PREFIX + "_" + language.getId() + ".properties"); + Path messagesPropertyFile = Path.of("src/main/resources").resolve(Localization.RESOURCE_PREFIX + "_" + language.getId() + ".properties"); assertTrue(Files.exists(messagesPropertyFile)); } diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationParser.java b/src/test/java/org/jabref/logic/l10n/LocalizationParser.java index 41ed013e605..e4b246e9bfb 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationParser.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationParser.java @@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -81,7 +80,7 @@ private static Set findLocalizationEntriesInFiles(Localizatio public static Set findLocalizationParametersStringsInJavaFiles(LocalizationBundleForTest type) throws IOException { - try (Stream pathStream = Files.walk(Paths.get("src/main"))) { + try (Stream pathStream = Files.walk(Path.of("src/main"))) { return pathStream .filter(LocalizationParser::isJavaFile) .flatMap(path -> getLocalizationParametersInJavaFile(path, type).stream()) @@ -93,7 +92,7 @@ public static Set findLocalizationParametersStringsInJavaFile private static Set findLocalizationEntriesInJavaFiles(LocalizationBundleForTest type) throws IOException { - try (Stream pathStream = Files.walk(Paths.get("src/main"))) { + try (Stream pathStream = Files.walk(Path.of("src/main"))) { return pathStream .filter(LocalizationParser::isJavaFile) .flatMap(path -> getLanguageKeysInJavaFile(path, type).stream()) @@ -105,7 +104,7 @@ private static Set findLocalizationEntriesInJavaFiles(Localiz private static Set findLocalizationEntriesInFxmlFiles(LocalizationBundleForTest type) throws IOException { - try (Stream pathStream = Files.walk(Paths.get("src/main"))) { + try (Stream pathStream = Files.walk(Path.of("src/main"))) { return pathStream .filter(LocalizationParser::isFxmlFile) .flatMap(path -> getLanguageKeysInFxmlFile(path, type).stream()) diff --git a/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java b/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java index 3e48db6b56b..282fe8d1ead 100644 --- a/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java +++ b/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -54,8 +54,8 @@ void testAuthorYear() throws IOException { @Test void testAuthorYearAsFile() throws URISyntaxException, IOException { - File defFile = Paths.get(OOBibStyleTest.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) - .toFile(); + File defFile = Path.of(OOBibStyleTest.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) + .toFile(); OOBibStyle style = new OOBibStyle(defFile, layoutFormatterPreferences, StandardCharsets.UTF_8); assertTrue(style.isValid()); assertFalse(style.isInternalStyle()); diff --git a/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java b/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java index e83ace4d707..21f0f22d539 100644 --- a/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java +++ b/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java @@ -3,7 +3,7 @@ import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -23,7 +23,7 @@ public class StyleLoaderTest { - private static int numberOfInternalStyles = 2; + private static final int numberOfInternalStyles = 2; private StyleLoader loader; private OpenOfficePreferences preferences; @@ -65,8 +65,8 @@ public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); loader = new StyleLoader(preferences, layoutPreferences, encoding); - String filename = Paths.get(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) - .toFile().getPath(); + String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) + .toFile().getPath(); loader.addStyleIfValid(filename); assertEquals(numberOfInternalStyles + 1, loader.getStyles().size()); } @@ -82,7 +82,7 @@ public void testAddInvalidStyleLeadsToNoMoreStyle() { @Test public void testInitalizeWithOneExternalFile() throws URISyntaxException { - String filename = Paths.get(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) + String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(Collections.singletonList(filename)); loader = new StyleLoader(preferences, layoutPreferences, encoding); @@ -99,7 +99,7 @@ public void testInitalizeWithIncorrectExternalFile() { @Test public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxException { - String filename = Paths.get(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) + String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(Collections.singletonList(filename)); @@ -120,7 +120,7 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept @Test public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() throws URISyntaxException { - String filename = Paths.get(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) + String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(Collections.singletonList(filename)); @@ -144,7 +144,7 @@ public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException preferences.setExternalStyles(Collections.emptyList()); loader = new StyleLoader(preferences, layoutPreferences, encoding); int beforeAdding = loader.getStyles().size(); - String filename = Paths.get(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) + String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); loader.addStyleIfValid(filename); loader.addStyleIfValid(filename); diff --git a/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java b/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java index 4f2754d9359..08c6e29d12b 100644 --- a/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java +++ b/src/test/java/org/jabref/logic/pdf/EntryAnnotationImporterTest.java @@ -1,7 +1,6 @@ package org.jabref.logic.pdf; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Map; @@ -28,7 +27,7 @@ public class EntryAnnotationImporterTest { @BeforeEach public void setUp() { entry = new BibEntry(); - when(databaseContext.getFileDirectoriesAsPaths(any())).thenReturn(Collections.singletonList(Paths.get("src/test/resources/pdfs/"))); + when(databaseContext.getFileDirectoriesAsPaths(any())).thenReturn(Collections.singletonList(Path.of("src/test/resources/pdfs/"))); } @Test diff --git a/src/test/java/org/jabref/logic/pdf/PdfAnnotationImporterTest.java b/src/test/java/org/jabref/logic/pdf/PdfAnnotationImporterTest.java index fc0bb832b35..7606bed8caf 100644 --- a/src/test/java/org/jabref/logic/pdf/PdfAnnotationImporterTest.java +++ b/src/test/java/org/jabref/logic/pdf/PdfAnnotationImporterTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.pdf; -import java.nio.file.Paths; +import java.nio.file.Path; import java.time.LocalDateTime; import java.util.Collections; import java.util.Optional; @@ -18,37 +18,37 @@ public class PdfAnnotationImporterTest { @Test public void invalidPath() { - assertEquals(Collections.emptyList(), importer.importAnnotations(Paths.get("/asdf/does/not/exist.pdf"))); + assertEquals(Collections.emptyList(), importer.importAnnotations(Path.of("/asdf/does/not/exist.pdf"))); } @Test public void invalidDirectory() { - assertEquals(Collections.emptyList(), importer.importAnnotations(Paths.get("src/test/resources/pdfs"))); + assertEquals(Collections.emptyList(), importer.importAnnotations(Path.of("src/test/resources/pdfs"))); } @Test public void invalidDocumentType() { - assertEquals(Collections.emptyList(), importer.importAnnotations(Paths.get("src/test/resources/pdfs/write-protected.docx"))); + assertEquals(Collections.emptyList(), importer.importAnnotations(Path.of("src/test/resources/pdfs/write-protected.docx"))); } @Test public void noAnnotationsWriteProtected() { - assertEquals(Collections.emptyList(), importer.importAnnotations(Paths.get("src/test/resources/pdfs/write-protected.pdf"))); + assertEquals(Collections.emptyList(), importer.importAnnotations(Path.of("src/test/resources/pdfs/write-protected.pdf"))); } @Test public void noAnnotationsEncrypted() { - assertEquals(Collections.emptyList(), importer.importAnnotations(Paths.get("src/test/resources/pdfs/encrypted.pdf"))); + assertEquals(Collections.emptyList(), importer.importAnnotations(Path.of("src/test/resources/pdfs/encrypted.pdf"))); } @Test public void twoAnnotationsThesisExample() { - assertEquals(2, importer.importAnnotations(Paths.get("src/test/resources/pdfs/thesis-example.pdf")).size()); + assertEquals(2, importer.importAnnotations(Path.of("src/test/resources/pdfs/thesis-example.pdf")).size()); } @Test public void noAnnotationsMinimal() { - assertEquals(Collections.emptyList(), importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal.pdf"))); + assertEquals(Collections.emptyList(), importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal.pdf"))); } @Test @@ -57,7 +57,7 @@ public void inlineNoteMinimal() { "inline note annotation", FileAnnotationType.FREETEXT, Optional.empty()); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-inlinenote.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-inlinenote.pdf"))); } @Test @@ -66,7 +66,7 @@ public void popupNoteMinimal() { "A simple pop-up note", FileAnnotationType.TEXT, Optional.empty()); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-popup.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-popup.pdf"))); } @Test @@ -76,7 +76,7 @@ public void highlightMinimalFoxit() { final FileAnnotation expected = new FileAnnotation("lynyus", LocalDateTime.of(2017, 5, 31, 15, 16, 1), 1, "Hello", FileAnnotationType.HIGHLIGHT, Optional.of(expectedLinkedAnnotation)); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-foxithighlight.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-foxithighlight.pdf"))); } @Test @@ -87,7 +87,7 @@ public void highlightNoNoteMinimal() { "World", FileAnnotationType.HIGHLIGHT, Optional.of(expectedLinkedAnnotation)); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-highlight-no-note.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-highlight-no-note.pdf"))); } @Test @@ -98,7 +98,7 @@ public void squigglyWithNoteMinimal() { "ello", FileAnnotationType.SQUIGGLY, Optional.of(expectedLinkedAnnotation)); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-squiggly.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-squiggly.pdf"))); } @Test @@ -109,7 +109,7 @@ public void strikeoutWithNoteMinimal() { "World", FileAnnotationType.STRIKEOUT, Optional.of(expectedLinkedAnnotation)); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-strikeout.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-strikeout.pdf"))); } @Test @@ -120,7 +120,7 @@ public void highlightWithNoteMinimal() { "World", FileAnnotationType.HIGHLIGHT, Optional.of(expectedLinkedAnnotation)); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-highlight-with-note.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-highlight-with-note.pdf"))); } @Test @@ -131,7 +131,7 @@ public void underlineWithNoteMinimal() { "Hello", FileAnnotationType.UNDERLINE, Optional.of(expectedLinkedAnnotation)); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-underline.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-underline.pdf"))); } @Test @@ -140,7 +140,7 @@ public void polygonNoNoteMinimal() { "polygon annotation", FileAnnotationType.POLYGON, Optional.empty()); assertEquals(Collections.singletonList(expected), - importer.importAnnotations(Paths.get("src/test/resources/pdfs/minimal-polygon.pdf"))); + importer.importAnnotations(Path.of("src/test/resources/pdfs/minimal-polygon.pdf"))); } } diff --git a/src/test/java/org/jabref/logic/protectedterms/ProtectedTermsLoaderTest.java b/src/test/java/org/jabref/logic/protectedterms/ProtectedTermsLoaderTest.java index b08c1c3546d..98bf2c7a709 100644 --- a/src/test/java/org/jabref/logic/protectedterms/ProtectedTermsLoaderTest.java +++ b/src/test/java/org/jabref/logic/protectedterms/ProtectedTermsLoaderTest.java @@ -38,7 +38,7 @@ void testGetProtectedTerms() throws URISyntaxException { loader.removeProtectedTermsList(list); } assertTrue(loader.getProtectedTermsLists().isEmpty()); - String filename = Paths.get( + String filename = Path.of( ProtectedTermsLoader.class.getResource("/org/jabref/logic/protectedterms/namedterms.terms").toURI()) .toFile().getPath(); loader.addProtectedTermsListFromFile(filename, true); @@ -58,7 +58,7 @@ void testAddProtectedTermsListFromFile() throws URISyntaxException { @Test void testReadProtectedTermsListFromFileReadsDescription() throws URISyntaxException, FileNotFoundException { - File file = Paths.get( + File file = Path.of( ProtectedTermsLoader.class.getResource("/org/jabref/logic/protectedterms/namedterms.terms").toURI()) .toFile(); ProtectedTermsList list = ProtectedTermsLoader.readProtectedTermsListFromFile(file, true); @@ -67,7 +67,7 @@ void testReadProtectedTermsListFromFileReadsDescription() throws URISyntaxExcept @Test void testReadProtectedTermsListFromFileDisabledWorks() throws URISyntaxException, FileNotFoundException { - File file = Paths.get( + File file = Path.of( ProtectedTermsLoader.class.getResource("/org/jabref/logic/protectedterms/namedterms.terms").toURI()) .toFile(); ProtectedTermsList list = ProtectedTermsLoader.readProtectedTermsListFromFile(file, false); @@ -76,7 +76,7 @@ void testReadProtectedTermsListFromFileDisabledWorks() throws URISyntaxException @Test void testReadProtectedTermsListFromFileEnabledWorks() throws URISyntaxException, FileNotFoundException { - File file = Paths.get( + File file = Path.of( ProtectedTermsLoader.class.getResource("/org/jabref/logic/protectedterms/namedterms.terms").toURI()) .toFile(); ProtectedTermsList list = ProtectedTermsLoader.readProtectedTermsListFromFile(file, true); @@ -85,7 +85,7 @@ void testReadProtectedTermsListFromFileEnabledWorks() throws URISyntaxException, @Test void testReadProtectedTermsListFromFileIsNotInternalList() throws URISyntaxException, FileNotFoundException { - File file = Paths.get( + File file = Path.of( ProtectedTermsLoader.class.getResource("/org/jabref/logic/protectedterms/namedterms.terms").toURI()) .toFile(); ProtectedTermsList list = ProtectedTermsLoader.readProtectedTermsListFromFile(file, true); @@ -95,7 +95,7 @@ void testReadProtectedTermsListFromFileIsNotInternalList() throws URISyntaxExcep @Test void testReadProtectedTermsListFromFileNoDescriptionGivesDefaultDescription() throws URISyntaxException, FileNotFoundException { - File file = Paths.get( + File file = Path.of( ProtectedTermsLoader.class.getResource("/org/jabref/logic/protectedterms/unnamedterms.terms") .toURI()) .toFile(); diff --git a/src/test/java/org/jabref/logic/texparser/DefaultTexParserTest.java b/src/test/java/org/jabref/logic/texparser/DefaultTexParserTest.java index 32022cd2861..ab41c9967e6 100644 --- a/src/test/java/org/jabref/logic/texparser/DefaultTexParserTest.java +++ b/src/test/java/org/jabref/logic/texparser/DefaultTexParserTest.java @@ -2,7 +2,6 @@ import java.net.URISyntaxException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import org.jabref.model.texparser.LatexParserResult; @@ -25,7 +24,7 @@ private void testMatchCite(String key, String citeString) { LatexParserResult latexParserResult = new DefaultLatexParser().parse(citeString); LatexParserResult expectedParserResult = new LatexParserResult(); - expectedParserResult.addKey(key, Paths.get(""), 1, 0, citeString.length(), citeString); + expectedParserResult.addKey(key, Path.of(""), 1, 0, citeString.length(), citeString); assertEquals(expectedParserResult, latexParserResult); } @@ -62,15 +61,15 @@ public void testTwoCitationsSameLine() { LatexParserResult latexParserResult = new DefaultLatexParser().parse(citeString); LatexParserResult expectedParserResult = new LatexParserResult(); - expectedParserResult.addKey(EINSTEIN_C, Paths.get(""), 1, 0, 21, citeString); - expectedParserResult.addKey(EINSTEIN_A, Paths.get(""), 1, 26, 47, citeString); + expectedParserResult.addKey(EINSTEIN_C, Path.of(""), 1, 0, 21, citeString); + expectedParserResult.addKey(EINSTEIN_A, Path.of(""), 1, 26, 47, citeString); assertEquals(expectedParserResult, latexParserResult); } @Test public void testFileEncodingUtf8() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("utf-8.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("utf-8.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -83,7 +82,7 @@ public void testFileEncodingUtf8() throws URISyntaxException { @Test public void testFileEncodingIso88591() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("iso-8859-1.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("iso-8859-1.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -98,7 +97,7 @@ public void testFileEncodingIso88591() throws URISyntaxException { @Test public void testFileEncodingIso885915() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("iso-8859-15.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("iso-8859-15.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -113,9 +112,9 @@ public void testFileEncodingIso885915() throws URISyntaxException { @Test public void testFileEncodingForThreeFiles() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("utf-8.tex").toURI()); - Path texFile2 = Paths.get(DefaultTexParserTest.class.getResource("iso-8859-1.tex").toURI()); - Path texFile3 = Paths.get(DefaultTexParserTest.class.getResource("iso-8859-15.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("utf-8.tex").toURI()); + Path texFile2 = Path.of(DefaultTexParserTest.class.getResource("iso-8859-1.tex").toURI()); + Path texFile3 = Path.of(DefaultTexParserTest.class.getResource("iso-8859-15.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser() .parse(Arrays.asList(texFile, texFile2, texFile3)); @@ -134,7 +133,7 @@ public void testFileEncodingForThreeFiles() throws URISyntaxException { @Test public void testSingleFile() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("paper.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("paper.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -151,8 +150,8 @@ public void testSingleFile() throws URISyntaxException { @Test public void testTwoFiles() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("paper.tex").toURI()); - Path texFile2 = Paths.get(DefaultTexParserTest.class.getResource("paper2.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("paper.tex").toURI()); + Path texFile2 = Path.of(DefaultTexParserTest.class.getResource("paper2.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(Arrays.asList(texFile, texFile2)); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -173,7 +172,7 @@ public void testTwoFiles() throws URISyntaxException { @Test public void testDuplicateFiles() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("paper.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("paper.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(Arrays.asList(texFile, texFile)); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -190,7 +189,7 @@ public void testDuplicateFiles() throws URISyntaxException { @Test public void testUnknownKey() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("unknown_key.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("unknown_key.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -206,7 +205,7 @@ public void testUnknownKey() throws URISyntaxException { @Test public void testFileNotFound() { - Path texFile = Paths.get("file_not_found.tex"); + Path texFile = Path.of("file_not_found.tex"); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -218,9 +217,9 @@ public void testFileNotFound() { @Test public void testNestedFiles() throws URISyntaxException { - Path texFile = Paths.get(DefaultTexParserTest.class.getResource("nested.tex").toURI()); - Path texFile2 = Paths.get(DefaultTexParserTest.class.getResource("nested2.tex").toURI()); - Path texFile3 = Paths.get(DefaultTexParserTest.class.getResource("paper.tex").toURI()); + Path texFile = Path.of(DefaultTexParserTest.class.getResource("nested.tex").toURI()); + Path texFile2 = Path.of(DefaultTexParserTest.class.getResource("nested2.tex").toURI()); + Path texFile3 = Path.of(DefaultTexParserTest.class.getResource("paper.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); diff --git a/src/test/java/org/jabref/logic/texparser/LatexParserTest.java b/src/test/java/org/jabref/logic/texparser/LatexParserTest.java index 105ca220f0e..fb6acd372a3 100644 --- a/src/test/java/org/jabref/logic/texparser/LatexParserTest.java +++ b/src/test/java/org/jabref/logic/texparser/LatexParserTest.java @@ -3,7 +3,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import org.jabref.logic.importer.ImportFormatPreferences; @@ -32,7 +31,7 @@ public class LatexParserTest { private final static String EINSTEIN_B = "Einstein1920b"; private final static String EINSTEIN_C = "Einstein1920c"; - private static FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); + private static final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); private static ImportFormatPreferences importFormatPreferences; private static BibDatabase database; private static BibDatabase database2; @@ -91,7 +90,7 @@ private void setUp() { @Test public void testSameFileDifferentDatabases() throws URISyntaxException { - Path texFile = Paths.get(LatexParserTest.class.getResource("paper.tex").toURI()); + Path texFile = Path.of(LatexParserTest.class.getResource("paper.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexParserResult expectedParserResult = new LatexParserResult(); @@ -119,8 +118,8 @@ public void testSameFileDifferentDatabases() throws URISyntaxException { @Test public void testTwoFilesDifferentDatabases() throws URISyntaxException { - Path texFile = Paths.get(LatexParserTest.class.getResource("paper.tex").toURI()); - Path texFile2 = Paths.get(LatexParserTest.class.getResource("paper2.tex").toURI()); + Path texFile = Path.of(LatexParserTest.class.getResource("paper.tex").toURI()); + Path texFile2 = Path.of(LatexParserTest.class.getResource("paper2.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(Arrays.asList(texFile, texFile2)); LatexParserResult expectedParserResult = new LatexParserResult(); diff --git a/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java b/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java index cd8dce92474..9dd0f8808f8 100644 --- a/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java +++ b/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java @@ -3,7 +3,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import org.jabref.logic.importer.ImportFormatPreferences; @@ -32,7 +31,7 @@ public class TexBibEntriesResolverTest { private final static String EINSTEIN_B = "Einstein1920b"; private final static String EINSTEIN_C = "Einstein1920c"; - private static FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); + private static final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); private static ImportFormatPreferences importFormatPreferences; private static BibDatabase database; private static BibDatabase database2; @@ -100,7 +99,7 @@ private void setUp() { @Test public void testSingleFile() throws URISyntaxException { - Path texFile = Paths.get(TexBibEntriesResolverTest.class.getResource("paper.tex").toURI()); + Path texFile = Path.of(TexBibEntriesResolverTest.class.getResource("paper.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexBibEntriesResolverResult crossingResult = new TexBibEntriesResolver(database, importFormatPreferences, fileMonitor).resolve(parserResult); @@ -111,8 +110,8 @@ public void testSingleFile() throws URISyntaxException { @Test public void testTwoFiles() throws URISyntaxException { - Path texFile = Paths.get(TexBibEntriesResolverTest.class.getResource("paper.tex").toURI()); - Path texFile2 = Paths.get(TexBibEntriesResolverTest.class.getResource("paper2.tex").toURI()); + Path texFile = Path.of(TexBibEntriesResolverTest.class.getResource("paper.tex").toURI()); + Path texFile2 = Path.of(TexBibEntriesResolverTest.class.getResource("paper2.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(Arrays.asList(texFile, texFile2)); LatexBibEntriesResolverResult crossingResult = new TexBibEntriesResolver(database, importFormatPreferences, fileMonitor).resolve(parserResult); @@ -123,7 +122,7 @@ public void testTwoFiles() throws URISyntaxException { @Test public void testDuplicateFiles() throws URISyntaxException { - Path texFile = Paths.get(TexBibEntriesResolverTest.class.getResource("paper.tex").toURI()); + Path texFile = Path.of(TexBibEntriesResolverTest.class.getResource("paper.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexBibEntriesResolverResult crossingResult = new TexBibEntriesResolver(database, importFormatPreferences, fileMonitor).resolve(parserResult); @@ -134,7 +133,7 @@ public void testDuplicateFiles() throws URISyntaxException { @Test public void testUnknownKey() throws URISyntaxException { - Path texFile = Paths.get(TexBibEntriesResolverTest.class.getResource("unknown_key.tex").toURI()); + Path texFile = Path.of(TexBibEntriesResolverTest.class.getResource("unknown_key.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexBibEntriesResolverResult crossingResult = new TexBibEntriesResolver(database, importFormatPreferences, fileMonitor).resolve(parserResult); @@ -145,7 +144,7 @@ public void testUnknownKey() throws URISyntaxException { @Test public void testNestedFiles() throws URISyntaxException { - Path texFile = Paths.get(TexBibEntriesResolverTest.class.getResource("nested.tex").toURI()); + Path texFile = Path.of(TexBibEntriesResolverTest.class.getResource("nested.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexBibEntriesResolverResult crossingResult = new TexBibEntriesResolver(database, importFormatPreferences, fileMonitor).resolve(parserResult); @@ -156,7 +155,7 @@ public void testNestedFiles() throws URISyntaxException { @Test public void testCrossRef() throws URISyntaxException { - Path texFile = Paths.get(TexBibEntriesResolverTest.class.getResource("crossref.tex").toURI()); + Path texFile = Path.of(TexBibEntriesResolverTest.class.getResource("crossref.tex").toURI()); LatexParserResult parserResult = new DefaultLatexParser().parse(texFile); LatexBibEntriesResolverResult crossingResult = new TexBibEntriesResolver(database, importFormatPreferences, fileMonitor).resolve(parserResult); diff --git a/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java b/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java index af895b2bcfc..9c1bfcccefb 100644 --- a/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.util.io; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -19,27 +19,27 @@ void setUp() { @Test void newItemsAreAddedInRightOrder() { - history.newFile(Paths.get("aa")); - history.newFile(Paths.get("bb")); - assertEquals(Arrays.asList(Paths.get("bb"), Paths.get("aa")), history.getHistory()); + history.newFile(Path.of("aa")); + history.newFile(Path.of("bb")); + assertEquals(Arrays.asList(Path.of("bb"), Path.of("aa")), history.getHistory()); } @Test void itemsAlreadyInListIsMovedToTop() { - history.newFile(Paths.get("aa")); - history.newFile(Paths.get("bb")); - history.newFile(Paths.get("aa")); - assertEquals(Arrays.asList(Paths.get("aa"), Paths.get("bb")), history.getHistory()); + history.newFile(Path.of("aa")); + history.newFile(Path.of("bb")); + history.newFile(Path.of("aa")); + assertEquals(Arrays.asList(Path.of("aa"), Path.of("bb")), history.getHistory()); } @Test void removeItemsLeavesOtherItemsInRightOrder() { - history.newFile(Paths.get("aa")); - history.newFile(Paths.get("bb")); - history.newFile(Paths.get("cc")); + history.newFile(Path.of("aa")); + history.newFile(Path.of("bb")); + history.newFile(Path.of("cc")); - history.removeItem(Paths.get("bb")); + history.removeItem(Path.of("bb")); - assertEquals(Arrays.asList(Paths.get("cc"), Paths.get("aa")), history.getHistory()); + assertEquals(Arrays.asList(Path.of("cc"), Path.of("aa")), history.getHistory()); } } diff --git a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java index be50604045f..f7bec14536d 100644 --- a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Arrays; import java.util.List; @@ -30,7 +29,7 @@ import static org.mockito.Mockito.mock; class FileUtilTest { - private final Path nonExistingTestPath = Paths.get("nonExistingTestPath"); + private final Path nonExistingTestPath = Path.of("nonExistingTestPath"); private Path existingTestFile; private Path otherExistingTestFile; private LayoutFormatterPreferences layoutFormatterPreferences; @@ -54,14 +53,14 @@ void setUpViewModel(@TempDir Path temporaryFolder) throws IOException { @Test void extensionBakAddedCorrectly() { - assertEquals(Paths.get("demo.bib.bak"), - FileUtil.addExtension(Paths.get("demo.bib"), ".bak")); + assertEquals(Path.of("demo.bib.bak"), + FileUtil.addExtension(Path.of("demo.bib"), ".bak")); } @Test void extensionBakAddedCorrectlyToAFileContainedInTmpDirectory() { - assertEquals(Paths.get("tmp", "demo.bib.bak"), - FileUtil.addExtension(Paths.get("tmp", "demo.bib"), ".bak")); + assertEquals(Path.of("tmp", "demo.bib.bak"), + FileUtil.addExtension(Path.of("tmp", "demo.bib"), ".bak")); } @Test @@ -152,22 +151,22 @@ void testGetLinkedFileNameByYearAuthorFirstpage() { @Test void testGetFileExtensionSimpleFile() { - assertEquals("pdf", FileHelper.getFileExtension(Paths.get("test.pdf")).get()); + assertEquals("pdf", FileHelper.getFileExtension(Path.of("test.pdf")).get()); } @Test void testGetFileExtensionMultipleDotsFile() { - assertEquals("pdf", FileHelper.getFileExtension(Paths.get("te.st.PdF")).get()); + assertEquals("pdf", FileHelper.getFileExtension(Path.of("te.st.PdF")).get()); } @Test void testGetFileExtensionNoExtensionFile() { - assertFalse(FileHelper.getFileExtension(Paths.get("JustTextNotASingleDot")).isPresent()); + assertFalse(FileHelper.getFileExtension(Path.of("JustTextNotASingleDot")).isPresent()); } @Test void testGetFileExtensionNoExtension2File() { - assertFalse(FileHelper.getFileExtension(Paths.get(".StartsWithADotIsNotAnExtension")).isPresent()); + assertFalse(FileHelper.getFileExtension(Path.of(".StartsWithADotIsNotAnExtension")).isPresent()); } @Test @@ -207,12 +206,12 @@ void getFileNameWithMultipleDotsString() { @Test void uniquePathSubstrings() { - String[] pathArr = {Paths.get("C:/uniquefile.bib").toString(), - Paths.get("C:/downloads/filename.bib").toString(), Paths.get("C:/mypaper/bib/filename.bib").toString(), - Paths.get("C:/external/mypaper/bib/filename.bib").toString(), ""}; - String[] uniqArr = {Paths.get("uniquefile.bib").toString(), Paths.get("downloads/filename.bib").toString(), - Paths.get("C:/mypaper/bib/filename.bib").toString(), - Paths.get("external/mypaper/bib/filename.bib").toString(), ""}; + String[] pathArr = {Path.of("C:/uniquefile.bib").toString(), + Path.of("C:/downloads/filename.bib").toString(), Path.of("C:/mypaper/bib/filename.bib").toString(), + Path.of("C:/external/mypaper/bib/filename.bib").toString(), ""}; + String[] uniqArr = {Path.of("uniquefile.bib").toString(), Path.of("downloads/filename.bib").toString(), + Path.of("C:/mypaper/bib/filename.bib").toString(), + Path.of("external/mypaper/bib/filename.bib").toString(), ""}; List paths = Arrays.asList(pathArr); List uniqPath = Arrays.asList(uniqArr); @@ -324,7 +323,7 @@ void testRenameFileWithFromFileExistAndOtherToFileExist() { void testRenameFileSuccessful(@TempDir Path otherTemporaryFolder) { // Be careful. This "otherTemporaryFolder" is the same as the "temporaryFolder" // in the @BeforeEach method. - Path temp = Paths.get(otherTemporaryFolder.resolve("123").toString()); + Path temp = Path.of(otherTemporaryFolder.resolve("123").toString()); System.out.println(temp); FileUtil.renameFile(existingTestFile, temp); diff --git a/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java b/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java index b1a2ff97ae7..23f61a3d1a0 100644 --- a/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java +++ b/src/test/java/org/jabref/logic/util/io/RegExpBasedFileFinderTests.java @@ -1,7 +1,6 @@ package org.jabref.logic.util.io; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -53,14 +52,14 @@ public void testFindFiles() throws Exception { List extensions = Collections.singletonList("pdf"); - List dirs = Collections.singletonList(Paths.get(FILES_DIRECTORY)); + List dirs = Collections.singletonList(Path.of(FILES_DIRECTORY)); RegExpBasedFileFinder fileFinder = new RegExpBasedFileFinder("**/[bibtexkey].*\\\\.[extension]", ','); // when List result = fileFinder.findAssociatedFiles(localEntry, dirs, extensions); // then - assertEquals(Collections.singletonList(Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/pdfInDatabase.pdf")), + assertEquals(Collections.singletonList(Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/pdfInDatabase.pdf")), result); } @@ -69,14 +68,14 @@ public void testYearAuthFirspageFindFiles() throws Exception { // given List extensions = Collections.singletonList("pdf"); - List dirs = Collections.singletonList(Paths.get(FILES_DIRECTORY)); + List dirs = Collections.singletonList(Path.of(FILES_DIRECTORY)); RegExpBasedFileFinder fileFinder = new RegExpBasedFileFinder("**/[year]_[auth]_[firstpage].*\\\\.[extension]", ','); // when List result = fileFinder.findAssociatedFiles(entry, dirs, extensions); // then - assertEquals(Collections.singletonList(Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/directory/subdirectory/2003_Hippel_209.pdf")), + assertEquals(Collections.singletonList(Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/directory/subdirectory/2003_Hippel_209.pdf")), result); } @@ -91,14 +90,14 @@ public void testAuthorWithDiacritics() throws Exception { List extensions = Collections.singletonList("pdf"); - List dirs = Collections.singletonList(Paths.get(FILES_DIRECTORY)); + List dirs = Collections.singletonList(Path.of(FILES_DIRECTORY)); RegExpBasedFileFinder fileFinder = new RegExpBasedFileFinder("**/[year]_[auth]_[firstpage]\\\\.[extension]", ','); // when List result = fileFinder.findAssociatedFiles(localEntry, dirs, extensions); // then - assertEquals(Collections.singletonList(Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/directory/subdirectory/2017_Gražulis_726.pdf")), + assertEquals(Collections.singletonList(Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/directory/subdirectory/2017_Gražulis_726.pdf")), result); } @@ -111,14 +110,14 @@ public void testFindFileInSubdirectory() throws Exception { List extensions = Collections.singletonList("pdf"); - List dirs = Collections.singletonList(Paths.get(FILES_DIRECTORY)); + List dirs = Collections.singletonList(Path.of(FILES_DIRECTORY)); RegExpBasedFileFinder fileFinder = new RegExpBasedFileFinder("**/[bibtexkey].*\\\\.[extension]", ','); // when List result = fileFinder.findAssociatedFiles(localEntry, dirs, extensions); // then - assertEquals(Collections.singletonList(Paths.get("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/directory/subdirectory/pdfInSubdirectory.pdf")), + assertEquals(Collections.singletonList(Path.of("src/test/resources/org/jabref/logic/importer/unlinkedFilesTestFolder/directory/subdirectory/pdfInSubdirectory.pdf")), result); } @@ -131,7 +130,7 @@ public void testFindFileNonRecursive() throws Exception { List extensions = Collections.singletonList("pdf"); - List dirs = Collections.singletonList(Paths.get(FILES_DIRECTORY)); + List dirs = Collections.singletonList(Path.of(FILES_DIRECTORY)); RegExpBasedFileFinder fileFinder = new RegExpBasedFileFinder("*/[bibtexkey].*\\\\.[extension]", ','); // when diff --git a/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java b/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java index a938cf26a87..37c43679ae1 100644 --- a/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java +++ b/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java @@ -4,7 +4,6 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -54,7 +53,7 @@ void setUp() { */ @Test void testReadArticleDublinCoreReadRawXmp() throws IOException, URISyntaxException, ParseException { - Path path = Paths.get(XmpUtilShared.class.getResource("article_dublinCore.pdf").toURI()); + Path path = Path.of(XmpUtilShared.class.getResource("article_dublinCore.pdf").toURI()); List meta = XmpUtilReader.readRawXmp(path); DublinCoreSchema dcSchema = meta.get(0).getDublinCoreSchema(); @@ -71,7 +70,7 @@ void testReadArticleDublinCoreReadRawXmp() throws IOException, URISyntaxExceptio */ @Test void testReadArticleDublinCoreReadXmp() throws IOException, URISyntaxException, ParseException { - Path pathPdf = Paths.get(XmpUtilShared.class.getResource("article_dublinCore.pdf").toURI()); + Path pathPdf = Path.of(XmpUtilShared.class.getResource("article_dublinCore.pdf").toURI()); List entries = XmpUtilReader.readXmp(pathPdf, xmpPreferences); BibEntry entry = entries.get(0); @@ -90,7 +89,7 @@ void testReadArticleDublinCoreReadXmp() throws IOException, URISyntaxException, */ @Test void testReadEmtpyMetadata() throws IOException, URISyntaxException { - List entries = XmpUtilReader.readXmp(Paths.get(XmpUtilShared.class.getResource("empty_metadata.pdf").toURI()), xmpPreferences); + List entries = XmpUtilReader.readXmp(Path.of(XmpUtilShared.class.getResource("empty_metadata.pdf").toURI()), xmpPreferences); assertEquals(Collections.emptyList(), entries); } @@ -99,7 +98,7 @@ void testReadEmtpyMetadata() throws IOException, URISyntaxException { */ @Test void testReadPDMetadata() throws IOException, URISyntaxException, ParseException { - Path pathPdf = Paths.get(XmpUtilShared.class.getResource("PD_metadata.pdf").toURI()); + Path pathPdf = Path.of(XmpUtilShared.class.getResource("PD_metadata.pdf").toURI()); List entries = XmpUtilReader.readXmp(pathPdf, xmpPreferences); String bibString = Resources.toString(XmpUtilShared.class.getResource("PD_metadata.bib"), StandardCharsets.UTF_8); diff --git a/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java b/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java index b2e911e1d3b..5b1da8d5f67 100644 --- a/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java +++ b/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; @@ -118,9 +117,9 @@ void testWriteMultipleBibEntries(@TempDir Path tempDir) throws IOException, Tran List entries = Arrays.asList(olly2018, vapnik2000, toral2006); - XmpUtilWriter.writeXmp(Paths.get(pdfFile.toAbsolutePath().toString()), entries, null, xmpPreferences); + XmpUtilWriter.writeXmp(Path.of(pdfFile.toAbsolutePath().toString()), entries, null, xmpPreferences); - List entryList = XmpUtilReader.readXmp(Paths.get(pdfFile.toAbsolutePath().toString()), xmpPreferences); + List entryList = XmpUtilReader.readXmp(Path.of(pdfFile.toAbsolutePath().toString()), xmpPreferences); assertEquals(3, entryList.size()); } diff --git a/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java b/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java index 5730acdf804..a714a5e672a 100644 --- a/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java +++ b/src/test/java/org/jabref/model/database/BibDatabaseContextTest.java @@ -1,7 +1,6 @@ package org.jabref.model.database; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -26,21 +25,21 @@ class BibDatabaseContextTest { @BeforeEach void setUp() { fileDirPrefs = mock(FilePreferences.class); - currentWorkingDir = Paths.get(System.getProperty("user.dir")); + currentWorkingDir = Path.of(System.getProperty("user.dir")); when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true); } @Test void getFileDirectoriesWithEmptyDbParent() { BibDatabaseContext database = new BibDatabaseContext(); - database.setDatabasePath(Paths.get("biblio.bib")); + database.setDatabasePath(Path.of("biblio.bib")); assertEquals(Collections.singletonList(currentWorkingDir), database.getFileDirectoriesAsPaths(fileDirPrefs)); } @Test void getFileDirectoriesWithRelativeDbParent() { - Path file = Paths.get("relative/subdir").resolve("biblio.bib"); + Path file = Path.of("relative/subdir").resolve("biblio.bib"); BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); @@ -50,7 +49,7 @@ void getFileDirectoriesWithRelativeDbParent() { @Test void getFileDirectoriesWithRelativeDottedDbParent() { - Path file = Paths.get("./relative/subdir").resolve("biblio.bib"); + Path file = Path.of("./relative/subdir").resolve("biblio.bib"); BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); @@ -60,7 +59,7 @@ void getFileDirectoriesWithRelativeDottedDbParent() { @Test void getFileDirectoriesWithAbsoluteDbParent() { - Path file = Paths.get("/absolute/subdir").resolve("biblio.bib"); + Path file = Path.of("/absolute/subdir").resolve("biblio.bib"); BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); @@ -70,23 +69,23 @@ void getFileDirectoriesWithAbsoluteDbParent() { @Test void getFileDirectoriesWithRelativeMetadata() { - Path file = Paths.get("/absolute/subdir").resolve("biblio.bib"); + Path file = Path.of("/absolute/subdir").resolve("biblio.bib"); BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); database.getMetaData().setDefaultFileDirectory("../Literature"); - assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Paths.get("/absolute/Literature").toAbsolutePath()), + assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Path.of("/absolute/Literature").toAbsolutePath()), database.getFileDirectoriesAsPaths(fileDirPrefs)); } @Test void getFileDirectoriesWithMetadata() { - Path file = Paths.get("/absolute/subdir").resolve("biblio.bib"); + Path file = Path.of("/absolute/subdir").resolve("biblio.bib"); BibDatabaseContext database = new BibDatabaseContext(); database.setDatabasePath(file); database.getMetaData().setDefaultFileDirectory("Literature"); - assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Paths.get("/absolute/subdir/Literature").toAbsolutePath()), + assertEquals(Arrays.asList(currentWorkingDir.resolve(file.getParent()), Path.of("/absolute/subdir/Literature").toAbsolutePath()), database.getFileDirectoriesAsPaths(fileDirPrefs)); } diff --git a/src/test/java/org/jabref/model/groups/TexGroupTest.java b/src/test/java/org/jabref/model/groups/TexGroupTest.java index 9e312db749e..7cf52a66aa2 100644 --- a/src/test/java/org/jabref/model/groups/TexGroupTest.java +++ b/src/test/java/org/jabref/model/groups/TexGroupTest.java @@ -1,7 +1,6 @@ package org.jabref.model.groups; import java.nio.file.Path; -import java.nio.file.Paths; import org.jabref.logic.auxparser.DefaultAuxParser; import org.jabref.model.database.BibDatabase; @@ -27,7 +26,7 @@ public void setUp() throws Exception { @Test public void containsReturnsTrueForEntryInAux() throws Exception { - Path auxFile = Paths.get(TexGroupTest.class.getResource("paper.aux").toURI()); + Path auxFile = Path.of(TexGroupTest.class.getResource("paper.aux").toURI()); TexGroup group = new TexGroup("paper", GroupHierarchyType.INDEPENDENT, auxFile, new DefaultAuxParser(new BibDatabase()), new DummyFileUpdateMonitor(), metaData); BibEntry inAux = new BibEntry(); inAux.setCiteKey("Darwin1888"); @@ -37,7 +36,7 @@ public void containsReturnsTrueForEntryInAux() throws Exception { @Test public void containsReturnsTrueForEntryNotInAux() throws Exception { - Path auxFile = Paths.get(TexGroupTest.class.getResource("paper.aux").toURI()); + Path auxFile = Path.of(TexGroupTest.class.getResource("paper.aux").toURI()); TexGroup group = new TexGroup("paper", GroupHierarchyType.INDEPENDENT, auxFile, new DefaultAuxParser(new BibDatabase()), new DummyFileUpdateMonitor(), metaData); BibEntry notInAux = new BibEntry(); notInAux.setCiteKey("NotInAux2017"); @@ -47,7 +46,7 @@ public void containsReturnsTrueForEntryNotInAux() throws Exception { @Test public void getFilePathReturnsRelativePath() throws Exception { - Path auxFile = Paths.get(TexGroupTest.class.getResource("paper.aux").toURI()); + Path auxFile = Path.of(TexGroupTest.class.getResource("paper.aux").toURI()); String user = "Darwin"; metaData.setLatexFileDirectory(user, auxFile.getParent()); TexGroup group = new TexGroup("paper", GroupHierarchyType.INDEPENDENT, auxFile, new DefaultAuxParser(new BibDatabase()), new DummyFileUpdateMonitor(), metaData, user); diff --git a/src/test/java/org/jabref/model/strings/StringUtilTest.java b/src/test/java/org/jabref/model/strings/StringUtilTest.java index 307fd886899..3fa176e208b 100644 --- a/src/test/java/org/jabref/model/strings/StringUtilTest.java +++ b/src/test/java/org/jabref/model/strings/StringUtilTest.java @@ -3,7 +3,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -18,7 +17,7 @@ class StringUtilTest { @Test void StringUtilClassIsSmall() throws Exception { - Path path = Paths.get("src", "main", "java", StringUtil.class.getName().replace('.', '/') + ".java"); + Path path = Path.of("src", "main", "java", StringUtil.class.getName().replace('.', '/') + ".java"); int lineCount = Files.readAllLines(path, StandardCharsets.UTF_8).size(); assertTrue(lineCount <= 756, "StringUtil increased in size to " + lineCount + ". " From 21a374f835923fe7f0e25ae0416923a52127dcb6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 30 Apr 2020 11:04:31 +0200 Subject: [PATCH 4/4] Fix code style --- .../org/jabref/logic/openoffice/StyleLoaderTest.java | 10 +++++----- .../org/jabref/logic/texparser/LatexParserTest.java | 8 ++++---- .../logic/texparser/TexBibEntriesResolverTest.java | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java b/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java index 21f0f22d539..be5e3768a01 100644 --- a/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java +++ b/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java @@ -23,7 +23,7 @@ public class StyleLoaderTest { - private static final int numberOfInternalStyles = 2; + private static final int NUMBER_OF_INTERNAL_STYLES = 2; private StyleLoader loader; private OpenOfficePreferences preferences; @@ -68,7 +68,7 @@ public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); loader.addStyleIfValid(filename); - assertEquals(numberOfInternalStyles + 1, loader.getStyles().size()); + assertEquals(NUMBER_OF_INTERNAL_STYLES + 1, loader.getStyles().size()); } @Test @@ -86,7 +86,7 @@ public void testInitalizeWithOneExternalFile() throws URISyntaxException { .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(Collections.singletonList(filename)); loader = new StyleLoader(preferences, layoutPreferences, encoding); - assertEquals(numberOfInternalStyles + 1, loader.getStyles().size()); + assertEquals(NUMBER_OF_INTERNAL_STYLES + 1, loader.getStyles().size()); } @Test @@ -94,7 +94,7 @@ public void testInitalizeWithIncorrectExternalFile() { preferences.setExternalStyles(Collections.singletonList("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky")); loader = new StyleLoader(preferences, layoutPreferences, encoding); - assertEquals(numberOfInternalStyles, loader.getStyles().size()); + assertEquals(NUMBER_OF_INTERNAL_STYLES, loader.getStyles().size()); } @Test @@ -200,6 +200,6 @@ public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() { } assertFalse(loader.removeStyle(toremove.get(0))); - assertEquals(numberOfInternalStyles, loader.getStyles().size()); + assertEquals(NUMBER_OF_INTERNAL_STYLES, loader.getStyles().size()); } } diff --git a/src/test/java/org/jabref/logic/texparser/LatexParserTest.java b/src/test/java/org/jabref/logic/texparser/LatexParserTest.java index fb6acd372a3..4d2df7cf963 100644 --- a/src/test/java/org/jabref/logic/texparser/LatexParserTest.java +++ b/src/test/java/org/jabref/logic/texparser/LatexParserTest.java @@ -31,10 +31,10 @@ public class LatexParserTest { private final static String EINSTEIN_B = "Einstein1920b"; private final static String EINSTEIN_C = "Einstein1920c"; - private static final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); - private static ImportFormatPreferences importFormatPreferences; - private static BibDatabase database; - private static BibDatabase database2; + private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); + private ImportFormatPreferences importFormatPreferences; + private BibDatabase database; + private BibDatabase database2; @BeforeEach private void setUp() { diff --git a/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java b/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java index 9dd0f8808f8..3a91846bf71 100644 --- a/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java +++ b/src/test/java/org/jabref/logic/texparser/TexBibEntriesResolverTest.java @@ -31,11 +31,11 @@ public class TexBibEntriesResolverTest { private final static String EINSTEIN_B = "Einstein1920b"; private final static String EINSTEIN_C = "Einstein1920c"; - private static final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); - private static ImportFormatPreferences importFormatPreferences; - private static BibDatabase database; - private static BibDatabase database2; - private static BibEntry bibEntry; + private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); + private ImportFormatPreferences importFormatPreferences; + private BibDatabase database; + private BibDatabase database2; + private BibEntry bibEntry; @BeforeEach private void setUp() {