Skip to content

Commit

Permalink
Merge branch 'main' into fix-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr authored Sep 8, 2024
2 parents 0c1890c + 28164eb commit 93cba84
Show file tree
Hide file tree
Showing 73 changed files with 604 additions and 425 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- 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 unescaped braces in the arXiv fetcher were not treated [#11704](https://github.com/JabRef/jabref/issues/11704)
- 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
8 changes: 8 additions & 0 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 @@ -896,3 +900,7 @@ jmh {
iterations = 10
fork = 2
}

requirementTracing {
inputDirectories = files('docs', 'src/main/java', 'src/test/java')
}
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).
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: 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 93cba84

Please sign in to comment.