Skip to content

Commit

Permalink
Merge branch 'main' into fix-deprecated-Java-API
Browse files Browse the repository at this point in the history
  • Loading branch information
leaf-soba authored Sep 10, 2024
2 parents 7314a83 + d02a504 commit 5371859
Show file tree
Hide file tree
Showing 155 changed files with 1,307 additions and 1,562 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@ jobs:
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}

requirements_coverage:
name: "Validate requiremenet coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
show-progress: 'false'
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21.0.2
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- run: ./gradlew traceRequirements

# This is https://github.com/marketplace/actions/gradle-wrapper-validation
# It ensures that the jar file is from gradle and not by a strange third party.
gradlevalidation:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We enabled creating a new file link manually. [#11017](https://github.com/JabRef/jabref/issues/11017)
- We added a toggle button to invert the selected groups. [#9073](https://github.com/JabRef/jabref/issues/9073)
- We reintroduced the floating search in the main table. [#4237](https://github.com/JabRef/jabref/issues/4237)
- We added a switch not to store the linked file URL, because it caused troubles at other apps. [#11735](https://github.com/JabRef/jabref/pull/11735)
- When starting a new SLR, the selected catalogs now persist within and across JabRef sessions. [koppor#614](https://github.com/koppor/jabref/issues/614)
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)

Expand All @@ -42,6 +43,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We enhanced the indexing speed. [#11502](https://github.com/JabRef/jabref/pull/11502)
- ⚠️ Renamed command line parameters `embeddBibfileInPdf` to `embedBibFileInPdf`, `writeMetadatatoPdf` to `writeMetadataToPdf`, and `writeXMPtoPdf` to `writeXmpToPdf`. [#11575](https://github.com/JabRef/jabref/pull/11575)
- The browse button for a Custom theme now opens in the directory of the current used CSS file. [#11597](https://github.com/JabRef/jabref/pull/11597)
- The browse button for a Custom exporter now opens in the directory of the current used exporter file. [#11717](https://github.com/JabRef/jabref/pull/11717)
- We improved the display of long messages in the integrity check dialog. [#11619](https://github.com/JabRef/jabref/pull/11619)

### Fixed
Expand All @@ -64,6 +66,9 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the full-text search results were incomplete. [#8626](https://github.com/JabRef/jabref/issues/8626)
- We fixed an issue where search result highlighting was incorrectly highlighting the boolean operators. [#11595](https://github.com/JabRef/jabref/issues/11595)
- We fixed an issue where search result highlighting was broken at complex searches. [#8067](https://github.com/JabRef/jabref/issues/8067)
- We fixed an exception when searching for unlinked files. [#11731](https://github.com/JabRef/jabref/issues/11731)
- We fixed an issue where two contradicting notifications were shown when cutting an entry in the main table. [#11724](https://github.com/JabRef/jabref/pull/11724)
- We fixed an issue where unescaped braces in the arXiv fetcher were not treated. [#11704](https://github.com/JabRef/jabref/issues/11704)

### Removed

Expand Down
16 changes: 12 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ plugins {
id 'idea'

id 'org.openrewrite.rewrite' version '6.20.0'

id "org.itsallcode.openfasttrace" version "3.0.0"
}

// Enable following for debugging
Expand Down Expand Up @@ -255,10 +257,12 @@ dependencies {

implementation 'org.controlsfx:controlsfx:11.2.1'

// region HTTP clients
implementation 'org.jsoup:jsoup:1.18.1'
implementation 'com.konghq:unirest-java-core:4.4.4'
implementation 'com.konghq:unirest-modules-gson:4.4.4'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1'
// endregion

implementation 'org.slf4j:slf4j-api:2.0.16'
implementation 'org.tinylog:tinylog-api:2.7.0'
Expand Down Expand Up @@ -321,7 +325,7 @@ dependencies {
implementation 'com.github.vatbub:mslinks:1.0.6.2'

// YAML formatting
implementation 'org.yaml:snakeyaml:2.2'
implementation 'org.yaml:snakeyaml:2.3'

// AI
implementation 'dev.langchain4j:langchain4j:0.33.0'
Expand All @@ -330,11 +334,11 @@ dependencies {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}
implementation('dev.langchain4j:langchain4j-mistral-ai:0.33.0')
implementation('dev.langchain4j:langchain4j-hugging-face:0.33.0')
implementation('dev.langchain4j:langchain4j-hugging-face:0.34.0')
implementation 'ai.djl:api:0.29.0'
implementation 'ai.djl.pytorch:pytorch-model-zoo:0.29.0'
implementation 'ai.djl.huggingface:tokenizers:0.29.0'
implementation 'io.github.stefanbratanov:jvm-openai:0.10.0'
implementation 'io.github.stefanbratanov:jvm-openai:0.11.0'
// openai depends on okhttp, which needs kotlin - see https://github.com/square/okhttp/issues/5299 for details
implementation ('com.squareup.okhttp3:okhttp:4.12.0') {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
Expand Down Expand Up @@ -365,7 +369,7 @@ dependencies {
xjc group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '3.0.2'
xjc group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '3.0.2'

rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.17.0"))
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.18.0"))
rewrite("org.openrewrite.recipe:rewrite-static-analysis")
rewrite("org.openrewrite.recipe:rewrite-logging-frameworks")
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks")
Expand Down Expand Up @@ -896,3 +900,7 @@ jmh {
iterations = 10
fork = 2
}

requirementTracing {
inputDirectories = files('docs', 'src/main/java', 'src/test/java')
}
2 changes: 1 addition & 1 deletion buildres/abbrv.jabref.org
2 changes: 2 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@ If you want to indicate that a pull request is not yet complete **before** creat

For improving developer's documentation, go on at the [docs/ subdirectory of JabRef's code](https://github.com/JabRef/jabref/tree/main/docs) and edit the file.
GitHub offers a good guide at [Editing files in another user's repository](https://help.github.com/en/github/managing-files-in-a-repository/editing-files-in-another-users-repository).

One can also add [callouts](https://just-the-docs.github.io/just-the-docs-tests/components/callouts/).
16 changes: 16 additions & 0 deletions docs/requirements/ai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
parent: Requirements
---
# AI

## User Interface

### Chatting with AI
`req~ai.chat.new-message-based-on-previous~1`

To enable simple editing and resending of previous messages, <kbd>Cursor Up</kbd> should show last message.
This should only happen if the current text field is empty.

Needs: impl

<!-- markdownlint-disable-file MD022 -->
49 changes: 49 additions & 0 deletions docs/requirements/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
nav_order: 7
has_children: true
---
# Requirements

This part of the documentation collects requirements using [OpenFastTrace](https://github.com/itsallcode/openfasttrace).

## Specifying requirements

One writes directly below a Markdown heading a requirement identifier.

Example:

```markdown
### Example
`req~ai.example~1`
```

It is important that there is no empty line directly after the heading.

{: note}
One needs to add `<!-- markdownlint-disable-file MD022 -->` to the end of the file, because the id of the requirement needs to follow the heading directly.

## Linking implementations

Then, one writes down at the requirement.
Directly at the end, one writes that it requires an implementation:

```markdown
Needs: impl
```

One can also state that there should be detailed design document (`dsn`).
However, typically in JabRef, we go from the requirement directly to the implementation.

Then, at the implementation, a comment is added this implementation is covered:

```java
// [impl->req~ai.example~1]
```

When executing the gradle task `traceRequirements`, `build/tracing.txt` is generated.
In case of a tracing error, one can inspect this file to see which requirements were not covered.

## More Information

- [User manual of OpenFastTrace](https://github.com/itsallcode/openfasttrace/blob/main/doc/user_guide.md)
- We cannot copy and paste real examples here, because of [openfasttrace#280](https://github.com/itsallcode/openfasttrace/issues/280).
3 changes: 3 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,6 @@ recipeList:
- org.openrewrite.java.testing.junit5.RemoveTryCatchFailBlocks
- org.openrewrite.java.testing.junit5.LifecycleNonPrivate
- org.openrewrite.java.testing.junit5.StaticImports

# Logging
- org.openrewrite.java.logging.slf4j.Slf4jBestPractices
8 changes: 4 additions & 4 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@
// dependency injection using HK2
requires org.glassfish.hk2.api;

// region: http clients
requires unirest.java.core;
requires unirest.modules.gson;
// region HTTP clients
requires org.apache.httpcomponents.core5.httpcore5;
requires org.jsoup;
requires unirest.java.core;
requires unirest.modules.gson;
// endregion

// region: SQL databases
Expand Down Expand Up @@ -155,7 +155,7 @@

// region: Lucene
/**
* In case the version is updated, please also adapt {@link org.jabref.model.search.SearchFieldConstants#VERSION} to the newly used version.
* In case the version is updated, please also increment {@link org.jabref.model.search.SearchFieldConstants#VERSION} to trigger reindexing.
*/
uses org.apache.lucene.codecs.lucene99.Lucene99Codec;
requires org.apache.lucene.analysis.common;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.ai.AiApiKeyProvider;

import com.airhacks.afterburner.injection.Injector;
import org.apache.commons.cli.ParseException;
Expand Down Expand Up @@ -64,7 +63,6 @@ public static void main(String[] args) {
// Initialize preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();
Injector.setModelOrService(PreferencesService.class, preferences);
Injector.setModelOrService(AiApiKeyProvider.class, preferences);

// Early exit in case another instance is already running
if (!handleMultipleAppInstances(args, preferences.getRemotePreferences())) {
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.prefs.BackingStoreException;

import org.jabref.gui.externalfiles.AutoSetFileLinksUtil;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.util.CurrentThreadTaskExecutor;
import org.jabref.logic.JabRefException;
import org.jabref.logic.UiCommand;
Expand Down Expand Up @@ -99,16 +98,13 @@ public ArgumentProcessor(String[] args,
}

/**
* Will open a file (like importFile), but will also request JabRef to focus on this database
* Will open a file (like {@link #importFile(String)}, but will also request JabRef to focus on this database.
*
* @param argument See importFile.
* @return ParserResult with setToOpenTab(true)
*/
private Optional<ParserResult> importToOpenBase(String argument) {
Optional<ParserResult> result = importFile(argument);

private Optional<ParserResult> importToOpenBase(String importArguments) {
Optional<ParserResult> result = importFile(importArguments);
result.ifPresent(ParserResult::setToOpenTab);

return result;
}

Expand All @@ -125,9 +121,13 @@ private Optional<ParserResult> importBibtexToOpenBase(String argument, ImportFor
}
}

private Optional<ParserResult> importFile(String argument) {
LOGGER.debug("Importing file {}", argument);
String[] data = argument.split(",");
/**
*
* @param importArguments Format: <code>fileName[,format]</code>
*/
private Optional<ParserResult> importFile(String importArguments) {
LOGGER.debug("Importing file {}", importArguments);
String[] data = importArguments.split(",");

String address = data[0];
Path file;
Expand Down Expand Up @@ -295,7 +295,7 @@ public void processArguments() {
}

private void writeMetadataToPdf(List<ParserResult> loaded,
String filesAndCitekeys,
String filesAndCiteKeys,
XmpPreferences xmpPreferences,
FilePreferences filePreferences,
BibDatabaseMode databaseMode,
Expand All @@ -314,7 +314,7 @@ private void writeMetadataToPdf(List<ParserResult> loaded,
XmpPdfExporter xmpPdfExporter = new XmpPdfExporter(xmpPreferences);
EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter = new EmbeddedBibFilePdfExporter(databaseMode, entryTypesManager, fieldPreferences);

if ("all".equals(filesAndCitekeys)) {
if ("all".equals(filesAndCiteKeys)) {
for (BibEntry entry : databaseContext.getEntries()) {
writeMetadataToPDFsOfEntry(
databaseContext,
Expand All @@ -332,7 +332,7 @@ private void writeMetadataToPdf(List<ParserResult> loaded,

List<String> citeKeys = new ArrayList<>();
List<String> pdfs = new ArrayList<>();
for (String fileOrCiteKey : filesAndCitekeys.split(",")) {
for (String fileOrCiteKey : filesAndCiteKeys.split(",")) {
if (fileOrCiteKey.toLowerCase(Locale.ROOT).endsWith(".pdf")) {
pdfs.add(fileOrCiteKey);
} else {
Expand Down Expand Up @@ -368,7 +368,7 @@ private void writeMetadataToPDFsOfEntry(BibDatabaseContext databaseContext,
EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter,
JournalAbbreviationRepository abbreviationRepository,
boolean writeXMP,
boolean embeddBibfile) {
boolean embedBibfile) {
try {
if (writeXMP) {
if (xmpPdfExporter.exportToAllFilesOfEntry(databaseContext, filePreferences, entry, List.of(entry), abbreviationRepository)) {
Expand All @@ -377,7 +377,7 @@ private void writeMetadataToPDFsOfEntry(BibDatabaseContext databaseContext,
System.err.printf("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey);
}
}
if (embeddBibfile) {
if (embedBibfile) {
if (embeddedBibFilePdfExporter.exportToAllFilesOfEntry(databaseContext, filePreferences, entry, List.of(entry), abbreviationRepository)) {
System.out.printf("Successfully embedded metadata on at least one linked file of %s%n", citeKey);
} else {
Expand Down Expand Up @@ -461,6 +461,7 @@ private boolean exportMatches(List<ParserResult> loaded) {

List<BibEntry> matches;
try {
// extract current thread task executor from luceneManager
matches = new DatabaseSearcher(query, databaseContext, new CurrentThreadTaskExecutor(), preferencesService.getFilePreferences()).getMatches();
} catch (IOException e) {
LOGGER.error("Error occurred when searching", e);
Expand Down Expand Up @@ -729,12 +730,17 @@ private void resetPreferences(String value) {
private void automaticallySetFileLinks(List<ParserResult> loaded) {
for (ParserResult parserResult : loaded) {
BibDatabase database = parserResult.getDatabase();
LOGGER.info(Localization.lang("Automatically setting file links"));
LOGGER.info("Automatically setting file links for {}",
parserResult.getDatabaseContext().getDatabasePath()
.map(Path::getFileName)
.map(Path::toString).orElse("UNKNOWN"));

AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(
parserResult.getDatabaseContext(),
preferencesService.getFilePreferences(),
preferencesService.getAutoLinkPreferences());
util.linkAssociatedFiles(database.getEntries(), new NamedCompound(""));

util.linkAssociatedFiles(database.getEntries(), (linkedFile, bibEntry) -> bibEntry.addFile(linkedFile));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static String getContentsPrimary() {
try {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.warn(e.getMessage());
LOGGER.warn("", e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/FallbackExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void installExceptionHandler() {

@Override
public void uncaughtException(Thread thread, Throwable exception) {
LOGGER.error("Uncaught exception occurred in " + thread, exception);
LOGGER.error("Uncaught exception occurred in {}", thread, exception);
UiTaskExecutor.runInJavaFXThread(() -> {
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
dialogService.showErrorDialogAndWait("Uncaught exception occurred in " + thread, exception);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.GuiPreferences;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.ai.AiApiKeyProvider;

import com.airhacks.afterburner.injection.Injector;
import com.tobiasdiez.easybind.EasyBind;
Expand Down Expand Up @@ -161,7 +160,6 @@ public void initialize() {
preferencesService.getAiPreferences(),
preferencesService.getFilePreferences(),
preferencesService.getCitationKeyPatternPreferences(),
Injector.instantiateModelOrService(AiApiKeyProvider.class),
dialogService,
taskExecutor);
Injector.setModelOrService(AiService.class, aiService);
Expand Down
Loading

0 comments on commit 5371859

Please sign in to comment.