├── .gitattributes ├── .github ├── release-drafter.yml └── workflows │ ├── build.yml │ └── release-drafter.yml ├── .gitignore ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── .sdkmanrc ├── LICENSE ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── release.sh └── src ├── main └── kotlin │ └── io │ └── github │ └── georgberky │ └── maven │ └── plugins │ └── depsupdate │ ├── ArtifactoryExtensions.kt │ ├── DependencyExtensions.kt │ ├── DependencyManagementVersionUpdate.kt │ ├── DependencyVersionUpdate.kt │ ├── GitProvider.kt │ ├── GitProviderChoice.kt │ ├── JGitProvider.kt │ ├── NativeGitProvider.kt │ ├── ParentVersionUpdate.kt │ ├── Update.kt │ ├── UpdateMojo.kt │ ├── UpdateResolver.kt │ └── VersionUpdate.kt ├── site └── site.xml └── test ├── kotlin └── io │ └── github │ └── georgberky │ └── maven │ └── plugins │ └── depsupdate │ ├── ArtifactVersionComparisonTest.kt │ ├── ArtifactoryExtensionsKtTest.kt │ ├── Bug37NewBranchFromMainIT.kt │ ├── DependencyManagementVersionUpdateTest.kt │ ├── DependencyVersionUpdateTest.kt │ ├── GitProviderTest.kt │ ├── JGitProviderTest.kt │ ├── NativeGitProviderErrorHandlingTest.kt │ ├── NativeGitProviderTest.kt │ ├── ParentVersionUpdateTest.kt │ ├── PomHelper.kt │ ├── UpdateMojoIT.kt │ ├── UpdateMojoJGitIT.kt │ ├── UpdateMojoJGitScmConfigIsMissingIT.kt │ ├── UpdateMojoNativeGitIT.kt │ ├── UpdateResolverTest.kt │ └── VersionUpdateTest.kt ├── resources-its └── io │ └── github │ └── georgberky │ └── maven │ └── plugins │ └── depsupdate │ ├── Bug37NewBranchFromMainIT │ ├── moreThanOneDependency │ │ └── pom.xml │ └── onlyOneDependency │ │ └── pom.xml │ ├── UpdateMojoIT │ └── remoteBranchForPreviousVersionExists │ │ └── pom.xml │ ├── UpdateMojoJGitIT │ └── jgitProviderIsSet_scmConfigIsSet │ │ ├── pom.xml │ │ └── settings.xml │ ├── UpdateMojoJGitScmConfigIsMissingIT │ └── jgitProviderIsSet_scmConfigIsMissing │ │ └── pom.xml │ └── UpdateMojoNativeGitIT │ └── nativeProviderIsSet │ └── pom.xml └── resources └── poms ├── dependenciesPom.xml ├── dependencyManagementPom.xml └── parentPom.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | *.bat text eol=crlf 2 | *.cmd text eol=crlf 3 | 4 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - title: '🚀 Features' 3 | label: 'feature' 4 | - title: '🐛 Bugfixes' 5 | label: 'bug' 6 | - title: '🧰 Maintenance' 7 | label: 'maintenance' 8 | - title: '📦 Dependencies' 9 | label: 'dependencies' 10 | - title: '✏️ Documentation' 11 | label: 'documentation' 12 | exclude-labels: 13 | - 'skip-changelog' 14 | 15 | template: | 16 | ## What's Changed 17 | 18 | $CHANGES 19 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: MavenBuild 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | jdk: 13 | name: "JDK 17 Eclipse Temurin" 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/cache@v3 18 | with: 19 | path: ~/.m2/repository 20 | key: maven-jdk-${{ hashFiles('**/pom.xml') }} 21 | restore-keys: maven-jdk 22 | - name: Set up JDK 17 23 | uses: actions/setup-java@v3 24 | with: 25 | java-version: '17' 26 | distribution: 'temurin' 27 | architecture: x64 28 | - name: 'Build' 29 | run: | 30 | git config --global user.email "noreply@dependency-plugin.invalid" 31 | git config --global user.name "dependency-update-maven-plugin" 32 | git config --global init.defaultBranch main 33 | ./mvnw \ 34 | --show-version \ 35 | --fail-at-end \ 36 | --batch-mode \ 37 | --no-transfer-progress \ 38 | clean verify \ 39 | site site:stage \ 40 | -Pdocs 41 | - uses: codecov/codecov-action@v3 42 | with: 43 | token: ${{ secrets.CODECOV_TOKEN }} 44 | files: ./target/site/jacoco/jacoco.xml 45 | fail_ci_if_error: true 46 | verbose: false 47 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | on: 3 | push: 4 | # branches to consider in the event; optional, defaults to all 5 | branches: 6 | - master 7 | # pull_request event is required only for autolabeler 8 | pull_request: 9 | # Only following types are handled by the action, but one can default to all as well 10 | types: [opened, reopened, synchronize] 11 | # pull_request_target event is required for autolabeler to support PRs from forks 12 | # pull_request_target: 13 | # types: [opened, reopened, synchronize] 14 | 15 | jobs: 16 | update_release_draft: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: release-drafter/release-drafter@v5.18.1 20 | # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml 21 | env: 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea/ 3 | target/ 4 | **/.DS_Store 5 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /.sdkmanrc: -------------------------------------------------------------------------------- 1 | # Enable auto-env through the sdkman_auto_env config 2 | # Add key=value pairs of SDKs to use below 3 | java=17.0.9-tem 4 | maven=3.9.6 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dependency Update Maven Plugin 2 | 3 | [![MavenBuild](https://github.com/georgberky/dependency-update-maven-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/georgberky/dependency-update-maven-plugin/actions/workflows/build.yml) [![codecov](https://codecov.io/gh/georgberky/dependency-update-maven-plugin/branch/master/graph/badge.svg?token=XMHYGY0L3A)](https://codecov.io/gh/georgberky/dependency-update-maven-plugin) 4 | 5 | The `Dependency Update Maven Plugin` analyzes the dependencies of your Maven project. 6 | 7 | If a more recent version of a dependency is found, the plugin will 8 | 9 | * create a new branch 10 | * update the dependency version in the POM 11 | * commit and push the change 12 | * create a merge request 13 | 14 | ## Features 15 | 16 | * supports Public Key, Username Password and Token-Based Authentication 17 | 18 | ## Quickstart 19 | 20 | ```sh 21 | mvn io.github.georgberky.maven.plugins.depsupdate:dependency-update-maven-plugin:update 22 | ``` 23 | 24 | ## Goals 25 | 26 | ### update 27 | 28 | [Update Mojo](https://pages.github.com/georgberky/dependency-update-maven-plugin/) 29 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.2.0 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | (CYGWIN*|MINGW*) [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 39 | native_path() { cygpath --path --windows "$1"; } ;; 40 | esac 41 | 42 | # set JAVACMD and JAVACCMD 43 | set_java_home() { 44 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 45 | if [ -n "${JAVA_HOME-}" ] ; then 46 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 47 | # IBM's JDK on AIX uses strange locations for the executables 48 | JAVACMD="$JAVA_HOME/jre/sh/java" 49 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 50 | else 51 | JAVACMD="$JAVA_HOME/bin/java" 52 | JAVACCMD="$JAVA_HOME/bin/javac" 53 | 54 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ] ; then 55 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 56 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 57 | return 1 58 | fi 59 | fi 60 | else 61 | JAVACMD="$('set' +e; 'unset' -f command 2>/dev/null; 'command' -v java)" || : 62 | JAVACCMD="$('set' +e; 'unset' -f command 2>/dev/null; 'command' -v javac)" || : 63 | 64 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ] ; then 65 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 66 | return 1 67 | fi 68 | fi 69 | } 70 | 71 | # hash string like Java String::hashCode 72 | hash_string() { 73 | str="${1:-}" h=0 74 | while [ -n "$str" ]; do 75 | h=$(( ( h * 31 + $(LC_CTYPE=C printf %d "'$str") ) % 4294967296 )) 76 | str="${str#?}" 77 | done 78 | printf %x\\n $h 79 | } 80 | 81 | verbose() { :; } 82 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 83 | 84 | die() { 85 | printf %s\\n "$1" >&2 86 | exit 1 87 | } 88 | 89 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 90 | while IFS="=" read -r key value; do 91 | case "${key-}" in 92 | distributionUrl) distributionUrl="${value-}" ;; 93 | distributionSha256Sum) distributionSha256Sum="${value-}" ;; 94 | esac 95 | done < "${0%/*}/.mvn/wrapper/maven-wrapper.properties" 96 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 97 | 98 | 99 | case "${distributionUrl##*/}" in 100 | (maven-mvnd-*bin.*) 101 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 102 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 103 | (*AMD64:CYGWIN*|*AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 104 | (:Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 105 | (:Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 106 | (:Linux*x86_64*) distributionPlatform=linux-amd64 ;; 107 | (*) echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 108 | distributionPlatform=linux-amd64 109 | ;; 110 | esac 111 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 112 | ;; 113 | (maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 114 | (*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 115 | esac 116 | 117 | # apply MVNW_REPOURL and calculate MAVEN_HOME 118 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 119 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 120 | distributionUrlName="${distributionUrl##*/}" 121 | distributionUrlNameMain="${distributionUrlName%.*}" 122 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 123 | MAVEN_HOME="$HOME/.m2/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 124 | 125 | exec_maven() { 126 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 127 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 128 | } 129 | 130 | if [ -d "$MAVEN_HOME" ]; then 131 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 132 | exec_maven "$@" 133 | fi 134 | 135 | case "${distributionUrl-}" in 136 | (*?-bin.zip|*?maven-mvnd-?*-?*.zip) ;; 137 | (*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 138 | esac 139 | 140 | # prepare tmp dir 141 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 142 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 143 | trap clean HUP INT TERM EXIT 144 | else 145 | die "cannot create temp dir" 146 | fi 147 | 148 | mkdir -p -- "${MAVEN_HOME%/*}" 149 | 150 | # Download and Install Apache Maven 151 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 152 | verbose "Downloading from: $distributionUrl" 153 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 154 | 155 | # select .zip or .tar.gz 156 | if ! command -v unzip >/dev/null; then 157 | distributionUrl="${distributionUrl%.zip}.tar.gz" 158 | distributionUrlName="${distributionUrl##*/}" 159 | fi 160 | 161 | # verbose opt 162 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 163 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 164 | 165 | # normalize http auth 166 | case "${MVNW_PASSWORD:+has-password}" in 167 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 168 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 169 | esac 170 | 171 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget > /dev/null; then 172 | verbose "Found wget ... using wget" 173 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" 174 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl > /dev/null; then 175 | verbose "Found curl ... using curl" 176 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" 177 | elif set_java_home; then 178 | verbose "Falling back to use Java to download" 179 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 180 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 181 | cat > "$javaSource" <<-END 182 | public class Downloader extends java.net.Authenticator 183 | { 184 | protected java.net.PasswordAuthentication getPasswordAuthentication() 185 | { 186 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 187 | } 188 | public static void main( String[] args ) throws Exception 189 | { 190 | setDefault( new Downloader() ); 191 | java.nio.file.Files.copy( new java.net.URL( args[0] ).openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 192 | } 193 | } 194 | END 195 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 196 | verbose " - Compiling Downloader.java ..." 197 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" 198 | verbose " - Running Downloader.java ..." 199 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 200 | fi 201 | 202 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 203 | if [ -n "${distributionSha256Sum-}" ]; then 204 | distributionSha256Result=false 205 | if [ "$MVN_CMD" = mvnd.sh ]; then 206 | echo "Checksum validation is not supported for maven-mvnd." >&2 207 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 208 | exit 1 209 | elif command -v sha256sum > /dev/null; then 210 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c > /dev/null 2>&1; then 211 | distributionSha256Result=true 212 | fi 213 | elif command -v shasum > /dev/null; then 214 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c > /dev/null 2>&1; then 215 | distributionSha256Result=true 216 | fi 217 | else 218 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 219 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 220 | exit 1 221 | fi 222 | if [ $distributionSha256Result = false ]; then 223 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 224 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 225 | exit 1 226 | fi 227 | fi 228 | 229 | # unzip and move 230 | if command -v unzip > /dev/null; then 231 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" 232 | else 233 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" 234 | fi 235 | printf %s\\n "$distributionUrl" > "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 236 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 237 | 238 | clean || : 239 | exec_maven "$@" 240 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.2.0 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @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 @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 83 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 84 | 85 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 86 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 87 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 88 | exit $? 89 | } 90 | 91 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 92 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 93 | } 94 | 95 | # prepare tmp dir 96 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 97 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 98 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 99 | trap { 100 | if ($TMP_DOWNLOAD_DIR.Exists) { 101 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 102 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 103 | } 104 | } 105 | 106 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 107 | 108 | # Download and Install Apache Maven 109 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 110 | Write-Verbose "Downloading from: $distributionUrl" 111 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 112 | 113 | $webclient = New-Object System.Net.WebClient 114 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 115 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 116 | } 117 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 118 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 119 | 120 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 121 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 122 | if ($distributionSha256Sum) { 123 | if ($USE_MVND) { 124 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 125 | } 126 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 127 | 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." 128 | } 129 | } 130 | 131 | # unzip and move 132 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 133 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 134 | try { 135 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 136 | } catch { 137 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 138 | Write-Error "fail to move MAVEN_HOME" 139 | } 140 | } finally { 141 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 142 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 143 | } 144 | 145 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 146 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | io.github.georgberky.maven.plugins.depsupdate 5 | dependency-update-maven-plugin 6 | maven-plugin 7 | 0.10.0-SNAPSHOT 8 | 9 | ${project.groupId}:${project.artifactId} 10 | The Dependency Update Maven plugin creates merge requests for dependency updates. 11 | https://github.com/georgberky/dependency-update-maven-plugin 12 | 13 | 14 | 15 | Apache License 2.0 16 | http://www.apache.org/licenses/LICENSE-2.0.txt 17 | 18 | 19 | 20 | 21 | 22 | Oliver Weiler 23 | wo6980@gmail.com 24 | 25 | 26 | Sandra Parsick 27 | mail@sandra-parsick.de 28 | 29 | 30 | Karl Heinz Marbaise 31 | kama@soebes.de 32 | 33 | 34 | Georg Berky 35 | hallo@berky.dev 36 | 37 | 38 | Benjamin Marwell 39 | bmarwell@apache.org 40 | 41 | 42 | 43 | 44 | scm:git:https://github.com/georgberky/dependency-update-maven-plugin.git 45 | scm:git:https://github.com/georgberky/dependency-update-maven-plugin.git 46 | 47 | https://github.com/georgberky/dependency-update-maven-plugin 48 | 49 | 50 | 51 | 52 | ossrh 53 | https://s01.oss.sonatype.org/content/repositories/snapshots 54 | 55 | 56 | ossrh 57 | https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ 58 | 59 | 60 | gh_pages 61 | Maven Site on GitHub Pages 62 | https://pages.github.com/georgberky/dependency-update-maven-plugin/ 63 | 64 | 65 | 66 | 67 | UTF-8 68 | UTF-8 69 | 3.8.8 70 | 1.6.0 71 | 3.10.2 72 | 1.7.10 73 | 0.11.0 74 | 2.27.1 75 | 0.47.1 76 | 17 77 | 17 78 | 6.4.0.202211300538-r 79 | 80 | 81 | 82 | ${maven.version} 83 | 84 | 85 | 86 | 87 | commons-io 88 | commons-io 89 | 2.7 90 | 91 | 92 | org.apache.maven 93 | maven-plugin-api 94 | ${maven.version} 95 | provided 96 | 97 | 98 | org.apache.maven 99 | maven-core 100 | ${maven.version} 101 | provided 102 | 103 | 104 | org.apache.maven.plugin-tools 105 | maven-plugin-annotations 106 | ${maven-plugin.version} 107 | provided 108 | 109 | 110 | org.jetbrains.kotlin 111 | kotlin-stdlib-jdk8 112 | ${kotlin.version} 113 | 114 | 115 | org.eclipse.jgit 116 | org.eclipse.jgit 117 | ${jgit.version} 118 | 119 | 120 | org.eclipse.jgit 121 | org.eclipse.jgit.ssh.jsch 122 | ${jgit.version} 123 | 124 | 125 | org.jsoup 126 | jsoup 127 | 1.15.3 128 | 129 | 130 | org.junit.jupiter 131 | junit-jupiter 132 | 5.7.2 133 | test 134 | 135 | 136 | org.junit-pioneer 137 | junit-pioneer 138 | 1.7.1 139 | test 140 | 141 | 142 | org.assertj 143 | assertj-core 144 | 3.15.0 145 | test 146 | 147 | 148 | com.soebes.itf.jupiter.extension 149 | itf-jupiter-extension 150 | ${itf.version} 151 | test 152 | 153 | 154 | com.soebes.itf.jupiter.extension 155 | itf-assertj 156 | ${itf.version} 157 | test 158 | 159 | 160 | io.rest-assured 161 | xml-path 162 | 4.3.0 163 | test 164 | 165 | 166 | org.apache.maven.plugin-testing 167 | maven-plugin-testing-harness 168 | 3.3.0 169 | test 170 | 171 | 172 | junit 173 | junit 174 | 175 | 176 | 177 | 178 | io.mockk 179 | mockk-jvm 180 | 1.12.8 181 | test 182 | 183 | 184 | org.slf4j 185 | slf4j-simple 186 | 1.7.5 187 | test 188 | 189 | 190 | io.github.sparsick.testcontainers.gitserver 191 | testcontainers-gitserver 192 | 0.4.0 193 | test 194 | 195 | 196 | org.testcontainers 197 | testcontainers 198 | test 199 | 200 | 201 | org.testcontainers 202 | junit-jupiter 203 | test 204 | 205 | 206 | 207 | 208 | 209 | 210 | org.testcontainers 211 | testcontainers-bom 212 | 1.16.3 213 | pom 214 | import 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | src/test/resources 223 | false 224 | 225 | 226 | src/test/resources-its 227 | true 228 | 229 | **/pom.xml 230 | 231 | 232 | 233 | src/test/resources-its 234 | false 235 | 236 | **/pom.xml 237 | 238 | 239 | 240 | src/main/kotlin 241 | src/test/kotlin 242 | 243 | 244 | 245 | 246 | org.apache.maven.plugins 247 | maven-plugin-plugin 248 | ${maven-plugin.version} 249 | 250 | 251 | org.apache.maven.plugins 252 | maven-resources-plugin 253 | 3.1.0 254 | 255 | 256 | org.jetbrains.kotlin 257 | kotlin-maven-plugin 258 | ${kotlin.version} 259 | 260 | 261 | com.soebes.itf.jupiter.extension 262 | itf-maven-plugin 263 | ${itf.version} 264 | 265 | 266 | org.apache.maven.plugins 267 | maven-failsafe-plugin 268 | 3.0.0-M5 269 | 270 | 271 | org.apache.maven.plugins 272 | maven-source-plugin 273 | 3.2.0 274 | 275 | 276 | maven-surefire-plugin 277 | 3.0.0-M5 278 | 279 | 280 | org.codehaus.mojo 281 | build-helper-maven-plugin 282 | 3.2.0 283 | 284 | 285 | org.jacoco 286 | jacoco-maven-plugin 287 | 0.8.7 288 | 289 | 290 | org.apache.maven.plugins 291 | maven-gpg-plugin 292 | 1.6 293 | 294 | 295 | org.sonatype.plugins 296 | nexus-staging-maven-plugin 297 | 1.6.8 298 | 299 | 300 | org.apache.maven.plugins 301 | maven-deploy-plugin 302 | 2.8.2 303 | 304 | 305 | org.apache.maven.plugins 306 | maven-install-plugin 307 | 2.5.2 308 | 309 | 310 | org.apache.maven.plugins 311 | maven-site-plugin 312 | 3.12.0 313 | 314 | 315 | org.apache.maven.plugins 316 | maven-project-info-reports-plugin 317 | 3.3.0 318 | 319 | 320 | org.eclipse.m2e:lifecycle-mapping 321 | 322 | 323 | 324 | 325 | 326 | 327 | com.diffplug.spotless 328 | spotless-maven-plugin 329 | ${spotless.version} 330 | 331 | 332 | 333 | 334 | 335 | 336 | org.apache.maven.plugins 337 | maven-resources-plugin 338 | 339 | false 340 | 341 | 342 | 343 | org.apache.maven.plugins 344 | maven-plugin-plugin 345 | 346 | 347 | generated-helpmojo 348 | 349 | helpmojo 350 | 351 | 352 | 353 | 354 | 355 | org.jetbrains.kotlin 356 | kotlin-maven-plugin 357 | 358 | 359 | compile 360 | compile 361 | 362 | compile 363 | 364 | 365 | 366 | test-compile 367 | test-compile 368 | 369 | test-compile 370 | 371 | 372 | 373 | 374 | 1.8 375 | 376 | 377 | 378 | com.soebes.itf.jupiter.extension 379 | itf-maven-plugin 380 | 381 | 382 | installing 383 | pre-integration-test 384 | 385 | install 386 | 387 | 388 | 389 | 390 | 391 | org.apache.maven.plugins 392 | maven-failsafe-plugin 393 | 394 | 397 | 398 | ${maven.version} 399 | ${maven.home} 400 | 401 | 402 | 403 | 404 | 405 | integration-test 406 | verify 407 | 408 | 409 | 410 | 411 | 412 | org.apache.maven.plugins 413 | maven-source-plugin 414 | 415 | 416 | 417 | jar-no-fork 418 | 419 | 420 | 421 | 422 | 423 | org.codehaus.mojo 424 | build-helper-maven-plugin 425 | 426 | 427 | add-source 428 | generate-sources 429 | 430 | add-source 431 | 432 | 433 | 434 | 435 | src/main/kotlin 436 | 437 | 438 | 439 | 440 | add-test-source 441 | generate-test-sources 442 | 443 | add-test-source 444 | 445 | 446 | 447 | 448 | src/test/kotlin 449 | 450 | 451 | 452 | 453 | 454 | 455 | org.jacoco 456 | jacoco-maven-plugin 457 | 458 | 459 | 460 | 461 | prepare-agent 462 | 463 | 465 | report 466 | 467 | 468 | 469 | 470 | 471 | 472 | com.diffplug.spotless 473 | spotless-maven-plugin 474 | 475 | 476 | validate 477 | 478 | check 479 | 480 | 481 | 482 | 483 | 484 | 485 | ${ktlint.version} 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | org.apache.maven.plugins 497 | maven-project-info-reports-plugin 498 | 499 | 500 | 501 | index 502 | summary 503 | dependency-info 504 | modules 505 | team 506 | scm 507 | issue-management 508 | mailing-lists 509 | dependency-management 510 | dependencies 511 | dependency-convergence 512 | ci-management 513 | plugin-management 514 | plugins 515 | distribution-management 516 | 517 | 518 | 519 | 520 | 521 | org.apache.maven.plugins 522 | maven-plugin-plugin 523 | 524 | 525 | org.jacoco 526 | jacoco-maven-plugin 527 | 528 | 529 | 530 | report 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | docs 541 | 542 | 543 | 544 | org.jetbrains.dokka 545 | dokka-maven-plugin 546 | ${dokka.version} 547 | 548 | 549 | package 550 | 551 | javadocJar 552 | 553 | 554 | 555 | 556 | 557 | 558 | org.jetbrains.dokka 559 | kotlin-as-java-plugin 560 | ${dokka.version} 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | release 570 | 571 | 572 | 573 | org.apache.maven.plugins 574 | maven-gpg-plugin 575 | 576 | 577 | 578 | sign 579 | 580 | 581 | 582 | 583 | 584 | --pinentry-mode 585 | loopback 586 | 587 | 588 | 589 | 590 | org.sonatype.plugins 591 | nexus-staging-maven-plugin 592 | true 593 | 594 | ossrh 595 | https://s01.oss.sonatype.org/ 596 | true 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | # Trap not-normal exit signals: 1/HUP, 2/INT, 3/QUIT, 15/TERM 6 | trap catch_sig 1 2 3 15 7 | # Trap errors (simple commands exiting with a non-zero status) 8 | trap 'catch_err ${LINENO}' ERR 9 | 10 | function clean_exit { 11 | echo "Exiting - version state may be inconsistent!" 12 | exit "$1" 13 | } 14 | 15 | function catch_err() { 16 | local PARENT_LINENO="$1" 17 | local MESSAGE="$2" 18 | local CODE="${3:-1}" 19 | if [[ -n "$MESSAGE" ]] ; then 20 | echo "Error on or near line ${PARENT_LINENO}: ${MESSAGE}; exiting with status ${CODE}" 21 | else 22 | echo "Error on or near line ${PARENT_LINENO}; exiting with status ${CODE}" 23 | fi 24 | clean_exit "${CODE}" 25 | } 26 | 27 | function catch_sig() { 28 | local exit_status=$? 29 | clean_exit $exit_status 30 | } 31 | 32 | deploy_site() { 33 | local upstream_url="${1}" 34 | local commit="${2}" 35 | local root_dir="$PWD" 36 | 37 | mkdir -p "$PWD/target" 38 | cd "$PWD/target" 39 | git clone --depth=1 --branch "gh_site" "${upstream_url}" "gh_site" || true 40 | 41 | if [ ! -d "gh_site" ]; then 42 | echo "[INFO] Initial creation of new orphan branch gh_site." 43 | git clone --depth=1 "${upstream_url}" "gh_site" 44 | cd gh_site || exit 1 45 | git checkout --orphan "gh_site" 46 | rm '.gitignore' 47 | fi 48 | 49 | rm -rf "${PWD}/." 50 | rsync -a "$root_dir/target/staging/." . 51 | git add . 52 | git commit -m "[SITE] update site commit [$commit]" 53 | git push origin gh_site 54 | cd "${root_dir}" 55 | } 56 | 57 | if [ $# -ne 2 ]; then 58 | echo "Usage: release.sh " 59 | exit 1 60 | fi 61 | 62 | release_version=$1 63 | new_version=$2 64 | 65 | mvn versions:set "-DnewVersion=$release_version" -DgenerateBackupPoms=false 66 | 67 | git commit -a -m "$release_version release" 68 | git tag -a "$release_version" -a -m "$release_version release" 69 | 70 | mvn clean site site:stage deploy -DskipTests -Prelease,docs 71 | deploy_site "$(git remote get-url origin)" "$(git rev-parse HEAD)" 72 | 73 | mvn versions:set "-DnewVersion=$new_version" -DgenerateBackupPoms=false 74 | git commit -a -m "Preparing $new_version iteration" 75 | 76 | git push 77 | git push origin "$release_version" 78 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/ArtifactoryExtensions.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.artifact.Artifact 4 | import org.apache.maven.artifact.factory.ArtifactFactory 5 | import org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec 6 | import org.apache.maven.model.Dependency 7 | 8 | fun ArtifactFactory.createDependencyArtifact(dependency: Dependency): Artifact? = 9 | createDependencyArtifact(dependency.groupId, dependency.artifactId, createFromVersionSpec(dependency.version), dependency.type, dependency.classifier, dependency.scope, dependency.optional) 10 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/DependencyExtensions.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.model.Dependency 4 | 5 | fun Dependency.isConcrete() = 6 | version != null && !version.contains("\\$\\{[^}]+}".toRegex()) 7 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/DependencyManagementVersionUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.jsoup.nodes.Document 4 | 5 | class DependencyManagementVersionUpdate( 6 | groupId: String, 7 | artifactId: String, 8 | version: String, 9 | latestVersion: String, 10 | private val pom: Document 11 | ) : VersionUpdate(groupId, artifactId, version, latestVersion) { 12 | 13 | override fun updatedPom(): Document { 14 | pom.selectFirst("project > dependencyManagement > dependencies > dependency:has(> groupId:containsOwn($groupId)):has(> artifactId:containsOwn($artifactId)):has(> version:containsOwn($version)) > version")!! 15 | .text(latestVersion) 16 | return pom 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/DependencyVersionUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.jsoup.nodes.Document 4 | 5 | class DependencyVersionUpdate( 6 | groupId: String, 7 | artifactId: String, 8 | version: String, 9 | latestVersion: String, 10 | 11 | private val pom: Document 12 | ) : VersionUpdate(groupId, artifactId, version, latestVersion) { 13 | 14 | override fun updatedPom(): Document { 15 | pom.selectFirst("project > dependencies > dependency:has(> groupId:containsOwn($groupId)):has(> artifactId:containsOwn($artifactId)):has(> version:containsOwn($version)) > version")!! 16 | .text(latestVersion) 17 | return pom 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/GitProvider.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | interface GitProvider : AutoCloseable { 4 | fun hasRemoteBranch(remoteBranchName: String): Boolean 5 | fun hasRemoteBranchWithPrefix(remoteBranchNamePrefix: String): Boolean 6 | fun checkoutNewBranch(branchName: String) 7 | fun add(filePattern: String) 8 | fun commit(author: String, email: String, message: String) 9 | fun push(localBranchName: String) 10 | fun checkoutInitialBranch() 11 | } 12 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/GitProviderChoice.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.settings.Settings 4 | import java.nio.file.Path 5 | 6 | enum class GitProviderChoice { 7 | NATIVE { 8 | override fun createProvider(localRepositoryPath: Path, settings: Settings, connection: String): GitProvider = 9 | NativeGitProvider(localRepositoryPath) 10 | }, 11 | JGIT { 12 | override fun createProvider(localRepositoryPath: Path, settings: Settings, connection: String): GitProvider = 13 | JGitProvider(localRepositoryPath, settings, connection) 14 | }; 15 | 16 | abstract fun createProvider(localRepositoryPath: Path, settings: Settings, connection: String): GitProvider 17 | } 18 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/JGitProvider.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import com.jcraft.jsch.JSch.setConfig 4 | import com.jcraft.jsch.Session 5 | import org.apache.maven.settings.Settings 6 | import org.eclipse.jgit.api.Git 7 | import org.eclipse.jgit.api.ListBranchCommand 8 | import org.eclipse.jgit.api.TransportConfigCallback 9 | import org.eclipse.jgit.lib.PersonIdent 10 | import org.eclipse.jgit.lib.RepositoryBuilder 11 | import org.eclipse.jgit.transport.RefSpec 12 | import org.eclipse.jgit.transport.SshTransport 13 | import org.eclipse.jgit.transport.URIish 14 | import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider 15 | import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory 16 | import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig 17 | import org.eclipse.jgit.util.FS 18 | import java.nio.file.Path 19 | 20 | class JGitProvider(localRepositoryPath: Path, val settings: Settings, val connection: String) : GitProvider { 21 | val git: Git = Git( 22 | RepositoryBuilder() 23 | .readEnvironment() 24 | .findGitDir(localRepositoryPath.toFile()) 25 | .setMustExist(true) 26 | .build() 27 | ) 28 | 29 | private val initialBranch: String = git.repository.branch 30 | 31 | override fun hasRemoteBranch(remoteBranchName: String): Boolean { 32 | return git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call() 33 | .any { it.name == "refs/remotes/origin/$remoteBranchName" } 34 | } 35 | 36 | override fun hasRemoteBranchWithPrefix(remoteBranchNamePrefix: String): Boolean { 37 | return git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call() 38 | .any { it.name.startsWith("refs/remotes/origin/$remoteBranchNamePrefix") } 39 | } 40 | 41 | override fun checkoutNewBranch(branchName: String) { 42 | git.checkout() 43 | .setStartPoint(git.repository.fullBranch) 44 | .setCreateBranch(true) 45 | .setName(branchName) 46 | .call() 47 | } 48 | 49 | override fun add(filePattern: String) { 50 | git.add() 51 | .addFilepattern(filePattern) 52 | .call() 53 | } 54 | 55 | override fun commit(author: String, email: String, message: String) { 56 | git.commit() 57 | .setAuthor(PersonIdent(author, email)) 58 | .setMessage(message) 59 | .call() 60 | } 61 | 62 | override fun push(localBranchName: String) { 63 | git.push() 64 | .setRefSpecs(RefSpec("$localBranchName:$localBranchName")) 65 | .apply { 66 | val uri = URIish(connection.removePrefix("scm:git:")) 67 | 68 | when (uri.scheme) { 69 | "https" -> { 70 | val (username, password) = usernamePassword(uri) 71 | 72 | setCredentialsProvider(UsernamePasswordCredentialsProvider(username, password)) 73 | } 74 | 75 | else -> { 76 | setTransportConfigCallback( 77 | TransportConfigCallback { transport -> 78 | if (transport !is SshTransport) return@TransportConfigCallback 79 | val (_, password) = usernamePassword(uri) 80 | if (password != null) { 81 | transport.sshSessionFactory = object : JschConfigSessionFactory() { 82 | override fun configure(hc: OpenSshConfig.Host?, session: Session?) { 83 | session?.setPassword(password) 84 | session?.setConfig("StrictHostKeyChecking", "no") 85 | } 86 | } 87 | } else { 88 | transport.sshSessionFactory = object : JschConfigSessionFactory() { 89 | override fun configure(hc: OpenSshConfig.Host?, session: Session?) { 90 | } 91 | 92 | override fun createDefaultJSch(fs: FS?) = 93 | settings.getServer(uri.host).run { 94 | super.createDefaultJSch(fs).apply { 95 | addIdentity(privateKey, passphrase) 96 | setConfig("StrictHostKeyChecking", "no") 97 | } 98 | } 99 | } 100 | } 101 | } 102 | ) 103 | } 104 | } 105 | } 106 | // .setPushOptions(listOf("merge_request.create")) 107 | .call() 108 | } 109 | 110 | override fun checkoutInitialBranch() { 111 | git 112 | .checkout() 113 | .setStartPoint(git.repository.fullBranch) 114 | .setName(initialBranch) 115 | .call() 116 | } 117 | 118 | override fun close() { 119 | git.close() 120 | } 121 | 122 | private fun usernamePassword(uri: URIish) = 123 | if (uri.user != null && uri.pass != null) { 124 | uri.user to uri.pass 125 | } else { 126 | settings.getServer(uri.host) 127 | .run { username to password } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/NativeGitProvider.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.commons.io.IOUtils 4 | import java.nio.charset.StandardCharsets 5 | import java.nio.file.Path 6 | 7 | open class NativeGitProvider(val localRepositoryDirectory: Path) : GitProvider { 8 | 9 | private val gitCommand: String by lazy { 10 | val process = ProcessBuilder("which", "git") 11 | .start() 12 | 13 | process.waitFor() 14 | IOUtils.toString(process.inputStream, StandardCharsets.UTF_8).trim() 15 | } 16 | 17 | private val initialBranch: String = 18 | run(gitCommand, "rev-parse", "--abbrev-ref", "HEAD").stdout.trim() 19 | 20 | override fun hasRemoteBranch(remoteBranchName: String): Boolean { 21 | val processResult = run(gitCommand, "branch", "--all") 22 | val processOutput = processResult.stdout 23 | return processOutput.contains("remotes/origin/" + remoteBranchName) 24 | } 25 | 26 | override fun hasRemoteBranchWithPrefix(remoteBranchNamePrefix: String): Boolean { 27 | val processResult = run(gitCommand, "branch", "--all") 28 | val processOutput = processResult.stdout 29 | return processOutput.lines() 30 | .map { it.trim() } 31 | .any { it.startsWith("remotes/origin/" + remoteBranchNamePrefix) } 32 | } 33 | 34 | override fun checkoutNewBranch(branchName: String) { 35 | run(gitCommand, "checkout", "-b", branchName) 36 | } 37 | 38 | override fun add(filePattern: String) { 39 | run(gitCommand, "add", filePattern) 40 | } 41 | 42 | override fun commit(author: String, email: String, message: String) { 43 | run(gitCommand, "commit", "-m", message, "--author='$author <$email>'") 44 | } 45 | 46 | override fun push(localBranchName: String) { 47 | run(gitCommand, "push", "--set-upstream", "origin", localBranchName) 48 | } 49 | 50 | override fun checkoutInitialBranch() { 51 | run(gitCommand, "checkout", initialBranch) 52 | } 53 | 54 | override fun close() { 55 | // not needed for native git 56 | } 57 | 58 | open fun run(vararg command: String): ProcessResult { 59 | val process = ProcessBuilder(*command) 60 | .directory(localRepositoryDirectory.toFile()) 61 | .start() 62 | 63 | val exitCode = process.waitFor() 64 | val stdout = IOUtils.toString(process.inputStream, StandardCharsets.UTF_8) 65 | val stderr = IOUtils.toString(process.errorStream, StandardCharsets.UTF_8) 66 | 67 | return ProcessResult(command, exitCode, stdout, stderr).orThrow() 68 | } 69 | 70 | data class ProcessResult( 71 | val command: Array, 72 | val exitCode: Int, 73 | val stdout: String, 74 | val stderr: String 75 | ) { 76 | fun orThrow(): ProcessResult { 77 | if (exitCode == 0) { 78 | return this 79 | } 80 | throw ProcessException( 81 | "Native git invocation failed. " + 82 | "Command: ${command.joinToString(" ")}, " + 83 | "return value was: $exitCode\n" + 84 | "stdout was: $stdout\n" + 85 | "stderr was: $stderr" 86 | ) 87 | } 88 | } 89 | 90 | class ProcessException(message: String?) : RuntimeException(message) 91 | } 92 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/ParentVersionUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.jsoup.nodes.Document 4 | 5 | class ParentVersionUpdate( 6 | groupId: String, 7 | artifactId: String, 8 | version: String, 9 | 10 | latestVersion: String, 11 | private val pom: Document 12 | ) : VersionUpdate(groupId, artifactId, version, latestVersion) { 13 | 14 | override fun updatedPom(): Document { 15 | pom.selectFirst("project > parent > version")!!.text(latestVersion) 16 | return pom 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/Update.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.jsoup.nodes.Document 4 | 5 | data class Update(val groupId: String, val artifactId: String, val version: String, val latestVersion: String, val modification: (Document) -> Unit) 6 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateMojo.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.artifact.factory.ArtifactFactory 4 | import org.apache.maven.artifact.metadata.ArtifactMetadataSource 5 | import org.apache.maven.artifact.repository.ArtifactRepository 6 | import org.apache.maven.execution.MavenSession 7 | import org.apache.maven.plugin.AbstractMojo 8 | import org.apache.maven.plugin.MojoExecutionException 9 | import org.apache.maven.plugins.annotations.Component 10 | import org.apache.maven.plugins.annotations.Mojo 11 | import org.apache.maven.plugins.annotations.Parameter 12 | import org.apache.maven.project.MavenProject 13 | import org.apache.maven.settings.Settings 14 | 15 | /** 16 | * The update mojo goes through all dependencies in the project and 17 | * create an own branch per dependency with its newest version. 18 | */ 19 | @Mojo(name = "update") 20 | class UpdateMojo : AbstractMojo() { 21 | 22 | @Parameter(defaultValue = "\${session}", readonly = true, required = true) 23 | lateinit var mavenSession: MavenSession 24 | 25 | @Parameter(defaultValue = "\${project}", required = true) 26 | lateinit var mavenProject: MavenProject 27 | 28 | @Parameter(defaultValue = "\${localRepository}", required = true) 29 | lateinit var localRepository: ArtifactRepository 30 | 31 | @Parameter(defaultValue = "\${settings}", required = true) 32 | lateinit var settings: Settings 33 | 34 | /** 35 | * Currently, it has to be set, but it is only necessary for the Git provider JGIT. 36 | */ 37 | @Parameter(property = "connectionUrl", defaultValue = "\${project.scm.connection}", required = false) 38 | var connectionUrl: String = "" 39 | 40 | /** 41 | * Currently, it has to be set, but it is only necessary for the Git provider JGIT. 42 | */ 43 | @Parameter(property = "developerConnectionUrl", defaultValue = "\${project.scm.developerConnection}", required = false) 44 | var developerConnectionUrl: String = "" 45 | 46 | /** 47 | * Currently, it has to be set, but it is only necessary for the Git provider JGIT. 48 | */ 49 | @Parameter(property = "connectionType", defaultValue = "connection", required = true) 50 | lateinit var connectionType: String 51 | 52 | /** 53 | * Set which Git provider should use, the installed git binary on your systen (NATIVE) or JGit (JGIT). 54 | */ 55 | @Parameter(property = "dependencyUpdate.git.provider", defaultValue = "NATIVE", required = false) 56 | lateinit var gitProvider: GitProviderChoice 57 | 58 | @Component 59 | lateinit var artifactFactory: ArtifactFactory 60 | 61 | @Component 62 | lateinit var artifactMetadataSource: ArtifactMetadataSource 63 | 64 | private val connection: String 65 | get() = if (connectionType == "developerConnection") developerConnectionUrl else connectionUrl 66 | 67 | override fun execute() { 68 | withGit { git -> 69 | val updateCandidates = UpdateResolver( 70 | mavenProject = mavenProject, 71 | artifactMetadataSource = artifactMetadataSource, 72 | localRepository = localRepository, 73 | artifactFactory = artifactFactory, 74 | mavenSession = mavenSession 75 | ) 76 | .updates 77 | .onEach { log.debug("execute in mojo: latestVersion: '${it.latestVersion}' / version:'${it.version}'") } 78 | .filterNot(VersionUpdate::isAlreadyLatestVersion) 79 | .onEach { log.debug("execute in mojo after latest version check: ${it.latestVersion}") } 80 | .map { it to UpdateBranchName(it.groupId, it.artifactId, it.latestVersion) } 81 | .onEach { log.debug("execute in mojo canSkip (after map): ${it.second} ${it.first}") } 82 | 83 | val updateCandidatesWithExistingUpdateBranch = updateCandidates 84 | .filter { (_, branchName) -> git.hasRemoteBranchWithPrefix(branchName.prefix()) } 85 | 86 | updateCandidatesWithExistingUpdateBranch 87 | .forEach { (_, branchName) -> 88 | log.warn( 89 | "Dependency '${branchName.prefix()}' already has a branch for a previous version update. " + 90 | "Please merge it first" 91 | ) 92 | } 93 | 94 | val updatesWithoutBranchForVersion = 95 | updateCandidates.filterNot { (_, branchName) -> git.hasRemoteBranchWithPrefix(branchName.prefix()) } 96 | 97 | updatesWithoutBranchForVersion 98 | .onEach { log.debug("execute in mojo after filter branches: ${it.second} ${it.first}") } 99 | .forEach { (update, branchName) -> 100 | git.checkoutNewBranch(branchName.toString()) 101 | val pom = update.updatedPom() 102 | mavenProject.file.writeText(pom.html()) 103 | git.add("pom.xml") 104 | git.commit( 105 | "dependency-update-bot", 106 | "", 107 | "Bump ${update.artifactId} from ${update.version} to ${update.latestVersion}" 108 | ) 109 | git.push(branchName.toString()) 110 | git.checkoutInitialBranch() 111 | } 112 | } 113 | } 114 | 115 | private fun withGit(f: (GitProvider) -> Unit) { 116 | configurationCheck() 117 | val git = gitProvider.createProvider(mavenProject.basedir.toPath(), settings, connection) 118 | git.use(f) 119 | } 120 | 121 | private fun configurationCheck() { 122 | if (gitProvider == GitProviderChoice.JGIT && connection.isEmpty()) { 123 | throw MojoExecutionException( 124 | "You chose JGIT as GitProvider. Therefore, you have to set properties " + 125 | "'developerConnectionUrl' or 'connectionUrl' dependent on the 'connectionType'" 126 | ) 127 | } 128 | } 129 | 130 | data class UpdateBranchName(val groupId: String, val artifactId: String, val version: String) { 131 | fun prefix(): String { 132 | return "dependency-update/$groupId-$artifactId" 133 | } 134 | 135 | override fun toString(): String { 136 | return "${prefix()}-$version" 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateResolver.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.artifact.Artifact 4 | import org.apache.maven.artifact.factory.ArtifactFactory 5 | import org.apache.maven.artifact.metadata.ArtifactMetadataSource 6 | import org.apache.maven.artifact.repository.ArtifactRepository 7 | import org.apache.maven.execution.MavenSession 8 | import org.apache.maven.model.Dependency 9 | import org.apache.maven.project.MavenProject 10 | import org.jsoup.Jsoup 11 | import org.jsoup.nodes.Document 12 | import org.jsoup.parser.Parser 13 | 14 | class UpdateResolver( 15 | private val mavenProject: MavenProject, 16 | private val artifactMetadataSource: ArtifactMetadataSource, 17 | private val localRepository: ArtifactRepository, 18 | private val artifactFactory: ArtifactFactory, 19 | private val mavenSession: MavenSession 20 | ) { 21 | val reactorDependencies 22 | get() = mavenSession.projects 23 | 24 | val updates 25 | get() = 26 | parentUpdates + dependencyManagementUpdates + dependencyUpdates 27 | 28 | val parentUpdates 29 | get() = listOfNotNull(mavenProject.parentArtifact) 30 | .map { artifact -> 31 | ParentVersionUpdate( 32 | artifact.groupId, 33 | artifact.artifactId, 34 | artifact.version, 35 | retrieveLatestVersion(artifact), 36 | pomXml() 37 | ) 38 | } 39 | 40 | val dependencyManagementUpdates 41 | get() = (mavenProject.originalModel.dependencyManagement?.dependencies ?: listOf()) 42 | .filter(Dependency::isConcrete) 43 | .filterNot { isReactorArtifact(it) } 44 | .mapNotNull(artifactFactory::createDependencyArtifact) 45 | .map { artifact -> 46 | DependencyManagementVersionUpdate( 47 | artifact.groupId, 48 | artifact.artifactId, 49 | artifact.version, 50 | retrieveLatestVersion(artifact), 51 | pomXml() 52 | ) 53 | } 54 | 55 | val dependencyUpdates 56 | get() = mavenProject.originalModel.dependencies 57 | .filter(Dependency::isConcrete) 58 | .filterNot { isReactorArtifact(it) } 59 | .onEach { println("dependencyUpdates: $it") } 60 | .mapNotNull(artifactFactory::createDependencyArtifact) 61 | .map { a -> 62 | DependencyVersionUpdate( 63 | a.groupId, 64 | a.artifactId, 65 | a.version, 66 | retrieveLatestVersion(a), 67 | pomXml() 68 | ) 69 | } 70 | 71 | /** 72 | * Returns the latest version or (if not resolvable) the String {@code "null"}. 73 | * 74 | * @return the latest version as String or the String {@code "null"} if no latest version was found. 75 | */ 76 | private fun retrieveLatestVersion(artifact: Artifact) = 77 | artifactMetadataSource 78 | .retrieveAvailableVersions(artifact, localRepository, mavenProject.remoteArtifactRepositories) 79 | .onEach { println("retrieveLatestVersion: $it") } 80 | .filter { it.qualifier != "SNAPSHOT" } 81 | .maxOrNull() 82 | .toString() 83 | 84 | private fun isReactorArtifact(dependency: Dependency): Boolean = 85 | reactorDependencies 86 | .any { module -> 87 | dependency.groupId == module.groupId && 88 | dependency.artifactId == module.artifactId && 89 | dependency.version == module.version && 90 | dependency.type == module.packaging 91 | } 92 | 93 | private fun pomXml(): Document { 94 | return Jsoup.parse(mavenProject.file.readText(), "", Parser.xmlParser()) 95 | .apply { outputSettings().prettyPrint(false) } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/georgberky/maven/plugins/depsupdate/VersionUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.jsoup.nodes.Document 4 | 5 | abstract class VersionUpdate( 6 | val groupId: String, 7 | val artifactId: String, 8 | val version: String, 9 | val latestVersion: String 10 | ) { 11 | abstract fun updatedPom(): Document 12 | 13 | fun isAlreadyLatestVersion(): Boolean { 14 | // TODO #12: use DI-injected logger 15 | println("canSkip: $latestVersion compare to $version") 16 | println("latestVersion.equals(version) = ${latestVersion.equals(version)}") 17 | return latestVersion != "null" && latestVersion == version 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/ArtifactVersionComparisonTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.artifact.versioning.DefaultArtifactVersion 4 | import org.assertj.core.api.Assertions.assertThat 5 | import org.junit.jupiter.api.Test 6 | 7 | class ArtifactVersionComparisonTest { 8 | @Test 9 | internal fun sameVersionIsEqual() { 10 | val version = DefaultArtifactVersion("1.0.0") 11 | 12 | assertThat(version).isEqualTo(version) 13 | } 14 | 15 | @Test 16 | internal fun sameVersionIsEqualInKotlin() { 17 | val version = DefaultArtifactVersion("1.0.0") 18 | 19 | assertThat(version == version).isTrue() 20 | } 21 | 22 | @Test 23 | internal fun compareVersions() { 24 | val version1 = DefaultArtifactVersion("1.0.0") 25 | val version2 = DefaultArtifactVersion("1.2.0") 26 | 27 | assertThat(version1).isLessThan(version2) 28 | assertThat(version2).isGreaterThan(version1) 29 | } 30 | 31 | @Test 32 | internal fun compareVersionsKotlin() { 33 | val version1 = DefaultArtifactVersion("1.0.0") 34 | val version2 = DefaultArtifactVersion("1.2.0") 35 | 36 | assertThat(version1 < version2).isTrue() 37 | assertThat(version2 > version1).isTrue() 38 | } 39 | 40 | @Test 41 | internal fun canFindMax() { 42 | val versions = listOf( 43 | DefaultArtifactVersion("1.0.0"), 44 | DefaultArtifactVersion("1.3.0"), 45 | DefaultArtifactVersion("1.2.0") 46 | ) 47 | 48 | assertThat(versions.maxOrNull()).isEqualTo(DefaultArtifactVersion("1.3.0")) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/ArtifactoryExtensionsKtTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.artifact.Artifact 4 | import org.apache.maven.artifact.factory.DefaultArtifactFactory 5 | import org.apache.maven.artifact.handler.ArtifactHandler 6 | import org.apache.maven.artifact.handler.DefaultArtifactHandler 7 | import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager 8 | import org.apache.maven.model.Dependency 9 | import org.assertj.core.api.Assertions.assertThat 10 | import org.junitpioneer.jupiter.cartesian.CartesianTest 11 | 12 | internal class ArtifactoryExtensionsKtTest { 13 | 14 | @CartesianTest 15 | fun `returns NULL if scope is test or provided`( 16 | @CartesianTest.Values(strings = [ "somegroup" ]) groupId: String, 17 | @CartesianTest.Values(strings = [ "", "someArtifactId" ]) artifactId: String, 18 | @CartesianTest.Values(strings = [ "", "1.0.0", "1", "1.FINAL", "[1.0,2.0)" ]) versionSpec: String, 19 | @CartesianTest.Values(strings = [ "", "jar", "pom", "bundle" ]) type: String, 20 | @CartesianTest.Values(strings = [ "", "classes" ]) classifier: String, 21 | @CartesianTest.Values(strings = [ "", "provided", "test", "compile", "runtime", "import", "system" ]) scope: String, 22 | @CartesianTest.Values(strings = [ "true", "false" ]) inheritedScope: String 23 | ) { 24 | // given 25 | val artifactHandlerManager = object : ArtifactHandlerManager { 26 | override fun getArtifactHandler(type: String?): ArtifactHandler { 27 | return DefaultArtifactHandler() 28 | } 29 | 30 | override fun addHandlers(handlers: MutableMap?) { 31 | TODO("Not yet implemented") 32 | } 33 | } 34 | val defaultArtifactFactory = DefaultArtifactFactory() 35 | val declaredField = defaultArtifactFactory.javaClass.getDeclaredField("artifactHandlerManager") 36 | declaredField.isAccessible = true 37 | declaredField.set(defaultArtifactFactory, artifactHandlerManager) 38 | val dependency = Dependency() 39 | dependency.groupId = groupId 40 | dependency.artifactId = artifactId 41 | dependency.version = versionSpec 42 | dependency.classifier = classifier 43 | dependency.scope = scope 44 | dependency.optional = inheritedScope 45 | 46 | // when 47 | val artifact: Artifact? = defaultArtifactFactory.createDependencyArtifact(dependency) 48 | 49 | // expect 50 | if (scope == "provided" || scope == "test") { 51 | assertThat(artifact).isNull() 52 | } else { 53 | assertThat(artifact).isNotNull 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/Bug37NewBranchFromMainIT.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import com.soebes.itf.jupiter.extension.MavenGoal 4 | import com.soebes.itf.jupiter.extension.MavenJupiterExtension 5 | import com.soebes.itf.jupiter.extension.MavenTest 6 | import com.soebes.itf.jupiter.maven.MavenExecutionResult 7 | import com.soebes.itf.jupiter.maven.MavenProjectResult 8 | import org.apache.commons.io.FileUtils 9 | import org.assertj.core.api.Assertions.assertThat 10 | import org.eclipse.jgit.api.Git 11 | import org.eclipse.jgit.api.ListBranchCommand 12 | import org.junit.jupiter.api.BeforeEach 13 | import org.junit.jupiter.api.io.TempDir 14 | import java.io.File 15 | import java.util.stream.Collectors.toList 16 | 17 | @MavenJupiterExtension 18 | internal class Bug37NewBranchFromMainIT { 19 | 20 | @TempDir 21 | lateinit var remoteRepo: File 22 | 23 | lateinit var repo: Git 24 | 25 | @BeforeEach 26 | internal fun setUp(result: MavenProjectResult) { 27 | FileUtils.copyDirectory(result.targetProjectDirectory, remoteRepo) 28 | 29 | repo = Git.init().setInitialBranch("main").setDirectory(remoteRepo).call() 30 | repo.add().addFilepattern(".").call() 31 | repo.commit() 32 | .setAuthor("Schorsch", "georg@email.com") 33 | .setMessage("Initial commit.") 34 | .call() 35 | 36 | FileUtils.deleteDirectory(result.targetProjectDirectory) 37 | 38 | repo = Git.cloneRepository() 39 | .setURI(remoteRepo.toURI().toString()) 40 | .setDirectory(result.targetProjectDirectory) 41 | .call() 42 | } 43 | 44 | @MavenTest 45 | @MavenGoal("\${project.groupId}:\${project.artifactId}:\${project.version}:update") 46 | fun onlyOneDependency(result: MavenExecutionResult) { 47 | val branchList = repo.branchList() 48 | .setListMode(ListBranchCommand.ListMode.ALL) 49 | .call() 50 | .stream() 51 | .map { it.name } 52 | .collect(toList()) 53 | 54 | val updatedBranchName = branchList.filter { it.startsWith("refs/heads/dependency-update") }.first() 55 | repo.checkout().setName(updatedBranchName).call() 56 | 57 | val previousCommit = repo.repository.resolve("HEAD^") 58 | 59 | val branchesWithPreviousCommit = repo.branchList().setContains(previousCommit.name()).call() 60 | .map { it.name } 61 | .toList() 62 | 63 | assertThat(branchesWithPreviousCommit).contains("refs/heads/main") 64 | } 65 | 66 | @MavenTest 67 | @MavenGoal("\${project.groupId}:\${project.artifactId}:\${project.version}:update") 68 | fun moreThanOneDependency(result: MavenExecutionResult) { 69 | val branchList = repo.branchList() 70 | .setListMode(ListBranchCommand.ListMode.ALL) 71 | .call() 72 | .stream() 73 | .map { it.name } 74 | .collect(toList()) 75 | 76 | val updatedBranchNames = branchList.filter { it.startsWith("refs/heads/dependency-update") } 77 | 78 | updatedBranchNames.forEach { 79 | repo.checkout().setName(it).call() 80 | 81 | val previousCommit = repo.repository.resolve("HEAD^") 82 | 83 | val branchesWithPreviousCommit = repo.branchList().setContains(previousCommit.name()).call() 84 | .map { it.name } 85 | .toList() 86 | 87 | assertThat(branchesWithPreviousCommit).contains("refs/heads/main") 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/DependencyManagementVersionUpdateTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class DependencyManagementVersionUpdateTest { 7 | 8 | @Test 9 | fun updatedPom() { 10 | val pom = readPom("src/test/resources/poms/dependencyManagementPom.xml") 11 | 12 | val updateVersionUnderTest = DependencyManagementVersionUpdate("org.junit.jupiter", "junit-jupiter", "5.5.2", "5.6.0", pom) 13 | 14 | val updatedPom = updateVersionUnderTest.updatedPom() 15 | 16 | assertThat(extractFromPom(updatedPom, "project.dependencyManagement.dependencies.dependency.find{ it.artifactId == 'junit-jupiter' }.version")).isEqualTo("5.6.0") 17 | assertThat(extractFromPom(updatedPom, "project.dependencyManagement.dependencies.dependency.find{ it.artifactId == 'assertj-core' }.version")).isEqualTo("3.15.0") 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/DependencyVersionUpdateTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class DependencyVersionUpdateTest { 7 | 8 | @Test 9 | fun updatedPom() { 10 | val pom = readPom("src/test/resources/poms/dependenciesPom.xml") 11 | 12 | val updateVersionUnderTest = DependencyVersionUpdate("org.junit.jupiter", "junit-jupiter", "5.5.2", "5.6.0", pom) 13 | 14 | val updatedPom = updateVersionUnderTest.updatedPom() 15 | 16 | assertThat(extractFromPom(updatedPom, "project.dependencies.dependency.find{ it.artifactId == 'junit-jupiter' }.version")).isEqualTo("5.6.0") 17 | assertThat(extractFromPom(updatedPom, "project.dependencies.dependency.find{ it.artifactId == 'assertj-core' }.version")).isEqualTo("3.15.0") 18 | } 19 | 20 | @Test 21 | fun skipStringNullVersions() { 22 | // given 23 | val pom = readPom("src/test/resources/poms/dependenciesPom.xml") 24 | val depUpdate = DependencyVersionUpdate("org.junit.jupiter", "junit-jupiter", "5.5.2", "null", pom) 25 | 26 | // when 27 | val canSkip = depUpdate.isAlreadyLatestVersion() 28 | 29 | // then 30 | assertThat(canSkip) 31 | .isFalse 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/GitProviderTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.eclipse.jgit.api.Git 5 | import org.junit.jupiter.api.BeforeEach 6 | import org.junit.jupiter.api.Test 7 | import org.junit.jupiter.api.io.TempDir 8 | import java.io.File 9 | import java.net.URI 10 | import java.nio.file.Path 11 | 12 | abstract class GitProviderTest() { 13 | @TempDir 14 | lateinit var tempDir: File 15 | lateinit var localGitDirectory: File 16 | lateinit var localGitRepo: Git 17 | lateinit var remoteGitDirectory: File 18 | lateinit var remoteGitRepo: Git 19 | lateinit var providerUnderTest: GitProvider 20 | 21 | @BeforeEach 22 | internal fun setUp() { 23 | setupRemoteGitRepoWithInitCommit() 24 | setupLocalGitRepoAsCloneOf(remoteGitDirectory.toURI()) 25 | 26 | providerUnderTest = setupGitProvider(localGitDirectory.toPath()) 27 | } 28 | 29 | abstract fun setupGitProvider(localGitDirectoryPath: Path): GitProvider 30 | 31 | @Test 32 | internal fun `can add files`() { 33 | val newFile = File(localGitDirectory, "newFile") 34 | newFile.createNewFile() 35 | 36 | providerUnderTest.add(newFile.name) 37 | 38 | assertThat(localGitRepo.status().call().added) 39 | .containsExactly(newFile.name) 40 | } 41 | 42 | @Test 43 | internal fun `can commit`() { 44 | val fileToCommit = File(localGitDirectory, "fileToCommit") 45 | fileToCommit.createNewFile() 46 | localGitRepo.add().addFilepattern(fileToCommit.name).call() 47 | 48 | providerUnderTest.commit("Sandra Parsick", "sandra@email.com", "Hello George") 49 | 50 | assertThat(localGitRepo.status().call().isClean) 51 | .describedAs("repository status should be clean") 52 | .isTrue() 53 | 54 | assertThat(localGitRepo.log().setMaxCount(1).call().first()) 55 | .describedAs("commit author and message should match") 56 | .extracting("authorIdent.name", "authorIdent.emailAddress", "shortMessage") 57 | .isEqualTo(listOf("Sandra Parsick", "sandra@email.com", "Hello George")) 58 | } 59 | 60 | @Test 61 | internal fun `can checkout new branch`() { 62 | providerUnderTest.checkoutNewBranch("newBranch") 63 | 64 | assertThat(localGitRepo.repository.branch).isEqualTo("newBranch") 65 | } 66 | 67 | @Test 68 | internal fun `has no remote branch`() { 69 | val hasRemoteBranch = providerUnderTest.hasRemoteBranch("remoteBranch") 70 | 71 | assertThat(hasRemoteBranch).isFalse() 72 | } 73 | 74 | @Test 75 | internal fun `has remote branch`() { 76 | remoteGitRepo.branchCreate().setName("myNewRemoteBranch").call() 77 | localGitRepo.fetch().call() 78 | 79 | val hasRemoteBranch = providerUnderTest.hasRemoteBranch("myNewRemoteBranch") 80 | 81 | assertThat(hasRemoteBranch) 82 | .describedAs("remote branch should exist") 83 | .isTrue() 84 | } 85 | 86 | @Test 87 | internal fun `checkout initial branch`() { 88 | val initialBranch = localGitRepo.repository.branch 89 | val fileToCommit = File(localGitDirectory, "fileToCommit") 90 | fileToCommit.createNewFile() 91 | localGitRepo.branchCreate().setName("newBranch").call() 92 | localGitRepo.checkout().setName("newBranch").call() 93 | localGitRepo.add().addFilepattern(fileToCommit.name).call() 94 | localGitRepo.commit().setAuthor("Georg", "georg@email.com").setMessage("init").call() 95 | 96 | providerUnderTest.checkoutInitialBranch() 97 | 98 | assertThat(localGitRepo.repository.branch).isEqualTo(initialBranch) 99 | } 100 | 101 | @Test 102 | fun `has remote branch with prefix`() { 103 | remoteGitRepo.branchCreate().setName("branchName-suffix").call() 104 | localGitRepo.fetch().call() 105 | 106 | val hasRemoteBranchWithPrefix = providerUnderTest.hasRemoteBranchWithPrefix("branchName") 107 | 108 | assertThat(hasRemoteBranchWithPrefix) 109 | .describedAs("remote branch with prefix should exist") 110 | .isTrue() 111 | } 112 | 113 | private fun setupLocalGitRepoAsCloneOf(remoteGitDirectory: URI) { 114 | localGitDirectory = File(tempDir, "localGitRepoDir") 115 | localGitRepo = Git.cloneRepository() 116 | .setURI(remoteGitDirectory.toString()) 117 | .setDirectory(localGitDirectory) 118 | .call() 119 | } 120 | 121 | private fun setupRemoteGitRepoWithInitCommit() { 122 | remoteGitDirectory = File(tempDir, "remoteGitRepoD") 123 | remoteGitRepo = Git.init() 124 | .setDirectory(remoteGitDirectory) 125 | .call() 126 | val fileToCommit = File(remoteGitDirectory, "initFile") 127 | fileToCommit.createNewFile() 128 | remoteGitRepo.add().addFilepattern(fileToCommit.name).call() 129 | remoteGitRepo.commit().setAuthor("Georg", "georg@email.com").setMessage("init").call() 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/JGitProviderTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.apache.maven.settings.Settings 4 | import org.assertj.core.api.Assumptions.assumeThatCode 5 | import org.eclipse.jgit.api.errors.TransportException 6 | import org.junit.jupiter.api.Test 7 | import java.io.File 8 | import java.nio.file.Path 9 | 10 | class JGitProviderTest : GitProviderTest() { 11 | override fun setupGitProvider(localGitDirectoryPath: Path): GitProvider { 12 | return JGitProvider(localGitDirectoryPath, Settings(), "scm:git:" + remoteGitDirectory.toURI().toString()) 13 | } 14 | 15 | @Test 16 | internal fun `push change to remote repository`() { 17 | val fileToCommit = File(localGitDirectory, "fileToCommit") 18 | fileToCommit.createNewFile() 19 | localGitRepo.branchCreate().setName("newBranch").call() 20 | localGitRepo.checkout().setName("newBranch").call() 21 | localGitRepo.add().addFilepattern(fileToCommit.name).call() 22 | localGitRepo.commit().setAuthor("Georg", "georg@email.com").setMessage("init").call() 23 | 24 | val lambda = { providerUnderTest.push("newBranch") } 25 | 26 | // TODO need a solution for testing push with JGitProvider, change to assertThatCode when fixed 27 | assumeThatCode(lambda).isInstanceOf(TransportException::class.java) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/NativeGitProviderErrorHandlingTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions.assertThatThrownBy 4 | import org.junit.jupiter.api.BeforeEach 5 | import org.junit.jupiter.api.Test 6 | import org.junit.jupiter.api.io.TempDir 7 | import java.io.File 8 | 9 | internal class NativeGitProviderErrorHandlingTest { 10 | 11 | private var processOutput: String = "" 12 | private var returnValue: Int = 0 13 | 14 | private lateinit var gitProvider: NativeGitProvider 15 | 16 | @TempDir 17 | lateinit var tempDir: File 18 | 19 | @BeforeEach 20 | internal fun setUp() { 21 | gitProvider = object : NativeGitProvider(tempDir.toPath()) { 22 | override fun run(vararg command: String): ProcessResult { 23 | return ProcessResult(command, returnValue, processOutput, "").orThrow() 24 | } 25 | } 26 | } 27 | 28 | @Test 29 | internal fun `error handling for add`() { 30 | returnValue = -1 31 | 32 | val callAdd = { gitProvider.add("") } 33 | 34 | assertThatThrownBy(callAdd) 35 | .isInstanceOf(NativeGitProvider.ProcessException::class.java) 36 | .hasMessageContaining("return value") 37 | .hasMessageContaining("-1") 38 | .hasMessageContaining("git") 39 | .hasMessageContaining("add") 40 | } 41 | 42 | @Test 43 | internal fun `error handling for checkout new branch`() { 44 | returnValue = -1 45 | 46 | val callCheckoutNewBranch = { gitProvider.checkoutNewBranch("newBranch") } 47 | 48 | assertThatThrownBy(callCheckoutNewBranch) 49 | .isInstanceOf(NativeGitProvider.ProcessException::class.java) 50 | .hasMessageContaining("return value") 51 | .hasMessageContaining("-1") 52 | .hasMessageContaining("git") 53 | .hasMessageContaining("checkout") 54 | .hasMessageContaining("newBranch") 55 | } 56 | 57 | @Test 58 | internal fun `error handling for a remote branch checking`() { 59 | returnValue = -1 60 | 61 | val callHasRemoteBranch: () -> Unit = { gitProvider.hasRemoteBranch("remoteBranch") } 62 | 63 | assertThatThrownBy(callHasRemoteBranch) 64 | .isInstanceOf(NativeGitProvider.ProcessException::class.java) 65 | .hasMessageContaining("return value") 66 | .hasMessageContaining("-1") 67 | .hasMessageContaining("git") 68 | .hasMessageContaining("branch") 69 | } 70 | 71 | @Test 72 | internal fun `error handling for commit`() { 73 | returnValue = -1 74 | 75 | val callCommit: () -> Unit = { gitProvider.commit("Georg Berky", "georg@email.org", "a commit message") } 76 | 77 | assertThatThrownBy(callCommit) 78 | .isInstanceOf(NativeGitProvider.ProcessException::class.java) 79 | .hasMessageContaining("return value") 80 | .hasMessageContaining("-1") 81 | .hasMessageContaining("git") 82 | .hasMessageContaining("commit") 83 | .hasMessageContaining("Georg Berky") 84 | .hasMessageContaining("a commit message") 85 | } 86 | 87 | @Test 88 | internal fun `error handling for push`() { 89 | returnValue = -1 90 | 91 | val callPush: () -> Unit = { gitProvider.push("localBranch") } 92 | 93 | assertThatThrownBy(callPush) 94 | .isInstanceOf(NativeGitProvider.ProcessException::class.java) 95 | .hasMessageContaining("return value") 96 | .hasMessageContaining("-1") 97 | .hasMessageContaining("git") 98 | .hasMessageContaining("push") 99 | .hasMessageContaining("localBranch") 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/NativeGitProviderTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions 4 | import org.junit.jupiter.api.Test 5 | import java.io.File 6 | import java.nio.file.Path 7 | import java.util.stream.Collectors 8 | 9 | class NativeGitProviderTest : GitProviderTest() { 10 | override fun setupGitProvider(localGitDirectoryPath: Path): GitProvider = NativeGitProvider(localGitDirectoryPath) 11 | 12 | @Test // TODO need a solution for testing push with JGitProvider 13 | internal fun `push change to remote repository`() { 14 | val fileToCommit = File(localGitDirectory, "fileToCommit") 15 | fileToCommit.createNewFile() 16 | localGitRepo.branchCreate().setName("newBranch").call() 17 | localGitRepo.checkout().setName("newBranch").call() 18 | localGitRepo.add().addFilepattern(fileToCommit.name).call() 19 | localGitRepo.commit().setAuthor("Georg", "georg@email.com").setMessage("init").call() 20 | 21 | providerUnderTest.push("newBranch") 22 | 23 | val branchList = remoteGitRepo.branchList().call().stream() 24 | .map { it.name } 25 | .collect(Collectors.toList()) 26 | Assertions.assertThat(branchList).contains("refs/heads/newBranch") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/ParentVersionUpdateTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.jupiter.api.Test 5 | 6 | internal class ParentVersionUpdateTest { 7 | 8 | @Test 9 | fun updatedPom() { 10 | val pom = readPom("src/test/resources/poms/parentPom.xml") 11 | 12 | val updateVersionUnderTest = ParentVersionUpdate("dummy", "dummy", "dummy", "0.7.0", pom) 13 | 14 | val updatedPom = updateVersionUnderTest.updatedPom() 15 | 16 | assertThat(extractFromPom(updatedPom, "project.parent.version")).isEqualTo("0.7.0") 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/PomHelper.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import io.restassured.path.xml.XmlPath 4 | import org.jsoup.Jsoup 5 | import org.jsoup.nodes.Document 6 | import org.jsoup.parser.Parser 7 | import java.io.File 8 | 9 | fun readPom(pomPath: String): Document = 10 | Jsoup.parse(File(pomPath).readText(), "", Parser.xmlParser()).apply { 11 | outputSettings().prettyPrint(false) 12 | } 13 | 14 | fun extractFromPom(pom: Document, xmlPath: String) = 15 | XmlPath.with(pom.html()).getString(xmlPath) 16 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoIT.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import com.soebes.itf.jupiter.extension.MavenGoal 4 | import com.soebes.itf.jupiter.extension.MavenJupiterExtension 5 | import com.soebes.itf.jupiter.extension.MavenTest 6 | import com.soebes.itf.jupiter.maven.MavenExecutionResult 7 | import com.soebes.itf.jupiter.maven.MavenProjectResult 8 | import org.apache.commons.io.FileUtils 9 | import org.assertj.core.api.Assertions.assertThat 10 | import org.eclipse.jgit.api.Git 11 | import org.eclipse.jgit.api.ListBranchCommand 12 | import org.junit.jupiter.api.BeforeEach 13 | import org.junit.jupiter.api.io.TempDir 14 | import java.io.File 15 | import java.util.stream.Collectors.toList 16 | import com.soebes.itf.extension.assertj.MavenExecutionResultAssert.assertThat as mavenAssertThat 17 | 18 | @MavenJupiterExtension 19 | internal class UpdateMojoIT { 20 | 21 | @TempDir 22 | lateinit var remoteRepo: File 23 | 24 | lateinit var repo: Git 25 | 26 | private val alreadyExistingRemoteBranch = UpdateMojo.UpdateBranchName("org.assertj", "assertj-core", "3.16.0") 27 | 28 | @BeforeEach 29 | internal fun setUp(result: MavenProjectResult) { 30 | FileUtils.copyDirectory(result.targetProjectDirectory, remoteRepo) 31 | 32 | repo = Git.init().setInitialBranch("main").setDirectory(remoteRepo).call() 33 | repo.add().addFilepattern(".").call() 34 | repo.commit() 35 | .setAuthor("Schorsch", "georg@email.com") 36 | .setMessage("Initial commit.") 37 | .call() 38 | repo.branchCreate() 39 | .setName(alreadyExistingRemoteBranch.toString()).call() 40 | 41 | FileUtils.deleteDirectory(result.targetProjectDirectory) 42 | 43 | repo = Git.cloneRepository() 44 | .setURI(remoteRepo.toURI().toString()) 45 | .setDirectory(result.targetProjectDirectory) 46 | .call() 47 | } 48 | 49 | @MavenTest 50 | @MavenGoal("\${project.groupId}:\${project.artifactId}:\${project.version}:update") 51 | fun remoteBranchForPreviousVersionExists(result: MavenExecutionResult) { 52 | val branchList = repo.branchList() 53 | .setListMode(ListBranchCommand.ListMode.ALL) 54 | .call() 55 | .stream() 56 | .map { it.name } 57 | .collect(toList()) 58 | 59 | mavenAssertThat(result) 60 | .describedAs("the build should have been successful") 61 | .isSuccessful() 62 | 63 | mavenAssertThat(result).out().warn().contains("Dependency '${alreadyExistingRemoteBranch.prefix()}' already has a branch for a previous version update. Please merge it first") 64 | 65 | assertThat(branchList) 66 | .describedAs("should create remote feature branches for two dependencies") 67 | .filteredOn { it.startsWith("refs/remotes/") } 68 | .filteredOn { !it.contains("origin/main") } 69 | .hasSize(2) 70 | 71 | assertThat(branchList) 72 | .describedAs("already existing update branch should not have been overwritten") 73 | .contains("refs/remotes/origin/$alreadyExistingRemoteBranch") 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoJGitIT.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import com.github.sparsick.testcontainers.gitserver.GitServerContainer 4 | import com.jcraft.jsch.Session 5 | import com.soebes.itf.jupiter.extension.MavenGoal 6 | import com.soebes.itf.jupiter.extension.MavenJupiterExtension 7 | import com.soebes.itf.jupiter.extension.MavenOption 8 | import com.soebes.itf.jupiter.extension.MavenProject 9 | import com.soebes.itf.jupiter.extension.MavenTest 10 | import com.soebes.itf.jupiter.maven.MavenExecutionResult 11 | import com.soebes.itf.jupiter.maven.MavenProjectResult 12 | import org.apache.commons.io.FileUtils 13 | import org.assertj.core.api.Assertions.assertThat 14 | import org.eclipse.jgit.api.Git 15 | import org.eclipse.jgit.api.ListBranchCommand 16 | import org.eclipse.jgit.transport.SshTransport 17 | import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory 18 | import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig 19 | import org.junit.jupiter.api.BeforeEach 20 | import org.junit.jupiter.api.io.TempDir 21 | import org.testcontainers.junit.jupiter.Container 22 | import org.testcontainers.junit.jupiter.Testcontainers 23 | import org.testcontainers.utility.DockerImageName 24 | import java.io.File 25 | import java.util.stream.Collectors.toList 26 | import com.soebes.itf.extension.assertj.MavenExecutionResultAssert.assertThat as mavenAssertThat 27 | 28 | @MavenJupiterExtension 29 | @MavenProject("jgitProviderIsSet_scmConfigIsSet") 30 | @Testcontainers(disabledWithoutDocker = true) 31 | internal class UpdateMojoJGitIT { 32 | 33 | @Container 34 | private val gitServer = GitServerContainer(DockerImageName.parse("rockstorm/git-server:2.40")) 35 | 36 | @TempDir 37 | lateinit var remoteRepo: File 38 | 39 | lateinit var repo: Git 40 | 41 | @BeforeEach 42 | internal fun setUp(result: MavenProjectResult) { 43 | val sshSessionFactory = object : JschConfigSessionFactory() { 44 | override fun configure(host: OpenSshConfig.Host?, session: Session?) { 45 | session?.setPassword("12345") 46 | session?.setConfig("StrictHostKeyChecking", "no") 47 | } 48 | } 49 | 50 | prepareRemoteRepo(sshSessionFactory, result) 51 | 52 | FileUtils.deleteDirectory(result.targetProjectDirectory) 53 | 54 | repo = Git.cloneRepository() 55 | .setURI(gitServer.getGitRepoURIAsSSH().toString()) 56 | .setDirectory(result.targetProjectDirectory) 57 | .setBranch("main") 58 | .setTransportConfigCallback({ transport -> 59 | val sshTransport = transport as SshTransport 60 | sshTransport.sshSessionFactory = sshSessionFactory 61 | }) 62 | .call() 63 | } 64 | 65 | private fun prepareRemoteRepo(sshSessionFactory: JschConfigSessionFactory, result: MavenProjectResult) { 66 | // TODO: replace scm connection in pom.xml 67 | val remoteRepoGit = Git.cloneRepository() 68 | .setURI(gitServer.getGitRepoURIAsSSH().toString()) 69 | .setDirectory(remoteRepo) 70 | .setBranch("main") 71 | .setTransportConfigCallback { transport -> 72 | val sshTransport = transport as SshTransport 73 | sshTransport.sshSessionFactory = sshSessionFactory 74 | } 75 | .call() 76 | 77 | FileUtils.copyDirectory(result.targetProjectDirectory, remoteRepo) 78 | remoteRepoGit.add().addFilepattern(".").call() 79 | remoteRepoGit.commit() 80 | .setAuthor("Schorsch", "georg@email.com") 81 | .setMessage("Initial commit.") 82 | .call() 83 | 84 | remoteRepoGit.push() 85 | .setTransportConfigCallback { transport -> 86 | val sshTransport = transport as SshTransport 87 | sshTransport.sshSessionFactory = sshSessionFactory 88 | }.call() 89 | } 90 | 91 | @MavenTest 92 | @MavenGoal("\${project.groupId}:\${project.artifactId}:\${project.version}:update") 93 | @MavenOption(value = "--settings", parameter = "settings.xml") 94 | fun jgitProviderIsSet_scmConfigIsSet(result: MavenExecutionResult) { 95 | val branchList = repo.branchList() 96 | .setListMode(ListBranchCommand.ListMode.ALL) 97 | .call() 98 | .stream() 99 | .map { it.name } 100 | .collect(toList()) 101 | 102 | mavenAssertThat(result) 103 | .describedAs("the build should have been successful") 104 | .isSuccessful() 105 | 106 | assertThat(branchList) 107 | .describedAs("should create remote feature branches for two dependencies") 108 | .filteredOn { it.startsWith("refs/remotes/") } 109 | .filteredOn { !it.contains("origin/main") } 110 | .hasSize(2) 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoJGitScmConfigIsMissingIT.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import com.soebes.itf.jupiter.extension.MavenGoal 4 | import com.soebes.itf.jupiter.extension.MavenJupiterExtension 5 | import com.soebes.itf.jupiter.extension.MavenProject 6 | import com.soebes.itf.jupiter.extension.MavenTest 7 | import com.soebes.itf.jupiter.maven.MavenExecutionResult 8 | import com.soebes.itf.jupiter.maven.MavenProjectResult 9 | import org.apache.commons.io.FileUtils 10 | import org.eclipse.jgit.api.Git 11 | import org.junit.jupiter.api.BeforeEach 12 | import org.junit.jupiter.api.io.TempDir 13 | import java.io.File 14 | import com.soebes.itf.extension.assertj.MavenExecutionResultAssert.assertThat as mavenAssertThat 15 | 16 | @MavenJupiterExtension 17 | @MavenProject("jgitProviderIsSet_scmConfigIsMissing") 18 | internal class UpdateMojoJGitScmConfigIsMissingIT { 19 | 20 | @TempDir 21 | lateinit var remoteRepo: File 22 | 23 | lateinit var repo: Git 24 | 25 | @BeforeEach 26 | internal fun setUp(result: MavenProjectResult) { 27 | FileUtils.copyDirectory(result.targetProjectDirectory, remoteRepo) 28 | 29 | repo = Git.init().setDirectory(remoteRepo).call() 30 | repo.add().addFilepattern(".").call() 31 | repo.commit() 32 | .setAuthor("Schorsch", "georg@email.com") 33 | .setMessage("Initial commit.") 34 | .call() 35 | 36 | FileUtils.deleteDirectory(result.targetProjectDirectory) 37 | 38 | repo = Git.cloneRepository() 39 | .setURI(remoteRepo.toURI().toString()) 40 | .setDirectory(result.targetProjectDirectory) 41 | .call() 42 | } 43 | 44 | @MavenTest 45 | @MavenGoal("\${project.groupId}:\${project.artifactId}:\${project.version}:update") 46 | fun jgitProviderIsSet_scmConfigIsMissing(result: MavenExecutionResult) { 47 | mavenAssertThat(result) 48 | .describedAs("the build should have been failed") 49 | .isFailure() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoNativeGitIT.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import com.soebes.itf.jupiter.extension.MavenGoal 4 | import com.soebes.itf.jupiter.extension.MavenJupiterExtension 5 | import com.soebes.itf.jupiter.extension.MavenProject 6 | import com.soebes.itf.jupiter.extension.MavenTest 7 | import com.soebes.itf.jupiter.maven.MavenExecutionResult 8 | import com.soebes.itf.jupiter.maven.MavenProjectResult 9 | import org.apache.commons.io.FileUtils 10 | import org.assertj.core.api.Assertions.assertThat 11 | import org.eclipse.jgit.api.Git 12 | import org.eclipse.jgit.api.ListBranchCommand 13 | import org.junit.jupiter.api.BeforeEach 14 | import org.junit.jupiter.api.io.TempDir 15 | import java.io.File 16 | import java.util.stream.Collectors.toList 17 | import com.soebes.itf.extension.assertj.MavenExecutionResultAssert.assertThat as mavenAssertThat 18 | 19 | @MavenJupiterExtension 20 | @MavenProject("nativeProviderIsSet") 21 | internal class UpdateMojoNativeGitIT { 22 | 23 | @TempDir 24 | lateinit var remoteRepo: File 25 | 26 | lateinit var repo: Git 27 | 28 | @BeforeEach 29 | internal fun setUp(result: MavenProjectResult) { 30 | FileUtils.copyDirectory(result.targetProjectDirectory, remoteRepo) 31 | 32 | repo = Git.init().setInitialBranch("main").setDirectory(remoteRepo).call() 33 | repo.add().addFilepattern(".").call() 34 | repo.commit() 35 | .setAuthor("Schorsch", "georg@email.com") 36 | .setMessage("Initial commit.") 37 | .call() 38 | 39 | FileUtils.deleteDirectory(result.targetProjectDirectory) 40 | 41 | repo = Git.cloneRepository() 42 | .setURI(remoteRepo.toURI().toString()) 43 | .setDirectory(result.targetProjectDirectory) 44 | .call() 45 | } 46 | 47 | @MavenTest 48 | @MavenGoal("\${project.groupId}:\${project.artifactId}:\${project.version}:update") 49 | fun nativeProviderIsSet(result: MavenExecutionResult) { 50 | val branchList = repo.branchList() 51 | .setListMode(ListBranchCommand.ListMode.ALL) 52 | .call() 53 | .stream() 54 | .map { it.name } 55 | .collect(toList()) 56 | 57 | mavenAssertThat(result) 58 | .describedAs("the build should have been successful") 59 | .isSuccessful() 60 | 61 | assertThat(branchList) 62 | .describedAs("should create remote feature branches for two dependencies") 63 | .filteredOn { it.startsWith("refs/remotes/") } 64 | .filteredOn { !it.contains("origin/main") } 65 | .hasSize(2) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/UpdateResolverTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import io.mockk.every 4 | import io.mockk.impl.annotations.MockK 5 | import io.mockk.junit5.MockKExtension 6 | import org.apache.maven.artifact.factory.ArtifactFactory 7 | import org.apache.maven.artifact.metadata.ArtifactMetadataSource 8 | import org.apache.maven.artifact.repository.ArtifactRepository 9 | import org.apache.maven.artifact.versioning.DefaultArtifactVersion 10 | import org.apache.maven.artifact.versioning.VersionRange 11 | import org.apache.maven.execution.MavenSession 12 | import org.apache.maven.model.Dependency 13 | import org.apache.maven.model.DependencyManagement 14 | import org.apache.maven.model.Model 15 | import org.apache.maven.plugin.testing.ArtifactStubFactory 16 | import org.apache.maven.project.MavenProject 17 | import org.assertj.core.api.Assertions.assertThat 18 | import org.assertj.core.api.Assertions.tuple 19 | import org.junit.jupiter.api.BeforeEach 20 | import org.junit.jupiter.api.Test 21 | import org.junit.jupiter.api.extension.ExtendWith 22 | import java.io.File 23 | 24 | @ExtendWith(MockKExtension::class) 25 | internal class UpdateResolverTest { 26 | private val junitArtifact = artifact("org.junit.jupiter", "junit-jupiter", "5.5.2") 27 | private val junitDependency = dependency("org.junit.jupiter", "junit-jupiter", "5.5.2") 28 | private val assertJDependency = dependency("org.assertj", "assertj-core", "3.15.0") 29 | private val assertJArtifact = artifact("org.assertj", "assertj-core", "3.15.0") 30 | private val reactorModuleA = dependency("com.text", "moduleA", "1.0.0-SNAPSHOT") 31 | private val reactorModuleAArtifact = artifact("com.text", "moduleA", "1.0.0-SNAPSHOT") 32 | private val reactorModuleB = dependency("com.text", "moduleB", "1.0.0-SNAPSHOT") 33 | private val reactorModuleBArtifact = artifact("com.text", "moduleB", "1.0.0-SNAPSHOT") 34 | 35 | @MockK 36 | lateinit var metadataSourceMock: ArtifactMetadataSource 37 | 38 | @MockK 39 | lateinit var localRepositoryMock: ArtifactRepository 40 | 41 | @MockK 42 | lateinit var artifactFactoryMock: ArtifactFactory 43 | 44 | @MockK 45 | lateinit var mavenSession: MavenSession 46 | 47 | @BeforeEach 48 | fun setUpMocks() { 49 | every { mavenSession.projects } returns listOf() 50 | } 51 | 52 | @Test 53 | fun parentUpdate() { 54 | val project = projectWithParent() 55 | every { metadataSourceMock.retrieveAvailableVersions(project.parentArtifact, any(), any()) } returns listOf(DefaultArtifactVersion("1.0.0")) 56 | 57 | val updateResolverUnderTest = UpdateResolver( 58 | project, 59 | metadataSourceMock, 60 | localRepositoryMock, 61 | artifactFactoryMock, 62 | mavenSession 63 | ) 64 | 65 | assertThat(updateResolverUnderTest.parentUpdates) 66 | .hasSize(1) 67 | .extracting("groupId", "artifactId", "version", "latestVersion") 68 | .containsExactly( 69 | tuple( 70 | project.parentArtifact.groupId, 71 | project.parentArtifact.artifactId, 72 | project.parentArtifact.version, 73 | "1.0.0" 74 | ) 75 | ) 76 | } 77 | 78 | @Test 79 | fun dependencyUpdates() { 80 | val project = projectWithDependencies() 81 | every { metadataSourceMock.retrieveAvailableVersions(any(), any(), any()) } returns listOf(DefaultArtifactVersion("6.0.0")) 82 | every { artifactFactoryMock.createDependencyArtifact(junitDependency) } returns junitArtifact 83 | every { artifactFactoryMock.createDependencyArtifact(assertJDependency) } returns assertJArtifact 84 | 85 | val updateResolverUnderTest = UpdateResolver( 86 | project, 87 | metadataSourceMock, 88 | localRepositoryMock, 89 | artifactFactoryMock, 90 | mavenSession 91 | ) 92 | 93 | assertThat(updateResolverUnderTest.dependencyUpdates) 94 | .hasSize(2) 95 | .extracting("groupId", "artifactId", "version", "latestVersion") 96 | .containsExactly( 97 | tuple("org.junit.jupiter", "junit-jupiter", "5.5.2", "6.0.0"), 98 | tuple("org.assertj", "assertj-core", "3.15.0", "6.0.0") 99 | ) 100 | } 101 | 102 | @Test 103 | fun dependencyManagementUpdates() { 104 | val project = projectWithDependenciesManagement() 105 | every { metadataSourceMock.retrieveAvailableVersions(any(), any(), any()) } returns listOf(DefaultArtifactVersion("6.0.0")) 106 | every { artifactFactoryMock.createDependencyArtifact(junitDependency) } returns junitArtifact 107 | every { artifactFactoryMock.createDependencyArtifact(assertJDependency) } returns assertJArtifact 108 | 109 | val updateResolverUnderTest = UpdateResolver( 110 | project, 111 | metadataSourceMock, 112 | localRepositoryMock, 113 | artifactFactoryMock, 114 | mavenSession 115 | ) 116 | 117 | assertThat(updateResolverUnderTest.dependencyManagementUpdates) 118 | .hasSize(2) 119 | .extracting("groupId", "artifactId", "version", "latestVersion") 120 | .containsExactly( 121 | tuple("org.junit.jupiter", "junit-jupiter", "5.5.2", "6.0.0"), 122 | tuple("org.assertj", "assertj-core", "3.15.0", "6.0.0") 123 | ) 124 | } 125 | 126 | @Test 127 | fun reactorProjectSkipsReactorModules() { 128 | val project = projectWithReactorDependencyManagement() 129 | 130 | val reactorModelA = Model() 131 | reactorModelA.groupId = reactorModuleA.groupId 132 | reactorModelA.artifactId = reactorModuleA.artifactId 133 | reactorModelA.version = reactorModuleA.version 134 | reactorModelA.packaging = "jar" 135 | val reactorModuleAProject = MavenProject(reactorModelA) 136 | 137 | val reactorModelB = Model() 138 | reactorModelB.groupId = reactorModuleB.groupId 139 | reactorModelB.artifactId = reactorModuleB.artifactId 140 | reactorModelB.version = reactorModuleB.version 141 | reactorModelB.packaging = "jar" 142 | val reactorModuleBProject = MavenProject(reactorModelB) 143 | 144 | every { mavenSession.projects } returns listOf(reactorModuleAProject, reactorModuleBProject) 145 | every { artifactFactoryMock.createDependencyArtifact(reactorModuleA) } returns reactorModuleAArtifact 146 | every { artifactFactoryMock.createDependencyArtifact(reactorModuleB) } returns reactorModuleBArtifact 147 | every { metadataSourceMock.retrieveAvailableVersions(any(), any(), any()) } returns listOf(DefaultArtifactVersion("6.0.0")) 148 | 149 | val updateResolverUnderTest = UpdateResolver( 150 | project, 151 | metadataSourceMock, 152 | localRepositoryMock, 153 | artifactFactoryMock, 154 | mavenSession 155 | ) 156 | 157 | assertThat(updateResolverUnderTest.dependencyManagementUpdates) 158 | .hasSize(0) 159 | } 160 | 161 | @Test 162 | fun nullDependencyUpdates() { 163 | // given 164 | val project = projectWithDependencies() 165 | val updateResolverUnderTest = UpdateResolver( 166 | project, 167 | metadataSourceMock, 168 | localRepositoryMock, 169 | artifactFactoryMock, 170 | mavenSession 171 | ) 172 | every { artifactFactoryMock.createDependencyArtifact(junitDependency) } returns null 173 | every { artifactFactoryMock.createDependencyArtifact(assertJDependency) } returns assertJArtifact 174 | 175 | // when 176 | val dependencyManagementUpdates = updateResolverUnderTest.dependencyManagementUpdates 177 | 178 | // then 179 | assertThat(dependencyManagementUpdates) 180 | .hasSize(0) 181 | } 182 | 183 | private fun projectWithParent(): MavenProject { 184 | val project = MavenProject() 185 | project.parentArtifact = artifact("io.github.georgberky.maven.plugins.depsupdate", "dependency-update-parent", "0.6.0") 186 | project.file = File("src/test/resources/poms/parentPom.xml") 187 | return project 188 | } 189 | 190 | private fun projectWithDependencies(): MavenProject { 191 | val project = MavenProject() 192 | val originalModel = Model() 193 | originalModel.dependencies = listOf(junitDependency, assertJDependency) 194 | project.originalModel = originalModel 195 | project.file = File("src/test/resources/poms/dependenciesPom.xml") 196 | return project 197 | } 198 | 199 | private fun projectWithDependenciesManagement(): MavenProject { 200 | val project = MavenProject() 201 | val originalModel = Model() 202 | val dependencyManagement = DependencyManagement() 203 | dependencyManagement.dependencies = listOf(junitDependency, assertJDependency) 204 | originalModel.dependencyManagement = dependencyManagement 205 | project.originalModel = originalModel 206 | project.file = File("src/test/resources/poms/dependencyManagementPom.xml") 207 | return project 208 | } 209 | 210 | private fun projectWithReactorDependencyManagement(): MavenProject { 211 | val project = MavenProject() 212 | val originalModel = Model() 213 | val dependencyManagement = DependencyManagement() 214 | dependencyManagement.dependencies = listOf(reactorModuleA, reactorModuleB) 215 | originalModel.dependencyManagement = dependencyManagement 216 | project.originalModel = originalModel 217 | project.file = File("src/test/resources/poms/dependencyManagementPom.xml") 218 | return project 219 | } 220 | 221 | private fun dependency(groupId: String, artifactId: String, version: String): Dependency { 222 | val dependency = Dependency() 223 | dependency.groupId = groupId 224 | dependency.artifactId = artifactId 225 | dependency.version = version 226 | return dependency 227 | } 228 | 229 | private fun artifact(groupId: String, artifactId: String, version: String) = 230 | ArtifactStubFactory().createArtifact( 231 | groupId, 232 | artifactId, 233 | VersionRange.createFromVersion(version), 234 | "compile", 235 | "jar", 236 | "", 237 | false 238 | ) 239 | } 240 | -------------------------------------------------------------------------------- /src/test/kotlin/io/github/georgberky/maven/plugins/depsupdate/VersionUpdateTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.georgberky.maven.plugins.depsupdate 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.jsoup.nodes.Document 5 | import org.junit.jupiter.params.ParameterizedTest 6 | import org.junit.jupiter.params.provider.Arguments 7 | import org.junit.jupiter.params.provider.Arguments.arguments 8 | import org.junit.jupiter.params.provider.MethodSource 9 | import java.util.stream.Stream 10 | 11 | internal class VersionUpdateTest { 12 | @ParameterizedTest 13 | @MethodSource("sameVersionUpdates") 14 | fun `is latest version returns true if version numbers are the same`(current: String, latest: String) { 15 | val versionUpdate = object : VersionUpdate("someGroupId", "someArtifactId", current, latest) { 16 | override fun updatedPom(): Document { 17 | throw Exception("should not be called") 18 | } 19 | } 20 | 21 | assertThat(versionUpdate.isAlreadyLatestVersion()) 22 | .isTrue() 23 | } 24 | 25 | @ParameterizedTest 26 | @MethodSource("differentVersionUpdates") 27 | fun `is latest version returns false if version numbers differ`(current: String, latest: String) { 28 | val versionUpdate = object : VersionUpdate("someGroupId", "someArtifactId", current, latest) { 29 | override fun updatedPom(): Document { 30 | throw Exception("should not be called") 31 | } 32 | } 33 | 34 | assertThat(versionUpdate.isAlreadyLatestVersion()) 35 | .isFalse() 36 | } 37 | 38 | companion object { 39 | @JvmStatic 40 | fun sameVersionUpdates(): Stream { 41 | return Stream.of( 42 | arguments("1.0.0", "1.0.0"), 43 | arguments("1.1.0", "1.1.0"), 44 | arguments("1.0.1", "1.0.1") 45 | ) 46 | } 47 | 48 | @JvmStatic 49 | fun differentVersionUpdates(): Stream { 50 | return Stream.of( 51 | arguments("1.0.0", "2.0.0"), 52 | arguments("1.1.0", "2.1.0"), 53 | arguments("1.0.1", "2.0.1") 54 | ) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/Bug37NewBranchFromMainIT/moreThanOneDependency/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.georgberky.maven.plugins.depsupdate 6 | bug-37-test 7 | 0.6.0 8 | 9 | 10 | someConnection 11 | someDeveloperConnection 12 | 13 | 14 | 15 | 16 | org.junit.jupiter 17 | junit-jupiter 18 | 5.5.2 19 | 20 | 21 | org.assertj 22 | assertj-core 23 | 3.15.0 24 | 25 | 26 | 27 | 28 | 29 | 30 | ${project.groupId} 31 | ${project.artifactId} 32 | ${project.version} 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/Bug37NewBranchFromMainIT/onlyOneDependency/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.georgberky.maven.plugins.depsupdate 6 | bug-37-test 7 | 0.6.0 8 | 9 | 10 | someConnection 11 | someDeveloperConnection 12 | 13 | 14 | 15 | 16 | org.junit.jupiter 17 | junit-jupiter 18 | 5.5.2 19 | 20 | 21 | 22 | 23 | 24 | 25 | ${project.groupId} 26 | ${project.artifactId} 27 | ${project.version} 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoIT/remoteBranchForPreviousVersionExists/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.georgberky.maven.plugins.depsupdate 6 | native-git-provider-test 7 | 0.6.0 8 | 9 | 10 | someConnection 11 | someDeveloperConnection 12 | 13 | 14 | 15 | 16 | org.junit.jupiter 17 | junit-jupiter 18 | 5.5.2 19 | 20 | 21 | org.assertj 22 | assertj-core 23 | 3.15.0 24 | 25 | 26 | 27 | 28 | 29 | 30 | ${project.groupId} 31 | ${project.artifactId} 32 | ${project.version} 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoJGitIT/jgitProviderIsSet_scmConfigIsSet/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.georgberky.maven.plugins.depsupdate 6 | jgit-provider-test 7 | 0.6.0 8 | 9 | 10 | scm:git:ssh://git@localhost:2222/srv/git/jgit-test.git 11 | 12 | 13 | 14 | 15 | org.junit.jupiter 16 | junit-jupiter 17 | 5.5.2 18 | 19 | 20 | org.assertj 21 | assertj-core 22 | 3.15.0 23 | 24 | 25 | 26 | 27 | 28 | 29 | ${project.groupId} 30 | ${project.artifactId} 31 | ${project.version} 32 | 33 | JGIT 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoJGitIT/jgitProviderIsSet_scmConfigIsSet/settings.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | localhost 6 | git 7 | 12345 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoJGitScmConfigIsMissingIT/jgitProviderIsSet_scmConfigIsMissing/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.georgberky.maven.plugins.depsupdate 6 | jgit-provider-test 7 | 0.6.0 8 | 9 | 10 | 11 | org.junit.jupiter 12 | junit-jupiter 13 | 5.5.2 14 | 15 | 16 | org.assertj 17 | assertj-core 18 | 3.15.0 19 | 20 | 21 | 22 | 23 | 24 | 25 | ${project.groupId} 26 | ${project.artifactId} 27 | ${project.version} 28 | 29 | JGIT 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/test/resources-its/io/github/georgberky/maven/plugins/depsupdate/UpdateMojoNativeGitIT/nativeProviderIsSet/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.georgberky.maven.plugins.depsupdate 6 | native-git-provider-test 7 | 0.6.0 8 | 9 | 10 | 11 | org.junit.jupiter 12 | junit-jupiter 13 | 5.5.2 14 | 15 | 16 | org.assertj 17 | assertj-core 18 | 3.15.0 19 | 20 | 21 | 22 | 23 | 24 | 25 | ${project.groupId} 26 | ${project.artifactId} 27 | ${project.version} 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/test/resources/poms/dependenciesPom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | io.github.georgberky.maven.plugins.depsupdate 7 | dependency-update-parent 8 | 0.6.0 9 | 10 | 11 | io.github.georgberky.maven.plugins.depsupdate 12 | dependency-update-maven-plugin 13 | 0.6.0 14 | 15 | 16 | 17 | org.junit.jupiter 18 | junit-jupiter 19 | 5.5.2 20 | 21 | 22 | org.assertj 23 | assertj-core 24 | 3.15.0 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/test/resources/poms/dependencyManagementPom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | io.github.georgberky.maven.plugins.depsupdate 7 | dependency-update-parent 8 | 0.6.0 9 | 10 | 11 | io.github.georgberky.maven.plugins.depsupdate 12 | dependency-update-maven-plugin 13 | 0.6.0 14 | 15 | 16 | 17 | 18 | org.junit.jupiter 19 | junit-jupiter 20 | 5.5.2 21 | 22 | 23 | org.assertj 24 | assertj-core 25 | 3.15.0 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/test/resources/poms/parentPom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | io.github.georgberky.maven.plugins.depsupdate 7 | dependency-update-parent 8 | 0.6.0 9 | 10 | 11 | io.github.georgberky.maven.plugins.depsupdate 12 | dependency-update-maven-plugin 13 | 0.6.0 14 | 15 | 16 | 17 | --------------------------------------------------------------------------------