Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into copyLinkedFilesIn…
Browse files Browse the repository at this point in the history
…Contextmenu

* 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
  ...
  • Loading branch information
Siedlerchr committed Jul 6, 2019
2 parents 48087ed + a50cb34 commit 0c027b0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: koppor
patreon: # Patreon user account
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: koppor
liberapay: JabRef
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: https://github.com/JabRef/jabref/wiki/Donations # Replace with a single custom sponsorship URL
34 changes: 17 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ buildscript {

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

compile 'org.apache.pdfbox:pdfbox:2.0.15'
compile 'org.apache.pdfbox:fontbox:2.0.15'
compile 'org.apache.pdfbox:xmpbox:2.0.15'
compile 'org.apache.pdfbox:pdfbox:2.0.16'
compile 'org.apache.pdfbox:fontbox:2.0.16'
compile 'org.apache.pdfbox:xmpbox:2.0.16'

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

Expand Down Expand Up @@ -143,10 +143,10 @@ dependencies {

// >1.8.0-beta is required for java 9 compatibility
compile 'org.slf4j:slf4j-api:2.0.0-alpha0'
compile 'org.apache.logging.log4j:log4j-slf4j18-impl:2.11.2'
compile 'org.apache.logging.log4j:log4j-jcl:2.11.2'
compile 'org.apache.logging.log4j:log4j-api:2.11.2'
compile 'org.apache.logging.log4j:log4j-core:2.11.2'
compile 'org.apache.logging.log4j:log4j-slf4j18-impl:2.12.0'
compile 'org.apache.logging.log4j:log4j-jcl:2.12.0'
compile 'org.apache.logging.log4j:log4j-api:2.12.0'
compile 'org.apache.logging.log4j:log4j-core:2.12.0'

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

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

testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.4.2'
testCompile 'org.junit.platform:junit-platform-launcher:1.4.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.0'
testCompile 'org.junit.platform:junit-platform-launcher:1.5.0'

testRuntime 'org.apache.logging.log4j:log4j-core:2.11.1'
testRuntime 'org.apache.logging.log4j:log4j-jul:2.11.2'
testRuntime 'org.apache.logging.log4j:log4j-core:2.12.0'
testRuntime 'org.apache.logging.log4j:log4j-jul:2.12.0'
testCompile 'org.mockito:mockito-core:2.28.2'
testCompile 'com.github.tomakehurst:wiremock:2.23.2'
testCompile 'org.reflections:reflections:0.9.11'
testCompile 'org.xmlunit:xmlunit-core:2.6.2'
testCompile 'org.xmlunit:xmlunit-matchers:2.6.2'
testCompile 'org.xmlunit:xmlunit-core:2.6.3'
testCompile 'org.xmlunit:xmlunit-matchers:2.6.3'
testRuntime 'com.tngtech.archunit:archunit-junit5-engine:0.10.2'
testCompile 'com.tngtech.archunit:archunit-junit5-api:0.10.2'
testCompile "org.testfx:testfx-core:4.0.+"
testCompile "org.testfx:testfx-junit5:4.0.+"

checkstyle 'com.puppycrawl.tools:checkstyle:8.21'
checkstyle 'com.puppycrawl.tools:checkstyle:8.22'
xjc 'com.sun.xml.bind:jaxb-xjc:2.2.4-1'
jython 'org.python:jython-standalone:2.7.1'
}
Expand Down
86 changes: 50 additions & 36 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.gui;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -28,13 +30,11 @@
import org.slf4j.LoggerFactory;

public class ClipBoardManager {

public static final DataFormat XML = new DataFormat("application/xml");

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

private final Clipboard clipboard;

private final ImportFormatReader importFormatReader;

public ClipBoardManager() {
Expand Down Expand Up @@ -63,9 +63,8 @@ public String getContents() {
String result = clipboard.getString();
if (result == null) {
return "";
} else {
return result;
}
return result;
}

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

public List<BibEntry> extractEntries() {
public List<BibEntry> extractData() {
Object entries = clipboard.getContent(DragAndDropDataFormats.ENTRIES);

if (entries == null) {
return handleStringData(clipboard.getString());
}
return handleBibTeXData((String) entries);
}

private List<BibEntry> handleBibTeXData(String entries) {
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
if (entries != null) {
// We have determined that the clipboard data is a set of entries (serialized as a string).
try {
return parser.parseEntries((String) entries);
} catch (ParseException ex) {
LOGGER.error("Could not paste", ex);
}
} else {
String data = clipboard.getString();
if (data != null) {
try {
// fetch from doi
Optional<DOI> doi = DOI.parse(data);
if (doi.isPresent()) {
LOGGER.info("Found DOI in clipboard");
Optional<BibEntry> entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(doi.get().getDOI());
return OptionalUtil.toList(entry);
} else {
try {
UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data);
return unknownFormatImport.parserResult.getDatabase().getEntries();
} catch (ImportException e) {
// import failed and result will be empty
}
}
} catch (FetcherException ex) {
LOGGER.error("Error while fetching", ex);
}
}
try {
return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8)));
} catch (ParseException ex) {
LOGGER.error("Could not paste", ex);
return Collections.emptyList();
}
}

private List<BibEntry> handleStringData(String data) {
if (data == null || data.isEmpty()) {
return Collections.emptyList();
}

Optional<DOI> doi = DOI.parse(data);
if (doi.isPresent()) {
return fetchByDOI(doi.get());
}

return tryImportFormats(data);
}

private List<BibEntry> tryImportFormats(String data) {
try {
UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data);
return unknownFormatImport.parserResult.getDatabase().getEntries();
} catch (ImportException ignored) {
return Collections.emptyList();
}
}

private List<BibEntry> fetchByDOI(DOI doi) {
LOGGER.info("Found DOI in clipboard");
try {
Optional<BibEntry> entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(doi.getDOI());
return OptionalUtil.toList(entry);
} catch (FetcherException ex) {
LOGGER.error("Error while fetching", ex);
return Collections.emptyList();
}
return Collections.emptyList();
}
}
18 changes: 3 additions & 15 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javax.inject.Inject;

Expand Down Expand Up @@ -280,12 +281,7 @@ private void updateSelection(List<TreeItem<GroupNodeViewModel>> newSelectedGroup
if ((newSelectedGroups == null) || newSelectedGroups.isEmpty()) {
viewModel.selectedGroupsProperty().clear();
} else {
List<GroupNodeViewModel> list = new ArrayList<>();
for (TreeItem<GroupNodeViewModel> model : newSelectedGroups) {
if ((model != null) && (model.getValue() != null) && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)) {
list.add(model.getValue());
}
}
List<GroupNodeViewModel> list = newSelectedGroups.stream().filter(model -> model != null && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)).map(TreeItem<GroupNodeViewModel>::getValue).collect(Collectors.toList());
viewModel.selectedGroupsProperty().setAll(list);
}
}
Expand All @@ -304,15 +300,7 @@ private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(TreeItem<Group
if (root.getValue().equals(value)) {
return Optional.of(root);
}

for (TreeItem<GroupNodeViewModel> child : root.getChildren()) {
Optional<TreeItem<GroupNodeViewModel>> treeItemByValue = getTreeItemByValue(child, value);
if (treeItemByValue.isPresent()) {
return treeItemByValue;
}
}

return Optional.empty();
return root.getChildren().stream().filter(child -> getTreeItemByValue(child, value).isPresent()).findFirst();
}

private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void clearAndSelectLast() {

public void paste() {
// Find entries in clipboard
List<BibEntry> entriesToAdd = Globals.clipboardManager.extractEntries();
List<BibEntry> entriesToAdd = Globals.clipboardManager.extractData();

if (!entriesToAdd.isEmpty()) {
// Add new entries
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/logic/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Version parse(String version) {
* Grabs all the available releases from the GitHub repository
*/
public static List<Version> getAllAvailableVersions() throws IOException {
URLConnection connection = new URL(JABREF_GITHUB_RELEASES).openConnection();
HttpURLConnection connection = (HttpURLConnection) new URL(JABREF_GITHUB_RELEASES).openConnection();
connection.setRequestProperty("Accept-Charset", "UTF-8");
try (BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {

Expand All @@ -102,6 +102,7 @@ public static List<Version> getAllAvailableVersions() throws IOException {
Version version = Version.parse(jsonObject.getString("tag_name").replaceFirst("v", ""));
versions.add(version);
}
connection.disconnect();
return versions;
}
}
Expand Down

0 comments on commit 0c027b0

Please sign in to comment.