diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 11163bde525..8c59721c045 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -31,9 +31,9 @@ // Install java. // See https://github.com/devcontainers/features/tree/main/src/java#options for details. "ghcr.io/devcontainers/features/java:1": { - "version": "20.0.2-tem", + "version": "21.0.1-librca", "installGradle": false, - "jdkDistro": "tem" + "jdkDistro": "librca" } } } diff --git a/.github/workflows/deployment-arm64.yml b/.github/workflows/deployment-arm64.yml index 87338bcee4c..b5cb0cf4bc0 100644 --- a/.github/workflows/deployment-arm64.yml +++ b/.github/workflows/deployment-arm64.yml @@ -61,23 +61,9 @@ jobs: - name: Setup JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - - name: Setup JDK jabref-fix macOS - shell: bash - run: | - mkdir ${{runner.temp}}/jdk - wget -qO- https://files.jabref.org/jdks/jdk-macos-aarch64.tar.gz | tar xz -C ${{runner.temp}}/jdk - mv ${{runner.temp}}/jdk/jdk-21.jdk ${{runner.temp}}/jdk/jdk-21 - echo "JDK21=${{runner.temp}}/jdk/jdk-21" >> "$GITHUB_ENV" - ls ${{runner.temp}}/jdk - - echo "org.gradle.java.installations.paths=${{runner.temp}}/jdk/jdk-21" >> gradle.properties - echo "org.gradle.java.installations.auto-detect=false" >> gradle.properties - cat gradle.properties - - sed -i'.bak' -e "s/JavaLanguageVersion.of(20)/JavaLanguageVersion.of(21)/" build.gradle - name: Clean up keychain run: | security delete-keychain signing_temp.keychain ${{runner.temp}}/keychain/notarization.keychain || true @@ -104,9 +90,9 @@ jobs: - name: Build dmg (macOS) shell: bash run: | - ${{env.JDK21}}/Contents/Home/bin/jpackage \ + jpackage \ --module org.jabref/org.jabref.cli.Launcher \ - --module-path ${{env.JDK21}}/Contents/Home/jmods/:build/jlinkbase/jlinkjars \ + --module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \ --add-modules org.jabref,org.jabref.merged.module \ --dest build/distribution \ --app-content buildres/mac/jabrefHost.py \ @@ -128,9 +114,9 @@ jobs: - name: Build pkg (macOS) shell: bash run: | - ${{env.JDK21}}/Contents/Home/bin/jpackage \ + jpackage \ --module org.jabref/org.jabref.cli.Launcher \ - --module-path ${{env.JDK21}}/Contents/Home/jmods/:build/jlinkbase/jlinkjars \ + --module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \ --add-modules org.jabref,org.jabref.merged.module \ --dest build/distribution \ --app-content buildres/mac/jabrefHost.py \ diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index fa9743d5557..019483f0125 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -92,52 +92,9 @@ jobs: - name: Setup JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - - name: Setup JDK jabref-fix (Windows) - if: (matrix.os == 'windows-latest') - shell: bash - run: | - mkdir ${{runner.temp}}\jdk - curl -kLsS ${{matrix.eaJDK}} -o temp.zip && 7z x temp.zip -o"$(cygpath -u "$RUNNER_TEMP\jdk")" - echo "JDK21=${{runner.temp}}\jdk\jdk-21" >> "$GITHUB_ENV" - ls "$(cygpath -u "$RUNNER_TEMP\jdk\jdk-21")" - - echo "org.gradle.java.installations.paths=${{runner.temp}}\jdk\jdk-21" | sed "s/\\\\/\\\\\\\\/g" >> gradle.properties - echo "org.gradle.java.installations.auto-detect=false" >> gradle.properties - cat gradle.properties - - sed -i "s/JavaLanguageVersion.of(20)/JavaLanguageVersion.of(21)/" build.gradle - - name: Setup JDK jabref-fix (linux) - if: (matrix.os == 'ubuntu-latest') - shell: bash - run: | - mkdir ${{runner.temp}}/jdk - wget -qO- ${{matrix.eaJDK}} | tar xz -C ${{runner.temp}}/jdk - echo "JDK21=${{runner.temp}}/jdk/jdk-21" >> "$GITHUB_ENV" - ls ${{runner.temp}}/jdk - - echo "org.gradle.java.installations.paths=${{runner.temp}}/jdk/jdk-21" >> gradle.properties - echo "org.gradle.java.installations.auto-detect=false" >> gradle.properties - cat gradle.properties - - sed -i "s/JavaLanguageVersion.of(20)/JavaLanguageVersion.of(21)/" build.gradle - - name: Setup JDK jabref-fix (macOS) - if: (matrix.os == 'macos-latest') - shell: bash - run: | - mkdir ${{runner.temp}}/jdk - wget -qO- ${{matrix.eaJDK}} | tar xz -C ${{runner.temp}}/jdk - mv ${{runner.temp}}/jdk/jdk-21.jdk ${{runner.temp}}/jdk/jdk-21 - echo "JDK21=${{runner.temp}}/jdk/jdk-21" >> "$GITHUB_ENV" - ls ${{runner.temp}}/jdk - - echo "org.gradle.java.installations.paths=${{runner.temp}}/jdk/jdk-21" >> gradle.properties - echo "org.gradle.java.installations.auto-detect=false" >> gradle.properties - cat gradle.properties - - sed -i'.bak' -e "s/JavaLanguageVersion.of(20)/JavaLanguageVersion.of(21)/" build.gradle - name: Prepare merged jars and modules dir (macOS) if: (matrix.os == 'macos-latest') || (steps.checksecrets.outputs.secretspresent == 'NO') run: ./gradlew -i -PprojVersion="${{ steps.gitversion.outputs.AssemblySemVer }}" -PprojVersionInfo="${{ steps.gitversion.outputs.InformationalVersion }}" prepareModulesDir @@ -160,9 +117,9 @@ jobs: if: (matrix.os == 'macos-latest') && (steps.checksecrets.outputs.secretspresent == 'YES') shell: bash run: | - ${{env.JDK21}}/Contents/Home/bin/jpackage \ + jpackage \ --module org.jabref/org.jabref.cli.Launcher \ - --module-path ${{env.JDK21}}/Contents/Home/jmods/:build/jlinkbase/jlinkjars \ + --module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \ --add-modules org.jabref,org.jabref.merged.module \ --dest build/distribution \ --app-content buildres/mac/jabrefHost.py \ @@ -185,9 +142,9 @@ jobs: if: (matrix.os == 'macos-latest') && (steps.checksecrets.outputs.secretspresent == 'YES') shell: bash run: | - ${{env.JDK21}}/Contents/Home/bin/jpackage \ + jpackage \ --module org.jabref/org.jabref.cli.Launcher \ - --module-path ${{env.JDK21}}/Contents/Home/jmods/:build/jlinkbase/jlinkjars \ + --module-path ${{env.JAVA_HOME}}/jmods/:build/jlinkbase/jlinkjars \ --add-modules org.jabref,org.jabref.merged.module \ --dest build/distribution \ --app-content buildres/mac/jabrefHost.py \ diff --git a/.github/workflows/refresh-journal-lists.yml b/.github/workflows/refresh-journal-lists.yml index dccbea60e00..88f43f673c1 100644 --- a/.github/workflows/refresh-journal-lists.yml +++ b/.github/workflows/refresh-journal-lists.yml @@ -30,8 +30,8 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Check whether journal-list.mv can be generated (the "real" generation is done inside JabRef's build process) run: | diff --git a/.github/workflows/tests-fetchers.yml b/.github/workflows/tests-fetchers.yml index 4baf08e3cdd..ee155b0c243 100644 --- a/.github/workflows/tests-fetchers.yml +++ b/.github/workflows/tests-fetchers.yml @@ -48,8 +48,8 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Run fetcher tests run: ./gradlew fetcherTest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2819ae4fe7d..7578854d6a9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,13 +29,13 @@ jobs: - name: Checkout source uses: actions/checkout@v4 with: - submodules: 'false' + submodules: 'true' show-progress: 'false' - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Run checkstyle reporter uses: nikitasavinov/checkstyle-action@master @@ -103,8 +103,8 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Run tests run: xvfb-run --auto-servernum ./gradlew check -x checkstyleJmh -x checkstyleMain -x checkstyleTest -x modernizer @@ -138,8 +138,8 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Run tests on PostgreSQL run: ./gradlew databaseTest --rerun-tasks @@ -175,8 +175,8 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Run GUI tests run: xvfb-run --auto-servernum ./gradlew guiTest @@ -216,8 +216,8 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 20 - distribution: 'temurin' + java-version: 21.0.1 + distribution: 'liberica' cache: 'gradle' - name: Update test coverage metrics if: steps.checksecrets.outputs.secretspresent == 'YES' diff --git a/build.gradle b/build.gradle index b9b841e7826..cc3cd713f75 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ import org.jabref.build.xjc.XjcTask plugins { id 'application' - id 'com.github.andygoossens.modernizer' version '1.8.0' + id 'com.github.andygoossens.modernizer' version '1.9.0' id 'me.champeau.jmh' version '0.7.1' @@ -41,15 +41,15 @@ group = "org.jabref" version = project.findProperty('projVersion') ?: '100.0.0' java { - sourceCompatibility = JavaVersion.VERSION_19 - targetCompatibility = JavaVersion.VERSION_19 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 // Workaround needed for Eclipse, probably because of https://github.com/gradle/gradle/issues/16922 // Should be removed as soon as Gradle 7.0.1 is released ( https://github.com/gradle/gradle/issues/16922#issuecomment-828217060 ) modularity.inferModulePath.set(false) toolchain { // If this is updated, also update .devcontainer/devcontainer.json#L34 - languageVersion = JavaLanguageVersion.of(20) + languageVersion = JavaLanguageVersion.of(21) } } diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-installs-temurin.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-installs-temurin.png index e85b5608460..320e2835da4 100644 Binary files a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-installs-temurin.png and b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-installs-temurin.png differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-open-module-settings.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-open-module-settings.png new file mode 100644 index 00000000000..deef5f86734 Binary files /dev/null and b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-open-module-settings.png differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-project-settings-jdk.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-project-settings-jdk.png new file mode 100644 index 00000000000..47902d31028 Binary files /dev/null and b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-project-settings-jdk.png differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-project-settings-jdk18.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-project-settings-jdk18.png deleted file mode 100644 index 2f60589ae37..00000000000 Binary files a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-project-settings-jdk18.png and /dev/null differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-select-jdk-eclipse-temurin.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-select-jdk-eclipse-temurin.png new file mode 100644 index 00000000000..f25d1238124 Binary files /dev/null and b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-select-jdk-eclipse-temurin.png differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-settings-gradle-gradlejvm-is-projectjvm.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-settings-gradle-gradlejvm-is-projectjvm.png new file mode 100644 index 00000000000..e7489e7f380 Binary files /dev/null and b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-intellij-settings-gradle-gradlejvm-is-projectjvm.png differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-select-jdk-18-eclipse-temurin.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-select-jdk-18-eclipse-temurin.png deleted file mode 100644 index 4472216f0c6..00000000000 Binary files a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-select-jdk-18-eclipse-temurin.png and /dev/null differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-settings-gradle-gradlejvm-is-projectjvm.png b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-settings-gradle-gradlejvm-is-projectjvm.png deleted file mode 100644 index 7a9b155bdf9..00000000000 Binary files a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/guidelines-settings-gradle-gradlejvm-is-projectjvm.png and /dev/null differ diff --git a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.md b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.md index e4dd5425f70..662c06c5723 100644 --- a/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.md +++ b/docs/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.md @@ -6,24 +6,24 @@ nav_order: 12 # Step 2: Setup the build system: JDK and Gradle -## Ensure that JDK 20 is available to IntelliJ +## Ensure that JDK 21 is available to IntelliJ -Ensure you have a Java 20 SDK configured by navigating to **File > Project Structure... > Platform Settings > SDKs**. +Ensure you have a Java 21 SDK configured by navigating to **File > Project Structure... > Platform Settings > SDKs**. -{% figure caption:"JDKs 11, 14, and 15 shown in available SDKs. JDK 20 is missing." %} +{% figure caption:"JDKs 11, 14, and 15 shown in available SDKs. JDK 21 is missing." %} ![Plattform Settings - SDKs](intellij-choose-jdk-adoptopenjdk-on-windows-project-settings.png) {% endfigure %} -If there is another JDK than JDK 20 selected, click on the plus button and choose "Download JDK..." +If there is another JDK than JDK 21 selected, click on the plus button and choose "Download JDK..." {% figure caption:"Download JDK..." %} ![Plattform Settings - SDKs - plus button - Download JDK...](guidelines-select-download-jdk.png) {% endfigure %} -Select JDK version 20 and then Eclipse Temurin (showing JDK 18 as example). +Select JDK version 21 and then Eclipse Temurin. -{% figure caption:"Example for JDK 18 - Choose Eclipse Temurin" %} -![Download Eclipse Temurin](guidelines-select-jdk-18-eclipse-temurin.png) +{% figure caption:"Example for JDK 21 - Choose Eclipse Temurin" %} +![Download Eclipse Temurin](guidelines-intellij-select-jdk-eclipse-temurin.png) {% endfigure %} After clicking "Download", IntelliJ installs Eclipse Temurin: @@ -32,20 +32,26 @@ After clicking "Download", IntelliJ installs Eclipse Temurin: ![IntelliJ installs Eclipse Temurin](guidelines-intellij-installs-temurin.png) {% endfigure %} -Navigate to **Project Settings > Project** and ensure that the projects' SDK is Java 20 +Open the module settings: Right click on "JabRef" and select "Open Module Settings": -{% figure caption:"Project SDK is pinned to the downloaded SDK (showing JDK 18 as example)" %} -![Project SDK is JDK 18](guidelines-intellij-project-settings-jdk18.png) +{% figure caption:"Open IntelliJ Module Settings" %} +![IntelliJ Module Settings](guidelines-intellij-open-module-settings.png) +{% endfigure %} + +Navigate to **Project Settings > Project** and ensure that the projects' SDK is Java 21. + +{% figure caption:"Project SDK is pinned to the downloaded SDK (showing JDK 21 as example)" %} +![Project SDK is JDK 21](guidelines-intellij-project-settings-jdk.png) {% endfigure %} Click "OK" to store the changes. ## Configure the Build System -Navigate to **File > Settings... > Build, Execution, Deployment > Build Tools > Gradle** and select the "Project SDK" as the Gradle JVM at the bottom. If that does not exist, just select a JDK 20. +Navigate to **File > Settings... > Build, Execution, Deployment > Build Tools > Gradle** and select the "Project SDK" as the Gradle JVM at the bottom. If that does not exist, just select a JDK 21. -{% figure caption:"Gradle JVM is project SDK (showing JDK 18 as example)" %} -![Gradle JVM is project SDK](guidelines-settings-gradle-gradlejvm-is-projectjvm.png) +{% figure caption:"Gradle JVM is project SDK (showing JDK 21 as example)" %} +![Gradle JVM is project SDK](guidelines-intellij-settings-gradle-gradlejvm-is-projectjvm.png) {% endfigure %} To prepare IntelliJ's build system additional steps are required: diff --git a/src/main/java/org/jabref/logic/bst/BstFunctions.java b/src/main/java/org/jabref/logic/bst/BstFunctions.java index 6689f83b2a5..1e048da1a45 100644 --- a/src/main/java/org/jabref/logic/bst/BstFunctions.java +++ b/src/main/java/org/jabref/logic/bst/BstFunctions.java @@ -1,9 +1,9 @@ package org.jabref.logic.bst; +import java.util.Deque; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.Stack; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -30,7 +30,7 @@ public class BstFunctions { private final Map functions; private final String preamble; - private final Stack stack; + private final Deque stack; private final StringBuilder bbl; private int bstWarning = 0; @@ -670,7 +670,7 @@ private void bstSkip(BstVMVisitor visitor, ParserRuleContext ctx) { * designers while debugging. */ private void bstStack(BstVMVisitor visitor, ParserRuleContext ctx) { - while (!stack.empty()) { + while (!stack.isEmpty()) { LOGGER.debug("Stack entry {}", stack.pop()); } } diff --git a/src/main/java/org/jabref/logic/bst/BstVM.java b/src/main/java/org/jabref/logic/bst/BstVM.java index a2428d683d9..bb643572fe5 100644 --- a/src/main/java/org/jabref/logic/bst/BstVM.java +++ b/src/main/java/org/jabref/logic/bst/BstVM.java @@ -4,9 +4,9 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.List; import java.util.Objects; -import java.util.Stack; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; @@ -93,7 +93,7 @@ public String render(Collection bibEntries) { return render(bibEntries, null); } - protected Stack getStack() { + protected Deque getStack() { if (latestContext != null) { return latestContext.stack(); } else { diff --git a/src/main/java/org/jabref/logic/bst/BstVMContext.java b/src/main/java/org/jabref/logic/bst/BstVMContext.java index 8a98f605dd8..472ec047734 100644 --- a/src/main/java/org/jabref/logic/bst/BstVMContext.java +++ b/src/main/java/org/jabref/logic/bst/BstVMContext.java @@ -1,11 +1,12 @@ package org.jabref.logic.bst; import java.nio.file.Path; +import java.util.Deque; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Stack; import org.jabref.model.database.BibDatabase; @@ -13,10 +14,11 @@ public record BstVMContext(List entries, Map strings, Map integers, Map functions, - Stack stack, + Deque stack, BibDatabase bibDatabase, Optional path) { public BstVMContext(List entries, BibDatabase bibDatabase, Path path) { - this(entries, new HashMap<>(), new HashMap<>(), new HashMap<>(), new Stack<>(), bibDatabase, Optional.ofNullable(path)); + // LinkedList instead of ArrayDeque, because we (currently) need null support + this(entries, new HashMap<>(), new HashMap<>(), new HashMap<>(), new LinkedList<>(), bibDatabase, Optional.ofNullable(path)); } } diff --git a/src/main/java/org/jabref/logic/util/io/FileUtil.java b/src/main/java/org/jabref/logic/util/io/FileUtil.java index 8d2d2d91920..05a2a4746c6 100644 --- a/src/main/java/org/jabref/logic/util/io/FileUtil.java +++ b/src/main/java/org/jabref/logic/util/io/FileUtil.java @@ -8,16 +8,16 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.StandardOpenOption; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.Deque; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Optional; -import java.util.Stack; -import java.util.Vector; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -36,9 +36,6 @@ * The idea of this class is to add general functionality that could possibly even in the * Java NIO package, * such as getting/adding file extension etc. - * - * This class is the "successor" of {@link FileHelper}. In case you miss something here, - * please look at {@link FileHelper} and migrate the functionality to here. */ public class FileUtil { @@ -105,9 +102,9 @@ public static String getBaseName(Path fileNameWithExtension) { /** * Returns a valid filename for most operating systems. - * + *

* Currently, only the length is restricted to 255 chars, see MAXIMUM_FILE_NAME_LENGTH. - * + *

* For "real" cleaning, {@link FileNameCleaner#cleanFileName(String)} should be used. */ public static String getValidFileName(String fileName) { @@ -126,7 +123,7 @@ public static String getValidFileName(String fileName) { /** * Adds an extension to the given file name. The original extension is not replaced. That means, "demo.bib", ".sav" * gets "demo.bib.sav" and not "demo.sav" - * + *

* Warning! If "ext" is passed, this is literally added. Thus addExtension("tmp.txt", "ext") leads to "tmp.txtext" * * @param path the path to add the extension to @@ -163,8 +160,7 @@ public static Optional getUniquePathDirectory(List paths, Path c public static Optional getUniquePathFragment(List paths, Path comparePath) { return uniquePathSubstrings(paths).stream() .filter(part -> comparePath.toString().contains(part)) - .sorted(Comparator.comparingInt(String::length).reversed()) - .findFirst(); + .max(Comparator.comparingInt(String::length)); } /** @@ -174,32 +170,34 @@ public static Optional getUniquePathFragment(List paths, Path co * @return the minimal unique path substring for each file path */ public static List uniquePathSubstrings(List paths) { - List> stackList = new ArrayList<>(paths.size()); + List> stackList = new ArrayList<>(paths.size()); // prepare data structures for (String path : paths) { List directories = Arrays.asList(path.split(Pattern.quote(File.separator))); - Stack stack = new Stack<>(); - stack.addAll(directories); + Deque stack = new ArrayDeque<>(directories.reversed()); stackList.add(stack); } List pathSubstrings = new ArrayList<>(Collections.nCopies(paths.size(), "")); // compute the shortest folder substrings - while (!stackList.stream().allMatch(Vector::isEmpty)) { + while (!stackList.stream().allMatch(Deque::isEmpty)) { for (int i = 0; i < stackList.size(); i++) { - String tempString = pathSubstrings.get(i); + String tempPathString = pathSubstrings.get(i); + + Deque stack = stackList.get(i); - if (tempString.isEmpty() && !stackList.get(i).isEmpty()) { - pathSubstrings.set(i, stackList.get(i).pop()); - } else if (!stackList.get(i).isEmpty()) { - pathSubstrings.set(i, stackList.get(i).pop() + File.separator + tempString); + if (tempPathString.isEmpty() && !stack.isEmpty()) { + String stringFromDeque = stack.pop(); + pathSubstrings.set(i, stringFromDeque); + } else if (!stack.isEmpty()) { + String stringFromStack = stack.pop(); + pathSubstrings.set(i, stringFromStack + File.separator + tempPathString); } } for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); - if (Collections.frequency(pathSubstrings, tempString) == 1) { stackList.get(i).clear(); } @@ -371,7 +369,7 @@ public static Optional find(String fileName, List directories) { * @param fileName the filename (e.g., a .pdf file), may contain path separators * @param directory the directory which should be search starting point * - * @returns an empty optional if the file does not exist, otherwise, the absolute path + * @return an empty optional if the file does not exist, otherwise, the absolute path */ public static Optional find(String fileName, Path directory) { Objects.requireNonNull(fileName); @@ -461,7 +459,7 @@ public static Path getInitialDirectory(BibDatabaseContext databaseContext, Path /** * Detect illegal characters in given filename. - * + *

* See also {@link org.jabref.logic.util.io.FileNameCleaner#cleanFileName} * * @param fileName the fileName to detect diff --git a/src/main/java/org/jabref/model/openoffice/ootext/OOTextIntoOO.java b/src/main/java/org/jabref/model/openoffice/ootext/OOTextIntoOO.java index 7e434495571..2f6fb39f0b6 100644 --- a/src/main/java/org/jabref/model/openoffice/ootext/OOTextIntoOO.java +++ b/src/main/java/org/jabref/model/openoffice/ootext/OOTextIntoOO.java @@ -1,14 +1,15 @@ package org.jabref.model.openoffice.ootext; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; +import java.util.Deque; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.Stack; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -145,7 +146,7 @@ public static void write(XTextDocument doc, XTextCursor position, OOText ootext) cursor.collapseToEnd(); MyPropertyStack formatStack = new MyPropertyStack(cursor); - Stack expectEnd = new Stack<>(); + Deque expectEnd = new ArrayDeque<>(); // We need to extract formatting. Use a simple regexp search iteration: int piv = 0; @@ -302,7 +303,7 @@ public static void write(XTextDocument doc, XTextCursor position, OOText ootext) formatStack.apply(cursor); cursor.collapseToEnd(); - if (!expectEnd.empty()) { + if (!expectEnd.isEmpty()) { StringBuilder rest = new StringBuilder(); for (String s : expectEnd) { rest.insert(0, String.format("<%s>", s)); @@ -438,7 +439,7 @@ static class MyPropertyStack { /** * Maintain a stack of layers, each containing a description of the desired state of properties. Each description is an ArrayList of property values, Optional.empty() encoding "not directly set". */ - final Stack>> layers; + final Deque>> layers; MyPropertyStack(XTextCursor cursor) { XPropertySet propertySet = UnoCast.cast(XPropertySet.class, cursor).get(); @@ -493,7 +494,7 @@ static class MyPropertyStack { } } - this.layers = new Stack<>(); + this.layers = new ArrayDeque<>(); this.layers.push(initialValuesOpt); } diff --git a/src/test/java/org/jabref/logic/bst/BstVMTest.java b/src/test/java/org/jabref/logic/bst/BstVMTest.java index 4a66a8d5836..52a36b987d0 100644 --- a/src/test/java/org/jabref/logic/bst/BstVMTest.java +++ b/src/test/java/org/jabref/logic/bst/BstVMTest.java @@ -102,7 +102,7 @@ public void testBuildIn() throws RecognitionException { vm.render(Collections.emptyList()); assertEquals(Integer.MAX_VALUE, vm.latestContext.stack().pop()); - assertTrue(vm.latestContext.stack().empty()); + assertTrue(vm.latestContext.stack().isEmpty()); } @Test