diff --git a/.asf.yaml b/.asf.yaml index 8c718460..14864468 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -29,4 +29,9 @@ github: merge: false rebase: true autolink_jira: - - MINVOKER \ No newline at end of file + - MINVOKER +notifications: + commits: commits@maven.apache.org + issues: issues@maven.apache.org + pullrequests: issues@maven.apache.org + jira_options: link label comment diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml index 8a95815d..f213d075 100644 --- a/.github/workflows/maven-verify.yml +++ b/.github/workflows/maven-verify.yml @@ -24,7 +24,6 @@ on: jobs: build: name: Verify - uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3 + uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4 with: - jdk-matrix: '[ "8", "11", "17", "19"]' verify-fail-fast: false diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index b44872cf..1049eaa3 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -22,4 +22,4 @@ on: - master jobs: update_release_draft: - uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml@v3 + uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml@v4 diff --git a/.gitignore b/.gitignore index f79c9285..8f9ebd5c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ out/ /bootstrap /dependencies.xml .java-version +.checkstyle \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index e257faf3..e9f05f7d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,4 +17,4 @@ * under the License. */ -asfMavenTlpPlgnBuild(jdks:[ "8", "11", "17", "19"]) +asfMavenTlpPlgnBuild() diff --git a/README.md b/README.md index 2faf6ca8..147abdbe 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Contributing to [Apache Maven Invoker Plugin](https://maven.apache.org/plugins/m [![ASF Jira](https://img.shields.io/endpoint?url=https%3A%2F%2Fmaven.apache.org%2Fbadges%2Fasf_jira-MINVOKER.json)][jira] [![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/apache/maven.svg?label=License)][license] [![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven.plugins/maven-invoker-plugin.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.maven.plugins/maven-invoker-plugin) -[![Reproducible Builds](https://img.shields.io/badge/Reproducible_Builds-ok-green?labelColor=blue)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/plugins/maven-invoker-plugin/README.md) +[![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/apache/maven/plugins/maven-invoker-plugin/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/plugins/maven-invoker-plugin/README.md) [![Jenkins Status](https://img.shields.io/jenkins/s/https/ci-maven.apache.org/job/Maven/job/maven-box/job/maven-invoker-plugin/job/master.svg?)][build] [![Jenkins tests](https://img.shields.io/jenkins/t/https/ci-maven.apache.org/job/Maven/job/maven-box/job/maven-invoker-plugin/job/master.svg?)][test-results] diff --git a/pom.xml b/pom.xml index 4bb9610a..6ee4640c 100644 --- a/pom.xml +++ b/pom.xml @@ -23,12 +23,12 @@ under the License. org.apache.maven.plugins maven-plugins - 39 + 43 maven-invoker-plugin - 3.4.1-SNAPSHOT + 3.8.2-SNAPSHOT maven-plugin Apache Maven Invoker Plugin @@ -40,8 +40,8 @@ under the License. - scm:git:https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git - scm:git:https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git + scm:git:https://github.com/apache/maven-invoker-plugin.git + scm:git:https://github.com/apache/maven-invoker-plugin.git HEAD https://github.com/apache/maven-invoker-plugin/tree/${project.scm.tag} @@ -62,12 +62,16 @@ under the License. 8 - 3.2.5 + 3.6.3 + 1.4.1 org.apache-extras.beanshell bsh 2.0b6 - 2022-12-15T01:19:19Z - 4.0.6 + 2024-10-18T16:49:15Z + 4.0.23 + + 3.21.0 + 2.0.0 @@ -81,7 +85,7 @@ under the License. commons-codec commons-codec - 1.15 + 1.17.1 commons-collections @@ -91,12 +95,12 @@ under the License. commons-io commons-io - 2.11.0 + 2.17.0 org.apache.groovy groovy-bom - ${groovy-version} + ${groovyVersion} pom import @@ -107,7 +111,7 @@ under the License. org.apache.maven.shared maven-invoker - 3.2.0 + 3.3.0 org.apache.maven @@ -145,30 +149,35 @@ under the License. ${mavenVersion} provided + + org.apache.maven.resolver + maven-resolver-api + ${resolverVersion} + provided + + + org.apache.maven.resolver + maven-resolver-util + ${resolverVersion} + org.apache.maven.reporting maven-reporting-api - 3.1.1 + 4.0.0 org.apache.maven.reporting maven-reporting-impl - 3.2.0 - - - org.codehaus.plexus - plexus-container-default - - + 4.0.0 org.apache.maven.doxia doxia-sink-api - 1.11.1 + 2.0.0 @@ -176,23 +185,22 @@ under the License. maven-plugin-annotations provided - - org.apache.maven.shared - maven-script-interpreter - 1.4 + javax.inject + javax.inject + 1 + provided org.apache.maven.shared - maven-artifact-transfer - 0.13.1 + maven-script-interpreter + 1.6 - org.apache.maven.shared - maven-common-artifact-filters - 3.2.0 - compile + org.slf4j + slf4j-api + 1.7.36 @@ -221,12 +229,17 @@ under the License. org.codehaus.plexus plexus-utils - 3.5.0 + + + org.codehaus.plexus + plexus-xml + + 3.0.1 org.codehaus.plexus plexus-interpolation - 1.26 + 1.27 org.codehaus.plexus @@ -242,43 +255,35 @@ under the License. org.apache.maven.shared maven-shared-utils - 3.3.4 + 3.4.2 - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-api test - org.mockito - mockito-core - 4.10.0 + org.junit.jupiter + junit-jupiter-params test - org.apache.maven.plugin-testing - maven-plugin-testing-harness - 3.3.0 + org.mockito + mockito-core + 4.11.0 test - - - org.codehaus.plexus - plexus-container-default - - - org.apache.maven - maven-compat - ${mavenVersion} + org.mockito + mockito-junit-jupiter + 4.11.0 test org.assertj assertj-core - 3.23.1 + 3.26.3 test @@ -309,6 +314,7 @@ under the License. maven-checkstyle-plugin true + src/config/checkstyle-suppressions.xml @@ -376,34 +382,22 @@ under the License. + + org.eclipse.sisu + sisu-maven-plugin + run-its - - - 3.1.0 - 3.2.0 - 3.10.1 - 3.1.0 - 3.3.0 - 3.1.0 - 3.3.0 - 3.7.0 - 3.3.0 - 3.12.1 - 3.2.1 - 3.0.0-M7 - org.apache.maven.plugins maven-invoker-plugin - 3.4.0 ${project.build.directory}/it setup @@ -411,7 +405,6 @@ under the License. ${project.build.directory}/local-repo src/it/settings.xml -Djava.io.tmpdir=${project.build.directory} - true ${maven.compiler.source} ${maven.compiler.target} diff --git a/src/config/checkstyle-suppressions.xml b/src/config/checkstyle-suppressions.xml new file mode 100644 index 00000000..9409ed9b --- /dev/null +++ b/src/config/checkstyle-suppressions.xml @@ -0,0 +1,25 @@ + + + + + + diff --git a/src/it/MINVOKER-191/plugin/pom.xml b/src/it/MINVOKER-191/plugin/pom.xml index cf5b9fce..cae0b2b8 100644 --- a/src/it/MINVOKER-191/plugin/pom.xml +++ b/src/it/MINVOKER-191/plugin/pom.xml @@ -39,6 +39,17 @@ under the License. + + + + org.apache.maven.plugins + maven-plugin-plugin + + test + + + + org.apache.maven.plugins diff --git a/src/it/MINVOKER-191/pom.xml b/src/it/MINVOKER-191/pom.xml index ee01722d..1e2d8866 100644 --- a/src/it/MINVOKER-191/pom.xml +++ b/src/it/MINVOKER-191/pom.xml @@ -49,17 +49,17 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - @compilerPluginVersion@ + @version.maven-compiler-plugin@ org.apache.maven.plugins maven-plugin-plugin - @pluginPluginVersion@ + @version.maven-plugin-tools@ org.apache.maven.plugins maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ org.apache.maven.plugins diff --git a/src/it/MINVOKER-196_junit_report_file/pom.xml b/src/it/MINVOKER-196_junit_report_file/pom.xml index cb5ee642..b6d11cc0 100644 --- a/src/it/MINVOKER-196_junit_report_file/pom.xml +++ b/src/it/MINVOKER-196_junit_report_file/pom.xml @@ -41,12 +41,12 @@ under the License. org.apache.maven.plugins maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true true diff --git a/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml b/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml index 56343427..1268201d 100644 --- a/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml +++ b/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml @@ -64,7 +64,7 @@ under the License. maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ diff --git a/src/it/MINVOKER-288-failed-setup-run/pom.xml b/src/it/MINVOKER-288-failed-setup-run/pom.xml index af7aec20..66934092 100644 --- a/src/it/MINVOKER-288-failed-setup-run/pom.xml +++ b/src/it/MINVOKER-288-failed-setup-run/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it true diff --git a/src/it/MINVOKER-288-failed-setup-verify/pom.xml b/src/it/MINVOKER-288-failed-setup-verify/pom.xml index b1822dd1..a2cdb0dc 100644 --- a/src/it/MINVOKER-288-failed-setup-verify/pom.xml +++ b/src/it/MINVOKER-288-failed-setup-verify/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it true diff --git a/src/it/MINVOKER-289/pom.xml b/src/it/MINVOKER-289/pom.xml index 09da8e89..fa4868e9 100644 --- a/src/it/MINVOKER-289/pom.xml +++ b/src/it/MINVOKER-289/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true true diff --git a/src/it/MINVOKER-328_install-default/invoker.properties b/src/it/MINVOKER-328_install-default/invoker.properties new file mode 100644 index 00000000..353946b6 --- /dev/null +++ b/src/it/MINVOKER-328_install-default/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = verify diff --git a/src/it/MINVOKER-328_install-default/pom.xml b/src/it/MINVOKER-328_install-default/pom.xml new file mode 100644 index 00000000..8b2718b3 --- /dev/null +++ b/src/it/MINVOKER-328_install-default/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker + minvoker328 + 1.0-SNAPSHOT + pom + + https://issues.apache.org/jira/browse/MINVOKER-328 + install with default configuration + + + UTF-8 + + + + + org.slf4j + slf4j-api + 1.7.36 + + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + + + install + + + + + + + + diff --git a/src/it/MINVOKER-328_install-default/verify.groovy b/src/it/MINVOKER-328_install-default/verify.groovy new file mode 100644 index 00000000..144091e7 --- /dev/null +++ b/src/it/MINVOKER-328_install-default/verify.groovy @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File buildLog = new File(basedir, 'build.log') +assert buildLog.text.contains('[DEBUG] Skip install the same target') \ No newline at end of file diff --git a/src/it/MINVOKER-330-realative-mavenExacutable/pom.xml b/src/it/MINVOKER-330-realative-mavenExacutable/pom.xml new file mode 100644 index 00000000..ae7d2cac --- /dev/null +++ b/src/it/MINVOKER-330-realative-mavenExacutable/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker.its + minvoker-330 + 1.0-SNAPSHOT + pom + + + Test to check for usage of relative path in mavenExecutable. + + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + + integration-test + initialize + + run + + + + + mvn + + + + + + diff --git a/src/it/MINVOKER-330-realative-mavenExacutable/src/it/project/pom.xml b/src/it/MINVOKER-330-realative-mavenExacutable/src/it/project/pom.xml new file mode 100644 index 00000000..e83b4293 --- /dev/null +++ b/src/it/MINVOKER-330-realative-mavenExacutable/src/it/project/pom.xml @@ -0,0 +1,28 @@ + + + + + + 4.0.0 + org.apache.maven.plugins.invoker.its + minvoker-330 + 0.1-SNAPSHOT + pom + diff --git a/src/it/MINVOKER-335-symlinks-in-source/invoker.properties b/src/it/MINVOKER-335-symlinks-in-source/invoker.properties new file mode 100644 index 00000000..f45dd01a --- /dev/null +++ b/src/it/MINVOKER-335-symlinks-in-source/invoker.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# NOTE: Don't clean here to be able to detect test failures +invoker.goals = initialize diff --git a/src/it/MINVOKER-335-symlinks-in-source/pom.xml b/src/it/MINVOKER-335-symlinks-in-source/pom.xml new file mode 100644 index 00000000..a62be04d --- /dev/null +++ b/src/it/MINVOKER-335-symlinks-in-source/pom.xml @@ -0,0 +1,65 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker + clone-clean-invocation + 1.0-SNAPSHOT + pom + + Test to check for copping symlinks from source to target + https://issues.apache.org/jira/browse/MINVOKER-335 + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + ${project.build.directory}/it + + */pom.xml + + + validate + + + + + integration-test + initialize + + run + + + + + + + + diff --git a/src/it/MINVOKER-335-symlinks-in-source/selector.groovy b/src/it/MINVOKER-335-symlinks-in-source/selector.groovy new file mode 100644 index 00000000..9afad9aa --- /dev/null +++ b/src/it/MINVOKER-335-symlinks-in-source/selector.groovy @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.nio.file.Files +import java.nio.file.Paths + +def projectPath = new File(basedir, 'src/it/clone-symlinks').toPath() + +def testDir = projectPath.resolve('testDir'); +def testFile = projectPath.resolve('test.txt') + +Files.createDirectory(testDir) +Files.createFile(testFile) + +// If FS does not support symlinks we should skip test +try { + Files.createSymbolicLink(projectPath.resolve('testDirLink'), Paths.get('testDir')) + Files.createSymbolicLink(projectPath.resolve('testLink.txt'), Paths.get('test.txt')) +} catch (IOException e) { + return false +} + +return true diff --git a/src/it/MINVOKER-335-symlinks-in-source/src/it/clone-symlinks/pom.xml b/src/it/MINVOKER-335-symlinks-in-source/src/it/clone-symlinks/pom.xml new file mode 100644 index 00000000..b49b4127 --- /dev/null +++ b/src/it/MINVOKER-335-symlinks-in-source/src/it/clone-symlinks/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + test + clone-symlnks + 0.1-SNAPSHOT + pom + + + UTF-8 + + diff --git a/src/it/MINVOKER-335-symlinks-in-source/verify.groovy b/src/it/MINVOKER-335-symlinks-in-source/verify.groovy new file mode 100644 index 00000000..dee7a378 --- /dev/null +++ b/src/it/MINVOKER-335-symlinks-in-source/verify.groovy @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.nio.file.Files +import java.nio.file.Paths + +def projectPath = new File(basedir, 'target/it/clone-symlinks').toPath() + +assert Files.readSymbolicLink(projectPath.resolve('testDirLink')) == Paths.get('testDir') +assert Files.readSymbolicLink(projectPath.resolve('testLink.txt')) == Paths.get('test.txt') diff --git a/src/it/MINVOKER-351/invoker.properties b/src/it/MINVOKER-351/invoker.properties new file mode 100644 index 00000000..d3ffde37 --- /dev/null +++ b/src/it/MINVOKER-351/invoker.properties @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals.1 = initialize +invoker.buildResult.1 = failure + +invoker.goals.2 = site diff --git a/src/it/MINVOKER-351/pom.xml b/src/it/MINVOKER-351/pom.xml new file mode 100644 index 00000000..a38261e0 --- /dev/null +++ b/src/it/MINVOKER-351/pom.xml @@ -0,0 +1,92 @@ + + + + + + 4.0.0 + + example.minvoker351 + minvoker-351 + 1.0-SNAPSHOT + pom + + Special XML chars in build-job, junit reports + + + UTF-8 + @version.maven-compiler-plugin@ + @version.maven-surefire@ + + + + + + org.apache.maven.plugins + maven-site-plugin + @version.maven-site-plugin@ + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + ${project.build.directory}/it + ${project.build.directory}/local-repo + true + + + + integration-test + initialize + + install + run + + + + + + + + + + true + + + org.apache.maven.plugins + maven-surefire-report-plugin + ${version.maven-surefire} + + + ${project.build.directory}/invoker-reports-test + + + + + + report-only + + + + + + + diff --git a/src/it/MINVOKER-351/src/it/minvoker-351/pom.xml b/src/it/MINVOKER-351/src/it/minvoker-351/pom.xml new file mode 100644 index 00000000..1e327cb6 --- /dev/null +++ b/src/it/MINVOKER-351/src/it/minvoker-351/pom.xml @@ -0,0 +1,35 @@ + + + + + + 4.0.0 + + example.minvoker351 + minvoker-351 + 1.0-SNAPSHOT + pom + + + UTF-8 + + + diff --git a/src/it/MINVOKER-351/src/it/minvoker-351/postbuild.groovy b/src/it/MINVOKER-351/src/it/minvoker-351/postbuild.groovy new file mode 100644 index 00000000..cc511ba0 --- /dev/null +++ b/src/it/MINVOKER-351/src/it/minvoker-351/postbuild.groovy @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +throw new Exception("Special chars \tcharName=" + Character.getName(7) + ": " + (char) 7) diff --git a/src/it/MINVOKER-351/verify.groovy b/src/it/MINVOKER-351/verify.groovy new file mode 100644 index 00000000..afc487b0 --- /dev/null +++ b/src/it/MINVOKER-351/verify.groovy @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// we have a special chars in build.log +def buildLog = new File(basedir, 'target/it/minvoker-351/build.log').text +buildLog.contains('Special chars \tcharName=BEL: \u0007') + +def surefireReport = new File(basedir, 'target/site/surefire-report.html').text +assert surefireReport.contains('maven.invoker.it.minvoker-351') + +// TODO remove after next release +// Due to error parsing junit-reports by Jenkins with forbidden chars +new File(basedir, 'build.log').delete() + +return true \ No newline at end of file diff --git a/src/it/MINVOKER-365-user-poperties-from-pre-build/pom.xml b/src/it/MINVOKER-365-user-poperties-from-pre-build/pom.xml new file mode 100644 index 00000000..044b2f84 --- /dev/null +++ b/src/it/MINVOKER-365-user-poperties-from-pre-build/pom.xml @@ -0,0 +1,65 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker.its + minvoker-335 + 1.0-SNAPSHOT + pom + + + Test to check a user properties generated by pre-build + + + + UTF-8 + @version.maven-enforcer-plugin@ + @version.maven-clean-plugin@ + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + + integration-test + initialize + + run + + + + + + clean + initialize + + + + + + + diff --git a/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/pom.xml b/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/pom.xml new file mode 100644 index 00000000..02d6e99a --- /dev/null +++ b/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + org.apache.maven.plugins.invoker.its + minvoker-365 + 0.1-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-clean-plugin + @version.maven-clean-plugin@ + + + org.apache.maven.plugins + maven-enforcer-plugin + @version.maven-enforcer-plugin@ + + + initialize + + enforce + + + + + + + + ${testFile} + + + + + + + + diff --git a/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/postbuild.groovy b/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/postbuild.groovy new file mode 100644 index 00000000..6491a73a --- /dev/null +++ b/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/postbuild.groovy @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def logs = new File(basedir, 'build.log').text + +assert logs.contains('[INFO] Clean is skipped.') diff --git a/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/prebuild.groovy b/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/prebuild.groovy new file mode 100644 index 00000000..ebb19e07 --- /dev/null +++ b/src/it/MINVOKER-365-user-poperties-from-pre-build/src/it/project/prebuild.groovy @@ -0,0 +1,26 @@ +import java.nio.file.Files + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def userProperties = context.get('userProperties') + +def testFilePath = Files.createTempFile('minvoker-365-prefix', 'suffix') +userProperties.put('testFile', testFilePath.toString()) +userProperties.put('maven.clean.skip', 'true') diff --git a/src/it/MINVOKER-365-user-poperties-from-pre-build/verify.groovy b/src/it/MINVOKER-365-user-poperties-from-pre-build/verify.groovy new file mode 100644 index 00000000..e82ee9ab --- /dev/null +++ b/src/it/MINVOKER-365-user-poperties-from-pre-build/verify.groovy @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def logs = new File(basedir, 'build.log').text + +// check if properties are pass to execution +if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) { + assert logs.contains("-D testFile=") + assert logs.contains("-D maven.clean.skip=true") +} else { + assert logs.contains("'-D' 'testFile=") + assert logs.contains("'-D' 'maven.clean.skip=true'") +} diff --git a/src/it/MINVOKER-368-install-filter-scope/pom.xml b/src/it/MINVOKER-368-install-filter-scope/pom.xml new file mode 100644 index 00000000..ed5374e6 --- /dev/null +++ b/src/it/MINVOKER-368-install-filter-scope/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.invoker + MINVOKER-368 + 1.0-SNAPSHOT + pom + + + Test to check for scope filtering during installation. + + + + UTF-8 + + + + + + + org.apache.maven.shared + maven-shared-utils + 3.4.2 + + + commons-io + commons-io + 2.16.1 + test + + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + ${project.build.directory}/it-repo + + + + integration-test + initialize + + install + + + + + + + + diff --git a/src/it/postbuild-executed-only-once/verify.bsh b/src/it/MINVOKER-368-install-filter-scope/verify.groovy similarity index 59% rename from src/it/postbuild-executed-only-once/verify.bsh rename to src/it/MINVOKER-368-install-filter-scope/verify.groovy index e05fbff3..1a8e1c28 100644 --- a/src/it/postbuild-executed-only-once/verify.bsh +++ b/src/it/MINVOKER-368-install-filter-scope/verify.groovy @@ -17,25 +17,16 @@ * under the License. */ -import java.io.*; -import java.util.*; -import java.util.regex.*; -try -{ - // make sure the Invoker Plugin was indeed run and the build didn't fail somewhere else - File touchFile = new File( basedir, "target/it/project/target/touch.txt" ); - System.out.println( "Checking for existence of touch file: " + touchFile ); - if ( !touchFile.exists() ) - { - System.out.println( "FAILED! no touchFile " + touchFile.toString() ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} +def expected = [ + 'org/apache/maven/shared/maven-shared-utils/3.4.2/maven-shared-utils-3.4.2.pom', + 'org/apache/maven/shared/maven-shared-utils/3.4.2/maven-shared-utils-3.4.2.jar', + 'commons-io/commons-io/2.11.0/commons-io-2.11.0.pom', + 'commons-io/commons-io/2.11.0/commons-io-2.11.0.jar' +] -return true; +def localRepo = new File(basedir, 'target/it-repo') + +def missingFiles = expected.findAll { !new File(localRepo, it).isFile() } + +assert missingFiles == [] diff --git a/src/it/clone-clean/pom.xml b/src/it/clone-clean/pom.xml index c2859244..ab2d2691 100644 --- a/src/it/clone-clean/pom.xml +++ b/src/it/clone-clean/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it true diff --git a/src/it/clone-clean/verify.bsh b/src/it/clone-clean/setup.groovy similarity index 79% rename from src/it/clone-clean/verify.bsh rename to src/it/clone-clean/setup.groovy index f2ece44f..02466de4 100644 --- a/src/it/clone-clean/verify.bsh +++ b/src/it/clone-clean/setup.groovy @@ -17,15 +17,9 @@ * under the License. */ -import java.io.*; +File itRoot = new File(basedir, "target/it/clone-clean") +itRoot.mkdirs() +assert new File(itRoot, "foobar.log").createNewFile() + +assert !new File(basedir, 'src/it/clone-clean/.mvn').exists() -try -{ - File itRoot = new File( basedir, "target/it/clone-clean" ); - return !new File( itRoot, "foobar.log" ).exists(); -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} diff --git a/src/it/clone-clean/setup.bsh b/src/it/clone-clean/verify.groovy similarity index 77% rename from src/it/clone-clean/setup.bsh rename to src/it/clone-clean/verify.groovy index b0296e20..9bb1d43f 100644 --- a/src/it/clone-clean/setup.bsh +++ b/src/it/clone-clean/verify.groovy @@ -17,16 +17,8 @@ * under the License. */ -import java.io.*; -try -{ - File itRoot = new File( basedir, "target/it/clone-clean" ); - itRoot.mkdirs(); - return new File(itRoot, "foobar.log").createNewFile(); -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} +File itRoot = new File(basedir, "target/it/clone-clean") +assert !new File(itRoot, "foobar.log").exists() +// .mnv will be created +assert new File(itRoot, ".mvn").isDirectory() diff --git a/src/it/clone-maven-plugin-packaging/pom.xml b/src/it/clone-maven-plugin-packaging/pom.xml index d3f9f85f..d1b8ff4c 100644 --- a/src/it/clone-maven-plugin-packaging/pom.xml +++ b/src/it/clone-maven-plugin-packaging/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it true diff --git a/src/it/exec-timeout-invoker-level/pom.xml b/src/it/exec-timeout-invoker-level/pom.xml index 441d9aac..352ba165 100644 --- a/src/it/exec-timeout-invoker-level/pom.xml +++ b/src/it/exec-timeout-invoker-level/pom.xml @@ -36,6 +36,17 @@ under the License. + + + + org.apache.maven.plugins + maven-plugin-plugin + + test + + + + org.apache.maven.plugins diff --git a/src/it/exec-timeout-mojo-level/pom.xml b/src/it/exec-timeout-mojo-level/pom.xml index e9a1f5e5..1ff964ec 100644 --- a/src/it/exec-timeout-mojo-level/pom.xml +++ b/src/it/exec-timeout-mojo-level/pom.xml @@ -36,6 +36,17 @@ under the License. + + + + org.apache.maven.plugins + maven-plugin-plugin + + test + + + + org.apache.maven.plugins diff --git a/src/it/fail-build-streamLogsOnFailures/pom.xml b/src/it/fail-build-streamLogsOnFailures/pom.xml index 49ec32d7..3ef70b8c 100644 --- a/src/it/fail-build-streamLogsOnFailures/pom.xml +++ b/src/it/fail-build-streamLogsOnFailures/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true false diff --git a/src/it/fail-build-with-verify/pom.xml b/src/it/fail-build-with-verify/pom.xml index 00ad8631..dd67c096 100644 --- a/src/it/fail-build-with-verify/pom.xml +++ b/src/it/fail-build-with-verify/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-build/pom.xml b/src/it/fail-build/pom.xml index 10ec51d5..f2de0411 100644 --- a/src/it/fail-build/pom.xml +++ b/src/it/fail-build/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true true diff --git a/src/it/fail-ignore-with-verify/pom.xml b/src/it/fail-ignore-with-verify/pom.xml index c0e4c8d8..80921378 100644 --- a/src/it/fail-ignore-with-verify/pom.xml +++ b/src/it/fail-ignore-with-verify/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-ignore/pom.xml b/src/it/fail-ignore/pom.xml index c34ec5da..d8aa3636 100644 --- a/src/it/fail-ignore/pom.xml +++ b/src/it/fail-ignore/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-noprojects_integration-test/pom.xml b/src/it/fail-noprojects_integration-test/pom.xml index 494f0869..e3ad38e1 100644 --- a/src/it/fail-noprojects_integration-test/pom.xml +++ b/src/it/fail-noprojects_integration-test/pom.xml @@ -37,7 +37,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-noprojects_run/pom.xml b/src/it/fail-noprojects_run/pom.xml index 4af1ff54..c14cb50d 100644 --- a/src/it/fail-noprojects_run/pom.xml +++ b/src/it/fail-noprojects_run/pom.xml @@ -37,7 +37,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-noprojects_verify/pom.xml b/src/it/fail-noprojects_verify/pom.xml index 312f4dfe..16b45835 100644 --- a/src/it/fail-noprojects_verify/pom.xml +++ b/src/it/fail-noprojects_verify/pom.xml @@ -37,7 +37,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-postbuild/pom.xml b/src/it/fail-postbuild/pom.xml index 4f6722fc..2f8651ff 100644 --- a/src/it/fail-postbuild/pom.xml +++ b/src/it/fail-postbuild/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-prebuild/pom.xml b/src/it/fail-prebuild/pom.xml index 29e464b0..b5d50262 100644 --- a/src/it/fail-prebuild/pom.xml +++ b/src/it/fail-prebuild/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/fail-run-postbuild/pom.xml b/src/it/fail-run-postbuild/pom.xml index 474fa363..cf806dff 100644 --- a/src/it/fail-run-postbuild/pom.xml +++ b/src/it/fail-run-postbuild/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/install-extra-artifacts/pom.xml b/src/it/install-extra-artifacts/pom.xml index 55da1fa9..6329a7aa 100644 --- a/src/it/install-extra-artifacts/pom.xml +++ b/src/it/install-extra-artifacts/pom.xml @@ -40,7 +40,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it-repo diff --git a/src/it/integration-test-never-fails/pom.xml b/src/it/integration-test-never-fails/pom.xml index 3d0a2a79..4d84b282 100644 --- a/src/it/integration-test-never-fails/pom.xml +++ b/src/it/integration-test-never-fails/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/invocation-cmdline-exclude/pom.xml b/src/it/invocation-cmdline-exclude/pom.xml index 1041bdca..9db8d1d9 100644 --- a/src/it/invocation-cmdline-exclude/pom.xml +++ b/src/it/invocation-cmdline-exclude/pom.xml @@ -31,7 +31,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-cmdline-exclude/src/it/minvoker-140-executable/pom.xml b/src/it/invocation-cmdline-exclude/src/it/minvoker-140-executable/pom.xml index 071fd003..2236da0d 100644 --- a/src/it/invocation-cmdline-exclude/src/it/minvoker-140-executable/pom.xml +++ b/src/it/invocation-cmdline-exclude/src/it/minvoker-140-executable/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-cmdline-exclude/src/it/minvoker-140-ignorable/pom.xml b/src/it/invocation-cmdline-exclude/src/it/minvoker-140-ignorable/pom.xml index 72fb0bcb..3209bafa 100644 --- a/src/it/invocation-cmdline-exclude/src/it/minvoker-140-ignorable/pom.xml +++ b/src/it/invocation-cmdline-exclude/src/it/minvoker-140-ignorable/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-debug/pom.xml b/src/it/invocation-debug/pom.xml index f3b3704e..9f39fc03 100644 --- a/src/it/invocation-debug/pom.xml +++ b/src/it/invocation-debug/pom.xml @@ -33,7 +33,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ @@ -41,7 +41,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ validate diff --git a/src/it/invocation-debug/src/it/minvoker-142/pom.xml b/src/it/invocation-debug/src/it/minvoker-142/pom.xml index 2716f598..20b989a4 100644 --- a/src/it/invocation-debug/src/it/minvoker-142/pom.xml +++ b/src/it/invocation-debug/src/it/minvoker-142/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-debug/src/it/minvoker-142/verify.groovy b/src/it/invocation-debug/src/it/minvoker-142/verify.groovy index b1367e9c..a658496c 100644 --- a/src/it/invocation-debug/src/it/minvoker-142/verify.groovy +++ b/src/it/invocation-debug/src/it/minvoker-142/verify.groovy @@ -17,4 +17,4 @@ * under the License. */ File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( '[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.AlwaysPass' ) \ No newline at end of file +assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.AlwaysPass passed' ) \ No newline at end of file diff --git a/src/it/invocation-emptyproperty/pom.xml b/src/it/invocation-emptyproperty/pom.xml index f22733f1..73a19d7a 100644 --- a/src/it/invocation-emptyproperty/pom.xml +++ b/src/it/invocation-emptyproperty/pom.xml @@ -31,7 +31,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-emptyproperty/src/it/minvoker-118/pom.xml b/src/it/invocation-emptyproperty/src/it/minvoker-118/pom.xml index f125d617..881f48ee 100644 --- a/src/it/invocation-emptyproperty/src/it/minvoker-118/pom.xml +++ b/src/it/invocation-emptyproperty/src/it/minvoker-118/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-environmentvariable/pom.xml b/src/it/invocation-environmentvariable/pom.xml index 94f697d4..5ae26913 100644 --- a/src/it/invocation-environmentvariable/pom.xml +++ b/src/it/invocation-environmentvariable/pom.xml @@ -32,8 +32,8 @@ under the License. UTF-8 - @enforcerPluginVersion@ - @helpPluginVersion@ + @version.maven-enforcer-plugin@ + @version.maven-help-plugin@ diff --git a/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml b/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml index dbf55779..bee9cf8c 100644 --- a/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml +++ b/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml @@ -37,7 +37,7 @@ org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml b/src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml index f89d646e..c04a02cb 100644 --- a/src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml +++ b/src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml @@ -36,7 +36,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/invocation-environmentvariable/src/it/minvoker-273/pom.xml b/src/it/invocation-environmentvariable/src/it/minvoker-273/pom.xml index d6f15f34..300c1bd8 100644 --- a/src/it/invocation-environmentvariable/src/it/minvoker-273/pom.xml +++ b/src/it/invocation-environmentvariable/src/it/minvoker-273/pom.xml @@ -36,7 +36,7 @@ under the License. org.apache.maven.plugins maven-help-plugin - @helpPluginVersion@ + @version.maven-help-plugin@ validate diff --git a/src/it/invocation-group-properties/src/it/projects/group-1/sub-1/pom.xml b/src/it/invocation-group-properties/src/it/projects/group-1/sub-1/pom.xml index cd693884..7089190c 100644 --- a/src/it/invocation-group-properties/src/it/projects/group-1/sub-1/pom.xml +++ b/src/it/invocation-group-properties/src/it/projects/group-1/sub-1/pom.xml @@ -31,7 +31,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ enforce diff --git a/src/it/invocation-group-properties/src/it/projects/group-1/sub-2/pom.xml b/src/it/invocation-group-properties/src/it/projects/group-1/sub-2/pom.xml index c428365b..9df94cb4 100644 --- a/src/it/invocation-group-properties/src/it/projects/group-1/sub-2/pom.xml +++ b/src/it/invocation-group-properties/src/it/projects/group-1/sub-2/pom.xml @@ -31,7 +31,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ enforce diff --git a/src/it/invocation-group-properties/src/it/projects/group-2/sub-1/pom.xml b/src/it/invocation-group-properties/src/it/projects/group-2/sub-1/pom.xml index cd693884..7089190c 100644 --- a/src/it/invocation-group-properties/src/it/projects/group-2/sub-1/pom.xml +++ b/src/it/invocation-group-properties/src/it/projects/group-2/sub-1/pom.xml @@ -31,7 +31,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ enforce diff --git a/src/it/invocation-group-properties/src/it/projects/group-2/sub-2/pom.xml b/src/it/invocation-group-properties/src/it/projects/group-2/sub-2/pom.xml index 555a9251..757cd413 100644 --- a/src/it/invocation-group-properties/src/it/projects/group-2/sub-2/pom.xml +++ b/src/it/invocation-group-properties/src/it/projects/group-2/sub-2/pom.xml @@ -31,7 +31,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ enforce diff --git a/src/it/invocation-multiple/pom.xml b/src/it/invocation-multiple/pom.xml index 7a01a729..2fbc5352 100644 --- a/src/it/invocation-multiple/pom.xml +++ b/src/it/invocation-multiple/pom.xml @@ -32,12 +32,12 @@ under the License. UTF-8 @mavenVersion@ - @compilerPluginVersion@ - @installPluginVersion@ - @jarPluginVersion@ - @pluginPluginVersion@ - @resourcesPluginVersion@ - @surefirePluginVersion@ + @version.maven-compiler-plugin@ + @version.maven-install-plugin@ + @version.maven-jar-plugin@ + @version.maven-plugin-tools@ + @version.maven-resources-plugin@ + @version.maven-surefire@ @@ -45,7 +45,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/invocation-multiple/src/it/project/invoker.properties b/src/it/invocation-multiple/src/it/project/invoker.properties index 89ca0884..3d0e1384 100644 --- a/src/it/invocation-multiple/src/it/project/invoker.properties +++ b/src/it/invocation-multiple/src/it/project/invoker.properties @@ -20,7 +20,7 @@ ####################################### invoker.goals = install invoker.profiles = plugin,profile0 -invoker.systemPropertiesFile = system1.properties +invoker.userPropertiesFile = user.properties ####################################### # First build @@ -40,4 +40,4 @@ invoker.profiles.2 = plugin,profile1 ####################################### invoker.goals.3 = test:test-maven-plugin:0.1-SNAPSHOT:test # profiles should fall back to invoker.profiles -invoker.systemPropertiesFile.3 = system2.properties +invoker.userPropertiesFile.3 = user3.properties diff --git a/src/it/invocation-multiple/src/it/project/pom.xml b/src/it/invocation-multiple/src/it/project/pom.xml index 3c43664c..4746a6eb 100644 --- a/src/it/invocation-multiple/src/it/project/pom.xml +++ b/src/it/invocation-multiple/src/it/project/pom.xml @@ -47,7 +47,7 @@ under the License. maven-compiler-plugin - @compilerPluginVersion@ + @version.maven-compiler-plugin@ ${maven.compiler.source} ${maven.compiler.target} @@ -55,23 +55,23 @@ under the License. maven-install-plugin - @installPluginVersion@ + @version.maven-install-plugin@ maven-jar-plugin - @jarPluginVersion@ + @version.maven-jar-plugin@ maven-plugin-plugin - @pluginPluginVersion@ + @version.maven-plugin-tools@ maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ maven-surefire-plugin - @surefirePluginVersion@ + @version.maven-surefire@ diff --git a/src/it/invocation-multiple/src/it/project/system1.properties b/src/it/invocation-multiple/src/it/project/user.properties similarity index 100% rename from src/it/invocation-multiple/src/it/project/system1.properties rename to src/it/invocation-multiple/src/it/project/user.properties diff --git a/src/it/invocation-multiple/src/it/project/system2.properties b/src/it/invocation-multiple/src/it/project/user3.properties similarity index 100% rename from src/it/invocation-multiple/src/it/project/system2.properties rename to src/it/invocation-multiple/src/it/project/user3.properties diff --git a/src/it/invocation-reactor-indirect/plugin/pom.xml b/src/it/invocation-reactor-indirect/plugin/pom.xml index f443bffe..76c4d843 100644 --- a/src/it/invocation-reactor-indirect/plugin/pom.xml +++ b/src/it/invocation-reactor-indirect/plugin/pom.xml @@ -37,4 +37,18 @@ under the License. 2.0 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + test + + + + + diff --git a/src/it/invocation-reactor-indirect/pom.xml b/src/it/invocation-reactor-indirect/pom.xml index e99c651f..c6e7a59a 100644 --- a/src/it/invocation-reactor-indirect/pom.xml +++ b/src/it/invocation-reactor-indirect/pom.xml @@ -48,17 +48,17 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - @compilerPluginVersion@ + @version.maven-compiler-plugin@ org.apache.maven.plugins maven-plugin-plugin - @pluginPluginVersion@ + @version.maven-plugin-tools@ org.apache.maven.plugins maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ org.apache.maven.plugins diff --git a/src/it/invocation-spaces/pom.xml b/src/it/invocation-spaces/pom.xml index cbe1b124..7a594b93 100644 --- a/src/it/invocation-spaces/pom.xml +++ b/src/it/invocation-spaces/pom.xml @@ -31,11 +31,11 @@ under the License. UTF-8 - @compilerPluginVersion@ - @installPluginVersion@ - @jarPluginVersion@ - @resourcesPluginVersion@ - @surefirePluginVersion@ + @version.maven-compiler-plugin@ + @version.maven-install-plugin@ + @version.maven-jar-plugin@ + @version.maven-resources-plugin@ + @version.maven-surefire@ @@ -43,7 +43,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true src/it projects diff --git a/src/it/invocation-spaces/src/it projects/project/spacy pom.xml b/src/it/invocation-spaces/src/it projects/project/spacy pom.xml index 34638172..98454b0b 100644 --- a/src/it/invocation-spaces/src/it projects/project/spacy pom.xml +++ b/src/it/invocation-spaces/src/it projects/project/spacy pom.xml @@ -41,21 +41,21 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - @compilerPluginVersion@ + @version.maven-compiler-plugin@ org.apache.maven.plugins maven-install-plugin - @installPluginVersion@ + @version.maven-install-plugin@ maven-jar-plugin - @jarPluginVersion@ + @version.maven-jar-plugin@ org.apache.maven.plugins maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ ${project.build.sourceEncoding} @@ -63,7 +63,7 @@ under the License. org.apache.maven.plugins maven-surefire-plugin - @surefirePluginVersion@ + @version.maven-surefire@ diff --git a/src/it/invoker-report/pom.xml b/src/it/invoker-report/pom.xml index dbc99085..a8864503 100644 --- a/src/it/invoker-report/pom.xml +++ b/src/it/invoker-report/pom.xml @@ -63,7 +63,7 @@ under the License. org.apache.maven.plugins maven-site-plugin - @sitePluginVersion@ + @version.maven-site-plugin@ diff --git a/src/it/invoker-report/verify.bsh b/src/it/invoker-report/verify.bsh index 3d507db7..d2607dc9 100644 --- a/src/it/invoker-report/verify.bsh +++ b/src/it/invoker-report/verify.bsh @@ -20,7 +20,7 @@ import java.io.*; import java.util.*; -File reportFile = new File( basedir, "target/site/invoker-report.html"); +File reportFile = new File( basedir, "target/site/invoker.html"); passed = true; diff --git a/src/it/local-repo-default/pom.xml b/src/it/local-repo-default/pom.xml index b601efb2..16b8edfa 100644 --- a/src/it/local-repo-default/pom.xml +++ b/src/it/local-repo-default/pom.xml @@ -41,7 +41,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/its diff --git a/src/it/local-repo-isolated/pom.xml b/src/it/local-repo-isolated/pom.xml index a2e2f8e7..f7cac4ff 100644 --- a/src/it/local-repo-isolated/pom.xml +++ b/src/it/local-repo-isolated/pom.xml @@ -40,7 +40,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it-repo diff --git a/src/it/local-repo-path/pom.xml b/src/it/local-repo-path/pom.xml index 7edfa613..0977b50e 100644 --- a/src/it/local-repo-path/pom.xml +++ b/src/it/local-repo-path/pom.xml @@ -41,7 +41,7 @@ under the License. org.apache.maven.plugins maven-clean-plugin - @cleanPluginVersion@ + @version.maven-clean-plugin@ org.apache.maven.plugins @@ -56,7 +56,7 @@ under the License. -c - org.apache.maven.plugins:maven-clean-plugin:@cleanPluginVersion@:clean + org.apache.maven.plugins:maven-clean-plugin:@version.maven-clean-plugin@:clean diff --git a/src/it/local-repo-url/pom.xml b/src/it/local-repo-url/pom.xml index cb3e8a8b..fb776dec 100644 --- a/src/it/local-repo-url/pom.xml +++ b/src/it/local-repo-url/pom.xml @@ -41,12 +41,12 @@ under the License. org.apache.maven.plugins maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it-repo src/it/settings.xml diff --git a/src/it/not-clone-not-plugin/pom.xml b/src/it/not-clone-not-plugin/pom.xml index 4cf525c6..1e293ce9 100644 --- a/src/it/not-clone-not-plugin/pom.xml +++ b/src/it/not-clone-not-plugin/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ diff --git a/src/it/pom-filtering-encoding/pom.xml b/src/it/pom-filtering-encoding/pom.xml index 431c256c..d07c1392 100644 --- a/src/it/pom-filtering-encoding/pom.xml +++ b/src/it/pom-filtering-encoding/pom.xml @@ -30,7 +30,7 @@ under the License. Test to check for proper handling of file encoding during POM filtering. - @resourcesPluginVersion@ + @version.maven-resources-plugin@ @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml b/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml index 65fae357..236d1bd3 100644 --- a/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml +++ b/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml @@ -47,7 +47,7 @@ under the License. maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ diff --git a/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml b/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml index 8d3d0deb..069c1c23 100644 --- a/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml +++ b/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml @@ -47,7 +47,7 @@ under the License. maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ diff --git a/src/it/pom-filtering-reactor/pom.xml b/src/it/pom-filtering-reactor/pom.xml index 79dac5f1..a64957bb 100644 --- a/src/it/pom-filtering-reactor/pom.xml +++ b/src/it/pom-filtering-reactor/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true ${project.build.directory}/it diff --git a/src/it/pom-filtering/pom.xml b/src/it/pom-filtering/pom.xml index 8fcb6dd7..047e5a51 100644 --- a/src/it/pom-filtering/pom.xml +++ b/src/it/pom-filtering/pom.xml @@ -34,7 +34,7 @@ under the License. UTF-8 PROPERTY-FROM-PROPERTIES-SECTION FAILED - @resourcesPluginVersion@ + @version.maven-resources-plugin@ diff --git a/src/it/pom-filtering/src/it/project/pom.xml b/src/it/pom-filtering/src/it/project/pom.xml index b273ae7c..cc98e82d 100644 --- a/src/it/pom-filtering/src/it/project/pom.xml +++ b/src/it/pom-filtering/src/it/project/pom.xml @@ -64,7 +64,7 @@ under the License. maven-resources-plugin - @resourcesPluginVersion@ + @version.maven-resources-plugin@ diff --git a/src/it/pom-less-invocation/pom.xml b/src/it/pom-less-invocation/pom.xml index a9458c49..4b5eda26 100644 --- a/src/it/pom-less-invocation/pom.xml +++ b/src/it/pom-less-invocation/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it diff --git a/src/it/postbuild-executed-only-once/pom.xml b/src/it/postbuild-executed-only-once/pom.xml index 9624cfb4..3a7cabb6 100644 --- a/src/it/postbuild-executed-only-once/pom.xml +++ b/src/it/postbuild-executed-only-once/pom.xml @@ -31,8 +31,8 @@ under the License. UTF-8 - @compilerPluginVersion@ - @surefirePluginVersion@ + @version.maven-compiler-plugin@ + @version.maven-surefire@ diff --git a/src/it/postbuild-executed-only-once/src/it/project/pom.xml b/src/it/postbuild-executed-only-once/src/it/project/pom.xml index 9cc053af..1f0fb33f 100644 --- a/src/it/postbuild-executed-only-once/src/it/project/pom.xml +++ b/src/it/postbuild-executed-only-once/src/it/project/pom.xml @@ -49,12 +49,12 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - @compilerPluginVersion@ + @version.maven-compiler-plugin@ org.apache.maven.plugins maven-surefire-plugin - @surefirePluginVersion@ + @version.maven-surefire@ ${create_touch_file} diff --git a/src/it/postbuild-executed-only-once/verify.groovy b/src/it/postbuild-executed-only-once/verify.groovy new file mode 100644 index 00000000..8ee560ad --- /dev/null +++ b/src/it/postbuild-executed-only-once/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// make sure the Invoker Plugin was indeed run and the build didn't fail somewhere else +def touchFile = new File(basedir, 'target/it/project/target/touch.txt') +assert touchFile.exists() + +def logs = new File(basedir, 'build.log').text +assert logs.contains('[WARNING] property invoker.systemPropertiesFile is deprecated - please use invoker.userPropertiesFile') diff --git a/src/it/project-cloning-reactor/pom.xml b/src/it/project-cloning-reactor/pom.xml index 7da94c98..c186bc8c 100644 --- a/src/it/project-cloning-reactor/pom.xml +++ b/src/it/project-cloning-reactor/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it diff --git a/src/it/project-cloning/pom.xml b/src/it/project-cloning/pom.xml index 1b7e9081..c1be5b8c 100644 --- a/src/it/project-cloning/pom.xml +++ b/src/it/project-cloning/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it diff --git a/src/it/project-setup/pom.xml b/src/it/project-setup/pom.xml index 0922bba0..ae3a507b 100644 --- a/src/it/project-setup/pom.xml +++ b/src/it/project-setup/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it diff --git a/src/it/script-accessibility/pom.xml b/src/it/script-accessibility/pom.xml index 808cf00e..340e2912 100644 --- a/src/it/script-accessibility/pom.xml +++ b/src/it/script-accessibility/pom.xml @@ -40,7 +40,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ */pom.xml diff --git a/src/it/script-additional-vars/pom.xml b/src/it/script-additional-vars/pom.xml index fbafe4fe..ed4bd558 100644 --- a/src/it/script-additional-vars/pom.xml +++ b/src/it/script-additional-vars/pom.xml @@ -40,7 +40,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ */pom.xml diff --git a/src/it/script-class-loading/pom.xml b/src/it/script-class-loading/pom.xml index d3c3c11c..64d29df6 100644 --- a/src/it/script-class-loading/pom.xml +++ b/src/it/script-class-loading/pom.xml @@ -48,7 +48,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true diff --git a/src/it/script-classpath-duplicates/pom.xml b/src/it/script-classpath-duplicates/pom.xml index 20a19265..04b3a6d0 100644 --- a/src/it/script-classpath-duplicates/pom.xml +++ b/src/it/script-classpath-duplicates/pom.xml @@ -43,7 +43,7 @@ under the License. org.apache.groovy groovy - @groovy-version@ + @groovyVersion@ pom test @@ -54,7 +54,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true true diff --git a/src/it/script-global-vars/pom.xml b/src/it/script-global-vars/pom.xml index 585b5b1b..ea98fdc6 100644 --- a/src/it/script-global-vars/pom.xml +++ b/src/it/script-global-vars/pom.xml @@ -40,7 +40,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ */pom.xml diff --git a/src/it/script-interpreter-detection/pom.xml b/src/it/script-interpreter-detection/pom.xml index b5d5ee1e..672b5255 100644 --- a/src/it/script-interpreter-detection/pom.xml +++ b/src/it/script-interpreter-detection/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/its true diff --git a/src/it/selector-conditions/pom.xml b/src/it/selector-conditions/pom.xml index c73a245b..c30863f5 100644 --- a/src/it/selector-conditions/pom.xml +++ b/src/it/selector-conditions/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ true diff --git a/src/it/selector-scripts/pom.xml b/src/it/selector-scripts/pom.xml index c3be520d..206f5ac3 100644 --- a/src/it/selector-scripts/pom.xml +++ b/src/it/selector-scripts/pom.xml @@ -38,7 +38,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/its true diff --git a/src/it/settings-auto-exclude/pom.xml b/src/it/settings-auto-exclude/pom.xml index c3491c68..240402d6 100644 --- a/src/it/settings-auto-exclude/pom.xml +++ b/src/it/settings-auto-exclude/pom.xml @@ -47,7 +47,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ diff --git a/src/it/settings-inherit/pom.xml b/src/it/settings-inherit/pom.xml index f979416a..7f60df1c 100644 --- a/src/it/settings-inherit/pom.xml +++ b/src/it/settings-inherit/pom.xml @@ -31,7 +31,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/settings-inherit/src/it/project/pom.xml b/src/it/settings-inherit/src/it/project/pom.xml index 42a3f4c2..5ad2dc66 100644 --- a/src/it/settings-inherit/src/it/project/pom.xml +++ b/src/it/settings-inherit/src/it/project/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ enforce-property diff --git a/src/it/settings-merge/pom.xml b/src/it/settings-merge/pom.xml index 26df7c72..acf4864f 100644 --- a/src/it/settings-merge/pom.xml +++ b/src/it/settings-merge/pom.xml @@ -32,7 +32,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/settings-merge/src/it/project/pom.xml b/src/it/settings-merge/src/it/project/pom.xml index 1058edb1..5262cf35 100644 --- a/src/it/settings-merge/src/it/project/pom.xml +++ b/src/it/settings-merge/src/it/project/pom.xml @@ -36,7 +36,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ verify-properties diff --git a/src/it/settings-merge_jdk9+/pom.xml b/src/it/settings-merge_jdk9+/pom.xml index 72ca04fd..b7bb9e0f 100644 --- a/src/it/settings-merge_jdk9+/pom.xml +++ b/src/it/settings-merge_jdk9+/pom.xml @@ -32,8 +32,8 @@ under the License. UTF-8 - @enforcerPluginVersion@ - @helpPluginVersion@ + @version.maven-enforcer-plugin@ + @version.maven-help-plugin@ diff --git a/src/it/settings-merge_jdk9+/src/it/project/pom.xml b/src/it/settings-merge_jdk9+/src/it/project/pom.xml index f2ab455f..9c67cce5 100644 --- a/src/it/settings-merge_jdk9+/src/it/project/pom.xml +++ b/src/it/settings-merge_jdk9+/src/it/project/pom.xml @@ -36,7 +36,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ verify-properties @@ -64,7 +64,7 @@ under the License. org.apache.maven.plugins maven-help-plugin - @helpPluginVersion@ + @version.maven-help-plugin@ effective-settings diff --git a/src/it/settings-override/pom.xml b/src/it/settings-override/pom.xml index e5818e64..60cc8008 100644 --- a/src/it/settings-override/pom.xml +++ b/src/it/settings-override/pom.xml @@ -32,7 +32,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/settings-override/src/it/project/pom.xml b/src/it/settings-override/src/it/project/pom.xml index 505aaea9..d84fbfe1 100644 --- a/src/it/settings-override/src/it/project/pom.xml +++ b/src/it/settings-override/src/it/project/pom.xml @@ -37,7 +37,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ verify-properties diff --git a/src/it/spaces-should-work_non-windows/pom.xml b/src/it/spaces-should-work_non-windows/pom.xml index af9fbf0d..d9858db4 100644 --- a/src/it/spaces-should-work_non-windows/pom.xml +++ b/src/it/spaces-should-work_non-windows/pom.xml @@ -34,7 +34,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/spaces-should-work_non-windows/src/it/minvoker-test/pom.xml b/src/it/spaces-should-work_non-windows/src/it/minvoker-test/pom.xml index 2716f598..20b989a4 100644 --- a/src/it/spaces-should-work_non-windows/src/it/minvoker-test/pom.xml +++ b/src/it/spaces-should-work_non-windows/src/it/minvoker-test/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/spaces-should-work_non-windows/src/it/minvoker-test/verify.groovy b/src/it/spaces-should-work_non-windows/src/it/minvoker-test/verify.groovy index 963ad63a..07309798 100644 --- a/src/it/spaces-should-work_non-windows/src/it/minvoker-test/verify.groovy +++ b/src/it/spaces-should-work_non-windows/src/it/minvoker-test/verify.groovy @@ -21,6 +21,6 @@ File buildLog = new File( basedir, 'build.log' ) // if one of criteria matches if( buildLog.exists() ) { - assert buildLog.text.contains( '[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.AlwaysPass' ) + assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.AlwaysPass passed' ) } diff --git a/src/it/spaces-should-work_windows/pom.xml b/src/it/spaces-should-work_windows/pom.xml index af9fbf0d..d9858db4 100644 --- a/src/it/spaces-should-work_windows/pom.xml +++ b/src/it/spaces-should-work_windows/pom.xml @@ -34,7 +34,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/spaces-should-work_windows/src/it/minvoker-test/pom.xml b/src/it/spaces-should-work_windows/src/it/minvoker-test/pom.xml index 2716f598..20b989a4 100644 --- a/src/it/spaces-should-work_windows/src/it/minvoker-test/pom.xml +++ b/src/it/spaces-should-work_windows/src/it/minvoker-test/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/spaces-should-work_windows/src/it/minvoker-test/verify.groovy b/src/it/spaces-should-work_windows/src/it/minvoker-test/verify.groovy index 963ad63a..07309798 100644 --- a/src/it/spaces-should-work_windows/src/it/minvoker-test/verify.groovy +++ b/src/it/spaces-should-work_windows/src/it/minvoker-test/verify.groovy @@ -21,6 +21,6 @@ File buildLog = new File( basedir, 'build.log' ) // if one of criteria matches if( buildLog.exists() ) { - assert buildLog.text.contains( '[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.AlwaysPass' ) + assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.AlwaysPass passed' ) } diff --git a/src/it/special-characters-should-work/pom.xml b/src/it/special-characters-should-work/pom.xml index 6f612081..218c7c71 100644 --- a/src/it/special-characters-should-work/pom.xml +++ b/src/it/special-characters-should-work/pom.xml @@ -33,7 +33,7 @@ under the License. UTF-8 - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/special-characters-should-work/src/it/minvoker-test/pom.xml b/src/it/special-characters-should-work/src/it/minvoker-test/pom.xml index 2716f598..20b989a4 100644 --- a/src/it/special-characters-should-work/src/it/minvoker-test/pom.xml +++ b/src/it/special-characters-should-work/src/it/minvoker-test/pom.xml @@ -35,7 +35,7 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin - @enforcerPluginVersion@ + @version.maven-enforcer-plugin@ diff --git a/src/it/special-characters-should-work/src/it/minvoker-test/verify.groovy b/src/it/special-characters-should-work/src/it/minvoker-test/verify.groovy index b1367e9c..a658496c 100644 --- a/src/it/special-characters-should-work/src/it/minvoker-test/verify.groovy +++ b/src/it/special-characters-should-work/src/it/minvoker-test/verify.groovy @@ -17,4 +17,4 @@ * under the License. */ File buildLog = new File( basedir, 'build.log' ) -assert buildLog.text.contains( '[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.AlwaysPass' ) \ No newline at end of file +assert buildLog.text.contains( '[INFO] Rule 0: org.apache.maven.enforcer.rules.AlwaysPass passed' ) \ No newline at end of file diff --git a/src/it/staging-dependencies-test-scope/invoker.properties b/src/it/staging-dependencies-test-scope/invoker.properties new file mode 100644 index 00000000..353946b6 --- /dev/null +++ b/src/it/staging-dependencies-test-scope/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = verify diff --git a/src/it/staging-dependencies-test-scope/pom.xml b/src/it/staging-dependencies-test-scope/pom.xml new file mode 100644 index 00000000..8118f99d --- /dev/null +++ b/src/it/staging-dependencies-test-scope/pom.xml @@ -0,0 +1,71 @@ + + + + + + 4.0.0 + + test + staging-dependencies-test-scope + 1.0-SNAPSHOT + + + Test to check for staging of test scope dependencies. + + + + + + org.slf4j + slf4j-api + 1.7.36 + + + + + org.slf4j + slf4j-simple + 1.7.36 + test + + + + + + + org.apache.maven.plugins + maven-invoker-plugin + @project.version@ + + ${project.build.directory}/it-repo + test + + + + integration-test + + install + + + + + + + diff --git a/src/it/staging-dependencies-test-scope/verify.bsh b/src/it/staging-dependencies-test-scope/verify.bsh new file mode 100644 index 00000000..9b32cff2 --- /dev/null +++ b/src/it/staging-dependencies-test-scope/verify.bsh @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.*; +import java.util.*; +import java.util.regex.*; + +import org.codehaus.plexus.util.*; +import org.codehaus.plexus.util.xml.*; + +try +{ + File itRepoDir = new File( basedir, "target/it-repo" ); + System.out.println( "Checking for existence of: " + itRepoDir ); + if ( !itRepoDir.isDirectory() ) + { + System.out.println( "FAILED!" ); + return false; + } + + String[] files = { + "org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar", + "org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.pom", + "org/slf4j/slf4j-api/maven-metadata-local.xml", + "org/slf4j/slf4j-parent/1.7.36/slf4j-parent-1.7.36.pom", + "org/slf4j/slf4j-parent/maven-metadata-local.xml", + "org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar", + "org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.pom", + "org/slf4j/slf4j-simple/maven-metadata-local.xml", + "test/staging-dependencies-test-scope/1.0-SNAPSHOT/staging-dependencies-test-scope-1.0-SNAPSHOT.pom", + "test/staging-dependencies-test-scope/1.0-SNAPSHOT/staging-dependencies-test-scope-1.0-SNAPSHOT.jar" + }; + for ( String file : files ) + { + File stagedFile = new File( itRepoDir, file ); + System.out.println( "Checking for existence of: " + stagedFile ); + if ( !stagedFile.isFile() ) + { + throw new IllegalStateException( "Missing: " + stagedFile ); + } + } +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/src/it/staging-dependencies/pom.xml b/src/it/staging-dependencies/pom.xml index 3aa0840a..9f2c462b 100644 --- a/src/it/staging-dependencies/pom.xml +++ b/src/it/staging-dependencies/pom.xml @@ -62,6 +62,18 @@ under the License. dep 2.0 + + org.slf4j + slf4j-simple + 1.7.36 + test + + + org.slf4j + slf4j-api + 1.7.36 + true + @@ -82,7 +94,7 @@ under the License. org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it-repo diff --git a/src/it/staging-dependencies/verify.bsh b/src/it/staging-dependencies/verify.bsh index ceb7f022..5a1fb4bb 100644 --- a/src/it/staging-dependencies/verify.bsh +++ b/src/it/staging-dependencies/verify.bsh @@ -56,6 +56,11 @@ try "org/apache/maven/its/dep/2.0/dep-2.0.pom", "org/apache/maven/its/dep/2.0/dep-2.0.jar", "org/apache/maven/its/dep/maven-metadata-local.xml", + "test/staging-dependencies/1.0-SNAPSHOT/staging-dependencies-1.0-SNAPSHOT.jar", + "test/staging-dependencies/1.0-SNAPSHOT/staging-dependencies-1.0-SNAPSHOT.pom", + "org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.pom", + "org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar", + "org/slf4j/slf4j-parent/1.7.36/slf4j-parent-1.7.36.pom" }; for ( String file : files ) { @@ -67,6 +72,12 @@ try } } + File stagedTestScope = new File(itRepoDir, "org/slf4j/slf4j-simple"); + if ( stagedTestScope.exists() ) + { + throw new IllegalStateException( "Test scope dependencies should not exists" ); + } + Reader reader = ReaderFactory.newXmlReader( new File( itRepoDir, "org/apache/maven/its/dep/maven-metadata-local.xml" ) ); Xpp3Dom dom = Xpp3DomBuilder.build( reader ); IOUtil.close( reader ); diff --git a/src/it/staging-pom/pom.xml b/src/it/staging-pom/pom.xml index 443a3fc6..db20423b 100644 --- a/src/it/staging-pom/pom.xml +++ b/src/it/staging-pom/pom.xml @@ -22,6 +22,13 @@ under the License. 4.0.0 + + org.apache.maven.plugins + maven-plugins + 39 + + + test pom-packaging 1.0-SNAPSHOT @@ -31,12 +38,16 @@ under the License. Test to check for MINVOKER-51, i.e. NPE when packaging is pom. + + true + + org.apache.maven.plugins maven-invoker-plugin - @pom.version@ + @project.version@ ${project.build.directory}/it-repo @@ -52,7 +63,7 @@ under the License. org.apache.maven.plugins maven-site-plugin - @sitePluginVersion@ + @version.maven-site-plugin@ diff --git a/src/it/staging-pom/verify.bsh b/src/it/staging-pom/verify.bsh index 8565933f..c49ef782 100644 --- a/src/it/staging-pom/verify.bsh +++ b/src/it/staging-pom/verify.bsh @@ -33,6 +33,9 @@ try String[] files = { "test/pom-packaging/1.0-SNAPSHOT/pom-packaging-1.0-SNAPSHOT.pom", + "org/apache/maven/plugins/maven-plugins/39/maven-plugins-39.pom", + "org/apache/maven/maven-parent/39/maven-parent-39.pom", + "org/apache/apache/29/apache-29.pom" }; for ( String file : files ) { diff --git a/src/it/staging-reactor/mod1-parent/pom.xml b/src/it/staging-reactor/mod1-parent/pom.xml index 7bfcffa5..d961392d 100644 --- a/src/it/staging-reactor/mod1-parent/pom.xml +++ b/src/it/staging-reactor/mod1-parent/pom.xml @@ -40,7 +40,7 @@ under the License. org.apache.maven.plugins maven-site-plugin - @sitePluginVersion@ + @version.maven-site-plugin@ diff --git a/src/it/staging-reactor/mod1/pom.xml b/src/it/staging-reactor/mod1/pom.xml index fad9dc45..e1cb6a6e 100644 --- a/src/it/staging-reactor/mod1/pom.xml +++ b/src/it/staging-reactor/mod1/pom.xml @@ -29,7 +29,7 @@ under the License. ../mod1-parent - mod1 + mod1 1.0-SNAPSHOT jar @@ -47,6 +47,12 @@ under the License. mod2 1.0-SNAPSHOT + + test + mod3 + 1.0-SNAPSHOT + true + diff --git a/src/it/staging-reactor/mod2/pom.xml b/src/it/staging-reactor/mod2/pom.xml index 38208b66..e6f4e676 100644 --- a/src/it/staging-reactor/mod2/pom.xml +++ b/src/it/staging-reactor/mod2/pom.xml @@ -44,7 +44,7 @@ under the License. maven-source-plugin - @sourcePluginVersion@ + @version.maven-source-plugin@ attach-resources diff --git a/src/it/staging-reactor/mod3/pom.xml b/src/it/staging-reactor/mod3/pom.xml new file mode 100644 index 00000000..3622d981 --- /dev/null +++ b/src/it/staging-reactor/mod3/pom.xml @@ -0,0 +1,59 @@ + + + + + + 4.0.0 + + + test + mod2-parent + 1.0-SNAPSHOT + + + mod3 + 1.0-SNAPSHOT + jar + + + Test to check for proper staging during a multi module build, i.e. artifacts from the reactor need to be considered. + + + + UTF-8 + + + + + + maven-source-plugin + @version.maven-source-plugin@ + + + attach-resources + + jar + + + + + + + diff --git a/src/it/staging-reactor/mod3/src/main/resources/main.properties b/src/it/staging-reactor/mod3/src/main/resources/main.properties new file mode 100644 index 00000000..00ae6c00 --- /dev/null +++ b/src/it/staging-reactor/mod3/src/main/resources/main.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + diff --git a/src/it/staging-reactor/pom.xml b/src/it/staging-reactor/pom.xml index ae0a279c..46420123 100644 --- a/src/it/staging-reactor/pom.xml +++ b/src/it/staging-reactor/pom.xml @@ -34,6 +34,7 @@ under the License. mod1 mod2 + mod3 @@ -45,7 +46,7 @@ under the License. org.apache.maven.plugins maven-site-plugin - @sitePluginVersion@ + @version.maven-site-plugin@ diff --git a/src/it/staging-reactor/verify.bsh b/src/it/staging-reactor/verify.bsh index 19f6fa83..bc88213d 100644 --- a/src/it/staging-reactor/verify.bsh +++ b/src/it/staging-reactor/verify.bsh @@ -44,7 +44,9 @@ try "test/mod2/1.0-SNAPSHOT/maven-metadata-local.xml", "test/mod2/1.0-SNAPSHOT/mod2-1.0-SNAPSHOT.pom", "test/mod2/1.0-SNAPSHOT/mod2-1.0-SNAPSHOT.jar", - "test/mod2/1.0-SNAPSHOT/mod2-1.0-SNAPSHOT-sources.jar", + "test/mod3/1.0-SNAPSHOT/maven-metadata-local.xml", + "test/mod3/1.0-SNAPSHOT/mod3-1.0-SNAPSHOT.pom", + "test/mod3/1.0-SNAPSHOT/mod3-1.0-SNAPSHOT.jar", "test/mod2-parent/maven-metadata-local.xml", "test/mod2-parent/1.0-SNAPSHOT/maven-metadata-local.xml", "test/mod2-parent/1.0-SNAPSHOT/mod2-parent-1.0-SNAPSHOT.pom", diff --git a/src/it/updateOnly/pom.xml b/src/it/updateOnly/pom.xml index 0b8d1f4b..86be0b69 100644 --- a/src/it/updateOnly/pom.xml +++ b/src/it/updateOnly/pom.xml @@ -42,7 +42,7 @@ under the License. org.apache.maven.plugins maven-antrun-plugin - @antrunPluginVersion@ + @version.maven-antrun-plugin@ initialize diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index aa59f786..4dfac9de 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -28,11 +28,11 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -44,6 +44,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.Set; import java.util.TreeSet; @@ -91,14 +92,14 @@ import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.InterpolationFilterReader; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.NioFiles; import org.codehaus.plexus.util.ReflectionUtils; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; +import org.codehaus.plexus.util.xml.XmlStreamReader; +import org.codehaus.plexus.util.xml.XmlStreamWriter; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomWriter; @@ -111,6 +112,8 @@ * @since 15-Aug-2009 09:09:29 */ public abstract class AbstractInvokerMojo extends AbstractMojo { + private static final float ONE_SECOND = 1000.0f; + /** * The zero-based column index where to print the invoker result. */ @@ -214,6 +217,9 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { @Parameter(defaultValue = "true") private boolean cloneClean; + @Parameter + private List collectedProjects; + /** * A single POM to build, skipping any scanning parameters and behavior. * @@ -407,6 +413,10 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { /** * The MAVEN_OPTS environment variable to use when invoking Maven. This value can be overridden for * individual integration tests by using {@link #invokerPropertiesFile}. + *
+ * Since the version 3.7.0 using an alternate syntax for mavenOpts, @{...} + * allows late replacement of properties when the plugin is executed, + * so properties that have been modified by other plugins will be picked up correctly. * * @since 1.2 */ @@ -429,7 +439,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { * @since 1.8 */ @Parameter(property = "invoker.mavenExecutable") - private File mavenExecutable; + private String mavenExecutable; /** * The JAVA_HOME environment variable to use for forked Maven invocations. Defaults to the current Java @@ -523,11 +533,11 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { * # can be indexed * invoker.offline = true * - * # The path to the properties file from which to load system properties, defaults to the + * # The path to the properties file from which to load user properties, defaults to the * # filename given by the plugin parameter testPropertiesFile * # Since plugin version 1.4 * # can be indexed - * invoker.systemPropertiesFile = test.properties + * invoker.userPropertiesFile = test.properties * * # An optional human friendly name and description for this build job. * # Both name and description have to be set to be included in the build reports. @@ -702,11 +712,6 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { */ private String filteredPomPrefix = "interpolated-"; - /** - * The format for elapsed build time. - */ - private final DecimalFormat secFormat = new DecimalFormat("(0.0 s)", new DecimalFormatSymbols(Locale.ENGLISH)); - /** * The version of Maven which is used to run the builds */ @@ -741,6 +746,9 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { @Component private ToolchainManagerPrivate toolchainManagerPrivate; + @Component + private InterpolatorUtils interpolatorUtils; + /** * Invokes Maven on the configured test projects. * @@ -754,9 +762,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } - if (StringUtils.isEmpty(encoding)) { - getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING - + ", i.e. build is platform dependent!"); + if (encoding == null || encoding.isEmpty()) { + getLog().warn("File encoding has not been set, using platform encoding " + + Charset.defaultCharset().displayName() + ", i.e. build is platform dependent!"); } // done it here to prevent issues with concurrent access in case of parallel run @@ -797,11 +805,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { handleScriptRunnerWithScriptClassPath(); - Collection collectedProjects = new LinkedHashSet<>(); - for (BuildJob buildJob : buildJobs) { - collectProjects(projectsDirectory, buildJob.getProject(), collectedProjects, true); - } - File projectsDir = projectsDirectory; if (cloneProjectsTo == null && "maven-plugin".equals(project.getPackaging())) { @@ -821,7 +824,15 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (cloneProjectsTo != null) { + Collection collectedProjects = this.collectedProjects; + if (collectedProjects == null) { + collectedProjects = new LinkedHashSet<>(); + for (BuildJob buildJob : buildJobs) { + collectProjects(projectsDirectory, buildJob.getProject(), collectedProjects, true); + } + } cloneProjects(collectedProjects); + addMissingDotMvnDirectory(cloneProjectsTo, buildJobs); projectsDir = cloneProjectsTo; } else { getLog().warn("Filtering of parent/child POMs is not supported without cloning the projects"); @@ -858,6 +869,31 @@ public void execute() throws MojoExecutionException, MojoFailureException { processResults(new InvokerSession(buildJobs)); } + /** + * We need add missing {@code .mnvn} directories for executing projects + * + * @param projectsDir base of projects + * @param buildJobs list of discovered jobs + */ + private void addMissingDotMvnDirectory(File projectsDir, List buildJobs) throws MojoExecutionException { + for (BuildJob buildJob : buildJobs) { + Path projectPath = projectsDir.toPath().resolve(buildJob.getProject()); + + if (Files.isRegularFile(projectPath)) { + projectPath = projectPath.getParent(); + } + + Path mvnDotPath = projectPath.resolve(".mvn"); + if (!Files.exists(mvnDotPath)) { + try { + Files.createDirectories(mvnDotPath); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } + } + } + private void setupActualMavenVersion() throws MojoExecutionException { if (mavenHome != null) { try { @@ -1024,8 +1060,7 @@ private void collectProjects( String projectDir = pomFile.getParent(); String parentPath = "../pom.xml"; - if (model.getParent() != null - && StringUtils.isNotEmpty(model.getParent().getRelativePath())) { + if (model.getParent() != null && isNotEmpty(model.getParent().getRelativePath())) { parentPath = model.getParent().getRelativePath(); } String parent = relativizePath(new File(projectDir, parentPath), projectsRoot); @@ -1048,13 +1083,17 @@ private void collectProjects( } } + private boolean isNotEmpty(String s) { + return Objects.nonNull(s) && !s.isEmpty(); + } + /** * Copies the specified projects to the directory given by {@link #cloneProjectsTo}. A project may either be denoted * by a path to a POM file or merely by a path to a base directory. During cloning, the POM files will be filtered. * * @param projectPaths The paths to the projects to clone, relative to the projects directory, must not be * null nor contain null elements. - * @throws org.apache.maven.plugin.MojoExecutionException If the the projects could not be copied/filtered. + * @throws org.apache.maven.plugin.MojoExecutionException If the projects could not be copied/filtered. */ private void cloneProjects(Collection projectPaths) throws MojoExecutionException { if (!cloneProjectsTo.mkdirs() && cloneClean) { @@ -1178,14 +1217,18 @@ private void copyDirectoryStructure(File sourceDir, File destDir) throws IOExcep /* * NOTE: Make sure the destination directory is always there (even if empty) to support POM-less ITs. */ - destDir.mkdirs(); + Files.createDirectories(destDir.toPath()); // Create all the directories, including any symlinks present in source FileUtils.mkDirs(sourceDir, scanner.getIncludedDirectories(), destDir); for (String includedFile : scanner.getIncludedFiles()) { File sourceFile = new File(sourceDir, includedFile); File destFile = new File(destDir, includedFile); - FileUtils.copyFile(sourceFile, destFile); + if (NioFiles.isSymbolicLink(sourceFile)) { + NioFiles.createSymbolicLink(destFile, NioFiles.readSymbolicLink(sourceFile)); + } else { + FileUtils.copyFile(sourceFile, destFile); + } // ensure clone project must be writable for additional changes destFile.setWritable(true); @@ -1398,7 +1441,7 @@ private File mergeSettings(File interpolatedSettingsFile) throws MojoExecutionEx private File writeMergedSettingsFile(Settings mergedSettings) throws IOException { File mergedSettingsFile; - mergedSettingsFile = File.createTempFile("invoker-settings", ".xml"); + mergedSettingsFile = Files.createTempFile("invoker-settings", ".xml").toFile(); SettingsXpp3Writer settingsWriter = new SettingsXpp3Writer(); @@ -1477,7 +1520,7 @@ private CharSequence resolveExternalJreVersion() { private File interpolatePomFile(File pomFile, File basedir) throws MojoExecutionException { File interpolatedPomFile = null; if (pomFile != null) { - if (StringUtils.isNotEmpty(filteredPomPrefix)) { + if (filteredPomPrefix != null && !filteredPomPrefix.isEmpty()) { interpolatedPomFile = new File(basedir, filteredPomPrefix + pomFile.getName()); buildInterpolatedFile(pomFile, interpolatedPomFile); } else { @@ -1523,7 +1566,7 @@ private void runBuild( File interpolatedPomFile = interpolatePomFile(pomFile, basedir); // FIXME: Think about the following code part -- ^^^^^^^ END - getLog().info(buffer().a("Building: ").strong(buildJob.getProject()).toString()); + getLog().info(buffer().a("Building: ").strong(buildJob.getProject()).build()); InvokerProperties invokerProperties = getInvokerProperties(basedir, globalInvokerProperties); @@ -1534,7 +1577,7 @@ private void runBuild( try { int selection = getSelection(invokerProperties, actualJreVersion); if (selection == 0) { - long milliseconds = System.currentTimeMillis(); + long startTime = System.currentTimeMillis(); boolean executed; FileLogger buildLogger = setupBuildLogFile(basedir); @@ -1546,8 +1589,8 @@ private void runBuild( executed = runBuild( basedir, interpolatedPomFile, settingsFile, actualJavaHome, invokerProperties, buildLogger); } finally { - milliseconds = System.currentTimeMillis() - milliseconds; - buildJob.setTime(milliseconds / 1000.0); + long elapsedTime = System.currentTimeMillis() - startTime; + buildJob.setTime(elapsedTime / ONE_SECOND); if (buildLogger != null) { buildLogger.close(); @@ -1558,13 +1601,15 @@ private void runBuild( buildJob.setResult(BuildJob.Result.SUCCESS); if (!suppressSummaries) { - getLog().info(pad(buildJob).success("SUCCESS").a(' ') + formatTime(buildJob.getTime())); + getLog().info(pad(buildJob).success("SUCCESS").a(' ') + "(" + + formatElapsedTime(buildJob.getTime()) + ")"); } } else { buildJob.setResult(BuildJob.Result.SKIPPED); if (!suppressSummaries) { - getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + formatTime(buildJob.getTime())); + getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + "(" + + formatElapsedTime(buildJob.getTime()) + ")"); } } } else { @@ -1604,7 +1649,8 @@ private void runBuild( if (!suppressSummaries) { getLog().info(" " + e.getMessage()); - getLog().info(pad(buildJob).failure("FAILED").a(' ') + formatTime(buildJob.getTime())); + getLog().info(pad(buildJob).failure("FAILED").a(' ') + "(" + formatElapsedTime(buildJob.getTime()) + + ")"); } } finally { deleteInterpolatedPomFile(interpolatedPomFile); @@ -1640,7 +1686,7 @@ private MessageBuilder pad(BuildJob buildJob) { * @param interpolatedPomFile The interpolated pom file. */ private void deleteInterpolatedPomFile(File interpolatedPomFile) { - if (interpolatedPomFile != null && StringUtils.isNotEmpty(filteredPomPrefix)) { + if (interpolatedPomFile != null && (filteredPomPrefix != null && !filteredPomPrefix.isEmpty())) { interpolatedPomFile.delete(); } } @@ -1697,7 +1743,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj File reportFile = new File(reportsDirectory, "TEST-" + safeFileName + ".xml"); Xpp3Dom testsuite = new Xpp3Dom("testsuite"); testsuite.setAttribute("name", junitPackageName + "." + safeFileName); - testsuite.setAttribute("time", Double.toString(buildJob.getTime())); + testsuite.setAttribute("time", Float.toString(buildJob.getTime())); // set default value for required attributes testsuite.setAttribute("tests", "1"); @@ -1729,7 +1775,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj } testcase.setAttribute("classname", junitPackageName + "." + safeFileName); testcase.setAttribute("name", safeFileName); - testcase.setAttribute("time", Double.toString(buildJob.getTime())); + testcase.setAttribute("time", Float.toString(buildJob.getTime())); Xpp3Dom systemOut = new Xpp3Dom("system-out"); testcase.addChild(systemOut); @@ -1755,13 +1801,20 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj } /** - * Formats the specified build duration time. + * Formats the specified elapsed time. * - * @param seconds The duration of the build. + * @param time The eapsed time of the build. * @return The formatted time, never null. */ - private String formatTime(double seconds) { - return secFormat.format(seconds); + private String formatElapsedTime(float time) { + /* + * Rationale: The idea is to always display four digits for visually consistent output + * Important: Keep in sync with src/main/resources/invoker-report.properties + */ + final MessageFormat elapsedTimeFormat = new MessageFormat( + "{0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s", + Locale.ROOT); + return elapsedTimeFormat.format(new Object[] {time}); } /** @@ -1797,24 +1850,15 @@ private boolean runBuild( } Map context = new LinkedHashMap<>(); + Properties scriptUserProperties = new Properties(); + context.put("userProperties", scriptUserProperties); - boolean selectorResult = true; + if (!runSelectorHook(basedir, context, logger)) { + return false; + } try { - try { - scriptRunner.run("selector script", basedir, selectorScript, context, logger); - } catch (ScriptReturnException e) { - selectorResult = false; - return false; - } catch (ScriptException e) { - throw new RunFailureException(BuildJob.Result.ERROR, e); - } - - try { - scriptRunner.run("pre-build script", basedir, preBuildHookScript, context, logger); - } catch (ScriptException e) { - throw new RunFailureException(BuildJob.Result.FAILURE_PRE_HOOK, e); - } + runPreBuildHook(basedir, context, logger); for (int invocationIndex = 1; ; invocationIndex++) { if (invocationIndex > 1 && !invokerProperties.isInvocationDefined(invocationIndex)) { @@ -1846,9 +1890,10 @@ private boolean runBuild( request.setUserSettingsFile(settingsFile); } - Properties systemProperties = - getSystemProperties(basedir, invokerProperties.getSystemPropertiesFile(invocationIndex)); - request.setProperties(systemProperties); + Properties userProperties = + getUserProperties(basedir, invokerProperties.getUserPropertiesFile(invocationIndex)); + userProperties.putAll(scriptUserProperties); + request.setProperties(userProperties); invokerProperties.configureInvocation(request, invocationIndex); @@ -1870,26 +1915,47 @@ private boolean runBuild( "Maven invocation failed. " + e.getMessage(), BuildJob.Result.FAILURE_BUILD); } } - } catch (IOException e) { - throw new MojoExecutionException(e.getMessage(), e); } finally { - if (selectorResult) { - runPostBuildHook(basedir, context, logger); - } + runPostBuildHook(basedir, context, logger); } return true; } int getParallelThreadsCount() { if (parallelThreads.endsWith("C")) { - double parallelThreadsMultiple = - Double.parseDouble(parallelThreads.substring(0, parallelThreads.length() - 1)); + float parallelThreadsMultiple = + Float.parseFloat(parallelThreads.substring(0, parallelThreads.length() - 1)); return (int) (parallelThreadsMultiple * Runtime.getRuntime().availableProcessors()); } else { return Integer.parseInt(parallelThreads); } } + private boolean runSelectorHook(File basedir, Map context, FileLogger logger) + throws MojoExecutionException, RunFailureException { + try { + scriptRunner.run("selector script", basedir, selectorScript, context, logger); + } catch (ScriptReturnException e) { + return false; + } catch (ScriptException e) { + throw new RunFailureException(BuildJob.Result.ERROR, e); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + return true; + } + + private void runPreBuildHook(File basedir, Map context, FileLogger logger) + throws MojoExecutionException, RunFailureException { + try { + scriptRunner.run("pre-build script", basedir, preBuildHookScript, context, logger); + } catch (ScriptException e) { + throw new RunFailureException(BuildJob.Result.FAILURE_PRE_HOOK, e); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } + private void runPostBuildHook(File basedir, Map context, FileLogger logger) throws MojoExecutionException, RunFailureException { try { @@ -1958,7 +2024,7 @@ private FileLogger setupBuildLogFile(File basedir) throws MojoExecutionException * @return The system properties to use, may be empty but never null. * @throws org.apache.maven.plugin.MojoExecutionException If the properties file exists but could not be read. */ - private Properties getSystemProperties(final File basedir, final String filename) throws MojoExecutionException { + private Properties getUserProperties(final File basedir, final String filename) throws MojoExecutionException { Properties collectedTestProperties = new Properties(); if (properties != null) { @@ -1973,18 +2039,16 @@ private Properties getSystemProperties(final File basedir, final String filename File propertiesFile = null; if (filename != null) { propertiesFile = new File(basedir, filename); - } else if (testPropertiesFile != null) { - propertiesFile = new File(basedir, testPropertiesFile); } if (propertiesFile != null && propertiesFile.isFile()) { - try (InputStream fin = new FileInputStream(propertiesFile)) { + try (InputStream fin = Files.newInputStream(propertiesFile.toPath())) { Properties loadedProperties = new Properties(); loadedProperties.load(fin); collectedTestProperties.putAll(loadedProperties); } catch (IOException e) { - throw new MojoExecutionException("Error reading system properties from " + propertiesFile); + throw new MojoExecutionException("Error reading user properties from " + propertiesFile); } } @@ -2025,7 +2089,7 @@ private void verify( private List calculateIncludes() { if (invokerTest != null) { - String[] testRegexes = StringUtils.split(invokerTest, ","); + String[] testRegexes = invokerTest.split(",+"); return Arrays.stream(testRegexes) .map(String::trim) .filter(s -> !s.isEmpty()) @@ -2043,7 +2107,7 @@ private List calculateExcludes() throws IOException { List excludes; if (invokerTest != null) { - String[] testRegexes = StringUtils.split(invokerTest, ","); + String[] testRegexes = invokerTest.split(",+"); excludes = Arrays.stream(testRegexes) .map(String::trim) .filter(s -> !s.isEmpty()) @@ -2265,13 +2329,12 @@ void buildInterpolatedFile(File originalFile, File interpolatedFile) throws Mojo // interpolation with token @...@ try (Reader reader = - new InterpolationFilterReader(ReaderFactory.newXmlReader(originalFile), composite, "@", "@")) { + new InterpolationFilterReader(new XmlStreamReader(originalFile), composite, "@", "@")) { xml = IOUtil.toString(reader); } - try (Writer writer = WriterFactory.newXmlWriter(interpolatedFile)) { + try (Writer writer = new XmlStreamWriter(interpolatedFile)) { interpolatedFile.getParentFile().mkdirs(); - writer.write(xml); } } catch (IOException e) { @@ -2325,10 +2388,11 @@ private InvokerProperties getInvokerProperties(final File projectDirectory, Prop invokerProperties.setDefaultGoals(goals); invokerProperties.setDefaultProfiles(profiles); invokerProperties.setDefaultMavenExecutable(mavenExecutable); - invokerProperties.setDefaultMavenOpts(mavenOpts); + invokerProperties.setDefaultMavenOpts(interpolatorUtils.interpolateAtPattern(mavenOpts)); invokerProperties.setDefaultTimeoutInSeconds(timeoutInSeconds); invokerProperties.setDefaultEnvironmentVariables(environmentVariables); invokerProperties.setDefaultUpdateSnapshots(updateSnapshots); + invokerProperties.setDefaultUserPropertiesFiles(testPropertiesFile); return invokerProperties; } diff --git a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java index 1e482873..8894ef9d 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java @@ -20,17 +20,18 @@ import java.io.File; import java.io.IOException; -import java.util.Collection; +import java.io.UncheckedIOException; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.RepositoryUtils; import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.plugin.AbstractMojo; @@ -41,53 +42,61 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter; -import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller; -import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate; -import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver; -import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException; -import org.apache.maven.shared.transfer.repository.RepositoryManager; -import org.codehaus.plexus.util.FileUtils; +import org.apache.maven.project.artifact.ProjectArtifact; +import org.eclipse.aether.DefaultRepositoryCache; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.ArtifactType; +import org.eclipse.aether.artifact.ArtifactTypeRegistry; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.DefaultDependencyNode; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.DependencyFilter; +import org.eclipse.aether.installation.InstallRequest; +import org.eclipse.aether.installation.InstallationException; +import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.LocalRepositoryManager; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResolutionException; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.resolution.DependencyRequest; +import org.eclipse.aether.resolution.DependencyResolutionException; +import org.eclipse.aether.resolution.DependencyResult; +import org.eclipse.aether.util.artifact.ArtifactIdUtils; +import org.eclipse.aether.util.artifact.JavaScopes; +import org.eclipse.aether.util.artifact.SubArtifact; +import org.eclipse.aether.util.filter.DependencyFilterUtils; /** * Installs the project artifacts of the main build into the local repository as a preparation to run the sub projects. * More precisely, all artifacts of the project itself, all its locally reachable parent POMs and all its dependencies * from the reactor will be installed to the local repository. * - * @since 1.2 * @author Paul Gier * @author Benjamin Bentmann - * + * @since 1.2 */ -// CHECKSTYLE_OFF: LineLength @Mojo( name = "install", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, - requiresDependencyResolution = ResolutionScope.RUNTIME, + requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) -// CHECKSTYLE_ON: LineLength public class InstallMojo extends AbstractMojo { - /** - * Maven artifact install component to copy artifacts to the local repository. - */ - @Component - private ArtifactInstaller installer; + // components used in Mojo @Component - private RepositoryManager repositoryManager; + private RepositorySystem repositorySystem; - /** - * The component used to create artifacts. - */ - @Component - private ArtifactFactory artifactFactory; + @Parameter(defaultValue = "${session}", readonly = true, required = true) + private MavenSession session; - /** - */ - @Parameter(property = "localRepository", required = true, readonly = true) - private ArtifactRepository localRepository; + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject project; /** * The path to the local repository into which the project artifacts should be installed for the integration tests. @@ -101,21 +110,6 @@ public class InstallMojo extends AbstractMojo { required = true) private File localRepositoryPath; - /** - * The current Maven project. - */ - @Parameter(defaultValue = "${project}", readonly = true, required = true) - private MavenProject project; - - @Parameter(defaultValue = "${session}", readonly = true, required = true) - private MavenSession session; - - /** - * The set of Maven projects in the reactor build. - */ - @Parameter(defaultValue = "${reactorProjects}", readonly = true) - private Collection reactorProjects; - /** * A flag used to disable the installation procedure. This is primarily intended for usage from the command line to * occasionally adjust the build. @@ -126,32 +120,23 @@ public class InstallMojo extends AbstractMojo { private boolean skipInstallation; /** - * The identifiers of already installed artifacts, used to avoid multiple installation of the same artifact. - */ - private Collection installedArtifacts; - - /** - * The identifiers of already copied artifacts, used to avoid multiple installation of the same artifact. - */ - private Collection copiedArtifacts; - - /** - * Extra dependencies that need to be installed on the local repository.
+ * Extra dependencies that need to be installed on the local repository. + *

* Format: - * *

      * groupId:artifactId:version:type:classifier
      * 
- * + *

* Examples: - * *

      * org.apache.maven.plugins:maven-clean-plugin:2.4:maven-plugin
      * org.apache.maven.plugins:maven-clean-plugin:2.4:jar:javadoc
      * 
- * + *

* If the type is 'maven-plugin' the plugin will try to resolve the artifact using plugin remote repositories, * instead of using artifact remote repositories. + *

+ * NOTICE all dependencies will be resolved with transitive dependencies in runtime scope. * * @since 1.6 */ @@ -159,19 +144,12 @@ public class InstallMojo extends AbstractMojo { private String[] extraArtifacts; /** + * Scope to resolve project artifacts. + * + * @since 3.5.0 */ - @Component - private DependencyResolver resolver; - - /** - * if the local repository is not used as test repo, the parameter can force get artifacts from local repo - * if available instead of download the artifacts again. - * @since 3.2.1 - */ - @Parameter(property = "invoker.useLocalRepository", defaultValue = "false") - private boolean useLocalRepository; - - private ProjectBuildingRequest projectBuildingRequest; + @Parameter(property = "invoker.install.scope", defaultValue = "runtime") + private String scope; /** * Performs this mojo's tasks. @@ -184,377 +162,264 @@ public void execute() throws MojoExecutionException { return; } - createTestRepository(); + Map resolvedArtifacts = new LinkedHashMap<>(); - installedArtifacts = new HashSet<>(); - copiedArtifacts = new HashSet<>(); + try { - installProjectDependencies(project, reactorProjects); - installProjectParents(project); - installProjectArtifacts(project); + resolveProjectArtifacts(resolvedArtifacts); + resolveProjectPoms(project, resolvedArtifacts); + resolveProjectDependencies(resolvedArtifacts); + resolveExtraArtifacts(resolvedArtifacts); + installArtifacts(resolvedArtifacts); - installExtraArtifacts(extraArtifacts); + } catch (DependencyResolutionException | InstallationException | ArtifactResolutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } } - /** - * Creates the local repository for the integration tests. If the user specified a custom repository location, the - * custom repository will have the same identifier, layout and policies as the real local repository. That means - * apart from the location, the custom repository will be indistinguishable from the real repository such that its - * usage is transparent to the integration tests. - * - * @throws MojoExecutionException If the repository could not be created. - */ - private void createTestRepository() throws MojoExecutionException { + private void resolveProjectArtifacts(Map resolvedArtifacts) { - if (!localRepositoryPath.exists() && !localRepositoryPath.mkdirs()) { - throw new MojoExecutionException("Failed to create directory: " + localRepositoryPath); + // pom packaging doesn't have a main artifact + if (project.getArtifact() != null && project.getArtifact().getFile() != null) { + Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact()); + resolvedArtifacts.put(ArtifactIdUtils.toId(artifact), artifact); } - projectBuildingRequest = - repositoryManager.setLocalRepositoryBasedir(session.getProjectBuildingRequest(), localRepositoryPath); + + project.getAttachedArtifacts().stream() + .map(RepositoryUtils::toArtifact) + .forEach(a -> resolvedArtifacts.put(ArtifactIdUtils.toId(a), a)); } - /** - * Installs the specified artifact to the local repository. Note: This method should only be used for artifacts that - * originate from the current (reactor) build. Artifacts that have been grabbed from the user's local repository - * should be installed to the test repository via {@link #copyArtifact(File, Artifact)}. - * - * @param file The file associated with the artifact, must not be null. This is in most cases the value - * of artifact.getFile() with the exception of the main artifact from a project with - * packaging "pom". Projects with packaging "pom" have no main artifact file. They have however artifact - * metadata (e.g. site descriptors) which needs to be installed. - * @param artifact The artifact to install, must not be null. - * @throws MojoExecutionException If the artifact could not be installed (e.g. has no associated file). - */ - private void installArtifact(File file, Artifact artifact) throws MojoExecutionException { - try { - if (file == null) { - throw new IllegalStateException("Artifact has no associated file: " + artifact.getId()); - } - if (!file.isFile()) { - throw new IllegalStateException("Artifact is not fully assembled: " + file); - } + private void resolveProjectPoms(MavenProject project, Map resolvedArtifacts) + throws ArtifactResolutionException { - if (installedArtifacts.add(artifact.getId())) { - artifact.setFile(file); - installer.install(projectBuildingRequest, localRepositoryPath, Collections.singletonList(artifact)); - } else { - getLog().debug("Not re-installing " + artifact + ", " + file); - } - } catch (Exception e) { - throw new MojoExecutionException("Failed to install artifact: " + artifact, e); + if (project == null) { + return; + } + + Artifact projectPom = RepositoryUtils.toArtifact(new ProjectArtifact(project)); + if (projectPom.getFile() != null) { + resolvedArtifacts.put(projectPom.toString(), projectPom); + } else { + Artifact artifact = resolveArtifact(projectPom, project.getRemoteProjectRepositories()); + resolvedArtifacts.put(ArtifactIdUtils.toId(artifact), artifact); } + resolveProjectPoms(project.getParent(), resolvedArtifacts); } - /** - * Installs the specified artifact to the local repository. This method serves basically the same purpose as - * {@link #installArtifact(File, Artifact)} but is meant for artifacts that have been resolved - * from the user's local repository (and not the current build outputs). The subtle difference here is that - * artifacts from the repository have already undergone transformations and these manipulations should not be redone - * by the artifact installer. For this reason, this method performs plain copy operations to install the artifacts. - * - * @param file The file associated with the artifact, must not be null. - * @param artifact The artifact to install, must not be null. - * @throws MojoExecutionException If the artifact could not be installed (e.g. has no associated file). - */ - private void copyArtifact(File file, Artifact artifact) throws MojoExecutionException { - try { - if (file == null) { - throw new IllegalStateException("Artifact has no associated file: " + artifact.getId()); - } - if (!file.isFile()) { - throw new IllegalStateException("Artifact is not fully assembled: " + file); - } + private void resolveProjectDependencies(Map resolvedArtifacts) + throws ArtifactResolutionException, MojoExecutionException, DependencyResolutionException { - if (copiedArtifacts.add(artifact.getId())) { - File destination = new File( - localRepositoryPath, - repositoryManager.getPathForLocalArtifact(projectBuildingRequest, artifact)); + DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(scope); - getLog().debug("Installing " + file + " to " + destination); + ArtifactTypeRegistry artifactTypeRegistry = + session.getRepositorySession().getArtifactTypeRegistry(); - copyFileIfDifferent(file, destination); + List managedDependencies = Optional.ofNullable(project.getDependencyManagement()) + .map(DependencyManagement::getDependencies) + .orElseGet(Collections::emptyList) + .stream() + .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry)) + .collect(Collectors.toList()); - MetadataUtils.createMetadata(destination, artifact); - } else { - getLog().debug("Not re-installing " + artifact + ", " + file); - } - } catch (Exception e) { - throw new MojoExecutionException("Failed to stage artifact: " + artifact, e); - } - } + List dependencies = project.getDependencies().stream() + .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry)) + .filter(d -> classpathFilter.accept(new DefaultDependencyNode(d), null)) + .collect(Collectors.toList()); - private void copyFileIfDifferent(File src, File dst) throws IOException { - if (src.lastModified() != dst.lastModified() || src.length() != dst.length()) { - FileUtils.copyFile(src, dst); - dst.setLastModified(src.lastModified()); - } - } + CollectRequest collectRequest = new CollectRequest(); + collectRequest.setRootArtifact(RepositoryUtils.toArtifact(project.getArtifact())); + collectRequest.setDependencies(dependencies); + collectRequest.setManagedDependencies(managedDependencies); - /** - * Installs the main artifact and any attached artifacts of the specified project to the local repository. - * - * @param mvnProject The project whose artifacts should be installed, must not be null. - * @throws MojoExecutionException If any artifact could not be installed. - */ - private void installProjectArtifacts(MavenProject mvnProject) throws MojoExecutionException { - try { - // Install POM (usually attached as metadata but that happens only as a side effect of the Install Plugin) - installProjectPom(mvnProject); + collectRequest.setRepositories(project.getRemoteProjectRepositories()); - // Install the main project artifact (if the project has one, e.g. has no "pom" packaging) - Artifact mainArtifact = mvnProject.getArtifact(); - if (mainArtifact.getFile() != null) { - installArtifact(mainArtifact.getFile(), mainArtifact); - } + DependencyRequest request = new DependencyRequest(collectRequest, classpathFilter); - // Install any attached project artifacts - Collection attachedArtifacts = mvnProject.getAttachedArtifacts(); - for (Artifact attachedArtifact : attachedArtifacts) { - installArtifact(attachedArtifact.getFile(), attachedArtifact); - } - } catch (Exception e) { - throw new MojoExecutionException("Failed to install project artifacts: " + mvnProject, e); - } - } + DependencyResult dependencyResult = + repositorySystem.resolveDependencies(session.getRepositorySession(), request); - /** - * Installs the (locally reachable) parent POMs of the specified project to the local repository. The parent POMs - * from the reactor must be installed or the forked IT builds will fail when using a clean repository. - * - * @param mvnProject The project whose parent POMs should be installed, must not be null. - * @throws MojoExecutionException If any POM could not be installed. - */ - private void installProjectParents(MavenProject mvnProject) throws MojoExecutionException { - try { - for (MavenProject parent = mvnProject.getParent(); parent != null; parent = parent.getParent()) { - if (parent.getFile() == null) { - copyParentPoms(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); - break; - } - installProjectPom(parent); - } - } catch (Exception e) { - throw new MojoExecutionException("Failed to install project parents: " + mvnProject, e); - } - } + List artifacts = dependencyResult.getArtifactResults().stream() + .map(ArtifactResult::getArtifact) + .collect(Collectors.toList()); - /** - * Installs the POM of the specified project to the local repository. - * - * @param mvnProject The project whose POM should be installed, must not be null. - * @throws MojoExecutionException If the POM could not be installed. - */ - private void installProjectPom(MavenProject mvnProject) throws MojoExecutionException { - try { - Artifact pomArtifact = null; - if ("pom".equals(mvnProject.getPackaging())) { - pomArtifact = mvnProject.getArtifact(); - } - if (pomArtifact == null) { - pomArtifact = artifactFactory.createProjectArtifact( - mvnProject.getGroupId(), mvnProject.getArtifactId(), mvnProject.getVersion()); - } - installArtifact(mvnProject.getFile(), pomArtifact); - } catch (Exception e) { - throw new MojoExecutionException("Failed to install POM: " + mvnProject, e); - } + artifacts.forEach(a -> resolvedArtifacts.put(ArtifactIdUtils.toId(a), a)); + resolvePomsForArtifacts(artifacts, resolvedArtifacts, collectRequest.getRepositories()); } /** - * Installs the dependent projects from the reactor to the local repository. The dependencies on other modules from - * the reactor must be installed or the forked IT builds will fail when using a clean repository. - * - * @param mvnProject The project whose dependent projects should be installed, must not be null. - * @param reactorProjects The set of projects in the reactor build, must not be null. - * @throws MojoExecutionException If any dependency could not be installed. + * Resolve extra artifacts. */ - private void installProjectDependencies(MavenProject mvnProject, Collection reactorProjects) - throws MojoExecutionException { - // ... into dependencies that were resolved from reactor projects ... - Collection dependencyProjects = new LinkedHashSet<>(); - collectAllProjectReferences(mvnProject, dependencyProjects); - - // index available reactor projects - Map projects = new HashMap<>(reactorProjects.size()); - for (MavenProject reactorProject : reactorProjects) { - String projectId = reactorProject.getGroupId() - + ':' - + reactorProject.getArtifactId() - + ':' - + reactorProject.getVersion(); - - projects.put(projectId, reactorProject); + private void resolveExtraArtifacts(Map resolvedArtifacts) + throws MojoExecutionException, DependencyResolutionException, ArtifactResolutionException { + + if (extraArtifacts == null) { + return; } - // group transitive dependencies (even those that don't contribute to the class path like POMs) ... - Collection artifacts = mvnProject.getArtifacts(); - // ... and those that were resolved from the (local) repo - Collection dependencyArtifacts = new LinkedHashSet<>(); + DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); - for (Artifact artifact : artifacts) { - // workaround for MNG-2961 to ensure the base version does not contain a timestamp - artifact.isSnapshot(); + for (String extraArtifact : extraArtifacts) { + String[] gav = extraArtifact.split(":"); + if (gav.length < 3 || gav.length > 5) { + throw new MojoExecutionException("Invalid artifact " + extraArtifact); + } - String projectId = artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion(); + String groupId = gav[0]; + String artifactId = gav[1]; + String version = gav[2]; - if (!projects.containsKey(projectId)) { - dependencyArtifacts.add(artifact); + String type = "jar"; + if (gav.length > 3) { + type = gav[3]; } - } - // install dependencies - try { - // copy dependencies that where resolved from the local repo - for (Artifact artifact : dependencyArtifacts) { - copyArtifact(artifact); + String classifier = null; + if (gav.length == 5) { + classifier = gav[4]; } - // install dependencies that were resolved from the reactor - for (String projectId : dependencyProjects) { - MavenProject dependencyProject = projects.get(projectId); - if (dependencyProject == null) { - getLog().warn("skip dependencyProject null for projectId=" + projectId); - continue; - } - installProjectArtifacts(dependencyProject); - installProjectParents(dependencyProject); - } - } catch (Exception e) { - throw new MojoExecutionException("Failed to install project dependencies: " + mvnProject, e); - } - } + ArtifactType artifactType = + session.getRepositorySession().getArtifactTypeRegistry().get(type); - protected void collectAllProjectReferences(MavenProject project, Collection dependencyProjects) { - for (MavenProject reactorProject : project.getProjectReferences().values()) { - String projectId = reactorProject.getGroupId() - + ':' - + reactorProject.getArtifactId() - + ':' - + reactorProject.getVersion(); - if (dependencyProjects.add(projectId)) { - collectAllProjectReferences(reactorProject, dependencyProjects); - } - } - } + List remoteRepositories = + artifactType != null && "maven-plugin".equals(artifactType.getId()) + ? project.getRemotePluginRepositories() + : project.getRemoteProjectRepositories(); - private void copyArtifact(Artifact artifact) throws MojoExecutionException { - copyPoms(artifact); + Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, null, version, artifactType); - Artifact depArtifact = artifactFactory.createArtifactWithClassifier( - artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getBaseVersion(), - artifact.getType(), - artifact.getClassifier()); + resolvePomsForArtifacts(Collections.singletonList(artifact), resolvedArtifacts, remoteRepositories); - File artifactFile = artifact.getFile(); + CollectRequest collectRequest = new CollectRequest(); + Dependency root = new Dependency(artifact, JavaScopes.COMPILE); + collectRequest.setRoot(root); + collectRequest.setRepositories(remoteRepositories); - copyArtifact(artifactFile, depArtifact); - } + DependencyRequest request = new DependencyRequest(collectRequest, classpathFilter); + DependencyResult dependencyResult = + repositorySystem.resolveDependencies(session.getRepositorySession(), request); - private void copyPoms(Artifact artifact) throws MojoExecutionException { - Artifact pomArtifact = artifactFactory.createProjectArtifact( - artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); + List artifacts = dependencyResult.getArtifactResults().stream() + .map(ArtifactResult::getArtifact) + .collect(Collectors.toList()); - File pomFile = new File(localRepository.getBasedir(), localRepository.pathOf(pomArtifact)); + artifacts.forEach(a -> resolvedArtifacts.put(ArtifactIdUtils.toId(a), a)); + resolvePomsForArtifacts(artifacts, resolvedArtifacts, collectRequest.getRepositories()); + } + } + + private void resolvePomsForArtifacts( + List artifacts, + Map resolvedArtifacts, + List remoteRepositories) + throws ArtifactResolutionException, MojoExecutionException { - if (pomFile.isFile()) { - copyArtifact(pomFile, pomArtifact); - copyParentPoms(pomFile); + for (Artifact a : artifacts) { + Artifact artifactResult = resolveArtifact(new SubArtifact(a, "", "pom"), remoteRepositories); + resolvePomWithParents(artifactResult, resolvedArtifacts, remoteRepositories); } } - /** - * Installs all parent POMs of the specified POM file that are available in the local repository. - * - * @param pomFile The path to the POM file whose parents should be installed, must not be null. - * @throws MojoExecutionException If any (existing) parent POM could not be installed. - */ - private void copyParentPoms(File pomFile) throws MojoExecutionException { - Model model = PomUtils.loadPom(pomFile); + private void resolvePomWithParents( + Artifact artifact, Map resolvedArtifacts, List remoteRepositories) + throws MojoExecutionException, ArtifactResolutionException { + + if (resolvedArtifacts.containsKey(ArtifactIdUtils.toId(artifact))) { + return; + } + + Model model = PomUtils.loadPom(artifact.getFile()); Parent parent = model.getParent(); if (parent != null) { - copyParentPoms(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); + DefaultArtifact pom = + new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "", "pom", parent.getVersion()); + Artifact resolvedPom = resolveArtifact(pom, remoteRepositories); + resolvePomWithParents(resolvedPom, resolvedArtifacts, remoteRepositories); } + + resolvedArtifacts.put(ArtifactIdUtils.toId(artifact), artifact); + } + + private Artifact resolveArtifact(Artifact artifact, List remoteRepositories) + throws ArtifactResolutionException { + + ArtifactRequest request = new ArtifactRequest(); + request.setArtifact(artifact); + request.setRepositories(remoteRepositories); + ArtifactResult artifactResult = repositorySystem.resolveArtifact(session.getRepositorySession(), request); + return artifactResult.getArtifact(); } /** - * Installs the specified POM and all its parent POMs to the local repository. - * - * @param groupId The group id of the POM which should be installed, must not be null. - * @param artifactId The artifact id of the POM which should be installed, must not be null. - * @param version The version of the POM which should be installed, must not be null. - * @throws MojoExecutionException If any (existing) parent POM could not be installed. + * Install list of artifacts into local repository. */ - private void copyParentPoms(String groupId, String artifactId, String version) throws MojoExecutionException { - Artifact pomArtifact = artifactFactory.createProjectArtifact(groupId, artifactId, version); + private void installArtifacts(Map resolvedArtifacts) throws InstallationException { - if (installedArtifacts.contains(pomArtifact.getId()) || copiedArtifacts.contains(pomArtifact.getId())) { - getLog().debug("Not re-installing " + pomArtifact); - return; - } + RepositorySystemSession systemSessionForLocalRepo = createSystemSessionForLocalRepo(); - File pomFile = new File(localRepository.getBasedir(), localRepository.pathOf(pomArtifact)); - if (pomFile.isFile()) { - copyArtifact(pomFile, pomArtifact); - copyParentPoms(pomFile); - } - } + // we can have on dependency two artifacts with the same groupId:artifactId + // with different version, in such case when we install both in one request + // metadata will contain only one version - private void installExtraArtifacts(String[] extraArtifacts) throws MojoExecutionException { - if (extraArtifacts == null) { - return; + Map> collect = resolvedArtifacts.values().stream() + .filter(a -> !hasTheSamePathAsTarget(a, systemSessionForLocalRepo)) + .collect(Collectors.groupingBy( + a -> String.format("%s:%s:%s", a.getGroupId(), a.getArtifactId(), a.getVersion()), + LinkedHashMap::new, + Collectors.toList())); + + for (List artifacts : collect.values()) { + InstallRequest request = new InstallRequest(); + request.setArtifacts(artifacts); + repositorySystem.install(systemSessionForLocalRepo, request); } + } - for (String extraArtifact : extraArtifacts) { - String[] gav = extraArtifact.split(":"); - if (gav.length < 3 || gav.length > 5) { - throw new MojoExecutionException("Invalid artifact " + extraArtifact); + private boolean hasTheSamePathAsTarget(Artifact artifact, RepositorySystemSession systemSession) { + try { + LocalRepositoryManager lrm = systemSession.getLocalRepositoryManager(); + File targetBasedir = lrm.getRepository().getBasedir(); + if (targetBasedir == null) { + return false; } - - String groupId = gav[0]; - String artifactId = gav[1]; - String version = gav[2]; - - String type = "jar"; - if (gav.length > 3) { - type = gav[3]; + File targetFile = new File(targetBasedir, lrm.getPathForLocalArtifact(artifact)).getCanonicalFile(); + File sourceFile = artifact.getFile().getCanonicalFile(); + if (Objects.equals(targetFile, sourceFile)) { + getLog().debug("Skip install the same target " + sourceFile); + return true; } + return false; + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } - String classifier = null; - if (gav.length == 5) { - classifier = gav[4]; + /** + * Create a new {@link RepositorySystemSession} connected with local repo. + */ + private RepositorySystemSession createSystemSessionForLocalRepo() { + RepositorySystemSession repositorySystemSession = session.getRepositorySession(); + if (localRepositoryPath != null) { + // "clone" repository session and replace localRepository + DefaultRepositorySystemSession newSession = + new DefaultRepositorySystemSession(session.getRepositorySession()); + // Clear cache, since we're using a new local repository + newSession.setCache(new DefaultRepositoryCache()); + // keep same repositoryType + String contentType = newSession.getLocalRepository().getContentType(); + if ("enhanced".equals(contentType)) { + contentType = "default"; } + LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( + newSession, new LocalRepository(localRepositoryPath, contentType)); - DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate(); - try { - coordinate.setGroupId(groupId); - coordinate.setArtifactId(artifactId); - coordinate.setVersion(version); - coordinate.setType(type); - coordinate.setClassifier(classifier); - - if (!localRepository.getBasedir().equals(localRepositoryPath.getPath()) && useLocalRepository) { - String previousId = localRepository.getId(); - try { - // using another request with the correct target repo - ProjectBuildingRequest projectBuildingRequest = repositoryManager.setLocalRepositoryBasedir( - session.getProjectBuildingRequest(), localRepositoryPath); - projectBuildingRequest.setRemoteRepositories(Collections.singletonList(localRepository)); - resolver.resolveDependencies( - projectBuildingRequest, - coordinate, - new PatternExclusionsFilter(Collections.emptyList())); - } finally { - localRepository.setId(previousId); - } - } else { - resolver.resolveDependencies( - projectBuildingRequest, coordinate, new PatternExclusionsFilter(Collections.emptyList())); - } - } catch (DependencyResolverException e) { - throw new MojoExecutionException("Unable to resolve dependencies for: " + coordinate, e); - } + newSession.setLocalRepositoryManager(localRepositoryManager); + repositorySystemSession = newSession; + getLog().debug("localRepoPath: " + + localRepositoryManager.getRepository().getBasedir()); } + + return repositorySystemSession; } } diff --git a/src/main/java/org/apache/maven/plugins/invoker/InterpolatorUtils.java b/src/main/java/org/apache/maven/plugins/invoker/InterpolatorUtils.java new file mode 100644 index 00000000..a4804b9b --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/invoker/InterpolatorUtils.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.invoker; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.interpolation.Interpolator; +import org.codehaus.plexus.interpolation.MapBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; + +/** + * Helper component for interpolating values. + */ +@Named +class InterpolatorUtils { + + private final Interpolator atInterpolator; + + /** + * A default constructor. + * + * @param mavenProject a MavenProject + */ + @Inject + InterpolatorUtils(MavenProject mavenProject) { + atInterpolator = new RegexBasedInterpolator("[@\\$]\\{(.+?)", "}"); + atInterpolator.addValueSource(new MapBasedValueSource(mavenProject.getProperties())); + } + + public String interpolateAtPattern(String value) throws MojoExecutionException { + + if (value == null || !(value.contains("@{") || value.contains("${"))) { + return value; + } + + try { + return atInterpolator.interpolate(value); + } catch (InterpolationException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } +} diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java index 08721a0f..4bf09e71 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java @@ -32,7 +32,8 @@ import java.util.regex.Pattern; import org.apache.maven.shared.invoker.InvocationRequest; -import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides a convenient facade around the invoker.properties. @@ -40,10 +41,13 @@ * @author Benjamin Bentmann */ class InvokerProperties { + + private final Logger logger = LoggerFactory.getLogger(InvokerProperties.class); + private static final String SELECTOR_PREFIX = "selector."; private static final Pattern ENVIRONMENT_VARIABLES_PATTERN = - Pattern.compile("invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.([0-9]+))?"); + Pattern.compile("invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.(\\d+))?"); // default values from Mojo configuration private Boolean defaultDebug; @@ -55,6 +59,7 @@ class InvokerProperties { private Map defaultEnvironmentVariables; private File defaultMavenExecutable; private Boolean defaultUpdateSnapshots; + private String defaultUserPropertiesFiles; private enum InvocationProperty { PROJECT("invoker.project"), @@ -67,6 +72,7 @@ private enum InvocationProperty { NON_RECURSIVE("invoker.nonRecursive"), OFFLINE("invoker.offline"), SYSTEM_PROPERTIES_FILE("invoker.systemPropertiesFile"), + USER_PROPERTIES_FILE("invoker.userPropertiesFile"), DEBUG("invoker.debug"), QUIET("invoker.quiet"), SETTINGS_FILE("invoker.settingsFile"), @@ -88,7 +94,7 @@ public String toString() { private enum SelectorProperty { JAVA_VERSION(".java.version"), MAVEN_VERSION(".maven.version"), - OS_FAMLY(".os.family"); + OS_FAMILY(".os.family"); private final String suffix; @@ -153,8 +159,10 @@ public void setDefaultProfiles(List defaultProfiles) { * Default value for mavenExecutable * @param defaultMavenExecutable a default value */ - public void setDefaultMavenExecutable(File defaultMavenExecutable) { - this.defaultMavenExecutable = defaultMavenExecutable; + public void setDefaultMavenExecutable(String defaultMavenExecutable) { + if (Objects.nonNull(defaultMavenExecutable) && !defaultMavenExecutable.isEmpty()) { + this.defaultMavenExecutable = new File(defaultMavenExecutable); + } } /** @@ -189,6 +197,14 @@ public void setDefaultUpdateSnapshots(boolean defaultUpdateSnapshots) { this.defaultUpdateSnapshots = defaultUpdateSnapshots; } + /** + * Default value for userPropertiesFile + * @param defaultUserPropertiesFiles a default value + */ + public void setDefaultUserPropertiesFiles(String defaultUserPropertiesFiles) { + this.defaultUserPropertiesFiles = defaultUserPropertiesFiles; + } + /** * Gets the invoker properties being wrapped. * @@ -279,7 +295,7 @@ public String getOsFamily() { * @since 3.0.0 */ public String getOsFamily(int index) { - return this.properties.getProperty(SELECTOR_PREFIX + index + SelectorProperty.OS_FAMLY, getOsFamily()); + return this.properties.getProperty(SELECTOR_PREFIX + index + SelectorProperty.OS_FAMILY, getOsFamily()); } public Collection getToolchains() { @@ -395,7 +411,7 @@ public void configureInvocation(InvocationRequest request, int index) { setIfNotNull( request::setGoals, get(InvocationProperty.GOALS, index) - .map(s -> StringUtils.split(s, ", \t\n\r\f")) + .map(s -> s.trim().split("\\s*[ ,]+\\s*")) .map(Arrays::asList) .filter(l -> !l.isEmpty()) .orElse(defaultGoals)); @@ -403,7 +419,7 @@ public void configureInvocation(InvocationRequest request, int index) { setIfNotNull( request::setProfiles, get(InvocationProperty.PROFILES, index) - .map(s -> StringUtils.split(s, ", \t\n\r\f")) + .map(s -> s.trim().split("\\s*[ ,]+\\s*")) .map(Arrays::asList) .filter(l -> !l.isEmpty()) .orElse(defaultProfiles)); @@ -466,13 +482,33 @@ public boolean isExpectedResult(int exitCode, int index) { } /** - * Gets the path to the properties file used to set the system properties for the specified invocation. + * Gets the path to the properties file used to set the user properties for the specified invocation. * * @param index The index of the invocation, must not be negative. * @return The path to the properties file or null if not set. */ - public String getSystemPropertiesFile(int index) { - return get(InvocationProperty.SYSTEM_PROPERTIES_FILE, index).orElse(null); + public String getUserPropertiesFile(int index) { + Optional userProperties = get(InvocationProperty.USER_PROPERTIES_FILE, index); + Optional systemProperties = get(InvocationProperty.SYSTEM_PROPERTIES_FILE, index); + + if (userProperties.isPresent() && systemProperties.isPresent()) { + throw new IllegalArgumentException("only one property '" + InvocationProperty.USER_PROPERTIES_FILE + + "' or '" + InvocationProperty.SYSTEM_PROPERTIES_FILE + "' can be used"); + } + + if (userProperties.isPresent()) { + return userProperties.get(); + } + + if (systemProperties.isPresent()) { + logger.warn( + "property {} is deprecated - please use {}", + InvocationProperty.SYSTEM_PROPERTIES_FILE, + InvocationProperty.USER_PROPERTIES_FILE); + return systemProperties.get(); + } + + return defaultUserPropertiesFiles; } /** diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java index bd3708de..ebc47b3d 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java @@ -20,15 +20,10 @@ import java.io.File; import java.io.IOException; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.MessageFormat; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import org.apache.maven.doxia.sink.Sink; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -37,8 +32,6 @@ import org.apache.maven.reporting.AbstractMavenReport; import org.apache.maven.reporting.MavenReportException; import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.XmlStreamReader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -53,12 +46,6 @@ @Mojo(name = "report", threadSafe = true) public class InvokerReport extends AbstractMavenReport { - /** - * Internationalization component. - */ - @Component - protected I18N i18n; - /** * Base directory where all build reports have been written to. */ @@ -66,61 +53,17 @@ public class InvokerReport extends AbstractMavenReport { private File reportsDirectory; /** - * The number format used to print percent values in the report locale. - */ - private NumberFormat percentFormat; - - /** - * The number format used to print time values in the report locale. - */ - private NumberFormat secondsFormat; - - /** - * The format used to print build name and description. + * Internationalization component */ - private MessageFormat nameAndDescriptionFormat; + @Component + protected I18N i18n; protected void executeReport(Locale locale) throws MavenReportException { - DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); - percentFormat = new DecimalFormat(getText(locale, "report.invoker.format.percent"), symbols); - secondsFormat = new DecimalFormat(getText(locale, "report.invoker.format.seconds"), symbols); - nameAndDescriptionFormat = new MessageFormat(getText(locale, "report.invoker.format.name_with_description")); - - Sink sink = getSink(); - - sink.head(); - - sink.title(); - sink.text(getText(locale, "report.invoker.result.title")); - sink.title_(); - - sink.head_(); - - sink.body(); - - sink.section1(); - sink.sectionTitle1(); - sink.text(getText(locale, "report.invoker.result.title")); - sink.sectionTitle1_(); - sink.paragraph(); - sink.text(getText(locale, "report.invoker.result.description")); - sink.paragraph_(); - sink.section1_(); - - // ---------------------------------- - // build buildJob beans - // ---------------------------------- - File[] reportFiles = ReportUtils.getReportFiles(reportsDirectory); - if (reportFiles.length <= 0) { - getLog().info("no invoker report files found, skip report generation"); - return; - } - + File[] reportFiles = getReportFiles(); BuildJobXpp3Reader buildJobReader = new BuildJobXpp3Reader(); - List buildJobs = new ArrayList<>(reportFiles.length); for (File reportFile : reportFiles) { - try (XmlStreamReader xmlReader = ReaderFactory.newXmlReader(reportFile)) { + try (XmlStreamReader xmlReader = new XmlStreamReader(reportFile)) { buildJobs.add(buildJobReader.read(xmlReader)); } catch (XmlPullParserException e) { throw new MavenReportException("Failed to parse report file: " + reportFile, e); @@ -128,193 +71,39 @@ protected void executeReport(Locale locale) throws MavenReportException { throw new MavenReportException("Failed to read report file: " + reportFile, e); } } - - // ---------------------------------- - // summary - // ---------------------------------- - - constructSummarySection(buildJobs, locale); - - // ---------------------------------- - // per file/it detail - // ---------------------------------- - - sink.section2(); - sink.sectionTitle2(); - - sink.text(getText(locale, "report.invoker.detail.title")); - - sink.sectionTitle2_(); - - sink.section2_(); - - // detail tests table header - sink.table(); - sink.tableRows(null, false); - - sink.tableRow(); - // ------------------------------------------- - // name | Result | time | message - // ------------------------------------------- - sinkTableHeader(sink, getText(locale, "report.invoker.detail.name")); - sinkTableHeader(sink, getText(locale, "report.invoker.detail.result")); - sinkTableHeader(sink, getText(locale, "report.invoker.detail.time")); - sinkTableHeader(sink, getText(locale, "report.invoker.detail.message")); - - sink.tableRow_(); - - for (BuildJob buildJob : buildJobs) { - renderBuildJob(buildJob); - } - - sink.tableRows_(); - sink.table_(); - - sink.body_(); - - sink.flush(); - sink.close(); + InvokerReportRenderer r = new InvokerReportRenderer(getSink(), i18n, locale, getLog(), buildJobs); + r.render(); } - private void constructSummarySection(List buildJobs, Locale locale) { - Sink sink = getSink(); - - sink.section2(); - sink.sectionTitle2(); - - sink.text(getText(locale, "report.invoker.summary.title")); - - sink.sectionTitle2_(); - sink.section2_(); - - // ------------------------------------------------------------------------ - // Building a table with - // it number | succes nb | failed nb | Success rate | total time | avg time - // ------------------------------------------------------------------------ - - sink.table(); - sink.tableRows(null, false); - - sink.tableRow(); - - sinkTableHeader(sink, getText(locale, "report.invoker.summary.number")); - sinkTableHeader(sink, getText(locale, "report.invoker.summary.success")); - sinkTableHeader(sink, getText(locale, "report.invoker.summary.failed")); - sinkTableHeader(sink, getText(locale, "report.invoker.summary.skipped")); - sinkTableHeader(sink, getText(locale, "report.invoker.summary.success.rate")); - sinkTableHeader(sink, getText(locale, "report.invoker.summary.time.total")); - sinkTableHeader(sink, getText(locale, "report.invoker.summary.time.avg")); - - int number = buildJobs.size(); - int success = 0; - int failed = 0; - int skipped = 0; - double totalTime = 0; - - for (BuildJob buildJob : buildJobs) { - if (BuildJob.Result.SUCCESS.equals(buildJob.getResult())) { - success++; - } else if (BuildJob.Result.SKIPPED.equals(buildJob.getResult())) { - skipped++; - } else { - failed++; - } - totalTime += buildJob.getTime(); - } - - sink.tableRow_(); - sink.tableRow(); - - sinkCell(sink, Integer.toString(number)); - sinkCell(sink, Integer.toString(success)); - sinkCell(sink, Integer.toString(failed)); - sinkCell(sink, Integer.toString(skipped)); - - if (success + failed > 0) { - sinkCell(sink, percentFormat.format((double) success / (success + failed))); - } else { - sinkCell(sink, ""); - } - - sinkCell(sink, secondsFormat.format(totalTime)); - - sinkCell(sink, secondsFormat.format(totalTime / number)); - - sink.tableRow_(); - - sink.tableRows_(); - sink.table_(); - } - - private void renderBuildJob(BuildJob buildJob) { - Sink sink = getSink(); - sink.tableRow(); - sinkCell(sink, getBuildJobReportName(buildJob)); - // FIXME image - sinkCell(sink, buildJob.getResult()); - sinkCell(sink, secondsFormat.format(buildJob.getTime())); - sinkCell(sink, buildJob.getFailureMessage()); - sink.tableRow_(); - } - - private String getBuildJobReportName(BuildJob buildJob) { - String buildJobName = buildJob.getName(); - String buildJobDescription = buildJob.getDescription(); - boolean emptyJobName = StringUtils.isEmpty(buildJobName); - boolean emptyJobDescription = StringUtils.isEmpty(buildJobDescription); - boolean isReportJobNameComplete = !emptyJobName && !emptyJobDescription; - if (isReportJobNameComplete) { - return getFormattedName(buildJobName, buildJobDescription); - } else { - String buildJobProject = buildJob.getProject(); - if (!emptyJobName) { - getLog().warn(incompleteNameWarning("description", buildJobProject)); - } else if (!emptyJobDescription) { - getLog().warn(incompleteNameWarning("name", buildJobProject)); - } - return buildJobProject; - } - } - - private static String incompleteNameWarning(String missing, String pom) { - return String.format( - "Incomplete job name-description: %s is missing. " + "POM (%s) will be used in place of job name.", - missing, pom); + /** + * @param locale The locale + * @param key The key to search for + * @return The text appropriate for the locale. + */ + private String getI18nString(Locale locale, String key) { + return i18n.getString("invoker-report", locale, "report.invoker." + key); } - private String getFormattedName(String name, String description) { - return nameAndDescriptionFormat.format(new Object[] {name, description}); + /** {@inheritDoc} */ + public String getName(Locale locale) { + return getI18nString(locale, "name"); } + /** {@inheritDoc} */ public String getDescription(Locale locale) { - return getText(locale, "report.invoker.result.description"); - } - - public String getName(Locale locale) { - return getText(locale, "report.invoker.result.name"); + return getI18nString(locale, "description"); } public String getOutputName() { - return "invoker-report"; + return "invoker"; } - public boolean canGenerateReport() { - return ReportUtils.getReportFiles(reportsDirectory).length > 0; + private File[] getReportFiles() { + return ReportUtils.getReportFiles(reportsDirectory); } - private String getText(Locale locale, String key) { - return i18n.getString("invoker-report", locale, key); - } - - private void sinkTableHeader(Sink sink, String header) { - sink.tableHeaderCell(); - sink.text(header); - sink.tableHeaderCell_(); - } - - private void sinkCell(Sink sink, String text) { - sink.tableCell(); - sink.text(text); - sink.tableCell_(); + @Override + public boolean canGenerateReport() { + return getReportFiles().length > 0; } } diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java new file mode 100644 index 00000000..3958a0a2 --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.invoker; + +import java.util.List; +import java.util.Locale; + +import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.invoker.model.BuildJob; +import org.apache.maven.reporting.AbstractMavenReportRenderer; +import org.codehaus.plexus.i18n.I18N; + +public class InvokerReportRenderer extends AbstractMavenReportRenderer { + private final I18N i18n; + private final Locale locale; + private final Log log; + private final List buildJobs; + + public InvokerReportRenderer(Sink sink, I18N i18n, Locale locale, Log log, List buildJobs) { + super(sink); + this.i18n = i18n; + this.locale = locale; + this.log = log; + this.buildJobs = buildJobs; + } + + @Override + public String getTitle() { + return getI18nString("title"); + } + + /** + * @param key The key to translate. + * @return the translated key. + */ + private String getI18nString(String key) { + return i18n.getString("invoker-report", locale, "report.invoker." + key); + } + + /** + * @param key The key to translate. + * @param args The args to pass to translated string. + * @return the translated key. + */ + private String formatI18nString(String key, Object... args) { + return i18n.format("invoker-report", locale, "report.invoker." + key, args); + } + + @Override + protected void renderBody() { + startSection(getTitle()); + paragraph(getI18nString("description")); + + renderSectionSummary(); + + renderSectionDetails(); + + endSection(); + } + + private void renderSectionSummary() { + startSection(getI18nString("summary.title")); + + startTable(); + + tableHeader(new String[] { + getI18nString("summary.builds"), + getI18nString("summary.success"), + getI18nString("summary.failures"), + getI18nString("summary.skipped"), + getI18nString("summary.successrate"), + getI18nString("summary.time") + }); + + int totalBuilds = buildJobs.size(); + int totalSuccess = 0; + int totalFailures = 0; + int totalSkipped = 0; + float totalTime = 0.0f; + + for (BuildJob buildJob : buildJobs) { + switch (buildJob.getResult()) { + case BuildJob.Result.SUCCESS: + totalSuccess++; + break; + case BuildJob.Result.SKIPPED: + totalSkipped++; + break; + default: + totalFailures++; + } + totalTime += buildJob.getTime(); + } + + tableRow(new String[] { + Integer.toString(totalBuilds), + Integer.toString(totalSuccess), + Integer.toString(totalFailures), + Integer.toString(totalSkipped), + (totalSuccess + totalFailures > 0) + ? formatI18nString("value.successrate", (totalSuccess / (float) (totalSuccess + totalFailures))) + : "", + formatI18nString("value.time", totalTime) + }); + + endTable(); + + endSection(); + } + + private void renderSectionDetails() { + startSection(getI18nString("detail.title")); + + startTable(); + + tableHeader(new String[] { + getI18nString("detail.name"), + getI18nString("detail.result"), + getI18nString("detail.time"), + getI18nString("detail.message") + }); + + for (BuildJob buildJob : buildJobs) { + renderBuildJob(buildJob); + } + + endTable(); + + endSection(); + } + + private void renderBuildJob(BuildJob buildJob) { + tableRow(new String[] { + getBuildJobReportName(buildJob), + // FIXME image + buildJob.getResult(), + formatI18nString("value.time", buildJob.getTime()), + buildJob.getFailureMessage() + }); + } + + private String getBuildJobReportName(BuildJob buildJob) { + String buildJobName = buildJob.getName(); + String buildJobDescription = buildJob.getDescription(); + boolean emptyJobName = buildJobName == null || buildJobName.isEmpty(); + boolean emptyJobDescription = buildJobDescription == null || buildJobDescription.isEmpty(); + boolean isReportJobNameComplete = !emptyJobName && !emptyJobDescription; + if (isReportJobNameComplete) { + return formatI18nString("text.name_with_description", buildJobName, buildJobDescription); + } else { + String buildJobProject = buildJob.getProject(); + if (!emptyJobName) { + log.warn(incompleteNameWarning("description", buildJobProject)); + } else if (!emptyJobDescription) { + log.warn(incompleteNameWarning("name", buildJobProject)); + } + return buildJobProject; + } + } + + private static String incompleteNameWarning(String missing, String pom) { + return "Incomplete job name-description: " + missing + " is missing. POM (" + pom + + ") will be used in place of job name!"; + } +} diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java index 9f47c1eb..a6667449 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java @@ -27,7 +27,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.invoker.model.BuildJob; -import org.apache.maven.shared.utils.io.IOUtil; +import org.codehaus.plexus.util.IOUtil; import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; @@ -38,7 +38,7 @@ */ class InvokerSession { private static final String SEPARATOR = - buffer().strong("-------------------------------------------------").toString(); + buffer().strong("-------------------------------------------------").build(); private List buildJobs; diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerToolchain.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerToolchain.java index a2e879b9..c132712c 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InvokerToolchain.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerToolchain.java @@ -29,7 +29,7 @@ public class InvokerToolchain { private final String type; - private Map provides = new HashMap<>(); + private final Map provides = new HashMap<>(); public InvokerToolchain(String type) { this.type = type; diff --git a/src/main/java/org/apache/maven/plugins/invoker/JobExecutor.java b/src/main/java/org/apache/maven/plugins/invoker/JobExecutor.java index 3e2c3744..704e214a 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/JobExecutor.java +++ b/src/main/java/org/apache/maven/plugins/invoker/JobExecutor.java @@ -18,6 +18,7 @@ */ package org.apache.maven.plugins.invoker; +import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -49,7 +50,7 @@ interface ThrowableJobConsumer { public void forEach(ThrowableJobConsumer jobConsumer) { // group and sort jobs by ordinal Map> groupedJobs = jobs.stream() - .sorted((j1, j2) -> Integer.compare(j2.getOrdinal(), j1.getOrdinal())) + .sorted(Comparator.comparing(BuildJob::getOrdinal).reversed()) .collect(Collectors.groupingBy(BuildJob::getOrdinal, LinkedHashMap::new, Collectors.toList())); ExecutorService executorService = Executors.newFixedThreadPool(threadsCount); diff --git a/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java b/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java deleted file mode 100644 index 13d2c4a4..00000000 --- a/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.plugins.invoker; - -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Date; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.TimeZone; - -import org.apache.maven.artifact.Artifact; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.WriterFactory; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import org.codehaus.plexus.util.xml.Xpp3DomUtils; -import org.codehaus.plexus.util.xml.Xpp3DomWriter; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -/** - * Provides utility methods for artifact metadata processing. - * - * @author Benjamin Bentmann - */ -class MetadataUtils { - - /** - * Creates local metadata files for the specified artifact. The goal is to simulate the installation of the artifact - * by a local build, thereby decoupling the forked builds from the inderministic collection of remote repositories - * that are available to the main build and from which the artifact was originally resolved. - * - * @param file The artifact's file in the local test repository, must not be null. - * @param artifact The artifact to create metadata for, must not be null. - * @throws IOException If the metadata could not be created. - */ - public static void createMetadata(File file, Artifact artifact) throws IOException { - TimeZone tz = java.util.TimeZone.getTimeZone("UTC"); - SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); - fmt.setTimeZone(tz); - String timestamp = fmt.format(new Date()); - - if (artifact.isSnapshot()) { - File metadataFile = new File(file.getParentFile(), "maven-metadata-local.xml"); - - Xpp3Dom metadata = new Xpp3Dom("metadata"); - addChild(metadata, "groupId", artifact.getGroupId()); - addChild(metadata, "artifactId", artifact.getArtifactId()); - addChild(metadata, "version", artifact.getBaseVersion()); - Xpp3Dom versioning = new Xpp3Dom("versioning"); - versioning.addChild(addChild(new Xpp3Dom("snapshot"), "localCopy", "true")); - addChild(versioning, "lastUpdated", timestamp); - metadata.addChild(versioning); - - writeMetadata(metadataFile, metadata); - } - - File metadataFile = new File(file.getParentFile().getParentFile(), "maven-metadata-local.xml"); - - Set allVersions = new LinkedHashSet<>(); - - Xpp3Dom metadata = readMetadata(metadataFile); - - if (metadata != null) { - Xpp3Dom versioning = metadata.getChild("versioning"); - if (versioning != null) { - Xpp3Dom versions = versioning.getChild("versions"); - if (versions != null) { - - Xpp3Dom[] children = versions.getChildren("version"); - for (Xpp3Dom aChildren : children) { - allVersions.add(aChildren.getValue()); - } - } - } - } - - allVersions.add(artifact.getBaseVersion()); - - metadata = new Xpp3Dom("metadata"); - addChild(metadata, "groupId", artifact.getGroupId()); - addChild(metadata, "artifactId", artifact.getArtifactId()); - Xpp3Dom versioning = new Xpp3Dom("versioning"); - versioning.addChild(addChildren(new Xpp3Dom("versions"), "version", allVersions)); - addChild(versioning, "lastUpdated", timestamp); - metadata.addChild(versioning); - - metadata = Xpp3DomUtils.mergeXpp3Dom(metadata, readMetadata(metadataFile)); - - writeMetadata(metadataFile, metadata); - } - - private static Xpp3Dom addChild(Xpp3Dom parent, String childName, String childValue) { - Xpp3Dom child = new Xpp3Dom(childName); - child.setValue(childValue); - parent.addChild(child); - return parent; - } - - private static Xpp3Dom addChildren(Xpp3Dom parent, String childName, Collection childValues) { - for (String childValue : childValues) { - addChild(parent, childName, childValue); - } - return parent; - } - - private static Xpp3Dom readMetadata(File metadataFile) throws IOException { - if (!metadataFile.isFile()) { - return null; - } - - try (Reader reader = ReaderFactory.newXmlReader(metadataFile)) { - return Xpp3DomBuilder.build(reader); - } catch (XmlPullParserException e) { - throw new IOException(e.getMessage(), e); - } - } - - private static void writeMetadata(File metadataFile, Xpp3Dom metadata) throws IOException { - metadataFile.getParentFile().mkdirs(); - - try (Writer writer = WriterFactory.newXmlWriter(metadataFile)) { - Xpp3DomWriter.write(writer, metadata); - } - } -} diff --git a/src/main/java/org/apache/maven/plugins/invoker/PomUtils.java b/src/main/java/org/apache/maven/plugins/invoker/PomUtils.java index 17965c96..526ed7dd 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/PomUtils.java +++ b/src/main/java/org/apache/maven/plugins/invoker/PomUtils.java @@ -25,7 +25,7 @@ import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.MojoExecutionException; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlStreamReader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** @@ -43,7 +43,7 @@ class PomUtils { * @throws MojoExecutionException If the POM file could not be loaded. */ public static Model loadPom(File pomFile) throws MojoExecutionException { - try (Reader reader = ReaderFactory.newXmlReader(pomFile)) { + try (Reader reader = new XmlStreamReader(pomFile)) { return new MavenXpp3Reader().read(reader, false); } catch (XmlPullParserException e) { throw new MojoExecutionException("Failed to parse POM: " + pomFile, e); diff --git a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java index fc062603..ded4fad3 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java +++ b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Properties; import java.util.stream.Collectors; @@ -37,7 +38,6 @@ import org.apache.maven.toolchain.MisconfiguredToolchainException; import org.apache.maven.toolchain.ToolchainPrivate; import org.codehaus.plexus.util.Os; -import org.codehaus.plexus.util.StringUtils; /** * Provides utility methods for selecting build jobs based on environmental conditions. @@ -47,7 +47,11 @@ class SelectorUtils { static void parseList(String list, Collection includes, Collection excludes) { - String[] tokens = (list != null) ? StringUtils.split(list, ",") : new String[0]; + if (Objects.isNull(list)) { + return; + } + + String[] tokens = list.split(",+"); for (String token1 : tokens) { String token = token1.trim(); @@ -69,17 +73,10 @@ static boolean isOsFamily(String osSpec) { } static boolean isOsFamily(List families, boolean defaultMatch) { - if (families != null && !families.isEmpty()) { - for (String family : families) { - if (Os.isFamily(family)) { - return true; - } - } - - return false; - } else { + if (families == null || families.isEmpty()) { return defaultMatch; } + return families.stream().anyMatch(Os::isFamily); } /** @@ -99,7 +96,8 @@ static String getMavenVersion() { .getClassLoader() .getResourceAsStream("META-INF/maven/org.apache.maven/maven-core/pom.properties")); // CHECKSTYLE_ON: LineLength - return StringUtils.trim(properties.getProperty("version")); + String str = properties.getProperty("version"); + return str == null ? null : str.trim(); } catch (Exception e) { return null; } @@ -121,7 +119,8 @@ static String getMavenVersion(File mavenHome) throws IOException { try (InputStream in = url.openStream()) { Properties properties = new Properties(); properties.load(in); - String version = StringUtils.trim(properties.getProperty("version")); + String str = properties.getProperty("version"); + String version = str == null ? null : str.trim(); if (version != null) { return version; } @@ -133,10 +132,6 @@ static String getMavenVersion(File mavenHome) throws IOException { return null; } - static boolean isMavenVersion(String mavenSpec) { - return isMavenVersion(mavenSpec, getMavenVersion()); - } - static boolean isMavenVersion(String mavenSpec, String actualVersion) { List includes = new ArrayList<>(); List excludes = new ArrayList<>(); @@ -151,15 +146,6 @@ static String getJreVersion() { return System.getProperty("java.version", ""); } - static String getJreVersion(File javaHome) { - // @todo detect actual version - return null; - } - - static boolean isJreVersion(String jreSpec) { - return isJreVersion(jreSpec, getJreVersion()); - } - static boolean isJreVersion(String jreSpec, String actualJreVersion) { List includes = new ArrayList<>(); List excludes = new ArrayList<>(); @@ -170,44 +156,39 @@ static boolean isJreVersion(String jreSpec, String actualJreVersion) { return isJreVersion(jreVersion, includes, true) && !isJreVersion(jreVersion, excludes, false); } - static boolean isJreVersion(List jreVersion, List versionPatterns, boolean defaultMatch) { - if (versionPatterns != null && !versionPatterns.isEmpty()) { - for (String versionPattern : versionPatterns) { - if (isJreVersion(jreVersion, versionPattern)) { - return true; - } - } - - return false; - } else { + static boolean isJreVersion(List jreVersions, List versionPatterns, boolean defaultMatch) { + if (versionPatterns == null || versionPatterns.isEmpty()) { return defaultMatch; } + + return versionPatterns.stream().anyMatch(versionPattern -> isJreVersion(jreVersions, versionPattern)); } - static boolean isJreVersion(List jreVersion, String versionPattern) { + static boolean isJreVersion(List jreVersions, String versionPattern) { List checkVersion = parseVersion(versionPattern); if (versionPattern.endsWith("+")) { // 1.5+ <=> [1.5,) - return compareVersions(jreVersion, checkVersion) >= 0; + return compareVersions(jreVersions, checkVersion) >= 0; } else if (versionPattern.endsWith("-")) { // 1.5- <=> (,1.5) - return compareVersions(jreVersion, checkVersion) < 0; + return compareVersions(jreVersions, checkVersion) < 0; } else { // 1.5 <=> [1.5,1.6) - return checkVersion.size() <= jreVersion.size() - && checkVersion.equals(jreVersion.subList(0, checkVersion.size())); + return checkVersion.size() <= jreVersions.size() + && checkVersion.equals(jreVersions.subList(0, checkVersion.size())); } } static List parseVersion(String version) { - version = version.replaceAll("[^0-9]", "."); - - String[] tokens = StringUtils.split(version, "."); + version = version.replaceAll("\\D", "."); - List numbers = Arrays.stream(tokens).map(Integer::valueOf).collect(Collectors.toList()); + String[] tokens = version.split("\\s*\\.+\\s*"); - return numbers; + return Arrays.stream(tokens) + .filter(s -> !s.isEmpty()) + .map(Integer::valueOf) + .collect(Collectors.toList()); } static int compareVersions(List version1, List version2) { diff --git a/src/main/java/org/apache/maven/plugins/invoker/VerifyMojo.java b/src/main/java/org/apache/maven/plugins/invoker/VerifyMojo.java index 9bd6d823..b3a21cb0 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/VerifyMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/VerifyMojo.java @@ -29,7 +29,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlStreamReader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** @@ -117,7 +117,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { InvokerSession invokerSession = new InvokerSession(); for (File reportFile : reportFiles) { - try (Reader xmlReader = ReaderFactory.newXmlReader(reportFile)) { + try (Reader xmlReader = new XmlStreamReader(reportFile)) { invokerSession.addJob(reader.read(xmlReader)); } catch (XmlPullParserException e) { throw new MojoExecutionException("Failed to parse report file: " + reportFile, e); diff --git a/src/main/mdo/invocation.mdo b/src/main/mdo/invocation.mdo index 6529e7c6..f4af4252 100644 --- a/src/main/mdo/invocation.mdo +++ b/src/main/mdo/invocation.mdo @@ -86,7 +86,7 @@ under the License. time 1.0.0 true - double + float The number of seconds that this build job took to complete. @@ -126,7 +126,7 @@ under the License. /** * Creates a new build job with the specified project path. - * + * * @param project The path to the project. */ public BuildJob( String project ) diff --git a/src/main/resources/invoker-report.properties b/src/main/resources/invoker-report.properties index 5fe569d2..9753d833 100644 --- a/src/main/resources/invoker-report.properties +++ b/src/main/resources/invoker-report.properties @@ -15,22 +15,25 @@ # specific language governing permissions and limitations # under the License. -report.invoker.result.description = The results of the Maven invocations. -report.invoker.result.name = Invoker Build Results -report.invoker.result.title = Invoker Report -report.invoker.summary.title = Summary -report.invoker.summary.number = Builds -report.invoker.summary.success = Success -report.invoker.summary.failed = Failures -report.invoker.summary.skipped = Skipped -report.invoker.summary.success.rate = Success Rate -report.invoker.summary.time.total = Total Time -report.invoker.summary.time.avg = Avg Time -report.invoker.detail.title = Build Details -report.invoker.detail.name = Name -report.invoker.detail.result = Result -report.invoker.detail.time = Time -report.invoker.detail.message = Message -report.invoker.format.percent = 0.0% -report.invoker.format.seconds = 0.0\u00A0s -report.invoker.format.name_with_description = {0}: {1} +report.invoker.name=Invoker +report.invoker.description=Report on the build results of the Maven invocations. +report.invoker.title=Invoker Report +report.invoker.summary.title=Summary +report.invoker.summary.builds=Builds +report.invoker.summary.success=Success +report.invoker.summary.failures=Failures +report.invoker.summary.skipped=Skipped +report.invoker.summary.successrate=Success Rate +report.invoker.summary.time=Time +report.invoker.detail.title=Build Details +report.invoker.detail.name=Name +report.invoker.detail.result=Result +report.invoker.detail.time=Time +report.invoker.detail.message=Message +report.invoker.value.successrate={0,choice,0#0%|0.0<{0,number,0.0%}|1#{0,number,0%}} +# Rationale: The idea is to always display four digits for visually consistent output +# Important: +# * Keep in sync with org.apache.maven.plugins.invoker.AbstractInvokerMojo +# * Needs to be copied into other bundles only if non-Latin script is used +report.invoker.value.time={0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s +report.invoker.text.name_with_description={0}: {1} diff --git a/src/main/resources/invoker-report_de.properties b/src/main/resources/invoker-report_de.properties index d1016e30..ed617c34 100644 --- a/src/main/resources/invoker-report_de.properties +++ b/src/main/resources/invoker-report_de.properties @@ -15,21 +15,18 @@ # specific language governing permissions and limitations # under the License. -report.invoker.result.description = Die Ergebnisse der Maven-Ausf\u00FChrungen. -report.invoker.result.name = Invoker-Build-Ergebnisse -report.invoker.result.title = Invoker-Bericht -report.invoker.summary.title = Zusammenfassungen -report.invoker.summary.number = Builds -report.invoker.summary.success = Erfolge -report.invoker.summary.failed = Fehlschl\u00E4ge -report.invoker.summary.skipped = Ausgelassen -report.invoker.summary.success.rate = Erfolgsrate -report.invoker.summary.time.total = Gesamtzeit -report.invoker.summary.time.avg = Durchschnittszeit -report.invoker.detail.title = Build-Details -report.invoker.detail.name = Name -report.invoker.detail.result = Ergebnis -report.invoker.detail.time = Zeit -report.invoker.detail.message = Meldung -report.invoker.format.percent = 0.0\u00A0% -report.invoker.format.seconds = 0.0\u00A0s +report.invoker.description=Bericht \u00FCber die Build-Ergebnisse der Maven-Ausf\u00FChrungen. +report.invoker.title=Invoker-Bericht +report.invoker.summary.title=Zusammenfassung +report.invoker.summary.builds=Builds +report.invoker.summary.success=Erfolge +report.invoker.summary.failures=Fehlschl\u00E4ge +report.invoker.summary.skipped=Ausgelassen +report.invoker.summary.successrate=Erfolgsrate +report.invoker.summary.time=Zeit +report.invoker.detail.title=Build-Details +report.invoker.detail.name=Name +report.invoker.detail.result=Ergebnis +report.invoker.detail.time=Zeit +report.invoker.detail.message=Meldung +report.invoker.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}} diff --git a/src/main/resources/invoker-report_fr.properties b/src/main/resources/invoker-report_fr.properties index 1d3393ab..75b52756 100644 --- a/src/main/resources/invoker-report_fr.properties +++ b/src/main/resources/invoker-report_fr.properties @@ -15,22 +15,19 @@ # specific language governing permissions and limitations # under the License. -report.invoker.result.description = Résultat des invocations de Maven -report.invoker.result.name = Invoker Résultat de builds -report.invoker.result.title = Invoker Rapport -report.invoker.summary.title = Sommaire -report.invoker.summary.number = Builds -report.invoker.summary.success = Réussis -report.invoker.summary.failed = Echecs -report.invoker.summary.skipped = Ignorés -report.invoker.summary.success.rate = Taux de réussite -report.invoker.summary.time.total = Durée totale -report.invoker.summary.time.avg = Durée moyenne -report.invoker.detail.title = Détails de Build -report.invoker.detail.name = Nom -report.invoker.detail.result = Résultat -report.invoker.detail.time = Durée -report.invoker.detail.message = Message -report.invoker.format.percent = 0.0% -report.invoker.format.seconds = 0.0\u00A0s -report.invoker.format.name_with_description = {0} : {1} +report.invoker.description=Résultat des invocations de Maven +report.invoker.title=Invoker Rapport +report.invoker.summary.title=Sommaire +report.invoker.summary.builds=Builds +report.invoker.summary.success=Réussis +report.invoker.summary.failures=Echecs +report.invoker.summary.skipped=Ignorés +report.invoker.summary.successrate=Taux de réussite +report.invoker.summary.time=Durée +report.invoker.detail.title=Détails de Build +report.invoker.detail.name=Nom +report.invoker.detail.result=Résultat +report.invoker.detail.time=Durée +report.invoker.detail.message=Message +report.invoker.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}} +report.invoker.text.name_with_description={0} : {1} diff --git a/src/site/apt/examples/post-build-script.apt.vm b/src/site/apt/examples/post-build-script.apt.vm deleted file mode 100644 index 93c15a8c..00000000 --- a/src/site/apt/examples/post-build-script.apt.vm +++ /dev/null @@ -1,97 +0,0 @@ - ------ - Using a Post-Build Script - ------ - Paul Gier - ------ - 2008-08-02 - ------ - - ~~ Licensed to the Apache Software Foundation (ASF) under one - ~~ or more contributor license agreements. See the NOTICE file - ~~ distributed with this work for additional information - ~~ regarding copyright ownership. The ASF licenses this file - ~~ to you under the Apache License, Version 2.0 (the - ~~ "License"); you may not use this file except in compliance - ~~ with the License. You may obtain a copy of the License at - ~~ - ~~ http://www.apache.org/licenses/LICENSE-2.0 - ~~ - ~~ Unless required by applicable law or agreed to in writing, - ~~ software distributed under the License is distributed on an - ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~~ KIND, either express or implied. See the License for the - ~~ specific language governing permissions and limitations - ~~ under the License. - - ~~ NOTE: For help with the syntax of this file, see: - ~~ http://maven.apache.org/doxia/references/apt-format.html - -Using a Post-Build Script - - Here is an example of how the Invoker Plugin can be used to run a set of Maven projects and then verify their output - with a {{{http://www.beanshell.org/}BeanShell}} or {{{http://groovy-lang.org/}Groovy}} script. The name of the - script file in this case is <<>>. - -+------------------ - - - - - maven-invoker-plugin - ${project.version} - - true - src/it - setup.bsh - verify.bsh - - - - integration-test - - run - - - - - - - -+------------------ - - Below is an example post-build BeanShell script (<<>>) that checks for the existence of a JAR file after - the build has run. If the JAR file does not exist, the script throws an exception which causes the Invoker Plugin to - log that the build failed. More precisely, any non-null return value which does not equal <<>> will be interpreted - as a failure condition. And of course, if the script exits abnormally due to an exception, the plugin will flag the - corresponding build as a failure, too. - -+------------------ -import java.io.*; - -File file = new File( basedir, "target/my-test-project-1.0-SNAPSHOT.jar" ); -if ( !file.isFile() ) -{ - throw new FileNotFoundException( "Could not find generated JAR: " + file ); -} -+------------------ - - Complementary to the post-build hook script, you can also create a pre-build hook script that will be run before - the invocation of Maven. This can be used to do some preparations for the build. - - To allow the scripts to access some useful data about the test project, the following global variables will be - defined by the Invoker Plugin before running the script: - -*--------------------------+----------------------+-----------------------------------------------------------+--------+ -|| Name || Type || Description || Since | -*--------------------------+----------------------+-----------------------------------------------------------+--------+ -| <<>> | <<>> | The absolute path to the base directory of the test project. | 1.0 | -*--------------------------+----------------------+-----------------------------------------------------------+--------+ -| <<>>| <<>> | The absolute path to the local repository used for the Maven invocation on the test project. | 1.3 | -*--------------------------+----------------------+-----------------------------------------------------------+--------+ -| <<>> | <<>> | The storage of key-value pairs used to pass data from the pre-build hook script to the post-build hook script. | 1.4 | -*--------------------------+----------------------+-----------------------------------------------------------+--------+ -| <<>> | <<>> | The version of Maven executing on the test project. | 1.9 | -*--------------------------+----------------------+-----------------------------------------------------------+--------+ - - Additional variables that can be accessed in the hook scripts can be defined through the - <<<{{{../run-mojo.html#scriptVariables}scriptVariables}}>>> parameter in the Invoker Plugin's configuration. \ No newline at end of file diff --git a/src/site/apt/examples/pre-post-build-script.apt.vm b/src/site/apt/examples/pre-post-build-script.apt.vm new file mode 100644 index 00000000..8a8e0948 --- /dev/null +++ b/src/site/apt/examples/pre-post-build-script.apt.vm @@ -0,0 +1,151 @@ + ------ + Using Pre and Post Build Script + ------ + Paul Gier + ------ + 2008-08-02 + ------ + + ~~ Licensed to the Apache Software Foundation (ASF) under one + ~~ or more contributor license agreements. See the NOTICE file + ~~ distributed with this work for additional information + ~~ regarding copyright ownership. The ASF licenses this file + ~~ to you under the Apache License, Version 2.0 (the + ~~ "License"); you may not use this file except in compliance + ~~ with the License. You may obtain a copy of the License at + ~~ + ~~ http://www.apache.org/licenses/LICENSE-2.0 + ~~ + ~~ Unless required by applicable law or agreed to in writing, + ~~ software distributed under the License is distributed on an + ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~~ KIND, either express or implied. See the License for the + ~~ specific language governing permissions and limitations + ~~ under the License. + + ~~ NOTE: For help with the syntax of this file, see: + ~~ http://maven.apache.org/doxia/references/apt-format.html + +Using a Pre-Build Script + + Complementary to the post-build hook script, you can also create a pre-build hook script that will be run before + the invocation of Maven. This can be used to do some preparations for the build. + + Default name of Pre-Build script is <<>>, you can use name <<>> or <<>> + according to chosen script language. + + In Pre-Build scripts you can prepare a test resources for your project. + + You can also define a user properties which will be added to executed test project by <<<-D>>> Maven argument. + + Here is an example of groovy script: + ++------------------ +def userProperties = context.get('userProperties') + +def server = new MockServer() +userProperties.put('serverHost', server.getHost()) +userProperties.put('serverPort', server.getPort()) ++------------------ + + Now you can use it in test project: + ++------------------ + + + + + org.example + my-maven-plugin + @project.version@ + + ${serverHost}:${serverPort} + + + .... + + + + + ++------------------ + +Using a Post-Build Script + + Here is an example of how the Invoker Plugin can be used to run a set of Maven projects and then verify their output + with a {{{https://beanshell.github.io/}BeanShell}} or {{{https://groovy-lang.org/}Groovy}} script. The name of the + script file in this case is <<>> - default value is <<>>. + ++------------------ + + + + + maven-invoker-plugin + ${project.version} + + true + src/it + setup + verify + + + + integration-test + + run + + + + + + + ++------------------ + + Below is an example post-build BeanShell script (<<>>) that checks for the existence of a JAR file after + the build has run. If the JAR file does not exist, the script throws an exception which causes the Invoker Plugin to + log that the build failed. More precisely, any non-null return value which does not equal <<>> will be interpreted + as a failure condition. And of course, if the script exits abnormally due to an exception, the plugin will flag the + corresponding build as a failure, too. + + Example <<>> + ++------------------ +import java.io.*; + +File file = new File( basedir, "target/my-test-project-1.0-SNAPSHOT.jar" ); +if ( !file.isFile() ) +{ + throw new FileNotFoundException( "Could not find generated JAR: " + file ); +} ++------------------ + + and similar <<>> + ++------------------ +def file = new File( basedir, "target/my-test-project-1.0-SNAPSHOT.jar" ) +assert file.isFile() ++------------------ + +Predefined global variables + + To allow the scripts to access some useful data about the test project, the following global variables will be + defined by the Invoker Plugin before running the script: + +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ +|| Name || Type || Description || Since | +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ +| <<>> | <<>> | The absolute path to the base directory of the test project. | 1.0 | +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ +| <<>> | <<>> | The absolute path to the local repository used for the Maven invocation on the test project. | 1.3 | +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ +| <<>> | <<>> | The storage of key-value pairs used to pass data from the pre-build hook script to the post-build hook script. | 1.4 | +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ +| <<>> | <<>> | The user properties for executing project | 3.7.0 | +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ +| <<>> | <<>> | The version of Maven executing on the test project. | 1.9 | +*-------------------------------------+----------------------------+-----------------------------------------------------------+--------+ + + Additional variables that can be accessed in the hook scripts can be defined through the + <<<{{{../run-mojo.html#scriptVariables}scriptVariables}}>>> parameter in the Invoker Plugin's configuration. diff --git a/src/site/apt/examples/selector-scripts.apt.vm b/src/site/apt/examples/selector-scripts.apt.vm index 43072dfe..806a2223 100644 --- a/src/site/apt/examples/selector-scripts.apt.vm +++ b/src/site/apt/examples/selector-scripts.apt.vm @@ -85,4 +85,7 @@ Selector Scripts If the script returns any value other than <<>>, then the project will not be executed. If the script throws an exception, then the project will be marked as being in ERROR. - + +Predefined global variables + + In Selector Scripts the same global variables are defined as in {{{./pre-post-build-script.html#predefined-global-variables}Pre and Post Build Script}} diff --git a/src/site/apt/groovy-version.apt.vm b/src/site/apt/groovy-version.apt.vm index bc1d17f9..959886c6 100644 --- a/src/site/apt/groovy-version.apt.vm +++ b/src/site/apt/groovy-version.apt.vm @@ -33,11 +33,11 @@ Groovy version and extensions Plugin <<>> in version <<<3.4.0>>> has only dependency on <<>> core add common extensions: - * <<>> + * <<>> - * <<>> + * <<>> - * <<>> + * <<>> [] @@ -56,7 +56,7 @@ Groovy version and extensions org.apache.groovy groovy-yaml - 3.0.10 + ${groovyVersion} diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm index 4ffeda1d..bcb7e576 100644 --- a/src/site/apt/index.apt.vm +++ b/src/site/apt/index.apt.vm @@ -34,6 +34,20 @@ ${project.name} This plugin is in particular handy to perform integration tests for other Maven plugins. The Invoker Plugin can be employed to run a set of test projects that have been designed to assert certain features of the plugin under test. +* Upcoming Incompatibility Notice + + With a future (minor) the report output filename will change for alignment with other + reporting plugins from <<>>. + To make you aware of that, see the following table for the upcoming changes: + +*---------------------*----------------------*------------------* +|| Mojo Class Name || Output name || New Output Name | +*---------------------+----------------------+------------------+ +| <<>> | <<>> | <<>> | +*---------------------+----------------------+------------------+ + + Details about this change can be found in {{{https://issues.apache.org/jira/browse/MINVOKER-346}MINVOKER-346}}. + * Goals Overview The plugin has four goals meant to participate in the default build lifecycle: @@ -84,7 +98,7 @@ ${project.name} * {{{./examples/install-artifacts.html}Install}} projects artifacts to a local repository before running. - * {{{./examples/post-build-script.html}Run a BeanShell or Groovy script}} to verify project output. + * {{{./examples/pre-post-build-script.html}Run a BeanShell or Groovy script}} to prepare or verify project. * {{{./examples/fast-use.html}Fast Invoker Plugin configuration}} to accelerate project execution. @@ -98,7 +112,7 @@ ${project.name} * {{{./examples/prepare-build-env.html}Prepare the Build Environment}} by building some setup projects before other projects. - * {{{./examples/integration-test-verify.html}Using with other integration test frameworks}} by decoupling checking + * {{{./examples/integration-test-verify.html}Using with other integration test frameworks}} by decoupling checking the results of the integration tests from executing the integration tests. [] diff --git a/src/site/apt/usage.apt.vm b/src/site/apt/usage.apt.vm index 8269569f..7562d05c 100644 --- a/src/site/apt/usage.apt.vm +++ b/src/site/apt/usage.apt.vm @@ -122,7 +122,7 @@ Usage When an integration test has finished, the plugin will invoke an optional post build hook script. In the example, this is the case for <<>> where <<>> will be run. The purpose of this script is usually to check that the build of the integration test did not only succeed but also produced the intended output. Have a look - at the example {{{./examples/post-build-script.html}Using a Post Build Script}} for a code snippet. + at the example {{{./examples/pre-post-build-script.html}Using Pre and Post Build Script}} for a code snippet. * Running Only Some Tests diff --git a/src/site/site.xml b/src/site/site.xml index 1b34bc66..89bcd9ef 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -19,8 +19,8 @@ specific language governing permissions and limitations under the License. --> - +

@@ -48,7 +48,7 @@ under the License. - + @@ -56,4 +56,4 @@ under the License. - + diff --git a/src/test/java/org/apache/maven/plugins/invoker/ExtendedMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/invoker/AbstractTestUtil.java similarity index 59% rename from src/test/java/org/apache/maven/plugins/invoker/ExtendedMavenProjectStub.java rename to src/test/java/org/apache/maven/plugins/invoker/AbstractTestUtil.java index b8e5f9d7..2a2f791e 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/ExtendedMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/invoker/AbstractTestUtil.java @@ -18,33 +18,18 @@ */ package org.apache.maven.plugins.invoker; -import java.util.Properties; +import java.io.File; -import org.apache.maven.model.Scm; -import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.codehaus.plexus.util.ReflectionUtils; -/** - * @author Olivier Lamy - * @since 22 nov. 07 - */ -public class ExtendedMavenProjectStub extends MavenProjectStub { - private Scm scm; - - private Properties properties; - - public Scm getScm() { - return scm; - } - - public void setScm(Scm scm) { - this.scm = scm; - } +abstract class AbstractTestUtil { - public Properties getProperties() { - return properties; + protected String getBasedir() { + String path = System.getProperty("basedir"); + return path != null ? path : new File("").getAbsolutePath(); } - public void setProperties(Properties properties) { - this.properties = properties; + protected void setVariableValueToObject(Object object, String filed, Object value) throws IllegalAccessException { + ReflectionUtils.setVariableValueInObject(object, filed, value); } } diff --git a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java index 637845d2..83850119 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java @@ -20,80 +20,80 @@ import java.io.File; import java.io.Reader; +import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.apache.maven.model.Scm; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlStreamReader; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Olivier Lamy * @since 22 nov. 07 */ -public class InterpolationTest extends AbstractMojoTestCase { +class InterpolationTest extends AbstractTestUtil { - protected MavenProjectStub buildMavenProjectStub() { - ExtendedMavenProjectStub project = new ExtendedMavenProjectStub(); + private MavenProject buildMavenProjectStub() { + MavenProject project = new MavenProject(); project.setVersion("1.0-SNAPSHOT"); project.setArtifactId("foo"); project.setGroupId("bar"); + project.setFile(new File(getBasedir(), "pom.xml")); Properties properties = new Properties(); properties.put("fooOnProject", "barOnProject"); - project.setProperties(properties); + project.getModel().setProperties(properties); Scm scm = new Scm(); scm.setConnection("http://blabla"); project.setScm(scm); return project; } - public void testCompositeMap() { + @Test + void testCompositeMap() { - Properties properties = new Properties(); + Map properties = new HashMap<>(); properties.put("foo", "bar"); properties.put("version", "2.0-SNAPSHOT"); - CompositeMap compositeMap = new CompositeMap(buildMavenProjectStub(), (Map) properties, false); - assertEquals("1.0-SNAPSHOT", compositeMap.get("pom.version")); - assertEquals("bar", compositeMap.get("foo")); - assertEquals("bar", compositeMap.get("pom.groupId")); - assertEquals("http://blabla", compositeMap.get("pom.scm.connection")); - assertEquals("barOnProject", compositeMap.get("fooOnProject")); + CompositeMap compositeMap = new CompositeMap(buildMavenProjectStub(), properties, false); + assertThat(compositeMap).containsEntry("pom.version", "1.0-SNAPSHOT"); + assertThat(compositeMap).containsEntry("foo", "bar"); + assertThat(compositeMap).containsEntry("pom.groupId", "bar"); + assertThat(compositeMap).containsEntry("pom.scm.connection", "http://blabla"); + assertThat(compositeMap).containsEntry("fooOnProject", "barOnProject"); } - public void testPomInterpolation() throws Exception { - Reader reader = null; + @Test + void testPomInterpolation() throws Exception { File interpolatedPomFile; - try { - InvokerMojo invokerMojo = new InvokerMojo(); - setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub()); - setVariableValueToObject(invokerMojo, "settings", new Settings()); - Properties properties = new Properties(); - properties.put("foo", "bar"); - properties.put("version", "2.0-SNAPSHOT"); - setVariableValueToObject(invokerMojo, "filterProperties", properties); - String dirPath = - getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar - + "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation"; + InvokerMojo invokerMojo = new InvokerMojo(); + setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub()); + setVariableValueToObject(invokerMojo, "settings", new Settings()); + Properties properties = new Properties(); + properties.put("foo", "bar"); + properties.put("version", "2.0-SNAPSHOT"); + setVariableValueToObject(invokerMojo, "filterProperties", properties); + String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar + + "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation"; - interpolatedPomFile = new File(getBasedir(), "target/interpolated-pom.xml"); - invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile); - reader = ReaderFactory.newXmlReader(interpolatedPomFile); + interpolatedPomFile = new File(getBasedir(), "target/interpolated-pom.xml"); + invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile); + try (Reader reader = new XmlStreamReader(interpolatedPomFile)) { + String content = IOUtil.toString(reader); + assertThat(content.indexOf("bar")) + .isPositive(); + } + // recreate it to test delete if exists before creation + invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile); + try (Reader reader = new XmlStreamReader(interpolatedPomFile)) { String content = IOUtil.toString(reader); - assertTrue(content.indexOf("bar") > 0); - reader.close(); - reader = null; - // recreate it to test delete if exists before creation - invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile); - reader = ReaderFactory.newXmlReader(interpolatedPomFile); - content = IOUtil.toString(reader); - assertTrue(content.indexOf("bar") > 0); - reader.close(); - reader = null; - } finally { - IOUtil.close(reader); + assertThat(content.indexOf("bar")) + .isPositive(); } } } diff --git a/src/test/java/org/apache/maven/plugins/invoker/InterpolatorUtilsTest.java b/src/test/java/org/apache/maven/plugins/invoker/InterpolatorUtilsTest.java new file mode 100644 index 00000000..ceab70aa --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/invoker/InterpolatorUtilsTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.invoker; + +import java.util.Properties; +import java.util.stream.Stream; + +import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class InterpolatorUtilsTest { + + @Mock + private MavenProject mavenProject; + + static Stream testAtInterpolate() { + return Stream.of( + Arguments.of(null, null), + Arguments.of("test", "test"), + Arguments.of("test@test", "test@test"), + Arguments.of("test$test", "test$test"), + Arguments.of("@{test}", "testInProps"), + Arguments.of("${test}", "testInProps"), + Arguments.of("test @{test} test", "test testInProps test"), + Arguments.of("test ${test} test", "test testInProps test"), + Arguments.of("@{test} @{test}", "testInProps testInProps"), + Arguments.of("${test} ${test}", "testInProps testInProps"), + Arguments.of("@{test} ${test}", "testInProps testInProps")); + } + + @ParameterizedTest + @MethodSource + void testAtInterpolate(String input, String expected) throws Exception { + // given + Properties properties = new Properties(); + properties.put("test", "testInProps"); + when(mavenProject.getProperties()).thenReturn(properties); + InterpolatorUtils interpolatorUtils = new InterpolatorUtils(mavenProject); + + // when + String output = interpolatorUtils.interpolateAtPattern(input); + + // then + assertThat(output).isEqualTo(expected); + } +} diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java index 49abbeba..fd603222 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java @@ -22,10 +22,10 @@ import java.util.Collections; import java.util.List; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugins.invoker.model.BuildJob; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +33,7 @@ * @author Olivier Lamy * @since 18 nov. 07 */ -public class InvokerMojoTest extends AbstractMojoTestCase { +class InvokerMojoTest extends AbstractTestUtil { private static final String DUMMY_PROJECT = "dummy" + File.separator + "pom.xml"; private static final String WITH_POM_DIR_PROJECT = "with-pom-project-dir" + File.separator + "pom.xml"; @@ -46,13 +46,16 @@ private MavenProject getMavenProject() { return mavenProject; } - public void testSingleInvokerTest() throws Exception { + @Test + void testSingleInvokerTest() throws Exception { // given + MavenProject mavenProject = getMavenProject(); InvokerMojo invokerMojo = new InvokerMojo(); String dirPath = getBasedir() + "/src/test/resources/unit"; setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath)); setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties"); - setVariableValueToObject(invokerMojo, "project", getMavenProject()); + setVariableValueToObject(invokerMojo, "project", mavenProject); + setVariableValueToObject(invokerMojo, "interpolatorUtils", new InterpolatorUtils(mavenProject)); setVariableValueToObject(invokerMojo, "invokerTest", "*dummy*"); setVariableValueToObject(invokerMojo, "settings", new Settings()); @@ -63,13 +66,16 @@ public void testSingleInvokerTest() throws Exception { assertThat(jobs).map(BuildJob::getProject).containsExactlyInAnyOrder(DUMMY_PROJECT); } - public void testMultiInvokerTest() throws Exception { + @Test + void testMultiInvokerTest() throws Exception { // given + MavenProject mavenProject = getMavenProject(); InvokerMojo invokerMojo = new InvokerMojo(); String dirPath = getBasedir() + "/src/test/resources/unit"; setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath)); setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties"); - setVariableValueToObject(invokerMojo, "project", getMavenProject()); + setVariableValueToObject(invokerMojo, "project", mavenProject); + setVariableValueToObject(invokerMojo, "interpolatorUtils", new InterpolatorUtils(mavenProject)); setVariableValueToObject(invokerMojo, "invokerTest", "*dummy*,*terpolatio*"); setVariableValueToObject(invokerMojo, "settings", new Settings()); @@ -80,13 +86,16 @@ public void testMultiInvokerTest() throws Exception { assertThat(jobs).map(BuildJob::getProject).containsExactlyInAnyOrder(DUMMY_PROJECT, INTERPOLATION_PROJECT); } - public void testFullPatternInvokerTest() throws Exception { + @Test + void testFullPatternInvokerTest() throws Exception { // given + MavenProject mavenProject = getMavenProject(); InvokerMojo invokerMojo = new InvokerMojo(); String dirPath = getBasedir() + "/src/test/resources/unit"; setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath)); setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties"); - setVariableValueToObject(invokerMojo, "project", getMavenProject()); + setVariableValueToObject(invokerMojo, "project", mavenProject); + setVariableValueToObject(invokerMojo, "interpolatorUtils", new InterpolatorUtils(mavenProject)); setVariableValueToObject(invokerMojo, "invokerTest", "*"); setVariableValueToObject(invokerMojo, "settings", new Settings()); @@ -100,13 +109,16 @@ public void testFullPatternInvokerTest() throws Exception { DUMMY_PROJECT, WITH_POM_DIR_PROJECT, WITHOUT_POM_PROJECT, INTERPOLATION_PROJECT); } - public void testSetupInProjectList() throws Exception { + @Test + void testSetupInProjectList() throws Exception { // given + MavenProject mavenProject = getMavenProject(); InvokerMojo invokerMojo = new InvokerMojo(); String dirPath = getBasedir() + "/src/test/resources/unit"; setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath)); setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties"); - setVariableValueToObject(invokerMojo, "project", getMavenProject()); + setVariableValueToObject(invokerMojo, "project", mavenProject); + setVariableValueToObject(invokerMojo, "interpolatorUtils", new InterpolatorUtils(mavenProject)); setVariableValueToObject(invokerMojo, "settings", new Settings()); setVariableValueToObject(invokerMojo, "setupIncludes", Collections.singletonList("dum*/pom.xml")); @@ -127,13 +139,16 @@ public void testSetupInProjectList() throws Exception { .containsExactlyInAnyOrder(DUMMY_PROJECT); } - public void testSetupProjectIsFiltered() throws Exception { + @Test + void testSetupProjectIsFiltered() throws Exception { // given + MavenProject mavenProject = getMavenProject(); InvokerMojo invokerMojo = new InvokerMojo(); String dirPath = getBasedir() + "/src/test/resources/unit"; setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath)); setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties"); - setVariableValueToObject(invokerMojo, "project", getMavenProject()); + setVariableValueToObject(invokerMojo, "project", mavenProject); + setVariableValueToObject(invokerMojo, "interpolatorUtils", new InterpolatorUtils(mavenProject)); setVariableValueToObject(invokerMojo, "settings", new Settings()); setVariableValueToObject(invokerMojo, "setupIncludes", Collections.singletonList("dum*/pom.xml")); setVariableValueToObject(invokerMojo, "invokerTest", "*project-dir*"); @@ -152,14 +167,20 @@ public void testSetupProjectIsFiltered() throws Exception { .isEmpty(); } - public void testAlreadyCloned() { - assertFalse(AbstractInvokerMojo.alreadyCloned("dir", Collections.emptyList())); - assertTrue(AbstractInvokerMojo.alreadyCloned("dir", Collections.singletonList("dir"))); - assertTrue(AbstractInvokerMojo.alreadyCloned("dir" + File.separator + "sub", Collections.singletonList("dir"))); - assertFalse(AbstractInvokerMojo.alreadyCloned("dirs", Collections.singletonList("dir"))); + @Test + void testAlreadyCloned() { + assertThat(AbstractInvokerMojo.alreadyCloned("dir", Collections.emptyList())) + .isFalse(); + assertThat(AbstractInvokerMojo.alreadyCloned("dir", Collections.singletonList("dir"))) + .isTrue(); + assertThat(AbstractInvokerMojo.alreadyCloned("dir" + File.separator + "sub", Collections.singletonList("dir"))) + .isTrue(); + assertThat(AbstractInvokerMojo.alreadyCloned("dirs", Collections.singletonList("dir"))) + .isFalse(); } - public void testParallelThreadsSettings() throws IllegalAccessException { + @Test + void testParallelThreadsSettings() throws Exception { Object[][] testValues = { {"4", 4}, {"1C", Runtime.getRuntime().availableProcessors()}, @@ -174,7 +195,7 @@ public void testParallelThreadsSettings() throws IllegalAccessException { setVariableValueToObject(invokerMojo, "parallelThreads", parallelThreads); - assertEquals(expectedParallelThreads, invokerMojo.getParallelThreadsCount()); + assertThat(expectedParallelThreads).isEqualTo(invokerMojo.getParallelThreadsCount()); } } } diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java index eb357c8b..58285f86 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java @@ -19,6 +19,7 @@ package org.apache.maven.plugins.invoker; import java.io.File; +import java.nio.file.Files; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -26,10 +27,10 @@ import org.apache.maven.shared.invoker.InvocationRequest; import org.apache.maven.shared.invoker.InvocationRequest.ReactorFailureBehavior; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -47,20 +48,20 @@ * * @author Benjamin Bentmann */ -@RunWith(MockitoJUnitRunner.class) -public class InvokerPropertiesTest { +@ExtendWith(MockitoExtension.class) +class InvokerPropertiesTest { @Mock private InvocationRequest request; @Test - public void testConstructorNullSafe() { + void testConstructorNullSafe() { InvokerProperties facade = new InvokerProperties(null); assertThat(facade.getProperties()).isNotNull(); } @Test - public void testGetInvokerProperty() { + void testGetInvokerProperty() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -75,7 +76,7 @@ public void testGetInvokerProperty() { } @Test - public void testGetJobName() { + void testGetJobName() { Properties props = new Properties(); final String jobName = "Build Job name"; props.put("invoker.name", jobName); @@ -85,7 +86,7 @@ public void testGetJobName() { } @Test - public void testIsExpectedResult() { + void testIsExpectedResult() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -102,7 +103,7 @@ public void testIsExpectedResult() { } @Test - public void testConfigureRequestEmptyProperties() { + void testConfigureRequestEmptyProperties() { InvokerProperties facade = new InvokerProperties(null); @@ -111,7 +112,7 @@ public void testConfigureRequestEmptyProperties() { } @Test - public void testConfigureRequestGoals() { + void testConfigureRequestGoals() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -148,7 +149,7 @@ public void testConfigureRequestGoals() { } @Test - public void testConfigureRequestProfiles() { + void testConfigureRequestProfiles() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -184,11 +185,11 @@ public void testConfigureRequestProfiles() { } @Test - public void testConfigureRequestProject() throws Exception { + void testConfigureRequestProject() throws Exception { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); - File tempPom = File.createTempFile("maven-invoker-plugin-test", ".pom"); + File tempPom = Files.createTempFile("maven-invoker-plugin-test", ".pom").toFile(); try { File tempDir = tempPom.getParentFile(); when(request.getBaseDirectory()).thenReturn(tempDir); @@ -210,12 +211,12 @@ public void testConfigureRequestProject() throws Exception { } @Test - public void testConfigureRequestMavenExecutable() { + void testConfigureRequestMavenExecutable() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); File aDefExecutable = new File("defExecutable"); - facade.setDefaultMavenExecutable(aDefExecutable); + facade.setDefaultMavenExecutable(aDefExecutable.toString()); props.setProperty("invoker.mavenExecutable", "aPropExecutable"); facade.configureInvocation(request, 0); @@ -231,7 +232,7 @@ public void testConfigureRequestMavenExecutable() { } @Test - public void testConfigureRequestMavenOpts() { + void testConfigureRequestMavenOpts() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -251,7 +252,7 @@ public void testConfigureRequestMavenOpts() { } @Test - public void testConfigureRequestFailureBehavior() { + void testConfigureRequestFailureBehavior() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -263,7 +264,7 @@ public void testConfigureRequestFailureBehavior() { } @Test - public void testConfigureRequestFailureBehaviorUnKnownName() { + void testConfigureRequestFailureBehaviorUnKnownName() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -277,7 +278,7 @@ public void testConfigureRequestFailureBehaviorUnKnownName() { } @Test - public void testConfigureRequestRecursion() { + void testConfigureRequestRecursion() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -294,7 +295,7 @@ public void testConfigureRequestRecursion() { } @Test - public void testConfigureRequestOffline() { + void testConfigureRequestOffline() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -311,7 +312,7 @@ public void testConfigureRequestOffline() { } @Test - public void testConfigureRequestDebug() { + void testConfigureRequestDebug() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -342,7 +343,7 @@ public void testConfigureRequestDebug() { } @Test - public void testConfigureRequestQuiet() { + void testConfigureRequestQuiet() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -373,7 +374,7 @@ public void testConfigureRequestQuiet() { } @Test - public void testConfigureRequestTimeoutInSeconds() { + void testConfigureRequestTimeoutInSeconds() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -392,7 +393,7 @@ public void testConfigureRequestTimeoutInSeconds() { } @Test - public void testConfigureEnvironmentVariables() { + void testConfigureEnvironmentVariables() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -410,7 +411,7 @@ public void testConfigureEnvironmentVariables() { } @Test - public void testConfigureEnvironmentVariablesWithIndex() { + void testConfigureEnvironmentVariablesWithIndex() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -428,7 +429,7 @@ public void testConfigureEnvironmentVariablesWithIndex() { } @Test - public void testConfigureUpdateSnapshots() { + void testConfigureUpdateSnapshots() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -446,7 +447,7 @@ public void testConfigureUpdateSnapshots() { } @Test - public void testConfigureUpdateSnapshotsDefault() { + void testConfigureUpdateSnapshotsDefault() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -463,7 +464,7 @@ public void testConfigureUpdateSnapshotsDefault() { } @Test - public void testIsInvocationDefined() { + void testIsInvocationDefined() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -485,7 +486,7 @@ public void testIsInvocationDefined() { } @Test - public void testIsSelectedDefined() { + void testIsSelectedDefined() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -507,7 +508,7 @@ public void testIsSelectedDefined() { } @Test - public void testGetToolchainsForEmptyProperties() { + void testGetToolchainsForEmptyProperties() { Properties props = new Properties(); InvokerProperties facade = new InvokerProperties(props); @@ -520,7 +521,7 @@ public void testGetToolchainsForEmptyProperties() { } @Test - public void testGetToolchains() { + void testGetToolchains() { Properties props = new Properties(); props.put("invoker.toolchain.jdk.version", "11"); InvokerProperties facade = new InvokerProperties(props); @@ -533,7 +534,7 @@ public void testGetToolchains() { } @Test - public void testGetToolchainsWithIndex() { + void testGetToolchainsWithIndex() { Properties props = new Properties(); props.put("selector.1.invoker.toolchain.jdk.version", "11"); InvokerProperties facade = new InvokerProperties(props); @@ -544,4 +545,43 @@ public void testGetToolchainsWithIndex() { assertThat(toolchain.getType()).isEqualTo("jdk"); assertThat(toolchain.getProvides()).containsExactlyEntriesOf(Collections.singletonMap("version", "11")); } + + @Test + void defaultValueForUserPropertiesFileShouldBeReturned() { + InvokerProperties facade = new InvokerProperties(new Properties()); + facade.setDefaultUserPropertiesFiles("test3.properties"); + + assertThat(facade.getUserPropertiesFile(0)).isEqualTo("test3.properties"); + } + + @Test + void userPropertiesFilesShouldBeUsed() { + Properties props = new Properties(); + props.put("invoker.userPropertiesFile", "test1"); + InvokerProperties facade = new InvokerProperties(props); + + assertThat(facade.getUserPropertiesFile(0)).isEqualTo("test1"); + } + + @Test + void systemPropertiesFilesShouldBeUsed() { + Properties props = new Properties(); + props.put("invoker.systemPropertiesFile", "test1"); + InvokerProperties facade = new InvokerProperties(props); + + assertThat(facade.getUserPropertiesFile(0)).isEqualTo("test1"); + } + + @Test + void userAndSystemPropertiesFilesShouldThrowException() { + Properties props = new Properties(); + props.put("invoker.systemPropertiesFile", "test1"); + props.put("invoker.userPropertiesFile", "test2"); + InvokerProperties facade = new InvokerProperties(props); + + assertThatCode(() -> facade.getUserPropertiesFile(0)) + .isExactlyInstanceOf(IllegalArgumentException.class) + .hasMessage( + "only one property 'invoker.userPropertiesFile' or 'invoker.systemPropertiesFile' can be used"); + } } diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java index 6226e394..9220735b 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java @@ -22,7 +22,7 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.invoker.model.BuildJob; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; @@ -32,10 +32,10 @@ /** * Unittest for {@link InvokerSession} */ -public class InvokerSessionTest { +class InvokerSessionTest { @Test - public void skipSummary() { + void skipSummary() { Log logger = mock(Log.class); BuildJob skippedBuildJob = new BuildJob("minvoker-279"); skippedBuildJob.setResult(BuildJob.Result.SKIPPED); diff --git a/src/test/java/org/apache/maven/plugins/invoker/JobExecutorTest.java b/src/test/java/org/apache/maven/plugins/invoker/JobExecutorTest.java index de374329..9f564086 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/JobExecutorTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/JobExecutorTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.maven.plugins.invoker.model.BuildJob; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -36,17 +36,17 @@ * * @author Slawomir Jaranowski */ -public class JobExecutorTest { +class JobExecutorTest { @Test - public void emptyJobList() { + void emptyJobList() { JobExecutor jobExecutor = new JobExecutor(Collections.emptyList(), 1); jobExecutor.forEach(job -> fail("fail")); } @Test - public void failedJob() { + void failedJob() { BuildJob job = aJob("job1", 100); JobExecutor jobExecutor = new JobExecutor(Collections.singletonList(job), 1); @@ -58,7 +58,7 @@ public void failedJob() { } @Test - public void jobsShouldBeGroupedAndExecutedInProperOrder() { + void jobsShouldBeGroupedAndExecutedInProperOrder() { Map jobsCounter = new HashMap<>(); jobsCounter.put(100, new AtomicInteger(3)); jobsCounter.put(10, new AtomicInteger(2)); diff --git a/src/test/java/org/apache/maven/plugins/invoker/SelectorTest.java b/src/test/java/org/apache/maven/plugins/invoker/SelectorTest.java index f4a8f974..d55875c9 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/SelectorTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/SelectorTest.java @@ -20,39 +20,39 @@ import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Test for {@link Selector}. */ -public class SelectorTest { +class SelectorTest { @Test - public void testGlobalMatch() { + void testGlobalMatch() { Selector selector = new Selector("3.2.5", "1.7", null); Properties props = new Properties(); props.setProperty("invoker.maven.version", "3.0+"); InvokerProperties invokerProperties = new InvokerProperties(props); - assertEquals(0, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isZero(); } @Test - public void testSelectorMatch() { + void testSelectorMatch() { Selector selector = new Selector("3.2.5", "1.7", null); Properties props = new Properties(); props.setProperty("selector.1.maven.version", "3.0+"); InvokerProperties invokerProperties = new InvokerProperties(props); - assertEquals(0, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isZero(); props.setProperty("selector.1.maven.version", "3.3.1+"); - assertEquals(Selector.SELECTOR_MULTI, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isEqualTo(Selector.SELECTOR_MULTI); } @Test - public void testSelectorWithGlobalMatch() { + void testSelectorWithGlobalMatch() { Selector selector = new Selector("3.2.5", "1.7", null); Properties props = new Properties(); @@ -61,16 +61,16 @@ public void testSelectorWithGlobalMatch() { props.setProperty("selector.1.java.version", "1.4+"); props.setProperty("selector.2.os.family", "myos"); InvokerProperties invokerProperties = new InvokerProperties(props); - assertEquals(0, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isZero(); props.setProperty("invoker.maven.version", "3.3.1+"); - assertEquals(Selector.SELECTOR_MULTI, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isEqualTo(Selector.SELECTOR_MULTI); props.setProperty("invoker.maven.version", "3.0+"); props.setProperty("selector.1.maven.version", "3.3.1+"); - assertEquals(Selector.SELECTOR_MULTI, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isEqualTo(Selector.SELECTOR_MULTI); props.setProperty("selector.2.os.family", "!myos"); - assertEquals(0, selector.getSelection(invokerProperties)); + assertThat(selector.getSelection(invokerProperties)).isZero(); } } diff --git a/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java b/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java index 77f26bee..8f72bfac 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java @@ -24,18 +24,14 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; import org.apache.maven.plugins.invoker.AbstractInvokerMojo.ToolchainPrivateManager; import org.apache.maven.toolchain.ToolchainPrivate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.isA; +import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -44,63 +40,69 @@ * * @author Benjamin Bentmann */ -public class SelectorUtilsTest { +class SelectorUtilsTest { @Test - public void testParseList() { + void testParseList() { List includes = new ArrayList<>(); List excludes = new ArrayList<>(); SelectorUtils.parseList(null, includes, excludes); SelectorUtils.parseList(" 1.5, !1.4, 1.6+ ", includes, excludes); - assertEquals(Arrays.asList("1.5", "1.6+"), includes); - assertEquals(Collections.singletonList("1.4"), excludes); + assertThat(includes).containsExactly("1.5", "1.6+"); + assertThat(excludes).containsExactly("1.4"); } @Test - public void testParseVersion() { - assertEquals(Arrays.asList(1, 6, 0, 12), SelectorUtils.parseVersion("1.6.0_12")); - - assertEquals(Arrays.asList(1, 6, 0, 12), SelectorUtils.parseVersion("1.6.0_12+")); - assertEquals(Arrays.asList(1, 6, 0, 12), SelectorUtils.parseVersion("1.6.0_12-")); + void testParseVersion() { + assertThat(SelectorUtils.parseVersion("1.6.0_12")).containsExactly(1, 6, 0, 12); + assertThat(SelectorUtils.parseVersion("1.6.0_12+")).containsExactly(1, 6, 0, 12); + assertThat(SelectorUtils.parseVersion("1.6.0_12-")).containsExactly(1, 6, 0, 12); } @Test - public void testCompareVersions() { - assertTrue(SelectorUtils.compareVersions(Arrays.asList(1, 6), Arrays.asList(1, 6)) == 0); - - assertTrue(SelectorUtils.compareVersions(Arrays.asList(1, 5), Arrays.asList(1, 6)) < 0); - assertTrue(SelectorUtils.compareVersions(Arrays.asList(1, 6), Arrays.asList(1, 5)) > 0); - - assertTrue(SelectorUtils.compareVersions(Collections.singletonList(1), Arrays.asList(1, 6)) < 0); - assertTrue(SelectorUtils.compareVersions(Arrays.asList(1, 6), Collections.singletonList(1)) > 0); + void testCompareVersions() { + assertThat(SelectorUtils.compareVersions(Arrays.asList(1, 6), Arrays.asList(1, 6))) + .isZero(); + + assertThat(SelectorUtils.compareVersions(Arrays.asList(1, 5), Arrays.asList(1, 6))) + .isNegative(); + assertThat(SelectorUtils.compareVersions(Arrays.asList(1, 6), Arrays.asList(1, 5))) + .isPositive(); + + assertThat(SelectorUtils.compareVersions(Collections.singletonList(1), Arrays.asList(1, 6))) + .isNegative(); + assertThat(SelectorUtils.compareVersions(Arrays.asList(1, 6), Collections.singletonList(1))) + .isPositive(); } @Test - public void testIsMatchingJre() { - - assertFalse(SelectorUtils.isJreVersion(Arrays.asList(1, 4, 2, 8), "1.5")); - assertTrue(SelectorUtils.isJreVersion(Arrays.asList(1, 5), "1.5")); - assertTrue(SelectorUtils.isJreVersion(Arrays.asList(1, 5, 9), "1.5")); - assertFalse(SelectorUtils.isJreVersion(Arrays.asList(1, 6), "1.5")); - - assertFalse(SelectorUtils.isJreVersion(Arrays.asList(1, 4, 2, 8), "1.5+")); - assertTrue(SelectorUtils.isJreVersion(Arrays.asList(1, 5), "1.5+")); - assertTrue(SelectorUtils.isJreVersion(Arrays.asList(1, 5, 9), "1.5+")); - assertTrue(SelectorUtils.isJreVersion(Arrays.asList(1, 6), "1.5+")); - - assertTrue(SelectorUtils.isJreVersion(Arrays.asList(1, 4, 2, 8), "1.5-")); - assertFalse(SelectorUtils.isJreVersion(Arrays.asList(1, 5), "1.5-")); - assertFalse(SelectorUtils.isJreVersion(Arrays.asList(1, 5, 9), "1.5-")); - assertFalse(SelectorUtils.isJreVersion(Arrays.asList(1, 6), "1.5-")); - - assertTrue(SelectorUtils.isJreVersion((String) null, "1.5")); - assertTrue(SelectorUtils.isJreVersion("", "1.5")); + void testIsMatchingJre() { + + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 4, 2, 8), "1.5")).isFalse(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 5), "1.5")).isTrue(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 5, 9), "1.5")).isTrue(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 6), "1.5")).isFalse(); + + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 4, 2, 8), "1.5+")) + .isFalse(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 5), "1.5+")).isTrue(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 5, 9), "1.5+")).isTrue(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 6), "1.5+")).isTrue(); + + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 4, 2, 8), "1.5-")) + .isTrue(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 5), "1.5-")).isFalse(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 5, 9), "1.5-")).isFalse(); + assertThat(SelectorUtils.isJreVersion(Arrays.asList(1, 6), "1.5-")).isFalse(); + + assertThat(SelectorUtils.isJreVersion((String) null, "1.5")).isTrue(); + assertThat(SelectorUtils.isJreVersion("", "1.5")).isTrue(); } @Test - public void testIsMatchingToolchain() throws Exception { + void testIsMatchingToolchain() throws Exception { InvokerToolchain openJdk9 = new InvokerToolchain("jdk"); openJdk9.addProvides("version", "9"); openJdk9.addProvides("vendor", "openJDK"); @@ -110,32 +112,37 @@ public void testIsMatchingToolchain() throws Exception { ToolchainPrivateManager toolchainPrivateManager = mock(ToolchainPrivateManager.class); ToolchainPrivate jdkMatching = mock(ToolchainPrivate.class); - when(jdkMatching.matchesRequirements(isA(Map.class))).thenReturn(true); + when(jdkMatching.matchesRequirements(anyMap())).thenReturn(true); when(jdkMatching.getType()).thenReturn("jdk"); ToolchainPrivate jdkMismatch = mock(ToolchainPrivate.class); when(jdkMismatch.getType()).thenReturn("jdk"); when(toolchainPrivateManager.getToolchainPrivates("jdk")).thenReturn(new ToolchainPrivate[] {jdkMatching}); - assertTrue(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))); + assertThat(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))) + .isTrue(); when(toolchainPrivateManager.getToolchainPrivates("jdk")).thenReturn(new ToolchainPrivate[] {jdkMismatch}); - assertFalse(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))); + assertThat(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))) + .isFalse(); when(toolchainPrivateManager.getToolchainPrivates("jdk")) .thenReturn(new ToolchainPrivate[] {jdkMatching, jdkMismatch, jdkMatching}); - assertTrue(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))); + assertThat(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))) + .isTrue(); when(toolchainPrivateManager.getToolchainPrivates("jdk")).thenReturn(new ToolchainPrivate[0]); - assertFalse(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))); + assertThat(SelectorUtils.isToolchain(toolchainPrivateManager, Collections.singleton(openJdk9))) + .isFalse(); when(toolchainPrivateManager.getToolchainPrivates("jdk")).thenReturn(new ToolchainPrivate[] {jdkMatching}); when(toolchainPrivateManager.getToolchainPrivates("maven")).thenReturn(new ToolchainPrivate[0]); - assertFalse(SelectorUtils.isToolchain(toolchainPrivateManager, Arrays.asList(openJdk9, maven360))); + assertThat(SelectorUtils.isToolchain(toolchainPrivateManager, Arrays.asList(openJdk9, maven360))) + .isFalse(); } @Test - public void mavenVersionForNotExistingMavenHomeThrowException() { + void mavenVersionForNotExistingMavenHomeThrowException() { File mavenHome = new File("not-existing-path"); assertThatCode(() -> SelectorUtils.getMavenVersion(mavenHome)) @@ -144,7 +151,7 @@ public void mavenVersionForNotExistingMavenHomeThrowException() { } @Test - public void mavenVersionFromMavenHome() throws IOException { + void mavenVersionFromMavenHome() throws IOException { File mavenHome = new File(System.getProperty("maven.home")); String mavenVersion = SelectorUtils.getMavenVersion(mavenHome);