diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000..a108a019 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,4 @@ +mapstruct-on-bazel/bazel-bin +mapstruct-on-bazel/bazel-out +mapstruct-on-bazel/bazel-testlogs +mapstruct-on-bazel/bazel-mapstruct-on-bazel diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..7898f976 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,96 @@ +name: CI + +on: [push, pull_request] + +env: + MAVEN_ARGS: >- + -V -B --no-transfer-progress + -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 + +jobs: + linux_maven: + strategy: + fail-fast: false + matrix: + java: [8, 11, 17, 21] + name: 'Linux JDK ${{ matrix.java }} Maven' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v4 + - name: 'Set up JDK' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: ${{ matrix.java }} + - name: 'Test' + run: ./mvnw ${MAVEN_ARGS} -U clean verify + linux_gradle: + strategy: + fail-fast: false + matrix: + java: [8, 11, 17, 21] + name: 'Linux JDK ${{ matrix.java }} Gradle' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v4 + - name: 'Set up JDK' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: ${{ matrix.java }} + - name: 'Test' + run: ./gradlew buildAll + windows_maven: + name: 'Windows' + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: 'Set up JDK 8' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - name: 'Test' + run: ./mvnw ${MAVEN_ARGS} -U clean verify + mac_maven: + name: 'Mac OS' + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: 'Set up JDK 8' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - name: 'Test' + run: ./mvnw ${MAVEN_ARGS} -U clean verify + linux_bazel: + strategy: + fail-fast: false + matrix: + java: [11, 17, 21] + name: 'Linux JDK ${{ matrix.java }} Bazel' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: ${{ matrix.java }} + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.18.0 + with: + # Avoid downloading Bazel every time. + bazelisk-cache: true + # Store build cache per workflow. + disk-cache: ${{ github.workflow }} + # Share repository cache between workflows. + repository-cache: true + - name: Test + run: bazelisk test //... + - name: Build + run: bazelisk build //... diff --git a/.gitignore b/.gitignore index c602080e..6ef8429b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,13 @@ target test-output /*/build +/*/*/build /*/bin +/*/out +/*/*/out # Gradle .gradle + +# Bazel +**/bazel-* \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..8dea6c22 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 32ae4287..00000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: java - -sudo: false -dist: trusty - -install: true - -matrix: - include: - - jdk: openjdk8 - - jdk: oraclejdk8 - - jdk: openjdk10 - # For some reason pulling from sonatype_snapshots does not work for openjdk10 and we have to manually symlink - # See https://github.com/travis-ci/travis-ci/issues/9368#issuecomment-405070163 - before_install: - - rm "${JAVA_HOME}/lib/security/cacerts" - - ln -s /etc/ssl/certs/java/cacerts "${JAVA_HOME}/lib/security/cacerts" - - jdk: openjdk11 - - jdk: openjdk-ea - allow_failures: - - jdk: openjdk-ea - -script: mvn clean verify -B -V -U - -cache: - directories: - - $HOME/.m2 diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..098eae1e --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,2 @@ +# Root BUILD file for mapstruct-examples +# The actual Bazel build is in the mapstruct-on-bazel subdirectory diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..13954602 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,19 @@ +module( + name = "mapstruct-examples", + version = "1.0.0", +) + +bazel_dep(name = "rules_java", version = "8.14.0") +bazel_dep(name = "rules_jvm_external", version = "6.6") + +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") + +maven.install( + artifacts = [ + "org.mapstruct:mapstruct:1.7.0.Beta1", + "org.mapstruct:mapstruct-processor:1.7.0.Beta1", + "junit:junit:4.13.2", + "org.assertj:assertj-core:3.27.7", + ], +) +use_repo(maven, "maven") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock new file mode 100644 index 00000000..8fb08990 --- /dev/null +++ b/MODULE.bazel.lock @@ -0,0 +1,207 @@ +{ + "lockFileVersion": 24, + "registryFileHashes": { + "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", + "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589", + "https://bcr.bazel.build/modules/abseil-cpp/20230125.1/MODULE.bazel": "89047429cb0207707b2dface14ba7f8df85273d484c2572755be4bab7ce9c3a0", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.0.bcr.1/MODULE.bazel": "1c8cec495288dccd14fdae6e3f95f772c1c91857047a098fad772034264cc8cb", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.0/MODULE.bazel": "d253ae36a8bd9ee3c5955384096ccb6baf16a1b1e93e858370da0a3b94f77c16", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.1/MODULE.bazel": "fa92e2eb41a04df73cdabeec37107316f7e5272650f81d6cc096418fe647b915", + "https://bcr.bazel.build/modules/abseil-cpp/20240116.1/MODULE.bazel": "37bcdb4440fbb61df6a1c296ae01b327f19e9bb521f9b8e26ec854b6f97309ed", + "https://bcr.bazel.build/modules/abseil-cpp/20240116.1/source.json": "9be551b8d4e3ef76875c0d744b5d6a504a27e3ae67bc6b28f46415fd2d2957da", + "https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", + "https://bcr.bazel.build/modules/bazel_features/1.15.0/MODULE.bazel": "d38ff6e517149dc509406aca0db3ad1efdd890a85e049585b7234d04238e2a4d", + "https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d", + "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", + "https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", + "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", + "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", + "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", + "https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", + "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.2/MODULE.bazel": "3bd40978e7a1fac911d5989e6b09d8f64921865a45822d8b09e815eaa726a651", + "https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953", + "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", + "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", + "https://bcr.bazel.build/modules/google_benchmark/1.8.2/MODULE.bazel": "a70cf1bba851000ba93b58ae2f6d76490a9feb74192e57ab8e8ff13c34ec50cb", + "https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4", + "https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/MODULE.bazel": "22c31a561553727960057361aa33bf20fb2e98584bc4fec007906e27053f80c6", + "https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/source.json": "41e9e129f80d8c8bf103a7acc337b76e54fad1214ac0a7084bf24f4cd924b8b4", + "https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f", + "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075", + "https://bcr.bazel.build/modules/jsoncpp/1.9.5/source.json": "4108ee5085dd2885a341c7fab149429db457b3169b86eb081fa245eadf69169d", + "https://bcr.bazel.build/modules/libpfm/4.11.0/MODULE.bazel": "45061ff025b301940f1e30d2c16bea596c25b176c8b6b3087e92615adbd52902", + "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5", + "https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f", + "https://bcr.bazel.build/modules/platforms/0.0.11/source.json": "f7e188b79ebedebfe75e9e1d098b8845226c7992b307e28e1496f23112e8fc29", + "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", + "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37", + "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", + "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", + "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", + "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", + "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", + "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", + "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df", + "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e", + "https://bcr.bazel.build/modules/protobuf/29.0/source.json": "b857f93c796750eef95f0d61ee378f3420d00ee1dd38627b27193aa482f4f981", + "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", + "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e", + "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/source.json": "be4789e951dd5301282729fe3d4938995dc4c1a81c2ff150afc9f1b0504c6022", + "https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206", + "https://bcr.bazel.build/modules/re2/2023-09-01/source.json": "e044ce89c2883cd957a2969a43e79f7752f9656f6b20050b62f90ede21ec6eb4", + "https://bcr.bazel.build/modules/rules_android/0.1.1/MODULE.bazel": "48809ab0091b07ad0182defb787c4c5328bd3a278938415c00a7b69b50c4d3a8", + "https://bcr.bazel.build/modules/rules_android/0.1.1/source.json": "e6986b41626ee10bdc864937ffb6d6bf275bb5b9c65120e6137d56e6331f089e", + "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", + "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", + "https://bcr.bazel.build/modules/rules_cc/0.0.13/MODULE.bazel": "0e8529ed7b323dad0775ff924d2ae5af7640b23553dfcd4d34344c7e7a867191", + "https://bcr.bazel.build/modules/rules_cc/0.0.14/MODULE.bazel": "5e343a3aac88b8d7af3b1b6d2093b55c347b8eefc2e7d1442f7a02dc8fea48ac", + "https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc", + "https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87", + "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", + "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", + "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", + "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", + "https://bcr.bazel.build/modules/rules_cc/0.1.1/source.json": "d61627377bd7dd1da4652063e368d9366fc9a73920bfa396798ad92172cf645c", + "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", + "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", + "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/source.json": "c8b1e2c717646f1702290959a3302a178fb639d987ab61d548105019f11e527e", + "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74", + "https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86", + "https://bcr.bazel.build/modules/rules_java/6.0.0/MODULE.bazel": "8a43b7df601a7ec1af61d79345c17b31ea1fedc6711fd4abfd013ea612978e39", + "https://bcr.bazel.build/modules/rules_java/6.4.0/MODULE.bazel": "e986a9fe25aeaa84ac17ca093ef13a4637f6107375f64667a15999f77db6c8f6", + "https://bcr.bazel.build/modules/rules_java/6.5.2/MODULE.bazel": "1d440d262d0e08453fa0c4d8f699ba81609ed0e9a9a0f02cd10b3e7942e61e31", + "https://bcr.bazel.build/modules/rules_java/7.10.0/MODULE.bazel": "530c3beb3067e870561739f1144329a21c851ff771cd752a49e06e3dc9c2e71a", + "https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6", + "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", + "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", + "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", + "https://bcr.bazel.build/modules/rules_java/8.14.0/MODULE.bazel": "717717ed40cc69994596a45aec6ea78135ea434b8402fb91b009b9151dd65615", + "https://bcr.bazel.build/modules/rules_java/8.14.0/source.json": "8a88c4ca9e8759da53cddc88123880565c520503321e2566b4e33d0287a3d4bc", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", + "https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909", + "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", + "https://bcr.bazel.build/modules/rules_jvm_external/5.3/MODULE.bazel": "bf93870767689637164657731849fb887ad086739bd5d360d90007a581d5527d", + "https://bcr.bazel.build/modules/rules_jvm_external/6.1/MODULE.bazel": "75b5fec090dbd46cf9b7d8ea08cf84a0472d92ba3585b476f44c326eda8059c4", + "https://bcr.bazel.build/modules/rules_jvm_external/6.3/MODULE.bazel": "c998e060b85f71e00de5ec552019347c8bca255062c990ac02d051bb80a38df0", + "https://bcr.bazel.build/modules/rules_jvm_external/6.6/MODULE.bazel": "153042249c7060536dc95b6bb9f9bb8063b8a0b0cb7acdb381bddbc2374aed55", + "https://bcr.bazel.build/modules/rules_jvm_external/6.6/source.json": "b1d7ffc3877e5a76e6e48e6bce459cbb1712c90eba14861b112bd299587a534d", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.0/MODULE.bazel": "ef85697305025e5a61f395d4eaede272a5393cee479ace6686dba707de804d59", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel": "d269a01a18ee74d0335450b10f62c9ed81f2321d7958a2934e44272fe82dcef3", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/source.json": "2faa4794364282db7c06600b7e5e34867a564ae91bda7cae7c29c64e9466b7d5", + "https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0", + "https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d", + "https://bcr.bazel.build/modules/rules_license/1.0.0/MODULE.bazel": "a7fda60eefdf3d8c827262ba499957e4df06f659330bbe6cdbdb975b768bb65c", + "https://bcr.bazel.build/modules/rules_license/1.0.0/source.json": "a52c89e54cc311196e478f8382df91c15f7a2bfdf4c6cd0e2675cc2ff0b56efb", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", + "https://bcr.bazel.build/modules/rules_pkg/1.0.1/MODULE.bazel": "5b1df97dbc29623bccdf2b0dcd0f5cb08e2f2c9050aab1092fd39a41e82686ff", + "https://bcr.bazel.build/modules/rules_pkg/1.0.1/source.json": "bd82e5d7b9ce2d31e380dd9f50c111d678c3bdaca190cb76b0e1c71b05e1ba8a", + "https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7", + "https://bcr.bazel.build/modules/rules_proto/6.0.2/MODULE.bazel": "ce916b775a62b90b61888052a416ccdda405212b6aaeb39522f7dc53431a5e73", + "https://bcr.bazel.build/modules/rules_proto/7.0.2/MODULE.bazel": "bf81793bd6d2ad89a37a40693e56c61b0ee30f7a7fdbaf3eabbf5f39de47dea2", + "https://bcr.bazel.build/modules/rules_proto/7.0.2/source.json": "1e5e7260ae32ef4f2b52fd1d0de8d03b606a44c91b694d2f1afb1d3b28a48ce1", + "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f", + "https://bcr.bazel.build/modules/rules_python/0.23.1/MODULE.bazel": "49ffccf0511cb8414de28321f5fcf2a31312b47c40cc21577144b7447f2bf300", + "https://bcr.bazel.build/modules/rules_python/0.25.0/MODULE.bazel": "72f1506841c920a1afec76975b35312410eea3aa7b63267436bfb1dd91d2d382", + "https://bcr.bazel.build/modules/rules_python/0.28.0/MODULE.bazel": "cba2573d870babc976664a912539b320cbaa7114cd3e8f053c720171cde331ed", + "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", + "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", + "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", + "https://bcr.bazel.build/modules/rules_python/0.40.0/source.json": "939d4bd2e3110f27bfb360292986bb79fd8dcefb874358ccd6cdaa7bda029320", + "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", + "https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b", + "https://bcr.bazel.build/modules/rules_shell/0.3.0/source.json": "c55ed591aa5009401ddf80ded9762ac32c358d2517ee7820be981e2de9756cf3", + "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", + "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", + "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", + "https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c", + "https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7", + "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", + "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806", + "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198" + }, + "selectedYankedVersions": {}, + "moduleExtensions": { + "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { + "general": { + "bzlTransitiveDigest": "rL/34P1aFDq2GqVC2zCFgQ8nTuOC6ziogocpvG50Qz8=", + "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "com_github_jetbrains_kotlin_git": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_compiler_git_repository", + "attributes": { + "urls": [ + "https://github.com/JetBrains/kotlin/releases/download/v1.9.23/kotlin-compiler-1.9.23.zip" + ], + "sha256": "93137d3aab9afa9b27cb06a824c2324195c6b6f6179d8a8653f440f5bd58be88" + } + }, + "com_github_jetbrains_kotlin": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_capabilities_repository", + "attributes": { + "git_repository_name": "com_github_jetbrains_kotlin_git", + "compiler_version": "1.9.23" + } + }, + "com_github_google_ksp": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:ksp.bzl%ksp_compiler_plugin_repository", + "attributes": { + "urls": [ + "https://github.com/google/ksp/releases/download/1.9.23-1.0.20/artifacts.zip" + ], + "sha256": "ee0618755913ef7fd6511288a232e8fad24838b9af6ea73972a76e81053c8c2d", + "strip_version": "1.9.23-1.0.20" + } + }, + "com_github_pinterest_ktlint": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_file", + "attributes": { + "sha256": "01b2e0ef893383a50dbeb13970fe7fa3be36ca3e83259e01649945b09d736985", + "urls": [ + "https://github.com/pinterest/ktlint/releases/download/1.3.0/ktlint" + ], + "executable": true + } + }, + "rules_android": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "sha256": "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", + "strip_prefix": "rules_android-0.1.1", + "urls": [ + "https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip" + ] + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_kotlin+", + "bazel_tools", + "bazel_tools" + ] + ] + } + } + }, + "facts": {} +} diff --git a/README.md b/README.md index a4c146f5..ec6b2df2 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,27 @@ This repository contains examples showing how to use [MapStruct](http://mapstruc Currently, the following examples exist: -* _mapstruct-on-ant_: Shows how to use MapStruct in Ant-based projects; to build this example, run `ant build` on the command line -* _mapstruct-on-gradle_: Shows how to use MapStruct in Gradle-based projects; to build the example project, run `./gradlew clean build` on the command line -* _mapstruct-lombok_: Shows how to use MapStruct together with Lombok (with both a Maven `pom.xml` and a Gradle `build.gradle`); to build the example project, run either `mvn clean install` or `./gradlew clean build` on the command line -* _mapstruct-iterable-non-iterable_: Shows how by means of a mapper util class conversions can be made from an iterable- to its non-iterable element -* _mapstruct-mapping-from-map_: Shows how by means of a mapper util class and qualifiers extracting value can be carried out on Maps. Watch [mapstruct/mapstruct#1075](https://github.com/mapstruct/mapstruct/issues/1075) for native support. -* _mapstruct-rounding_: Shows how by means of a mapper util class and qualifiers roundings can be carried out on Numbers -* _mapstruct-examples-updatemethods-1_: Shows how to update an existing target object -* _mapstruct-examples-field-mapping_: Shows how MapStruct can be used with "struct" like objects with public fields -* _mapstruct-nested-bean-mappings_: Shows how to map object graphs via a main root method -* _mapstruct-mapping-with-cycles_: Shows how to map object graphs that can contain cycles -* _mapstruct-spi-accessor-naming_: Example on how to use the Service Provider Interface (SPI) for a custom accessor naming strategy. -* _mapstruct-protobuf3_: Example on how to use protobuf3 with MapStruct -* _mapstruct-kotlin_: Example on how to use MapStruct with Kotlin using KAPT (Kotlin Annotation Processing Tool) -* _mapstruct-jpa-parent-child_: Example on how to use @Context in relation to parent / child relations in JPA) -* _mapstruct-lookup-entity-with-composed-key_: Shows how an object with composite key can be read from the database in a mapping method. +* [_mapstruct-on-ant_](mapstruct-on-ant): Shows how to use MapStruct in Ant-based projects; to build this example, run `ant build` on the command line +* [_mapstruct-on-gradle_](mapstruct-on-gradle): Shows how to use MapStruct in Gradle-based projects; to build the example project, run `./gradlew clean build` on the command line +* [_mapstruct-on-bazel_](mapstruct-on-bazel): Shows how to use MapStruct in Bazel-based projects; to build the example project, run `bazel build //...` on the command line, to test the project, run `bazel test //...`. +* [_mapstruct-lombok_](mapstruct-lombok): Shows how to use MapStruct together with Lombok (with both a Maven `pom.xml` and a Gradle `build.gradle`); to build the example project, run either `mvn clean install` or `./gradlew clean build` on the command line +* [_mapstruct-iterable-non-iterable_](mapstruct-iterable-to-non-iterable): Shows how by means of a mapper util class conversions can be made from an iterable- to its non-iterable element +* [_mapstruct-mapping-from-map_](mapstruct-mapping-from-map): Shows how by means of a mapper util class and qualifiers extracting value can be carried out on Maps. Watch [mapstruct/mapstruct#1075](https://github.com/mapstruct/mapstruct/issues/1075) for native support. +* [_mapstruct-rounding_](mapstruct-rounding): Shows how by means of a mapper util class and qualifiers roundings can be carried out on Numbers +* [_mapstruct-updatemethods_](mapstruct-updatemethods-1): Shows how to update an existing target object +* [_mapstruct-field-mapping_](mapstruct-field-mapping): Shows how MapStruct can be used with "struct" like objects with public fields +* [_mapstruct-nested-bean-mappings_](mapstruct-nested-bean-mappings): Shows how to map object graphs via a main root method +* [_mapstruct-mapping-with-cycles_](mapstruct-nested-bean-mappings): Shows how to map object graphs that can contain cycles +* [_mapstruct-spi-accessor-naming_](mapstruct-spi-accessor-naming): Example on how to use the Service Provider Interface (SPI) for a custom accessor naming strategy. +* [_mapstruct-protobuf3_](mapstruct-protobuf3): Example on how to use protobuf3 with MapStruct +* [_mapstruct-kotlin_](mapstruct-kotlin): Example on how to use MapStruct with Kotlin using KAPT (Kotlin Annotation Processing Tool) +* [_mapstruct-kotlin-gradle_](mapstruct-kotlin-gradle): Example on how to use MapStruct with Kotlin and Gradle Kotlin DSL using KAPT +* [_mapstruct-jpa-child-parent_](mapstruct-jpa-child-parent): Example on how to use @Context in relation to parent / child relations in JPA) +* [_mapstruct-suppress-unmapped_](mapstruct-suppress-unmapped): Shows how mapping to target properties can be ignored without warning by default in a mixed scenario. However bean property mappings that have the same name will still be applied. +* [_mapstruct-lookup-entity-with-id_](mapstruct-lookup-entity-with-id): Shows how an object with composite key can be read from the database in a mapping method. +* [_mapstruct-clone_](mapstruct-clone): Shows how an object can be deeply cloned by defining all mapping methods. +* [_mapstruct-metadata-annotations_](mapstruct-metadata-with-annotations): Demonstrates how to read annotations and use them as mapping instruction. +* [_mapstruct-mappers-repo_](mapstruct-mapper-repo): Demonstrates how one can build a repo of mappers by means of code generation. ## License diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000..42d95e50 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,2 @@ +# This project has been migrated to Bzlmod (MODULE.bazel) +# The WORKSPACE file is kept for compatibility but is no longer actively used diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..f59c0a65 --- /dev/null +++ b/build.gradle @@ -0,0 +1,3 @@ +task buildAll { + dependsOn gradle.includedBuilds*.task(':build') +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..e708b1c0 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..db9a6b82 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..4f906e0c --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..107acd32 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/license.txt b/license.txt index f053dd8c..73ce4f8a 100644 --- a/license.txt +++ b/license.txt @@ -1,16 +1,3 @@ - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - The MapStruct Examples project is licensed under the Apache License, - Version 2.0 (the "License"); you may not use this software except in - compliance with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 diff --git a/mapstruct-clone/pom.xml b/mapstruct-clone/pom.xml new file mode 100644 index 00000000..fe7bc83c --- /dev/null +++ b/mapstruct-clone/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.mapstruct.examples.clone + mapstruct-deep-clone + 1.0.0 + + + UTF-8 + 1.7.0.Beta1 + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + junit + junit + 4.13.1 + test + + + + org.assertj + assertj-core + 3.27.7 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + diff --git a/mapstruct-clone/src/main/java/org/mapstruct/example/dto/CustomerDto.java b/mapstruct-clone/src/main/java/org/mapstruct/example/dto/CustomerDto.java new file mode 100644 index 00000000..3d3386e4 --- /dev/null +++ b/mapstruct-clone/src/main/java/org/mapstruct/example/dto/CustomerDto.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.dto; + +import java.util.List; +import java.util.Map; + +/** + * @author Sjaak Derksen + */ +public class CustomerDto { + + private Long id; + private String customerName; + private List orders; + private Map stock; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public List getOrders() { + return orders; + } + + public void setOrders(List orders) { + this.orders = orders; + } + + public Map getStock() { + return stock; + } + + public void setStock(Map stock) { + this.stock = stock; + } +} diff --git a/mapstruct-clone/src/main/java/org/mapstruct/example/dto/OrderItemDto.java b/mapstruct-clone/src/main/java/org/mapstruct/example/dto/OrderItemDto.java new file mode 100644 index 00000000..758c79f2 --- /dev/null +++ b/mapstruct-clone/src/main/java/org/mapstruct/example/dto/OrderItemDto.java @@ -0,0 +1,26 @@ +package org.mapstruct.example.dto; + +/** + * @author Sjaak Derksen + */ +public class OrderItemDto { + + private String name; + private Long quantity; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getQuantity() { + return quantity; + } + + public void setQuantity(Long quantity) { + this.quantity = quantity; + } +} diff --git a/mapstruct-clone/src/main/java/org/mapstruct/example/dto/OrderItemKeyDto.java b/mapstruct-clone/src/main/java/org/mapstruct/example/dto/OrderItemKeyDto.java new file mode 100644 index 00000000..1fd800a1 --- /dev/null +++ b/mapstruct-clone/src/main/java/org/mapstruct/example/dto/OrderItemKeyDto.java @@ -0,0 +1,17 @@ +package org.mapstruct.example.dto; + +/** + * @author Sjaak Derksen + */ +public class OrderItemKeyDto { + + private long stockNumber; + + public long getStockNumber() { + return stockNumber; + } + + public void setStockNumber(long stockNumber) { + this.stockNumber = stockNumber; + } +} diff --git a/mapstruct-clone/src/main/java/org/mapstruct/example/mapper/Cloner.java b/mapstruct-clone/src/main/java/org/mapstruct/example/mapper/Cloner.java new file mode 100644 index 00000000..4c3807d7 --- /dev/null +++ b/mapstruct-clone/src/main/java/org/mapstruct/example/mapper/Cloner.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; +import org.mapstruct.example.dto.CustomerDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + * + * By defining all methods, we force MapStruct to generate new objects for each mapper in stead of + * taking shortcuts by mapping an object directly. + */ +@Mapper(mappingControl = DeepClone.class) +public interface Cloner { + + Cloner MAPPER = Mappers.getMapper( Cloner.class ); + + CustomerDto clone(CustomerDto customerDto); +} diff --git a/mapstruct-clone/src/test/java/org/mapstruct/example/ClonerTest.java b/mapstruct-clone/src/test/java/org/mapstruct/example/ClonerTest.java new file mode 100644 index 00000000..3db410cd --- /dev/null +++ b/mapstruct-clone/src/test/java/org/mapstruct/example/ClonerTest.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.mapstruct.example.dto.CustomerDto; +import org.mapstruct.example.dto.OrderItemDto; +import org.mapstruct.example.dto.OrderItemKeyDto; +import org.mapstruct.example.mapper.Cloner; + +/** + * + * @author Sjaak Derksen + */ +public class ClonerTest { + + @Test + public void testMapDtoToEntity() { + + CustomerDto customerDto = new CustomerDto(); + customerDto.setId( 10L ); + customerDto.setCustomerName("Jaques" ); + OrderItemDto order1 = new OrderItemDto(); + order1.setName ("Table" ); + order1.setQuantity( 2L ); + customerDto.setOrders( new ArrayList<>( Collections.singleton( order1 ) ) ); + OrderItemKeyDto key = new OrderItemKeyDto(); + key.setStockNumber( 5 ); + Map stock = new HashMap( ); + stock.put( key, order1 ); + customerDto.setStock( stock ); + + CustomerDto customer = Cloner.MAPPER.clone( customerDto ); + + // check if cloned + assertThat( customer.getId() ).isEqualTo( 10 ); + assertThat( customer.getCustomerName() ).isEqualTo( "Jaques" ); + assertThat( customer.getOrders() ) + .extracting( "name", "quantity" ) + .containsExactly( tuple( "Table", 2L ) ); + assertThat( customer.getStock() ).isNotNull(); + assertThat( customer.getStock() ).hasSize( 1 ); + + Map.Entry entry = customer.getStock().entrySet().iterator().next(); + assertThat( entry.getKey().getStockNumber() ).isEqualTo( 5 ); + assertThat( entry.getValue().getName() ).isEqualTo( "Table" ); + assertThat( entry.getValue().getQuantity() ).isEqualTo( 2L ); + + // check mapper really created new objects + assertThat( customer ).isNotSameAs( customerDto ); + assertThat( customer.getOrders().get( 0 ) ).isNotEqualTo( order1 ); + assertThat( entry.getKey() ).isNotEqualTo( key ); + assertThat( entry.getValue() ).isNotEqualTo( order1 ); + assertThat( entry.getValue() ).isNotEqualTo( customer.getOrders().get( 0 ) ); + } +} diff --git a/mapstruct-field-mapping/pom.xml b/mapstruct-field-mapping/pom.xml index b8e0f718..d56f7a00 100644 --- a/mapstruct-field-mapping/pom.xml +++ b/mapstruct-field-mapping/pom.xml @@ -1,22 +1,9 @@ 1.0.0 - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -50,14 +38,14 @@ junit junit - 4.12 + 4.13.1 test org.assertj assertj-core - 3.6.2 + 3.27.7 test @@ -68,10 +56,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 - 1.7 - 1.7 + 1.8 + 1.8 org.mapstruct diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java index 92955700..3365a291 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/Customer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java index 7537a61d..630623dd 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/dto/CustomerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java index a939057a..869f28ec 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/CustomerMapper.java @@ -1,27 +1,13 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.Customer; import org.mapstruct.example.dto.CustomerDto; import org.mapstruct.factory.Mappers; @@ -34,10 +20,8 @@ public interface CustomerMapper { CustomerMapper MAPPER = Mappers.getMapper( CustomerMapper.class ); - @Mappings({ - @Mapping(source = "orders", target = "orderItems"), - @Mapping(source = "customerName", target = "name") - }) + @Mapping(target = "orderItems", source = "orders") + @Mapping(target = "name", source = "customerName") Customer toCustomer(CustomerDto customerDto); @InheritInverseConfiguration diff --git a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java index 43868eb1..16914a28 100644 --- a/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java +++ b/mapstruct-field-mapping/src/main/java/org/mapstruct/example/mapper/OrderItemMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; diff --git a/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java b/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java index 5aaf5f19..2c2aa2da 100644 --- a/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java +++ b/mapstruct-field-mapping/src/test/java/org/mapstruct/example/CustomerMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-iterable-to-non-iterable/pom.xml b/mapstruct-iterable-to-non-iterable/pom.xml index 4307b1b7..bf2c3293 100644 --- a/mapstruct-iterable-to-non-iterable/pom.xml +++ b/mapstruct-iterable-to-non-iterable/pom.xml @@ -1,22 +1,9 @@ @@ -26,8 +13,9 @@ 1.0-SNAPSHOT - 1.7 - 1.7 + UTF-8 + 1.8 + 1.8 @@ -35,20 +23,20 @@ org.mapstruct mapstruct - 1.3.0.Beta1 + 1.7.0.Beta1 org.mapstruct mapstruct-processor - 1.3.0.Beta1 + 1.7.0.Beta1 provided junit junit - 4.12 + 4.13.1 test @@ -60,7 +48,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 org.mapstruct.ap.MappingProcessor diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Main.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Main.java index 68659e45..4d26e920 100644 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Main.java +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Main.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Source.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Source.java index 47a2275c..d70abada 100644 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Source.java +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/SourceTargetMapper.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/SourceTargetMapper.java index a6547328..34401eba 100644 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/SourceTargetMapper.java +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/SourceTargetMapper.java @@ -1,40 +1,24 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; import com.mycompany.mapper.util.FirstElement; -import com.mycompany.mapper.util.IterableNonInterableUtil; +import com.mycompany.mapper.util.IterableNonIterableUtil; import com.mycompany.mapper.util.LastElement; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; -@Mapper( uses = IterableNonInterableUtil.class ) +@Mapper( uses = IterableNonIterableUtil.class ) public interface SourceTargetMapper { SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); - @Mappings( { - @Mapping( source = "myIntegers", target = "myInteger", qualifiedBy = FirstElement.class ), - @Mapping( source = "myStrings", target = "myString", qualifiedBy = LastElement.class ) - } ) + @Mapping( target = "myInteger", source = "myIntegers", qualifiedBy = FirstElement.class ) + @Mapping( target = "myString", source = "myStrings", qualifiedBy = LastElement.class ) Target toTarget( Source s ); } diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Target.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Target.java index 78604a19..1cfc37d4 100644 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Target.java +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/FirstElement.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/FirstElement.java index bd4461d6..8b2c59b9 100644 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/FirstElement.java +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/FirstElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper.util; diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/IterableNonInterableUtil.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/IterableNonInterableUtil.java deleted file mode 100644 index 82d8ab74..00000000 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/IterableNonInterableUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mycompany.mapper.util; - -import java.util.List; -//import org.mapstruct.ap.test.selection.qualifier.annotation.TitleTranslator; - -/** - * - * @author Sjaak Derksen - */ -public class IterableNonInterableUtil { - - @FirstElement - public T first( List in ) { - if ( in != null && !in.isEmpty() ) { - return in.get( 0 ); - } - else { - return null; - } - } - - @LastElement - public T last( List in ) { - if ( in != null && !in.isEmpty() ) { - return in.get( in.size() - 1 ); - } - else { - return null; - } - } - - -} diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/IterableNonIterableUtil.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/IterableNonIterableUtil.java new file mode 100644 index 00000000..1db01f88 --- /dev/null +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/IterableNonIterableUtil.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package com.mycompany.mapper.util; + +import java.util.List; +//import org.mapstruct.ap.test.selection.qualifier.annotation.TitleTranslator; + +/** + * + * @author Sjaak Derksen + */ +public class IterableNonIterableUtil { + + @FirstElement + public T first( List in ) { + if ( in != null && !in.isEmpty() ) { + return in.get( 0 ); + } + else { + return null; + } + } + + @LastElement + public T last( List in ) { + if ( in != null && !in.isEmpty() ) { + return in.get( in.size() - 1 ); + } + else { + return null; + } + } + + +} diff --git a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/LastElement.java b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/LastElement.java index 835cccd7..ed402416 100644 --- a/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/LastElement.java +++ b/mapstruct-iterable-to-non-iterable/src/main/java/com/mycompany/mapper/util/LastElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper.util; diff --git a/mapstruct-iterable-to-non-iterable/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java b/mapstruct-iterable-to-non-iterable/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java index dc2d77e3..07b5f1d4 100644 --- a/mapstruct-iterable-to-non-iterable/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java +++ b/mapstruct-iterable-to-non-iterable/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; diff --git a/mapstruct-jpa-child-parent/pom.xml b/mapstruct-jpa-child-parent/pom.xml index 926c59eb..7c3ddf2e 100644 --- a/mapstruct-jpa-child-parent/pom.xml +++ b/mapstruct-jpa-child-parent/pom.xml @@ -1,22 +1,9 @@ @@ -26,9 +13,10 @@ 1.0-SNAPSHOT - 1.3.0.Beta1 - 1.7 - 1.7 + UTF-8 + 1.7.0.Beta1 + 1.8 + 1.8 @@ -54,14 +42,14 @@ junit junit - 4.12 + 4.13.1 test org.assertj assertj-core - 3.9.0 + 3.27.7 test @@ -72,10 +60,8 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 - 1.7 - 1.7 org.mapstruct diff --git a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildDto.java b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildDto.java index 7b26873a..0fbea00d 100644 --- a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildDto.java +++ b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildEntity.java b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildEntity.java index bd9780da..f41fb0a3 100644 --- a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildEntity.java +++ b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ChildEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/JpaContext.java b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/JpaContext.java index 514269ee..3aecfd7b 100644 --- a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/JpaContext.java +++ b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/JpaContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentDto.java b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentDto.java index d427efb5..339ef89e 100644 --- a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentDto.java +++ b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentEntity.java b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentEntity.java index f349ae38..f6c5a38b 100644 --- a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentEntity.java +++ b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/ParentEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java index 02bc4dd5..2bb54a32 100644 --- a/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java +++ b/mapstruct-jpa-child-parent/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-jpa-child-parent/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java b/mapstruct-jpa-child-parent/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java index 4c57233d..4d6949b5 100644 --- a/mapstruct-jpa-child-parent/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java +++ b/mapstruct-jpa-child-parent/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-kotlin-gradle/build.gradle.kts b/mapstruct-kotlin-gradle/build.gradle.kts new file mode 100644 index 00000000..9aee9753 --- /dev/null +++ b/mapstruct-kotlin-gradle/build.gradle.kts @@ -0,0 +1,43 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.9.10" + kotlin("kapt") version "1.9.10" +} + +group = "org.mapstruct.examples" +version = "1.0.0-SNAPSHOT" + +java.sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8 + +repositories { + mavenCentral() +} + +dependencies { + implementation(kotlin("stdlib-jdk8")) + implementation("org.mapstruct:mapstruct:1.7.0.Beta1") + kapt("org.mapstruct:mapstruct-processor:1.7.0.Beta1") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.3.1") + testImplementation("org.assertj:assertj-core:3.11.1") +} + + +kapt { + arguments { + // Set Mapstruct Configuration options here + // https://kotlinlang.org/docs/reference/kapt.html#annotation-processor-arguments + // https://mapstruct.org/documentation/stable/reference/html/#configuration-options + // arg("mapstruct.defaultComponentModel", "spring") + } +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +val test by tasks.getting(Test::class) { + useJUnitPlatform { } +} diff --git a/mapstruct-kotlin-gradle/gradle/wrapper/gradle-wrapper.jar b/mapstruct-kotlin-gradle/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..e708b1c0 Binary files /dev/null and b/mapstruct-kotlin-gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/mapstruct-kotlin-gradle/gradle/wrapper/gradle-wrapper.properties b/mapstruct-kotlin-gradle/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..db9a6b82 --- /dev/null +++ b/mapstruct-kotlin-gradle/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/mapstruct-kotlin-gradle/gradlew b/mapstruct-kotlin-gradle/gradlew new file mode 100755 index 00000000..4f906e0c --- /dev/null +++ b/mapstruct-kotlin-gradle/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/mapstruct-kotlin-gradle/gradlew.bat b/mapstruct-kotlin-gradle/gradlew.bat new file mode 100644 index 00000000..107acd32 --- /dev/null +++ b/mapstruct-kotlin-gradle/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/mapstruct-kotlin-gradle/settings.gradle b/mapstruct-kotlin-gradle/settings.gradle new file mode 100644 index 00000000..26a174d5 --- /dev/null +++ b/mapstruct-kotlin-gradle/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'mapstruct-kotlin-gradle' + diff --git a/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/Main.kt b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/Main.kt new file mode 100644 index 00000000..d381262b --- /dev/null +++ b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/Main.kt @@ -0,0 +1,20 @@ +package org.mapstruct.example.kotlin + +import org.mapstruct.example.kotlin.converter.PersonConverter +import org.mapstruct.example.kotlin.model.Person +import org.mapstruct.factory.Mappers +import java.time.LocalDate + +fun main(args: Array) { + + val converter = Mappers.getMapper(PersonConverter::class.java) // or PersonConverterImpl() + + val person = Person("Samuel", "Jackson", "0123 334466", LocalDate.of(1948, 12, 21)) + + val personDto = converter.convertToDto(person) + println(personDto) + + val personModel = converter.convertToModel(personDto) + println(personModel) + +} diff --git a/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt new file mode 100644 index 00000000..4f009cec --- /dev/null +++ b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt @@ -0,0 +1,18 @@ +package org.mapstruct.example.kotlin.converter + +import org.mapstruct.InheritInverseConfiguration +import org.mapstruct.Mapper +import org.mapstruct.Mapping +import org.mapstruct.example.kotlin.dto.PersonDto +import org.mapstruct.example.kotlin.model.Person + +@Mapper +interface PersonConverter { + + @Mapping(target = "phone", source = "phoneNumber") + fun convertToDto(person: Person): PersonDto + + @InheritInverseConfiguration + fun convertToModel(personDto: PersonDto): Person + +} diff --git a/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt new file mode 100644 index 00000000..c6080361 --- /dev/null +++ b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt @@ -0,0 +1,5 @@ +package org.mapstruct.example.kotlin.dto + +import java.time.LocalDate + +data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) diff --git a/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt new file mode 100644 index 00000000..ca3ad1ef --- /dev/null +++ b/mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt @@ -0,0 +1,5 @@ +package org.mapstruct.example.kotlin.model + +import java.time.LocalDate + +data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) diff --git a/mapstruct-kotlin-gradle/src/test/kotlin/org/mapstruct/example/kotlin/converter/PersonConverterTest.kt b/mapstruct-kotlin-gradle/src/test/kotlin/org/mapstruct/example/kotlin/converter/PersonConverterTest.kt new file mode 100644 index 00000000..8a5875d9 --- /dev/null +++ b/mapstruct-kotlin-gradle/src/test/kotlin/org/mapstruct/example/kotlin/converter/PersonConverterTest.kt @@ -0,0 +1,40 @@ +package org.mapstruct.example.kotlin.converter + +import org.mapstruct.example.kotlin.dto.PersonDto +import org.mapstruct.example.kotlin.model.Person + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mapstruct.factory.Mappers +import java.time.LocalDate + +class PersonConverterTest { + + @Test + fun testConvertToDto() { + val converter = Mappers.getMapper(PersonConverter::class.java) + + val person = Person("Samuel", "Jackson", "0123 334466", LocalDate.of(1948, 12, 21)) + + val personDto = converter.convertToDto(person) + assertThat(personDto).isNotNull + assertThat(personDto.firstName).isEqualTo("Samuel") + assertThat(personDto.lastName).isEqualTo("Jackson") + assertThat(personDto.phone).isEqualTo("0123 334466") + assertThat(personDto.birthdate).isEqualTo(LocalDate.of(1948, 12, 21)) + } + + @Test + fun testConvertToModel() { + val converter = Mappers.getMapper(PersonConverter::class.java) + + val personDto = PersonDto("Samuel", "Jackson", "0123 334466", LocalDate.of(1948, 12, 21)) + + val person = converter.convertToModel(personDto) + assertThat(person).isNotNull + assertThat(person.firstName).isEqualTo("Samuel") + assertThat(person.lastName).isEqualTo("Jackson") + assertThat(person.phoneNumber).isEqualTo("0123 334466") + assertThat(person.birthdate).isEqualTo(LocalDate.of(1948, 12, 21)) + } +} diff --git a/mapstruct-kotlin/README.md b/mapstruct-kotlin/README.md index 20f2d2d8..15c954ee 100644 --- a/mapstruct-kotlin/README.md +++ b/mapstruct-kotlin/README.md @@ -7,17 +7,11 @@ Example usage of MapStruct and Kotlin with JDK-8 Bytecode. This is achieved by u In this example we want to map between a Person (Model) and a PersonDto (DTO). ```kotlin -data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) { - // Necessary for MapStruct - constructor() : this(null, null, null, null) -} +data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) ``` ```kotlin -data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) { - // Necessary for MapStruct - constructor() : this(null, null, null, null) -} +data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) ``` The MapStruct converter: @@ -26,7 +20,7 @@ The MapStruct converter: @Mapper interface PersonConverter { - @Mapping(source = "phoneNumber", target = "phone") + @Mapping(target = "phone", source = "phoneNumber") fun convertToDto(person: Person) : PersonDto @InheritInverseConfiguration @@ -74,12 +68,12 @@ Kotlin: https://kotlinlang.org/ ## Maven Setup -Add `mapstruct-jdk8` to your dependencies +Add `mapstruct` to your dependencies ```xml org.mapstruct - mapstruct-jdk8 + mapstruct ${mapstruct.version} ``` diff --git a/mapstruct-kotlin/pom.xml b/mapstruct-kotlin/pom.xml index f046641b..6919a6a3 100644 --- a/mapstruct-kotlin/pom.xml +++ b/mapstruct-kotlin/pom.xml @@ -9,20 +9,18 @@ 1.0.0-SNAPSHOT jar - Sample application demonstration the use of MapStruct and Kotlin - UTF-8 - 1.2.51 + 2.3.0 1.8 - 1.3.0.Beta1 + 1.7.0.Beta1 org.mapstruct - mapstruct-jdk8 + mapstruct ${mapstruct.version} @@ -40,13 +38,13 @@ junit junit - 4.12 + 4.13.1 test org.assertj assertj-core - 3.8.0 + 3.27.7 test @@ -77,6 +75,11 @@ mapstruct-processor ${mapstruct.version} + + org.jetbrains.kotlin + kotlin-metadata-jvm + ${kotlin.version} + @@ -100,7 +103,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 none ${kotlin.compiler.jvmTarget} diff --git a/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt b/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt index 9f9186cc..4f009cec 100644 --- a/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt +++ b/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/converter/PersonConverter.kt @@ -9,7 +9,7 @@ import org.mapstruct.example.kotlin.model.Person @Mapper interface PersonConverter { - @Mapping(source = "phoneNumber", target = "phone") + @Mapping(target = "phone", source = "phoneNumber") fun convertToDto(person: Person): PersonDto @InheritInverseConfiguration diff --git a/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt b/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt index c42402da..c6080361 100644 --- a/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt +++ b/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt @@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.dto import java.time.LocalDate -data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) { - - // Necessary for MapStruct - constructor() : this(null, null, null, null) - -} +data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) diff --git a/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt b/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt index af6086b3..ca3ad1ef 100644 --- a/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt +++ b/mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt @@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.model import java.time.LocalDate -data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) { - - // Necessary for MapStruct - constructor() : this(null, null, null, null) - -} +data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) diff --git a/mapstruct-lombok/build.gradle b/mapstruct-lombok/build.gradle index 3d7f5700..67efc56c 100644 --- a/mapstruct-lombok/build.gradle +++ b/mapstruct-lombok/build.gradle @@ -1,6 +1,5 @@ plugins { id 'java' - id 'net.ltgt.apt' version '0.9' } repositories { @@ -8,19 +7,22 @@ repositories { mavenLocal() } -task wrapper(type: Wrapper) { - gradleVersion = '3.4' -} - ext { - mapstructVersion = "1.3.0.Beta1" - lombokVersion = "1.18.0" + mapstructVersion = "1.7.0.Beta1" + lombokVersion = "1.18.30" + lombokMapstructBindingVersion = "0.2.0" } sourceCompatibility = JavaVersion.VERSION_1_8 dependencies { - compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}" - testCompile 'junit:junit:4.12' - apt "org.mapstruct:mapstruct-processor:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}" + implementation "org.mapstruct:mapstruct:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}" + testImplementation 'junit:junit:4.13.1' + + /* + this example uses lombok directly over the annotationProcessor, + the io.freefair.lombok plugin works as well. + The freefair-lombok plugin is used in the example mapstruct-on-gradle-testcp-with-lombok + */ + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}", "org.projectlombok:lombok-mapstruct-binding:${lombokMapstructBindingVersion}" } diff --git a/mapstruct-lombok/gradle/wrapper/gradle-wrapper.jar b/mapstruct-lombok/gradle/wrapper/gradle-wrapper.jar index 05ef575b..e708b1c0 100644 Binary files a/mapstruct-lombok/gradle/wrapper/gradle-wrapper.jar and b/mapstruct-lombok/gradle/wrapper/gradle-wrapper.jar differ diff --git a/mapstruct-lombok/gradle/wrapper/gradle-wrapper.properties b/mapstruct-lombok/gradle/wrapper/gradle-wrapper.properties index 6b3ef346..db9a6b82 100644 --- a/mapstruct-lombok/gradle/wrapper/gradle-wrapper.properties +++ b/mapstruct-lombok/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Feb 25 23:47:27 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip diff --git a/mapstruct-lombok/gradlew b/mapstruct-lombok/gradlew index 9d82f789..4f906e0c 100755 --- a/mapstruct-lombok/gradlew +++ b/mapstruct-lombok/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,28 +75,14 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -85,7 +106,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -105,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -134,27 +156,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/mapstruct-lombok/gradlew.bat b/mapstruct-lombok/gradlew.bat index 8a0b282a..107acd32 100644 --- a/mapstruct-lombok/gradlew.bat +++ b/mapstruct-lombok/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,20 +24,23 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,34 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/mapstruct-lombok/pom.xml b/mapstruct-lombok/pom.xml index ccce4906..f29a0a4a 100644 --- a/mapstruct-lombok/pom.xml +++ b/mapstruct-lombok/pom.xml @@ -1,22 +1,9 @@ @@ -29,37 +16,42 @@ jar UTF-8 - 1.7 - 1.7 - 1.3.0.Beta1 - 1.18.0 + 1.8 + 1.8 + 1.7.0.Beta1 + 1.18.30 + 0.2.0 - - org.projectlombok - lombok - ${org.projectlombok.version} - provided - org.mapstruct mapstruct ${org.mapstruct.version} + + + org.projectlombok + lombok + ${org.projectlombok.version} + provided + + + + junit junit test - 4.12 + 4.13.1 @@ -69,7 +61,35 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 + + 1.8 + 1.8 + + + + + + + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + org.projectlombok + lombok + ${org.projectlombok.version} + + + org.projectlombok + lombok-mapstruct-binding + ${lombok-mapstruct-binding.version} + + + diff --git a/mapstruct-lombok/settings.gradle b/mapstruct-lombok/settings.gradle new file mode 100644 index 00000000..ea5c17eb --- /dev/null +++ b/mapstruct-lombok/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'mapstruct-lombok' diff --git a/mapstruct-lombok/src/main/java/com/mycompany/dto/Source.java b/mapstruct-lombok/src/main/java/com/mycompany/dto/Source.java index c4aada7a..dc4f0cd9 100644 --- a/mapstruct-lombok/src/main/java/com/mycompany/dto/Source.java +++ b/mapstruct-lombok/src/main/java/com/mycompany/dto/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.dto; diff --git a/mapstruct-lombok/src/main/java/com/mycompany/entities/Target.java b/mapstruct-lombok/src/main/java/com/mycompany/entities/Target.java index afc3d0c5..223a8860 100644 --- a/mapstruct-lombok/src/main/java/com/mycompany/entities/Target.java +++ b/mapstruct-lombok/src/main/java/com/mycompany/entities/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.entities; diff --git a/mapstruct-lombok/src/main/java/com/mycompany/mapper/Main.java b/mapstruct-lombok/src/main/java/com/mycompany/mapper/Main.java index 1956327c..a8fd6b3d 100644 --- a/mapstruct-lombok/src/main/java/com/mycompany/mapper/Main.java +++ b/mapstruct-lombok/src/main/java/com/mycompany/mapper/Main.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; diff --git a/mapstruct-lombok/src/main/java/com/mycompany/mapper/SourceTargetMapper.java b/mapstruct-lombok/src/main/java/com/mycompany/mapper/SourceTargetMapper.java index 33cc99c1..bf3ae459 100644 --- a/mapstruct-lombok/src/main/java/com/mycompany/mapper/SourceTargetMapper.java +++ b/mapstruct-lombok/src/main/java/com/mycompany/mapper/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; @@ -30,6 +17,6 @@ public interface SourceTargetMapper { SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); - @Mapping( source = "test", target = "testing" ) + @Mapping( target = "testing", source = "test" ) Target toTarget( Source s ); } diff --git a/mapstruct-lombok/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java b/mapstruct-lombok/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java index 49f57c15..4110d79e 100644 --- a/mapstruct-lombok/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java +++ b/mapstruct-lombok/src/test/java/com/mycompany/mapper/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package com.mycompany.mapper; diff --git a/mapstruct-lookup-entity-with-id/pom.xml b/mapstruct-lookup-entity-with-id/pom.xml index 52db1309..b7b7e946 100644 --- a/mapstruct-lookup-entity-with-id/pom.xml +++ b/mapstruct-lookup-entity-with-id/pom.xml @@ -1,22 +1,9 @@ @@ -26,7 +13,8 @@ 1.0-SNAPSHOT - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 @@ -38,7 +26,7 @@ org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -52,14 +40,14 @@ junit junit - 4.12 + 4.13.1 test org.assertj assertj-core - 3.9.0 + 3.27.7 test @@ -70,7 +58,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 1.8 1.8 diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ArticleRepository.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ArticleRepository.java index 1fea0b5d..139e7e93 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ArticleRepository.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ArticleRepository.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/CombinedOfferingEntity.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/CombinedOfferingEntity.java index 03cfc991..77660458 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/CombinedOfferingEntity.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/CombinedOfferingEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ComposedKey.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ComposedKey.java index 3e1bab20..65ae07a5 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ComposedKey.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ComposedKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Entity.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Entity.java index a52c784d..e9e34bb4 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Entity.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Entity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java index cd187f5c..e2cd10ff 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ToothPaste.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ToothPaste.java index 692a4b34..43ded1d9 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ToothPaste.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/ToothPaste.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Toothbrush.java b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Toothbrush.java index 01a71ffc..59f667e1 100644 --- a/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Toothbrush.java +++ b/mapstruct-lookup-entity-with-id/src/main/java/org/mapstruct/jpa/Toothbrush.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-lookup-entity-with-id/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java b/mapstruct-lookup-entity-with-id/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java index 8e760cca..dfde755d 100644 --- a/mapstruct-lookup-entity-with-id/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java +++ b/mapstruct-lookup-entity-with-id/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.jpa; diff --git a/mapstruct-mapper-repo/example/pom.xml b/mapstruct-mapper-repo/example/pom.xml new file mode 100755 index 00000000..96735a69 --- /dev/null +++ b/mapstruct-mapper-repo/example/pom.xml @@ -0,0 +1,66 @@ + + 4.0.0 + repo-example + + + org.mapstruct.examples.repo + repo + 0.0.1-SNAPSHOT + .. + + + + UTF-8 + + + + + + org.mapstruct.examples.repo + repo-generator + + + + org.mapstruct + mapstruct + + + + org.mapstruct + mapstruct-processor + + + + junit + junit + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + org.mapstruct.examples.repo + repo-generator + ${project.version} + + + + + + + + \ No newline at end of file diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Boss.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Boss.java new file mode 100755 index 00000000..1ff06bc0 --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Boss.java @@ -0,0 +1,91 @@ +/** + * + */ +package org.mapstruct.example.repo.domain; + +/** + * @author jucheme + * + */ +public class Boss { + + private String name; + private String title; + private String address; + private Long age; + + public Boss() { + + } + + /** + * Construct! + * + * @param name + * @param address + * @param age + */ + public Boss(String name, String title, String address, Long age) { + super(); + this.name = name; + this.title = title; + this.address = address; + this.age = age; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the address + */ + public String getAddress() { + return address; + } + /** + * @param address + * the address to set + */ + public void setAddress(String address) { + this.address = address; + } + /** + * @return the age + */ + public Long getAge() { + return age; + } + /** + * @param age + * the age to set + */ + public void setAge(Long age) { + this.age = age; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title + * the title to set + */ + public void setTitle(String title) { + this.title = title; + } + +} diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Car.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Car.java new file mode 100755 index 00000000..9a4c6e23 --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Car.java @@ -0,0 +1,78 @@ +/** + * + */ +package org.mapstruct.example.repo.domain; + +/** + * @author jucheme + * + */ +public class Car { + + private String make; + private int numberOfSeats; + private CarType type; + + /** + * Construct! + * + */ + public Car() { + + } + + /** + * Construct! + * + * @param make + * @param numberOfSeats + * @param type + */ + public Car(String make, int numberOfSeats, CarType type) { + super(); + this.make = make; + this.numberOfSeats = numberOfSeats; + this.type = type; + } + + /** + * @return the make + */ + public String getMake() { + return make; + } + /** + * @param make + * the make to set + */ + public void setMake(String make) { + this.make = make; + } + /** + * @return the numberOfSeats + */ + public int getNumberOfSeats() { + return numberOfSeats; + } + /** + * @param numberOfSeats + * the numberOfSeats to set + */ + public void setNumberOfSeats(int numberOfSeats) { + this.numberOfSeats = numberOfSeats; + } + /** + * @return the type + */ + public CarType getType() { + return type; + } + /** + * @param type + * the type to set + */ + public void setType(CarType type) { + this.type = type; + } + +} diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/CarDto.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/CarDto.java new file mode 100755 index 00000000..a8d2a12b --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/CarDto.java @@ -0,0 +1,78 @@ +/** + * + */ +package org.mapstruct.example.repo.domain; + +/** + * @author jucheme + * + */ +public class CarDto { + + private String make; + private int seatCount; + private String type; + + /** + * Construct! + * + */ + public CarDto() { + + } + + /** + * Construct! + * + * @param make + * @param seatCount + * @param type + */ + public CarDto(String make, int seatCount, String type) { + super(); + this.make = make; + this.seatCount = seatCount; + this.type = type; + } + + /** + * @return the make + */ + public String getMake() { + return make; + } + /** + * @param make + * the make to set + */ + public void setMake(String make) { + this.make = make; + } + /** + * @return the seatCount + */ + public int getSeatCount() { + return seatCount; + } + /** + * @param seatCount + * the seatCount to set + */ + public void setSeatCount(int seatCount) { + this.seatCount = seatCount; + } + /** + * @return the type + */ + public String getType() { + return type; + } + /** + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + +} diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/CarType.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/CarType.java new file mode 100755 index 00000000..8a8784da --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/CarType.java @@ -0,0 +1,14 @@ +/** + * + */ +package org.mapstruct.example.repo.domain; + +/** + * @author jucheme + * + */ +public enum CarType { + + SPORTS, OTHER; + +} diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Employee.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Employee.java new file mode 100755 index 00000000..0c9ba5a2 --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Employee.java @@ -0,0 +1,74 @@ +/** + * + */ +package org.mapstruct.example.repo.domain; + +/** + * @author jucheme + * + */ +public class Employee { + + private String name; + private String address; + private Long age; + + public Employee() { + + } + + /** + * Construct! + * + * @param name + * @param address + * @param age + */ + public Employee(String name, String address, Long age) { + super(); + this.name = name; + this.address = address; + this.age = age; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the address + */ + public String getAddress() { + return address; + } + /** + * @param address + * the address to set + */ + public void setAddress(String address) { + this.address = address; + } + /** + * @return the age + */ + public Long getAge() { + return age; + } + /** + * @param age + * the age to set + */ + public void setAge(Long age) { + this.age = age; + } + +} diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Person.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Person.java new file mode 100755 index 00000000..2878a044 --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/domain/Person.java @@ -0,0 +1,96 @@ +/** + * + */ +package org.mapstruct.example.repo.domain; + +/** + * @author jucheme + * + */ +public class Person { + + private String firstName; + private String lastName; + private String address; + private Long age; + + public Person() { + } + + /** + * Construct! + * + * @param firstName + * @param lastName + * @param address + * @param age + */ + public Person(String firstName, String lastName, String address, Long age) { + super(); + this.firstName = firstName; + this.lastName = lastName; + this.address = address; + this.age = age; + } + + /** + * @return the firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName + * the firstName to set + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return the lastName + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName + * the lastName to set + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return the address + */ + public String getAddress() { + return address; + } + + /** + * @param address + * the address to set + */ + public void setAddress(String address) { + this.address = address; + } + + /** + * @return the age + */ + public Long getAge() { + return age; + } + + /** + * @param age + * the age to set + */ + public void setAge(Long age) { + this.age = age; + } + +} diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/CarMapper.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/CarMapper.java new file mode 100755 index 00000000..b2d24a70 --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/CarMapper.java @@ -0,0 +1,24 @@ +/** + * + */ +package org.mapstruct.example.repo.mappers; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.example.repo.AddToRepo; +import org.mapstruct.example.repo.StandardMapper; +import org.mapstruct.example.repo.domain.Car; +import org.mapstruct.example.repo.domain.CarDto; + +/** + * @author jucheme + * + */ +@AddToRepo +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface CarMapper extends StandardMapper { + + @Mapping(target = "seatCount", source = "numberOfSeats") + CarDto map(Car Car); +} \ No newline at end of file diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/PersonMapper.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/PersonMapper.java new file mode 100755 index 00000000..68e1707f --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/PersonMapper.java @@ -0,0 +1,23 @@ +/** + * + */ +package org.mapstruct.example.repo.mappers; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.example.repo.AddToRepo; +import org.mapstruct.example.repo.StandardMapper; +import org.mapstruct.example.repo.domain.Employee; +import org.mapstruct.example.repo.domain.Person; + +/** + * @author jucheme + * + */ +@AddToRepo +@Mapper +public interface PersonMapper extends StandardMapper { + + @Mapping(target = "name", source = "firstName") + Employee map(Person p); +} \ No newline at end of file diff --git a/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/PersonToBossMapper.java b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/PersonToBossMapper.java new file mode 100755 index 00000000..8f7616fb --- /dev/null +++ b/mapstruct-mapper-repo/example/src/main/java/org/mapstruct/example/repo/mappers/PersonToBossMapper.java @@ -0,0 +1,24 @@ +/** + * + */ +package org.mapstruct.example.repo.mappers; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.example.repo.AddToRepo; +import org.mapstruct.example.repo.StandardMapper; +import org.mapstruct.example.repo.domain.Boss; +import org.mapstruct.example.repo.domain.Person; + +/** + * @author jucheme + * + */ +@AddToRepo +@Mapper +public interface PersonToBossMapper extends StandardMapper { + + @Mapping(target = "name", source = "firstName") + @Mapping(target = "title", constant = "Boss") + Boss map(Person p); +} \ No newline at end of file diff --git a/mapstruct-mapper-repo/example/src/test/java/org/mapstruct/example/repo/TestMapperRepo.java b/mapstruct-mapper-repo/example/src/test/java/org/mapstruct/example/repo/TestMapperRepo.java new file mode 100755 index 00000000..3286f711 --- /dev/null +++ b/mapstruct-mapper-repo/example/src/test/java/org/mapstruct/example/repo/TestMapperRepo.java @@ -0,0 +1,79 @@ +/** + * + */ +package org.mapstruct.example.repo; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import org.mapstruct.example.repo.domain.Boss; +import org.mapstruct.example.repo.domain.Car; +import org.mapstruct.example.repo.domain.CarDto; +import org.mapstruct.example.repo.domain.CarType; +import org.mapstruct.example.repo.domain.Employee; +import org.mapstruct.example.repo.domain.Person; + +/** + * @author jucheme + * + */ +public class TestMapperRepo { + + @Test + public void testMapToFromNew() { + MapperRepo mf = MapperRepo.getInstance(); + Car car = new Car("Morris", 5, CarType.SPORTS); + Person p = new Person("mark", "juchems", "411 manor", 54L); + + CarDto c = mf.map(car, CarDto.class); + System.out.println(c); + + Employee e = mf.map(p, Employee.class); + System.out.println(e); + + Boss b = mf.map(p, Boss.class); + System.out.println(b); + } + + @Test + public void testMapObjectToObject() { + MapperRepo mf = MapperRepo.getInstance(); + Car car = new Car("Morris", 5, CarType.SPORTS); + + CarDto carDto = new CarDto(); + carDto.setMake("toyota"); + CarDto x = mf.map(car, carDto); + Assert.assertSame(x, carDto); + Assert.assertEquals("Morris", carDto.getMake()); + } + + /** + * Test mapAll + */ + @Test + public void testMapAll() { + MapperRepo mf = MapperRepo.getInstance(); + Person p = new Person("mark", "juchems", "411 manor", 54L); + + List result = mf.mapAll(p); + Assert.assertEquals(2, result.size()); + result.forEach(r -> { + System.out.println(r); + }); + + Assert.assertEquals(0, mf.mapAll(Long.class).size()); + } + + /** + * Test method. + */ + @Test + public void testHasRegisteredMapper() { + MapperRepo mf = MapperRepo.getInstance(); + + Assert.assertTrue(mf.hasRegisteredMapper(Car.class, CarDto.class)); + Assert.assertFalse(mf.hasRegisteredMapper(Car.class, Person.class)); + } +} \ No newline at end of file diff --git a/mapstruct-mapper-repo/generator/pom.xml b/mapstruct-mapper-repo/generator/pom.xml new file mode 100755 index 00000000..de79cea1 --- /dev/null +++ b/mapstruct-mapper-repo/generator/pom.xml @@ -0,0 +1,56 @@ + + 4.0.0 + repo-generator + + + org.mapstruct.examples.repo + repo + 0.0.1-SNAPSHOT + .. + + + + + + org.mapstruct + mapstruct + + + + org.freemarker + freemarker + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + + -proc:none + + org/mapstruct/example/repo/generator/RepositoryGenerator.java + + + + + compile-project + compile + + compile + + + + + + + + \ No newline at end of file diff --git a/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/AddToRepo.java b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/AddToRepo.java new file mode 100644 index 00000000..e6dbd417 --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/AddToRepo.java @@ -0,0 +1,13 @@ +package org.mapstruct.example.repo; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Target( ElementType.TYPE ) +@Retention( RetentionPolicy.CLASS ) +public @interface AddToRepo { +} diff --git a/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/FromToKey.java b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/FromToKey.java new file mode 100755 index 00000000..bb63c005 --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/FromToKey.java @@ -0,0 +1,68 @@ +/** + * + */ +package org.mapstruct.example.repo; + +/** + * @author jucheme + * + */ +public class FromToKey { + + @SuppressWarnings("rawtypes") + public final Class from; + @SuppressWarnings("rawtypes") + public final Class to; + + @SuppressWarnings("rawtypes") + public FromToKey(Class from, Class to) { + this.from = from; + this.to = to; + } + + public String toString() { + return from.getSimpleName() + ":" + to.getSimpleName(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((from == null) ? 0 : from.hashCode()); + result = prime * result + ((to == null) ? 0 : to.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FromToKey other = (FromToKey) obj; + if (from == null) { + if (other.from != null) + return false; + } else if (!from.equals(other.from)) + return false; + if (to == null) { + if (other.to != null) + return false; + } else if (!to.equals(other.to)) + return false; + return true; + } + +} diff --git a/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/MapperRepo.java b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/MapperRepo.java new file mode 100755 index 00000000..52f1f936 --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/MapperRepo.java @@ -0,0 +1,58 @@ +/** + * + */ +package org.mapstruct.example.repo; + +import java.util.List; + +/** + * @author jucheme + * + */ +public interface MapperRepo { + + /** + * Maps from an object to a new instance of an object. + * + * @param from + * @param to + * @return + */ + T map(Object from, Class to); + + /** + * Maps from an exsisting objec TO an existing object. + * + * @param from + * @param to + * @return + */ + T map(Object from, Object to); + + /** + * Maps this object using all available mappers. + * + * @param from + * @return + */ + List mapAll(Object from); + + /** + * Do we have a mapper for these two classes? + * + * @param from + * @param to + * @return + */ + @SuppressWarnings("rawtypes") + boolean hasRegisteredMapper(Class from, Class to); + + static MapperRepo getInstance() { + try { + return (MapperRepo)Class.forName( "org.mapstruct.example.repo.MapperRepoImpl" ).newInstance(); + } + catch ( ClassNotFoundException | InstantiationException | IllegalAccessException ex ) { + throw new IllegalStateException( ex ); + } + } +} \ No newline at end of file diff --git a/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/StandardMapper.java b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/StandardMapper.java new file mode 100755 index 00000000..58e2efba --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/StandardMapper.java @@ -0,0 +1,30 @@ +/** + * + */ +package org.mapstruct.example.repo; + +import org.mapstruct.MappingTarget; + +/** + * @author jucheme + * + */ +public interface StandardMapper { + + /** + * Maps from one object to another. + * + * @param from + * @return to + */ + To map(From from); + + /** + * Update the object. + * + * @param from + * @param to + * @return + */ + To update(From from, @MappingTarget To to); +} diff --git a/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/generator/RepoItem.java b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/generator/RepoItem.java new file mode 100644 index 00000000..38f56104 --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/generator/RepoItem.java @@ -0,0 +1,45 @@ +package org.mapstruct.example.repo.generator; + +import javax.lang.model.type.DeclaredType; + +/** + * @author sjaakd + * + */ +public class RepoItem { + + private DeclaredType sourceType; + private DeclaredType targetType; + private DeclaredType mapperType; + + public RepoItem(DeclaredType sourceType, DeclaredType targetType, DeclaredType mapperType) { + this.sourceType = sourceType; + this.targetType = targetType; + this.mapperType = mapperType; + } + + public String getSourceType() { + return sourceType.toString(); + } + + public String getTargetType() { + return targetType.toString(); + } + + public String getMapperType() { + return mapperType.toString(); + } + + public String getSourceTypeShort() { + return sourceType.asElement().getSimpleName().toString(); + } + + public String getTargetTypeShort() { + return targetType.asElement().getSimpleName().toString(); + } + + public String getMapperTypeShort() { + return mapperType.asElement().getSimpleName().toString(); + } + +} diff --git a/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/generator/RepositoryGenerator.java b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/generator/RepositoryGenerator.java new file mode 100644 index 00000000..38b237cb --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/java/org/mapstruct/example/repo/generator/RepositoryGenerator.java @@ -0,0 +1,117 @@ +package org.mapstruct.example.repo.generator; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; +import javax.tools.Diagnostic; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import freemarker.template.Version; +import org.mapstruct.example.repo.AddToRepo; +import org.mapstruct.example.repo.MapperRepo; +import org.mapstruct.example.repo.StandardMapper; + +/** + * @author sjaakd + * + */ +@SupportedAnnotationTypes( "org.mapstruct.example.repo.AddToRepo" ) +public class RepositoryGenerator extends AbstractProcessor { + + private Filer filer; + private Messager messager; + private List repoItems = new ArrayList<>( ); + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + this.filer = processingEnv.getFiler(); + this.messager = processingEnv.getMessager(); + Elements elementUtils = processingEnv.getElementUtils(); + Types typeUtils = processingEnv.getTypeUtils(); + + TypeMirror standardMapperType = + typeUtils.erasure( elementUtils.getTypeElement( StandardMapper.class.getName() ).asType() ); + TypeMirror addToRepoType = elementUtils.getTypeElement( AddToRepo.class.getName() ).asType(); + + + for ( TypeElement annotation : annotations ) { + + if ( typeUtils.isSameType( addToRepoType, annotation.asType() ) ) { + Iterator i = roundEnv.getElementsAnnotatedWith( annotation ).iterator(); + List standardMappers = new ArrayList<>( ); + while ( i.hasNext() ) { + Element mapperCandidateElement = i.next(); + TypeMirror mapperCandidateType = mapperCandidateElement.asType(); + if ( typeUtils.isAssignable( mapperCandidateType, standardMapperType ) ) { + repoItems.add( toRepoItem( (DeclaredType ) mapperCandidateType ) ); + } + else { + messager.printMessage( + Diagnostic.Kind.WARNING, + "@AddToRepo annotated class should implement a StandardMapper", + annotation + ); + } + } + + } + } + if ( roundEnv.processingOver() ) { + write( elementUtils.getTypeElement( MapperRepo.class.getName() ) ); + } + return true; + } + + private RepoItem toRepoItem(DeclaredType mapper) { + RepoItem result = null; + for ( Element element : mapper.asElement().getEnclosedElements() ) { + if ( element.getKind() == ElementKind.METHOD && "map".equals( element.getSimpleName().toString() ) ) { + ExecutableElement method = (ExecutableElement) element; + result = new RepoItem( (DeclaredType) method.getParameters().get( 0 ).asType(), + (DeclaredType) method.getReturnType(), + mapper + ); + } + } + return result; + } + + private void write(TypeElement mapperElement) { + try (Writer writer = filer.createSourceFile( MapperRepo.class.getName() + "Impl", mapperElement ) + .openWriter()) { + Configuration cfg = new Configuration( new Version( "2.3.21" ) ); + cfg.setClassForTemplateLoading( RepositoryGenerator.class, "/" ); + cfg.setDefaultEncoding( "UTF-8" ); + + Map templateData = new HashMap<>(); + + templateData.put( "repoItems", repoItems ); + Template template = cfg.getTemplate( "MapperRepoImpl.ftl" ); + template.process( templateData, writer ); + } + catch ( TemplateException | IOException ex ) { + throw new IllegalStateException( ex ); + } + } + +} diff --git a/mapstruct-mapper-repo/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/mapstruct-mapper-repo/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 00000000..7cb40dba --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.mapstruct.example.repo.generator.RepositoryGenerator diff --git a/mapstruct-mapper-repo/generator/src/main/resources/MapperRepoImpl.ftl b/mapstruct-mapper-repo/generator/src/main/resources/MapperRepoImpl.ftl new file mode 100644 index 00000000..a8f43da5 --- /dev/null +++ b/mapstruct-mapper-repo/generator/src/main/resources/MapperRepoImpl.ftl @@ -0,0 +1,83 @@ +package org.mapstruct.example.repo; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +<#list repoItems as repoItem> +import ${repoItem.sourceType}; + +<#list repoItems as repoItem> +import ${repoItem.targetType}; + +<#list repoItems as repoItem> +import ${repoItem.mapperType}; + +<#list repoItems as repoItem> +import ${repoItem.mapperType}Impl; + + +@SuppressWarnings("rawtypes") +public class MapperRepoImpl implements MapperRepo { + + private Map bindings; + private Map> listBindings; + + public MapperRepoImpl() { + + Map tempBindings = new HashMap<>(); + Map> tempListBindings = new HashMap<>(); + + <#list repoItems as repoItem> + tempBindings.put(new FromToKey( ${repoItem.sourceTypeShort}.class, ${repoItem.targetTypeShort}.class ), new ${repoItem.mapperTypeShort}Impl() ); + if ( !tempListBindings.containsKey( ${repoItem.sourceTypeShort}.class ) ) { + tempListBindings.put( ${repoItem.sourceTypeShort}.class, new ArrayList() ); + } + tempListBindings.get( ${repoItem.sourceTypeShort}.class ).add( new ${repoItem.mapperTypeShort}Impl() ); + + + this.bindings = Collections.unmodifiableMap(tempBindings); + this.listBindings = Collections.unmodifiableMap(tempListBindings); + } + + @Override + @SuppressWarnings("unchecked") + public T map(Object from, Class to) { + StandardMapper mapper = this.bindings.get(new FromToKey(from.getClass(), to)); + if (mapper != null) { + return (T) mapper.map(from); + } + return null; + } + + @Override + @SuppressWarnings("unchecked") + public T map(Object from, Object to) { + StandardMapper mapper = this.bindings.get(new FromToKey(from.getClass(), to.getClass())); + if (mapper != null) { + return (T) mapper.update(from, to); + } + return null; + } + + @Override + @SuppressWarnings("unchecked") + public List mapAll(Object from) { + List mappings = new ArrayList<>(); + if (this.listBindings.containsKey(from.getClass())) { + this.listBindings.get( from.getClass()).forEach( mapper -> mappings.add( mapper.map( from ) ) ); + } + return mappings; + } + + @Override + public boolean hasRegisteredMapper(Class from, Class to) { + return this.bindings.containsKey(new FromToKey(from, to)); + } +} diff --git a/mapstruct-mapper-repo/pom.xml b/mapstruct-mapper-repo/pom.xml new file mode 100755 index 00000000..b1f3705d --- /dev/null +++ b/mapstruct-mapper-repo/pom.xml @@ -0,0 +1,77 @@ + + 4.0.0 + org.mapstruct.examples.repo + repo + 0.0.1-SNAPSHOT + mapstruct-repo + pom + + + UTF-8 + 1.7.0.Beta1 + + + + generator + example + + + + + + + + org.mapstruct.examples.repo + repo-generator + ${project.version} + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + org.freemarker + freemarker + 2.3.23 + + + + + junit + junit + 4.13.1 + test + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + 1.8 + 1.8 + + + + + + + \ No newline at end of file diff --git a/mapstruct-mapping-from-map/pom.xml b/mapstruct-mapping-from-map/pom.xml index 1b014303..95bec89f 100644 --- a/mapstruct-mapping-from-map/pom.xml +++ b/mapstruct-mapping-from-map/pom.xml @@ -1,22 +1,9 @@ @@ -26,13 +13,14 @@ 1.0.0 - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -49,7 +37,7 @@ junit junit - 4.12 + 4.13.1 test @@ -60,7 +48,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 1.8 1.8 diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Department.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Department.java new file mode 100644 index 00000000..42ccd612 --- /dev/null +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Department.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.dto; + +/** + * @author Filip Hrisafov + */ +public class Department { + + private String id; + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Employee.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Employee.java new file mode 100644 index 00000000..907e710e --- /dev/null +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Employee.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.dto; + +/** + * @author Filip Hrisafov + */ +public class Employee { + + private String id; + private String name; + private Department department; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } +} diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Source.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Source.java index 541ccfaf..7a66a372 100644 --- a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Source.java +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Target.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Target.java index e6043d4c..f37a6d75 100644 --- a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Target.java +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/dto/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/MapToBeanMapper.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/MapToBeanMapper.java new file mode 100644 index 00000000..da365dc3 --- /dev/null +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/MapToBeanMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.mapper; + +import java.lang.annotation.Target; +import java.util.Map; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.example.dto.Department; +import org.mapstruct.example.dto.Employee; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MapToBeanMapper { + + MapToBeanMapper INSTANCE = Mappers.getMapper(MapToBeanMapper.class); + + @Mapping(target = "department", ignore = true) + Employee fromMap(Map map); + + @AfterMapping + default void finishEmployee(@MappingTarget Employee employee, Map map) { + employee.setDepartment(fromMapToDepartment(map)); + } + + @Mapping(target = "id", source = "did") + @Mapping(target = "name", source = "dname") + Department fromMapToDepartment(Map map); +} diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index 73736fad..299d5a9d 100644 --- a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -1,27 +1,13 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.Source; import org.mapstruct.example.dto.Target; import org.mapstruct.example.mapper.util.MappingUtil; @@ -38,9 +24,7 @@ public interface SourceTargetMapper { SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); - @Mappings( { - @Mapping(source = "map", target = "ip", qualifiedBy = Ip.class ), - @Mapping(source = "map", target = "server", qualifiedBy = Server.class ), - } ) + @Mapping(target = "ip", source = "map", qualifiedBy = Ip.class ) + @Mapping(target = "server", source = "map", qualifiedBy = Server.class ) Target toTarget(Source s); } diff --git a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/util/MappingUtil.java b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/util/MappingUtil.java index e6af9b59..a0887df0 100644 --- a/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/util/MappingUtil.java +++ b/mapstruct-mapping-from-map/src/main/java/org/mapstruct/example/mapper/util/MappingUtil.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper.util; diff --git a/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/MapToBeanMapperTest.java b/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/MapToBeanMapperTest.java new file mode 100644 index 00000000..ff0b9f6c --- /dev/null +++ b/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/MapToBeanMapperTest.java @@ -0,0 +1,38 @@ +package org.mapstruct.example; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.mapstruct.example.dto.Department; +import org.mapstruct.example.dto.Employee; +import org.mapstruct.example.mapper.MapToBeanMapper; + +/** + * @author Filip Hrisafov + */ +public class MapToBeanMapperTest { + + @Test + public void shouldMapMapToBean() { + Map map = new HashMap<>(); + map.put("id", "1234"); + map.put("name", "Tester"); + map.put("did", "4321"); //Department Id + map.put("dname", "Test");// Depart name + + Employee employee = MapToBeanMapper.INSTANCE.fromMap(map); + + assertNotNull(employee); + assertEquals(employee.getId(), "1234"); + assertEquals(employee.getName(), "Tester"); + + Department department = employee.getDepartment(); + assertNotNull(department); + assertEquals(department.getId(), "4321"); + assertEquals(department.getName(), "Test"); + } +} diff --git a/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index b2ada78f..3739e89c 100644 --- a/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-mapping-from-map/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-mapping-with-cycles/pom.xml b/mapstruct-mapping-with-cycles/pom.xml index 33bb8e63..4ad1a32c 100644 --- a/mapstruct-mapping-with-cycles/pom.xml +++ b/mapstruct-mapping-with-cycles/pom.xml @@ -1,22 +1,9 @@ 1.0.0 - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -50,14 +38,14 @@ junit junit - 4.12 + 4.13.1 test org.assertj assertj-core - 3.6.2 + 3.27.7 test @@ -68,7 +56,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 1.8 1.8 diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java index 64fc4b76..fe169065 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/Employee.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java index 5d5fd640..48cd939e 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/dto/EmployeeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/CycleAvoidingMappingContext.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/CycleAvoidingMappingContext.java index 26938604..ed82e178 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/CycleAvoidingMappingContext.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/CycleAvoidingMappingContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; diff --git a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java index 11fc87b0..a3155cd2 100644 --- a/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java +++ b/mapstruct-mapping-with-cycles/src/main/java/org/mapstruct/example/mapper/EmployeeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; @@ -34,7 +21,7 @@ public interface EmployeeMapper { EmployeeMapper MAPPER = Mappers.getMapper( EmployeeMapper.class ); - @Mapping(source = "employeeName", target = "name") + @Mapping(target = "name", source = "employeeName") Employee toEmployee(EmployeeDto employeeDto, @Context CycleAvoidingMappingContext context); @InheritInverseConfiguration diff --git a/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java b/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java index b4a87e28..d2d1be81 100644 --- a/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java +++ b/mapstruct-mapping-with-cycles/src/test/java/org/mapstruct/example/EmployeeMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-metadata-with-annotations/pom.xml b/mapstruct-metadata-with-annotations/pom.xml new file mode 100644 index 00000000..3b6309ba --- /dev/null +++ b/mapstruct-metadata-with-annotations/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + org.mapstruct.examples.metadata + mapstruct-examples-metadata-with-annotations + 1.0.0 + + + UTF-8 + 1.7.0.Beta1 + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + junit + junit + 4.13.1 + test + + + + org.assertj + assertj-core + 3.27.7 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + + diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/dto/LegalEntity.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/dto/LegalEntity.java new file mode 100644 index 00000000..e179029a --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/dto/LegalEntity.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.dto; + +/** + * + * @author Sjaak Derksen + */ +public class LegalEntity { + + private String name; + + private String address; + + private String id; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/dto/TaxRecord.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/dto/TaxRecord.java new file mode 100644 index 00000000..f2ded5e7 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/dto/TaxRecord.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.dto; + +/** + * + * @author Sjaak Derksen + */ +public class TaxRecord { + + private int number; + + private int year; + + private LegalEntity legalEntity; + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public LegalEntity getLegalEntity() { + return legalEntity; + } + + public void setLegalEntity(LegalEntity legalEntity) { + this.legalEntity = legalEntity; + } + +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/LegalEntityPE.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/LegalEntityPE.java new file mode 100644 index 00000000..79094d6a --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/LegalEntityPE.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.entities; + + +/** + * + * @author Sjaak Derksen + */ +public class LegalEntityPE { + + private String name; + + private String address; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/OrganisationPE.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/OrganisationPE.java new file mode 100644 index 00000000..697d2ff2 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/OrganisationPE.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.entities; + +/** + * + * @author Sjaak Derksen + */ +public class OrganisationPE extends LegalEntityPE { + + private String chamberOfCommerceNumber; + + public String getChamberOfCommerceNumber() { + return chamberOfCommerceNumber; + } + + public void setChamberOfCommerceNumber(String chamberOfCommerceNumber) { + this.chamberOfCommerceNumber = chamberOfCommerceNumber; + } + +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/PersonPE.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/PersonPE.java new file mode 100644 index 00000000..fe3e1bff --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/PersonPE.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.entities; + + +/** + * + * @author Sjaak Derksen + */ +public class PersonPE extends LegalEntityPE { + + private String socialSecurityNumber; + + public String getSocialSecurityNumber() { + return socialSecurityNumber; + } + + public void setSocialSecurityNumber(String socialSecurityNumber) { + this.socialSecurityNumber = socialSecurityNumber; + } + +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/TaxRecordPE.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/TaxRecordPE.java new file mode 100644 index 00000000..ccb5a3a2 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/entities/TaxRecordPE.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.entities; + +import org.mapstruct.example.metadata.mapper.annotations.Treatment; + +/** + * + * @author Sjaak Derksen + */ +public class TaxRecordPE { + + private int number; + + private int year; + + private LegalEntityPE legalEntity; + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public LegalEntityPE getLegalEntity() { + return legalEntity; + } + + @Treatment( formatAs = "organisation" ) + public void setLegalEntity(LegalEntityPE legalEntity) { + this.legalEntity = legalEntity; + } + +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/SourceTargetMapper.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/SourceTargetMapper.java new file mode 100644 index 00000000..8a933620 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/SourceTargetMapper.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.mapper; + +import org.mapstruct.example.metadata.mapper.util.TaxContext; +import java.lang.annotation.Annotation; +import java.util.List; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.example.metadata.dto.LegalEntity; +import org.mapstruct.example.metadata.dto.TaxRecord; +import org.mapstruct.example.metadata.entities.LegalEntityPE; +import org.mapstruct.example.metadata.entities.OrganisationPE; +import org.mapstruct.example.metadata.entities.PersonPE; +import org.mapstruct.example.metadata.entities.TaxRecordPE; +import org.mapstruct.example.metadata.mapper.annotations.DoNotSelectForMapping; +import org.mapstruct.example.metadata.mapper.annotations.Treatment; +import org.mapstruct.factory.Mappers; + + + + +@Mapper +public abstract class SourceTargetMapper { + + public static final SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); + + public abstract TaxRecordPE toTarget( TaxRecord s, @Context TaxContext ctx ); + + protected LegalEntityPE convert( LegalEntity s, @Context TaxContext ctx ) { + + List annotations = ctx.getAnnotationsForMethod( "setLegalEntity" ); + String formatAs = annotations.stream() + .filter( Treatment.class::isInstance ) + .map( Treatment.class::cast ) + .findFirst() + .map( Treatment::formatAs ) + .orElse( "person" ); + if ( "organisation".equals( formatAs ) ) { + return mapOrganisation( s ); + } + else { + return mapPerson( s ); + } + } + + @DoNotSelectForMapping + @Mapping( target = "socialSecurityNumber", source = "id" ) + protected abstract PersonPE mapPerson( LegalEntity s ); + + @DoNotSelectForMapping + @Mapping( target = "chamberOfCommerceNumber", source = "id" ) + protected abstract OrganisationPE mapOrganisation( LegalEntity s ); +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/annotations/DoNotSelectForMapping.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/annotations/DoNotSelectForMapping.java new file mode 100644 index 00000000..e76f3649 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/annotations/DoNotSelectForMapping.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.mapper.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.mapstruct.Qualifier; + +/** + * This is a qualfier with the opposite purpose. It is never used in an @Mapping and + * its purpose is to avoid selection of a method annotated with his qualifier + */ +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.SOURCE) +public @interface DoNotSelectForMapping { +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/annotations/Treatment.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/annotations/Treatment.java new file mode 100644 index 00000000..8457f14e --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/annotations/Treatment.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.metadata.mapper.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Treatment { + + String formatAs() default "person"; +} diff --git a/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/util/TaxContext.java b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/util/TaxContext.java new file mode 100644 index 00000000..31874b84 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/main/java/org/mapstruct/example/metadata/mapper/util/TaxContext.java @@ -0,0 +1,51 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mapstruct.example.metadata.mapper.util; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.mapstruct.BeforeMapping; +import org.mapstruct.TargetType; + +/** + * + * @author Sjaak Derksen + */ +public class TaxContext { + + private final Map> annotations = new HashMap<>(); + + @BeforeMapping + public void registerAnnotationsForTarget(@TargetType Class t) { + /* Although MapStruct is all about generating code, there is currently + * no means to analyse annotations runtime without reflection. One could + * even argue whether this is should be part of a mapping framework such + * as MapStruct. Hence, reflection is used in this particular place, in this + * example to demonstrate how to do this. + */ + Method[] methods = t.getMethods(); + for ( Method method : methods ) { + for ( Annotation annotation : method.getAnnotations() ) { + registerAnnotationForMethod( method.getName(), annotation ); + } + } + } + + private void registerAnnotationForMethod(String methodName, Annotation annotation) { + if ( !annotations.containsKey( methodName ) ) { + annotations.put( methodName, new ArrayList<>() ); + } + annotations.get( methodName ).add( annotation ); + } + + public List getAnnotationsForMethod(String methodName) { + return annotations.getOrDefault( methodName, new ArrayList<>() ); + } +} diff --git a/mapstruct-metadata-with-annotations/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-metadata-with-annotations/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java new file mode 100644 index 00000000..92b37e49 --- /dev/null +++ b/mapstruct-metadata-with-annotations/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import static org.assertj.core.api.Assertions.assertThat; +import org.mapstruct.example.metadata.mapper.SourceTargetMapper; +import org.junit.Test; +import org.mapstruct.example.metadata.dto.LegalEntity; +import org.mapstruct.example.metadata.dto.TaxRecord; +import org.mapstruct.example.metadata.entities.OrganisationPE; +import org.mapstruct.example.metadata.entities.TaxRecordPE; +import org.mapstruct.example.metadata.mapper.util.TaxContext; + +/** + * + * @author Sjaak Derksen + */ +public class SourceTargetMapperTest { + + public SourceTargetMapperTest() { + } + + /** + * Test of toTarget method, of class SourceTargetMapper. + */ + @Test + public void testToTarget() { + + LegalEntity legalEntity = new LegalEntity(); + legalEntity.setName( "ACME" ); + legalEntity.setAddress( "Tinseltown" ); + legalEntity.setId( "123.4567" ); + TaxRecord taxRecord = new TaxRecord(); + taxRecord.setNumber( 1 ); + taxRecord.setYear( 2017 ); + taxRecord.setLegalEntity( legalEntity ); + + TaxRecordPE taxRecordPE = SourceTargetMapper.MAPPER.toTarget( taxRecord, new TaxContext() ); + + assertThat( taxRecordPE ).isNotNull(); + assertThat( taxRecordPE.getNumber() ).isEqualTo( 1 ); + assertThat( taxRecordPE.getYear() ).isEqualTo( 2017 ); + assertThat( taxRecordPE.getLegalEntity() ).isNotNull(); + assertThat( taxRecordPE.getLegalEntity().getName() ).isEqualTo( "ACME" ); + assertThat( taxRecordPE.getLegalEntity().getAddress() ).isEqualTo( "Tinseltown" ); + // check whether annotation analysis worked + assertThat( taxRecordPE.getLegalEntity() ).isInstanceOf( OrganisationPE.class ); + OrganisationPE organisation = (OrganisationPE) taxRecordPE.getLegalEntity(); + assertThat( ( organisation ).getChamberOfCommerceNumber() ).isEqualTo( "123.4567" ); + } + + + +} diff --git a/mapstruct-nested-bean-mappings/pom.xml b/mapstruct-nested-bean-mappings/pom.xml index 930f71b3..41976934 100644 --- a/mapstruct-nested-bean-mappings/pom.xml +++ b/mapstruct-nested-bean-mappings/pom.xml @@ -1,22 +1,9 @@ 1.0.0 - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -50,14 +38,14 @@ junit junit - 4.12 + 4.13.1 test org.assertj assertj-core - 3.6.2 + 3.27.7 test @@ -68,7 +56,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 1.8 1.8 diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java index 7df77354..0de9cd70 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java index 02f60e74..627d5bfc 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java index 093ded05..179412c2 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/FishTankWithNestedDocumentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java index cecc43c8..b000783b 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java index 22d5f0a8..3f230210 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/MaterialTypeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java index 3e6d40fa..ad60ebeb 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/OrnamentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java index bbf06de8..0bec1fa5 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterPlantDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java index 5012a573..e8d1f083 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java index fba834a8..bbed7810 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityOrganisationDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java index 4c8b9578..dbc0919b 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityReportDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java index c332bc1b..c96bb09a 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/dto/WaterQualityWithDocumentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java index 995927fd..9321efd6 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapper.java @@ -1,27 +1,13 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; import org.mapstruct.factory.Mappers; @@ -35,22 +21,18 @@ public interface FishTankMapper { FishTankMapper INSTANCE = Mappers.getMapper( FishTankMapper.class ); - @Mappings({ - @Mapping(target = "fish.kind", source = "fish.type"), - @Mapping(target = "fish.name", ignore = true), - @Mapping(target = "ornament", source = "interior.ornament"), - @Mapping(target = "material.materialType", source = "material"), - @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") - }) + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", ignore = true) + @Mapping(target = "ornament", source = "interior.ornament") + @Mapping(target = "material.materialType", source = "material") + @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") FishTankDto map(FishTank source); - @Mappings({ - @Mapping(target = "fish.kind", source = "source.fish.type"), - @Mapping(target = "fish.name", ignore = true), - @Mapping(target = "ornament", source = "source.interior.ornament"), - @Mapping(target = "material.materialType", source = "source.material"), - @Mapping(target = "quality.report.organisation.name", source = "source.quality.report.organisationName") - }) + @Mapping(target = "fish.kind", source = "source.fish.type") + @Mapping(target = "fish.name", ignore = true) + @Mapping(target = "ornament", source = "source.interior.ornament") + @Mapping(target = "material.materialType", source = "source.material") + @Mapping(target = "quality.report.organisation.name", source = "source.quality.report.organisationName") FishTankDto mapAsWell(FishTank source); @InheritInverseConfiguration( name = "map" ) diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java index bf7ed73e..5c98c3be 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperConstant.java @@ -1,26 +1,12 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; import org.mapstruct.factory.Mappers; @@ -34,14 +20,12 @@ public interface FishTankMapperConstant { FishTankMapperConstant INSTANCE = Mappers.getMapper( FishTankMapperConstant.class ); - @Mappings({ - @Mapping(target = "fish.kind", source = "fish.type"), - @Mapping(target = "fish.name", constant = "Nemo"), - @Mapping(target = "ornament", ignore = true ), - @Mapping(target = "material.materialType", source = "material"), - @Mapping(target = "material.manufacturer", constant = "MMM" ), - @Mapping(target = "quality", ignore = true) - }) + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", constant = "Nemo") + @Mapping(target = "ornament", ignore = true ) + @Mapping(target = "material.materialType", source = "material") + @Mapping(target = "material.manufacturer", constant = "MMM" ) + @Mapping(target = "quality", ignore = true) FishTankDto map(FishTank source); } diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java index 681a347b..3e56b73d 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperExpression.java @@ -1,26 +1,12 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.FishTankDto; import org.mapstruct.example.model.FishTank; import org.mapstruct.factory.Mappers; @@ -34,14 +20,12 @@ public interface FishTankMapperExpression { FishTankMapperExpression INSTANCE = Mappers.getMapper( FishTankMapperExpression.class ); - @Mappings({ - @Mapping(target = "fish.kind", source = "fish.type"), - @Mapping(target = "fish.name", expression = "java(\"Jaws\")"), - @Mapping(target = "plant", ignore = true ), - @Mapping(target = "ornament", ignore = true ), - @Mapping(target = "material", ignore = true), - @Mapping(target = "quality.report.organisation.name", expression = "java(\"Dunno\")" ) - }) + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", expression = "java(\"Jaws\")") + @Mapping(target = "plant", ignore = true ) + @Mapping(target = "ornament", ignore = true ) + @Mapping(target = "material", ignore = true) + @Mapping(target = "quality.report.organisation.name", expression = "java(\"Dunno\")" ) FishTankDto map(FishTank source); } diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java index 81d1fac6..66ee5433 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/mapper/FishTankMapperWithDocument.java @@ -1,26 +1,12 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.FishTankWithNestedDocumentDto; import org.mapstruct.example.model.FishTank; import org.mapstruct.factory.Mappers; @@ -34,15 +20,13 @@ public interface FishTankMapperWithDocument { FishTankMapperWithDocument INSTANCE = Mappers.getMapper( FishTankMapperWithDocument.class ); - @Mappings({ - @Mapping(target = "fish.kind", source = "fish.type"), - @Mapping(target = "fish.name", expression = "java(\"Jaws\")"), - @Mapping(target = "plant", ignore = true ), - @Mapping(target = "ornament", ignore = true ), - @Mapping(target = "material", ignore = true), - @Mapping(target = "quality.document", source = "quality.report"), - @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) - }) + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", expression = "java(\"Jaws\")") + @Mapping(target = "plant", ignore = true ) + @Mapping(target = "ornament", ignore = true ) + @Mapping(target = "material", ignore = true) + @Mapping(target = "quality.document", source = "quality.report") + @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) FishTankWithNestedDocumentDto map(FishTank source); } diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Fish.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Fish.java index cc07c141..adeeca3c 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Fish.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Fish.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/FishTank.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/FishTank.java index eadda141..3e20e40f 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/FishTank.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/FishTank.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Interior.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Interior.java index 438b7a73..9b587753 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Interior.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Interior.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/MaterialType.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/MaterialType.java index 2ed3e035..24631bc0 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/MaterialType.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/MaterialType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Ornament.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Ornament.java index 4e94c186..98a8ff09 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Ornament.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/Ornament.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterPlant.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterPlant.java index e93f0db0..bd0bc995 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterPlant.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterPlant.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQuality.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQuality.java index 33577490..9d6c8191 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQuality.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQuality.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQualityReport.java b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQualityReport.java index 4ced9766..31fb3378 100644 --- a/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQualityReport.java +++ b/mapstruct-nested-bean-mappings/src/main/java/org/mapstruct/example/model/WaterQualityReport.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.model; diff --git a/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java b/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java index 3ef79fc1..10abe98f 100644 --- a/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java +++ b/mapstruct-nested-bean-mappings/src/test/java/org/mapstruct/example/FishTanksMappersTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-on-ant/build.xml b/mapstruct-on-ant/build.xml index 80b502bd..0f2e8143 100644 --- a/mapstruct-on-ant/build.xml +++ b/mapstruct-on-ant/build.xml @@ -1,22 +1,12 @@ - + @@ -30,7 +20,7 @@ - + @@ -47,7 +37,7 @@ - + diff --git a/mapstruct-on-ant/src/main/java/org/mapstruct/example/Source.java b/mapstruct-on-ant/src/main/java/org/mapstruct/example/Source.java index daf483c2..234c6055 100644 --- a/mapstruct-on-ant/src/main/java/org/mapstruct/example/Source.java +++ b/mapstruct-on-ant/src/main/java/org/mapstruct/example/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-on-ant/src/main/java/org/mapstruct/example/SourceTargetMapper.java b/mapstruct-on-ant/src/main/java/org/mapstruct/example/SourceTargetMapper.java index c0abe930..79ebd8c7 100644 --- a/mapstruct-on-ant/src/main/java/org/mapstruct/example/SourceTargetMapper.java +++ b/mapstruct-on-ant/src/main/java/org/mapstruct/example/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; @@ -28,8 +15,8 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper(SourceTargetMapper.class); - @Mapping(source = "qax", target = "baz") - @Mapping(source = "baz", target = "qax") + @Mapping(target = "baz", source = "qax") + @Mapping(target = "qax", source = "baz") Target sourceToTarget(Source source); @InheritInverseConfiguration diff --git a/mapstruct-on-ant/src/main/java/org/mapstruct/example/Target.java b/mapstruct-on-ant/src/main/java/org/mapstruct/example/Target.java index 8f704bab..74848972 100644 --- a/mapstruct-on-ant/src/main/java/org/mapstruct/example/Target.java +++ b/mapstruct-on-ant/src/main/java/org/mapstruct/example/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-on-ant/src/test/java/org/mapstruct/example/ConversionTest.java b/mapstruct-on-ant/src/test/java/org/mapstruct/example/ConversionTest.java index 9261afd7..85e8c8be 100644 --- a/mapstruct-on-ant/src/test/java/org/mapstruct/example/ConversionTest.java +++ b/mapstruct-on-ant/src/test/java/org/mapstruct/example/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-on-bazel/.bazelversion b/mapstruct-on-bazel/.bazelversion new file mode 100644 index 00000000..f9c71a52 --- /dev/null +++ b/mapstruct-on-bazel/.bazelversion @@ -0,0 +1 @@ +8.5.1 diff --git a/mapstruct-on-bazel/BUILD.bazel b/mapstruct-on-bazel/BUILD.bazel new file mode 100644 index 00000000..5df19289 --- /dev/null +++ b/mapstruct-on-bazel/BUILD.bazel @@ -0,0 +1,49 @@ +load("@rules_java//java:defs.bzl", "java_library", "java_plugin", "java_test") + +java_library( + name = "mapstruct-on-bazel", + srcs = glob(["src/main/java/**/*.java"]), + resources = glob(["src/main/resources/**"], allow_empty = True), + deps = [ + ":mapstruct", + ], +) + +java_library( + name = "tests", + srcs = glob(["src/test/java/**/*.java"]), + resources = glob(["src/test/resources/**"], allow_empty = True), + deps = [ + ":mapstruct-on-bazel", + "@maven//:junit_junit", + "@maven//:org_assertj_assertj_core", + ], +) + +java_test( + name = "ConversionTest", + test_class = "org.mapstruct.example.ConversionTest", + runtime_deps = [ + ":tests", + ], +) + +java_library( + name = "mapstruct", + exported_plugins = [ + ":mapstruct_plugin", + ], + visibility = ["//visibility:public"], + exports = [ + "@maven//:org_mapstruct_mapstruct", + ], +) + +java_plugin( + name = "mapstruct_plugin", + generates_api = True, + processor_class = "org.mapstruct.ap.MappingProcessor", + deps = [ + "@maven//:org_mapstruct_mapstruct_processor", + ], +) diff --git a/mapstruct-on-bazel/MODULE.bazel b/mapstruct-on-bazel/MODULE.bazel new file mode 100644 index 00000000..7923d979 --- /dev/null +++ b/mapstruct-on-bazel/MODULE.bazel @@ -0,0 +1,19 @@ +module( + name = "mapstruct-on-bazel", + version = "1.0.0", +) + +bazel_dep(name = "rules_java", version = "8.14.0") + +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") +bazel_dep(name = "rules_jvm_external", version = "6.6") + +maven.install( + artifacts = [ + "org.mapstruct:mapstruct:1.7.0.Beta1", + "org.mapstruct:mapstruct-processor:1.7.0.Beta1", + "junit:junit:4.13.2", + "org.assertj:assertj-core:3.27.7", + ], +) +use_repo(maven, "maven") diff --git a/mapstruct-on-bazel/MODULE.bazel.lock b/mapstruct-on-bazel/MODULE.bazel.lock new file mode 100644 index 00000000..8fb08990 --- /dev/null +++ b/mapstruct-on-bazel/MODULE.bazel.lock @@ -0,0 +1,207 @@ +{ + "lockFileVersion": 24, + "registryFileHashes": { + "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", + "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589", + "https://bcr.bazel.build/modules/abseil-cpp/20230125.1/MODULE.bazel": "89047429cb0207707b2dface14ba7f8df85273d484c2572755be4bab7ce9c3a0", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.0.bcr.1/MODULE.bazel": "1c8cec495288dccd14fdae6e3f95f772c1c91857047a098fad772034264cc8cb", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.0/MODULE.bazel": "d253ae36a8bd9ee3c5955384096ccb6baf16a1b1e93e858370da0a3b94f77c16", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.1/MODULE.bazel": "fa92e2eb41a04df73cdabeec37107316f7e5272650f81d6cc096418fe647b915", + "https://bcr.bazel.build/modules/abseil-cpp/20240116.1/MODULE.bazel": "37bcdb4440fbb61df6a1c296ae01b327f19e9bb521f9b8e26ec854b6f97309ed", + "https://bcr.bazel.build/modules/abseil-cpp/20240116.1/source.json": "9be551b8d4e3ef76875c0d744b5d6a504a27e3ae67bc6b28f46415fd2d2957da", + "https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", + "https://bcr.bazel.build/modules/bazel_features/1.15.0/MODULE.bazel": "d38ff6e517149dc509406aca0db3ad1efdd890a85e049585b7234d04238e2a4d", + "https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d", + "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", + "https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", + "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", + "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", + "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", + "https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", + "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.2/MODULE.bazel": "3bd40978e7a1fac911d5989e6b09d8f64921865a45822d8b09e815eaa726a651", + "https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953", + "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", + "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", + "https://bcr.bazel.build/modules/google_benchmark/1.8.2/MODULE.bazel": "a70cf1bba851000ba93b58ae2f6d76490a9feb74192e57ab8e8ff13c34ec50cb", + "https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4", + "https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/MODULE.bazel": "22c31a561553727960057361aa33bf20fb2e98584bc4fec007906e27053f80c6", + "https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/source.json": "41e9e129f80d8c8bf103a7acc337b76e54fad1214ac0a7084bf24f4cd924b8b4", + "https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f", + "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075", + "https://bcr.bazel.build/modules/jsoncpp/1.9.5/source.json": "4108ee5085dd2885a341c7fab149429db457b3169b86eb081fa245eadf69169d", + "https://bcr.bazel.build/modules/libpfm/4.11.0/MODULE.bazel": "45061ff025b301940f1e30d2c16bea596c25b176c8b6b3087e92615adbd52902", + "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5", + "https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f", + "https://bcr.bazel.build/modules/platforms/0.0.11/source.json": "f7e188b79ebedebfe75e9e1d098b8845226c7992b307e28e1496f23112e8fc29", + "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", + "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37", + "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", + "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", + "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", + "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", + "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", + "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", + "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df", + "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e", + "https://bcr.bazel.build/modules/protobuf/29.0/source.json": "b857f93c796750eef95f0d61ee378f3420d00ee1dd38627b27193aa482f4f981", + "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", + "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e", + "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/source.json": "be4789e951dd5301282729fe3d4938995dc4c1a81c2ff150afc9f1b0504c6022", + "https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206", + "https://bcr.bazel.build/modules/re2/2023-09-01/source.json": "e044ce89c2883cd957a2969a43e79f7752f9656f6b20050b62f90ede21ec6eb4", + "https://bcr.bazel.build/modules/rules_android/0.1.1/MODULE.bazel": "48809ab0091b07ad0182defb787c4c5328bd3a278938415c00a7b69b50c4d3a8", + "https://bcr.bazel.build/modules/rules_android/0.1.1/source.json": "e6986b41626ee10bdc864937ffb6d6bf275bb5b9c65120e6137d56e6331f089e", + "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", + "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", + "https://bcr.bazel.build/modules/rules_cc/0.0.13/MODULE.bazel": "0e8529ed7b323dad0775ff924d2ae5af7640b23553dfcd4d34344c7e7a867191", + "https://bcr.bazel.build/modules/rules_cc/0.0.14/MODULE.bazel": "5e343a3aac88b8d7af3b1b6d2093b55c347b8eefc2e7d1442f7a02dc8fea48ac", + "https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc", + "https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87", + "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", + "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", + "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", + "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", + "https://bcr.bazel.build/modules/rules_cc/0.1.1/source.json": "d61627377bd7dd1da4652063e368d9366fc9a73920bfa396798ad92172cf645c", + "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", + "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", + "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/source.json": "c8b1e2c717646f1702290959a3302a178fb639d987ab61d548105019f11e527e", + "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74", + "https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86", + "https://bcr.bazel.build/modules/rules_java/6.0.0/MODULE.bazel": "8a43b7df601a7ec1af61d79345c17b31ea1fedc6711fd4abfd013ea612978e39", + "https://bcr.bazel.build/modules/rules_java/6.4.0/MODULE.bazel": "e986a9fe25aeaa84ac17ca093ef13a4637f6107375f64667a15999f77db6c8f6", + "https://bcr.bazel.build/modules/rules_java/6.5.2/MODULE.bazel": "1d440d262d0e08453fa0c4d8f699ba81609ed0e9a9a0f02cd10b3e7942e61e31", + "https://bcr.bazel.build/modules/rules_java/7.10.0/MODULE.bazel": "530c3beb3067e870561739f1144329a21c851ff771cd752a49e06e3dc9c2e71a", + "https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6", + "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", + "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", + "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", + "https://bcr.bazel.build/modules/rules_java/8.14.0/MODULE.bazel": "717717ed40cc69994596a45aec6ea78135ea434b8402fb91b009b9151dd65615", + "https://bcr.bazel.build/modules/rules_java/8.14.0/source.json": "8a88c4ca9e8759da53cddc88123880565c520503321e2566b4e33d0287a3d4bc", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", + "https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909", + "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", + "https://bcr.bazel.build/modules/rules_jvm_external/5.3/MODULE.bazel": "bf93870767689637164657731849fb887ad086739bd5d360d90007a581d5527d", + "https://bcr.bazel.build/modules/rules_jvm_external/6.1/MODULE.bazel": "75b5fec090dbd46cf9b7d8ea08cf84a0472d92ba3585b476f44c326eda8059c4", + "https://bcr.bazel.build/modules/rules_jvm_external/6.3/MODULE.bazel": "c998e060b85f71e00de5ec552019347c8bca255062c990ac02d051bb80a38df0", + "https://bcr.bazel.build/modules/rules_jvm_external/6.6/MODULE.bazel": "153042249c7060536dc95b6bb9f9bb8063b8a0b0cb7acdb381bddbc2374aed55", + "https://bcr.bazel.build/modules/rules_jvm_external/6.6/source.json": "b1d7ffc3877e5a76e6e48e6bce459cbb1712c90eba14861b112bd299587a534d", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.0/MODULE.bazel": "ef85697305025e5a61f395d4eaede272a5393cee479ace6686dba707de804d59", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel": "d269a01a18ee74d0335450b10f62c9ed81f2321d7958a2934e44272fe82dcef3", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/source.json": "2faa4794364282db7c06600b7e5e34867a564ae91bda7cae7c29c64e9466b7d5", + "https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0", + "https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d", + "https://bcr.bazel.build/modules/rules_license/1.0.0/MODULE.bazel": "a7fda60eefdf3d8c827262ba499957e4df06f659330bbe6cdbdb975b768bb65c", + "https://bcr.bazel.build/modules/rules_license/1.0.0/source.json": "a52c89e54cc311196e478f8382df91c15f7a2bfdf4c6cd0e2675cc2ff0b56efb", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", + "https://bcr.bazel.build/modules/rules_pkg/1.0.1/MODULE.bazel": "5b1df97dbc29623bccdf2b0dcd0f5cb08e2f2c9050aab1092fd39a41e82686ff", + "https://bcr.bazel.build/modules/rules_pkg/1.0.1/source.json": "bd82e5d7b9ce2d31e380dd9f50c111d678c3bdaca190cb76b0e1c71b05e1ba8a", + "https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7", + "https://bcr.bazel.build/modules/rules_proto/6.0.2/MODULE.bazel": "ce916b775a62b90b61888052a416ccdda405212b6aaeb39522f7dc53431a5e73", + "https://bcr.bazel.build/modules/rules_proto/7.0.2/MODULE.bazel": "bf81793bd6d2ad89a37a40693e56c61b0ee30f7a7fdbaf3eabbf5f39de47dea2", + "https://bcr.bazel.build/modules/rules_proto/7.0.2/source.json": "1e5e7260ae32ef4f2b52fd1d0de8d03b606a44c91b694d2f1afb1d3b28a48ce1", + "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f", + "https://bcr.bazel.build/modules/rules_python/0.23.1/MODULE.bazel": "49ffccf0511cb8414de28321f5fcf2a31312b47c40cc21577144b7447f2bf300", + "https://bcr.bazel.build/modules/rules_python/0.25.0/MODULE.bazel": "72f1506841c920a1afec76975b35312410eea3aa7b63267436bfb1dd91d2d382", + "https://bcr.bazel.build/modules/rules_python/0.28.0/MODULE.bazel": "cba2573d870babc976664a912539b320cbaa7114cd3e8f053c720171cde331ed", + "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", + "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", + "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", + "https://bcr.bazel.build/modules/rules_python/0.40.0/source.json": "939d4bd2e3110f27bfb360292986bb79fd8dcefb874358ccd6cdaa7bda029320", + "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", + "https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b", + "https://bcr.bazel.build/modules/rules_shell/0.3.0/source.json": "c55ed591aa5009401ddf80ded9762ac32c358d2517ee7820be981e2de9756cf3", + "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", + "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", + "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", + "https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c", + "https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7", + "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", + "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806", + "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198" + }, + "selectedYankedVersions": {}, + "moduleExtensions": { + "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { + "general": { + "bzlTransitiveDigest": "rL/34P1aFDq2GqVC2zCFgQ8nTuOC6ziogocpvG50Qz8=", + "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "com_github_jetbrains_kotlin_git": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_compiler_git_repository", + "attributes": { + "urls": [ + "https://github.com/JetBrains/kotlin/releases/download/v1.9.23/kotlin-compiler-1.9.23.zip" + ], + "sha256": "93137d3aab9afa9b27cb06a824c2324195c6b6f6179d8a8653f440f5bd58be88" + } + }, + "com_github_jetbrains_kotlin": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_capabilities_repository", + "attributes": { + "git_repository_name": "com_github_jetbrains_kotlin_git", + "compiler_version": "1.9.23" + } + }, + "com_github_google_ksp": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:ksp.bzl%ksp_compiler_plugin_repository", + "attributes": { + "urls": [ + "https://github.com/google/ksp/releases/download/1.9.23-1.0.20/artifacts.zip" + ], + "sha256": "ee0618755913ef7fd6511288a232e8fad24838b9af6ea73972a76e81053c8c2d", + "strip_version": "1.9.23-1.0.20" + } + }, + "com_github_pinterest_ktlint": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_file", + "attributes": { + "sha256": "01b2e0ef893383a50dbeb13970fe7fa3be36ca3e83259e01649945b09d736985", + "urls": [ + "https://github.com/pinterest/ktlint/releases/download/1.3.0/ktlint" + ], + "executable": true + } + }, + "rules_android": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "sha256": "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", + "strip_prefix": "rules_android-0.1.1", + "urls": [ + "https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip" + ] + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_kotlin+", + "bazel_tools", + "bazel_tools" + ] + ] + } + } + }, + "facts": {} +} diff --git a/mapstruct-on-bazel/README.md b/mapstruct-on-bazel/README.md new file mode 100644 index 00000000..c4d5fb1e --- /dev/null +++ b/mapstruct-on-bazel/README.md @@ -0,0 +1,8 @@ +# Using MapStruct with Bazel + +This example project shows how to use MapStruct with Bazel. +The sample code is using the one from `mapstruct-on-ant`. + +To build the project, run `bazel build //...` or `bazel build //mapstruct-on-bazel:all` + +To test the project, run `bazel test //...` or `bazel test //mapstruct-on-bazel:ConversionTest` diff --git a/mapstruct-on-bazel/src/main/java/org/mapstruct/example/Source.java b/mapstruct-on-bazel/src/main/java/org/mapstruct/example/Source.java new file mode 100644 index 00000000..234c6055 --- /dev/null +++ b/mapstruct-on-bazel/src/main/java/org/mapstruct/example/Source.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +public class Source { + + private int foo; + private Long bar; + private int qax; + private Long baz; + private int zip; + + public int getFoo() { + return foo; + } + + public void setFoo(int foo) { + this.foo = foo; + } + + public Long getBar() { + return bar; + } + + public void setBar(Long bar) { + this.bar = bar; + } + + public int getQax() { + return qax; + } + + public void setQax(int qax) { + this.qax = qax; + } + + public Long getBaz() { + return baz; + } + + public void setBaz(Long baz) { + this.baz = baz; + } + + public int getZip() { + return zip; + } + + public void setZip(int zip) { + this.zip = zip; + } +} diff --git a/mapstruct-on-bazel/src/main/java/org/mapstruct/example/SourceTargetMapper.java b/mapstruct-on-bazel/src/main/java/org/mapstruct/example/SourceTargetMapper.java new file mode 100644 index 00000000..79ebd8c7 --- /dev/null +++ b/mapstruct-on-bazel/src/main/java/org/mapstruct/example/SourceTargetMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper(SourceTargetMapper.class); + + @Mapping(target = "baz", source = "qax") + @Mapping(target = "qax", source = "baz") + Target sourceToTarget(Source source); + + @InheritInverseConfiguration + Source targetToSource(Target target); +} diff --git a/mapstruct-on-bazel/src/main/java/org/mapstruct/example/Target.java b/mapstruct-on-bazel/src/main/java/org/mapstruct/example/Target.java new file mode 100644 index 00000000..74848972 --- /dev/null +++ b/mapstruct-on-bazel/src/main/java/org/mapstruct/example/Target.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +public class Target { + + private Long foo; + private int bar; + private Long baz; + private int qax; + private String zip; + + public Long getFoo() { + return foo; + } + + public void setFoo(Long foo) { + this.foo = foo; + } + + public int getBar() { + return bar; + } + + public void setBar(int bar) { + this.bar = bar; + } + + public Long getBaz() { + return baz; + } + + public void setBaz(Long baz) { + this.baz = baz; + } + + public int getQax() { + return qax; + } + + public void setQax(int qax) { + this.qax = qax; + } + + public String getZip() { + return zip; + } + + public void setZip(String zip) { + this.zip = zip; + } +} diff --git a/mapstruct-on-bazel/src/test/java/org/mapstruct/example/ConversionTest.java b/mapstruct-on-bazel/src/test/java/org/mapstruct/example/ConversionTest.java new file mode 100644 index 00000000..44cbfe88 --- /dev/null +++ b/mapstruct-on-bazel/src/test/java/org/mapstruct/example/ConversionTest.java @@ -0,0 +1,80 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ConversionTest { + + @Test + public void shouldApplyConversions() { + Source source = new Source(); + source.setFoo(42); + source.setBar(23L); + source.setZip(73); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source); + + assertThat(target).isNotNull(); + assertThat(target.getFoo()).isEqualTo(42L); + assertThat(target.getBar()).isEqualTo(23); + assertThat(target.getZip()).isEqualTo("73"); + } + + @Test + public void shouldHandleNulls() { + Source source = new Source(); + Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source); + + assertThat(target).isNotNull(); + assertThat(target.getFoo()).isEqualTo(0L); + assertThat(target.getBar()).isEqualTo(0); + assertThat(target.getZip()).isEqualTo("0"); + } + + @Test + public void shouldApplyConversionsToMappedProperties() { + Source source = new Source(); + source.setQax(42); + source.setBaz(23L); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source); + + assertThat(target).isNotNull(); + assertThat(target.getBaz()).isEqualTo(42L); + assertThat(target.getQax()).isEqualTo(23); + } + + @Test + public void shouldApplyConversionsForReverseMapping() { + Target target = new Target(); + target.setFoo(42L); + target.setBar(23); + target.setZip("73"); + + Source source = SourceTargetMapper.INSTANCE.targetToSource(target); + + assertThat(source).isNotNull(); + assertThat(source.getFoo()).isEqualTo(42); + assertThat(source.getBar()).isEqualTo(23); + assertThat(source.getZip()).isEqualTo(73); + } + + @Test + public void shouldApplyConversionsToMappedPropertiesForReverseMapping() { + Target target = new Target(); + target.setQax(42); + target.setBaz(23L); + + Source source = SourceTargetMapper.INSTANCE.targetToSource(target); + + assertThat(source).isNotNull(); + assertThat(source.getBaz()).isEqualTo(42); + assertThat(source.getQax()).isEqualTo(23); + } +} diff --git a/mapstruct-on-gradle-protobuf3/build.gradle b/mapstruct-on-gradle-protobuf3/build.gradle new file mode 100644 index 00000000..faf1be79 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/build.gradle @@ -0,0 +1,14 @@ +plugins { + id 'java' + id "com.google.protobuf" version "0.9.4" +} + +subprojects { + repositories { + mavenCentral() + } + + ext { + mapstructVersion = "1.7.0.Beta1" + } +} diff --git a/mapstruct-on-gradle-protobuf3/gradle/wrapper/gradle-wrapper.jar b/mapstruct-on-gradle-protobuf3/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..e708b1c0 Binary files /dev/null and b/mapstruct-on-gradle-protobuf3/gradle/wrapper/gradle-wrapper.jar differ diff --git a/mapstruct-on-gradle-protobuf3/gradle/wrapper/gradle-wrapper.properties b/mapstruct-on-gradle-protobuf3/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..db9a6b82 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/mapstruct-on-gradle-protobuf3/gradlew b/mapstruct-on-gradle-protobuf3/gradlew new file mode 100755 index 00000000..4f906e0c --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/mapstruct-on-gradle-protobuf3/gradlew.bat b/mapstruct-on-gradle-protobuf3/gradlew.bat new file mode 100644 index 00000000..107acd32 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/mapstruct-on-gradle-protobuf3/settings.gradle b/mapstruct-on-gradle-protobuf3/settings.gradle new file mode 100644 index 00000000..541fd3a9 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = 'mapstruct-on-gradle-protobuf3' +rootProject.buildFileName = 'build.gradle' +include 'usage' +include 'spi-impl' \ No newline at end of file diff --git a/mapstruct-on-gradle-protobuf3/spi-impl/build.gradle b/mapstruct-on-gradle-protobuf3/spi-impl/build.gradle new file mode 100644 index 00000000..b39371e6 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/spi-impl/build.gradle @@ -0,0 +1,8 @@ +apply plugin: 'java' + +sourceCompatibility = JavaVersion.VERSION_1_8 + +dependencies { + implementation "org.mapstruct:mapstruct:$mapstructVersion" + implementation "org.mapstruct:mapstruct-processor:$mapstructVersion" +} diff --git a/mapstruct-on-gradle-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java b/mapstruct-on-gradle-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java new file mode 100644 index 00000000..398c094f --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/spi-impl/src/main/java/org/mapstruct/example/protobuf/ProtobufAccessorNamingStrategy.java @@ -0,0 +1,99 @@ +package org.mapstruct.example.protobuf; + +import java.util.List; +import java.util.Map; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; +import org.mapstruct.ap.spi.MapStructProcessingEnvironment; +import org.mapstruct.ap.spi.MethodType; + +/** + * @author Thomas Kratz + * @author Filip Hrisafov + */ +public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + + public static final String PROTOBUF_MESSAGE_OR_BUILDER = "com.google.protobuf.MessageOrBuilder"; + public static final String LIST_SUFFIX = "List"; + + protected TypeMirror protobufMesageOrBuilderType; + + @Override + public void init(MapStructProcessingEnvironment processingEnvironment) { + super.init(processingEnvironment); + + TypeElement typeElement = elementUtils.getTypeElement(PROTOBUF_MESSAGE_OR_BUILDER); + if (typeElement != null) { + protobufMesageOrBuilderType = typeElement.asType(); + } + } + + @Override + public String getElementName(ExecutableElement adderMethod) { + + String methodName = super.getElementName(adderMethod); + Element receiver = adderMethod.getEnclosingElement(); + if (receiver != null && protobufMesageOrBuilderType != null && typeUtils.isAssignable(receiver.asType(), protobufMesageOrBuilderType)) { + methodName += LIST_SUFFIX; + } + return methodName; + } + + @Override + public boolean isSetterMethod(ExecutableElement method) { + if ( super.isSetterMethod( method ) && !isProtoBufMethod( method ) && !isRemoveMethod( method ) + && !isMergeFrom( method ) ) { + return true; + } + return false; + } + + @Override + public boolean isGetterMethod(ExecutableElement method) { + if ( super.isGetterMethod( method ) && !isBuilderListMethod( method ) && !isGetAllFieldsMethod( method ) + && !isBuilderListMethod( method ) && !isValueListMethod( method ) ) { + return true; + } + return false; + } + + /* the following methods might be to crude for some use cases, more precise matching might be required */ + private boolean isProtoBufMethod(ExecutableElement method) { + String argTypeName = method.getParameters().get( 0 ).asType().toString(); + return argTypeName.startsWith( "com.google.protobuf" ); + } + + private boolean isRemoveMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + String argTypeName = method.getParameters().get( 0 ).asType().toString(); + return methodName.startsWith( "remove" ) && argTypeName.equals( "int" ); + } + + private boolean isBuilderListMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + String returnTypeName = typeUtils.erasure( method.getReturnType() ).toString(); + return methodName.endsWith( "BuilderList" ) && returnTypeName.equals( List.class.getName() ); + } + + private boolean isValueListMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + String returnTypeName = typeUtils.erasure( method.getReturnType() ).toString(); + return methodName.endsWith( "ValueList" ) && returnTypeName.equals( List.class.getName() ); + } + + private boolean isGetAllFieldsMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + String returnTypeName = typeUtils.erasure( method.getReturnType() ).toString(); + return "getAllFields".equals( methodName ) && returnTypeName.equals( Map.class.getName() ); + } + + private boolean isMergeFrom( ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + return "mergeFrom".equals( methodName ); + } + +} \ No newline at end of file diff --git a/mapstruct-on-gradle-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy b/mapstruct-on-gradle-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy new file mode 100644 index 00000000..93e2eb33 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/spi-impl/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy @@ -0,0 +1 @@ +org.mapstruct.example.protobuf.ProtobufAccessorNamingStrategy diff --git a/mapstruct-on-gradle-protobuf3/usage/build.gradle b/mapstruct-on-gradle-protobuf3/usage/build.gradle new file mode 100644 index 00000000..2f2162ca --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.google.protobuf' +apply plugin: 'java' + +sourceCompatibility = JavaVersion.VERSION_1_8 + +dependencies { + implementation project(':spi-impl') + implementation "org.mapstruct:mapstruct:$mapstructVersion" + implementation 'com.google.protobuf:protobuf-java:3.6.1' + + testImplementation 'junit:junit:4.13.1' + testAnnotationProcessor "org.mapstruct:mapstruct-processor:$mapstructVersion" + + annotationProcessor "org.mapstruct:mapstruct-processor:$mapstructVersion" + annotationProcessor project(':spi-impl') +} + +sourceSets { + main { + java { + srcDir file("${buildDir}/generated/source/proto") + } + } +} + +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:3.6.1" + } +} diff --git a/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java new file mode 100644 index 00000000..b8f0f2e1 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.mapper; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.ValueMapping; +import org.mapstruct.example.protobuf.Department; +import org.mapstruct.example.protobuf.Permission; +import org.mapstruct.example.protobuf.User; +import org.mapstruct.example.protobuf.UserProtos.DepartmentDTO; +import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; +import org.mapstruct.example.protobuf.UserProtos.UserDTO; +import org.mapstruct.factory.Mappers; + +/** + * @author Thomas Kratz + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +public interface UserMapper { + + UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); + + + @Mapping(target = "permissionsList", source = "permissions") + @Mapping(target = "mainDepartmentsList", source = "mainDepartments") + @Mapping(target = "departmentsList", source = "departments") + UserDTO map(User user); + + @Mapping(target = "permissions", source = "permissionsList") + @Mapping(target = "mainDepartments", source = "mainDepartmentsList") + @Mapping(target = "departments", source = "departmentsList") + User map(UserDTO userDTO); + + @ValueMapping(target = MappingConstants.NULL, source = "UNRECOGNIZED") + Permission map(PermissionDTO permissionDTO); + + PermissionDTO map(Permission perm); + + + Department map(DepartmentDTO departmentDTO); + DepartmentDTO map(Department department); +} diff --git a/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Department.java b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Department.java new file mode 100644 index 00000000..a4ae9c34 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Department.java @@ -0,0 +1,22 @@ +package org.mapstruct.example.protobuf; + +/** + * @author Thomas Kratz + */ +public class Department { + private String name; + + public Department() {} + + public Department(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java new file mode 100644 index 00000000..d0085a4d --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Permission.java @@ -0,0 +1,11 @@ +package org.mapstruct.example.protobuf; + +/** + * @author Thomas Kratz + */ +public enum Permission { + + ADMIN, + USER, + NONE +} diff --git a/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java new file mode 100644 index 00000000..6e779b32 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java @@ -0,0 +1,56 @@ +package org.mapstruct.example.protobuf; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Thomas Kratz + */ +public class User { + + private String id; + private String email; + private List permissions = new ArrayList<>(); + private List mainDepartments = new ArrayList<>(); + private List departments = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public List getPermissions() { + return permissions; + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } + + public List getDepartments() { + return departments; + } + + public void setDepartments(List departments) { + this.departments = departments; + } + + public List getMainDepartments() { + return mainDepartments; + } + + public void setMainDepartments(List mainDepartments) { + this.mainDepartments = mainDepartments; + } +} diff --git a/mapstruct-on-gradle-protobuf3/usage/src/main/proto/User.proto b/mapstruct-on-gradle-protobuf3/usage/src/main/proto/User.proto new file mode 100644 index 00000000..71c50b46 --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/src/main/proto/User.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + + +option java_package = "org.mapstruct.example.protobuf"; +option java_outer_classname = "UserProtos"; + +message UserDTO { + string id = 1; + string email = 2; + repeated PermissionDTO permissions = 3; + repeated DepartmentDTO main_departments = 4; + repeated DepartmentDTO departments = 5; +} + +enum PermissionDTO { + NONE = 0; + USER = 1; + ADMIN = 2; +} + +message DepartmentDTO { + string name = 1; +} + diff --git a/mapstruct-on-gradle-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-on-gradle-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java new file mode 100644 index 00000000..ac8c0e2e --- /dev/null +++ b/mapstruct-on-gradle-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import com.google.protobuf.InvalidProtocolBufferException; +import org.junit.Assert; +import org.junit.Test; +import org.mapstruct.example.mapper.UserMapper; +import org.mapstruct.example.protobuf.Department; +import org.mapstruct.example.protobuf.Permission; +import org.mapstruct.example.protobuf.User; +import org.mapstruct.example.protobuf.UserProtos.UserDTO; + +/** + * @author Thomas Kratz + */ +public class ProtobufTest { + /** + * Test if everything is working when sources are present + */ + @Test + public void test() throws InvalidProtocolBufferException { + User user = new User(); + user.setId(""); + user.setEmail("test"); + user.getPermissions().add(Permission.ADMIN); + user.getMainDepartments().add(new Department("SALES")); + user.getDepartments().add(new Department("AFTER_MARKET")); + + UserDTO dto = UserMapper.INSTANCE.map(user); + UserDTO deserialized = UserDTO.parseFrom(dto.toByteArray()); + User back = UserMapper.INSTANCE.map(deserialized); + + Assert.assertEquals("", back.getId()); + Assert.assertEquals("test", back.getEmail()); + Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); + + Assert.assertEquals(1,back.getMainDepartments().size()); + Assert.assertEquals("SALES",back.getMainDepartments().get(0).getName()); + + Assert.assertEquals(1,back.getDepartments().size()); + Assert.assertEquals("AFTER_MARKET",back.getDepartments().get(0).getName()); + } + + + @Test + public void testNulls() throws InvalidProtocolBufferException { + User user = new User(); + // if id is null we should get the default empty string + user.setEmail("test"); + user.getPermissions().add(Permission.ADMIN); + + UserDTO dto = UserMapper.INSTANCE.map(user); + UserDTO deserialized = UserDTO.parseFrom(dto.toByteArray()); + User back = UserMapper.INSTANCE.map(deserialized); + + Assert.assertEquals("", back.getId()); + Assert.assertEquals("test", back.getEmail()); + Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); + } +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/build.gradle b/mapstruct-on-gradle-testcp-with-lombok/build.gradle new file mode 100644 index 00000000..7ae0b3ff --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'java' + id "io.freefair.lombok" version "8.3" +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + + annotationProcessor 'org.mapstruct:mapstruct-processor:1.7.0.Beta1' + implementation 'org.mapstruct:mapstruct:1.7.0.Beta1' + + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.7.0.Beta1' +} + +lombok { + version = "1.18.30" +} + +test { + useJUnitPlatform() +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/gradle/wrapper/gradle-wrapper.jar b/mapstruct-on-gradle-testcp-with-lombok/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..e708b1c0 Binary files /dev/null and b/mapstruct-on-gradle-testcp-with-lombok/gradle/wrapper/gradle-wrapper.jar differ diff --git a/mapstruct-on-gradle-testcp-with-lombok/gradle/wrapper/gradle-wrapper.properties b/mapstruct-on-gradle-testcp-with-lombok/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..db9a6b82 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/mapstruct-on-gradle-testcp-with-lombok/gradlew b/mapstruct-on-gradle-testcp-with-lombok/gradlew new file mode 100755 index 00000000..4f906e0c --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/mapstruct-on-gradle-testcp-with-lombok/gradlew.bat b/mapstruct-on-gradle-testcp-with-lombok/gradlew.bat new file mode 100644 index 00000000..107acd32 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/mapstruct-on-gradle-testcp-with-lombok/settings.gradle b/mapstruct-on-gradle-testcp-with-lombok/settings.gradle new file mode 100644 index 00000000..78c2a92c --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'mapstruct-gradle-in-testclasses' + diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/mapper/SourceTargetMapper.java b/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/mapper/SourceTargetMapper.java new file mode 100644 index 00000000..7c6cfe24 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/mapper/SourceTargetMapper.java @@ -0,0 +1,11 @@ +package de.beanfactory.samples.mapstruct.mapper; + +import de.beanfactory.samples.mapstruct.model.SourceBean; +import de.beanfactory.samples.mapstruct.model.TargetBean; +import org.mapstruct.Mapper; + +@Mapper +public interface SourceTargetMapper { + + public TargetBean map(SourceBean source); +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/model/SourceBean.java b/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/model/SourceBean.java new file mode 100644 index 00000000..0a67ee64 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/model/SourceBean.java @@ -0,0 +1,14 @@ +package de.beanfactory.samples.mapstruct.model; + +import lombok.Data; + +@Data +public class SourceBean { + int id; + String data; + + public SourceBean(int id, String data) { + this.id = id; + this.data = data; + } +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/model/TargetBean.java b/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/model/TargetBean.java new file mode 100644 index 00000000..262e882d --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/main/java/de/beanfactory/samples/mapstruct/model/TargetBean.java @@ -0,0 +1,9 @@ +package de.beanfactory.samples.mapstruct.model; + +import lombok.Data; + +@Data +public class TargetBean { + int id; + String data; +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/SourceTargetMapperTest.java b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/SourceTargetMapperTest.java new file mode 100644 index 00000000..ef86e841 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/SourceTargetMapperTest.java @@ -0,0 +1,23 @@ +package de.beanfactory.samples.mapstruct.mapper; + +import de.beanfactory.samples.mapstruct.model.SourceBean; +import de.beanfactory.samples.mapstruct.model.TargetBean; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; + +import static org.junit.jupiter.api.Assertions.*; + +class SourceTargetMapperTest { + + @Test + void itShouldMapSourceToTargetBean() { + SourceTargetMapper mapper = Mappers.getMapper(SourceTargetMapper.class); + + SourceBean sourceBean = new SourceBean(0, "datastring"); + TargetBean targetBean = mapper.map(sourceBean); + + assertEquals(sourceBean.getId(), targetBean.getId()); + assertEquals(sourceBean.getData(), targetBean.getData()); + } + +} \ No newline at end of file diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/TestSourceMapper.java b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/TestSourceMapper.java new file mode 100644 index 00000000..8f785931 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/TestSourceMapper.java @@ -0,0 +1,11 @@ +package de.beanfactory.samples.mapstruct.mapper; + +import de.beanfactory.samples.mapstruct.model.TestSourceBean; +import de.beanfactory.samples.mapstruct.model.TestTargetBean; +import org.mapstruct.Mapper; + +@Mapper +public interface TestSourceMapper { + + TestTargetBean map(TestSourceBean testSource); +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/TestSourceTargetMapperTest.java b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/TestSourceTargetMapperTest.java new file mode 100644 index 00000000..56d5d584 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/mapper/TestSourceTargetMapperTest.java @@ -0,0 +1,25 @@ +package de.beanfactory.samples.mapstruct.mapper; + +import de.beanfactory.samples.mapstruct.model.SourceBean; +import de.beanfactory.samples.mapstruct.model.TargetBean; +import de.beanfactory.samples.mapstruct.model.TestSourceBean; +import de.beanfactory.samples.mapstruct.model.TestTargetBean; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TestSourceTargetMapperTest { + + @Test + void itShouldMapTestSourceToTestTargetBean() { + TestSourceMapper mapper = Mappers.getMapper(TestSourceMapper.class); + + TestSourceBean sourceBean = new TestSourceBean(0, "datastring"); + TestTargetBean targetBean = mapper.map(sourceBean); + + assertEquals(sourceBean.getId(), targetBean.getId()); + assertEquals(sourceBean.getData(), targetBean.getData()); + } + +} \ No newline at end of file diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/model/TestSourceBean.java b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/model/TestSourceBean.java new file mode 100644 index 00000000..314a0d98 --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/model/TestSourceBean.java @@ -0,0 +1,14 @@ +package de.beanfactory.samples.mapstruct.model; + +import lombok.Data; + +@Data +public class TestSourceBean { + private int id; + private String data; + + public TestSourceBean(int id, String data) { + this.id = id; + this.data = data; + } +} diff --git a/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/model/TestTargetBean.java b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/model/TestTargetBean.java new file mode 100644 index 00000000..79ac03dd --- /dev/null +++ b/mapstruct-on-gradle-testcp-with-lombok/src/test/java/de/beanfactory/samples/mapstruct/model/TestTargetBean.java @@ -0,0 +1,10 @@ +package de.beanfactory.samples.mapstruct.model; + +import java.util.Objects; +import lombok.Data; + +@Data +public class TestTargetBean { + private int id; + private String data; +} diff --git a/mapstruct-on-gradle/build.gradle b/mapstruct-on-gradle/build.gradle index 83b4a417..27bf4c75 100644 --- a/mapstruct-on-gradle/build.gradle +++ b/mapstruct-on-gradle/build.gradle @@ -1,6 +1,5 @@ plugins { id 'java' - id 'net.ltgt.apt' version '0.9' } repositories { @@ -8,20 +7,16 @@ repositories { mavenLocal() } -task wrapper(type: Wrapper) { - gradleVersion = '3.4' -} - ext { - mapstructVersion = "1.3.0.Beta1" + mapstructVersion = "1.7.0.Beta1" } sourceCompatibility = JavaVersion.VERSION_1_8 dependencies { - compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}" - testCompile 'org.testng:testng:6.10', 'org.easytesting:fest-assert:1.4' - apt "org.mapstruct:mapstruct-processor:${mapstructVersion}" + implementation "org.mapstruct:mapstruct:${mapstructVersion}" + testImplementation "org.testng:testng:6.10", "org.easytesting:fest-assert:1.4" + annotationProcessor "org.mapstruct:mapstruct-processor:1.7.0.Beta1" } tasks.withType(JavaCompile) { diff --git a/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.jar b/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.jar index 05ef575b..e708b1c0 100644 Binary files a/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.jar and b/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.properties b/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.properties index 6b3ef346..db9a6b82 100644 --- a/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.properties +++ b/mapstruct-on-gradle/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Feb 25 23:47:27 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip diff --git a/mapstruct-on-gradle/gradlew b/mapstruct-on-gradle/gradlew index 9d82f789..4f906e0c 100755 --- a/mapstruct-on-gradle/gradlew +++ b/mapstruct-on-gradle/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,28 +75,14 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -85,7 +106,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -105,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -134,27 +156,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/mapstruct-on-gradle/gradlew.bat b/mapstruct-on-gradle/gradlew.bat index 8a0b282a..107acd32 100644 --- a/mapstruct-on-gradle/gradlew.bat +++ b/mapstruct-on-gradle/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,20 +24,23 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,34 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/mapstruct-on-gradle/settings.gradle b/mapstruct-on-gradle/settings.gradle new file mode 100644 index 00000000..805cfaed --- /dev/null +++ b/mapstruct-on-gradle/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'mapstruct-gradle' + diff --git a/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Source.java b/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Source.java index daf483c2..234c6055 100644 --- a/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Source.java +++ b/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-on-gradle/src/main/java/org/mapstruct/example/SourceTargetMapper.java b/mapstruct-on-gradle/src/main/java/org/mapstruct/example/SourceTargetMapper.java index c0abe930..79ebd8c7 100644 --- a/mapstruct-on-gradle/src/main/java/org/mapstruct/example/SourceTargetMapper.java +++ b/mapstruct-on-gradle/src/main/java/org/mapstruct/example/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; @@ -28,8 +15,8 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper(SourceTargetMapper.class); - @Mapping(source = "qax", target = "baz") - @Mapping(source = "baz", target = "qax") + @Mapping(target = "baz", source = "qax") + @Mapping(target = "qax", source = "baz") Target sourceToTarget(Source source); @InheritInverseConfiguration diff --git a/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Target.java b/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Target.java index 8f704bab..74848972 100644 --- a/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Target.java +++ b/mapstruct-on-gradle/src/main/java/org/mapstruct/example/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-on-gradle/src/test/java/org/mapstruct/example/ConversionTest.java b/mapstruct-on-gradle/src/test/java/org/mapstruct/example/ConversionTest.java index 9e5ac9b3..a174dbba 100644 --- a/mapstruct-on-gradle/src/test/java/org/mapstruct/example/ConversionTest.java +++ b/mapstruct-on-gradle/src/test/java/org/mapstruct/example/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-protobuf3/pom.xml b/mapstruct-protobuf3/pom.xml index edb97317..d5fe4fd2 100644 --- a/mapstruct-protobuf3/pom.xml +++ b/mapstruct-protobuf3/pom.xml @@ -1,22 +1,9 @@ pom - 1.4.0.Final - 0.5.0 - 3.2.0 - 1.3.0.Beta1 + UTF-8 + 1.7.1 + 0.6.1 + 4.27.3 + 1.7.0.Beta1 1.8 1.8 @@ -46,7 +34,7 @@ org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -59,7 +47,7 @@ junit junit - 4.12 + 4.13.1 @@ -70,7 +58,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 diff --git a/mapstruct-protobuf3/spi-impl/pom.xml b/mapstruct-protobuf3/spi-impl/pom.xml index 7bfd7d5f..86a73346 100644 --- a/mapstruct-protobuf3/spi-impl/pom.xml +++ b/mapstruct-protobuf3/spi-impl/pom.xml @@ -1,22 +1,9 @@ org.mapstruct - mapstruct-jdk8 + mapstruct com.google.protobuf @@ -45,7 +32,7 @@ junit junit - 4.12 + 4.13.1 test @@ -72,16 +59,17 @@ compile-custom - com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} + com.google.protobuf:protoc:${protobuf.java.version}:exe:${os.detected.classifier} grpc-java - io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier} + io.grpc:protoc-gen-grpc-java:1.66.0:exe:${os.detected.classifier} + org.apache.maven.plugins maven-compiler-plugin diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java index aee75680..b8f0f2e1 100644 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/mapper/UserMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; @@ -24,8 +11,10 @@ import org.mapstruct.MappingConstants; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.ValueMapping; +import org.mapstruct.example.protobuf.Department; import org.mapstruct.example.protobuf.Permission; import org.mapstruct.example.protobuf.User; +import org.mapstruct.example.protobuf.UserProtos.DepartmentDTO; import org.mapstruct.example.protobuf.UserProtos.PermissionDTO; import org.mapstruct.example.protobuf.UserProtos.UserDTO; import org.mapstruct.factory.Mappers; @@ -40,15 +29,22 @@ public interface UserMapper { UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); - @Mapping(source = "permissions", target = "permissionsList") + @Mapping(target = "permissionsList", source = "permissions") + @Mapping(target = "mainDepartmentsList", source = "mainDepartments") + @Mapping(target = "departmentsList", source = "departments") UserDTO map(User user); - @Mapping(source = "permissionsList", target = "permissions") + @Mapping(target = "permissions", source = "permissionsList") + @Mapping(target = "mainDepartments", source = "mainDepartmentsList") + @Mapping(target = "departments", source = "departmentsList") User map(UserDTO userDTO); - @ValueMapping(source = "UNRECOGNIZED", target = MappingConstants.NULL) + @ValueMapping(target = MappingConstants.NULL, source = "UNRECOGNIZED") Permission map(PermissionDTO permissionDTO); PermissionDTO map(Permission perm); + + Department map(DepartmentDTO departmentDTO); + DepartmentDTO map(Department department); } diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Department.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Department.java new file mode 100644 index 00000000..a4ae9c34 --- /dev/null +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/Department.java @@ -0,0 +1,22 @@ +package org.mapstruct.example.protobuf; + +/** + * @author Thomas Kratz + */ +public class Department { + private String name; + + public Department() {} + + public Department(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java index b95dd9e4..6e779b32 100644 --- a/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java +++ b/mapstruct-protobuf3/usage/src/main/java/org/mapstruct/example/protobuf/User.java @@ -11,6 +11,8 @@ public class User { private String id; private String email; private List permissions = new ArrayList<>(); + private List mainDepartments = new ArrayList<>(); + private List departments = new ArrayList<>(); public String getId() { return id; @@ -35,4 +37,20 @@ public List getPermissions() { public void setPermissions(List permissions) { this.permissions = permissions; } + + public List getDepartments() { + return departments; + } + + public void setDepartments(List departments) { + this.departments = departments; + } + + public List getMainDepartments() { + return mainDepartments; + } + + public void setMainDepartments(List mainDepartments) { + this.mainDepartments = mainDepartments; + } } diff --git a/mapstruct-protobuf3/usage/src/main/proto/User.proto b/mapstruct-protobuf3/usage/src/main/proto/User.proto index bcb8652c..71c50b46 100644 --- a/mapstruct-protobuf3/usage/src/main/proto/User.proto +++ b/mapstruct-protobuf3/usage/src/main/proto/User.proto @@ -8,10 +8,17 @@ message UserDTO { string id = 1; string email = 2; repeated PermissionDTO permissions = 3; + repeated DepartmentDTO main_departments = 4; + repeated DepartmentDTO departments = 5; } enum PermissionDTO { NONE = 0; USER = 1; ADMIN = 2; -} \ No newline at end of file +} + +message DepartmentDTO { + string name = 1; +} + diff --git a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java index 399fbe83..ac8c0e2e 100644 --- a/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java +++ b/mapstruct-protobuf3/usage/src/test/java/org/mapstruct/example/ProtobufTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; @@ -22,6 +9,7 @@ import org.junit.Assert; import org.junit.Test; import org.mapstruct.example.mapper.UserMapper; +import org.mapstruct.example.protobuf.Department; import org.mapstruct.example.protobuf.Permission; import org.mapstruct.example.protobuf.User; import org.mapstruct.example.protobuf.UserProtos.UserDTO; @@ -39,6 +27,8 @@ public void test() throws InvalidProtocolBufferException { user.setId(""); user.setEmail("test"); user.getPermissions().add(Permission.ADMIN); + user.getMainDepartments().add(new Department("SALES")); + user.getDepartments().add(new Department("AFTER_MARKET")); UserDTO dto = UserMapper.INSTANCE.map(user); UserDTO deserialized = UserDTO.parseFrom(dto.toByteArray()); @@ -47,6 +37,12 @@ public void test() throws InvalidProtocolBufferException { Assert.assertEquals("", back.getId()); Assert.assertEquals("test", back.getEmail()); Assert.assertTrue(back.getPermissions().contains(Permission.ADMIN)); + + Assert.assertEquals(1,back.getMainDepartments().size()); + Assert.assertEquals("SALES",back.getMainDepartments().get(0).getName()); + + Assert.assertEquals(1,back.getDepartments().size()); + Assert.assertEquals("AFTER_MARKET",back.getDepartments().get(0).getName()); } diff --git a/mapstruct-quarkus/.mvn/wrapper/MavenWrapperDownloader.java b/mapstruct-quarkus/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 00000000..b901097f --- /dev/null +++ b/mapstruct-quarkus/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/mapstruct-quarkus/.mvn/wrapper/maven-wrapper.jar b/mapstruct-quarkus/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..0d5e6498 Binary files /dev/null and b/mapstruct-quarkus/.mvn/wrapper/maven-wrapper.jar differ diff --git a/mapstruct-quarkus/.mvn/wrapper/maven-wrapper.properties b/mapstruct-quarkus/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..642d572c --- /dev/null +++ b/mapstruct-quarkus/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/mapstruct-quarkus/README.md b/mapstruct-quarkus/README.md new file mode 100644 index 00000000..1cde25b6 --- /dev/null +++ b/mapstruct-quarkus/README.md @@ -0,0 +1,89 @@ +# MapStruct + Quarkus + +This example demonstrates how easy it is to use MapStruct in a [Quarkus](https://quarkus.io) application. + +The example was basically built with the following steps: + +1. Create a new Quarkus application + + ``` + mvn io.quarkus:quarkus-maven-plugin:1.0.1.Final:create \ + -DprojectGroupId=org.mapstruct.examples.quarkus \ + -DprojectArtifactId=mapstruct-examples-quarkus \ + -DclassName="org.mapstruct.example.quarkus.PersonResource" \ + -Dpath="/person" \ + -Dextensions="resteasy-jsonb" + ``` + +2. Add `mapstruct` as a dependency + + ```xml + + org.mapstruct + mapstruct + ${org.mapstruct.version} + provided + + ``` + +3. Add the `mapstruct-processor` as a regular `provided` scoped dependency and *not* as described in the +[reference guide](http://mapstruct.org/documentation/dev/reference/html/#_apache_maven) + + ```xml + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + provided + + ``` + +4. Set CDI as the default component-model (see [reference guide](http://mapstruct.org/documentation/dev/reference/html/#configuration-options)) +5. Define a mapper and inject it with `@Inject` in the service + +That's it! + +### Native images + +As MapStruct is not using reflection within the mappers native images are supported as long as CDI is used to retrieve the mappers. +Just try to package your Quarkus application in a native image and feel the speed! + +``` +mvn package -Dnative +``` + +In case you prefer to use `Mappers.getMapper(...)` be aware that this is not automatically supported by native images. Internally the `getMapper` method uses reflection to +retrieve the mapper implementation. +This is the only place where MapStruct uses reflection and thus it causes issues with native images. + +There are some workarounds by defining additional metadata used during native image creation by GraalVM. For example you can create a `Feature` as described +[here](https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md) and register all you mapper implementations and their constructor(s). + +For example if you just have a `PersonMapper` the feature might look like this: + +```java +@AutomaticFeature +class MapstructMapperFeature implements Feature { + public void beforeAnalysis(BeforeAnalysisAccess access) { + try { + Class mapperClass = Class.forName( "org.mapstruct.example.quarkus.mapper.PersonMapperImpl" ); + RuntimeReflection.register( mapperClass ); + RuntimeReflection.register( mapperClass.getConstructors() ); + } + catch ( ClassNotFoundException e ) { + throw new RuntimeException( e ); + } + } +} +``` + + +### One drawback + +When using the Quarkus dev mode the mapper will automatically be (re)generated in case you make change to the `@Mapper` annotated class. +Changing a dependent class (like `PersonDto` in this example) will not (re)generate the mapper implementation. + +As a workaround you can quit the dev-mode, recompile and start the application once again or you can make a (temporary) change to the `@Mapper` annotated class so that it +will be picked up and a valid implementation will be generated. + +*Pay attention*: You have to add the mapstruct-processor as described above and *not* using the `maven-compile-plugin`. diff --git a/mapstruct-quarkus/mvnw b/mapstruct-quarkus/mvnw new file mode 100755 index 00000000..d2f0ea38 --- /dev/null +++ b/mapstruct-quarkus/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mapstruct-quarkus/mvnw.cmd b/mapstruct-quarkus/mvnw.cmd new file mode 100644 index 00000000..b26ab24f --- /dev/null +++ b/mapstruct-quarkus/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/mapstruct-quarkus/pom.xml b/mapstruct-quarkus/pom.xml new file mode 100644 index 00000000..89390e3c --- /dev/null +++ b/mapstruct-quarkus/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + org.mapstruct.examples.quarkus + mapstruct-examples-quarkus + 1.0-SNAPSHOT + + + 3.14.1 + true + 1.8 + 1.8 + UTF-8 + UTF-8 + 1.0.1.Final + quarkus-bom + io.quarkus + 1.13.6.Final + 1.13.6.Final + 3.0.0-M5 + + 1.7.0.Beta1 + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jsonb + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + provided + + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + + quarkus-build + + build + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + + diff --git a/mapstruct-quarkus/src/main/docker/Dockerfile.jvm b/mapstruct-quarkus/src/main/docker/Dockerfile.jvm new file mode 100644 index 00000000..f185a1e5 --- /dev/null +++ b/mapstruct-quarkus/src/main/docker/Dockerfile.jvm @@ -0,0 +1,54 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/getting-started-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/getting-started-jvm +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=1001 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=1001 target/quarkus-app/*.jar /deployments/ +COPY --chown=1001 target/quarkus-app/app/ /deployments/app/ +COPY --chown=1001 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] diff --git a/mapstruct-quarkus/src/main/docker/Dockerfile.legacy-jar b/mapstruct-quarkus/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 00000000..16b4dc7e --- /dev/null +++ b/mapstruct-quarkus/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,51 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/getting-started-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/getting-started-legacy-jar +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/app.jar + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] diff --git a/mapstruct-quarkus/src/main/docker/Dockerfile.native b/mapstruct-quarkus/src/main/docker/Dockerfile.native new file mode 100644 index 00000000..7400c006 --- /dev/null +++ b/mapstruct-quarkus/src/main/docker/Dockerfile.native @@ -0,0 +1,27 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode +# +# Before building the container image run: +# +# ./mvnw package -Pnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/getting-started . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/mapstruct-quarkus/src/main/docker/Dockerfile.native-distroless b/mapstruct-quarkus/src/main/docker/Dockerfile.native-distroless new file mode 100644 index 00000000..634552f9 --- /dev/null +++ b/mapstruct-quarkus/src/main/docker/Dockerfile.native-distroless @@ -0,0 +1,23 @@ +#### +# This Dockerfile is used in order to build a distroless container that runs the Quarkus application in native (no JVM) mode +# +# Before building the container image run: +# +# ./mvnw package -Pnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-distroless -t quarkus/getting-started . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started +# +### +FROM quay.io/quarkus/quarkus-distroless-image:1.0 +COPY target/*-runner /application + +EXPOSE 8080 +USER nonroot + +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/PersonResource.java b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/PersonResource.java new file mode 100644 index 00000000..f247eb33 --- /dev/null +++ b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/PersonResource.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.mapstruct.example.quarkus.mapper.PersonMapper; +import org.mapstruct.example.quarkus.dto.PersonDto; +import org.mapstruct.example.quarkus.service.PersonService; + +@Path("/person") +public class PersonResource { + + @Inject + PersonService personService; + + @Inject + PersonMapper personMapper; + + @GET + @Produces(MediaType.APPLICATION_JSON) + public PersonDto loadPerson() { + return personMapper.toResource( personService.loadPerson() ); + } +} \ No newline at end of file diff --git a/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/dto/PersonDto.java b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/dto/PersonDto.java new file mode 100644 index 00000000..e8aae41b --- /dev/null +++ b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/dto/PersonDto.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus.dto; + +public class PersonDto { + private String firstname; + private String surname; + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } +} diff --git a/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/mapper/PersonMapper.java b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/mapper/PersonMapper.java new file mode 100644 index 00000000..56e7baed --- /dev/null +++ b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/mapper/PersonMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.example.quarkus.dto.PersonDto; +import org.mapstruct.example.quarkus.service.Person; + +@Mapper(config = QuarkusMappingConfig.class) +public interface PersonMapper { + @Mapping(target = "surname", source = "lastname") + PersonDto toResource(Person person); +} diff --git a/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/mapper/QuarkusMappingConfig.java b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/mapper/QuarkusMappingConfig.java new file mode 100644 index 00000000..1973900b --- /dev/null +++ b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/mapper/QuarkusMappingConfig.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus.mapper; + +import org.mapstruct.MapperConfig; + +@MapperConfig(componentModel = "cdi") +interface QuarkusMappingConfig { +} diff --git a/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/service/Person.java b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/service/Person.java new file mode 100644 index 00000000..8f16235c --- /dev/null +++ b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/service/Person.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus.service; + +public class Person { + private String firstname; + private String lastname; + + public Person(String firstname, String lastname) { + this.firstname = firstname; + this.lastname = lastname; + } + + public String getFirstname() { + return firstname; + } + + public String getLastname() { + return lastname; + } +} diff --git a/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/service/PersonService.java b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/service/PersonService.java new file mode 100644 index 00000000..b8e138ce --- /dev/null +++ b/mapstruct-quarkus/src/main/java/org/mapstruct/example/quarkus/service/PersonService.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus.service; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class PersonService { + + public Person loadPerson() { + return new Person("Bob", "Miller"); + } + +} diff --git a/mapstruct-quarkus/src/test/java/org/mapstruct/example/quarkus/NativePersonResourceIT.java b/mapstruct-quarkus/src/test/java/org/mapstruct/example/quarkus/NativePersonResourceIT.java new file mode 100644 index 00000000..9f2d3c3b --- /dev/null +++ b/mapstruct-quarkus/src/test/java/org/mapstruct/example/quarkus/NativePersonResourceIT.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +public class NativePersonResourceIT extends PersonResourceTest { + + // Execute the same tests but in native mode. +} diff --git a/mapstruct-quarkus/src/test/java/org/mapstruct/example/quarkus/PersonResourceTest.java b/mapstruct-quarkus/src/test/java/org/mapstruct/example/quarkus/PersonResourceTest.java new file mode 100644 index 00000000..c183645e --- /dev/null +++ b/mapstruct-quarkus/src/test/java/org/mapstruct/example/quarkus/PersonResourceTest.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example.quarkus; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +@QuarkusTest +public class PersonResourceTest { + + @Test + public void testPersonEndpoint() { + given() + .when().get("/person") + .then() + .statusCode(200) + .body( "firstname", is("Bob") ) + .body("surname", is("Miller") ); + } + +} \ No newline at end of file diff --git a/mapstruct-record/pom.xml b/mapstruct-record/pom.xml new file mode 100644 index 00000000..7564c43a --- /dev/null +++ b/mapstruct-record/pom.xml @@ -0,0 +1,105 @@ + + + + 4.0.0 + + org.mapstruct.examples.record + mapstruct-examples-record + 1.0-SNAPSHOT + + jar + + + UTF-8 + 16 + ${java.version} + ${java.version} + ${java.version} + 1.7.0.Beta1 + + + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + junit + junit + test + 4.13.1 + + + org.assertj + assertj-core + 3.27.7 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + + + + + + java17 + + 17 + + + 17 + + + + + + + sonatype-oss-snapshot + http://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + diff --git a/mapstruct-record/src/main/java/org/mapstruct/example/CustomerDto.java b/mapstruct-record/src/main/java/org/mapstruct/example/CustomerDto.java new file mode 100644 index 00000000..a426cde9 --- /dev/null +++ b/mapstruct-record/src/main/java/org/mapstruct/example/CustomerDto.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +/** + * @author Filip Hrisafov + */ +public record CustomerDto(String name, String email) { + +} diff --git a/mapstruct-record/src/main/java/org/mapstruct/example/CustomerEntity.java b/mapstruct-record/src/main/java/org/mapstruct/example/CustomerEntity.java new file mode 100644 index 00000000..77515328 --- /dev/null +++ b/mapstruct-record/src/main/java/org/mapstruct/example/CustomerEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +/** + * @author Filip Hrisafov + */ +public class CustomerEntity { + + private String name; + private String mail; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } +} diff --git a/mapstruct-record/src/main/java/org/mapstruct/example/CustomerMapper.java b/mapstruct-record/src/main/java/org/mapstruct/example/CustomerMapper.java new file mode 100644 index 00000000..99dc71a7 --- /dev/null +++ b/mapstruct-record/src/main/java/org/mapstruct/example/CustomerMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(target = "mail", source = "email") + CustomerEntity fromRecord(CustomerDto record); + + @InheritInverseConfiguration + CustomerDto toRecord(CustomerEntity entity); + +} diff --git a/mapstruct-record/src/test/java/org/mapstruct/example/CustomerMapperTest.java b/mapstruct-record/src/test/java/org/mapstruct/example/CustomerMapperTest.java new file mode 100644 index 00000000..1f917eb7 --- /dev/null +++ b/mapstruct-record/src/test/java/org/mapstruct/example/CustomerMapperTest.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.example; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +public class CustomerMapperTest { + + @Test + public void mapRecords() { + CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); + } + + @Test + public void mapToRecords() { + CustomerEntity entity = new CustomerEntity(); + entity.setName( "Fozzie" ); + entity.setMail( "fozzie@test.com" ); + + CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity ); + + assertThat( customer ).isNotNull(); + assertThat( customer.name() ).isEqualTo( "Fozzie" ); + assertThat( customer.email() ).isEqualTo( "fozzie@test.com" ); + } +} diff --git a/mapstruct-rounding/pom.xml b/mapstruct-rounding/pom.xml index d6e14553..b5e6bd4c 100644 --- a/mapstruct-rounding/pom.xml +++ b/mapstruct-rounding/pom.xml @@ -1,22 +1,9 @@ @@ -26,7 +13,8 @@ 1.0.0 - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 @@ -39,7 +27,7 @@ junit junit - 4.12 + 4.13.1 test @@ -50,7 +38,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 1.8 1.8 diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java index d0881335..b77c892b 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java index 4e791f08..7f88c3de 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/dto/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index 69e5da1d..3db7935c 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -1,27 +1,13 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.Source; import org.mapstruct.example.dto.Target; import org.mapstruct.example.mapper.util.RoundingUtil; @@ -35,10 +21,8 @@ public interface SourceTargetMapper { SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); - @Mappings( { - @Mapping( target = "bd2", qualifiedBy = Fraction2.class ), - @Mapping( target = "bd3", qualifiedBy = Fraction3.class ), - @Mapping( target = "bdUnConstrained" ) - } ) + @Mapping( target = "bd2", qualifiedBy = Fraction2.class ) + @Mapping( target = "bd3", qualifiedBy = Fraction3.class ) + @Mapping( target = "bdUnConstrained" ) Target toTarget( Source s ); } diff --git a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/util/RoundingUtil.java b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/util/RoundingUtil.java index 1dab5824..8692f229 100644 --- a/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/util/RoundingUtil.java +++ b/mapstruct-rounding/src/main/java/org/mapstruct/example/mapper/util/RoundingUtil.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper.util; diff --git a/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index 81a30981..a6eb0756 100644 --- a/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-rounding/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-spi-accessor-naming/pom.xml b/mapstruct-spi-accessor-naming/pom.xml index 818acc93..1ed623a8 100644 --- a/mapstruct-spi-accessor-naming/pom.xml +++ b/mapstruct-spi-accessor-naming/pom.xml @@ -1,22 +1,9 @@ @@ -28,7 +15,8 @@ pom - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 1.8 1.8 @@ -42,7 +30,7 @@ org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -55,7 +43,7 @@ junit junit - 4.12 + 4.13.1 @@ -66,7 +54,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 diff --git a/mapstruct-spi-accessor-naming/spi-impl/pom.xml b/mapstruct-spi-accessor-naming/spi-impl/pom.xml index fec57fc0..16df89b5 100644 --- a/mapstruct-spi-accessor-naming/spi-impl/pom.xml +++ b/mapstruct-spi-accessor-naming/spi-impl/pom.xml @@ -1,22 +1,9 @@ diff --git a/mapstruct-spi-accessor-naming/spi-impl/src/main/java/org/mapstruct/example/spi/CustomAccessorNamingStrategy.java b/mapstruct-spi-accessor-naming/spi-impl/src/main/java/org/mapstruct/example/spi/CustomAccessorNamingStrategy.java index 28fe2128..8ddb8995 100644 --- a/mapstruct-spi-accessor-naming/spi-impl/src/main/java/org/mapstruct/example/spi/CustomAccessorNamingStrategy.java +++ b/mapstruct-spi-accessor-naming/spi-impl/src/main/java/org/mapstruct/example/spi/CustomAccessorNamingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.spi; diff --git a/mapstruct-spi-accessor-naming/usage/pom.xml b/mapstruct-spi-accessor-naming/usage/pom.xml index 9439f910..a47c5787 100644 --- a/mapstruct-spi-accessor-naming/usage/pom.xml +++ b/mapstruct-spi-accessor-naming/usage/pom.xml @@ -1,22 +1,9 @@ @@ -34,13 +21,13 @@ org.mapstruct - mapstruct-jdk8 + mapstruct junit junit - 4.12 + 4.13.1 test @@ -48,6 +35,7 @@ + org.apache.maven.plugins maven-compiler-plugin diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java index 0eecd317..f019b74b 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java index 197ae369..a6d2ab32 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/dto/GolfPlayerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java index 421d5790..580dfb01 100644 --- a/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java +++ b/mapstruct-spi-accessor-naming/usage/src/main/java/org/mapstruct/example/mapper/GolfPlayerMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; diff --git a/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java b/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java index 999bcb50..20f9a8d5 100644 --- a/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java +++ b/mapstruct-spi-accessor-naming/usage/src/test/java/org/mapstruct/example/SpiTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-suppress-unmapped/pom.xml b/mapstruct-suppress-unmapped/pom.xml new file mode 100644 index 00000000..af0bdd08 --- /dev/null +++ b/mapstruct-suppress-unmapped/pom.xml @@ -0,0 +1,72 @@ + + + + 4.0.0 + org.mapstruct.examples.suppress + mapstruct-suppress-unmapped + 1.0-SNAPSHOT + + + UTF-8 + 1.7.0.Beta1 + 1.8 + 1.8 + + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + provided + + + + junit + junit + 4.13.1 + test + + + + org.assertj + assertj-core + 3.27.7 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + diff --git a/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ChildDto.java b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ChildDto.java new file mode 100644 index 00000000..f0fcbd03 --- /dev/null +++ b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ChildDto.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.jpa; + +/** + * + * @author Sjaak Derksen + */ +public class ChildDto { + + private String name; + private int age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + +} diff --git a/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ChildEntity.java b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ChildEntity.java new file mode 100644 index 00000000..6072cd7e --- /dev/null +++ b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ChildEntity.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.jpa; + +/** + * + * @author Sjaak Derksen + */ +public class ChildEntity { + + private String name; + private Integer childAge; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getChildAge() { + return childAge; + } + + public void setChildAge(Integer childAge) { + this.childAge = childAge; + } + +} diff --git a/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ParentDto.java b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ParentDto.java new file mode 100644 index 00000000..339ef89e --- /dev/null +++ b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ParentDto.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.jpa; + +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class ParentDto { + + private String name; + private List children; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + +} diff --git a/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ParentEntity.java b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ParentEntity.java new file mode 100644 index 00000000..f6c5a38b --- /dev/null +++ b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/ParentEntity.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.jpa; + +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class ParentEntity { + + private String name; + private List children; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + +} diff --git a/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java new file mode 100644 index 00000000..6ee1a6d2 --- /dev/null +++ b/mapstruct-suppress-unmapped/src/main/java/org/mapstruct/jpa/SourceTargetMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.jpa; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( uses = SourceTargetMapper.LenientMapper.class ) +public interface SourceTargetMapper { + + SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); + + void toEntity(ParentDto s, @MappingTarget ParentEntity t); + + @Mapper( unmappedTargetPolicy = ReportingPolicy.IGNORE ) + public interface LenientMapper { + + // ChildDto.name will be mapped to ChildEntity.name (based on name), explicit ignore would still be required + // ChildDto.age will not be mapped ChildDto.childAge (ignore) and there's no warning either + // this is handy when @BeanMapping#ignoreByDefault causes too many manual mappings to add + void toEntity(ChildDto s, @MappingTarget ChildEntity t); + } +} diff --git a/mapstruct-suppress-unmapped/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java b/mapstruct-suppress-unmapped/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java new file mode 100644 index 00000000..11bacdbc --- /dev/null +++ b/mapstruct-suppress-unmapped/src/test/java/org/mapstruct/jpa/SourceTargetMapperTest.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.jpa; + +import java.util.Arrays; +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * + * @author Sjaak Derksen + */ +public class SourceTargetMapperTest { + + public SourceTargetMapperTest() { + } + + /** + * Test of toTarget method, of class SourceTargetMapper. + */ + @Test + public void testToTarget() { + + // prepare dto's + ParentDto parent = new ParentDto(); + parent.setName( "jim" ); + ChildDto childDto1 = new ChildDto(); + childDto1.setName( "jack" ); + ChildDto childDto2 = new ChildDto(); + childDto2.setName( "jill" ); + parent.setChildren( Arrays.asList( childDto1, childDto2 ) ); + + + ParentEntity parentEntity = new ParentEntity(); + SourceTargetMapper.MAPPER.toEntity( parent, parentEntity ); + + //results + assertThat( parentEntity ).isNotNull(); + assertThat( parentEntity.getName() ).isEqualTo( "jim" ); + assertThat( parentEntity.getChildren() ).hasSize( 2 ); + assertThat( parentEntity.getChildren().get( 0 ).getName() ).isEqualTo( "jack" ); + assertThat( parentEntity.getChildren().get( 0 ).getChildAge() ).isNull(); + assertThat( parentEntity.getChildren().get( 1 ).getName() ).isEqualTo( "jill" ); + assertThat( parentEntity.getChildren().get( 1 ).getChildAge() ).isNull(); + } + +} diff --git a/mapstruct-updatemethods-1/pom.xml b/mapstruct-updatemethods-1/pom.xml index bd0d8460..3931bdb5 100644 --- a/mapstruct-updatemethods-1/pom.xml +++ b/mapstruct-updatemethods-1/pom.xml @@ -1,22 +1,9 @@ @@ -26,7 +13,8 @@ 1.0.0 - 1.3.0.Beta1 + UTF-8 + 1.7.0.Beta1 @@ -39,7 +27,7 @@ junit junit - 4.12 + 4.13.1 test @@ -57,7 +45,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.2 + 3.14.1 1.8 1.8 diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java index e2f8cb2f..6c13cc15 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java index 3a6f1180..a35a79ab 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/dto/MammalEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.dto; diff --git a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java index e63b966f..752c445f 100644 --- a/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java +++ b/mapstruct-updatemethods-1/src/main/java/org/mapstruct/example/mapper/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; @@ -22,7 +9,6 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.MammalDto; import org.mapstruct.example.dto.MammalEntity; import org.mapstruct.factory.Mappers; @@ -33,8 +19,6 @@ public interface SourceTargetMapper { SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); - @Mappings( { - @Mapping( target = "numberOfStomachs", source = "numberOfStomachs" ) - } ) + @Mapping( target = "numberOfStomachs", source = "numberOfStomachs" ) void toTarget( MammalDto source, Long numberOfStomachs, @MappingTarget MammalEntity target ); } diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java index 56911aa6..811928a3 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java index 52bb77de..4fbaec58 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/SourceTargetTestMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example; diff --git a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java index 990e3500..1dbaa339 100644 --- a/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java +++ b/mapstruct-updatemethods-1/src/test/java/org/mapstruct/example/mapper/SourceTargetTestMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.example.mapper; @@ -22,7 +9,6 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; -import org.mapstruct.Mappings; import org.mapstruct.example.dto.MammalDto; import org.mapstruct.example.dto.MammalEntity; import org.mapstruct.factory.Mappers; @@ -38,8 +24,6 @@ public interface SourceTargetTestMapper { SourceTargetTestMapper MAPPER = Mappers.getMapper( SourceTargetTestMapper.class ); - @Mappings({ - @Mapping(target = "numberOfStomachs", source = "numberOfStomachs") - }) + @Mapping(target = "numberOfStomachs", source = "numberOfStomachs") void toTarget(MammalDto source, Long numberOfStomachs, @MappingTarget MammalEntity target); } diff --git a/mvnw b/mvnw new file mode 100755 index 00000000..bd8896bf --- /dev/null +++ b/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 00000000..92450f93 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml index 59055be0..7014467d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,22 +1,9 @@ mapstruct-spi-accessor-naming mapstruct-protobuf3 mapstruct-updatemethods-1 - mapstruct-kotlin mapstruct-jpa-child-parent mapstruct-lookup-entity-with-id + mapstruct-metadata-with-annotations + mapstruct-suppress-unmapped + mapstruct-clone + mapstruct-mapper-repo + mapstruct-kotlin + + + + java14+ + + [14,) + + + mapstruct-record + + + + java14- + + (,14) + + + mapstruct-quarkus + + + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..d23b4a19 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +rootProject.name = 'mapstruct-examples' + +if (JavaVersion.current() <= JavaVersion.VERSION_17) { +includeBuild 'mapstruct-kotlin-gradle' +} +includeBuild 'mapstruct-lombok' +includeBuild 'mapstruct-on-gradle' +includeBuild 'mapstruct-on-gradle-protobuf3' +includeBuild 'mapstruct-on-gradle-testcp-with-lombok'