Skip to content

Commit

Permalink
Fix #4735. Catch file not found exception and handle non existing aux…
Browse files Browse the repository at this point in the history
… files gracefully.
  • Loading branch information
tobiasdiez committed Apr 2, 2019
1 parent 05eaa64 commit 4cfae78
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where selecting a group messed up the focus of the main table / entry editor. https://github.com/JabRef/jabref/issues/3367
- We fixed an issue where composite author names were sorted incorrectly. https://github.com/JabRef/jabref/issues/2828
- We fixed an issue where commands followed by `-` didn't work. [#3805](https://github.com/JabRef/jabref/issues/3805)
- We fixed an issue where a non-existing aux file in a group made it impossible to open the library. [#4735](https://github.com/JabRef/jabref/issues/4735)
- We fixed an issue where some journal names were wrongly marked as abbreviated. [#4115](https://github.com/JabRef/jabref/issues/4115)
- We fixed an issue where the custom file column were sorted incorrectly. https://github.com/JabRef/jabref/issues/3119
- We fixed an issues where the entry losses focus when a field is edited and at the same time used for sorting. https://github.com/JabRef/jabref/issues/3373
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ groupName, getContext(),
autoGroupPersonsField.getText().trim());
}
} else if (texRadioButton.isSelected()) {
resultingGroup = new TexGroup(groupName, getContext(),
resultingGroup = TexGroup.create(groupName, getContext(),
Paths.get(texGroupFilePath.getText().trim()), new DefaultAuxParser(new BibDatabase()), Globals.getFileUpdateMonitor(), basePanel.getBibDatabaseContext().getMetaData());
}

Expand Down Expand Up @@ -466,7 +466,7 @@ private VBox createOptionsTexGroup() {
texGroupBrowseButton.setOnAction((ActionEvent e) -> openBrowseDialog());
texGroupHBox.getChildren().add(texGroupFilePath);
texGroupHBox.getChildren().add(texGroupBrowseButton);
texGroupHBox.setHgrow(texGroupFilePath, Priority.ALWAYS);
HBox.setHgrow(texGroupFilePath, Priority.ALWAYS);
texPanel.getChildren().add(texGroupHBox);
return texPanel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private AuxParserResult parseAuxFile(Path auxFile) {
matchNestedAux(auxFile, result, fileList, line);
}
} catch (FileNotFoundException e) {
LOGGER.info("Cannot locate input file", e);
LOGGER.warn("Cannot locate input file", e);
} catch (IOException e) {
LOGGER.warn("Problem opening file", e);
}
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/jabref/logic/importer/util/GroupsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.FileUpdateMonitor;

import org.slf4j.LoggerFactory;

/**
* Converts string representation of groups to a parsed {@link GroupTreeNode}.
*/
public class GroupsParser {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(GroupsParser.class);

private GroupsParser() {
}

Expand Down Expand Up @@ -123,9 +127,18 @@ private static AbstractGroup texGroupFromString(String string, FileUpdateMonitor
GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
try {
Path path = Paths.get(tok.nextToken());
TexGroup newGroup = new TexGroup(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData);
addGroupDetails(tok, newGroup);
return newGroup;
try {
TexGroup newGroup = TexGroup.create(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData);
addGroupDetails(tok, newGroup);
return newGroup;
} catch (IOException ex) {
// Problem accessing file -> create without file monitoring
LOGGER.warn("Could not access file " + path + ". The group " + name + " will not reflect changes to the aux file.", ex);

TexGroup newGroup = TexGroup.createWithoutFileMonitoring(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData);
addGroupDetails(tok, newGroup);
return newGroup;
}
} catch (InvalidPathException | IOException ex) {
throw new ParseException(ex);
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/jabref/model/groups/TexGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,30 @@ public class TexGroup extends AbstractGroup implements FileUpdateListener {
private final MetaData metaData;
private String user;

public TexGroup(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData, String user) throws IOException {
TexGroup(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData, String user) {
super(name, context);
this.metaData = metaData;
this.user = user;
this.filePath = expandPath(Objects.requireNonNull(filePath));
this.auxParser = auxParser;
this.fileMonitor = fileMonitor;
fileMonitor.addListenerForFile(this.filePath, this);
}

public TexGroup(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData) throws IOException {
TexGroup(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData) throws IOException {
this(name, context, filePath, auxParser, fileMonitor, metaData, System.getProperty("user.name") + '-' + InetAddress.getLocalHost().getHostName());
}

public static TexGroup create(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData) throws IOException {
TexGroup group = new TexGroup(name, context, filePath, auxParser, fileMonitor, metaData);
fileMonitor.addListenerForFile(filePath, group);
return group;
}

public static TexGroup createWithoutFileMonitoring(String name, GroupHierarchyType context, Path filePath, AuxParser auxParser, FileUpdateMonitor fileMonitor, MetaData metaData) throws IOException {
return new TexGroup(name, context, filePath, auxParser, fileMonitor, metaData);
}


@Override
public boolean contains(BibEntry entry) {
if (keysUsedInAux == null) {
Expand Down Expand Up @@ -124,7 +134,7 @@ private List<Path> getFileDirectoriesAsPaths() {
List<Path> fileDirs = new ArrayList<>();

metaData.getLaTexFileDirectory(user)
.ifPresent(laTexFileDirectory -> fileDirs.add(laTexFileDirectory));
.ifPresent(fileDirs::add);

return fileDirs;
}
Expand Down

0 comments on commit 4cfae78

Please sign in to comment.