forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor DefaultLatexParser, LatexParserResult classes (JabRef#11158)
* Convert Citation class to record * Add citation key to the Citation record We need to represent the citations in a map of `Path` and `Set<Citations>` to update each file individually. * Remove fileList and nestedFiles list from LatexParserResult `fileList` and `nestedFiles` are not used anywhere. * Modified DefaultTexParser to parse file by file * Adapt test classes * Minor changes * Fix MainArchitectureTest * Update DefaultLatexParser.java * Normalize Path to avoid duplications * Add CitationFinder class * new CitationFinder instance if the directory changed * Update parse method to return Optional * Fix refresh button * Fix refresh button
- Loading branch information
1 parent
8329b82
commit 3ddb9e0
Showing
15 changed files
with
419 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/org/jabref/logic/texparser/CitationFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jabref.logic.texparser; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import org.jabref.model.texparser.Citation; | ||
import org.jabref.model.texparser.LatexParserResults; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CitationFinder { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CitationFinder.class); | ||
private static final String TEX_EXT = ".tex"; | ||
private final Path directory; | ||
|
||
private LatexParserResults latexParserResults; | ||
|
||
public CitationFinder(Path directory) { | ||
this.directory = directory; | ||
} | ||
|
||
public Collection<Citation> searchAndParse(String citeKey) throws IOException { | ||
if (latexParserResults == null) { | ||
if (!Files.exists(directory)) { | ||
throw new IOException("Current search directory does not exist: %s".formatted(directory)); | ||
} | ||
|
||
List<Path> texFiles = searchDirectory(directory); | ||
LOGGER.debug("Found tex files: {}", texFiles); | ||
latexParserResults = new DefaultLatexParser().parse(texFiles); | ||
} | ||
|
||
return latexParserResults.getCitationsByKey(citeKey); | ||
} | ||
|
||
/** | ||
* @param directory the directory to search for. It is recursively searched. | ||
*/ | ||
private List<Path> searchDirectory(Path directory) { | ||
LOGGER.debug("Searching directory {}", directory); | ||
try (Stream<Path> paths = Files.walk(directory)) { | ||
return paths.filter(Files::isRegularFile) | ||
.filter(path -> path.toString().endsWith(TEX_EXT)) | ||
.toList(); | ||
} catch (IOException e) { | ||
LOGGER.error("Error while searching files", e); | ||
return List.of(); | ||
} | ||
} | ||
} |
Oops, something went wrong.