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

Find Unlinked files should ignore Thumbs.db, etc #8800

Merged
merged 29 commits into from
Jun 27, 2022
Merged
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3f85f67
added ui component to ignore unlinked files
prashant1712 May 2, 2022
05ae9ef
ignore the files in ".gitignore" when searching for unlinked local files
zhaoqingying123 May 11, 2022
849bb4f
ignore the name of files and the extention in ".gitignore" when searc…
zhaoqingying123 May 11, 2022
c654ca5
Merge branch 'Ziheng' of https://github.com/prashant1712/jabref into …
prashant1712 May 12, 2022
c0926a5
linked ui to the logic & refactored the code
prashant1712 May 12, 2022
595e203
resolved conflicts
prashant1712 May 14, 2022
4be3ce4
adding localization key
prashant1712 May 14, 2022
8f3c80e
Merge branch 'unlinkedFiles#373' of https://github.com/prashant1712/j…
prashant1712 May 14, 2022
165c4a7
Merge branch 'JabRef:main' into unlinkedFiles#373
prashant1712 May 15, 2022
713b954
changelog updated
prashant1712 May 15, 2022
c6cb911
Merge branch 'unlinkedFiles#373' of https://github.com/prashant1712/j…
prashant1712 May 15, 2022
77cf185
Update .gitignore
calixtus May 16, 2022
65c1de5
changes after review
prashant1712 May 17, 2022
3fe6eab
Merge branch 'unlinkedFiles#373' of https://github.com/prashant1712/j…
prashant1712 May 17, 2022
68bdca8
Update CHANGELOG.md
prashant1712 May 17, 2022
0d88c52
Merge branch 'JabRef:main' into unlinkedFiles#373
prashant1712 May 17, 2022
79be853
remove any modification from JabRef_Main.xml
prashant1712 May 17, 2022
a10916e
Rrefactor and move
Siedlerchr May 19, 2022
2dae7de
checkstyle
Siedlerchr May 19, 2022
663f1b4
Update .gitignore
calixtus May 19, 2022
dfefd35
changing to read .gitignore from source directory of JabRef
prashant1712 May 21, 2022
a78b739
using Path.of instead Paths
prashant1712 May 21, 2022
81e8d9d
adding test for filterForUnlinkedFiles
prashant1712 May 22, 2022
1db7b6e
Merge remote-tracking branch 'origin/main' into unlinkedFiles#373
koppor Jun 20, 2022
0a066ea
Rewrote .gitignore logic
koppor Jun 20, 2022
463d3d8
Merge remote-tracking branch 'upstream/main' into unlinkedFiles#373
Siedlerchr Jun 27, 2022
27d021f
Fix tests by adding hashcode and equals
Siedlerchr Jun 27, 2022
9ede81d
Update FileNodeViewModel.java
koppor Jun 27, 2022
17ef36f
Fix indent
koppor Jun 27, 2022
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ gradle.properties
*.ipr
*.iml


# UNKNWON
jabref.xml
*.sonargraph
@@ -239,7 +240,7 @@ fabric.properties
*.zip
*.tar.gz
*.rar

AAGenerator.cpp
calixtus marked this conversation as resolved.
Show resolved Hide resolved
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

@@ -418,7 +419,7 @@ Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

data.tsv
calixtus marked this conversation as resolved.
Show resolved Hide resolved
# Dump file
*.stackdump

41 changes: 32 additions & 9 deletions src/main/java/org/jabref/gui/externalfiles/FileFilterUtils.java
Original file line number Diff line number Diff line change
@@ -6,8 +6,7 @@
import java.nio.file.attribute.FileTime;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

import org.slf4j.Logger;
@@ -16,7 +15,8 @@
public class FileFilterUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(FileFilterUtils.class);

calixtus marked this conversation as resolved.
Show resolved Hide resolved
private static final Set<String> FILEIGNORESET = FileIgnore.getInstance().getIgnoreFileSet();

/* Returns the last edited time of a file as LocalDateTime. */
public static LocalDateTime getFileTime(Path path) {
FileTime lastEditedTime = null;
@@ -33,28 +33,28 @@ public static LocalDateTime getFileTime(Path path) {
return localDateTime;
}

/* Returns true if a file with a specific path
/* Returns true if a file with a specific path
* was edited during the last 24 hours. */
public boolean isDuringLastDay(LocalDateTime fileEditTime) {
LocalDateTime NOW = LocalDateTime.now(ZoneId.systemDefault());
return fileEditTime.isAfter(NOW.minusHours(24));
}

/* Returns true if a file with a specific path
/* Returns true if a file with a specific path
* was edited during the last 7 days. */
public boolean isDuringLastWeek(LocalDateTime fileEditTime) {
LocalDateTime NOW = LocalDateTime.now(ZoneId.systemDefault());
return fileEditTime.isAfter(NOW.minusDays(7));
}

/* Returns true if a file with a specific path
/* Returns true if a file with a specific path
* was edited during the last 30 days. */
public boolean isDuringLastMonth(LocalDateTime fileEditTime) {
LocalDateTime NOW = LocalDateTime.now(ZoneId.systemDefault());
return fileEditTime.isAfter(NOW.minusDays(30));
}

/* Returns true if a file with a specific path
/* Returns true if a file with a specific path
* was edited during the last 365 days. */
public boolean isDuringLastYear(LocalDateTime fileEditTime) {
LocalDateTime NOW = LocalDateTime.now(ZoneId.systemDefault());
@@ -75,7 +75,30 @@ public static boolean filterByDate(Path path, DateRange filter) {
return isInDateRange;
}

/* Sorts a list of Path objects according to the last edited date
/* Returns true if a file should be ignored by .gitignore */
public static boolean filterByFileExtension(Path path) {
try {
String fileExtension = "";
int i = path.toString().lastIndexOf('.');
if (i > 0) {
fileExtension = path.toString().substring(i + 1);
}
if (fileExtension != "" && FILEIGNORESET.contains(fileExtension)) {
return false;
}
} catch (Exception e) {
LOGGER.info("Not file");
}

return true;
}
public static boolean filterByFileName(Path path) {
if (FILEIGNORESET.contains(path.getFileName().toString())){
return false;}
return true;
}

/* Sorts a list of Path objects according to the last edited date
* of their corresponding files, from newest to oldest. */
public List<Path> sortByDateAscending(List<Path> files) {
return files.stream()
@@ -86,7 +109,7 @@ public List<Path> sortByDateAscending(List<Path> files) {
.collect(Collectors.toList());
}

/* Sorts a list of Path objects according to the last edited date
/* Sorts a list of Path objects according to the last edited date
* of their corresponding files, from oldest to newest. */
public List<Path> sortByDateDescending(List<Path> files) {
return files.stream()
49 changes: 49 additions & 0 deletions src/main/java/org/jabref/gui/externalfiles/FileIgnore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.jabref.gui.externalfiles;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class FileIgnore {

private static FileIgnore instance;
private static Set<String> IgnoreFileSet = new HashSet<>();
private static final Logger LOGGER = LoggerFactory.getLogger(FileIgnore.class);
private String gitIgnorePath = ".gitignore";

public FileIgnore() {
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(gitIgnorePath)
))) {
String line = "";
line = br.readLine();
while (line != null) {
line = br.readLine();
if (line != null && line.length() > 2 && line.charAt(0) == '*') {
IgnoreFileSet.add(line.substring(2));
}else if (line != null && line.length() > 1 && line.charAt(0) == '.'){
IgnoreFileSet.add(line.substring(1));
}else if (line != null && line.length() > 1 &&(!line.contains("/"))){
IgnoreFileSet.add(line);
}

}
} catch (IOException e) {
LOGGER.error("No such file.");
}
}

public Set<String> getIgnoreFileSet(){
return IgnoreFileSet;
}

public static FileIgnore getInstance(){
if (instance == null){
return new FileIgnore();
}
return instance;
}
}
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ protected FileNodeViewModel call() throws IOException {
* 'state' must be set to 1, to keep the recursion running. When the states value changes, the method will resolve
* its recursion and return what it has saved so far.
* <br>
* The files are filtered according to the {@link DateRange} filter value
* The files are filtered according to the {@link DateRange} filter value
* and then sorted according to the {@link ExternalFileSorter} value.
*
* @throws IOException if directory is not a directory or empty
@@ -102,7 +102,7 @@ private FileNodeViewModel searchDirectory(Path directory, UnlinkedPDFFileFilter
// filter files according to last edited date.
List<Path> filteredFiles = new ArrayList<Path>();
for (Path path : files) {
if (FileFilterUtils.filterByDate(path, dateFilter)) {
if (FileFilterUtils.filterByDate(path, dateFilter) && FileFilterUtils.filterByFileExtension(path)&&FileFilterUtils.filterByFileName(path)) {
filteredFiles.add(path);
}
}