├── .editorconfig ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ └── verify.yaml ├── .gitignore ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── .sdkmanrc ├── LICENSE ├── README.adoc ├── build └── eclipse-formatter-config.xml ├── mvnw ├── mvnw.cmd ├── pom-tuner-tests ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── l2x6 │ │ └── pom │ │ └── tuner │ │ ├── MavenSourceTreeTest.java │ │ ├── PomTransformerTest.java │ │ ├── model │ │ ├── AbstractSetTest.java │ │ ├── GavPatternTest.java │ │ ├── GavSetTest.java │ │ ├── GavTest.java │ │ ├── GavtcsPatternTest.java │ │ ├── GavtcsSetTest.java │ │ └── GlobTest.java │ │ └── shell │ │ ├── BadExitCodeException.java │ │ ├── BuildException.java │ │ ├── CommandTimeoutException.java │ │ ├── LineConsumer.java │ │ ├── Shell.java │ │ └── ShellCommand.java │ └── resources │ ├── MavenSourceTree │ ├── properties │ │ ├── middle │ │ │ ├── module-1 │ │ │ │ └── pom.xml │ │ │ ├── module-2 │ │ │ │ └── pom.xml │ │ │ └── pom.xml │ │ └── pom.xml │ ├── set-versions-expected │ │ ├── module-1 │ │ │ └── pom.xml │ │ ├── module-2 │ │ │ └── pom.xml │ │ ├── module-3 │ │ │ └── pom.xml │ │ ├── module-4 │ │ │ └── pom.xml │ │ ├── module-5 │ │ │ └── pom.xml │ │ ├── module-6 │ │ │ └── pom.xml │ │ ├── module-7 │ │ │ └── pom.xml │ │ ├── plugin-1 │ │ │ └── pom.xml │ │ ├── plugin-2 │ │ │ └── pom.xml │ │ ├── plugin-3 │ │ │ └── pom.xml │ │ └── pom.xml │ ├── set-versions │ │ ├── module-1 │ │ │ └── pom.xml │ │ ├── module-2 │ │ │ └── pom.xml │ │ ├── module-3 │ │ │ └── pom.xml │ │ ├── module-4 │ │ │ └── pom.xml │ │ ├── module-5 │ │ │ └── pom.xml │ │ ├── module-6 │ │ │ └── pom.xml │ │ ├── module-7 │ │ │ └── pom.xml │ │ ├── plugin-1 │ │ │ └── pom.xml │ │ ├── plugin-2 │ │ │ └── pom.xml │ │ ├── plugin-3 │ │ │ └── pom.xml │ │ └── pom.xml │ ├── tree-1-expected │ │ ├── declared-parent │ │ │ ├── module-8 │ │ │ │ └── pom.xml │ │ │ └── pom.xml │ │ ├── module-1 │ │ │ └── pom.xml │ │ ├── module-2 │ │ │ └── pom.xml │ │ ├── module-3 │ │ │ └── pom.xml │ │ ├── module-4 │ │ │ └── pom.xml │ │ ├── module-6 │ │ │ └── pom.xml │ │ ├── module-7 │ │ │ └── pom.xml │ │ ├── plugin │ │ │ └── pom.xml │ │ ├── pom.xml │ │ └── proper-parent │ │ │ ├── module-5 │ │ │ └── pom.xml │ │ │ └── pom.xml │ └── tree-1 │ │ ├── declared-parent │ │ ├── module-8 │ │ │ └── pom.xml │ │ └── pom.xml │ │ ├── module-1 │ │ └── pom.xml │ │ ├── module-2 │ │ └── pom.xml │ │ ├── module-3 │ │ └── pom.xml │ │ ├── module-4 │ │ └── pom.xml │ │ ├── module-6 │ │ └── pom.xml │ │ ├── module-7 │ │ └── pom.xml │ │ ├── plugin │ │ └── pom.xml │ │ ├── pom.xml │ │ └── proper-parent │ │ ├── module-5 │ │ └── pom.xml │ │ └── pom.xml │ └── settings-mrm.xml ├── pom-tuner ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── l2x6 │ │ └── pom │ │ └── tuner │ │ ├── Comparators.java │ │ ├── ExpressionEvaluator.java │ │ ├── MavenSourceTree.java │ │ ├── PomTransformer.java │ │ ├── PomTunerUtils.java │ │ └── model │ │ ├── Dependency.java │ │ ├── Expression.java │ │ ├── Ga.java │ │ ├── Gav.java │ │ ├── GavExpression.java │ │ ├── GavPattern.java │ │ ├── GavSet.java │ │ ├── Gavtcs.java │ │ ├── GavtcsPattern.java │ │ ├── GavtcsSet.java │ │ ├── Glob.java │ │ ├── Module.java │ │ ├── Plugin.java │ │ ├── Profile.java │ │ └── ValueDefinition.java │ └── test │ └── java │ └── org │ └── l2x6 │ └── pom │ └── tuner │ └── SomeSimpleTest.java └── pom.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2015 Maven Utilities Project 3 | # project contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # 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, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | root = true 19 | 20 | [*] 21 | charset = utf-8 22 | indent_style = space 23 | indent_size = 4 24 | trim_trailing_whitespace = true 25 | end_of_line = lf 26 | 27 | [*.cmd] 28 | end_of_line = crlf 29 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | *.cmd text eol=crlf 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2015 Maven Utilities Project 3 | # project contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # 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, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | version: 2 19 | updates: 20 | 21 | - package-ecosystem: "maven" 22 | directory: "/" 23 | schedule: 24 | interval: "daily" 25 | 26 | - package-ecosystem: "github-actions" 27 | directory: "/" 28 | schedule: 29 | interval: "daily" 30 | -------------------------------------------------------------------------------- /.github/workflows/verify.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2015 Maven Utilities Project 3 | # project contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # 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, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | name: CI 19 | 20 | on: 21 | push: 22 | branches: [ main ] 23 | pull_request: 24 | branches: [ main ] 25 | 26 | jobs: 27 | install: 28 | name: Install 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Set up Java 32 | uses: actions/setup-java@v4 33 | with: 34 | java-version: 21 35 | distribution: 'temurin' 36 | - name: Checkout 37 | uses: actions/checkout@v4 38 | with: 39 | persist-credentials: false 40 | - name: Cache 41 | uses: actions/cache@v4 42 | with: 43 | path: ~/.m2/repository 44 | key: pom-tuner-${{ hashFiles('**/pom.xml') }}-${{ github.sha }} 45 | restore-keys: | 46 | pom-tuner-${{ hashFiles('**/pom.xml') }}- 47 | pom-tuner- 48 | - name: Install 49 | shell: bash 50 | run: ./mvnw install -e -B -V -ntp 51 | 52 | test: 53 | name: Test 54 | needs: install 55 | runs-on: ubuntu-latest 56 | strategy: 57 | fail-fast: false 58 | matrix: 59 | os: [ "ubuntu-latest", "windows-latest", "macOS-latest" ] 60 | jdk: [ "8", "21" ] 61 | steps: 62 | - uses: actions/checkout@v4 63 | with: 64 | persist-credentials: false 65 | - uses: actions/setup-java@v4 66 | with: 67 | java-version: ${{ matrix.jdk }} 68 | distribution: 'temurin' 69 | - uses: actions/cache@v4 70 | with: 71 | path: ~/.m2/repository 72 | key: pom-tuner-${{ hashFiles('**/pom.xml') }}-${{ github.sha }} 73 | - run: ./mvnw verify -e -B -V -ntp -rf :pom-tuner-tests 74 | 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | 9 | # Eclipse 10 | .project 11 | .classpath 12 | .settings/ 13 | bin/ 14 | 15 | # IDEA 16 | .idea 17 | *.ipr 18 | *.iml 19 | *.iws 20 | 21 | # NetBeans 22 | nb-configuration.xml 23 | 24 | # KDE 25 | .directory 26 | 27 | # OSX 28 | .DS_Store -------------------------------------------------------------------------------- /.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 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 20 | -------------------------------------------------------------------------------- /.sdkmanrc: -------------------------------------------------------------------------------- 1 | # Enable auto-env through the sdkman_auto_env config 2 | # Add key=value pairs of SDKs to use below 3 | java=11.0.25-tem 4 | mvnd=1.0.2 5 | maven=3.9.9 -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = POM Tuner 2 | 3 | A library for analyzing and programmatic editing of Maven `pom.xml` files. 4 | 5 | Its two main parts are `PomTransformer` and `MavenSourceTree` 6 | 7 | == `PomTransformer` 8 | 9 | Transform a single `pom.xml` file by using any of the pre-cooked ``Transformation``s or by writing your own. 10 | 11 | A basic usage example: 12 | 13 | [source,java] 14 | ---- 15 | import org.l2x6.pom.tuner.model.Gavtcs; 16 | import org.l2x6.pom.tuner.PomTransformer; 17 | import org.l2x6.pom.tuner.PomTransformer.SimpleElementWhitespace; 18 | import org.l2x6.pom.tuner.PomTransformer.Transformation; 19 | 20 | new PomTransformer(Paths.get("pom.xml"), StandardCharsets.UTF_8, SimpleElementWhitespace.AUTODETECT_PREFER_EMPTY) 21 | .transform( 22 | Transformation.addModuleIfNeeded("my-new-module", String::compareTo), 23 | Transformation.addOrSetProperty("my-prop", "new-value"), 24 | Transformation.addDependencyIfNeeded(new Gavtcs("org.acme", "a1", "1.2.3"), 25 | Gavtcs.scopeAndTypeFirstComparator()) 26 | ); 27 | ---- 28 | 29 | Characteristics: 30 | 31 | * Parses the given `pom.xml` file once into a DOM, applies one or more ``Transformation``s and writes the file back to the disk. 32 | * Generally keeps all formatting and whitespace, including end of line (EOL) characters (unlike many DOM writers which use the current platform's default EOLs). 33 | * Indentation for newly added elements is auto-detected based on the first indent available in the file. 34 | * Respects the http://maven.apache.org/developers/conventions/code.html#POM_Code_Convention[canonical ordering] when adding new elements under ``. 35 | 36 | == `MavenSourceTree` 37 | 38 | A representation of a Maven module hierarchy. 39 | 40 | It comes in handy in a variety of scenarios: 41 | 42 | * Analyze relationships in the dependency graph: 43 | ** On which other modules (including transitives) depends some given module? - see `MavenSourceTree.collect[Own|Transitive]Dependencies()` 44 | ** Which modules in the tree are required for building some given module? - see `MavenSourceTree.findRequiredModules()` 45 | * Transform the `pom.xml` files: 46 | ** Set versions of the modules - see `MavenSourceTree.setVersions()` 47 | ** Reduce the tree by removing some modules from the `pom.xml` file - see `MavenSourceTree.unlinkModules()` 48 | 49 | == Maven coordinates 50 | 51 | [source,xml] 52 | ---- 53 | 54 | org.l2x6.pom-tuner 55 | pom-tuner 56 | 57 | 58 | ---- 59 | 60 | Check the latest version on Maven Central: https://repo1.maven.org/maven2/org/l2x6/pom-tuner/pom-tuner/ 61 | 62 | == History 63 | 64 | This project beared the name `maven-utils` initially for a short period of time. 65 | -------------------------------------------------------------------------------- /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.3.2 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 | if ($env:MAVEN_USER_HOME) { 83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" 84 | } 85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 87 | 88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 91 | exit $? 92 | } 93 | 94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 96 | } 97 | 98 | # prepare tmp dir 99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 102 | trap { 103 | if ($TMP_DOWNLOAD_DIR.Exists) { 104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 106 | } 107 | } 108 | 109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 110 | 111 | # Download and Install Apache Maven 112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 113 | Write-Verbose "Downloading from: $distributionUrl" 114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 115 | 116 | $webclient = New-Object System.Net.WebClient 117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 119 | } 120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 122 | 123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 125 | if ($distributionSha256Sum) { 126 | if ($USE_MVND) { 127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 128 | } 129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 131 | 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." 132 | } 133 | } 134 | 135 | # unzip and move 136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 138 | try { 139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 140 | } catch { 141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 142 | Write-Error "fail to move MAVEN_HOME" 143 | } 144 | } finally { 145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 147 | } 148 | 149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 150 | -------------------------------------------------------------------------------- /pom-tuner-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.l2x6.pom-tuner 25 | pom-tuner-parent 26 | 4.5.3-SNAPSHOT 27 | 28 | 29 | pom-tuner-tests 30 | ${project.groupId}:${project.artifactId} 31 | 32 | 33 | 34 | org.l2x6.pom-tuner 35 | pom-tuner 36 | ${project.version} 37 | 38 | 39 | 40 | org.junit.jupiter 41 | junit-jupiter-api 42 | test 43 | 44 | 45 | org.junit.jupiter 46 | junit-jupiter-params 47 | test 48 | 49 | 50 | org.assertj 51 | assertj-core 52 | test 53 | 54 | 55 | org.slf4j 56 | slf4j-simple 57 | test 58 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | org.codehaus.mojo 67 | mrm-maven-plugin 68 | 69 | 70 | mrm-start 71 | process-test-classes 72 | 73 | start 74 | 75 | 76 | 77 | mrm-stop 78 | prepare-package 79 | 80 | stop 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.apache.maven.plugins 88 | maven-resources-plugin 89 | 90 | 91 | filter-settings-mrm 92 | process-test-classes 93 | 94 | copy-resources 95 | 96 | 97 | false 98 | 99 | 100 | src/test/resources 101 | settings-mrm.xml 102 | true 103 | 104 | 105 | ${project.build.directory} 106 | 107 | 108 | 109 | 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-surefire-plugin 114 | 115 | 116 | ${project.basedir} 117 | ${project.build.directory} 118 | ${project.build.directory}/settings-mrm.xml 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/model/AbstractSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.List; 20 | import org.junit.jupiter.api.Test; 21 | 22 | public abstract class AbstractSetTest { 23 | 24 | abstract List set(String[] includes, String[] excludes); 25 | 26 | abstract List set(String includes, String excludes); 27 | 28 | abstract List setDefaultResultExcludeAll(); 29 | 30 | abstract List union(String[] includes, String[] excludes, String[] unionIncludes); 31 | 32 | abstract List unionDefaultResultExcludeAll(); 33 | 34 | abstract void containsGav(boolean expected, T set, String g, String a, String v); 35 | 36 | static String[] arr(String... elems) { 37 | return elems; 38 | } 39 | 40 | @Test 41 | public void defaults() { 42 | List sets = set(arr(), arr()); 43 | for (T set : sets) { 44 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 45 | } 46 | } 47 | 48 | @Test 49 | public void excludeArtifact() { 50 | List sets = set(arr(), arr("org.group1:artifact1")); 51 | for (T set : sets) { 52 | containsGav(false, set, "org.group1", "artifact1", "1.2.3"); 53 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 54 | 55 | containsGav(true, set, "org.group2", "artifact2", "5.6.7"); 56 | containsGav(true, set, "org.group2", "artifact3", "6.7.8"); 57 | 58 | containsGav(true, set, "com.group3", "artifact4", "5.6.7"); 59 | } 60 | } 61 | 62 | @Test 63 | public void excludeGroups() { 64 | List sets = set(arr(), arr("org.group1", "org.group2")); 65 | for (T set : sets) { 66 | containsGav(false, set, "org.group1", "artifact1", "1.2.3"); 67 | containsGav(false, set, "org.group1", "artifact2", "2.3.4"); 68 | 69 | containsGav(false, set, "org.group2", "artifact2", "5.6.7"); 70 | containsGav(false, set, "org.group2", "artifact3", "6.7.8"); 71 | 72 | containsGav(true, set, "com.group3", "artifact4", "5.6.7"); 73 | } 74 | } 75 | 76 | @Test 77 | public void includeArtifact() { 78 | List sets = set(arr("org.group1:artifact1"), arr()); 79 | for (T set : sets) { 80 | 81 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 82 | containsGav(false, set, "org.group1", "artifact2", "2.3.4"); 83 | 84 | containsGav(false, set, "org.group2", "artifact2", "5.6.7"); 85 | containsGav(false, set, "org.group2", "artifact3", "6.7.8"); 86 | 87 | containsGav(false, set, "com.group3", "artifact4", "5.6.7"); 88 | } 89 | 90 | } 91 | 92 | @Test 93 | public void includeExcludeGroups() { 94 | List sets = set(arr("org.group1"), arr("org.group2")); 95 | for (T set : sets) { 96 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 97 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 98 | 99 | containsGav(false, set, "org.group2", "artifact2", "5.6.7"); 100 | containsGav(false, set, "org.group2", "artifact3", "6.7.8"); 101 | 102 | containsGav(false, set, "com.group3", "artifact4", "5.6.7"); 103 | } 104 | 105 | } 106 | 107 | @Test 108 | public void includeGroup() { 109 | List sets = set(arr("org.group1"), arr()); 110 | for (T set : sets) { 111 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 112 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 113 | 114 | containsGav(false, set, "org.group2", "artifact2", "5.6.7"); 115 | } 116 | 117 | } 118 | 119 | @Test 120 | public void includeGroups() { 121 | List sets = set(arr("org.group1", "org.group2"), arr()); 122 | for (T set : sets) { 123 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 124 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 125 | 126 | containsGav(true, set, "org.group2", "artifact2", "5.6.7"); 127 | containsGav(true, set, "org.group2", "artifact3", "6.7.8"); 128 | 129 | containsGav(false, set, "com.group3", "artifact4", "5.6.7"); 130 | } 131 | 132 | } 133 | 134 | @Test 135 | public void includeGroupsExcludeArtifact() { 136 | List sets = set(arr("org.group1", "org.group2", "com.group3"), 137 | arr("org.group1:artifact2", "org.group1:artifact3", "org.group2:artifact2", "org.group2:artifact3")); 138 | for (T set : sets) { 139 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 140 | containsGav(false, set, "org.group1", "artifact2", "2.3.4"); 141 | containsGav(false, set, "org.group1", "artifact3", "2.3.4"); 142 | 143 | containsGav(true, set, "org.group2", "artifact1", "1.2.3"); 144 | containsGav(false, set, "org.group2", "artifact2", "2.3.4"); 145 | containsGav(false, set, "org.group2", "artifact3", "2.3.4"); 146 | 147 | containsGav(true, set, "com.group3", "artifact1", "5.6.7"); 148 | containsGav(true, set, "com.group3", "artifact2", "5.6.7"); 149 | containsGav(true, set, "com.group3", "artifact3", "5.6.7"); 150 | containsGav(true, set, "com.group3", "artifact4", "5.6.7"); 151 | } 152 | 153 | } 154 | 155 | @Test 156 | public void whitespaceSeparated() { 157 | List sets = set("org.group1,org.group2\n com.group3", 158 | "org.group1:artifact2\t\torg.group1:artifact3 org.group2:artifact2\torg.group2:artifact3"); 159 | for (T set : sets) { 160 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 161 | containsGav(false, set, "org.group1", "artifact2", "2.3.4"); 162 | containsGav(false, set, "org.group1", "artifact3", "2.3.4"); 163 | 164 | containsGav(true, set, "org.group2", "artifact1", "1.2.3"); 165 | containsGav(false, set, "org.group2", "artifact2", "2.3.4"); 166 | containsGav(false, set, "org.group2", "artifact3", "2.3.4"); 167 | 168 | containsGav(true, set, "com.group3", "artifact1", "5.6.7"); 169 | containsGav(true, set, "com.group3", "artifact2", "5.6.7"); 170 | containsGav(true, set, "com.group3", "artifact3", "5.6.7"); 171 | containsGav(true, set, "com.group3", "artifact4", "5.6.7"); 172 | } 173 | 174 | } 175 | 176 | @Test 177 | public void union() { 178 | List sets = union(arr("org.group1"), arr("org.group1:artifact2"), arr("org.group1:artifact2")); 179 | for (T set : sets) { 180 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 181 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 182 | } 183 | 184 | } 185 | 186 | @Test 187 | public void unionExplicitDefault() { 188 | List sets = unionDefaultResultExcludeAll(); 189 | for (T set : sets) { 190 | containsGav(false, set, "org.group1", "artifact1", "1.2.3"); 191 | containsGav(false, set, "org.group1", "artifact2", "2.3.4"); 192 | } 193 | 194 | } 195 | 196 | @Test 197 | public void unionImplicitDefault() { 198 | List sets = union(arr(), arr(), arr()); 199 | for (T set : sets) { 200 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 201 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 202 | } 203 | 204 | } 205 | 206 | @Test 207 | public void includeExcludeExplicitDefault() { 208 | List sets = setDefaultResultExcludeAll(); 209 | for (T set : sets) { 210 | containsGav(false, set, "org.group1", "artifact1", "1.2.3"); 211 | containsGav(false, set, "org.group1", "artifact2", "2.3.4"); 212 | } 213 | 214 | } 215 | 216 | @Test 217 | public void includeExcludeImplicitDefault() { 218 | List sets = set(arr(), arr()); 219 | for (T set : sets) { 220 | containsGav(true, set, "org.group1", "artifact1", "1.2.3"); 221 | containsGav(true, set, "org.group1", "artifact2", "2.3.4"); 222 | } 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/model/GavPatternTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.Set; 20 | import java.util.TreeSet; 21 | import java.util.function.BiFunction; 22 | import java.util.function.Function; 23 | import java.util.function.Supplier; 24 | import java.util.stream.Collectors; 25 | import org.assertj.core.util.TriFunction; 26 | import org.junit.jupiter.api.Test; 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | 30 | public class GavPatternTest { 31 | 32 | @Test 33 | void comparable() { 34 | comparable(() -> new TreeSet(), GavPattern::of); 35 | } 36 | 37 | static void comparable(Supplier> setSupplier, Function ofFunction) { 38 | Set gavPatterns = setSupplier.get(); 39 | gavPatterns.add(ofFunction.apply("org.group2:artifact1")); 40 | gavPatterns.add(ofFunction.apply("org.group1:artifact1")); 41 | gavPatterns.add(ofFunction.apply("org.group1:artifact2")); 42 | gavPatterns.add(ofFunction.apply("org.group1")); 43 | gavPatterns.add(ofFunction.apply("*")); 44 | assertThat("*,org.group1,org.group1:artifact1,org.group1:artifact2,org.group2:artifact1").isEqualTo( 45 | gavPatterns.stream().map(Object::toString).collect(Collectors.joining(","))); 46 | } 47 | 48 | @Test 49 | void asWildcardGa() { 50 | asWildcardGa(s -> GavPattern.of(s).asWildcardGa()); 51 | } 52 | 53 | static void asWildcardGa(Function as) { 54 | assertThat(Ga.of("org.group2:artifact1")).isEqualTo(as.apply("org.group2:artifact1")); 55 | assertThat(Ga.of("org.group2:*")).isEqualTo(as.apply("org.group2")); 56 | assertThat(Ga.of("*:*")).isEqualTo(as.apply("*")); 57 | } 58 | 59 | @Test 60 | void matchesGa() { 61 | assertMatchesGa( 62 | GavPattern::of, 63 | (pat, ga) -> pat.matches(ga), 64 | (pat, g, a) -> pat.matches(g, a)); 65 | } 66 | 67 | static void assertMatchesGa( 68 | Function of, 69 | BiFunction matches1, 70 | TriFunction matches2) { 71 | assertMatchesGa(of, matches1, matches2, "*", "a:b", true); 72 | assertMatchesGa(of, matches1, matches2, "*:*", "a:b", true); 73 | assertMatchesGa(of, matches1, matches2, "a", "a:b", true); 74 | assertMatchesGa(of, matches1, matches2, "a:b", "a:b", true); 75 | assertMatchesGa(of, matches1, matches2, "*:b", "a:b", true); 76 | assertMatchesGa(of, matches1, matches2, "a:*", "a:b", true); 77 | 78 | assertMatchesGa(of, matches1, matches2, "b", "a:b", false); 79 | assertMatchesGa(of, matches1, matches2, "b:b", "a:b", false); 80 | assertMatchesGa(of, matches1, matches2, "*:a", "a:b", false); 81 | assertMatchesGa(of, matches1, matches2, "b:*", "a:b", false); 82 | } 83 | 84 | static void assertMatchesGa( 85 | Function of, 86 | BiFunction matches1, 87 | TriFunction matches2, 88 | String pattern, 89 | String probe, 90 | boolean expected) { 91 | final T pat = of.apply(pattern); 92 | final Ga ga = Ga.of(probe); 93 | assertThat(matches1.apply(pat, ga)).isEqualTo(expected); 94 | assertThat(matches2.apply(pat, ga.getGroupId(), ga.getArtifactId())).isEqualTo(expected); 95 | } 96 | 97 | @Test 98 | void matchesGav() { 99 | assertMatchesGav( 100 | GavPattern::of, 101 | (pat, ga) -> pat.matches(ga), 102 | (pat, gav) -> pat.matches(gav[0], gav[1], gav[2])); 103 | } 104 | 105 | static void assertMatchesGav( 106 | Function of, 107 | BiFunction matches1, 108 | BiFunction matches2) { 109 | assertMatchesGav(of, matches1, matches2, "*", "a:b:c", true); 110 | assertMatchesGav(of, matches1, matches2, "*:*", "a:b:c", true); 111 | assertMatchesGav(of, matches1, matches2, "*:*:*", "a:b:c", true); 112 | assertMatchesGav(of, matches1, matches2, "a", "a:b:c", true); 113 | assertMatchesGav(of, matches1, matches2, "a:b", "a:b:c", true); 114 | assertMatchesGav(of, matches1, matches2, "a:b:c", "a:b:c", true); 115 | assertMatchesGav(of, matches1, matches2, "*:b", "a:b:c", true); 116 | assertMatchesGav(of, matches1, matches2, "*:*:c", "a:b:c", true); 117 | assertMatchesGav(of, matches1, matches2, "a:*", "a:b:c", true); 118 | assertMatchesGav(of, matches1, matches2, "a:b:*", "a:b:c", true); 119 | assertMatchesGav(of, matches1, matches2, "a:*:c", "a:b:c", true); 120 | 121 | assertMatchesGav(of, matches1, matches2, "b", "a:b:c", false); 122 | assertMatchesGav(of, matches1, matches2, "b:b", "a:b:c", false); 123 | assertMatchesGav(of, matches1, matches2, "a:b:d", "a:b:c", false); 124 | assertMatchesGav(of, matches1, matches2, "*:a", "a:b:c", false); 125 | assertMatchesGav(of, matches1, matches2, "*:a:*", "a:b:c", false); 126 | assertMatchesGav(of, matches1, matches2, "a:*:d", "a:b:c", false); 127 | 128 | } 129 | 130 | static void assertMatchesGav( 131 | Function of, 132 | BiFunction matches1, 133 | BiFunction matches2, 134 | String pattern, 135 | String probe, 136 | boolean expected) { 137 | final T pat = of.apply(pattern); 138 | final Gav gav = Gav.of(probe); 139 | assertThat(matches1.apply(pat, gav)).isEqualTo(expected); 140 | assertThat(matches2.apply(pat, new String[] { gav.getGroupId(), gav.getArtifactId(), gav.getVersion() })) 141 | .isEqualTo(expected); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/model/GavSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.List; 22 | import java.util.stream.Stream; 23 | import org.l2x6.pom.tuner.model.GavSet.IncludeExcludeGavSet.Builder; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | 27 | public class GavSetTest extends AbstractSetTest { 28 | 29 | @Override 30 | List set(String[] includes, String[] excludes) { 31 | List result = new ArrayList<>(); 32 | result.add(GavSet.builder().includes(includes).excludes(excludes).build()); 33 | result.add(GavSet.builder().includes(Arrays.asList(includes)).excludes(Arrays.asList(excludes)).build()); 34 | 35 | final Builder b = GavSet.builder(); 36 | Stream.of(includes).forEach(b::include); 37 | Stream.of(excludes).forEach(b::exclude); 38 | result.add(b.build()); 39 | return result; 40 | } 41 | 42 | @Override 43 | List set(String includes, String excludes) { 44 | List result = new ArrayList<>(); 45 | result.add(GavSet.builder().includes(includes).excludes(excludes).build()); 46 | return result; 47 | } 48 | 49 | @Override 50 | void containsGav(boolean expected, GavSet set, String g, String a, String v) { 51 | assertThat(set.contains(g, a, v)).isEqualTo(expected); 52 | } 53 | 54 | @Override 55 | List union(String[] includes, String[] excludes, String[] unionIncludes) { 56 | GavSet r = GavSet.builder() // 57 | .includes(includes) // 58 | .excludes(excludes) // 59 | .build(); 60 | if (unionIncludes.length > 0) { 61 | return Arrays.asList(r 62 | .union(GavSet.builder().includes(unionIncludes).build())); 63 | } else { 64 | return Arrays.asList(r); 65 | } 66 | } 67 | 68 | @Override 69 | List unionDefaultResultExcludeAll() { 70 | return Arrays.asList(GavSet.unionBuilder() // 71 | .defaultResult(GavSet.excludeAll()) 72 | .build()); 73 | } 74 | 75 | @Override 76 | List setDefaultResultExcludeAll() { 77 | return Arrays.asList(GavSet.builder() // 78 | .defaultResult(GavSet.excludeAll()) 79 | .build()); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/model/GavTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * @author Peter Palaga 24 | */ 25 | public class GavTest { 26 | @Test 27 | public void of() { 28 | Assertions.assertEquals(new Gav("g", "a", "v"), Gav.of("g:a:v")); 29 | } 30 | 31 | @Test 32 | public void ofMissingArtifactId() { 33 | Assertions.assertThrows(IllegalStateException.class, () -> Gav.of("g")); 34 | } 35 | 36 | @Test 37 | public void ofMissingVersion() { 38 | Assertions.assertThrows(IllegalStateException.class, () -> Gav.of("g:a")); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/model/GavtcsPatternTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.TreeSet; 20 | import java.util.function.BiFunction; 21 | import java.util.function.Function; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.assertj.core.api.Assertions.assertThat; 25 | 26 | public class GavtcsPatternTest { 27 | 28 | @Test 29 | void comparable() { 30 | GavPatternTest.comparable(() -> new TreeSet(), GavtcsPattern::of); 31 | } 32 | 33 | @Test 34 | void asWildcardGa() { 35 | GavPatternTest.asWildcardGa(s -> GavtcsPattern.of(s).asWildcardGa()); 36 | } 37 | 38 | @Test 39 | void matchesGa() { 40 | GavPatternTest.assertMatchesGa( 41 | GavtcsPattern::of, 42 | (pat, ga) -> pat.matches(ga), 43 | (pat, g, a) -> pat.matches(g, a)); 44 | } 45 | 46 | @Test 47 | void matchesGav() { 48 | GavPatternTest.assertMatchesGav( 49 | GavtcsPattern::of, 50 | (pat, ga) -> pat.matches(ga), 51 | (pat, gav) -> pat.matches(gav[0], gav[1], gav[2])); 52 | } 53 | 54 | @Test 55 | void matchesGavtcs() { 56 | assertMatchesGavtcs( 57 | GavtcsPattern::of, 58 | (pat, ga) -> pat.matches(ga), 59 | (pat, gav) -> pat.matches(gav[0], gav[1], gav[2], gav[3], gav[4], gav[5])); 60 | } 61 | 62 | static void assertMatchesGavtcs( 63 | Function of, 64 | BiFunction matches1, 65 | BiFunction matches2) { 66 | assertMatchesGavtcs(of, matches1, matches2, "*", "g:a:v:t:c:s", true); 67 | assertMatchesGavtcs(of, matches1, matches2, "*:*", "g:a:v:t:c:s", true); 68 | assertMatchesGavtcs(of, matches1, matches2, "*:*:*", "g:a:v:t:c:s", true); 69 | assertMatchesGavtcs(of, matches1, matches2, "*:*:*:*", "g:a:v:t:c:s", true); 70 | assertMatchesGavtcs(of, matches1, matches2, "*:*:*:*:*", "g:a:v:t:c:s", true); 71 | assertMatchesGavtcs(of, matches1, matches2, "*:*:*:*:*:*", "g:a:v:t:c:s", true); 72 | 73 | assertMatchesGavtcs(of, matches1, matches2, "g", "g:a:v:t:c:s", true); 74 | assertMatchesGavtcs(of, matches1, matches2, "g:a", "g:a:v:t:c:s", true); 75 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v", "g:a:v:t:c:s", true); 76 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "g:a:v:t:c:s", true); 77 | assertMatchesGavtcs(of, matches1, matches2, "*:a", "g:a:v:t:c:s", true); 78 | assertMatchesGavtcs(of, matches1, matches2, "*:*:v", "g:a:v:t:c:s", true); 79 | assertMatchesGavtcs(of, matches1, matches2, "g:*", "g:a:v:t:c:s", true); 80 | assertMatchesGavtcs(of, matches1, matches2, "g:a:*", "g:a:v:t:c:s", true); 81 | assertMatchesGavtcs(of, matches1, matches2, "g:*:v", "g:a:v:t:c:s", true); 82 | 83 | assertMatchesGavtcs(of, matches1, matches2, "b", "g:a:v:t:c:s", false); 84 | assertMatchesGavtcs(of, matches1, matches2, "g:b", "g:a:v:t:c:s", false); 85 | assertMatchesGavtcs(of, matches1, matches2, "g:a:d", "g:a:v:t:c:s", false); 86 | assertMatchesGavtcs(of, matches1, matches2, "*:b", "g:a:v:t:c:s", false); 87 | assertMatchesGavtcs(of, matches1, matches2, "*:b:*", "g:a:v:t:c:s", false); 88 | assertMatchesGavtcs(of, matches1, matches2, "g:*:d", "g:a:v:t:c:s", false); 89 | 90 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "x:a:v:t:c:s", false); 91 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "g:x:v:t:c:s", false); 92 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "g:a:x:t:c:s", false); 93 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "g:a:v:x:c:s", false); 94 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "g:a:v:t:x:s", false); 95 | assertMatchesGavtcs(of, matches1, matches2, "g:a:v:t:c:s", "g:a:v:t:c:x", false); 96 | 97 | } 98 | 99 | static void assertMatchesGavtcs( 100 | Function of, 101 | BiFunction matches1, 102 | BiFunction matches2, 103 | String pattern, 104 | String probe, 105 | boolean expected) { 106 | final T pat = of.apply(pattern); 107 | final Gavtcs gav = Gavtcs.of(probe); 108 | assertThat(matches1.apply(pat, gav)).isEqualTo(expected); 109 | assertThat(matches2.apply( 110 | pat, 111 | new String[] { 112 | gav.getGroupId(), 113 | gav.getArtifactId(), 114 | gav.getVersion(), 115 | gav.getType(), 116 | gav.getClassifier(), 117 | gav.getScope() 118 | })).isEqualTo(expected); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/model/GavtcsSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.List; 22 | import java.util.stream.Stream; 23 | import org.junit.jupiter.api.Test; 24 | import org.l2x6.pom.tuner.model.GavtcsSet.IncludeExcludeGavSet.Builder; 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; 27 | 28 | public class GavtcsSetTest extends AbstractSetTest { 29 | 30 | @Override 31 | List set(String[] includes, String[] excludes) { 32 | List result = new ArrayList<>(); 33 | result.add(GavtcsSet.builder().includes(includes).excludes(excludes).build()); 34 | result.add(GavtcsSet.builder().includes(Arrays.asList(includes)).excludes(Arrays.asList(excludes)).build()); 35 | final Builder b = GavtcsSet.builder(); 36 | Stream.of(includes).forEach(b::include); 37 | Stream.of(excludes).forEach(b::exclude); 38 | result.add(b.build()); 39 | return result; 40 | } 41 | 42 | @Override 43 | List set(String includes, String excludes) { 44 | List result = new ArrayList<>(); 45 | result.add(GavtcsSet.builder().includes(includes).excludes(excludes).build()); 46 | return result; 47 | } 48 | 49 | @Override 50 | void containsGav(boolean expected, GavtcsSet set, String g, String a, String v) { 51 | assertThat(set.contains(g, a, v)).isEqualTo(expected); 52 | } 53 | 54 | void containsGav(boolean expected, GavtcsSet set, String g, String a, String v, String type, String classifier, 55 | String scope) { 56 | assertThat(set.contains(g, a, v, type, classifier, scope)).isEqualTo(expected); 57 | assertThat(set.contains(new Gavtcs(g, a, v, type, classifier, scope))).isEqualTo(expected); 58 | } 59 | 60 | @Override 61 | List union(String[] includes, String[] excludes, String[] unionIncludes) { 62 | GavtcsSet r = GavtcsSet.builder() // 63 | .includes(includes) // 64 | .excludes(excludes) // 65 | .build(); 66 | if (unionIncludes.length > 0) { 67 | return Arrays.asList(r 68 | .union(GavtcsSet.builder().includes(unionIncludes).build())); 69 | } else { 70 | return Arrays.asList(r); 71 | } 72 | } 73 | 74 | @Override 75 | List unionDefaultResultExcludeAll() { 76 | return Arrays.asList(GavtcsSet.unionBuilder() // 77 | .defaultResult(GavtcsSet.excludeAll()) 78 | .build()); 79 | } 80 | 81 | @Override 82 | List setDefaultResultExcludeAll() { 83 | return Arrays.asList(GavtcsSet.builder() // 84 | .defaultResult(GavtcsSet.excludeAll()) 85 | .build()); 86 | } 87 | 88 | @Test 89 | public void defaults() { 90 | super.defaults(); 91 | List sets = set(arr(), arr()); 92 | for (GavtcsSet set : sets) { 93 | containsGav(true, set, "org.group1", "artifact1", "1.2.3", "", "", ""); 94 | containsGav(true, set, "org.group1", "artifact1", "1.2.3", "jar", "x86_64", "compile"); 95 | } 96 | } 97 | 98 | @Override 99 | public void excludeArtifact() { 100 | super.excludeArtifact(); 101 | 102 | List sets = set(arr(), arr("org.group1:artifact1:*:jar::test")); 103 | for (GavtcsSet set : sets) { 104 | containsGav(false, set, "org.group1", "artifact1", "1.2.3", "jar", "", "test"); 105 | containsGav(true, set, "org.group1", "artifact2", "2.3.4", "jar", "", "test"); 106 | containsGav(true, set, "org.group1", "artifact2", "2.3.4", "jar", "x86_64", "test"); 107 | 108 | containsGav(true, set, "org.group1", "artifact1", "1.2.3", "jar", "", "compile"); 109 | containsGav(true, set, "org.group1", "artifact1", "1.2.3", "jar", "x86_64", "test"); 110 | containsGav(true, set, "org.group1", "artifact1", "1.2.3", "pom", "", "test"); 111 | } 112 | 113 | } 114 | 115 | @Override 116 | public void includeArtifact() { 117 | super.includeArtifact(); 118 | 119 | List sets = set(arr("org.group1:artifact1:*:jar::test"), arr()); 120 | for (GavtcsSet set : sets) { 121 | containsGav(true, set, "org.group1", "artifact1", "1.2.3", "jar", "", "test"); 122 | containsGav(false, set, "org.group1", "artifact2", "2.3.4", "jar", "", "test"); 123 | containsGav(false, set, "org.group1", "artifact2", "2.3.4", "jar", "x86_64", "test"); 124 | 125 | containsGav(false, set, "org.group1", "artifact1", "1.2.3", "jar", "", "compile"); 126 | containsGav(false, set, "org.group1", "artifact1", "1.2.3", "jar", "x86_64", "test"); 127 | containsGav(false, set, "org.group1", "artifact1", "1.2.3", "pom", "", "test"); 128 | } 129 | 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/shell/BadExitCodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.shell; 18 | 19 | import java.util.Arrays; 20 | 21 | /** 22 | * Thrown when a shell command exits with a non-zero exit code. 23 | * 24 | * @author Peter Palaga 25 | */ 26 | public class BadExitCodeException extends BuildException { 27 | private static final long serialVersionUID = 5437686562879042682L; 28 | private final int exitCode; 29 | 30 | public BadExitCodeException(String[] cmdArray, int exitCode) { 31 | super(String.format("Command returned exit code [%d]: %s", exitCode, Arrays.toString(cmdArray))); 32 | this.exitCode = exitCode; 33 | } 34 | 35 | /** 36 | * @return the exist code of a command that caused this {@link BadExitCodeException} to be thrown 37 | */ 38 | public int getExitCode() { 39 | return exitCode; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/shell/BuildException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.shell; 18 | 19 | /** 20 | * Thrown on any build related problems. Note that {@link BuildException} has a few subclasses that are thrown in some 21 | * specific situations. 22 | * 23 | * @author Peter Palaga 24 | */ 25 | public class BuildException extends Exception { 26 | private static final long serialVersionUID = 1520625837859688798L; 27 | 28 | public BuildException(String message) { 29 | super(message); 30 | } 31 | 32 | public BuildException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public BuildException(Throwable cause) { 37 | super(cause); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/shell/CommandTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.shell; 18 | 19 | /** 20 | * Thrown when an execution of a shell command is not finished within some given timeout. 21 | * 22 | * @author Peter Palaga 23 | */ 24 | public class CommandTimeoutException extends BuildException { 25 | 26 | private static final long serialVersionUID = -8311365402356710884L; 27 | 28 | public CommandTimeoutException(String message) { 29 | super(message); 30 | } 31 | 32 | public CommandTimeoutException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public CommandTimeoutException(Throwable cause) { 37 | super(cause); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/shell/LineConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.shell; 18 | 19 | import java.io.Closeable; 20 | import java.io.IOException; 21 | import java.io.Writer; 22 | import java.nio.charset.StandardCharsets; 23 | import java.nio.file.Files; 24 | import java.nio.file.Path; 25 | import java.nio.file.StandardCopyOption; 26 | import java.util.function.Consumer; 27 | import org.slf4j.Logger; 28 | 29 | public interface LineConsumer extends Consumer, Closeable { 30 | 31 | class LoggerLineConsumer implements LineConsumer { 32 | 33 | private final String id; 34 | private Logger logger; 35 | 36 | LoggerLineConsumer(String id, Logger logger) { 37 | super(); 38 | this.id = id; 39 | this.logger = logger; 40 | } 41 | 42 | @Override 43 | public void accept(String t) { 44 | logger.info("srcdeps[{}]: {}", id, t); 45 | } 46 | 47 | @Override 48 | public void close() throws IOException { 49 | } 50 | } 51 | 52 | class StringLineConsumer implements LineConsumer { 53 | 54 | private final StringBuilder sb = new StringBuilder(); 55 | 56 | @Override 57 | public void accept(String t) { 58 | sb.append(t).append('\n'); 59 | } 60 | 61 | @Override 62 | public void close() throws IOException { 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return sb.toString(); 68 | } 69 | 70 | } 71 | 72 | class TeeLineConsumer implements LineConsumer { 73 | 74 | private final LineConsumer delegate1; 75 | private final LineConsumer delegate2; 76 | 77 | TeeLineConsumer(LineConsumer delegate1, LineConsumer delegate2) { 78 | super(); 79 | this.delegate1 = delegate1; 80 | this.delegate2 = delegate2; 81 | } 82 | 83 | @Override 84 | public void accept(String t) { 85 | delegate1.accept(t); 86 | delegate2.accept(t); 87 | } 88 | 89 | @Override 90 | public void close() throws IOException { 91 | delegate1.close(); 92 | delegate2.close(); 93 | } 94 | 95 | } 96 | 97 | class WriterLineConsumer implements LineConsumer { 98 | 99 | private final Writer delegate; 100 | private final String id; 101 | 102 | WriterLineConsumer(String id, Writer delegate) { 103 | super(); 104 | this.id = id; 105 | this.delegate = delegate; 106 | } 107 | 108 | @Override 109 | public void accept(String t) { 110 | try { 111 | delegate.write(t); 112 | delegate.write('\n'); 113 | } catch (IOException e) { 114 | throw new RuntimeException(e); 115 | } 116 | } 117 | 118 | @Override 119 | public void close() throws IOException { 120 | delegate.close(); 121 | } 122 | 123 | @Override 124 | public String toString() { 125 | return id; 126 | } 127 | 128 | } 129 | 130 | LineConsumer DUMMY = new LineConsumer() { 131 | 132 | @Override 133 | public void accept(String t) { 134 | } 135 | 136 | @Override 137 | public void close() throws IOException { 138 | } 139 | 140 | @Override 141 | public String toString() { 142 | return "DummyLineConsumer"; 143 | } 144 | 145 | }; 146 | 147 | static LineConsumer dummy() { 148 | return DUMMY; 149 | } 150 | 151 | static LineConsumer logger(String id, Logger logger) { 152 | return new LoggerLineConsumer(id, logger); 153 | } 154 | 155 | static void renameIfNeeded(Path path, int level, int count, String base, String ext) throws IOException { 156 | final int newLevel = level + 1; 157 | if (newLevel < count) { 158 | final Path newPath = path.getParent().resolve(base + "-" + newLevel + ext); 159 | renameIfNeeded(newPath, newLevel, count, base, ext); 160 | if (Files.exists(path)) { 161 | Files.move(path, newPath, StandardCopyOption.REPLACE_EXISTING); 162 | } 163 | } 164 | } 165 | 166 | static LineConsumer rotate(Path path, int count) { 167 | final String fileName = path.getFileName().toString(); 168 | final int periodPos = fileName.lastIndexOf('.'); 169 | final String base = periodPos >= 0 ? fileName.substring(0, periodPos) : fileName; 170 | final String ext = periodPos >= 0 ? fileName.substring(periodPos) : ""; 171 | try { 172 | renameIfNeeded(path, 0, count, base, ext); 173 | return new WriterLineConsumer(path.toString(), Files.newBufferedWriter(path, StandardCharsets.UTF_8)); 174 | } catch (IOException e) { 175 | throw new RuntimeException(e); 176 | } 177 | } 178 | 179 | static LineConsumer string() { 180 | return new StringLineConsumer(); 181 | } 182 | 183 | static LineConsumer tee(LineConsumer lc1, LineConsumer lc2) { 184 | return new TeeLineConsumer(lc1, lc2); 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/shell/Shell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.shell; 18 | 19 | import java.io.BufferedReader; 20 | import java.io.Closeable; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.InputStreamReader; 24 | import java.nio.charset.StandardCharsets; 25 | import java.util.Arrays; 26 | import java.util.Map; 27 | import java.util.concurrent.TimeUnit; 28 | import java.util.stream.Collectors; 29 | import org.slf4j.Logger; 30 | import org.slf4j.LoggerFactory; 31 | 32 | /** 33 | * A utility for executing {@link ShellCommand}s. 34 | * 35 | * @author Peter Palaga 36 | */ 37 | public class Shell { 38 | 39 | /** 40 | * A simple wrapper over {@link Process} that manages its destroying and offers Java 8-like 41 | * {@link #waitFor(long, TimeUnit, String[])} with timeout. 42 | */ 43 | public static class CommandProcess implements Closeable { 44 | 45 | private final Process process; 46 | private final Thread shutDownHook; 47 | private final StreamGobbler stdOut; 48 | 49 | public CommandProcess(String requestId, Process process, LineConsumer out) { 50 | super(); 51 | this.process = process; 52 | this.stdOut = new StreamGobbler(process.getInputStream(), out); 53 | stdOut.start(); 54 | 55 | this.shutDownHook = new Thread(new Runnable() { 56 | @Override 57 | public void run() { 58 | stdOut.cancel(); 59 | // stdErr.cancel(); 60 | CommandProcess.this.process.destroy(); 61 | } 62 | }); 63 | Runtime.getRuntime().addShutdownHook(shutDownHook); 64 | } 65 | 66 | @Override 67 | public void close() { 68 | process.destroy(); 69 | } 70 | 71 | public CommandResult waitFor(long timeout, TimeUnit unit, String[] cmdArray) 72 | throws CommandTimeoutException, InterruptedException, IOException { 73 | final long startMillisTime = System.currentTimeMillis(); 74 | final long startNanoTime = System.nanoTime(); 75 | long rem = unit.toNanos(timeout); 76 | 77 | do { 78 | try { 79 | int exitCode = process.exitValue(); 80 | try { 81 | Runtime.getRuntime().removeShutdownHook(shutDownHook); 82 | } catch (Exception ignored) { 83 | } 84 | 85 | stdOut.join(); 86 | stdOut.assertSuccess(); 87 | 88 | return new CommandResult(cmdArray, exitCode, System.currentTimeMillis() - startMillisTime); 89 | } catch (IllegalThreadStateException ex) { 90 | if (rem > 0) { 91 | Thread.sleep(Math.min(TimeUnit.NANOSECONDS.toMillis(rem) + 1, 100)); 92 | } 93 | } 94 | rem = unit.toNanos(timeout) - (System.nanoTime() - startNanoTime); 95 | } while (rem > 0); 96 | throw new CommandTimeoutException( 97 | String.format("Command has not finished within [%d] ms: %s", timeout, Arrays.toString(cmdArray))); 98 | } 99 | 100 | } 101 | 102 | /** 103 | * A result of a {@link ShellCommand}'s execution. 104 | */ 105 | public static class CommandResult { 106 | private final String[] cmdArray; 107 | private final int exitCode; 108 | private final long runtimeMs; 109 | 110 | public CommandResult(String[] cmdArray, int exitCode, long runtimeMs) { 111 | super(); 112 | this.cmdArray = cmdArray; 113 | this.exitCode = exitCode; 114 | this.runtimeMs = runtimeMs; 115 | } 116 | 117 | /** 118 | * @return this {@link CommandResult} 119 | * @throws BadExitCodeException if and only if {@link #exitCode} != 0 120 | */ 121 | public CommandResult assertSuccess() throws BadExitCodeException { 122 | if (exitCode != 0) { 123 | throw new BadExitCodeException(cmdArray, exitCode); 124 | } 125 | return this; 126 | } 127 | 128 | /** 129 | * @return the exit code returned by the underlying {@link ShellCommand} 130 | */ 131 | public int getExitCode() { 132 | return exitCode; 133 | } 134 | 135 | public long getRuntimeMs() { 136 | return runtimeMs; 137 | } 138 | } 139 | 140 | /** 141 | * The usual friend of {@link Process#getInputStream()} / {@link Process#getErrorStream()}. 142 | */ 143 | static class StreamGobbler extends Thread { 144 | private volatile boolean cancelled; 145 | private IOException exception; 146 | private final InputStream in; 147 | private final LineConsumer out; 148 | 149 | private StreamGobbler(InputStream in, LineConsumer out) { 150 | this.in = in; 151 | this.out = out; 152 | } 153 | 154 | public void assertSuccess() throws IOException { 155 | if (exception != null) { 156 | throw exception; 157 | } 158 | } 159 | 160 | public void cancel() { 161 | this.cancelled = true; 162 | } 163 | 164 | @Override 165 | public void run() { 166 | try (BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { 167 | String line; 168 | while (!cancelled && (line = r.readLine()) != null) { 169 | out.accept(line); 170 | } 171 | } catch (IOException e) { 172 | exception = e; 173 | } 174 | } 175 | } 176 | 177 | static final Logger log = LoggerFactory.getLogger(Shell.class); 178 | 179 | /** 180 | * Executes the given {@link ShellCommand} synchronously. 181 | * 182 | * @param command the command to execute 183 | * @return the {@link CommandResult} that can be used to determine if the execution was 184 | * successful 185 | * @throws BuildException on any build related problems 186 | * @throws CommandTimeoutException if the execution is not finished within the timeout defined in 187 | * {@link ShellCommand#getTimeoutMs()} 188 | */ 189 | public static CommandResult execute(ShellCommand command) throws BuildException, CommandTimeoutException { 190 | final String[] cmdArray = command.asCmdArray(); 191 | final String cmdArrayString = Arrays.stream(cmdArray).collect(Collectors.joining(" ")); 192 | final Map env = command.getEnvironment(); 193 | log.info("srcdeps[{}]: Executing command [{}] using env {}", command.getId(), cmdArrayString, env); 194 | ProcessBuilder builder = new ProcessBuilder(cmdArray) // 195 | .directory(command.getWorkingDirectory().toFile()) // 196 | .redirectErrorStream(true); 197 | if (!env.isEmpty()) { 198 | builder.environment().putAll(env); 199 | } 200 | try (LineConsumer out = command.getOutput().get(); 201 | CommandProcess process = new CommandProcess(command.getId(), builder.start(), out)) { 202 | return process.waitFor(command.getTimeoutMs(), TimeUnit.MILLISECONDS, cmdArray).assertSuccess(); 203 | } catch (IOException | InterruptedException e) { 204 | throw new BuildException(String.format("Could not start command [%s]", cmdArrayString), e); 205 | } 206 | } 207 | 208 | /** 209 | * You are looking for {@link #execute(ShellCommand)}. 210 | */ 211 | private Shell() { 212 | super(); 213 | } 214 | 215 | } 216 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/java/org/l2x6/pom/tuner/shell/ShellCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Copyright 2015-2016 Maven Source Dependencies 19 | * Plugin contributors as indicated by the @author tags. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); 22 | * you may not use this file except in compliance with the License. 23 | * You may obtain a copy of the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, 29 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 30 | * See the License for the specific language governing permissions and 31 | * limitations under the License. 32 | */ 33 | package org.l2x6.pom.tuner.shell; 34 | 35 | import java.nio.file.Files; 36 | import java.nio.file.Path; 37 | import java.nio.file.Paths; 38 | import java.util.ArrayList; 39 | import java.util.Collections; 40 | import java.util.LinkedHashMap; 41 | import java.util.List; 42 | import java.util.Map; 43 | import java.util.Objects; 44 | import java.util.function.Supplier; 45 | 46 | /** 47 | * A definition of a shell command that can be executed by {@link Shell#execute(ShellCommand)}. 48 | * 49 | * @author Peter Palaga 50 | */ 51 | public class ShellCommand { 52 | public static class ShellCommandBuilder { 53 | private List arguments = new ArrayList<>(); 54 | private Map environment = new LinkedHashMap<>(); 55 | private String executable; 56 | private String id; 57 | private Supplier output; 58 | private long timeoutMs = Long.MAX_VALUE; 59 | private Path workingDirectory; 60 | 61 | public ShellCommandBuilder arguments(List args) { 62 | this.arguments.addAll(args); 63 | return this; 64 | } 65 | 66 | public ShellCommandBuilder arguments(String... args) { 67 | for (int i = 0; i < args.length; i++) { 68 | this.arguments.add(args[i]); 69 | } 70 | return this; 71 | } 72 | 73 | public ShellCommand build() { 74 | return new ShellCommand(id, executable, Collections.unmodifiableList(arguments), workingDirectory, 75 | Collections.unmodifiableMap(environment), output, timeoutMs); 76 | } 77 | 78 | public ShellCommandBuilder environment(Map buildEnvironment) { 79 | this.environment.putAll(buildEnvironment); 80 | return this; 81 | } 82 | 83 | public ShellCommandBuilder environmentEntry(String key, String value) { 84 | this.environment.put(key, value); 85 | return this; 86 | } 87 | 88 | public ShellCommandBuilder executable(String executable) { 89 | this.executable = executable; 90 | return this; 91 | } 92 | 93 | public ShellCommandBuilder id(String id) { 94 | this.id = id; 95 | return this; 96 | } 97 | 98 | public ShellCommandBuilder output(Supplier output) { 99 | this.output = output; 100 | return this; 101 | } 102 | 103 | public ShellCommandBuilder timeoutMs(long timeoutMs) { 104 | this.timeoutMs = timeoutMs; 105 | return this; 106 | } 107 | 108 | public ShellCommandBuilder workingDirectory(Path workingDirectory) { 109 | this.workingDirectory = workingDirectory; 110 | return this; 111 | } 112 | 113 | } 114 | 115 | public static ShellCommandBuilder builder() { 116 | return new ShellCommandBuilder(); 117 | } 118 | 119 | /** 120 | * Climbs up the file system hierarchy starting in {@code start} and searching for a {@code mvnw} or 121 | * {@code mvnw.cmd} file suitable for the current platform. 122 | * 123 | * @param start a preferably absolute path to a file or directory where the search should start 124 | * @return a path to {@code mvnw} or {@code mvnw.cmd} (suitable for the current platform) 125 | * @throws IllegalStateException if no {@code mvnw} or {@code mvnw.cmd} could be found 126 | */ 127 | public static Path findMvnw(final Path start) { 128 | Path dir = Files.isDirectory(start) ? start : start.getParent(); 129 | final Path mvnwRelPath = Paths.get("mvnw" + (isWindows ? ".cmd" : "")); 130 | while (dir != null) { 131 | final Path result = dir.resolve(mvnwRelPath); 132 | if (Files.exists(result)) { 133 | return result; 134 | } 135 | dir = dir.getParent(); 136 | } 137 | throw new IllegalStateException(String.format("Could not find mvnw starting in [%s]", start)); 138 | } 139 | 140 | private static final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win"); 141 | 142 | private final List arguments; 143 | private final Map environment; 144 | private final String executable; 145 | private final String id; 146 | private final Supplier output; 147 | 148 | private final long timeoutMs; 149 | 150 | private final Path workingDirectory; 151 | 152 | private ShellCommand(String id, String executable, List arguments, Path workingDirectory, 153 | Map environment, Supplier output, long timeoutMs) { 154 | super(); 155 | Objects.requireNonNull(id, "id"); 156 | Objects.requireNonNull(executable, "executable"); 157 | Objects.requireNonNull(arguments, "arguments"); 158 | Objects.requireNonNull(workingDirectory, "workingDirectory"); 159 | Objects.requireNonNull(environment, "environment"); 160 | Objects.requireNonNull(output, "output"); 161 | 162 | this.id = id; 163 | this.executable = executable; 164 | this.arguments = arguments; 165 | this.workingDirectory = workingDirectory; 166 | this.environment = environment; 167 | this.output = output; 168 | this.timeoutMs = timeoutMs; 169 | } 170 | 171 | /** 172 | * @return an array containing the executable and its arguments that can be passed e.g. to 173 | * {@link ProcessBuilder#command(String...)} 174 | */ 175 | public String[] asCmdArray() { 176 | String[] result = new String[arguments.size() + 1]; 177 | int i = 0; 178 | result[i++] = executable; 179 | for (String arg : arguments) { 180 | result[i++] = arg; 181 | } 182 | return result; 183 | } 184 | 185 | /** 186 | * @return the {@link List} arguments for the executable. Cannot be {@code null}. 187 | */ 188 | public List getArguments() { 189 | return arguments; 190 | } 191 | 192 | /** 193 | * @return a {@link Map} of environment variables that should be used when executing this {@link ShellCommand}. 194 | * Cannot be {@code null}. Note that these are just overlay variables - when a new {@link Process} is 195 | * spawned, the environment is copied from the present process and only the variables the provided by the 196 | * present method are overwritten. 197 | */ 198 | public Map getEnvironment() { 199 | return environment; 200 | } 201 | 202 | /** 203 | * @return the executable file that should be called 204 | */ 205 | public String getExecutable() { 206 | return executable; 207 | } 208 | 209 | public String getId() { 210 | return id; 211 | } 212 | // 213 | // public Consumer getLogger() { 214 | // return logger; 215 | // } 216 | 217 | public Supplier getOutput() { 218 | return output; 219 | } 220 | 221 | /** 222 | * @return timeout in milliseconds 223 | */ 224 | public long getTimeoutMs() { 225 | return timeoutMs; 226 | } 227 | 228 | /** 229 | * @return the directory in which this {@link ShellCommand} should be executed 230 | */ 231 | public Path getWorkingDirectory() { 232 | return workingDirectory; 233 | } 234 | 235 | } 236 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/properties/middle/module-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.properties 25 | middle-parent 26 | 0.0.1 27 | 28 | 29 | module-1 30 | 31 | 32 | val-1/main 33 | 34 | 35 | 36 | 37 | p1 38 | 39 | 40 | val-1/p1 41 | 42 | 43 | 44 | 45 | p2 46 | 47 | 48 | val-1/p2 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/properties/middle/module-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.properties 25 | middle-parent 26 | 0.0.1 27 | 28 | 29 | module-2 30 | 31 | 32 | val1 33 | val2 34 | val3 35 | val4 36 | 37 | 38 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/properties/middle/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.properties 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | middle-parent 30 | pom 31 | 32 | 33 | module-1 34 | module-2 35 | 36 | 37 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/properties/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | org.srcdeps.properties 24 | tree-parent 25 | 0.0.1 26 | pom 27 | 28 | A Maven source tree parent 29 | 30 | 31 | val-parent/main 32 | 33 | 34 | 35 | 36 | 37 | middle 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-1 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-2 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-3 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-4 30 | 31 | 32 | 2.2.2 33 | 6.7.8 34 | 7.8.9 35 | 36 | 37 | 38 | 39 | org.srcdeps.versions 40 | module-1 41 | 42 | 43 | org.srcdeps.versions 44 | module-2 45 | 46 | 47 | org.srcdeps.versions 48 | module-3 49 | 2.2.2 50 | 51 | 52 | org.srcdeps.whatever 53 | whatever-1 54 | 55 | 56 | 57 | 58 | org.srcdeps.versions 59 | module-5 60 | ${project.version} 61 | 62 | 63 | org.srcdeps.versions 64 | plugin-1 65 | ${plugin-1.version} 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.srcdeps.versions 74 | module-7 75 | 2.2.2 76 | 77 | 78 | org.srcdeps.external 79 | external-extension 80 | 1.2.3 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.srcdeps.external 88 | external-plugin-2 89 | ${external-plugin-2.version} 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.srcdeps.versions 97 | plugin-1 98 | 99 | 100 | org.srcdeps.versions 101 | plugin-2 102 | 103 | 104 | org.srcdeps.versions 105 | plugin-3 106 | 2.2.2 107 | 108 | 109 | org.srcdeps.external 110 | external-plugin-1 111 | ${external-plugin-1.version} 112 | 113 | 114 | 115 | 116 | 117 | 118 | p1 119 | 120 | 121 | org.srcdeps.versions 122 | module-3 123 | 2.2.2 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-5 30 | 31 | 32 | 2.2.2 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.srcdeps.versions 40 | plugin-1 41 | 2.2.2 42 | 43 | 44 | org.srcdeps.versions 45 | module-1 46 | 2.2.2 47 | 48 | 49 | org.srcdeps.versions 50 | module-2 51 | ${project.version} 52 | 53 | 54 | org.srcdeps.versions 55 | module-3 56 | ${org.srcdeps.versions.version} 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.srcdeps.versions 66 | plugin-1 67 | 68 | 69 | org.srcdeps.versions 70 | module-1 71 | 2.2.2 72 | 73 | 74 | org.srcdeps.versions 75 | module-2 76 | ${project.version} 77 | 78 | 79 | org.srcdeps.versions 80 | module-3 81 | ${org.srcdeps.versions.version} 82 | 83 | 84 | 85 | 86 | org.srcdeps.versions 87 | plugin-2 88 | 89 | 90 | org.srcdeps.versions 91 | plugin-3 92 | 2.2.2 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-6 30 | 31 | 32 | 2.2.2 33 | 34 | 35 | 36 | 37 | ${project.groupId} 38 | module-1 39 | 2.2.2 40 | 41 | 42 | ${project.groupId} 43 | module-5 44 | ${project.version} 45 | 46 | 47 | ${project.groupId} 48 | plugin-1 49 | ${plugin-1.version} 50 | 51 | 52 | 53 | 54 | 55 | 56 | ${project.groupId} 57 | plugin-3 58 | 2.2.2 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/module-7/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | module-7 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/plugin-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | plugin-1 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/plugin-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | plugin-2 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/plugin-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 2.2.2 27 | 28 | 29 | plugin-3 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions-expected/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | org.srcdeps.external 24 | extenal-parent 25 | 1.2.3 26 | 27 | 28 | org.srcdeps.versions 29 | tree-parent 30 | 2.2.2 31 | pom 32 | 33 | A Maven source tree parent 34 | 35 | 36 | val-parent/main 37 | 38 | 39 | 40 | module-1 41 | module-2 42 | module-3 43 | module-4 44 | module-5 45 | module-6 46 | module-7 47 | plugin-1 48 | plugin-2 49 | plugin-3 50 | 51 | 52 | 53 | 54 | 55 | org.srcdeps.versions 56 | module-1 57 | 2.2.2 58 | 59 | 60 | org.srcdeps.whatever 61 | whatever-1 62 | 63 | 64 | 65 | 66 | org.srcdeps.versions 67 | module-2 68 | ${project.version} 69 | 70 | 71 | org.srcdeps.external 72 | extenal-bom 73 | 1.2.3 74 | import 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.srcdeps.versions 83 | plugin-1 84 | ${project.version} 85 | 86 | 87 | org.srcdeps.versions 88 | plugin-2 89 | 2.2.2 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-1 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-2 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-3 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-4 30 | 31 | 32 | 0.0.1 33 | 6.7.8 34 | 7.8.9 35 | 36 | 37 | 38 | 39 | org.srcdeps.versions 40 | module-1 41 | 42 | 43 | org.srcdeps.versions 44 | module-2 45 | 46 | 47 | org.srcdeps.versions 48 | module-3 49 | 0.0.1 50 | 51 | 52 | org.srcdeps.whatever 53 | whatever-1 54 | 55 | 56 | 57 | 58 | org.srcdeps.versions 59 | module-5 60 | ${project.version} 61 | 62 | 63 | org.srcdeps.versions 64 | plugin-1 65 | ${plugin-1.version} 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.srcdeps.versions 74 | module-7 75 | 0.0.1 76 | 77 | 78 | org.srcdeps.external 79 | external-extension 80 | 1.2.3 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.srcdeps.external 88 | external-plugin-2 89 | ${external-plugin-2.version} 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.srcdeps.versions 97 | plugin-1 98 | 99 | 100 | org.srcdeps.versions 101 | plugin-2 102 | 103 | 104 | org.srcdeps.versions 105 | plugin-3 106 | 0.0.1 107 | 108 | 109 | org.srcdeps.external 110 | external-plugin-1 111 | ${external-plugin-1.version} 112 | 113 | 114 | 115 | 116 | 117 | 118 | p1 119 | 120 | 121 | org.srcdeps.versions 122 | module-3 123 | 0.0.1 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-5 30 | 31 | 32 | 0.0.1 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.srcdeps.versions 40 | plugin-1 41 | 0.0.1 42 | 43 | 44 | org.srcdeps.versions 45 | module-1 46 | 0.0.1 47 | 48 | 49 | org.srcdeps.versions 50 | module-2 51 | ${project.version} 52 | 53 | 54 | org.srcdeps.versions 55 | module-3 56 | ${org.srcdeps.versions.version} 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.srcdeps.versions 66 | plugin-1 67 | 68 | 69 | org.srcdeps.versions 70 | module-1 71 | 0.0.1 72 | 73 | 74 | org.srcdeps.versions 75 | module-2 76 | ${project.version} 77 | 78 | 79 | org.srcdeps.versions 80 | module-3 81 | ${org.srcdeps.versions.version} 82 | 83 | 84 | 85 | 86 | org.srcdeps.versions 87 | plugin-2 88 | 89 | 90 | org.srcdeps.versions 91 | plugin-3 92 | 0.0.1 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-6 30 | 31 | 32 | 0.0.1 33 | 34 | 35 | 36 | 37 | ${project.groupId} 38 | module-1 39 | 0.0.1 40 | 41 | 42 | ${project.groupId} 43 | module-5 44 | ${project.version} 45 | 46 | 47 | ${project.groupId} 48 | plugin-1 49 | ${plugin-1.version} 50 | 51 | 52 | 53 | 54 | 55 | 56 | ${project.groupId} 57 | plugin-3 58 | 0.0.1 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/module-7/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | module-7 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/plugin-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | plugin-1 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/plugin-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | plugin-2 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/plugin-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.versions 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | plugin-3 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/set-versions/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | org.srcdeps.external 24 | extenal-parent 25 | 1.2.3 26 | 27 | 28 | org.srcdeps.versions 29 | tree-parent 30 | 0.0.1 31 | pom 32 | 33 | A Maven source tree parent 34 | 35 | 36 | val-parent/main 37 | 38 | 39 | 40 | module-1 41 | module-2 42 | module-3 43 | module-4 44 | module-5 45 | module-6 46 | module-7 47 | plugin-1 48 | plugin-2 49 | plugin-3 50 | 51 | 52 | 53 | 54 | 55 | org.srcdeps.versions 56 | module-1 57 | 0.0.1 58 | 59 | 60 | org.srcdeps.whatever 61 | whatever-1 62 | 63 | 64 | 65 | 66 | org.srcdeps.versions 67 | module-2 68 | ${project.version} 69 | 70 | 71 | org.srcdeps.external 72 | extenal-bom 73 | 1.2.3 74 | import 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.srcdeps.versions 83 | plugin-1 84 | ${project.version} 85 | 86 | 87 | org.srcdeps.versions 88 | plugin-2 89 | 0.0.1 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/declared-parent/module-8/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | declared-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-8 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/declared-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | declared-parent 30 | pom 31 | 32 | 33 | module-8 34 | 35 | 36 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/module-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-1 30 | A Maven source tree parent 31 | 32 | 33 | 34 | 35 | org.srcdeps.external 36 | artifact-2 37 | 1.2.3 38 | 39 | 40 | org.srcdeps.tree-1 41 | tree-module-3 42 | 0.0.1 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.srcdeps.external 50 | artifact-3 51 | 1.2.3 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/module-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-2 30 | A Maven source tree parent 31 | 32 | 33 | 34 | org.srcdeps.tree-1 35 | tree-module-4 36 | 0.0.1 37 | 38 | 39 | org.srcdeps.tree-1 40 | tree-module-7 41 | 0.0.1 42 | 43 | 44 | org.srcdeps.tree-1 45 | tree-module-8 46 | 0.0.1 47 | 48 | 49 | org.srcdeps.external 50 | artifact-4 51 | 1.2.3 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.srcdeps.tree-1 59 | tree-plugin 60 | 0.0.1 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/module-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-3 30 | A Maven source tree parent 31 | 32 | 33 | 34 | org.srcdeps.external 35 | artifact-1 36 | 1.2.3 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/module-4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-4 30 | A Maven source tree parent 31 | 32 | 33 | org.srcdeps.tree-1 34 | tree-module-1 35 | 0.0.1 36 | 37 | 38 | org.srcdeps.tree-1 39 | tree-module-5 40 | 0.0.1 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/module-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-6 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/module-7/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-7 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-plugin 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.external 25 | external-parent 26 | 1.2.3 27 | 28 | 29 | org.srcdeps.tree-1 30 | tree-parent 31 | 0.0.1 32 | pom 33 | 34 | A Maven source tree parent 35 | 36 | 37 | val-parent 38 | 39 | 40 | 41 | module-1 42 | module-2 43 | 44 | module-4 45 | 46 | module-7 47 | plugin 48 | proper-parent 49 | declared-parent 50 | 51 | 52 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/proper-parent/module-5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | ../../pom.xml 28 | 29 | 30 | tree-module-5 31 | 32 | 33 | val-5 34 | 35 | 36 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1-expected/proper-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | proper-parent 30 | pom 31 | 32 | 33 | val-proper-parent 34 | 35 | 36 | 37 | module-5 38 | 39 | 40 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/declared-parent/module-8/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | declared-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-8 30 | 31 | 32 | val-8/main 33 | 34 | 35 | 36 | 37 | org.srcdeps.tree-1 38 | tree-module-1 39 | 0.0.1 40 | 41 | 42 | 43 | 44 | 45 | p1 46 | 47 | 48 | val-8/p1 49 | 50 | 51 | 52 | 53 | p2 54 | 55 | 56 | val-8/p2 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/declared-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | declared-parent 30 | pom 31 | 32 | 33 | module-8 34 | 35 | 36 | 37 | 38 | org.srcdeps.external 39 | artifact-5 40 | 1.2.3 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/module-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-1 30 | A Maven source tree parent 31 | 32 | 33 | 34 | 35 | org.srcdeps.external 36 | artifact-2 37 | 1.2.3 38 | 39 | 40 | org.srcdeps.tree-1 41 | tree-module-3 42 | 0.0.1 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.srcdeps.external 50 | artifact-3 51 | 1.2.3 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/module-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-2 30 | A Maven source tree parent 31 | 32 | 33 | 34 | org.srcdeps.tree-1 35 | tree-module-4 36 | 0.0.1 37 | 38 | 39 | org.srcdeps.tree-1 40 | tree-module-7 41 | 0.0.1 42 | 43 | 44 | org.srcdeps.tree-1 45 | tree-module-8 46 | 0.0.1 47 | 48 | 49 | org.srcdeps.external 50 | artifact-4 51 | 1.2.3 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.srcdeps.tree-1 59 | tree-plugin 60 | 0.0.1 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/module-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-3 30 | A Maven source tree parent 31 | 32 | 33 | 34 | org.srcdeps.external 35 | artifact-1 36 | 1.2.3 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/module-4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-4 30 | A Maven source tree parent 31 | 32 | 33 | org.srcdeps.tree-1 34 | tree-module-1 35 | 0.0.1 36 | 37 | 38 | org.srcdeps.tree-1 39 | tree-module-5 40 | 0.0.1 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/module-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-6 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/module-7/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-module-7 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | tree-plugin 30 | 31 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.external 25 | external-parent 26 | 1.2.3 27 | 28 | 29 | org.srcdeps.tree-1 30 | tree-parent 31 | 0.0.1 32 | pom 33 | 34 | A Maven source tree parent 35 | 36 | 37 | val-parent 38 | 39 | 40 | 41 | module-1 42 | module-2 43 | module-3 44 | module-4 45 | module-6 46 | module-7 47 | plugin 48 | proper-parent 49 | declared-parent 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/proper-parent/module-5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | ../../pom.xml 28 | 29 | 30 | tree-module-5 31 | 32 | 33 | val-5 34 | 35 | 36 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/MavenSourceTree/tree-1/proper-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.srcdeps.tree-1 25 | tree-parent 26 | 0.0.1 27 | 28 | 29 | proper-parent 30 | pom 31 | 32 | 33 | val-proper-parent 34 | 35 | 36 | 37 | module-5 38 | 39 | 40 | -------------------------------------------------------------------------------- /pom-tuner-tests/src/test/resources/settings-mrm.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | mrm-maven-plugin 24 | Mock Repository Manager 25 | ${mrm.repository.url} 26 | * 27 | 28 | 29 | 30 | 31 | it-repo 32 | 33 | true 34 | 35 | 36 | 37 | snapshots 38 | ${mrm.repository.url} 39 | 40 | true 41 | ignore 42 | never 43 | 44 | 45 | true 46 | ignore 47 | always 48 | 49 | 50 | 51 | 52 | 53 | snapshots 54 | ${mrm.repository.url} 55 | 56 | true 57 | ignore 58 | never 59 | 60 | 61 | true 62 | ignore 63 | always 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /pom-tuner/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.l2x6.pom-tuner 25 | pom-tuner-parent 26 | 4.5.3-SNAPSHOT 27 | 28 | 29 | pom-tuner 30 | ${project.groupId}:${project.artifactId} 31 | 32 | 33 | 34 | org.slf4j 35 | slf4j-api 36 | provided 37 | 38 | 39 | 40 | org.junit.jupiter 41 | junit-jupiter-api 42 | test 43 | 44 | 45 | org.junit.jupiter 46 | junit-jupiter-params 47 | test 48 | 49 | 50 | org.slf4j 51 | slf4j-simple 52 | test 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/Comparators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner; 18 | 19 | import java.util.Comparator; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | 23 | public class Comparators { 24 | private static final Comparator SAFE_STRING_COMPARATOR = (a, b) -> a == b 25 | ? 0 26 | : (a != null ? a.compareTo(b) : -1); 27 | 28 | private Comparators() { 29 | } 30 | 31 | public static Comparator> entryKeyOnly() { 32 | return Comparator 33 | .comparing(Map.Entry::getKey, SAFE_STRING_COMPARATOR); 34 | } 35 | 36 | public static Comparator> entryValueOnly() { 37 | return Comparator 38 | .comparing(Map.Entry::getValue, SAFE_STRING_COMPARATOR); 39 | } 40 | 41 | public static Comparator> entryKeyValue() { 42 | return Comparator 43 | .comparing((Map.Entry en) -> en.getKey(), SAFE_STRING_COMPARATOR) 44 | .thenComparing(Map.Entry::getValue, SAFE_STRING_COMPARATOR); 45 | } 46 | 47 | public static Comparator before(T item) { 48 | return new BeforeItemComparator(item); 49 | } 50 | 51 | public static Comparator after(T item) { 52 | return new AfterItemComparator(item); 53 | } 54 | 55 | public static Comparator safeStringComparator() { 56 | return SAFE_STRING_COMPARATOR; 57 | } 58 | 59 | static class AfterItemComparator implements Comparator { 60 | private final T item; 61 | private boolean found = false; 62 | 63 | public AfterItemComparator(T item) { 64 | this.item = item; 65 | } 66 | 67 | @Override 68 | public int compare(T o1, T o2) { 69 | boolean oldFound = found; 70 | if (Objects.equals(o2, item)) { 71 | found = true; 72 | } 73 | if (Objects.equals(o1, o2)) { 74 | return 0; 75 | } 76 | return oldFound ? -1 : 1; 77 | } 78 | } 79 | 80 | static class BeforeItemComparator implements Comparator { 81 | private final T item; 82 | private boolean found = false; 83 | 84 | public BeforeItemComparator(T item) { 85 | this.item = item; 86 | } 87 | 88 | @Override 89 | public int compare(T o1, T o2) { 90 | if (Objects.equals(o2, item)) { 91 | found = true; 92 | } 93 | if (Objects.equals(o1, o2)) { 94 | return 0; 95 | } 96 | return found ? -1 : 1; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/ExpressionEvaluator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner; 18 | 19 | import org.l2x6.pom.tuner.model.Expression; 20 | import org.l2x6.pom.tuner.model.Ga; 21 | import org.l2x6.pom.tuner.model.Gav; 22 | import org.l2x6.pom.tuner.model.GavExpression; 23 | 24 | public interface ExpressionEvaluator { 25 | String evaluate(Expression expression); 26 | 27 | default Gav evaluateGav(GavExpression gav) { 28 | return new Gav(evaluate(gav.getGroupId()), evaluate(gav.getArtifactId()), evaluate(gav.getVersion())); 29 | } 30 | 31 | default Ga evaluateGa(GavExpression gav) { 32 | return new Ga(evaluate(gav.getGroupId()), evaluate(gav.getArtifactId())); 33 | } 34 | 35 | class ConstantOnlyExpressionEvaluator implements ExpressionEvaluator { 36 | 37 | @Override 38 | public String evaluate(Expression expression) { 39 | if (expression.isConstant()) { 40 | return expression.getRawExpression(); 41 | } 42 | throw new IllegalArgumentException(ConstantOnlyExpressionEvaluator.class.getSimpleName() 43 | + " cannot resolve a non-constant expression " + expression); 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/PomTunerUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner; 18 | 19 | public class PomTunerUtils { 20 | 21 | private PomTunerUtils() { 22 | } 23 | 24 | /** 25 | * @param anyPath a path with either slashes or backslashes 26 | * @return a file path with slashes 27 | */ 28 | public static String toUnixPath(String anyPath) { 29 | if (anyPath == null || anyPath.isEmpty()) { 30 | return anyPath; 31 | } 32 | return anyPath.replace('\\', '/'); 33 | } 34 | 35 | /** 36 | * A generator of XPath 1.0 "any namespace" selector, such as 37 | * {@code /*:[local-name()='foo']/*:[local-name()='bar']}. In XPath 2.0, this would be just {@code /*:foo/*:bar}, 38 | * but as of Java 13, there is only XPath 1.0 available in the JDK. 39 | * 40 | * @param elements namespace-less element names 41 | * @return am XPath 1.0 style selector 42 | */ 43 | public static String anyNs(String... elements) { 44 | StringBuilder sb = new StringBuilder(); 45 | for (String e : elements) { 46 | sb.append("/*[local-name()='").append(e).append("']"); 47 | } 48 | return sb.toString(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/Dependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | public class Dependency extends GavExpression { 20 | private final String scope; 21 | private final String type; 22 | private final Expression classifier; 23 | static final String JAR = "jar"; 24 | static final String COMPILE = "compile"; 25 | 26 | public Dependency(Expression groupId, Expression artifactId, Expression version, String type, Expression classifier, 27 | String scope) { 28 | super(groupId, artifactId, version); 29 | this.classifier = classifier; 30 | this.type = type == null || type.isEmpty() ? JAR : type; 31 | this.scope = scope == null || scope.isEmpty() ? COMPILE : scope; 32 | } 33 | 34 | public String getType() { 35 | return type; 36 | } 37 | 38 | public Expression getClassifier() { 39 | return classifier; 40 | } 41 | 42 | public String getScope() { 43 | return scope; 44 | } 45 | 46 | public boolean isVirtual() { 47 | return "pom".equals(type) && "test".equals(scope); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | final int prime = 31; 53 | int result = super.hashCode(); 54 | result = prime * result + ((classifier == null) ? 0 : classifier.hashCode()); 55 | result = prime * result + ((scope == null) ? 0 : scope.hashCode()); 56 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 57 | return result; 58 | } 59 | 60 | @Override 61 | public boolean equals(Object obj) { 62 | if (this == obj) 63 | return true; 64 | if (!super.equals(obj)) 65 | return false; 66 | if (getClass() != obj.getClass()) 67 | return false; 68 | Dependency other = (Dependency) obj; 69 | if (classifier == null) { 70 | if (other.classifier != null) 71 | return false; 72 | } else if (!classifier.equals(other.classifier)) 73 | return false; 74 | if (scope == null) { 75 | if (other.scope != null) 76 | return false; 77 | } else if (!scope.equals(other.scope)) 78 | return false; 79 | if (type == null) { 80 | if (other.type != null) 81 | return false; 82 | } else if (!type.equals(other.type)) 83 | return false; 84 | return true; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return getGroupId() + ":" + getArtifactId() + ":" + type + ":" + classifier + ":" + getVersion() + ":" + scope; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | /** 20 | * An expression used in Maven {@code pom.xml} files, such as ${my-property} or 21 | * my-prefix-${my-property} 22 | */ 23 | public class Expression { 24 | 25 | final String expression; 26 | private final Ga ga; 27 | private final boolean constant; 28 | 29 | public Expression(String expression, Ga ga) { 30 | super(); 31 | this.expression = expression; 32 | this.constant = expression.indexOf("${") < 0; 33 | this.ga = ga; 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = 1; 40 | result = prime * result + ((expression == null) ? 0 : expression.hashCode()); 41 | result = prime * result + ((ga == null || constant) ? 0 : ga.hashCode()); 42 | return result; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object obj) { 47 | if (this == obj) 48 | return true; 49 | if (obj == null) 50 | return false; 51 | if (getClass() != obj.getClass()) 52 | return false; 53 | Expression other = (Expression) obj; 54 | if (expression == null) { 55 | if (other.expression != null) 56 | return false; 57 | } else if (!expression.equals(other.expression)) 58 | return false; 59 | if (!constant) { 60 | if (ga == null) { 61 | if (other.ga != null) 62 | return false; 63 | } else if (!ga.equals(other.ga)) 64 | return false; 65 | } 66 | return true; 67 | } 68 | 69 | public String getExpression() { 70 | return expression; 71 | } 72 | 73 | /** 74 | * @return the raw source of this {@link Expression} 75 | */ 76 | public String getRawExpression() { 77 | return expression; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return expression; 83 | } 84 | 85 | /** 86 | * @return the constant value of this {@link Expression} if this is a {@link Constant}; otherwise an 87 | * {@link IllegalStateException} is thrown 88 | */ 89 | public String asConstant() { 90 | if (constant) { 91 | return expression; 92 | } 93 | throw new IllegalStateException(expression + "is not a constant"); 94 | } 95 | 96 | public static class NoSuchPropertyException extends RuntimeException { 97 | /** */ 98 | private static final long serialVersionUID = 8378620214313767928L; 99 | private final String propertyName; 100 | 101 | public NoSuchPropertyException(String propertyName) { 102 | super(String.format( 103 | "Unable to resolve property [%s]: root of the module hierarchy reached", 104 | propertyName)); 105 | this.propertyName = propertyName; 106 | } 107 | 108 | public String getPropertyName() { 109 | return propertyName; 110 | } 111 | 112 | } 113 | 114 | /** 115 | * @param expression the expression possibly containing ${...} placeholders 116 | * @param ga the {@link Ga} against which the resulting {@link Expression} should be evaluated 117 | * @return a {@link NonConstant} or {@link Constant} depending on whether the given {@code expression} 118 | * contains 119 | * ${ 120 | */ 121 | public static Expression of(String expression, Ga ga) { 122 | return new Expression(expression, ga); 123 | } 124 | 125 | public boolean isConstant() { 126 | return constant; 127 | } 128 | 129 | /** 130 | * @return the {@link Ga} of the module where the resolution of this {@link Expression} should start. For expressions 131 | * used in {@code } block, this would be the parent {@link Ga}. For all other cases, this is the 132 | * {@link Gav} of the {@code pom.xml} where this {@link Expression} occurs. 133 | */ 134 | public Ga getGa() { 135 | return ga; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/Ga.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.StringTokenizer; 20 | 21 | /** 22 | * An immutable {@link #groupId}, {@link #artifactId} pair with a fast {@link #hashCode()} and {@link #equals(Object)}. 23 | * 24 | * @author Peter Palaga 25 | */ 26 | public class Ga implements Comparable { 27 | 28 | private static final Ga EXCELUDE_ALL = new Ga("*", "*"); 29 | private final String artifactId; 30 | private final String groupId; 31 | private final int hashCode; 32 | 33 | /** 34 | * Returns a new {@link Ga} instance parsed out of the given {@code gavString}. 35 | * 36 | * @param gavString the string to parse, something of the form {@code groupId:artifactId:version} 37 | * @return a new {@link Ga} instance parsed out of the given {@code gavString} 38 | */ 39 | public static Ga of(String gavString) { 40 | StringTokenizer st = new StringTokenizer(gavString, ":"); 41 | if (!st.hasMoreTokens()) { 42 | throw new IllegalStateException(String.format("Cannot parse [%s] to a " + Ga.class.getName(), gavString)); 43 | } else { 44 | final String g = st.nextToken(); 45 | if (!st.hasMoreTokens()) { 46 | throw new IllegalStateException( 47 | String.format("Cannot parse [%s] to a " + Ga.class.getName(), gavString)); 48 | } else { 49 | final String a = st.nextToken(); 50 | return new Ga(g, a); 51 | } 52 | } 53 | } 54 | 55 | public static Ga of(String groupId, String artifactId) { 56 | if ("*".equals(groupId) && "*".equals(artifactId)) { 57 | return EXCELUDE_ALL; 58 | } 59 | return new Ga(groupId, artifactId); 60 | } 61 | 62 | public Ga(String groupId, String artifactId) { 63 | super(); 64 | this.groupId = groupId; 65 | this.artifactId = artifactId; 66 | this.hashCode = 31 * (31 + artifactId.hashCode()) + groupId.hashCode(); 67 | } 68 | 69 | @Override 70 | public int compareTo(Ga o) { 71 | int result = this.groupId.compareTo(o.groupId); 72 | if (result != 0) { 73 | return result; 74 | } else { 75 | return this.artifactId.compareTo(o.artifactId); 76 | } 77 | } 78 | 79 | @Override 80 | public boolean equals(Object obj) { 81 | if (this == obj) 82 | return true; 83 | if (obj == null) 84 | return false; 85 | if (getClass() != obj.getClass()) 86 | return false; 87 | Ga other = (Ga) obj; 88 | return this.artifactId.equals(other.artifactId) && this.groupId.equals(other.groupId); 89 | } 90 | 91 | public String getArtifactId() { 92 | return artifactId; 93 | } 94 | 95 | public String getGroupId() { 96 | return groupId; 97 | } 98 | 99 | @Override 100 | public int hashCode() { 101 | return hashCode; 102 | } 103 | 104 | @Override 105 | public String toString() { 106 | return groupId + ":" + artifactId; 107 | } 108 | 109 | public static Ga excludeAll() { 110 | return EXCELUDE_ALL; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/Gav.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.StringTokenizer; 20 | 21 | /** 22 | * An immutable {@link #groupId}, {@link #artifactId}, {@link #version} triple with a fast {@link #hashCode()} and 23 | * {@link #equals(Object)}. 24 | * 25 | * @author Peter Palaga 26 | */ 27 | public class Gav implements Comparable { 28 | 29 | /** 30 | * Returns a new {@link Gav} instance parsed out of the given {@code gavString}. 31 | * 32 | * @param gavString the string to parse, something of the form {@code groupId:artifactId:version} 33 | * @return a new {@link Gav} instance parsed out of the given {@code gavString} 34 | */ 35 | public static Gav of(String gavString) { 36 | StringTokenizer st = new StringTokenizer(gavString, ":"); 37 | if (!st.hasMoreTokens()) { 38 | throw new IllegalStateException(String.format("Cannot parse [%s] to a " + Gav.class.getName(), gavString)); 39 | } else { 40 | final String g = st.nextToken(); 41 | if (!st.hasMoreTokens()) { 42 | throw new IllegalStateException( 43 | String.format("Cannot parse [%s] to a " + Gav.class.getName(), gavString)); 44 | } else { 45 | final String a = st.nextToken(); 46 | if (!st.hasMoreTokens()) { 47 | throw new IllegalStateException( 48 | String.format("Cannot parse [%s] to a " + Gav.class.getName(), gavString)); 49 | } else { 50 | final String v = st.nextToken(); 51 | return new Gav(g, a, v); 52 | } 53 | } 54 | } 55 | } 56 | 57 | private final String artifactId; 58 | private final String groupId; 59 | private final int hashCode; 60 | private final String version; 61 | 62 | public Gav(String groupId, String artifactId, String version) { 63 | super(); 64 | this.groupId = groupId; 65 | this.artifactId = artifactId; 66 | this.version = version; 67 | this.hashCode = 31 * (31 * (31 + artifactId.hashCode()) + groupId.hashCode()) + version.hashCode(); 68 | } 69 | 70 | @Override 71 | public int compareTo(Gav o) { 72 | int result = this.groupId.compareTo(o.groupId); 73 | if (result != 0) { 74 | return result; 75 | } else { 76 | result = this.artifactId.compareTo(o.artifactId); 77 | if (result != 0) { 78 | return result; 79 | } else { 80 | return this.version.compareTo(o.version); 81 | } 82 | } 83 | } 84 | 85 | @Override 86 | public boolean equals(Object obj) { 87 | if (this == obj) 88 | return true; 89 | if (obj == null) 90 | return false; 91 | if (getClass() != obj.getClass()) 92 | return false; 93 | Gav other = (Gav) obj; 94 | return this.version.equals(other.version) && this.artifactId.equals(other.artifactId) 95 | && this.groupId.equals(other.groupId); 96 | } 97 | 98 | public String getArtifactId() { 99 | return artifactId; 100 | } 101 | 102 | public String getGroupId() { 103 | return groupId; 104 | } 105 | 106 | public String getVersion() { 107 | return version; 108 | } 109 | 110 | @Override 111 | public int hashCode() { 112 | return hashCode; 113 | } 114 | 115 | @Override 116 | public String toString() { 117 | return groupId + ":" + artifactId + ":" + version; 118 | } 119 | 120 | public Ga toGa() { 121 | return new Ga(groupId, artifactId); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/GavExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * A {@link Ga} combined with a version {@link Expression}. 23 | */ 24 | public class GavExpression { 25 | 26 | private final Expression artifactId; 27 | private final Expression groupId; 28 | 29 | private final Expression version; 30 | 31 | public GavExpression(Expression groupId, Expression artifactId, Expression version) { 32 | this.groupId = Objects.requireNonNull(groupId, "groupId"); 33 | this.artifactId = Objects.requireNonNull(artifactId, "artifactId"); 34 | this.version = version; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | GavExpression other = (GavExpression) obj; 46 | if (artifactId == null) { 47 | if (other.artifactId != null) 48 | return false; 49 | } else if (!artifactId.equals(other.artifactId)) 50 | return false; 51 | if (groupId == null) { 52 | if (other.groupId != null) 53 | return false; 54 | } else if (!groupId.equals(other.groupId)) 55 | return false; 56 | if (version == null) { 57 | if (other.version != null) 58 | return false; 59 | } else if (!version.equals(other.version)) 60 | return false; 61 | return true; 62 | } 63 | 64 | public Expression getArtifactId() { 65 | return artifactId; 66 | } 67 | 68 | public Expression getGroupId() { 69 | return groupId; 70 | } 71 | 72 | public Expression getVersion() { 73 | return version; 74 | } 75 | 76 | @Override 77 | public int hashCode() { 78 | final int prime = 31; 79 | int result = 1; 80 | result = prime * result + ((artifactId == null) ? 0 : artifactId.hashCode()); 81 | result = prime * result + ((groupId == null) ? 0 : groupId.hashCode()); 82 | result = prime * result + ((version == null) ? 0 : version.hashCode()); 83 | return result; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | return groupId.getRawExpression() + ":" + artifactId.getRawExpression() + ":" + version; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.Set; 20 | 21 | public class Plugin extends GavExpression { 22 | private final Set dependencies; 23 | 24 | public Plugin(Expression groupId, Expression artifactId, Expression version, Set dependencies) { 25 | super(groupId, artifactId, version); 26 | this.dependencies = dependencies; 27 | } 28 | 29 | public Set getDependencies() { 30 | return dependencies; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/Profile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | import java.util.AbstractMap; 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.LinkedHashMap; 23 | import java.util.LinkedHashSet; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Set; 27 | import java.util.function.Predicate; 28 | import java.util.stream.Collectors; 29 | import org.l2x6.pom.tuner.MavenSourceTree; 30 | import org.l2x6.pom.tuner.model.Module.DependencyBuilder; 31 | import org.l2x6.pom.tuner.model.Module.ModuleGavBuilder; 32 | import org.l2x6.pom.tuner.model.Module.PlainGavBuilder; 33 | import org.l2x6.pom.tuner.model.Module.PluginGavBuilder; 34 | 35 | /** 36 | * A Maven profile. 37 | */ 38 | public class Profile { 39 | 40 | /** 41 | * A Maven {@link Profile} builder. 42 | */ 43 | public static class Builder { 44 | Set children = new LinkedHashSet<>(); 45 | List dependencies = new ArrayList<>(); 46 | List dependencyManagement = new ArrayList<>(); 47 | List extensions = new ArrayList<>(); 48 | private String id; 49 | List pluginManagement = new ArrayList<>(); 50 | List plugins = new ArrayList<>(); 51 | List properties = new ArrayList<>(); 52 | final Predicate dependencyExcludes; 53 | 54 | Builder(Predicate dependencyExcludes) { 55 | this.dependencyExcludes = dependencyExcludes; 56 | } 57 | 58 | public Profile build() { 59 | final Set useChildren = Collections.unmodifiableSet(new LinkedHashSet<>(children)); 60 | final Set useDependencies = Collections 61 | . unmodifiableSet((Set) dependencies.stream() 62 | .map(DependencyBuilder::build) 63 | .filter(dep -> !dependencyExcludes.test(dep)) 64 | .collect(Collectors.toCollection(LinkedHashSet::new))); 65 | final Set useManagedDependencies = Collections 66 | . unmodifiableSet( 67 | (Set) dependencyManagement.stream().map(DependencyBuilder::build) 68 | .collect(Collectors.toCollection(LinkedHashSet::new))); 69 | final Set usePlugins = Collections. unmodifiableSet((Set) plugins.stream() 70 | .map(PluginGavBuilder::build).collect(Collectors.toCollection(LinkedHashSet::new))); 71 | final Set usePluginManagement = Collections 72 | . unmodifiableSet((Set) pluginManagement.stream().map(PluginGavBuilder::build) 73 | .collect(Collectors.toCollection(LinkedHashSet::new))); 74 | 75 | final Set useExtensions = Collections 76 | . unmodifiableSet((Set) extensions 77 | .stream().map(PlainGavBuilder::build).collect(Collectors.toCollection(LinkedHashSet::new))); 78 | 79 | final Map useProps = Collections.unmodifiableMap(properties.stream() // 80 | .map(PropertyBuilder::build) // 81 | .collect(( // 82 | Collectors.toMap( // 83 | e -> e.getKey(), // 84 | e -> e.getValue(), // 85 | (u, v) -> v, // 86 | LinkedHashMap::new // 87 | ) // 88 | )) // 89 | ); 90 | return new Profile(id, useChildren, useDependencies, useManagedDependencies, usePlugins, 91 | usePluginManagement, useExtensions, useProps); 92 | } 93 | 94 | public void id(String id) { 95 | this.id = id; 96 | } 97 | 98 | public Set getChildren() { 99 | return children; 100 | } 101 | 102 | public List getDependencies() { 103 | return dependencies; 104 | } 105 | 106 | public List getProperties() { 107 | return properties; 108 | } 109 | } 110 | 111 | public static class PropertyBuilder { 112 | final ModuleGavBuilder ga; 113 | 114 | final String key; 115 | final String value; 116 | 117 | PropertyBuilder(String key, String value, ModuleGavBuilder ga) { 118 | super(); 119 | this.key = key; 120 | this.value = value; 121 | this.ga = ga; 122 | } 123 | 124 | public Map.Entry build() { 125 | final Expression val = Expression.of(value, ga.getGa()); 126 | return new AbstractMap.SimpleImmutableEntry<>(key, val); 127 | } 128 | } 129 | 130 | /** A path to child project's pom.xml relative to {@link MavenSourceTree#rootDirectory} */ 131 | final Set children; 132 | final Set dependencies; 133 | final Set dependencyManagement; 134 | private final Set extensions; 135 | private final String id; 136 | private final Set pluginManagement; 137 | 138 | final Set plugins; 139 | final Map properties; 140 | 141 | Profile(String id, Set children, Set dependencies, Set dependencyManagement, 142 | Set plugins, Set pluginManagement, Set extensions, 143 | Map properties) { 144 | super(); 145 | this.id = id; 146 | this.children = children; 147 | this.dependencies = dependencies; 148 | this.dependencyManagement = dependencyManagement; 149 | this.plugins = plugins; 150 | this.pluginManagement = pluginManagement; 151 | this.extensions = extensions; 152 | this.properties = properties; 153 | } 154 | 155 | /** 156 | * @return a {@link Set} of paths to {@code pom.xml} files of child modules of this Module realtive to 157 | * {@link MavenSourceTree#getRootDirectory()} 158 | */ 159 | public Set getChildren() { 160 | return children; 161 | } 162 | 163 | /** 164 | * @return a {@link Set} of dependencies declared in this {@link Profile} 165 | */ 166 | public Set getDependencies() { 167 | return dependencies; 168 | } 169 | 170 | /** 171 | * @return a {@link Set} of dependencyManagement entries declared in this {@link Profile} 172 | */ 173 | public Set getDependencyManagement() { 174 | return dependencyManagement; 175 | } 176 | 177 | public Set getExtensions() { 178 | return extensions; 179 | } 180 | 181 | /** 182 | * @return an ID of this profile or {@code null} if this is the representation of a top level profile-less 183 | * dependencies, plugins, etc. 184 | */ 185 | public String getId() { 186 | return id; 187 | } 188 | 189 | /** 190 | * @return a {@link Set} of pluginManagement entries declared in this {@link Profile} 191 | */ 192 | public Set getPluginManagement() { 193 | return pluginManagement; 194 | } 195 | 196 | /** 197 | * @return a {@link Set} of plugins declared in this {@link Profile} 198 | */ 199 | public Set getPlugins() { 200 | return plugins; 201 | } 202 | 203 | /** 204 | * @return the {@link Map} of properties declared in this {@link Profile} 205 | */ 206 | public Map getProperties() { 207 | return properties; 208 | } 209 | 210 | } 211 | -------------------------------------------------------------------------------- /pom-tuner/src/main/java/org/l2x6/pom/tuner/model/ValueDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner.model; 18 | 19 | public class ValueDefinition { 20 | private final Module module; 21 | private final Expression value; 22 | private final String xPath; 23 | 24 | public ValueDefinition(Module module, String xPath, Expression value) { 25 | super(); 26 | this.module = module; 27 | this.xPath = xPath; 28 | this.value = value; 29 | } 30 | 31 | /** 32 | * @return the {@link Module} in which {@link #value} is defined 33 | */ 34 | public Module getModule() { 35 | return module; 36 | } 37 | 38 | /** 39 | * @return the value of the {@link Expression} 40 | */ 41 | public Expression getValue() { 42 | return value; 43 | } 44 | 45 | /** 46 | * @return an XPath expression pointing at the element where the {@link #value} is defined 47 | */ 48 | public String getXPath() { 49 | return xPath; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pom-tuner/src/test/java/org/l2x6/pom/tuner/SomeSimpleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Maven Utilities Project 3 | * project contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * 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, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.l2x6.pom.tuner; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | public class SomeSimpleTest { 24 | 25 | @Test 26 | void smoke() { 27 | assertTrue(true); 28 | } 29 | 30 | } 31 | --------------------------------------------------------------------------------