diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2537322 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +max_line_length = 80 + +[*.yml] +indent_size = 2 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..dfd2495 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: maven + directory: / + schedule: + interval: monthly + open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly + open-pull-requests-limit: 10 diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml new file mode 100644 index 0000000..a4af466 --- /dev/null +++ b/.github/workflows/java.yml @@ -0,0 +1,28 @@ +name: Java CI with Maven +on: + - push + - pull_request + - merge_group +jobs: + build_jdk11: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: adopt + - name: Build with Maven + run: mvn -B package --file pom.xml + build_latest_lts: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: adopt + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index d9f8e69..0000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,22 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -# Triggers the workflow on push or pull request events (for any branch in a repository) -on: [ push, pull_request ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'adopt' - - name: Build with Maven - run: mvn -B package --file pom.xml diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 0000000..107e2e9 --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,25 @@ +name: QA +on: + - merge_group + - push + - pull_request +jobs: + spellcheck: + name: Spellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: crate-ci/typos@v1.16.19 + nix-shell: + name: nix-shell works + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v22 + with: + # Only used for "nix-build", "nix-shell" etc. + # Inside the files, I use pinned nixpkgs. + nix_path: nixpkgs=channel:nixos-23.05 + - uses: DeterminateSystems/magic-nix-cache-action@main + - run: | + nix-shell --pure --run "mvn -B dependency:tree" diff --git a/.gitignore b/.gitignore index 34859a1..cd31358 100644 --- a/.gitignore +++ b/.gitignore @@ -155,3 +155,6 @@ $RECYCLE.BIN/ *.lnk # End of https://www.gitignore.io/api/linux,macos,maven,windows,intellij,visualstudiocode +/.classpath +/.project +/.settings diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..d2ab45a --- /dev/null +++ b/.typos.toml @@ -0,0 +1,13 @@ +# Configuration for https://github.com/crate-ci/typos + +[files] + +[default] +extend-ignore-identifiers-re = [ + # Markdown in README.md + "earchAnd*", +] + +[default.extend-words] + +[default.extend-identifiers] diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b854a2..c46f2c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 2.0.0 (2023-11-03) +- **BREAKING** This library is now based on Java 11 instead of Java 8 +- It now references docx4j-dependencies in version 11 instead of version 8 +- internal improvements (other dependency updates) + # 1.0.7 (2023-01-22) - bug fix that produces NPEs () - bumped `docx4j-JAXB-ReferenceImpl` from `8.3.2` to `8.3.9` @@ -17,4 +22,4 @@ Dependency upgrades + small fixes + definitely works with Java 8. Using `docx4j-JAXB-ReferenceImpl` @ `8.x` # 1.0.1 -Initial release on Maven \ No newline at end of file +Initial release on Maven diff --git a/LICENSE b/LICENSE index e82e807..5c05afd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Philipp Schuster (phip1611@gmail.com) +Copyright (c) 2023 Philipp Schuster Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..84bb7fd --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,14 @@ +{ + "nixpkgs": { + "branch": "nixos-23.05", + "description": "Nix Packages collection", + "homepage": null, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6c43a3495a11e261e5f41e5d7eda2d71dae1b2fe", + "sha256": "16f329z831bq7l3wn1dfvbkh95l2gcggdwn6rk3cisdmv2aa3189", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/6c43a3495a11e261e5f41e5d7eda2d71dae1b2fe.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..fe3dadf --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/pom.xml b/pom.xml index df16953..6efe001 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.phip1611 docx4j-search-and-replace-util - 1.0.7-SNAPSHOT + 2.0.0-SNAPSHOT Docx4J Search and Replace Util Docx4JSRUtil library helps you to search and replace text inside docx-Documents parsed by Docx4J. https://github.com/phip1611/docx4j-search-and-replace-util @@ -34,8 +34,8 @@ UTF-8 - 1.8 - 1.8 + 11 + 11 @@ -61,12 +61,7 @@ org.docx4j docx4j-JAXB-ReferenceImpl - 8.3.9 - - - javax.xml.bind - jaxb-api - 2.3.1 + 11.4.9 junit @@ -77,7 +72,7 @@ org.slf4j slf4j-simple - 1.7.36 + 2.0.9 test @@ -95,7 +90,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.1 + 3.6.0 attach-javadocs @@ -108,7 +103,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources @@ -120,7 +115,7 @@ maven-deploy-plugin - 3.0.0 + 3.1.1 default-deploy @@ -145,7 +140,7 @@ org.apache.maven.plugins maven-release-plugin - 2.5.3 + 3.0.1 true false @@ -159,12 +154,12 @@ org.apache.maven.scm maven-scm-provider-gitexe - 1.13.0 + 2.0.1 org.apache.maven.scm maven-scm-api - 1.13.0 + 2.0.1 @@ -186,7 +181,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.1.0 sign-artifacts @@ -205,6 +200,4 @@ - - - \ No newline at end of file + diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..828a30f --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +let + sources = import ./nix/sources.nix; + pkgs = import sources.nixpkgs {}; +in +pkgs.mkShell rec { + nativeBuildInputs = with pkgs; [ + maven + jdk11 + ]; +} diff --git a/src/main/java/de/phip1611/Docx4JSRUtil.java b/src/main/java/de/phip1611/Docx4JSRUtil.java index 82e6ca8..b544964 100644 --- a/src/main/java/de/phip1611/Docx4JSRUtil.java +++ b/src/main/java/de/phip1611/Docx4JSRUtil.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2020 Philipp Schuster (phip1611@gmail.com) + * Copyright (c) 2023 Philipp Schuster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBElement; import java.util.ArrayList; import java.util.Collection; import java.util.List; diff --git a/src/main/java/de/phip1611/StringFindUtil.java b/src/main/java/de/phip1611/StringFindUtil.java index 2a2ffdd..682f639 100644 --- a/src/main/java/de/phip1611/StringFindUtil.java +++ b/src/main/java/de/phip1611/StringFindUtil.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2020 Philipp Schuster (phip1611@gmail.com) + * Copyright (c) 2023 Philipp Schuster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/test/java/de/phip1611/Docx4JSRUtilTest.java b/src/test/java/de/phip1611/Docx4JSRUtilTest.java index 7d9ef04..39d4d5b 100644 --- a/src/test/java/de/phip1611/Docx4JSRUtilTest.java +++ b/src/test/java/de/phip1611/Docx4JSRUtilTest.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2020 Philipp Schuster (phip1611@gmail.com) + * Copyright (c) 2023 Philipp Schuster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/test/java/de/phip1611/ProcessDocxUserFileTest.java b/src/test/java/de/phip1611/ProcessDocxUserFileTest.java index b58d2f1..eeceea6 100644 --- a/src/test/java/de/phip1611/ProcessDocxUserFileTest.java +++ b/src/test/java/de/phip1611/ProcessDocxUserFileTest.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2020 Philipp Schuster (phip1611@gmail.com) + * Copyright (c) 2023 Philipp Schuster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,40 +26,32 @@ import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; - import java.io.File; import java.util.HashMap; import java.util.Map; /** - * Processes a user specified docx file and writes the - * transformed document into the specified location. - * - * This IS NOT a test JUnit should execute but a test for - * humans (to execute from your IDE). This way you can - * easily specify a path and check the processed .docx. + * Processes a user specified docx file and writes the transformed document + * into the specified location. This is not really a JUnit test but a test + * meant for you, the dev, to be used from your IDE. This way, you can easily + * specify a path and check the processed .docx file. */ public class ProcessDocxUserFileTest { private static final String SOURCE_DOCX_PATH = "src/test/resources/source.docx"; - private static final String DEST_DOCX_PATH = "/Users//Desktop/test-processed.docx"; - // private static final String DEST_DOCX_PATH = "C:/Users//Desktop/test-processed.docx"; + private static final String DEST_DOCX_PATH = "target/test-processed.docx"; @Test - // Unignore to execute and test this; - // but don't check this into git without ignore! - @Ignore public void processDocxTest() { Map placeholderMap = new HashMap<>(); - // Line breaks works as well placeholderMap.put("${NAME}", "Philipp"); placeholderMap.put("${SURNAME}", "Schuster"); placeholderMap.put("${PLACE_OF_BIRTH}", "GERMANY"); try { - // this max take 4 seconds but this happens only once (internal heatup of data structures) + // this max take 4 seconds but this happens only once (internal heatup of data + // structures) // https://stackoverflow.com/questions/18975049/how-to-decrease-docx4j-load-time WordprocessingMLPackage sourceDocxDoc = WordprocessingMLPackage.load(new File(SOURCE_DOCX_PATH)); @@ -71,6 +63,4 @@ public void processDocxTest() { Assert.fail("Exception occurred!"); } } - - -} \ No newline at end of file +} diff --git a/src/test/java/de/phip1611/StringFindUtilTest.java b/src/test/java/de/phip1611/StringFindUtilTest.java index e71dd48..903b7f1 100644 --- a/src/test/java/de/phip1611/StringFindUtilTest.java +++ b/src/test/java/de/phip1611/StringFindUtilTest.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2020 Philipp Schuster (phip1611@gmail.com) + * Copyright (c) 2023 Philipp Schuster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal