Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Removed BIB file directory from search when preferences has option unchecked #6451

Merged
merged 10 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed to only search file links in the BIB file location directory when preferences has corresponding checkbox checked. [#5891](https://github.com/JabRef/jabref/issues/5891)
- We fixed wrong button order (Apply and Cancel) in ManageProtectedTermsDialog.
- We fixed an issue with incompatible characters at BibTeX key [#6257](https://github.com/JabRef/jabref/issues/6257)
- We fixed an issue where dash (`-`) was reported as illegal BibTeX key [#6295](https://github.com/JabRef/jabref/issues/6295)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/preferences/FileTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<TextField fx:id="mainFileDir" HBox.hgrow="ALWAYS"/>
<Button onAction="#mainFileDirBrowse" text="%Browse"/>
</HBox>
<CheckBox fx:id="useBibLocationAsPrimary" text="%Use the BIB file location as primary file directory">
<CheckBox fx:id="useBibLocationAsPrimary" text="%Search and store files relative to library file location">
<tooltip>
<Tooltip
text="%When downloading files, or moving linked files to the file directory, prefer the BIB file location rather than the file directory set above"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ public List<Path> getFileDirectoriesAsPaths(FilePreferences preferences) {
// Check if we should add it as primary file dir (first in the list) or not:
if (preferences.isBibLocationAsPrimary()) {
fileDirs.add(0, parentPath);
} else {
fileDirs.add(parentPath);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ Web\ search=Web search
Style\ selection=Style selection
No\ valid\ style\ file\ defined=No valid style file defined
Choose\ pattern=Choose pattern
Use\ the\ BIB\ file\ location\ as\ primary\ file\ directory=Use the BIB file location as primary file directory
Search\ and\ store\ files\ relative\ to\ library\ file\ location=Search and store files relative to library file location
Could\ not\ run\ the\ gnuclient/emacsclient\ program.\ Make\ sure\ you\ have\ the\ emacsclient/gnuclient\ program\ installed\ and\ available\ in\ the\ PATH.=Could not run the gnuclient/emacsclient program. Make sure you have the emacsclient/gnuclient program installed and available in the PATH.
You\ must\ select\ either\ a\ valid\ style\ file,\ or\ use\ one\ of\ the\ default\ styles.=You must select either a valid style file, or use one of the default styles.

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ This\ entry\ type\ is\ intended\ for\ sources\ such\ as\ web\ sites\ which\ are\
A\ single-volume\ work\ of\ reference\ such\ as\ an\ encyclopedia\ or\ a\ dictionary.=Неделимая работа или ссылка, как энциклопедия или словарь.
A\ technical\ report,\ research\ report,\ or\ white\ paper\ published\ by\ a\ university\ or\ some\ other\ institution.=Технический отчет, исследовательский отчет, или белая книга, выпущенная институтом или другим учреждением.
An\ entry\ set\ is\ a\ group\ of\ entries\ which\ are\ cited\ as\ a\ single\ reference\ and\ listed\ as\ a\ single\ item\ in\ the\ bibliography.=Набор записей представляет собой группу записей, которые приводятся в виде единой ссылки и перечислены в виде одного элемента в библиографии.
Supplemental\ material\ in\ a\ "Book".\ This\ type\ is\ provided\ for\ elements\ such\ as\ prefaces,\ introductions,\ forewords,\ afterwords,\ etc.\ which\ often\ have\ a\ generic\ title\ only.=Дополнительный материал в "Книге" предназначен для таких элементов, как предисловия, введения, послесловия и т.д.
Supplemental\ material\ in\ a\ "Book".\ This\ type\ is\ provided\ for\ elements\ such\ as\ prefaces,\ introductions,\ forewords,\ afterwords,\ etc.\ which\ often\ have\ a\ generic\ title\ only.=Дополнительный материал в "Книге" предназначен для таких элементов, как предисловия, введения, послесловия и т.д.
Supplemental\ material\ in\ a\ "Collection".=Дополнительные материалы в "Коллекции".
Supplemental\ material\ in\ a\ "Periodical".\ This\ type\ may\ be\ useful\ when\ referring\ to\ items\ such\ as\ regular\ columns,\ obituaries,\ letters\ to\ the\ editor,\ etc.\ which\ only\ have\ a\ generic\ title.=Дополнительные материалы в "Периодическом издании". Этот тип может быть полезен при обращении к таким элементам, как обычные колонки, некрологи, письма к редактору и т.д., которые имеют только общее название.
A\ thesis\ written\ for\ an\ educational\ institution\ to\ satisfy\ the\ requirements\ for\ a\ degree.=Тезис, написанный для учебного заведения с целью удовлетворения требований к степени.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,31 @@ public class AutoSetFileLinksUtilTest {
private final BibDatabaseContext databaseContext = mock(BibDatabaseContext.class);
private final ExternalFileTypes externalFileTypes = mock(ExternalFileTypes.class);
private final BibEntry entry = new BibEntry(StandardEntryType.Article);
private Path path = null;

@BeforeEach
public void setUp(@TempDir Path folder) throws Exception {
Path path = folder.resolve("CiteKey.pdf");
path = folder.resolve("CiteKey.pdf");
Files.createFile(path);
entry.setCiteKey("CiteKey");
when(databaseContext.getFileDirectoriesAsPaths(any())).thenReturn(Collections.singletonList(path.getParent()));
when(externalFileTypes.getExternalFileTypeSelection()).thenReturn(new TreeSet<>(ExternalFileTypes.getDefaultExternalFileTypes()));
}

@Test
public void test() throws Exception {
public void testFindAssociatedNotLinkedFilesSuccess() throws Exception {
// Due to mocking the externalFileType class, the file extension will not be found

when(databaseContext.getFileDirectoriesAsPaths(any())).thenReturn(Collections.singletonList(path.getParent()));
Copy link
Member

Choose a reason for hiding this comment

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

Why did you move the mockings here?

Copy link
Author

Choose a reason for hiding this comment

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

This mocking of getFileDirectoriesAsPaths method returns non empty values, which is not applicable for the newly added test case testFindAssociatedNotLinkedFilesForEmptySearchDir. The new test case expects that getFileDirectoriesAsPaths would return empty list.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, but the externalFileType should be independent of this

Copy link
Author

Choose a reason for hiding this comment

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

yeah, agreed. I will move that one back to setup.

List<LinkedFile> expected = Collections.singletonList(new LinkedFile("", "CiteKey.pdf", ""));

AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, fileDirPrefs, autoLinkPrefs, externalFileTypes);
List<LinkedFile> actual = util.findAssociatedNotLinkedFiles(entry);
assertEquals(expected, actual);
}

@Test
public void testFindAssociatedNotLinkedFilesForEmptySearchDir() throws Exception {
when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(false);
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, fileDirPrefs, autoLinkPrefs, externalFileTypes);
List<LinkedFile> actual = util.findAssociatedNotLinkedFiles(entry);
assertEquals(Collections.emptyList(), actual);
}
}
14 changes: 13 additions & 1 deletion src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -32,6 +35,7 @@ class MoveFilesCleanupTest {
private MoveFilesCleanup cleanup;
private BibEntry entry;
private FilePreferences filePreferences;
private BibDatabaseContext databaseContext;

@BeforeEach
void setUp(@TempDir Path bibFolder) throws IOException {
Expand All @@ -47,7 +51,7 @@ void setUp(@TempDir Path bibFolder) throws IOException {

MetaData metaData = new MetaData();
metaData.setDefaultFileDirectory(defaultFileFolder.toAbsolutePath().toString());
BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(), metaData);
databaseContext = new BibDatabaseContext(new BibDatabase(), metaData);
Files.createFile(bibFolder.resolve("test.bib"));
databaseContext.setDatabasePath(bibFolder.resolve("test.bib"));

Expand Down Expand Up @@ -119,4 +123,12 @@ void movesFileWithSubdirectoryPattern() throws Exception {
assertFalse(Files.exists(fileBefore));
assertTrue(Files.exists(fileAfter));
}

@Test
void movesFileWithNoDirectory() throws Exception {
databaseContext.setMetaData(new MetaData());
when(filePreferences.getFileDirPattern()).thenReturn("");
List<FieldChange> changes = cleanup.cleanup(entry);
assertEquals(Collections.emptyList(), changes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* This class tests the Integrity Checker as a whole.
Expand Down Expand Up @@ -177,8 +178,10 @@ private void assertWrong(BibDatabaseContext context) {
}

private void assertCorrect(BibDatabaseContext context) {
FilePreferences filePreferencesMock = mock(FilePreferences.class);
when(filePreferencesMock.isBibLocationAsPrimary()).thenReturn(true);
List<IntegrityMessage> messages = new IntegrityCheck(context,
mock(FilePreferences.class),
filePreferencesMock,
createBibtexKeyPatternPreferences(),
JournalAbbreviationLoader.loadBuiltInRepository(), false
).check();
Expand Down