Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into decode-DOI-contains…
Browse files Browse the repository at this point in the history
…-masked-characters#8787

* upstream/main:
  Add: Add test cases for non-default styles in CitationStyleTest (JabRef#8828)
  Open event log when clicking on collapsed notification (JabRef#8837)
  Fix right clicking a group and choosing "remove selected entries from this group" leads to error when Bibtex source tab is selected (JabRef#8821)
  Fix single identifier cannot be opened on click (JabRef#8838)
  Add Pubmed/Medline Query Transformer (JabRef#8818)
  adjust and add testcases for FileAnnotationViewModel (JabRef#8830)
  Append config instead of replacing (JabRef#8834)
  Fix eclipse config (JabRef#8835)
  Add Nemo file manager (JabRef#8831)
  Fix missing clear action on pressing esc within the "Filter groups" field (JabRef#8829)
  Update bouncycalse to new base version (JabRef#8827)
  add: add test cases for FileUtil (JabRef#8810)
  Restrict use of standard streams (JabRef#8816)
  • Loading branch information
Siedlerchr committed May 22, 2022
2 parents 5160bcf + 264357c commit 51b77ba
Show file tree
Hide file tree
Showing 26 changed files with 360 additions and 65 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- Writing BibTeX data into a PDF (XMP) removes braces. [#8452](https://github.com/JabRef/jabref/issues/8452)
- Writing BibTeX data into a PDF (XMP) does not write the `file` field.
- Writing BibTeX data into a PDF (XMP) considers the configured keyword separator (and does not use "," as default any more)
- The Medline/Pubmed search now also supports the [default fields and operators for searching](https://docs.jabref.org/collect/import-using-online-bibliographic-database#search-syntax). [forum#3554](https://discourse.jabref.org/t/native-pubmed-search/3354)

### Fixed

Expand All @@ -30,6 +31,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where deprecated fields tab is shown when the fields don't contain any values. [#8396](https://github.com/JabRef/jabref/issues/8396)
- We fixed an issue that there are exceptions for DOI search in case DOI contains masked characters. [#8787](https://github.com/JabRef/jabref/issues/8787)
- We fixed an issue which allow us to select and open identifiers from a popup list in the maintable [#8758](https://github.com/JabRef/jabref/issues/8758), [8802](https://github.com/JabRef/jabref/issues/8802)
- We fixed an issue where the escape button had no functionality within the "Filter groups" textfield. [koppor#562](https://github.com/koppor/jabref/issues/562)
- We fixed an issue where right clicking a group and choose "remove selected entries from this group" leads to error when Bibtex source tab is selected. [#8012](https://github.com/JabRef/jabref/issues/8012)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ dependencies {
implementation 'com.ibm.icu:icu4j-charset:71.1'

// required for reading write-protected PDFs - see https://github.com/JabRef/jabref/pull/942#issuecomment-209252635
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
implementation 'org.bouncycastle:bcprov-jdk18on:1.71'

implementation 'commons-cli:commons-cli:1.5.0'

Expand Down
8 changes: 7 additions & 1 deletion eclipse.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ eclipse {
}

def javafxcontrols = entries.find { isJavafxControls(it) };
javafxcontrols.entryAttributes['add-exports'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=org.jabref:javafx.controls/javafx.scene.control=org.jabref';
javafxcontrols.entryAttributes['add-exports'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=org.jabref:javafx.controls/javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix';
javafxcontrols.entryAttributes['add-opens'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=org.jabref:javafx.controls/javafx.scene.control=org.jabref:javafx.controls/javafx.scene.control.skin=org.controlsfx.controls';

def javafxgraphics = entries.find { isJavafxGraphics(it) };
javafxgraphics.entryAttributes['add-opens'] = 'javafx.graphics/javafx.scene=org.controlsfx.controls';
javafxgraphics.entryAttributes['add-exports'] = 'javafx.graphics/com.sun.javafx.stage=com.jfoenix';

def javafxbase = entries.find { isJavafxBase(it) };
javafxbase.entryAttributes['add-exports'] = 'javafx.base/com.sun.javafx.event=org.controlsfx.controls:';

def javafxfxml = entries.find { isJavafxFXML(it) };
javafxfxml.entryAttributes['add-opens'] = 'javafx.fxml/javafx.fxml=org.jabref';
Expand Down Expand Up @@ -61,6 +65,8 @@ boolean isJavafxControls(entry) { return entry.properties.path.contains('javafx-

boolean isJavafxGraphics(entry) { return entry.properties.path.contains('javafx-graphics'); }

boolean isJavafxBase(entry) { return entry.properties.path.contains('javafx-base'); }

boolean isJavafxFXML(entry) { return entry.properties.path.contains('javafx-fxml'); }

// add formatter and cleanup settings to Eclipse settings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.jabref.architecture;

/**
* Annotation to indicate that this class can use System.Out.* instead of using the logging framework
*/
public @interface AllowedToUseStandardStreams {

// The rationale
String value();
}
8 changes: 7 additions & 1 deletion src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javafx.stage.Window;
import javafx.util.Duration;

import org.jabref.gui.help.ErrorConsoleAction;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BackgroundTask;
Expand Down Expand Up @@ -343,9 +344,14 @@ public void notify(String message) {
.threshold(5,
Notifications.create()
.title(Localization.lang("Last notification"))
// TODO: Change to a notification overview instead of event log when that is available. The event log is not that user friendly (different purpose).
.text(
"(" + Localization.lang("Check the event log to see all notifications") + ")"
+ "\n\n" + message))
+ "\n\n" + message)
.onAction((e)-> {
ErrorConsoleAction ec = new ErrorConsoleAction();
ec.execute();
}))
.hideCloseButton()
.show();
});
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private static void addLogToDisk() {
"writerFile.level", "info",
"writerFile.file", directory.resolve("log.txt").toString(),
"writerFile.charset", "UTF-8");
Configuration.replace(configuration);

configuration.entrySet().forEach(config -> Configuration.set(config.getKey(), config.getValue()));
initializeLogger();
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ private void nativeOpenFile(String filePath) {
try {
File file = new File(filePath);
Desktop.getDesktop().open(file);
System.out.println("Open file in default application with Desktop integration");
LOGGER.debug("Open file in default application with Desktop integration");
} catch (IllegalArgumentException e) {
System.out.println("Fail back to xdg-open");
LOGGER.debug("Fail back to xdg-open");
try {
String[] cmd = {"xdg-open", filePath};
Runtime.getRuntime().exec(cmd);
} catch (Exception e2) {
System.out.println("Open operation not successful: " + e2);
LOGGER.warn("Open operation not successful: " + e2);
}
} catch (IOException e) {
System.out.println("Native open operation not successful: " + e);
LOGGER.warn("Native open operation not successful: " + e);
}
});
}
Expand Down Expand Up @@ -94,9 +94,13 @@ public void openFolderAndSelectFile(Path filePath) throws IOException {
if (desktopSession != null) {
desktopSession = desktopSession.toLowerCase(Locale.ROOT);
if (desktopSession.contains("gnome")) {
cmd = "nautilus" + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde")) {
cmd = "nautilus --select " + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde") || desktopSession.contains("plasma")) {
cmd = "dolphin --select " + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("mate")) {
cmd = "caja --select " + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("cinnamon")) {
cmd = "nemo --select " + filePath.toString().replace(" ", "\\ ");
}
}
Runtime.getRuntime().exec(cmd);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ private void storeSource(BibEntry outOfFocusEntry, String text) {
new FieldWriter(fieldWriterPreferences).write(fieldName, newValue);

compound.addEdit(new UndoableFieldChange(outOfFocusEntry, fieldName, oldValue, newValue));
outOfFocusEntry.setField(fieldName, newValue);
if (outOfFocusEntry.getField(fieldName).isPresent()) {
outOfFocusEntry.setField(fieldName, newValue);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javafx.beans.property.StringProperty;

import org.jabref.logic.formatter.bibtexfields.RemoveHyphenatedNewlinesFormatter;
import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.pdf.FileAnnotation;
import org.jabref.model.pdf.FileAnnotationType;
Expand Down Expand Up @@ -33,22 +32,23 @@ private void setupContentProperties(FileAnnotation annotation) {
String annotationContent = annotation.getContent();
String illegibleTextMessage = Localization.lang("The marked area does not contain any legible text!");
String markingContent = (annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
// remove newlines && hyphens before linebreaks
markingContent = markingContent.replaceAll("-" + NEWLINE, "");
new RemoveHyphenatedNewlinesFormatter().format(markingContent);
// remove new lines not preceded by '.' or ':'
markingContent = markingContent.replaceAll("(?<![.|:])" + NEWLINE, " ");
this.marking.set(markingContent);
this.marking.set(removePunctuationMark(markingContent));
} else {
String content = annotation.getContent();
// remove newlines && hyphens before linebreaks
content = new RemoveHyphenatedNewlinesFormatter().format(content);
content = new RemoveNewlinesFormatter().format(content);
this.content.set(content);
this.content.set(removePunctuationMark(content));
this.marking.set("");
}
}

public String removePunctuationMark(String content) {
// remove newlines && hyphens before linebreaks
content = content.replaceAll("-" + NEWLINE, "");
content = new RemoveHyphenatedNewlinesFormatter().format(content);
// remove new lines not preceded by '.' or ':'
content = content.replaceAll("(?<![.|:])" + NEWLINE, " ");
return content;
}

public String getAuthor() {
return author.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public static void call(Scene scene, KeyEvent event) {
focusedTextField.positionCaret(res.caretPosition);
event.consume();
}
case CLOSE -> {
focusedTextField.clear();
event.consume();
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public LinkedIdentifierColumn(MainTableColumnModel model,
.withTooltip(this::createIdentifierTooltip)
.withMenu(this::createIdentifierMenu)
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
if ((event.getButton() == MouseButton.SECONDARY)) {
new OpenUrlAction(dialogService, stateManager, preferences).execute();
// If we only have one identifer, open directly
if ((linkedFiles.size() == 1) && (event.getButton() == MouseButton.PRIMARY)) {
new OpenUrlAction(dialogService, stateManager, preferences).execute();
}
})
.install(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer;
import org.jabref.logic.importer.fetcher.transformers.MedlineQueryTransformer;
import org.jabref.logic.importer.fileformat.MedlineImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
Expand All @@ -54,16 +54,6 @@ public class MedlineFetcher implements IdBasedParserFetcher, SearchBasedFetcher

private int numberOfResultsFound;

/**
* Replaces all commas in a given string with " AND "
*
* @param query input to remove commas
* @return input without commas
*/
private static String replaceCommaWithAND(String query) {
return query.replaceAll(", ", " AND ").replaceAll(",", " AND ");
}

/**
* When using 'esearch.fcgi?db=&lt;database>&term=&lt;query>' we will get a list of IDs matching the query.
* Input: Any text query (&term)
Expand Down Expand Up @@ -164,7 +154,7 @@ private URL createSearchUrl(String query) throws URISyntaxException, MalformedUR
uriBuilder.addParameter("db", "pubmed");
uriBuilder.addParameter("sort", "relevance");
uriBuilder.addParameter("retmax", String.valueOf(NUMBER_TO_FETCH));
uriBuilder.addParameter("term", replaceCommaWithAND(query));
uriBuilder.addParameter("term", query); // already lucene query
return uriBuilder.build().toURL();
}

Expand Down Expand Up @@ -200,7 +190,7 @@ private List<BibEntry> fetchMedline(List<String> ids) throws FetcherException {
@Override
public List<BibEntry> performSearch(QueryNode luceneQuery) throws FetcherException {
List<BibEntry> entryList;
DefaultQueryTransformer transformer = new DefaultQueryTransformer();
MedlineQueryTransformer transformer = new MedlineQueryTransformer();
Optional<String> transformedQuery = transformer.transformLuceneQuery(luceneQuery);

if (transformedQuery.isEmpty() || transformedQuery.get().isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jabref.logic.importer.fetcher.transformers;

/**
*
* Medline/Pubmed specific transformer which uses suffixes for searches
* see <a href="https://pubmed.ncbi.nlm.nih.gov/help/#search-tags">Pubmed help</a> for details
*
*/
public class MedlineQueryTransformer extends AbstractQueryTransformer {

@Override
protected String getLogicalAndOperator() {
return " AND ";
}

@Override
protected String getLogicalOrOperator() {
return " OR ";
}

@Override
protected String getLogicalNotOperator() {
return "NOT ";
}

@Override
protected String handleAuthor(String author) {
return author + "[au]";
}

@Override
protected String handleTitle(String title) {
return title + "[ti]";
}

@Override
protected String handleJournal(String journalTitle) {
return journalTitle + "[ta]";
}

@Override
protected String handleYear(String year) {
return year + "[dp]";
}

@Override
protected String handleYearRange(String yearRange) {
parseYearRange(yearRange);
if (endYear == Integer.MAX_VALUE) {
return yearRange;
}
return Integer.toString(startYear) + ":" + Integer.toString(endYear) + "[dp]";
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/logic/util/io/XMLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.jabref.architecture.AllowedToUseStandardStreams;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
Expand All @@ -25,6 +27,7 @@
/**
* Currently used for debugging only
*/
@AllowedToUseStandardStreams("Used for debugging only")
public class XMLUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(XMLUtil.class);

Expand Down
14 changes: 13 additions & 1 deletion src/test/java/org/jabref/architecture/MainArchitectureTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.library.GeneralCodingRules;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.library.Architectures.layeredArchitecture;
Expand All @@ -20,6 +21,7 @@ class MainArchitectureTests {
private static final String PACKAGE_ORG_JABREF_GUI = "org.jabref.gui..";
private static final String PACKAGE_ORG_JABREF_LOGIC = "org.jabref.logic..";
private static final String PACKAGE_ORG_JABREF_MODEL = "org.jabref.model..";
private static final String PACKAGE_ORG_JABREF_CLI = "org.jabref.cli..";

@ArchTest
public static void doNotUseApacheCommonsLang3(JavaClasses classes) {
Expand Down Expand Up @@ -92,7 +94,7 @@ public static void respectLayeredArchitecture(JavaClasses classes) {
.layer("Gui").definedBy(PACKAGE_ORG_JABREF_GUI)
.layer("Logic").definedBy(PACKAGE_ORG_JABREF_LOGIC)
.layer("Model").definedBy(PACKAGE_ORG_JABREF_MODEL)
.layer("Cli").definedBy("org.jabref.cli..")
.layer("Cli").definedBy(PACKAGE_ORG_JABREF_CLI)
.layer("Migrations").definedBy("org.jabref.migrations..") // TODO: Move to logic
.layer("Preferences").definedBy("org.jabref.preferences..")
.layer("Styletester").definedBy("org.jabref.styletester..")
Expand Down Expand Up @@ -135,4 +137,14 @@ public static void restrictUsagesInLogic(JavaClasses classes) {
.orShould().dependOnClassesThat().haveFullyQualifiedName(CLASS_ORG_JABREF_GLOBALS)
.check(classes);
}

@ArchTest
public static void restrictStandardStreams(JavaClasses classes) {
noClasses().that().resideOutsideOfPackages(PACKAGE_ORG_JABREF_CLI)
.and().resideOutsideOfPackages("org.jabref.gui.openoffice..") // Uses LibreOffice SDK
.and().areNotAnnotatedWith(AllowedToUseStandardStreams.class)
.should(GeneralCodingRules.ACCESS_STANDARD_STREAMS)
.because("logging framework should be used instead or the class be marked explicitly as @AllowedToUseStandardStreams")
.check(classes);
}
}
Loading

0 comments on commit 51b77ba

Please sign in to comment.