Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into convertSearchWorker
Browse files Browse the repository at this point in the history
* upstream/master:
  Fix downloading pdf produces html as extension (#4965)
  Too big error message #4827 (#4966)
  Reformat Understanding the basics section of CONTRIBUTING.md (#4978)
  Revised README.md (#4974)
  Switch Jsoup's StringUtil for JabRef's StringUtil (#4970)
  • Loading branch information
Siedlerchr committed May 18, 2019
2 parents cd6d181 + 102ed25 commit e419b2d
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 85 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where special characters where removed from non label key generation pattern parts [#4767](https://github.com/JabRef/jabref/issues/4767)
- We fixed an issue where the RIS import would overwite the article date with the value of the acessed date [#4816](https://github.com/JabRef/jabref/issues/4816)
- We fixed an issue where an NullPointer exception was thrown when a referenced entry in an Open/Libre Office document was no longer present in the library. Now an error message with the reference marker of the missing entry is shown. [#4932](https://github.com/JabRef/jabref/issues/4932)


- We fixed an issue where a database exception related to a missing timezone was too big. [#4827](https://github.com/JabRef/jabref/issues/4827)

### Removed
- The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group.
Expand Down
17 changes: 9 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
After reading through this guide, check out some good first issues to contribute to by clicking here: [Good First Issues](https://github.com/JabRef/jabref/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)

## Understanding the basics
We welcome contributions to JabRef and encourage to create a fork, clone, **create a new branch** (such as `fix-for-issue-121`), **work on the new branch — not master**, and create a pull request.
Be sure to create a **separate branch** for each improvement you implement.
Take a look at GitHub's excellent overview on the [GitHub flow](https://guides.github.com/introduction/flow/index.html) and their [pull request help documentation](https://help.github.com/articles/about-pull-requests/) for a detailed explanation and the explanation of [Feature Branch Workflow](https://de.atlassian.com/git/tutorials/comparing-workflows#feature-branch-workflow) for the idea behind this kind of development.

We also have [code howtos](https://github.com/JabRef/jabref/wiki/Code-Howtos) and [guidelines for setting up a local workspace](https://github.com/JabRef/jabref/wiki/Guidelines-for-setting-up-a-local-workspace).

In case you have any question, do not hesitate to write one of our [JabRef developers](https://github.com/orgs/JabRef/teams/developers) an email.
We should also be online at [gitter](https://gitter.im/JabRef/jabref).
We welcome contributions to JabRef and encourage you to follow the GitHub workflow specified below. If you are not familiar with this type of workflow, take a look at GitHub's excellent overview on the [GitHub flow](https://guides.github.com/introduction/flow/index.html) and the explanation of [Feature Branch Workflow](https://atlassian.com/git/tutorials/comparing-workflows#feature-branch-workflow) for the idea behind this kind of development.
1. Get the JabRef code on your local machine. Detailed instructions about this step can be found in our [guidelines for setting up a local workspace](https://github.com/JabRef/jabref/wiki/Guidelines-for-setting-up-a-local-workspace).
1. Fork the JabRef into your GitHub account.
2. Clone your forked repository on your local machine.
3. **Create a new branch** (such as `fix-for-issue-121`). Be sure to create a **separate branch** for each improvement you implement.
4. Do your work on the **new branch - not the master branch.** Refer to our [code howtos](https://github.com/JabRef/jabref/wiki/Code-Howtos) if you have questions about your implementation.
5. Create a pull request. For an overview of pull requests, take a look at GitHub's [pull request help documentation](https://help.github.com/articles/about-pull-requests/).

In case you have any questions, do not hesitate to write one of our [JabRef developers](https://github.com/orgs/JabRef/teams/developers) an email. We should also be online at [gitter](https://gitter.im/JabRef/jabref).


## Formal requirements for a pull request
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ An explanation of donation possibilities and usage of donations is available at

> Not a programmer? [Learn how to help.](http://contribute.jabref.org)
Want to be part of a free and open-source project that tens of thousands scientist use every day?
Check out our [issue tracker](https://github.com/JabRef/jabref/issues) to find something to work on.
You are also welcome to contribute new features.
To get your code included into JabRef, just fork JabRef and create a pull request.
For details have a look at our [guidelines for contributing](CONTRIBUTING.md).
Want to be part of a free and open-source project that tens of thousands scientist use every day? Check out the ways you can contribute, below:
- For details on how to contribute, have a look at our [guidelines for contributing](CONTRIBUTING.md).
- You are welcome to contribute new features. To get your code included into JabRef, just [fork](https://help.github.com/en/articles/fork-a-repo) the JabRef repository, make your changes, and create a [pull request](https://help.github.com/en/articles/about-pull-requests).
- To work on existing JabRef issues, check out our [issue tracker](https://github.com/JabRef/jabref/issues). New to open source contributing? Look for issues with the ["good first issue"](https://github.com/JabRef/jabref/labels/good%20first%20issue) label to get started.

We view pull requests as a collaborative process.
Submit a pull request early to get feedback from the team on work in progress.
We will discuss improvements with you and agree to merge them once the [developers](https://github.com/JabRef/jabref/blob/master/DEVELOPERS) approve.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ dependencies {
compile 'com.jfoenix:jfoenix:8.0.8'

// Cannot be updated to 9.*.* until Jabref works with Java 9
compile 'org.controlsfx:controlsfx:8.40.15-SNAPSHOT'
compile 'org.controlsfx:controlsfx:8.40.16-SNAPSHOT'

compile 'org.jsoup:jsoup:1.11.3'
compile 'org.jsoup:jsoup:1.12.1'
compile 'com.mashape.unirest:unirest-java:1.4.9'

// >1.8.0-beta is required for java 9 compatibility
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void showErrorDialogAndWait(String title, String content) {
@Override
public void showErrorDialogAndWait(String message, Throwable exception) {
ExceptionDialog exceptionDialog = new ExceptionDialog(exception);
exceptionDialog.getDialogPane().setMaxWidth(mainWindow.getWidth() / 2);
exceptionDialog.setHeaderText(message);
exceptionDialog.showAndWait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel;
import org.jabref.gui.util.BackgroundTask;
Expand Down Expand Up @@ -136,15 +137,15 @@ private void addLinkedFileFromURL(URL url, BibEntry entry, Path targetDirectory)
basePanel.getBibDatabaseContext(),
Globals.TASK_EXECUTOR,
dialogService,
JabRefPreferences.getInstance());
JabRefPreferences.getInstance(), ExternalFileTypes.getInstance());

try {
URLDownload urlDownload = new URLDownload(newLinkedFile.getLink());
BackgroundTask<Path> downloadTask = onlineFile.prepareDownloadTask(targetDirectory, urlDownload);
downloadTask.onSuccess(destination -> {
LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile(
destination,
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()));
basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(JabRefPreferences.getInstance().getFilePreferences()), ExternalFileTypes.getInstance());
entry.addFile(downloadedFile);
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ public class LinkedFileViewModel extends AbstractViewModel {
private final FilePreferences filePreferences;
private final XmpPreferences xmpPreferences;
private final LinkedFileHandler linkedFileHandler;
private final ExternalFileTypes externalFileTypes;

public LinkedFileViewModel(LinkedFile linkedFile,
BibEntry entry,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
DialogService dialogService,
JabRefPreferences preferences) {
JabRefPreferences preferences,
ExternalFileTypes externalFileTypes) {

this.linkedFile = linkedFile;
this.filePreferences = preferences.getFilePreferences();
Expand All @@ -81,6 +83,7 @@ public LinkedFileViewModel(LinkedFile linkedFile,
this.entry = entry;
this.dialogService = dialogService;
this.taskExecutor = taskExecutor;
this.externalFileTypes = externalFileTypes;

xmpPreferences = preferences.getXMPPreferences();
downloadOngoing.bind(downloadProgress.greaterThanOrEqualTo(0).and(downloadProgress.lessThan(1)));
Expand Down Expand Up @@ -402,7 +405,7 @@ public void download() {
URLDownload urlDownload = new URLDownload(linkedFile.getLink());
BackgroundTask<Path> downloadTask = prepareDownloadTask(targetDirectory.get(), urlDownload);
downloadTask.onSuccess(destination -> {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences));
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences), externalFileTypes);
linkedFile.setLink(newLinkedFile.getLink());
linkedFile.setFileType(newLinkedFile.getFileType());
});
Expand All @@ -420,7 +423,7 @@ public BackgroundTask<Path> prepareDownloadTask(Path targetDirectory, URLDownloa
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
linkedFile.setFileType(suggestedTypeName);

String suggestedName = linkedFileHandler.getSuggestedFileName();
String suggestedName = linkedFileHandler.getSuggestedFileName(suggestedTypeName);
return targetDirectory.resolve(suggestedName);
})
.then(destination -> new FileDownloadTask(urlDownload.getSource(), destination))
Expand All @@ -443,15 +446,15 @@ private Optional<ExternalFileType> inferFileTypeFromMimeType(URLDownload urlDown

if (mimeType != null) {
LOGGER.debug("MIME Type suggested: " + mimeType);
return ExternalFileTypes.getInstance().getExternalFileTypeByMimeType(mimeType);
return externalFileTypes.getExternalFileTypeByMimeType(mimeType);
} else {
return Optional.empty();
}
}

private Optional<ExternalFileType> inferFileTypeFromURL(String url) {
return URLUtil.getSuffix(url)
.flatMap(extension -> ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension));
.flatMap(extension -> externalFileTypes.getExternalFileTypeByExt(extension));
}

public LinkedFile getFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ public class LinkedFilesEditorViewModel extends AbstractEditorViewModel {
private final BibDatabaseContext databaseContext;
private final TaskExecutor taskExecutor;
private final JabRefPreferences preferences;
private final ExternalFileTypes externalFileTypes = ExternalFileTypes.getInstance();

public LinkedFilesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider<?> suggestionProvider,
DialogService dialogService,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
FieldCheckers fieldCheckers,
JabRefPreferences preferences) {

super(fieldName, suggestionProvider, fieldCheckers);

this.dialogService = dialogService;
this.databaseContext = databaseContext;
this.taskExecutor = taskExecutor;
this.preferences = preferences;


BindingsHelper.bindContentBidirectional(
files,
text,
Expand All @@ -86,9 +87,9 @@ private static String getStringRepresentation(List<LinkedFileViewModel> files) {
*
* TODO: Move this method to {@link LinkedFile} as soon as {@link CustomExternalFileType} lives in model.
*/
public static LinkedFile fromFile(Path file, List<Path> fileDirectories) {
public static LinkedFile fromFile(Path file, List<Path> fileDirectories, ExternalFileTypes externalFileTypesFile) {
String fileExtension = FileHelper.getFileExtension(file).orElse("");
ExternalFileType suggestedFileType = ExternalFileTypes.getInstance()
ExternalFileType suggestedFileType = externalFileTypesFile
.getExternalFileTypeByExt(fileExtension)
.orElse(new UnknownExternalFileType(fileExtension));
Path relativePath = FileUtil.relativize(file, fileDirectories);
Expand All @@ -98,8 +99,8 @@ public static LinkedFile fromFile(Path file, List<Path> fileDirectories) {
public LinkedFileViewModel fromFile(Path file) {
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences());

LinkedFile linkedFile = fromFile(file, fileDirectories);
return new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
LinkedFile linkedFile = fromFile(file, fileDirectories, externalFileTypes);
return new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileTypes);

}

Expand All @@ -113,7 +114,7 @@ public BooleanProperty fulltextLookupInProgressProperty() {

private List<LinkedFileViewModel> parseToFileViewModel(String stringValue) {
return FileFieldParser.parse(stringValue).stream()
.map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences))
.map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileTypes))
.collect(Collectors.toList());
}

Expand All @@ -135,8 +136,8 @@ public void addNewFile() {

List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences());
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences));
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories, externalFileTypes);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileTypes));
});
}

Expand All @@ -162,7 +163,7 @@ private List<LinkedFileViewModel> findAssociatedNotLinkedFiles(BibEntry entry) {
try {
List<LinkedFile> linkedFiles = util.findAssociatedNotLinkedFiles(entry);
for (LinkedFile linkedFile : linkedFiles) {
LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, externalFileTypes);
newLinkedFile.markAsAutomaticallyFound();
result.add(newLinkedFile);
}
Expand Down Expand Up @@ -205,7 +206,7 @@ public void addFromURL() {
}

private void addFromURL(URL url) {
LinkedFileViewModel onlineFile = new LinkedFileViewModel(new LinkedFile(url, ""), entry, databaseContext, taskExecutor, dialogService, preferences);
LinkedFileViewModel onlineFile = new LinkedFileViewModel(new LinkedFile(url, ""), entry, databaseContext, taskExecutor, dialogService, preferences, externalFileTypes);
files.add(onlineFile);
onlineFile.download();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/filelist/AttachFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.gui.util.FileDialogConfiguration;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void execute() {

dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {

LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()));
LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()), ExternalFileTypes.getInstance());

LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public void openBrowseDialog() {
String fileName = Paths.get(fileText).getFileName().toString();

FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(workingDir)
.withInitialFileName(fileName)
.build();
.withInitialDirectory(workingDir)
.withInitialFileName(fileName)
.build();

dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> {
// Store the directory for next time:
Expand All @@ -92,8 +92,11 @@ public void openBrowseDialog() {
public void setValues(LinkedFile linkedFile) {
description.set(linkedFile.getDescription());

Path linkPath = Paths.get(linkedFile.getLink());
link.set(relativize(linkPath));
if (linkedFile.isOnlineLink()) {
link.setValue(linkedFile.getLink()); //Might be an URL
} else {
link.setValue(relativize(Paths.get(linkedFile.getLink())));
}

selectedExternalFileType.setValue(null);

Expand Down
Loading

0 comments on commit e419b2d

Please sign in to comment.