diff --git a/.github/dependabot.yml b/.github/dependabot.yml index dbeb22bd3fe..bcb116b5cb6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,8 +9,6 @@ updates: schedule: interval: weekly day: sunday - labels: - - "dependencies" ignore: - dependency-name: com.microsoft.azure:applicationinsights-core versions: @@ -23,10 +21,14 @@ updates: schedule: interval: weekly day: sunday - labels: - - "dependencies" - package-ecosystem: "gitsubmodule" directory: "/" schedule: interval: weekly day: sunday + - package-ecosystem: "maven" + directories: + - "jablib-examples/maven3/doi-to-bibtex" + schedule: + interval: weekly + day: sunday diff --git a/.github/workflows/tests-code.yml b/.github/workflows/tests-code.yml index 5cdaa367392..4692c966227 100644 --- a/.github/workflows/tests-code.yml +++ b/.github/workflows/tests-code.yml @@ -434,7 +434,7 @@ jobs: KOPPOR_MAVENCENTRALUSERNAME: ${{ secrets.KOPPOR_MAVENCENTRALUSERNAME }} KOPPOR_MAVENCENTRALPASSWORD: ${{ secrets.KOPPOR_MAVENCENTRALPASSWORD }} - jbang: + jbang-main: name: JBang (main) runs-on: ubuntu-latest needs: publish @@ -452,7 +452,7 @@ jobs: files: | .jbang/*.java jablib/src/main/java/**/*.java - jablib-examples/**/*.java + jablib-examples/jbang/**/*.java files_ignore: | jablib/src/main/java/**/*-*.java - name: Set up JDK @@ -488,7 +488,7 @@ jobs: done if: steps.changed-jablib-files.outputs.any_changed != 'true' - run: | - for f in jablib-examples/*.java; do + for f in jablib-examples/jbang/*.java; do echo "Building $f..." jbang build --fresh "$f" done @@ -510,7 +510,7 @@ jobs: strategy: fail-fast: false matrix: - script: [.jbang/JabKitLauncher.java, .jbang/JabLsLauncher.java, .jbang/JabSrvLauncher.java, jablib-examples/ieee_pdf_references_to_bibtex.java] + script: [.jbang/JabKitLauncher.java, .jbang/JabLsLauncher.java, .jbang/JabSrvLauncher.java, jablib-examples/jbang/doi_to_bibtex.java, jablib-examples/jbang/ieee_pdf_references_to_bibtex.java] steps: - name: Checkout source uses: actions/checkout@v5 @@ -525,7 +525,7 @@ jobs: .jbang/*.java jabkit/src/main/java/**/*.java jablib/src/main/java/**/*.java - jablib-examples/**/*.java + jablib-examples/jbang/**/*.java files_ignore: | jablib/src/main/java/**/*-*.java - name: Set up JDK @@ -578,6 +578,60 @@ jobs: if: ${{ contains(matrix.script, 'Launcher.java') }} shell: bash + maven-examples: + name: Maven examples (main) + runs-on: ubuntu-latest + needs: publish + if: github.ref == 'refs/heads/main' + strategy: + fail-fast: false + matrix: + project: [jablib-examples/maven3/doi-to-bibtex] + steps: + - name: Checkout source + uses: actions/checkout@v5 + with: + submodules: 'false' + show-progress: 'false' + - name: Set up JDK + uses: actions/setup-java@v5 + with: + java-version: 24 + distribution: 'corretto' + cache: maven + check-latest: true + - run: | + cd ${{ matrix.project }} + mvn --batch-mode --update-snapshots verify + shell: bash + + maven-pr: + name: Maven examples (PR) + runs-on: ubuntu-latest + # does not need publish, because there is no publishing on non-main + if: github.ref != 'refs/heads/main' + strategy: + fail-fast: false + matrix: + project: [jablib-examples/maven3/doi-to-bibtex] + steps: + - name: Checkout source + uses: actions/checkout@v5 + with: + submodules: 'false' + show-progress: 'false' + - name: Set up JDK + uses: actions/setup-java@v5 + with: + java-version: 24 + distribution: 'corretto' + cache: maven + check-latest: true + - run: | + cd ${{ matrix.project }} + mvn --batch-mode --update-snapshots verify + shell: bash + codecoverage: if: false name: Code coverage diff --git a/.jbang/JabKitLauncher.java b/.jbang/JabKitLauncher.java index cbcbfa5073b..97ba4d72f78 100755 --- a/.jbang/JabKitLauncher.java +++ b/.jbang/JabKitLauncher.java @@ -22,19 +22,11 @@ //SOURCES ../jabkit/src/main/java/org/jabref/toolkit/JabKit.java //FILES tinylog.properties=../jabkit/src/main/resources/tinylog.properties -// REPOS mavencentral,snapshots=https://central.sonatype.com/repository/maven-snapshots/ -// REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots -//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ -// REPOS mavencentral,jitpack=https://jitpack.io +// raw is for https://github.com/unicode-org/icu/pull/2127 +//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ -// TODO: ASCII things won't work, but we accept for now to keep things going -//DEPS com.ibm.icu:icu4j:78.1 - -// Choose one - both should work -// https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/org/jabref/jablib/ //DEPS org.jabref:jablib:6.0-SNAPSHOT -// https://jitpack.io/#jabref/jabref/main-SNAPSHOT -// DEPS com.github.jabref:jabref:main-SNAPSHOT + //DEPS io.github.darvil82:terminal-text-formatter:2.2.0 //DEPS info.picocli:picocli:4.7.7 //DEPS com.github.ben-manes.caffeine:caffeine:3.2.3 diff --git a/.jbang/JabLsLauncher.java b/.jbang/JabLsLauncher.java index b4d41b15582..2302c30ba36 100755 --- a/.jbang/JabLsLauncher.java +++ b/.jbang/JabLsLauncher.java @@ -26,16 +26,10 @@ //SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/definition/LatexDefinitionProvider.java //SOURCES ../jabls/src/main/java/org/jabref/languageserver/util/definition/MarkdownDefinitionProvider.java -// REPOS mavencentral,snapshots=https://central.sonatype.com/repository/maven-snapshots/ -// REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots -//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ -// REPOS mavencentral,jitpack=https://jitpack.io +// raw is for https://github.com/unicode-org/icu/pull/2127 +//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ -// Choose one - both should work -// https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/org/jabref/jablib/ //DEPS org.jabref:jablib:6.0-SNAPSHOT -// https://jitpack.io/#jabref/jabref/main-SNAPSHOT -// DEPS com.github.jabref:jabref:main-SNAPSHOT //DEPS io.github.darvil82:terminal-text-formatter:2.2.0 //DEPS info.picocli:picocli:4.7.7 @@ -43,9 +37,9 @@ // from jabls //DEPS com.fasterxml.jackson.core:jackson-databind:2.20.1 -//DEPS com.github.eclipse:lsp4j:0.24.0 //DEPS info.picocli:picocli:4.7.7 //DEPS org.apache.logging.log4j:log4j-to-slf4j:2.25.2 +//DEPS org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0 //DEPS org.jabref:afterburner.fx:2.0.0 //DEPS org.slf4j:jul-to-slf4j:2.0.17 //DEPS org.slf4j:slf4j-api:2.0.17 diff --git a/.jbang/JabSrvLauncher.java b/.jbang/JabSrvLauncher.java index 0e5e30f8248..97095e17b32 100755 --- a/.jbang/JabSrvLauncher.java +++ b/.jbang/JabSrvLauncher.java @@ -44,19 +44,10 @@ //SOURCES ../jabsrv/src/main/java/org/jabref/http/server/PreferencesFactory.java //SOURCES ../jabsrv/src/main/java/org/jabref/http/server/Server.java -// REPOS mavencentral,snapshots=https://central.sonatype.com/repository/maven-snapshots/ -// REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots -//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ -// REPOS mavencentral,jitpack=https://jitpack.io +// raw is for https://github.com/unicode-org/icu/pull/2127 +//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ -// TODO: ASCII things won't work, but we accept for now to keep things going -//DEPS com.ibm.icu:icu4j:78.1 - -// Choose one - both should work -// https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/org/jabref/jablib/ //DEPS org.jabref:jablib:6.0-SNAPSHOT -// https://jitpack.io/#jabref/jabref/main-SNAPSHOT -// DEPS com.github.jabref:jabref:main-SNAPSHOT //DEPS io.github.darvil82:terminal-text-formatter:2.2.0 //DEPS info.picocli:picocli:4.7.7 diff --git a/build-logic/src/main/kotlin/org.jabref.gradle.feature.compile.gradle.kts b/build-logic/src/main/kotlin/org.jabref.gradle.feature.compile.gradle.kts index 12bf831596e..090f12509dc 100644 --- a/build-logic/src/main/kotlin/org.jabref.gradle.feature.compile.gradle.kts +++ b/build-logic/src/main/kotlin/org.jabref.gradle.feature.compile.gradle.kts @@ -7,14 +7,17 @@ java { // If this is updated, also update // - build.gradle -> jacoco -> toolVersion (because JaCoCo does not support newest JDK out of the box. Check versions at https://www.jacoco.org/jacoco/trunk/doc/changes.html) // - jitpack.yml + // - .sdkmanrc // - .devcontainer/devcontainer.json#L34 - there, also check if the gradleVersion matches the one of gradle/wrapper/gradle-wrapper.properties // - .moderne/moderne.yml // - .github/workflows/binaries*.yml // - .github/workflows/publish.yml // - .github/workflows/tests*.yml // - .github/workflows/update-gradle-wrapper.yml + // - .jbang/Jab*.java // - docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.md - // - .sdkmanrc + // - jablib-examples/jbang/*.java + // - jablib-examples/maven3/*/pom.xml languageVersion = JavaLanguageVersion.of(24) // See https://docs.gradle.org/current/javadoc/org/gradle/jvm/toolchain/JvmVendorSpec.html for a full list // Temurin does not ship jmods, thus we need to use another JDK -- see https://github.com/actions/setup-java/issues/804 diff --git a/jablib-examples/README.md b/jablib-examples/README.md index 298f5110d60..b203342e2a9 100644 --- a/jablib-examples/README.md +++ b/jablib-examples/README.md @@ -1,19 +1,4 @@ # `jablib` examples -This directory contains [`JBang`](https://www.jbang.dev/) examples to show how to use some `jablib` features. - -## Development - -In case you need to modify `jablib`, you can do it while working on your script. - -You need then to add each modified file following this pattern: - -```java -//SOURCES ../jablib/src/main/java/org/jabref/logic/citation/repository/BibEntrySerializer.java -``` - -The list of modified files can be generated using git and some Linux command line tools as follows: - -```bash -git diff --name-status --diff-filter=AMCR --find-renames=50% --find-copies=50% main | awk -F '\t' '($1=="A"||$1=="M"){print $2} ($1 ~ /^C/ || $1 ~ /^R/){print $3}' | grep 'jablib/src/main' | grep -v 'module-info' | grep -v '\.properties$' | sed 's#\(.*\)#//SOURCES ../\1#' -``` +The subdirectory [`jbang`](jbang/) contains rather minimal `.java` files showing how `jablib` can be used in Java projects. +The code is intended as code-snippets to be used and modified as required. diff --git a/jablib-examples/jbang/README.md b/jablib-examples/jbang/README.md new file mode 100644 index 00000000000..298f5110d60 --- /dev/null +++ b/jablib-examples/jbang/README.md @@ -0,0 +1,19 @@ +# `jablib` examples + +This directory contains [`JBang`](https://www.jbang.dev/) examples to show how to use some `jablib` features. + +## Development + +In case you need to modify `jablib`, you can do it while working on your script. + +You need then to add each modified file following this pattern: + +```java +//SOURCES ../jablib/src/main/java/org/jabref/logic/citation/repository/BibEntrySerializer.java +``` + +The list of modified files can be generated using git and some Linux command line tools as follows: + +```bash +git diff --name-status --diff-filter=AMCR --find-renames=50% --find-copies=50% main | awk -F '\t' '($1=="A"||$1=="M"){print $2} ($1 ~ /^C/ || $1 ~ /^R/){print $3}' | grep 'jablib/src/main' | grep -v 'module-info' | grep -v '\.properties$' | sed 's#\(.*\)#//SOURCES ../\1#' +``` diff --git a/jablib-examples/doi_to_bibtex.java b/jablib-examples/jbang/doi_to_bibtex.java similarity index 77% rename from jablib-examples/doi_to_bibtex.java rename to jablib-examples/jbang/doi_to_bibtex.java index ec82e3551d9..1a955e9c62b 100644 --- a/jablib-examples/doi_to_bibtex.java +++ b/jablib-examples/jbang/doi_to_bibtex.java @@ -15,8 +15,10 @@ //RUNTIME_OPTIONS --enable-native-access=ALL-UNNAMED //FILES tinylog.properties=tinylog.properties +//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/ //DEPS org.jabref:jablib:6.0-SNAPSHOT -//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ +// JabRef relies on PR https://github.com/unicode-org/icu/pull/2127; for experiments the release version is OK. +//DEPS com.ibm.icu:icu4j:78.1 void main() throws Exception { var preferences = JabRefCliPreferences.getInstance(); diff --git a/jablib-examples/ieee_pdf_references_to_bibtex.java b/jablib-examples/jbang/ieee_pdf_references_to_bibtex.java similarity index 81% rename from jablib-examples/ieee_pdf_references_to_bibtex.java rename to jablib-examples/jbang/ieee_pdf_references_to_bibtex.java index 95d9c393759..71a0d45f932 100644 --- a/jablib-examples/ieee_pdf_references_to_bibtex.java +++ b/jablib-examples/jbang/ieee_pdf_references_to_bibtex.java @@ -14,8 +14,10 @@ //RUNTIME_OPTIONS --enable-native-access=ALL-UNNAMED //FILES tinylog.properties=tinylog.properties +//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/ //DEPS org.jabref:jablib:6.0-SNAPSHOT -//REPOS mavencentral,mavencentralsnapshots=https://central.sonatype.com/repository/maven-snapshots/,s01oss=https://s01.oss.sonatype.org/content/repositories/snapshots/,oss=https://oss.sonatype.org/content/repositories,jitpack=https://jitpack.io,oss2=https://oss.sonatype.org/content/groups/public,ossrh=https://oss.sonatype.org/content/repositories/snapshots,raw=https://raw.githubusercontent.com/JabRef/jabref/refs/heads/main/jablib/lib/ +// JabRef relies on PR https://github.com/unicode-org/icu/pull/2127; for experiments the release version is OK. +//DEPS com.ibm.icu:icu4j:78.1 void main() throws Exception { var preferences = JabRefCliPreferences.getInstance(); diff --git a/jablib-examples/tinylog.properties b/jablib-examples/jbang/tinylog.properties similarity index 100% rename from jablib-examples/tinylog.properties rename to jablib-examples/jbang/tinylog.properties diff --git a/jablib-examples/maven3/doi-to-bibtex/.gitignore b/jablib-examples/maven3/doi-to-bibtex/.gitignore new file mode 100644 index 00000000000..f13e66fac43 --- /dev/null +++ b/jablib-examples/maven3/doi-to-bibtex/.gitignore @@ -0,0 +1,111 @@ +# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,maven +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,maven + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# End of https://www.toptal.com/developers/gitignore/api/intellij+all,maven diff --git a/jablib-examples/maven3/doi-to-bibtex/.mvn/jvm.config b/jablib-examples/maven3/doi-to-bibtex/.mvn/jvm.config new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jablib-examples/maven3/doi-to-bibtex/.mvn/maven.config b/jablib-examples/maven3/doi-to-bibtex/.mvn/maven.config new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jablib-examples/maven3/doi-to-bibtex/pom.xml b/jablib-examples/maven3/doi-to-bibtex/pom.xml new file mode 100644 index 00000000000..25ac39bfa19 --- /dev/null +++ b/jablib-examples/maven3/doi-to-bibtex/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + + org.jabref.jablib.examples + doi-to-bibtex + 0.1.0-SNAPSHOT + + doi-to-bibtex + + + UTF-8 + 24 + + + + + + Central Portal Snapshots + central-portal-snapshots + https://central.sonatype.com/repository/maven-snapshots/ + + false + + + true + + + + + central + https://repo.maven.apache.org/maven2 + + + + jitpack + https://jitpack.io + + + + + + org.jabref + jablib + 6.0-SNAPSHOT + + + + + com.ibm.icu + icu4j + 78.1 + + + + org.tinylog + tinylog-api + 2.7.0 + + + org.tinylog + tinylog-impl + 2.7.0 + runtime + + + + + + + + maven-clean-plugin + 3.4.0 + + + maven-resources-plugin + 3.3.1 + + + maven-compiler-plugin + 3.13.0 + + + maven-surefire-plugin + 3.3.0 + + + maven-jar-plugin + 3.4.2 + + + maven-deploy-plugin + 3.1.2 + + + maven-project-info-reports-plugin + 3.6.1 + + + + + diff --git a/jablib-examples/maven3/doi-to-bibtex/src/main/java/org/jabref/jablib/examples/App.java b/jablib-examples/maven3/doi-to-bibtex/src/main/java/org/jabref/jablib/examples/App.java new file mode 100644 index 00000000000..58b33b51a5b --- /dev/null +++ b/jablib-examples/maven3/doi-to-bibtex/src/main/java/org/jabref/jablib/examples/App.java @@ -0,0 +1,51 @@ +package org.jabref.jablib.examples; + +import org.jabref.logic.exporter.BibDatabaseWriter; +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.fetcher.CrossRef; +import org.jabref.logic.preferences.JabRefCliPreferences; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseContext; + +import org.jabref.model.entry.BibEntry; + +import org.tinylog.Logger; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.util.List; + +/** + * Converts a DOI to BibTeX + */ +public class App { + public static void main(String[] args) { + String doi; + if (args.length == 1) { + doi = args[0]; + } else { + doi = "10.47397/tb/44-3/tb138kopp-jabref"; + } + JabRefCliPreferences preferences = JabRefCliPreferences.getInstance(); + + // All `IdParserFetcher` can do. In JabRef, there is currently only one implemented + + CrossRef fetcher = new CrossRef(); + BibEntry entry = null; // will throw an exception if not found + try { + entry = fetcher.performSearchById(doi).get(); + } catch (FetcherException e) { + Logger.error("Could not fetch entry", e); + return; + } + + try (OutputStreamWriter writer = new OutputStreamWriter(System.out, StandardCharsets.UTF_8)) { + BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(entry))); + BibDatabaseWriter bibWriter = new BibDatabaseWriter(writer, context, preferences); + bibWriter.writeDatabase(context); + } catch (IOException e) { + Logger.error("Could not write library", e); + } + } +} diff --git a/jablib-examples/maven3/doi-to-bibtex/src/main/resources/tinylog.properties b/jablib-examples/maven3/doi-to-bibtex/src/main/resources/tinylog.properties new file mode 100644 index 00000000000..0c42d3e27d5 --- /dev/null +++ b/jablib-examples/maven3/doi-to-bibtex/src/main/resources/tinylog.properties @@ -0,0 +1,16 @@ +level = debug +writer = console + +writer.format = {date} [{thread}] {class}.{method}()\n{level}: {message}\n + +# More shrunk exception logs. See https://tinylog.org/v2/configuration/#strip-stack-trace-elements for details +exception = strip: jdk.internal + +level@org.jabref = info + +level@org.apache.pdfbox.pdmodel.font = error +level@org.apache.pdfbox.pdmodel.PDSimpleFont = error +level@org.apache.fontbox.util.autodetect.FontFileFinder = warn +level@org.apache.fontbox.ttf = warn +level@ai.djl = info +level@io.zonky.test.db.postgres.embedded = warn