Skip to content

Commit 0c027b0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into copyLinkedFilesInContextmenu
* upstream/master: (21 commits) Bump junit-vintage-engine from 5.4.2 to 5.5.0 Bump log4j-api from 2.11.2 to 2.12.0 Bump junit-platform-launcher from 1.4.2 to 1.5.0 Bump log4j-core from 2.11.2 to 2.12.0 Bump log4j-slf4j18-impl from 2.11.2 to 2.12.0 Bump log4j-jul from 2.11.2 to 2.12.0 Bump junit-jupiter from 5.4.2 to 5.5.0 Bump com.github.johnrengelman.shadow from 5.0.0 to 5.1.0 Bump log4j-jcl from 2.11.2 to 2.12.0 Bump fontbox from 2.0.15 to 2.0.16 (#5080) Bump pdfbox from 2.0.15 to 2.0.16 (#5081) Bump xmpbox from 2.0.15 to 2.0.16 (#5082) Update FUNDING.yml Delete autoapproval.yml Bump com.install4j.gradle from 7.0.11 to 7.0.12 (#5077) Configure autoapproval plugin for dependabot Bump xmlunit-matchers from 2.6.2 to 2.6.3 (#5074) Bump checkstyle from 8.21 to 8.22 (#5072) Bump xmlunit-core from 2.6.2 to 2.6.3 (#5073) Refactor for loop to stream in groupTree Close version socket ...
2 parents 48087ed + a50cb34 commit 0c027b0

File tree

6 files changed

+76
-73
lines changed

6 files changed

+76
-73
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# These are supported funding model platforms
22

33
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4-
patreon: koppor
4+
patreon: # Patreon user account
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username
77
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
88
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9-
liberapay: koppor
9+
liberapay: JabRef
1010
issuehunt: # Replace with a single IssueHunt username
1111
otechie: # Replace with a single Otechie username
1212
custom: https://github.com/JabRef/jabref/wiki/Donations # Replace with a single custom sponsorship URL

build.gradle

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ buildscript {
1717

1818
plugins {
1919
id 'com.gradle.build-scan' version '2.3'
20-
id 'com.install4j.gradle' version '7.0.11'
21-
id 'com.github.johnrengelman.shadow' version '5.0.0'
20+
id 'com.install4j.gradle' version '7.0.12'
21+
id 'com.github.johnrengelman.shadow' version '5.1.0'
2222
id "com.simonharrer.modernizer" version '1.6.0-1'
2323
id 'me.champeau.gradle.jmh' version '0.4.8'
2424
id 'net.ltgt.errorprone' version '0.8.1'
@@ -90,9 +90,9 @@ dependencies {
9090
// Include all jar-files in the 'lib' folder as dependencies
9191
compile fileTree(dir: 'lib', includes: ['*.jar'])
9292

93-
compile 'org.apache.pdfbox:pdfbox:2.0.15'
94-
compile 'org.apache.pdfbox:fontbox:2.0.15'
95-
compile 'org.apache.pdfbox:xmpbox:2.0.15'
93+
compile 'org.apache.pdfbox:pdfbox:2.0.16'
94+
compile 'org.apache.pdfbox:fontbox:2.0.16'
95+
compile 'org.apache.pdfbox:xmpbox:2.0.16'
9696

9797
compile group: 'org.apache.tika', name: 'tika-core', version: '1.21'
9898

@@ -143,10 +143,10 @@ dependencies {
143143

144144
// >1.8.0-beta is required for java 9 compatibility
145145
compile 'org.slf4j:slf4j-api:2.0.0-alpha0'
146-
compile 'org.apache.logging.log4j:log4j-slf4j18-impl:2.11.2'
147-
compile 'org.apache.logging.log4j:log4j-jcl:2.11.2'
148-
compile 'org.apache.logging.log4j:log4j-api:2.11.2'
149-
compile 'org.apache.logging.log4j:log4j-core:2.11.2'
146+
compile 'org.apache.logging.log4j:log4j-slf4j18-impl:2.12.0'
147+
compile 'org.apache.logging.log4j:log4j-jcl:2.12.0'
148+
compile 'org.apache.logging.log4j:log4j-api:2.12.0'
149+
compile 'org.apache.logging.log4j:log4j-core:2.12.0'
150150

151151
compile 'de.undercouch:citeproc-java:1.0.1'
152152

@@ -157,23 +157,23 @@ dependencies {
157157
compile group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.3.1'
158158
compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.3.1'
159159

160-
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
161-
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.4.2'
162-
testCompile 'org.junit.platform:junit-platform-launcher:1.4.2'
160+
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0'
161+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.0'
162+
testCompile 'org.junit.platform:junit-platform-launcher:1.5.0'
163163

164-
testRuntime 'org.apache.logging.log4j:log4j-core:2.11.1'
165-
testRuntime 'org.apache.logging.log4j:log4j-jul:2.11.2'
164+
testRuntime 'org.apache.logging.log4j:log4j-core:2.12.0'
165+
testRuntime 'org.apache.logging.log4j:log4j-jul:2.12.0'
166166
testCompile 'org.mockito:mockito-core:2.28.2'
167167
testCompile 'com.github.tomakehurst:wiremock:2.23.2'
168168
testCompile 'org.reflections:reflections:0.9.11'
169-
testCompile 'org.xmlunit:xmlunit-core:2.6.2'
170-
testCompile 'org.xmlunit:xmlunit-matchers:2.6.2'
169+
testCompile 'org.xmlunit:xmlunit-core:2.6.3'
170+
testCompile 'org.xmlunit:xmlunit-matchers:2.6.3'
171171
testRuntime 'com.tngtech.archunit:archunit-junit5-engine:0.10.2'
172172
testCompile 'com.tngtech.archunit:archunit-junit5-api:0.10.2'
173173
testCompile "org.testfx:testfx-core:4.0.+"
174174
testCompile "org.testfx:testfx-junit5:4.0.+"
175175

176-
checkstyle 'com.puppycrawl.tools:checkstyle:8.21'
176+
checkstyle 'com.puppycrawl.tools:checkstyle:8.22'
177177
xjc 'com.sun.xml.bind:jaxb-xjc:2.2.4-1'
178178
jython 'org.python:jython-standalone:2.7.1'
179179
}

src/main/java/org/jabref/gui/ClipBoardManager.java

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.jabref.gui;
22

3+
import java.io.ByteArrayInputStream;
34
import java.io.IOException;
5+
import java.nio.charset.StandardCharsets;
46
import java.util.Collections;
57
import java.util.List;
68
import java.util.Optional;
@@ -28,13 +30,11 @@
2830
import org.slf4j.LoggerFactory;
2931

3032
public class ClipBoardManager {
31-
3233
public static final DataFormat XML = new DataFormat("application/xml");
33-
34+
3435
private static final Logger LOGGER = LoggerFactory.getLogger(ClipBoardManager.class);
3536

3637
private final Clipboard clipboard;
37-
3838
private final ImportFormatReader importFormatReader;
3939

4040
public ClipBoardManager() {
@@ -63,9 +63,8 @@ public String getContents() {
6363
String result = clipboard.getString();
6464
if (result == null) {
6565
return "";
66-
} else {
67-
return result;
6866
}
67+
return result;
6968
}
7069

7170
public void setHtmlContent(String html) {
@@ -89,40 +88,55 @@ public void setContent(List<BibEntry> entries) throws IOException {
8988
clipboard.setContent(content);
9089
}
9190

92-
public List<BibEntry> extractEntries() {
91+
public List<BibEntry> extractData() {
9392
Object entries = clipboard.getContent(DragAndDropDataFormats.ENTRIES);
9493

94+
if (entries == null) {
95+
return handleStringData(clipboard.getString());
96+
}
97+
return handleBibTeXData((String) entries);
98+
}
99+
100+
private List<BibEntry> handleBibTeXData(String entries) {
95101
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
96-
if (entries != null) {
97-
// We have determined that the clipboard data is a set of entries (serialized as a string).
98-
try {
99-
return parser.parseEntries((String) entries);
100-
} catch (ParseException ex) {
101-
LOGGER.error("Could not paste", ex);
102-
}
103-
} else {
104-
String data = clipboard.getString();
105-
if (data != null) {
106-
try {
107-
// fetch from doi
108-
Optional<DOI> doi = DOI.parse(data);
109-
if (doi.isPresent()) {
110-
LOGGER.info("Found DOI in clipboard");
111-
Optional<BibEntry> entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(doi.get().getDOI());
112-
return OptionalUtil.toList(entry);
113-
} else {
114-
try {
115-
UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data);
116-
return unknownFormatImport.parserResult.getDatabase().getEntries();
117-
} catch (ImportException e) {
118-
// import failed and result will be empty
119-
}
120-
}
121-
} catch (FetcherException ex) {
122-
LOGGER.error("Error while fetching", ex);
123-
}
124-
}
102+
try {
103+
return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8)));
104+
} catch (ParseException ex) {
105+
LOGGER.error("Could not paste", ex);
106+
return Collections.emptyList();
107+
}
108+
}
109+
110+
private List<BibEntry> handleStringData(String data) {
111+
if (data == null || data.isEmpty()) {
112+
return Collections.emptyList();
113+
}
114+
115+
Optional<DOI> doi = DOI.parse(data);
116+
if (doi.isPresent()) {
117+
return fetchByDOI(doi.get());
118+
}
119+
120+
return tryImportFormats(data);
121+
}
122+
123+
private List<BibEntry> tryImportFormats(String data) {
124+
try {
125+
UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data);
126+
return unknownFormatImport.parserResult.getDatabase().getEntries();
127+
} catch (ImportException ignored) {
128+
return Collections.emptyList();
129+
}
130+
}
131+
132+
private List<BibEntry> fetchByDOI(DOI doi) {
133+
LOGGER.info("Found DOI in clipboard");
134+
try {
135+
Optional<BibEntry> entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(doi.getDOI());
136+
return OptionalUtil.toList(entry);
137+
} catch (FetcherException ex) {
138+
LOGGER.error("Error while fetching", ex);
139+
return Collections.emptyList();
125140
}
126-
return Collections.emptyList();
127141
}
128142
}

src/main/java/org/jabref/gui/groups/GroupTreeView.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Optional;
99
import java.util.function.Consumer;
10+
import java.util.stream.Collectors;
1011

1112
import javax.inject.Inject;
1213

@@ -280,12 +281,7 @@ private void updateSelection(List<TreeItem<GroupNodeViewModel>> newSelectedGroup
280281
if ((newSelectedGroups == null) || newSelectedGroups.isEmpty()) {
281282
viewModel.selectedGroupsProperty().clear();
282283
} else {
283-
List<GroupNodeViewModel> list = new ArrayList<>();
284-
for (TreeItem<GroupNodeViewModel> model : newSelectedGroups) {
285-
if ((model != null) && (model.getValue() != null) && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)) {
286-
list.add(model.getValue());
287-
}
288-
}
284+
List<GroupNodeViewModel> list = newSelectedGroups.stream().filter(model -> model != null && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)).map(TreeItem<GroupNodeViewModel>::getValue).collect(Collectors.toList());
289285
viewModel.selectedGroupsProperty().setAll(list);
290286
}
291287
}
@@ -304,15 +300,7 @@ private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(TreeItem<Group
304300
if (root.getValue().equals(value)) {
305301
return Optional.of(root);
306302
}
307-
308-
for (TreeItem<GroupNodeViewModel> child : root.getChildren()) {
309-
Optional<TreeItem<GroupNodeViewModel>> treeItemByValue = getTreeItemByValue(child, value);
310-
if (treeItemByValue.isPresent()) {
311-
return treeItemByValue;
312-
}
313-
}
314-
315-
return Optional.empty();
303+
return root.getChildren().stream().filter(child -> getTreeItemByValue(child, value).isPresent()).findFirst();
316304
}
317305

318306
private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {

src/main/java/org/jabref/gui/maintable/MainTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private void clearAndSelectLast() {
209209

210210
public void paste() {
211211
// Find entries in clipboard
212-
List<BibEntry> entriesToAdd = Globals.clipboardManager.extractEntries();
212+
List<BibEntry> entriesToAdd = Globals.clipboardManager.extractData();
213213

214214
if (!entriesToAdd.isEmpty()) {
215215
// Add new entries

src/main/java/org/jabref/logic/util/Version.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.io.BufferedReader;
44
import java.io.IOException;
55
import java.io.InputStreamReader;
6+
import java.net.HttpURLConnection;
67
import java.net.URL;
7-
import java.net.URLConnection;
88
import java.util.ArrayList;
99
import java.util.List;
1010
import java.util.Objects;
@@ -91,7 +91,7 @@ public static Version parse(String version) {
9191
* Grabs all the available releases from the GitHub repository
9292
*/
9393
public static List<Version> getAllAvailableVersions() throws IOException {
94-
URLConnection connection = new URL(JABREF_GITHUB_RELEASES).openConnection();
94+
HttpURLConnection connection = (HttpURLConnection) new URL(JABREF_GITHUB_RELEASES).openConnection();
9595
connection.setRequestProperty("Accept-Charset", "UTF-8");
9696
try (BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
9797

@@ -102,6 +102,7 @@ public static List<Version> getAllAvailableVersions() throws IOException {
102102
Version version = Version.parse(jsonObject.getString("tag_name").replaceFirst("v", ""));
103103
versions.add(version);
104104
}
105+
connection.disconnect();
105106
return versions;
106107
}
107108
}

0 commit comments

Comments
 (0)