Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sbom-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
Generated via Gradle task `cyclonedxBom` using the org.cyclonedx.bom plugin configured in the build.
branch: chore/update-sbom
delete-branch: true
labels: "dev: dependencies""
labels: "dev: dependencies"
add-paths: |
bom.json
bom.xml
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We removed unnecessary spacing and margin in the AutomaticFieldEditor. [#13792](https://github.com/JabRef/jabref/pull/13792)
- We fixed an issue where global search auto-completion only worked after switching tabs. [#11428](https://github.com/JabRef/jabref/issues/11428)
- We fixed an issue where hierarchical keywords would only show the parent keyword in the entry editor. [#11390](https://github.com/JabRef/jabref/issues/11390)
- We fixed an issue where some file choosers regarding LaTeX-aux files did not open in the directory of the last selected file. [#8344](https://github.com/JabRef/jabref/issues/8344)
- We fixed an issue where the LaTeX-File directory was not stored correctly in combination with the usage of Groups from aux files. [#13820](https://github.com/JabRef/jabref/issues/13820)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void browse() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.AUX)
.withDefaultExtension(StandardFileType.AUX)
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build();
.withInitialDirectory(auxFileProperty.get() == null ? preferences.getFilePreferences().getWorkingDirectory().toString() : auxFileProperty.get()).build();
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileProperty.setValue(file.toAbsolutePath().toString()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void setLatexDirectory() {
.withInitialDirectory(directory.get()).build();

dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory ->
currentDatabaseContext.getMetaData().setLatexFileDirectory(preferences.getFilePreferences().getUserAndHost(), selectedDirectory.toAbsolutePath()));
currentDatabaseContext.getMetaData().setLatexFileDirectory(preferences.getFilePreferences().getUserAndHost(), selectedDirectory.toString()));

checkAndUpdateDirectory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ private void setupValidation() {
return false;
}
return FileUtil.getFileExtension(input)
.map("aux"::equalsIgnoreCase)
.orElse(false);
.map("aux"::equalsIgnoreCase)
.orElse(false);
}
},
ValidationMessage.error(Localization.lang("Please provide a valid aux file.")));
Expand Down Expand Up @@ -373,7 +373,9 @@ public AbstractGroup resultConverter(ButtonType button) {
Path.of(texGroupFilePathProperty.getValue().trim()),
new DefaultAuxParser(new BibDatabase()),
fileUpdateMonitor,
currentDatabase.getMetaData());
currentDatabase.getMetaData(),
preferences.getFilePreferences().getUserAndHost()
);
}

if (resultingGroup != null) {
Expand Down Expand Up @@ -485,9 +487,10 @@ public void texGroupBrowse() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.AUX)
.withDefaultExtension(StandardFileType.AUX)
.withInitialDirectory(currentDatabase.getMetaData()
.getLatexFileDirectory(preferences.getFilePreferences().getUserAndHost())
.orElse(FileUtil.getInitialDirectory(currentDatabase, preferences.getFilePreferences().getWorkingDirectory()))).build();
.withInitialDirectory(texGroupFilePathProperty.getValue().isBlank() ?
currentDatabase.getMetaData()
.getLatexFileDirectory(preferences.getFilePreferences().getUserAndHost())
.orElse(FileUtil.getInitialDirectory(currentDatabase, preferences.getFilePreferences().getWorkingDirectory())).toString() : texGroupFilePathProperty.get()).build();
dialogService.showFileOpenDialog(fileDialogConfiguration)
.ifPresent(file -> texGroupFilePathProperty.setValue(
FileUtil.relativize(file.toAbsolutePath(), getFileDirectoriesAsPaths()).toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void storeSettings() {
if (latexFileDirectory.isEmpty()) {
newMetaData.clearLatexFileDirectory(preferences.getFilePreferences().getUserAndHost());
} else if (laTexFileDirectoryStatus().isValid()) {
newMetaData.setLatexFileDirectory(preferences.getFilePreferences().getUserAndHost(), Path.of(latexFileDirectory));
newMetaData.setLatexFileDirectory(preferences.getFilePreferences().getUserAndHost(), latexFileDirectory);
}

databaseContext.setMetaData(newMetaData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private BibDatabaseContext getBibDatabaseContextForSharedDatabase() {
preferences.getBibEntryPreferences().getKeywordSeparator(),
preferences.getFieldPreferences(),
preferences.getCitationKeyPatternPreferences().getKeyPatterns(),
fileUpdateMonitor);
fileUpdateMonitor,
preferences.getFilePreferences().getUserAndHost());
bibDatabaseContext.convertToSharedDatabase(synchronizer);
return bibDatabaseContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static Map<String, String> getSerializedStringMap(MetaData metaData,
metaData.getUserFileDirectories().forEach((user, path) -> stringyMetaData
.put(MetaData.FILE_DIRECTORY + '-' + user, List.of(path.trim())));
metaData.getLatexFileDirectories().forEach((user, path) -> stringyMetaData
.put(MetaData.FILE_DIRECTORY_LATEX + '-' + user, List.of(path.toString().trim())));
.put(MetaData.FILE_DIRECTORY_LATEX + '-' + user, List.of(path.trim())));
metaData.getVersionDBStructure().ifPresent(
versionDBStructure -> stringyMetaData.put(MetaData.VERSION_DB_STRUCT, List.of(versionDBStructure.trim())));
metaData.getBlgFilePaths().forEach((user, path) -> stringyMetaData.put(MetaData.BLG_FILE_PATH + "-" + user, List.of(path.toString().trim())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.importer;

import org.jabref.logic.FilePreferences;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.importer.util.GrobidPreferences;
Expand All @@ -13,5 +14,6 @@ public record ImportFormatPreferences(
FieldPreferences fieldPreferences,
XmpPreferences xmpPreferences,
DOIPreferences doiPreferences,
GrobidPreferences grobidPreferences) {
GrobidPreferences grobidPreferences,
FilePreferences filePreferences) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ private ParserResult parseFileContent() throws IOException {
try {
MetaData metaData = metaDataParser.parse(
meta,
importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
importFormatPreferences.bibEntryPreferences().getKeywordSeparator(),
importFormatPreferences.filePreferences().getUserAndHost());
if (bibDeskGroupTreeNode != null) {
metaData.getGroups().ifPresentOrElse(existingGroupTree -> {
String existingGroups = meta.get(MetaData.GROUPSTREE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class GroupsParser {
private GroupsParser() {
}

public static GroupTreeNode importGroups(List<String> orderedData, Character keywordSeparator, FileUpdateMonitor fileMonitor, MetaData metaData)
public static GroupTreeNode importGroups(List<String> orderedData, Character keywordSeparator, FileUpdateMonitor fileMonitor, MetaData metaData, String userAndHost)
throws ParseException {
try {
GroupTreeNode cursor = null;
GroupTreeNode root = null;
for (String string : orderedData) {
// This allows to read databases that have been modified by, e.g., BibDesk
// This allows reading databases that have been modified by, e.g., BibDesk
string = string.trim();
if (string.isEmpty()) {
continue;
Expand All @@ -62,7 +62,7 @@ public static GroupTreeNode importGroups(List<String> orderedData, Character key
throw new ParseException("Expected \"" + string + "\" to contain whitespace");
}
int level = Integer.parseInt(string.substring(0, spaceIndex));
AbstractGroup group = GroupsParser.fromString(string.substring(spaceIndex + 1), keywordSeparator, fileMonitor, metaData);
AbstractGroup group = GroupsParser.fromString(string.substring(spaceIndex + 1), keywordSeparator, fileMonitor, metaData, userAndHost);
GroupTreeNode newNode = GroupTreeNode.fromGroup(group);
if (cursor == null) {
// create new root
Expand Down Expand Up @@ -92,7 +92,7 @@ public static GroupTreeNode importGroups(List<String> orderedData, Character key
* @return New instance of the encoded group.
* @throws ParseException If an error occurred and a group could not be created, e.g. due to a malformed regular expression.
*/
public static AbstractGroup fromString(String s, Character keywordSeparator, FileUpdateMonitor fileMonitor, MetaData metaData)
public static AbstractGroup fromString(String s, Character keywordSeparator, FileUpdateMonitor fileMonitor, MetaData metaData, String userAndHost)
throws ParseException {
if (s.startsWith(MetadataSerializationConfiguration.KEYWORD_GROUP_ID)) {
return keywordGroupFromString(s, keywordSeparator);
Expand All @@ -119,13 +119,13 @@ public static AbstractGroup fromString(String s, Character keywordSeparator, Fil
return automaticKeywordGroupFromString(s);
}
if (s.startsWith(MetadataSerializationConfiguration.TEX_GROUP_ID)) {
return texGroupFromString(s, fileMonitor, metaData);
return texGroupFromString(s, fileMonitor, metaData, userAndHost);
}

throw new ParseException("Unknown group: " + s);
}

private static AbstractGroup texGroupFromString(String string, FileUpdateMonitor fileMonitor, MetaData metaData) throws ParseException {
private static AbstractGroup texGroupFromString(String string, FileUpdateMonitor fileMonitor, MetaData metaData, String userAndHost) throws ParseException {
QuotedStringTokenizer tok = new QuotedStringTokenizer(string.substring(MetadataSerializationConfiguration.TEX_GROUP_ID
.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);

Expand All @@ -134,14 +134,14 @@ private static AbstractGroup texGroupFromString(String string, FileUpdateMonitor
try {
Path path = Path.of(tok.nextToken());
try {
TexGroup newGroup = TexGroup.create(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData);
TexGroup newGroup = TexGroup.create(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData, userAndHost);
addGroupDetails(tok, newGroup);
return newGroup;
} catch (IOException ex) {
// Problem accessing file -> create without file monitoring
LOGGER.warn("Could not access file {}. The group {} will not reflect changes to the aux file.", path, name, ex);

TexGroup newGroup = TexGroup.create(name, context, path, new DefaultAuxParser(new BibDatabase()), metaData);
TexGroup newGroup = TexGroup.create(name, context, path, new DefaultAuxParser(new BibDatabase()), metaData, userAndHost);
addGroupDetails(tok, newGroup);
return newGroup;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ private static AbstractGroup automaticKeywordGroupFromString(String string) {
*
* @param s The String representation obtained from KeywordGroup.toString()
*/
private static KeywordGroup keywordGroupFromString(String s, Character keywordSeparator) throws ParseException {
private static KeywordGroup keywordGroupFromString(String s, Character keywordSeparator) {
if (!s.startsWith(MetadataSerializationConfiguration.KEYWORD_GROUP_ID)) {
throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\".");
}
Expand Down Expand Up @@ -267,7 +267,7 @@ private static ExplicitGroup legacyExplicitGroupFromString(String input, Charact
/**
* Called only when created fromString.
* JabRef used to store the entries of an explicit group in the serialization, e.g.
* ExplicitGroup:GroupName\;0\;Key1\;Key2\;;
* ExplicitGroup:GroupName\;0\;Key1\;Key2\;;
* This method exists for backwards compatibility.
*/
private static void addLegacyEntryKeys(QuotedStringTokenizer tok, ExplicitGroup group) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.jabref.model.metadata.ContentSelectors;
import org.jabref.model.metadata.MetaData;
import org.jabref.model.metadata.SaveOrder;
import org.jabref.model.metadata.UserHostInfo;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.FileUpdateMonitor;

Expand Down Expand Up @@ -94,16 +93,16 @@ public static Optional<BibEntryType> parseCustomEntryType(String comment) {
/**
* Parses the given data map and returns a new resulting {@link MetaData} instance.
*/
public MetaData parse(Map<String, String> data, Character keywordSeparator) throws ParseException {
return parse(new MetaData(), data, keywordSeparator);
public MetaData parse(Map<String, String> data, Character keywordSeparator, String userAndHost) throws ParseException {
return parse(new MetaData(), data, keywordSeparator, userAndHost);
}

/**
* Parses the data map and changes the given {@link MetaData} instance respectively.
*
* @return the given metaData instance (which is modified, too)
*/
public MetaData parse(MetaData metaData, Map<String, String> data, Character keywordSeparator) throws ParseException {
public MetaData parse(MetaData metaData, Map<String, String> data, Character keywordSeparator, String userAndHost) throws ParseException {
CitationKeyPattern defaultCiteKeyPattern = CitationKeyPattern.NULL_CITATION_KEY_PATTERN;
Map<EntryType, CitationKeyPattern> nonDefaultCiteKeyPatterns = new HashMap<>();

Expand Down Expand Up @@ -131,20 +130,7 @@ public MetaData parse(MetaData metaData, Map<String, String> data, Character key
} else if (entry.getKey().startsWith(MetaData.FILE_DIRECTORY_LATEX)) {
// The user-host string starts directly after FILE_DIRECTORY_LATEX + '-'
String userHostString = entry.getKey().substring(MetaData.FILE_DIRECTORY_LATEX.length() + 1);
Path path = Path.of(parseDirectory(entry.getValue())).normalize();

UserHostInfo userHostInfo = UserHostInfo.parse(userHostString);
String currentHost = org.jabref.logic.os.OS.getHostName();

if (!userHostInfo.host().isEmpty() && !userHostInfo.host().equals(currentHost)) {
// If the host doesn't match the current host, we need to use the current user-host
// This w that the LaTeX file directory is set for the current user on the current host
LOGGER.warn("Host mismatch for LaTeX file directory: {} vs current host {}", userHostInfo.host(), currentHost);
// We don't have access to the current user-host here, so we'll just store the path
// The correct user-host will be used when the path is retrieved via the GUI
}

metaData.setLatexFileDirectory(userHostString, path);
metaData.setLatexFileDirectory(userHostString, parseDirectory(entry.getValue()));
} else if (MetaData.SAVE_ACTIONS.equals(entry.getKey())) {
metaData.setSaveActions(fieldFormatterCleanupsParse(values));
} else if (MetaData.DATABASE_TYPE.equals(entry.getKey())) {
Expand All @@ -160,7 +146,7 @@ public MetaData parse(MetaData metaData, Map<String, String> data, Character key
} else if (MetaData.SAVE_ORDER_CONFIG.equals(entry.getKey())) {
metaData.setSaveOrder(SaveOrder.parse(values));
} else if (MetaData.GROUPSTREE.equals(entry.getKey()) || MetaData.GROUPSTREE_LEGACY.equals(entry.getKey())) {
metaData.setGroups(GroupsParser.importGroups(values, keywordSeparator, fileMonitor, metaData));
metaData.setGroups(GroupsParser.importGroups(values, keywordSeparator, fileMonitor, metaData, userAndHost));
} else if (MetaData.GROUPS_SEARCH_SYNTAX_VERSION.equals(entry.getKey())) {
Version version = Version.parse(getSingleItem(values));
metaData.setGroupSearchSyntaxVersion(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,8 @@ public ImportFormatPreferences getImportFormatPreferences() {
getFieldPreferences(),
getXmpPreferences(),
getDOIPreferences(),
getGrobidPreferences());
getGrobidPreferences(),
getFilePreferences());
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public class DBMSSynchronizer implements DatabaseSynchronizer {
private final FieldPreferences fieldPreferences;
private final FileUpdateMonitor fileMonitor;
private Optional<BibEntry> lastEntryChanged;
private final String userAndHost;

public DBMSSynchronizer(BibDatabaseContext bibDatabaseContext, Character keywordSeparator,
FieldPreferences fieldPreferences,
GlobalCitationKeyPatterns globalCiteKeyPattern, FileUpdateMonitor fileMonitor) {
GlobalCitationKeyPatterns globalCiteKeyPattern, FileUpdateMonitor fileMonitor, String userAndHost) {
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);
this.bibDatabase = bibDatabaseContext.getDatabase();
this.metaData = bibDatabaseContext.getMetaData();
Expand All @@ -70,6 +71,7 @@ public DBMSSynchronizer(BibDatabaseContext bibDatabaseContext, Character keyword
this.keywordSeparator = keywordSeparator;
this.globalCiteKeyPattern = Objects.requireNonNull(globalCiteKeyPattern);
this.lastEntryChanged = Optional.empty();
this.userAndHost = userAndHost;
}

/**
Expand Down Expand Up @@ -267,7 +269,7 @@ public void synchronizeLocalMetaData() {
try {
metaData.setEventPropagation(false);
MetaDataParser parser = new MetaDataParser(fileMonitor);
parser.parse(metaData, dbmsProcessor.getSharedMetaData(), keywordSeparator);
parser.parse(metaData, dbmsProcessor.getSharedMetaData(), keywordSeparator, userAndHost);
metaData.setEventPropagation(true);
} catch (ParseException e) {
LOGGER.error("Parse error", e);
Expand Down
Loading
Loading