diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml
index 065619be..56062b54 100644
--- a/.github/workflows/maven-verify.yml
+++ b/.github/workflows/maven-verify.yml
@@ -26,5 +26,6 @@ jobs:
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4
with:
- maven4-enabled: true
-
+ ff-maven: "4.0.0-beta-3" # Maven version for fail-fast-build
+ maven-matrix: '[ "4.0.0-beta-3" ]'
+ jdk-matrix: '[ "17", "21" ]'
diff --git a/pom.xml b/pom.xml
index ed748468..47decf5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
maven-install-plugin
- 3.1.3-SNAPSHOT
+ 4.0.0-SNAPSHOT
maven-plugin
Apache Maven Install Plugin
@@ -46,7 +46,7 @@
- 3.6.3
+ ${mavenVersion}
@@ -71,134 +71,144 @@
- 8
- 3.9.6
+ 17
+ 4.0.0-beta-3
- 1.9.18
-
- 1.7.36
+ 2.0.13
- ${version.maven-antrun-plugin}
- ${version.maven-compiler-plugin}
- ${version.maven-enforcer-plugin}
- ${version.maven-jar-plugin}
- ${version.maven-plugin-tools}
- ${version.maven-resources-plugin}
- ${version.maven-source-plugin}
- ${version.maven-surefire}
+ 6.0.0
+ 5.10.2
+ 3.1.0
+ 3.10.1
+ 3.1.0
+ 3.3.0
+ 4.0.0-SNAPSHOT
+ 4.0.0-alpha-3-SNAPSHOT
+ 3.3.0
+ 3.2.1
+ 3.2.2
+ 5.12.0
+ 4.0.1
+ ${mavenPluginPluginVersion}
+ 3.7.0
2024-04-26T10:23:20Z
+
+
+
+ com.google.guava
+ guava
+ 32.0.1-jre
+
+
+
+
org.apache.maven
- maven-plugin-api
+ maven-api-core
${mavenVersion}
provided
org.apache.maven
- maven-artifact
+ maven-api-di
${mavenVersion}
provided
-
org.apache.maven
- maven-core
+ maven-api-meta
${mavenVersion}
provided
org.apache.maven
- maven-model
+ maven-api-model
${mavenVersion}
provided
+
- org.apache.maven.resolver
- maven-resolver-api
- ${resolverVersion}
- provided
-
-
- org.apache.maven.resolver
- maven-resolver-util
- ${resolverVersion}
-
- compile
-
-
- org.codehaus.plexus
- plexus-utils
-
-
- org.codehaus.plexus
- plexus-xml
+ org.apache.maven.plugin-testing
+ maven-plugin-testing-harness
+ ${mavenPluginTestingVersion}
+ test
-
-
- org.apache.maven.plugin-tools
- maven-plugin-annotations
- provided
+ org.apache.maven
+ maven-core
+ ${mavenVersion}
+ test
-
- junit
- junit
- 4.13.2
+ org.apache.maven
+ maven-api-impl
+ ${mavenVersion}
test
- org.apache.maven.plugin-testing
- maven-plugin-testing-harness
- 3.3.0
+ org.codehaus.plexus
+ plexus-utils
test
-
- org.apache.maven
- maven-compat
- ${mavenVersion}
+ com.google.inject
+ guice
+ ${guiceVersion}
test
org.mockito
mockito-core
- 4.8.1
+ ${mockitoVersion}
test
- org.slf4j
- slf4j-api
- ${slf4jVersion}
- provided
+ org.apache.maven.resolver
+ maven-resolver-api
+ 2.0.0-alpha-11
+ test
org.slf4j
- slf4j-nop
+ slf4j-simple
${slf4jVersion}
test
- org.apache.maven.resolver
- maven-resolver-impl
- ${resolverVersion}
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junitVersion}
test
+
+
+ org.apache.maven.plugin-tools
+ maven-plugin-annotations
+ none
+
- org.apache.maven.plugins
- maven-compiler-plugin
+ com.diffplug.spotless
+ spotless-maven-plugin
- none
- true
+
+
+ src/**/*.java
+
+
+
+
+ **/pom.xml
+
+
diff --git a/src/it/MINSTALL-108/module1/pom.xml b/src/it/MINSTALL-108/module1/pom.xml
index 7708ddef..ee393b2f 100644
--- a/src/it/MINSTALL-108/module1/pom.xml
+++ b/src/it/MINSTALL-108/module1/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
diff --git a/src/it/MINSTALL-108/pom.xml b/src/it/MINSTALL-108/pom.xml
index 957e7b89..23b1a93d 100644
--- a/src/it/MINSTALL-108/pom.xml
+++ b/src/it/MINSTALL-108/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.iae.pass
@@ -28,9 +25,11 @@ under the License.
1.0
pom
-
- Tests installation at end override.
-
+ Tests installation at end override.
+
+
+ module1
+
true
@@ -69,8 +68,4 @@ under the License.
-
- module1
-
-
diff --git a/src/it/MINSTALL-52/pom.xml b/src/it/MINSTALL-52/pom.xml
index 3a25d596..6f721d72 100644
--- a/src/it/MINSTALL-52/pom.xml
+++ b/src/it/MINSTALL-52/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.plugins.install.its
minstall52
1.0-SNAPSHOT
-
- Test to verify that the pom inside the jar in used when installing the file
-
+ Test to verify that the pom inside the jar in used when installing the file
diff --git a/src/it/MINSTALL-98/module1/pom.xml b/src/it/MINSTALL-98/module1/pom.xml
index 092076b4..e7e4a13a 100644
--- a/src/it/MINSTALL-98/module1/pom.xml
+++ b/src/it/MINSTALL-98/module1/pom.xml
@@ -1,25 +1,22 @@
-
-
-
-
-
- 4.0.0
-
-
- org.apache.maven.its.minstall-98
- multithread
- 1.0
-
- module1
-
-
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.minstall-98
+ multithread
+ 1.0
+
+ module1
+
+
diff --git a/src/it/MINSTALL-98/module2/pom.xml b/src/it/MINSTALL-98/module2/pom.xml
index f0b6d1b7..74b36ce3 100644
--- a/src/it/MINSTALL-98/module2/pom.xml
+++ b/src/it/MINSTALL-98/module2/pom.xml
@@ -1,26 +1,23 @@
-
-
-
-
-
- 4.0.0
-
-
- org.apache.maven.its.minstall-98
- multithread
- 1.0
-
- module2
- pom
-
-
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.minstall-98
+ multithread
+ 1.0
+
+ module2
+ pom
+
+
diff --git a/src/it/MINSTALL-98/pom.xml b/src/it/MINSTALL-98/pom.xml
index b1ff4268..3b78f102 100644
--- a/src/it/MINSTALL-98/pom.xml
+++ b/src/it/MINSTALL-98/pom.xml
@@ -1,77 +1,72 @@
-
-
-
-
-
- 4.0.0
-
- org.apache.maven.its.minstall-98
- multithread
- 1.0
- pom
-
-
- Tests installation at end with two threads.
-
-
-
- true
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- @mavenCompilerPluginVersion@
-
-
- org.apache.maven.plugins
- maven-install-plugin
- @project.version@
-
- true
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- @mavenJarPluginVersion@
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- @mavenResourcesPluginVersion@
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- @mavenSurefirePluginVersion@
-
-
-
-
-
- module1
- module2
-
-
-
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.minstall-98
+ multithread
+ 1.0
+ pom
+
+ Tests installation at end with two threads.
+
+
+ module1
+ module2
+
+
+
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ @mavenCompilerPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ @project.version@
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ @mavenJarPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ @mavenResourcesPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ @mavenSurefirePluginVersion@
+
+
+
+
+
diff --git a/src/it/MINSTALL-99/module1/pom.xml b/src/it/MINSTALL-99/module1/pom.xml
index 5c925e41..e8b821b6 100644
--- a/src/it/MINSTALL-99/module1/pom.xml
+++ b/src/it/MINSTALL-99/module1/pom.xml
@@ -1,25 +1,22 @@
-
-
-
-
-
- 4.0.0
-
-
- org.apache.maven.its.minstall-99
- configperproject
- 1.0
-
- module1
-
-
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.minstall-99
+ configperproject
+ 1.0
+
+ module1
+
+
diff --git a/src/it/MINSTALL-99/module2/pom.xml b/src/it/MINSTALL-99/module2/pom.xml
index 6d984aa4..478f8df9 100644
--- a/src/it/MINSTALL-99/module2/pom.xml
+++ b/src/it/MINSTALL-99/module2/pom.xml
@@ -1,39 +1,36 @@
-
-
-
-
-
- 4.0.0
-
-
- org.apache.maven.its.minstall-99
- configperproject
- 1.0
-
- module2
- pom
-
-
-
-
- org.apache.maven.plugins
- maven-install-plugin
- @project.version@
-
- true
-
-
-
-
-
-
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.minstall-99
+ configperproject
+ 1.0
+
+ module2
+ pom
+
+
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ @project.version@
+
+ true
+
+
+
+
+
+
diff --git a/src/it/MINSTALL-99/pom.xml b/src/it/MINSTALL-99/pom.xml
index 2f768b9b..d7c3a941 100644
--- a/src/it/MINSTALL-99/pom.xml
+++ b/src/it/MINSTALL-99/pom.xml
@@ -1,77 +1,72 @@
-
-
-
-
-
- 4.0.0
-
- org.apache.maven.its.minstall-99
- configperproject
- 1.0
- pom
-
-
- Tests installation at end with different plugin configurations.
-
-
-
- true
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- @mavenCompilerPluginVersion@
-
-
- org.apache.maven.plugins
- maven-install-plugin
- @project.version@
-
- true
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- @mavenJarPluginVersion@
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- @mavenResourcesPluginVersion@
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- @mavenSurefirePluginVersion@
-
-
-
-
-
- module1
- module2
-
-
-
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.minstall-99
+ configperproject
+ 1.0
+ pom
+
+ Tests installation at end with different plugin configurations.
+
+
+ module1
+ module2
+
+
+
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ @mavenCompilerPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ @project.version@
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ @mavenJarPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ @mavenResourcesPluginVersion@
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ @mavenSurefirePluginVersion@
+
+
+
+
+
diff --git a/src/it/attach-jar-checksum/pom.xml b/src/it/attach-jar-checksum/pom.xml
index 8867c955..242a313a 100644
--- a/src/it/attach-jar-checksum/pom.xml
+++ b/src/it/attach-jar-checksum/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.ajc
@@ -28,9 +25,7 @@ under the License.
1.0-SNAPSHOT
jar
-
- Tests the installation of a simple snapshot JAR with an attached artifact and checksums
-
+ Tests the installation of a simple snapshot JAR with an attached artifact and checksums
true
diff --git a/src/it/attach-release-jar/pom.xml b/src/it/attach-release-jar/pom.xml
index 1527897c..bbebcdc4 100644
--- a/src/it/attach-release-jar/pom.xml
+++ b/src/it/attach-release-jar/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.arj
@@ -28,9 +25,7 @@ under the License.
1.0
jar
-
- Tests the installation of a simple release JAR with an attached artifact.
-
+ Tests the installation of a simple release JAR with an attached artifact.
true
diff --git a/src/it/gav-validation/invoker.properties b/src/it/gav-validation/invoker.properties
index 07e1b130..70d43e48 100644
--- a/src/it/gav-validation/invoker.properties
+++ b/src/it/gav-validation/invoker.properties
@@ -18,5 +18,5 @@
invoker.goals = org.apache.maven.plugins:maven-install-plugin:${project.version}:install-file
invoker.buildResult = failure
-invoker.systemPropertiesFile.1 = test-invalid.properties
-invoker.systemPropertiesFile.2 = test-missing.properties
+invoker.userPropertiesFile.1 = test-invalid.properties
+invoker.userPropertiesFile.2 = test-missing.properties
diff --git a/src/it/gav-validation/pom.xml b/src/it/gav-validation/pom.xml
index d0ce3393..eb31bd0c 100644
--- a/src/it/gav-validation/pom.xml
+++ b/src/it/gav-validation/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.gv
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Tests the manual installation validates the coordinates of the artifact just like the model validator would
- (MINSTALL-59).
-
+ Tests the manual installation validates the coordinates of the artifact just like the model validator would
+ (MINSTALL-59).
diff --git a/src/it/generate-pom-auto-1/pom.xml b/src/it/generate-pom-auto-1/pom.xml
index bb852eb0..b3904c21 100644
--- a/src/it/generate-pom-auto-1/pom.xml
+++ b/src/it/generate-pom-auto-1/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.gpa1
@@ -28,9 +25,7 @@ under the License.
1.0
jar
-
- Tests that by default a POM is generated for the installed file if no POM exists already in the local repo.
-
+ Tests that by default a POM is generated for the installed file if no POM exists already in the local repo.
diff --git a/src/it/generate-pom-auto-2/pom.xml b/src/it/generate-pom-auto-2/pom.xml
index f2f97e9e..9512c9a7 100644
--- a/src/it/generate-pom-auto-2/pom.xml
+++ b/src/it/generate-pom-auto-2/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.gpa2
@@ -28,9 +25,7 @@ under the License.
1.0
jar
-
- Tests that by default no POM is generated for the installed file if already a POM exists in the local repo.
-
+ Tests that by default no POM is generated for the installed file if already a POM exists in the local repo.
diff --git a/src/it/install-at-end-fail/module1/pom.xml b/src/it/install-at-end-fail/module1/pom.xml
index 10ebadcb..ec5f4097 100644
--- a/src/it/install-at-end-fail/module1/pom.xml
+++ b/src/it/install-at-end-fail/module1/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
@@ -36,7 +33,7 @@
-
+
diff --git a/src/it/install-at-end-fail/pom.xml b/src/it/install-at-end-fail/pom.xml
index 23de9d8b..5c660f6f 100644
--- a/src/it/install-at-end-fail/pom.xml
+++ b/src/it/install-at-end-fail/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.dae.fail
@@ -28,9 +25,11 @@ under the License.
1.0
pom
-
- Tests installation at end.
-
+ Tests installation at end.
+
+
+ module1
+
true
@@ -69,8 +68,4 @@ under the License.
-
- module1
-
-
diff --git a/src/it/install-at-end-pass/module1/pom.xml b/src/it/install-at-end-pass/module1/pom.xml
index 31279ce7..9c6b1f96 100644
--- a/src/it/install-at-end-pass/module1/pom.xml
+++ b/src/it/install-at-end-pass/module1/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
diff --git a/src/it/install-at-end-pass/module2/pom.xml b/src/it/install-at-end-pass/module2/pom.xml
index f78eb0db..05c13fc2 100644
--- a/src/it/install-at-end-pass/module2/pom.xml
+++ b/src/it/install-at-end-pass/module2/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
diff --git a/src/it/install-at-end-pass/module3/pom.xml b/src/it/install-at-end-pass/module3/pom.xml
index 2d346dbe..56754f2b 100644
--- a/src/it/install-at-end-pass/module3/pom.xml
+++ b/src/it/install-at-end-pass/module3/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
diff --git a/src/it/install-at-end-pass/module4/pom.xml b/src/it/install-at-end-pass/module4/pom.xml
index cb4ca5fd..bc66e762 100644
--- a/src/it/install-at-end-pass/module4/pom.xml
+++ b/src/it/install-at-end-pass/module4/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
diff --git a/src/it/install-at-end-pass/pom.xml b/src/it/install-at-end-pass/pom.xml
index 9bf09686..36d2efa1 100644
--- a/src/it/install-at-end-pass/pom.xml
+++ b/src/it/install-at-end-pass/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.dae.pass
@@ -28,9 +25,14 @@ under the License.
1.0
pom
-
- Tests installation at end.
-
+ Tests installation at end.
+
+
+ module1
+ module2
+ module3
+ module4
+
true
@@ -69,11 +71,4 @@ under the License.
-
- module1
- module2
- module3
- module4
-
-
diff --git a/src/it/install-file-minstall-121-bundle/pom.xml b/src/it/install-file-minstall-121-bundle/pom.xml
index c4e69fde..5c8f5bf8 100644
--- a/src/it/install-file-minstall-121-bundle/pom.xml
+++ b/src/it/install-file-minstall-121-bundle/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.121
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Test to install a file via install:install-file using
- packaging and expected having a different file extension.
-
+ Test to install a file via install:install-file using
+ packaging and expected having a different file extension.
diff --git a/src/it/install-file-minstall-121-java-source/pom.xml b/src/it/install-file-minstall-121-java-source/pom.xml
index 6791cccb..16817295 100644
--- a/src/it/install-file-minstall-121-java-source/pom.xml
+++ b/src/it/install-file-minstall-121-java-source/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.121
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Test to install a file via install:install-file using
- packaging and expected having a different file extension.
-
+ Test to install a file via install:install-file using
+ packaging and expected having a different file extension.
diff --git a/src/it/install-file-minstall-121-maven-archetype/pom.xml b/src/it/install-file-minstall-121-maven-archetype/pom.xml
index 02d76349..58fbbbd2 100644
--- a/src/it/install-file-minstall-121-maven-archetype/pom.xml
+++ b/src/it/install-file-minstall-121-maven-archetype/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.121
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Test to install a file via install:install-file using
- packaging and expected having a different file extension.
-
+ Test to install a file via install:install-file using
+ packaging and expected having a different file extension.
diff --git a/src/it/install-file-minstall-121-targz/pom.xml b/src/it/install-file-minstall-121-targz/pom.xml
index 72009e35..88270c2b 100644
--- a/src/it/install-file-minstall-121-targz/pom.xml
+++ b/src/it/install-file-minstall-121-targz/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.121
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Test to install a file via install:install-file using
- packaging and expected having a different file extension.
-
+ Test to install a file via install:install-file using
+ packaging and expected having a different file extension.
diff --git a/src/it/install-file-minstall-121-war/pom.xml b/src/it/install-file-minstall-121-war/pom.xml
index d4c252b3..51c44da8 100644
--- a/src/it/install-file-minstall-121-war/pom.xml
+++ b/src/it/install-file-minstall-121-war/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.121
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Test to install a file via install:install-file using
- packaging and expected having a different file extension.
-
+ Test to install a file via install:install-file using
+ packaging and expected having a different file extension.
diff --git a/src/it/install-file-minstall-121/pom.xml b/src/it/install-file-minstall-121/pom.xml
index 4ba0c85a..4b614554 100644
--- a/src/it/install-file-minstall-121/pom.xml
+++ b/src/it/install-file-minstall-121/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.121
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Test to install a file via install:install-file using
- packaging and expected having a different file extension.
-
+ Test to install a file via install:install-file using
+ packaging and expected having a different file extension.
diff --git a/src/it/jar-sources-javadoc/pom.xml b/src/it/jar-sources-javadoc/pom.xml
index 32ca82e7..2ebb9f87 100644
--- a/src/it/jar-sources-javadoc/pom.xml
+++ b/src/it/jar-sources-javadoc/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.jsj
@@ -28,9 +25,7 @@ under the License.
1.0
jar
-
- Tests combined installation of a JAR together with its API docs and sources (cf. MINSTALL-49).
-
+ Tests combined installation of a JAR together with its API docs and sources (cf. MINSTALL-49).
diff --git a/src/it/local-repo-override-with-checksum-generatePom/pom.xml b/src/it/local-repo-override-with-checksum-generatePom/pom.xml
index 0dfca77a..5ff1695c 100644
--- a/src/it/local-repo-override-with-checksum-generatePom/pom.xml
+++ b/src/it/local-repo-override-with-checksum-generatePom/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.lro
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Tests the manual installation into a different local repo than the one configured in the settings
- (MINSTALL-35), also installing checksums.
-
+ Tests the manual installation into a different local repo than the one configured in the settings
+ (MINSTALL-35), also installing checksums.
diff --git a/src/it/local-repo-override-with-checksum/pom.xml b/src/it/local-repo-override-with-checksum/pom.xml
index 0dfca77a..5ff1695c 100644
--- a/src/it/local-repo-override-with-checksum/pom.xml
+++ b/src/it/local-repo-override-with-checksum/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.lro
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Tests the manual installation into a different local repo than the one configured in the settings
- (MINSTALL-35), also installing checksums.
-
+ Tests the manual installation into a different local repo than the one configured in the settings
+ (MINSTALL-35), also installing checksums.
diff --git a/src/it/local-repo-override/pom.xml b/src/it/local-repo-override/pom.xml
index 71ec5691..936c3ee0 100644
--- a/src/it/local-repo-override/pom.xml
+++ b/src/it/local-repo-override/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.lro
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Tests the manual installation into a different local repo than the one configured in the settings
- (MINSTALL-35).
-
+ Tests the manual installation into a different local repo than the one configured in the settings
+ (MINSTALL-35).
diff --git a/src/it/minstall-55/pom.xml b/src/it/minstall-55/pom.xml
index fcf8f33e..b04f83f8 100644
--- a/src/it/minstall-55/pom.xml
+++ b/src/it/minstall-55/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.55
@@ -28,10 +25,8 @@ under the License.
1.0
jar
-
- Tests the manual installation of a simple release JAR with a corresponding POM whose coordinates are inherited
- from the parent.
-
+ Tests the manual installation of a simple release JAR with a corresponding POM whose coordinates are inherited
+ from the parent.
diff --git a/src/it/no-main-artifact-1/pom.xml b/src/it/no-main-artifact-1/pom.xml
index 850b2b5a..cee9d0c6 100644
--- a/src/it/no-main-artifact-1/pom.xml
+++ b/src/it/no-main-artifact-1/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.nma1
@@ -28,11 +25,9 @@ under the License.
1.0-SNAPSHOT
jar
-
- Tests the installation of a non-POM project that has no main artifact file but only attached artifacts (see
+ Tests the installation of a non-POM project that has no main artifact file but only attached artifacts (see
MINSTALL-18, MINSTALL-40, MINSTALL-41). This variant of the test checks the build when target/classes is
- non-existent.
-
+ non-existent.
true
@@ -49,16 +44,16 @@ under the License.
-
+
delete-output-dir
- verify
run
+ verify
diff --git a/src/it/no-main-artifact-1/verify.groovy b/src/it/no-main-artifact-1/verify.groovy
index 7274ba5c..9442aa7d 100644
--- a/src/it/no-main-artifact-1/verify.groovy
+++ b/src/it/no-main-artifact-1/verify.groovy
@@ -19,5 +19,5 @@
def buildLog = new File ( basedir, "build.log")
-assert buildLog.text.contains( "The packaging plugin for project test did not assign "
+assert buildLog.text.contains( "The packaging plugin for this project did not assign "
+ "a main file to the project but it has attachments. Change packaging to 'pom'." )
\ No newline at end of file
diff --git a/src/it/no-main-artifact-2/pom.xml b/src/it/no-main-artifact-2/pom.xml
index 93e04512..0bd432b5 100644
--- a/src/it/no-main-artifact-2/pom.xml
+++ b/src/it/no-main-artifact-2/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.nma2
@@ -28,10 +25,8 @@ under the License.
1.0-SNAPSHOT
jar
-
- Tests the installation of a non-POM project that has no main artifact file but only attached artifacts (see
- MINSTALL-18, MINSTALL-40, MINSTALL-41). This variant of the test checks the build when target/classes is existent.
-
+ Tests the installation of a non-POM project that has no main artifact file but only attached artifacts (see
+ MINSTALL-18, MINSTALL-40, MINSTALL-41). This variant of the test checks the build when target/classes is existent.
true
@@ -48,16 +43,16 @@ under the License.
-
+
make-output-dir
- verify
run
+ verify
diff --git a/src/it/no-main-artifact-2/verify.groovy b/src/it/no-main-artifact-2/verify.groovy
index 7274ba5c..9442aa7d 100644
--- a/src/it/no-main-artifact-2/verify.groovy
+++ b/src/it/no-main-artifact-2/verify.groovy
@@ -19,5 +19,5 @@
def buildLog = new File ( basedir, "build.log")
-assert buildLog.text.contains( "The packaging plugin for project test did not assign "
+assert buildLog.text.contains( "The packaging plugin for this project did not assign "
+ "a main file to the project but it has attachments. Change packaging to 'pom'." )
\ No newline at end of file
diff --git a/src/it/non-changed-artifact/invoker.properties b/src/it/non-changed-artifact/invoker.properties
deleted file mode 100644
index a23a59c2..00000000
--- a/src/it/non-changed-artifact/invoker.properties
+++ /dev/null
@@ -1,23 +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.
-
-# check was removed in MRESOLVER-392
-invoker.maven.version = !4+
-
-# install called in two different Maven invocations, otherwise the build would fail with the Jar Plugin (MJAR-198)
-invoker.goals.1 = install
-invoker.goals.2 = install
diff --git a/src/it/non-changed-artifact/pom.xml b/src/it/non-changed-artifact/pom.xml
deleted file mode 100644
index bdf4f610..00000000
--- a/src/it/non-changed-artifact/pom.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
-
-
- 4.0.0
-
- org.apache.maven.plugins.install.its
- minstall-39
- 1.0-SNAPSHOT
- jar
-
-
- Tests the manual installation of a simple release JAR with a corresponding POM whose coordinates are inherited
- from the parent.
-
-
-
-
-
- org.apache.maven.plugins
- maven-install-plugin
- @project.version@
-
-
-
-
-
diff --git a/src/it/non-changed-artifact/verify.groovy b/src/it/non-changed-artifact/verify.groovy
deleted file mode 100644
index 0be1085a..00000000
--- a/src/it/non-changed-artifact/verify.groovy
+++ /dev/null
@@ -1,30 +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.
- */
-
-File buildLog = new File( basedir, 'build.log' )
-assert buildLog.exists()
-
-def logText = buildLog.text
-
-artifactPath = new File( basedir, 'target/minstall-39-1.0-SNAPSHOT.jar' ).canonicalPath
-copyArtifactPath = new File( basedir, '../../local-repo/org/apache/maven/plugins/install/its/minstall-39/1.0-SNAPSHOT/minstall-39-1.0-SNAPSHOT.jar' ).canonicalPath
-
-assert 2 == logText.count( "[INFO] Installing ${artifactPath} to ${copyArtifactPath}" )
-assert 1 == logText.count( "[DEBUG] Skipped re-installing ${artifactPath} to ${copyArtifactPath}, seems unchanged" )
-
diff --git a/src/it/pom-checksum/pom.xml b/src/it/pom-checksum/pom.xml
index 4272babb..722c2ed9 100644
--- a/src/it/pom-checksum/pom.xml
+++ b/src/it/pom-checksum/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.pc
@@ -28,9 +25,7 @@ under the License.
1.0-SNAPSHOT
pom
-
- Tests the installation of a simple snapshot POM with checksums
-
+ Tests the installation of a simple snapshot POM with checksums
true
diff --git a/src/it/release-jar/pom.xml b/src/it/release-jar/pom.xml
index f243b3c6..c5e59c62 100644
--- a/src/it/release-jar/pom.xml
+++ b/src/it/release-jar/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.rj
@@ -28,9 +25,7 @@ under the License.
1.0
jar
-
- Tests the installation of a simple release JAR.
-
+ Tests the installation of a simple release JAR.
true
diff --git a/src/it/release-pom/pom.xml b/src/it/release-pom/pom.xml
index 163efa3e..8fe17b1e 100644
--- a/src/it/release-pom/pom.xml
+++ b/src/it/release-pom/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.rp
@@ -28,9 +25,7 @@ under the License.
1.0
pom
-
- Tests the installation of a simple release POM.
-
+ Tests the installation of a simple release POM.
true
diff --git a/src/it/setup-mock-phase-maven-plugin/pom.xml b/src/it/setup-mock-phase-maven-plugin/pom.xml
index 09ed9c31..bf8feb02 100644
--- a/src/it/setup-mock-phase-maven-plugin/pom.xml
+++ b/src/it/setup-mock-phase-maven-plugin/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.mock
@@ -28,12 +25,12 @@ under the License.
1.0
maven-plugin
+ plugin with Maven phase without m-install-p
+
@mavenVersion@
- plugin with Maven phase without m-install-p
-
diff --git a/src/it/skip-install/pom.xml b/src/it/skip-install/pom.xml
index 64ecd4ae..4be4a6c8 100644
--- a/src/it/skip-install/pom.xml
+++ b/src/it/skip-install/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.skip
@@ -28,9 +25,7 @@ under the License.
1.0
jar
-
- Tests the skip installation of a simple release JAR.
-
+ Tests the skip installation of a simple release JAR.
true
diff --git a/src/it/snapshot-jar/pom.xml b/src/it/snapshot-jar/pom.xml
index 392da48e..67103e06 100644
--- a/src/it/snapshot-jar/pom.xml
+++ b/src/it/snapshot-jar/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.sj
@@ -28,9 +25,7 @@ under the License.
1.0-SNAPSHOT
jar
-
- Tests the installation of a simple snapshot JAR.
-
+ Tests the installation of a simple snapshot JAR.
true
diff --git a/src/it/snapshot-pom/pom.xml b/src/it/snapshot-pom/pom.xml
index 2532c859..fe6a9237 100644
--- a/src/it/snapshot-pom/pom.xml
+++ b/src/it/snapshot-pom/pom.xml
@@ -1,5 +1,4 @@
-
-
-
+
4.0.0
org.apache.maven.its.install.sp
@@ -28,9 +25,7 @@ under the License.
1.0-SNAPSHOT
pom
-
- Tests the installation of a simple snapshot POM.
-
+ Tests the installation of a simple snapshot POM.
true
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
index 4ba6b641..ab762ab4 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
@@ -22,58 +22,45 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
-import java.util.function.Predicate;
+import java.util.ArrayList;
+import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-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.DefaultArtifact;
-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.util.artifact.SubArtifact;
-
-import static java.util.Objects.isNull;
-import static java.util.Objects.nonNull;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Parent;
+import org.apache.maven.api.plugin.Log;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerException;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.xml.ModelXmlFactory;
+import org.apache.maven.api.services.xml.XmlReaderException;
/**
* Installs a file in the local repository.
- *
- * @author Brett Porter
*/
-@Mojo(name = "install-file", requiresProject = false, aggregator = true, threadSafe = true)
-public class InstallFileMojo extends AbstractMojo {
- private static final String LS = System.lineSeparator();
+@Mojo(name = "install-file", projectRequired = false, aggregator = true)
+@SuppressWarnings("unused")
+public class InstallFileMojo implements org.apache.maven.api.plugin.Mojo {
+ private static final String TAR = "tar.";
+ private static final String ILLEGAL_VERSION_CHARS = "\\/:\"<>|?*[](){},";
- @Component
- private RepositorySystem repositorySystem;
+ @Inject
+ private Log log;
- @Parameter(defaultValue = "${session}", required = true, readonly = true)
- private MavenSession session;
+ @Inject
+ private Session session;
/**
* GroupId of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
@@ -116,7 +103,7 @@ public class InstallFileMojo extends AbstractMojo {
* The file to be installed in the local repository.
*/
@Parameter(property = "file", required = true)
- private File file;
+ private Path file;
/**
* The bundled API docs for the artifact.
@@ -124,7 +111,7 @@ public class InstallFileMojo extends AbstractMojo {
* @since 2.3
*/
@Parameter(property = "javadoc")
- private File javadoc;
+ private Path javadoc;
/**
* The bundled sources for the artifact.
@@ -132,7 +119,7 @@ public class InstallFileMojo extends AbstractMojo {
* @since 2.3
*/
@Parameter(property = "sources")
- private File sources;
+ private Path sources;
/**
* Location of an existing POM file to be installed alongside the main artifact, given by the {@link #file}
@@ -141,7 +128,7 @@ public class InstallFileMojo extends AbstractMojo {
* @since 2.1
*/
@Parameter(property = "pomFile")
- private File pomFile;
+ private Path pomFile;
/**
* Generate a minimal POM for the artifact if none is supplied via the parameter {@link #pomFile}. Defaults to
@@ -159,152 +146,145 @@ public class InstallFileMojo extends AbstractMojo {
* @since 2.2
*/
@Parameter(property = "localRepositoryPath")
- private File localRepositoryPath;
-
- private static final Predicate IS_EMPTY = s -> isNull(s) || s.isEmpty();
-
- private static final Predicate IS_POM_PACKAGING = "pom"::equals;
+ private Path localRepositoryPath;
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- if (!file.exists()) {
- String message = "The specified file '" + file.getPath() + "' does not exist";
- getLog().error(message);
- throw new MojoFailureException(message);
+ public void execute() {
+ if (!Files.exists(file)) {
+ String message = "The specified file '" + file + "' does not exist";
+ log.error(message);
+ throw new MojoException(message);
}
- RepositorySystemSession repositorySystemSession = session.getRepositorySession();
+ Session session = this.session;
+
+ List installableArtifacts = new ArrayList<>();
+
+ // Override the default local repository
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));
- newSession.setLocalRepositoryManager(localRepositoryManager);
- repositorySystemSession = newSession;
- getLog().debug("localRepoPath: "
- + localRepositoryManager.getRepository().getBasedir());
- }
+ session = session.withLocalRepository(session.createLocalRepository(localRepositoryPath));
- File temporaryPom = null;
+ log.debug("localRepoPath: " + localRepositoryPath);
+ }
- if (pomFile == null) {
- temporaryPom = readingPomFromJarFile();
+ Path deployedPom;
+ Path temporaryPom = null;
+ if (pomFile != null) {
+ deployedPom = pomFile;
+ processModel(readModel(deployedPom));
+ } else {
if (!Boolean.TRUE.equals(generatePom)) {
- pomFile = temporaryPom;
- getLog().debug("Using JAR embedded POM as pomFile");
+ temporaryPom = readingPomFromJarFile();
+ deployedPom = temporaryPom;
+ if (deployedPom != null) {
+ log.debug("Using JAR embedded POM as pomFile");
+ }
+ } else {
+ deployedPom = null;
}
- } else {
- processModel(readModel(pomFile));
}
- if (isNull(groupId) || isNull(artifactId) || isNull(version) || isNull(packaging)) {
- throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', "
+ if (groupId == null || artifactId == null || version == null || packaging == null) {
+ throw new MojoException("The artifact information is incomplete: 'groupId', 'artifactId', "
+ "'version' and 'packaging' are required.");
}
if (!isValidId(groupId) || !isValidId(artifactId) || !isValidVersion(version)) {
- throw new MojoExecutionException("The artifact information is not valid: uses invalid characters.");
+ throw new MojoException("The artifact information is not valid: uses invalid characters.");
}
- InstallRequest installRequest = new InstallRequest();
+ boolean isFilePom = classifier == null && "pom".equals(packaging);
+ Artifact artifact = session.createArtifact(
+ groupId, artifactId, version, classifier, isFilePom ? "pom" : getExtension(file), packaging);
- boolean isFilePom = isNull(classifier) && IS_POM_PACKAGING.test(packaging);
- if (!isFilePom) {
- ArtifactType artifactType =
- repositorySystemSession.getArtifactTypeRegistry().get(packaging);
- if (nonNull(artifactType) && IS_EMPTY.test(classifier) && !IS_EMPTY.test(artifactType.getClassifier())) {
- classifier = artifactType.getClassifier();
- }
+ if (file.equals(getLocalRepositoryFile(artifact))) {
+ throw new MojoException("Cannot install artifact. "
+ + "Artifact is already in the local repository.\n\nFile in question is: " + file + "\n");
}
- Artifact mainArtifact = new DefaultArtifact(
- groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
- .setFile(file);
- installRequest.addArtifact(mainArtifact);
-
- File artifactLocalFile = getLocalRepositoryFile(repositorySystemSession, mainArtifact);
- File pomLocalFile = getPomLocalRepositoryFile(repositorySystemSession, mainArtifact);
- if (file.equals(artifactLocalFile)) {
- throw new MojoFailureException("Cannot install artifact. " + "Artifact is already in the local repository."
- + LS + LS + "File in question is: " + file + LS);
- }
+ ArtifactManager artifactManager = session.getService(ArtifactManager.class);
+ artifactManager.setPath(artifact, file);
+ installableArtifacts.add(artifact);
- if (!IS_POM_PACKAGING.test(packaging)) {
- if (isNull(pomFile)) {
- if (Boolean.TRUE.equals(generatePom) || (generatePom == null && !pomLocalFile.exists())) {
- temporaryPom = generatePomFile();
- getLog().debug("Installing generated POM");
- installRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", temporaryPom));
+ if (!isFilePom) {
+ Artifact pomArtifact = session.createArtifact(groupId, artifactId, version, null, "pom", null);
+ if (deployedPom != null) {
+ artifactManager.setPath(pomArtifact, deployedPom);
+ installableArtifacts.add(pomArtifact);
+ } else {
+ temporaryPom = generatePomFile();
+ deployedPom = temporaryPom;
+ artifactManager.setPath(pomArtifact, deployedPom);
+ if (Boolean.TRUE.equals(generatePom)
+ || (generatePom == null && !Files.exists(getLocalRepositoryFile(pomArtifact)))) {
+ log.debug("Installing generated POM");
+ installableArtifacts.add(pomArtifact);
} else if (generatePom == null) {
- getLog().debug("Skipping installation of generated POM, already present in local repository");
+ log.debug("Skipping installation of generated POM, already present in local repository");
}
- } else {
- installRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", pomFile));
}
}
if (sources != null) {
- installRequest.addArtifact(new SubArtifact(mainArtifact, "sources", "jar", sources));
+ Artifact sourcesArtifact = session.createArtifact(groupId, artifactId, version, "sources", "jar", null);
+ artifactManager.setPath(sourcesArtifact, sources);
+ installableArtifacts.add(sourcesArtifact);
}
if (javadoc != null) {
- installRequest.addArtifact(new SubArtifact(mainArtifact, "javadoc", "jar", javadoc));
+ Artifact javadocArtifact = session.createArtifact(groupId, artifactId, version, "javadoc", "jar", null);
+ artifactManager.setPath(javadocArtifact, javadoc);
+ installableArtifacts.add(javadocArtifact);
}
try {
- repositorySystem.install(repositorySystemSession, installRequest);
- } catch (InstallationException e) {
- throw new MojoExecutionException(e.getMessage(), e);
+ ArtifactInstaller artifactInstaller = session.getService(ArtifactInstaller.class);
+ artifactInstaller.install(session, installableArtifacts);
+ } catch (ArtifactInstallerException e) {
+ throw new MojoException(e.getMessage(), e);
} finally {
if (temporaryPom != null) {
- // noinspection ResultOfMethodCallIgnored
- temporaryPom.delete();
+ try {
+ Files.deleteIfExists(temporaryPom);
+ } catch (IOException e) {
+ // ignore
+ }
}
}
}
- private static final Pattern POM_ENTRY_PATTERN = Pattern.compile("META-INF/maven/.*/pom\\.xml");
-
- private static final Predicate IS_POM_ENTRY =
- entry -> POM_ENTRY_PATTERN.matcher(entry.getName()).matches();
-
- private File readingPomFromJarFile() throws MojoExecutionException {
-
- String base = file.getName();
- if (base.contains(".")) {
- base = base.substring(0, base.lastIndexOf('.'));
- }
-
- try (JarFile jarFile = new JarFile(file)) {
-
- JarEntry pomEntry = jarFile.stream().filter(IS_POM_ENTRY).findAny().orElse(null);
-
- if (isNull(pomEntry)) {
- // This means there is no entry which matches the "pom.xml"...(or in other words: not packaged by Maven)
- getLog().info("pom.xml not found in " + file.getName());
- return null;
+ private Path readingPomFromJarFile() {
+ Pattern pomEntry = Pattern.compile("META-INF/maven/.*/pom\\.xml");
+ try {
+ try (JarFile jarFile = new JarFile(file.toFile())) {
+ JarEntry entry = jarFile.stream()
+ .filter(e -> pomEntry.matcher(e.getName()).matches())
+ .findFirst()
+ .orElse(null);
+ if (entry != null) {
+ log.debug("Loading " + entry.getName());
+
+ try (InputStream pomInputStream = jarFile.getInputStream(entry)) {
+ String base = file.getFileName().toString();
+ if (base.indexOf('.') > 0) {
+ base = base.substring(0, base.lastIndexOf('.'));
+ }
+ Path pomFile = File.createTempFile(base, ".pom").toPath();
+
+ Files.copy(pomInputStream, pomFile, StandardCopyOption.REPLACE_EXISTING);
+
+ processModel(readModel(pomFile));
+
+ return pomFile;
+ }
+ } else {
+ log.info("pom.xml not found in " + file.getFileName());
+ }
}
-
- Path tempPomFile = Files.createTempFile(base, ".pom");
-
- Files.copy(jarFile.getInputStream(pomEntry), tempPomFile, StandardCopyOption.REPLACE_EXISTING);
-
- getLog().debug("Loading " + pomEntry.getName());
- processModel(readModel(tempPomFile.toFile()));
- return tempPomFile.toFile();
-
} catch (IOException e) {
// ignore, artifact not packaged by Maven
- return null;
}
+ return null;
}
/**
@@ -312,17 +292,19 @@ private File readingPomFromJarFile() throws MojoExecutionException {
*
* @param pomFile The path of the POM file to parse, must not be null
.
* @return The model from the POM file, never null
.
- * @throws MojoExecutionException If the POM could not be parsed.
+ * @throws MojoException If the POM could not be parsed.
*/
- private Model readModel(File pomFile) throws MojoExecutionException {
- try (InputStream reader = Files.newInputStream(pomFile.toPath())) {
- return new MavenXpp3Reader().read(reader);
+ private Model readModel(Path pomFile) throws MojoException {
+ try {
+ try (InputStream is = Files.newInputStream(pomFile)) {
+ return session.getService(ModelXmlFactory.class).read(is);
+ }
} catch (FileNotFoundException e) {
- throw new MojoExecutionException("File not found " + pomFile, e);
+ throw new MojoException("File not found " + pomFile, e);
} catch (IOException e) {
- throw new MojoExecutionException("Error reading POM " + pomFile, e);
- } catch (XmlPullParserException e) {
- throw new MojoExecutionException("Error parsing POM " + pomFile, e);
+ throw new MojoException("Error reading POM " + pomFile, e);
+ } catch (XmlReaderException e) {
+ throw new MojoException("Error parsing POM " + pomFile, e);
}
}
@@ -360,18 +342,14 @@ private void processModel(Model model) {
* @return The generated model, never null
.
*/
private Model generateModel() {
- Model model = new Model();
-
- model.setModelVersion("4.0.0");
-
- model.setGroupId(groupId);
- model.setArtifactId(artifactId);
- model.setVersion(version);
- model.setPackaging(packaging);
-
- model.setDescription("POM was created from install:install-file");
-
- return model;
+ return Model.newBuilder()
+ .modelVersion("4.0.0")
+ .groupId(groupId)
+ .artifactId(artifactId)
+ .version(version)
+ .packaging(packaging)
+ .description("POM was created from install:install-file")
+ .build();
}
/**
@@ -379,19 +357,18 @@ private Model generateModel() {
* the generated file when no longer needed.
*
* @return The path to the generated POM file, never null
.
- * @throws MojoExecutionException If the POM file could not be generated.
+ * @throws MojoException If the POM file could not be generated.
*/
- private File generatePomFile() throws MojoExecutionException {
+ private Path generatePomFile() throws MojoException {
Model model = generateModel();
try {
- Path tempPomFile = Files.createTempFile("mvninstall", ".pom");
-
- try (OutputStream writer = Files.newOutputStream(tempPomFile)) {
- new MavenXpp3Writer().write(writer, model);
- return tempPomFile.toFile();
+ Path pomFile = File.createTempFile("mvninstall", ".pom").toPath();
+ try (Writer writer = Files.newBufferedWriter(pomFile)) {
+ session.getService(ModelXmlFactory.class).write(model, writer);
}
+ return pomFile;
} catch (IOException e) {
- throw new MojoExecutionException("Error writing temporary POM file: " + e.getMessage(), e);
+ throw new MojoException("Error writing temporary POM file: " + e.getMessage(), e);
}
}
@@ -399,33 +376,21 @@ private File generatePomFile() throws MojoExecutionException {
* Gets the path of the specified artifact within the local repository. Note that the returned path need not exist
* (yet).
*/
- private File getLocalRepositoryFile(RepositorySystemSession session, Artifact artifact) {
- String path = session.getLocalRepositoryManager().getPathForLocalArtifact(artifact);
- return new File(session.getLocalRepository().getBasedir(), path);
- }
-
- /**
- * Gets the path of the specified artifact POM within the local repository. Note that the returned path need
- * not exist (yet).
- */
- private File getPomLocalRepositoryFile(RepositorySystemSession session, Artifact artifact) {
- SubArtifact pomArtifact = new SubArtifact(artifact, "", "pom");
- String path = session.getLocalRepositoryManager().getPathForLocalArtifact(pomArtifact);
- return new File(session.getLocalRepository().getBasedir(), path);
+ private Path getLocalRepositoryFile(Artifact artifact) {
+ return session.getPathForLocalArtifact(artifact);
}
- // these below should be shared (duplicated in m-install-p, m-deploy-p)
-
/**
- * Specialization of {@link FileUtils#getExtension(String)} that honors various {@code tar.xxx} combinations.
+ * Get file extension, honoring various {@code tar.xxx} combinations.
*/
- private String getExtension(final File file) {
- String filename = file.getName();
- if (filename.contains(".tar.")) {
- return "tar." + FileUtils.getExtension(filename);
- } else {
- return FileUtils.getExtension(filename);
+ private String getExtension(final Path file) {
+ String filename = file.getFileName().toString();
+ int lastDot = filename.lastIndexOf('.');
+ if (lastDot > 0 && lastDot < filename.length() - 1) {
+ String ext = filename.substring(lastDot + 1);
+ return filename.regionMatches(lastDot + 1 - TAR.length(), TAR, 0, TAR.length()) ? TAR + ext : ext;
}
+ return "";
}
/**
@@ -449,8 +414,6 @@ private boolean isValidId(String id) {
return true;
}
- private static final String ILLEGAL_VERSION_CHARS = "\\/:\"<>|?*[](){},";
-
/**
* Returns {@code true} if passed in string is "valid Maven (simple. non range, expression, etc) version".
*/
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
index 35eb1c1d..bd9699ac 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
@@ -18,50 +18,46 @@
*/
package org.apache.maven.plugins.install;
-import java.io.File;
+import java.nio.file.Files;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.function.Predicate;
+import java.util.Objects;
import java.util.stream.Collectors;
-import org.apache.maven.RepositoryUtils;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.model.PluginExecution;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.ProjectArtifact;
-import org.eclipse.aether.RepositorySystem;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.installation.InstallRequest;
-import org.eclipse.aether.installation.InstallationException;
-import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.plugin.Log;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectManager;
/**
* Installs the project's main artifact, and any other artifacts attached by other plugins in the lifecycle, to the
* local repository.
- *
- * @author Emmanuel Venisse
*/
-@Mojo(name = "install", defaultPhase = LifecyclePhase.INSTALL, threadSafe = true)
-public class InstallMojo extends AbstractMojo {
- @Component
- private RepositorySystem repositorySystem;
+@SuppressWarnings("unused")
+@Mojo(name = "install", defaultPhase = "install")
+public class InstallMojo implements org.apache.maven.api.plugin.Mojo {
+ @Inject
+ private Log log;
- @Parameter(defaultValue = "${session}", required = true, readonly = true)
- private MavenSession session;
+ @Inject
+ private Session session;
- @Parameter(defaultValue = "${project}", readonly = true, required = true)
- private MavenProject project;
+ @Inject
+ private Project project;
- @Parameter(defaultValue = "${plugin}", required = true, readonly = true)
- private PluginDescriptor pluginDescriptor;
+ @Inject
+ private MojoExecution mojoExecution;
/**
* Whether every project should be installed during its own install-phase or at the end of the multimodule build. If
@@ -70,7 +66,7 @@ public class InstallMojo extends AbstractMojo {
*
* @since 2.5
*/
- @Parameter(defaultValue = "false", property = "installAtEnd")
+ @Parameter(property = "installAtEnd", defaultValue = "false")
private boolean installAtEnd;
/**
@@ -91,7 +87,7 @@ public class InstallMojo extends AbstractMojo {
*
* @since 3.1.1
*/
- @Parameter(defaultValue = "false", property = "allowIncompleteProjects")
+ @Parameter(property = "allowIncompleteProjects", defaultValue = "false")
private boolean allowIncompleteProjects;
private enum State {
@@ -102,146 +98,143 @@ private enum State {
private static final String INSTALL_PROCESSED_MARKER = InstallMojo.class.getName() + ".processed";
+ public InstallMojo() {}
+
private void putState(State state) {
- getPluginContext().put(INSTALL_PROCESSED_MARKER, state.name());
+ session.getPluginContext(project).put(INSTALL_PROCESSED_MARKER, state.name());
}
- private State getState(MavenProject project) {
- Map pluginContext = session.getPluginContext(pluginDescriptor, project);
+ private void putState(State state, ArtifactInstallerRequest request) {
+ session.getPluginContext(project).put(INSTALL_PROCESSED_MARKER, state.name());
+ session.getPluginContext(project).put(ArtifactInstallerRequest.class.getName(), request);
+ }
+
+ private State getState(Project project) {
+ Map pluginContext = session.getPluginContext(project);
return State.valueOf((String) pluginContext.get(INSTALL_PROCESSED_MARKER));
}
- private boolean hasState(MavenProject project) {
- Map pluginContext = session.getPluginContext(pluginDescriptor, project);
+ private boolean hasState(Project project) {
+ Map pluginContext = session.getPluginContext(project);
return pluginContext.containsKey(INSTALL_PROCESSED_MARKER);
}
+ private boolean usingPlugin(Project project) {
+ Plugin plugin = project.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-install-plugin");
+ return plugin != null
+ && plugin.getExecutions().stream()
+ .anyMatch(e -> Objects.equals(e.getId(), mojoExecution.getExecutionId())
+ && !"none".equals(e.getPhase()));
+ }
+
@Override
- public void execute() throws MojoExecutionException {
+ public void execute() {
if (skip) {
- getLog().info("Skipping artifact installation");
+ log.info("Skipping artifact installation");
putState(State.SKIPPED);
} else {
- if (installAtEnd) {
+ if (!installAtEnd) {
+ installProject(processProject(project));
+ putState(State.INSTALLED);
+ } else {
getLog().info("Deferring install for " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ project.getVersion() + " at end");
- putState(State.TO_BE_INSTALLED);
- } else {
- InstallRequest request = new InstallRequest();
- processProject(project, request);
- installProject(request);
- putState(State.INSTALLED);
+ putState(State.TO_BE_INSTALLED, processProject(project));
}
}
- List allProjectsUsingPlugin = getAllProjectsUsingPlugin();
-
- if (allProjectsMarked(allProjectsUsingPlugin)) {
- InstallRequest request = new InstallRequest();
- for (MavenProject reactorProject : allProjectsUsingPlugin) {
+ List projectsUsingPlugin =
+ session.getProjects().stream().filter(this::usingPlugin).collect(Collectors.toList());
+ if (allProjectsMarked(projectsUsingPlugin)) {
+ for (Project reactorProject : projectsUsingPlugin) {
State state = getState(reactorProject);
if (state == State.TO_BE_INSTALLED) {
- processProject(reactorProject, request);
+ Map pluginContext = session.getPluginContext(reactorProject);
+ ArtifactInstallerRequest request =
+ (ArtifactInstallerRequest) pluginContext.get(ArtifactInstallerRequest.class.getName());
+ installProject(request);
}
}
- installProject(request);
}
}
- private boolean allProjectsMarked(List allProjectsUsingPlugin) {
- return allProjectsUsingPlugin.stream().allMatch(this::hasState);
- }
-
- private final Predicate hasMavenInstallPluginExecution =
- rp -> hasExecution(rp.getPlugin("org.apache.maven.plugins:maven-install-plugin"));
-
- private List getAllProjectsUsingPlugin() {
- return session.getProjects().stream()
- .filter(hasMavenInstallPluginExecution)
- .collect(Collectors.toList());
- }
-
- private final Predicate havingGoals = pe -> !pe.getGoals().isEmpty();
- private final Predicate nonePhase = pe -> !"none".equalsIgnoreCase(pe.getPhase());
-
- private boolean hasExecution(Plugin plugin) {
- if (plugin == null) {
- return false;
- }
-
- return plugin.getExecutions().stream().filter(havingGoals).anyMatch(nonePhase);
+ private boolean allProjectsMarked(List projectsUsingPlugin) {
+ return projectsUsingPlugin.stream().allMatch(this::hasState);
}
- private void installProject(InstallRequest request) throws MojoExecutionException {
+ private void installProject(ArtifactInstallerRequest request) {
try {
- repositorySystem.install(session.getRepositorySession(), request);
- } catch (InstallationException e) {
- throw new MojoExecutionException(e.getMessage(), e);
+ getArtifactInstaller().install(request);
+ } catch (MojoException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new MojoException(e.getMessage(), e);
}
}
/**
- * Processes passed in {@link MavenProject} and prepares content of {@link InstallRequest} out of it.
+ * Processes passed in {@link Project} and produces {@link ArtifactInstallerRequest} out of it.
*
- * @throws MojoExecutionException if project is badly set up.
+ * @throws IllegalArgumentException if project is badly set up.
*/
- private void processProject(MavenProject project, InstallRequest request) throws MojoExecutionException {
- // always exists, as project exists
- Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project));
- // always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged)
- Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact());
-
- // pom project: pomArtifact and projectArtifact are SAME
- // jar project: pomArtifact and projectArtifact are DIFFERENT
- // incomplete project: is not pom project and projectArtifact has no file
-
- // we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in)
- // BUT if projectArtifact has file set, use that one
- if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) {
- if (isFile(projectArtifact.getFile())) {
- pomArtifact = projectArtifact;
- }
- projectArtifact = null;
- }
-
- if (isFile(pomArtifact.getFile())) {
- request.addArtifact(pomArtifact);
- } else {
- throw new MojoExecutionException(
- "The POM for project " + project.getArtifactId() + " could not be attached");
- }
-
- // is not packaged, is "incomplete"
- boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile());
- if (projectArtifact != null) {
- if (!isIncomplete) {
- request.addArtifact(projectArtifact);
- } else if (!project.getAttachedArtifacts().isEmpty()) {
- if (allowIncompleteProjects) {
- getLog().warn("");
- getLog().warn("The packaging plugin for project " + project.getArtifactId() + " did not assign");
- getLog().warn("a main file to the project but it has attachments. Change packaging to 'pom'.");
- getLog().warn("");
- getLog().warn("Incomplete projects like this will fail in future Maven versions!");
- getLog().warn("");
+ private ArtifactInstallerRequest processProject(Project project) {
+ ProjectManager projectManager = getProjectManager();
+ Collection installables = projectManager.getAllArtifacts(project);
+ Collection attachedArtifacts = projectManager.getAttachedArtifacts(project);
+
+ getArtifactManager().setPath(project.getPomArtifact(), project.getPomPath());
+
+ for (Artifact installable : installables) {
+ if (!isValidPath(installable)) {
+ if (installable == project.getMainArtifact().orElse(null)) {
+ if (attachedArtifacts.isEmpty()) {
+ throw new MojoException(
+ "The packaging for this project did not assign a file to the build artifact");
+ } else {
+ if (allowIncompleteProjects) {
+ getLog().warn("");
+ getLog().warn("The packaging plugin for this project did not assign");
+ getLog().warn(
+ "a main file to the project but it has attachments. Change packaging to 'pom'.");
+ getLog().warn("");
+ getLog().warn("Incomplete projects like this will fail in future Maven versions!");
+ getLog().warn("");
+ } else {
+ throw new MojoException("The packaging plugin for this project did not assign "
+ + "a main file to the project but it has attachments. Change packaging to 'pom'.");
+ }
+ }
} else {
- throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
- + " did not assign a main file to the project but it has attachments. Change packaging"
- + " to 'pom'.");
+ throw new MojoException("The packaging for this project did not assign "
+ + "a file to the attached artifact: " + installable);
}
- } else {
- throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
- + " did not assign a file to the build artifact");
}
}
- for (org.apache.maven.artifact.Artifact attached : project.getAttachedArtifacts()) {
- getLog().debug("Attaching for install: " + attached.getId());
- request.addArtifact(RepositoryUtils.toArtifact(attached));
- }
+ return ArtifactInstallerRequest.build(session, installables);
+ }
+
+ private boolean isValidPath(Artifact a) {
+ return getArtifactManager().getPath(a).filter(Files::isRegularFile).isPresent();
+ }
+
+ void setSkip(boolean skip) {
+ this.skip = skip;
+ }
+
+ protected Log getLog() {
+ return log;
+ }
+
+ private ArtifactInstaller getArtifactInstaller() {
+ return session.getService(ArtifactInstaller.class);
+ }
+
+ private ArtifactManager getArtifactManager() {
+ return session.getService(ArtifactManager.class);
}
- private boolean isFile(File file) {
- return file != null && file.isFile();
+ private ProjectManager getProjectManager() {
+ return session.getService(ProjectManager.class);
}
}
diff --git a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
index 5094468a..0d00731a 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
@@ -19,340 +19,345 @@
package org.apache.maven.plugins.install;
import java.io.File;
-import java.io.Reader;
-
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.ProjectBuildingRequest;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.LocalRepository;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.api.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
+import org.apache.maven.api.plugin.testing.stubs.SessionMock;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.xml.ModelXmlFactory;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.xml.XmlStreamReader;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
-import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory;
-import org.eclipse.aether.internal.impl.DefaultTrackingFileManager;
-import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
-
-import static org.mockito.Mockito.mock;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
/**
* @author Allan Ramirez
*/
-public class InstallFileMojoTest extends AbstractMojoTestCase {
- private String groupId;
+@MojoTest
+public class InstallFileMojoTest {
+ private static final String LOCAL_REPO = "target/local-repo";
+ private String groupId;
private String artifactId;
-
private String version;
-
private String packaging;
-
private String classifier;
+ private Path file;
- private File file;
+ @Inject
+ Session session;
- private final String LOCAL_REPO = "target/local-repo/";
+ @Inject
+ ArtifactManager artifactManager;
- private final String SPECIFIC_LOCAL_REPO = "target/specific-local-repo/";
+ @Inject
+ ArtifactInstaller artifactInstaller;
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
FileUtils.deleteDirectory(new File(getBasedir() + "/" + LOCAL_REPO));
- FileUtils.deleteDirectory(new File(getBasedir() + "/" + SPECIFIC_LOCAL_REPO));
}
- public void testInstallFileFromLocalRepositoryToLocalRepositoryPath() throws Exception {
- File localRepository =
- new File(getBasedir(), "target/test-classes/unit/install-file-from-local-repository-test/target");
-
- File testPom = new File(localRepository.getParentFile(), "plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(
+ name = "file",
+ value = "${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+ public void testInstallFileTestEnvironment(InstallFileMojo mojo) {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(localRepository.getAbsolutePath()));
-
- File specificLocalRepositoryPath = new File(getBasedir() + "/" + SPECIFIC_LOCAL_REPO);
-
- setVariableValueToObject(mojo, "localRepositoryPath", specificLocalRepositoryPath);
-
- assignValuesForParameter(mojo);
-
- mojo.execute();
-
- String localPath = getBasedir() + "/" + SPECIFIC_LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
- + artifactId + "-" + version;
-
- File installedArtifact = new File(localPath + "." + "jar");
-
- assertTrue(installedArtifact.exists());
-
- assertEquals(
- FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).toString(),
- 5,
- FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).size());
}
- public void testInstallFileWithLocalRepositoryPath() throws Exception {
- File testPom =
- new File(getBasedir(), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(
+ name = "file",
+ value = "${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+ public void testBasicInstallFile(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
- File specificLocalRepositoryPath = new File(getBasedir() + "/" + SPECIFIC_LOCAL_REPO);
-
- setVariableValueToObject(mojo, "localRepositoryPath", specificLocalRepositoryPath);
-
assignValuesForParameter(mojo);
mojo.execute();
- String localPath = getBasedir() + "/" + SPECIFIC_LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
- + artifactId + "-" + version;
-
- File installedArtifact = new File(localPath + "." + "jar");
-
- assertTrue(installedArtifact.exists());
+ ArtifactInstallerRequest request = execute(mojo);
+ assertNotNull(request);
+ Set artifacts = new HashSet<>(request.getArtifacts());
+ Artifact pom = getArtifact(null, "pom");
+ Artifact jar = getArtifact(null, "jar");
+ assertEquals(new HashSet<>(Arrays.asList(pom, jar)), artifacts);
+ assertFileExists(artifactManager.getPath(jar).orElse(null));
+ assertFileExists(artifactManager.getPath(jar).orElse(null));
assertEquals(
- FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).toString(),
- 5,
- FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).size());
- }
-
- public void testInstallFileTestEnvironment() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
- assertNotNull(mojo);
+ LOCAL_REPO,
+ request.getSession().getLocalRepository().getPath().toString().replace(File.separator, "/"));
}
- public void testBasicInstallFile() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(name = "file", value = "${project.basedir}/target/test-classes/unit/file-does-not-exist.jar")
+ public void testFileDoesNotExists(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
assignValuesForParameter(mojo);
- mojo.execute();
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
- + packaging);
-
- assertTrue(installedArtifact.exists());
-
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ assertThrows(MojoException.class, mojo::execute);
}
- public void testInstallFileWithClassifier() throws Exception {
- File testPom =
- new File(getBasedir(), "target/test-classes/unit/install-file-with-classifier/plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(name = "classifier", value = "sources")
+ @MojoParameter(
+ name = "file",
+ value = "${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+ public void testInstallFileWithClassifier(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
assignValuesForParameter(mojo);
-
assertNotNull(classifier);
- mojo.execute();
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-"
- + classifier + "." + packaging);
-
- assertTrue(installedArtifact.exists());
+ ArtifactInstallerRequest request = execute(mojo);
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ assertNotNull(request);
+ Set artifacts = new HashSet<>(request.getArtifacts());
+ Artifact pom = getArtifact(null, "pom");
+ Artifact sources = getArtifact("sources", "jar");
+ assertEquals(new HashSet<>(Arrays.asList(pom, sources)), artifacts);
+ // pom file does not exists, as it should have been deleted after the installation
+ assertFileNotExists(artifactManager.getPath(pom).get());
+ assertFileExists(artifactManager.getPath(sources).get());
+ assertEquals(
+ LOCAL_REPO,
+ request.getSession().getLocalRepository().getPath().toString().replace(File.separator, "/"));
}
- public void testInstallFileWithGeneratePom() throws Exception {
- File testPom =
- new File(getBasedir(), "target/test-classes/unit/install-file-test-generatePom/plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(
+ name = "file",
+ value = "${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+ @MojoParameter(name = "generatePom", value = "true")
+ public void testInstallFileWithGeneratePom(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
assignValuesForParameter(mojo);
-
- mojo.execute();
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
- + packaging);
-
assertTrue((Boolean) getVariableValueFromObject(mojo, "generatePom"));
- assertTrue(installedArtifact.exists());
-
- File installedPom = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
- + "pom");
-
- try (Reader reader = new XmlStreamReader(installedPom)) {
- Model model = new MavenXpp3Reader().read(reader);
-
- assertEquals("4.0.0", model.getModelVersion());
-
- assertEquals((String) getVariableValueFromObject(mojo, "groupId"), model.getGroupId());
-
- assertEquals(artifactId, model.getArtifactId());
+ AtomicReference model = new AtomicReference<>();
+ ArtifactInstallerRequest request = execute(mojo, air -> model.set(readModel(getArtifact(null, "pom"))));
+
+ assertNotNull(request);
+ Set artifacts = new HashSet<>(request.getArtifacts());
+ Artifact pom = getArtifact(null, "pom");
+ Artifact jar = getArtifact(null, "jar");
+ assertEquals(new HashSet<>(Arrays.asList(pom, jar)), artifacts);
+ assertEquals("4.0.0", model.get().getModelVersion());
+ assertEquals(getVariableValueFromObject(mojo, "groupId"), model.get().getGroupId());
+ assertEquals(artifactId, model.get().getArtifactId());
+ assertEquals(version, model.get().getVersion());
+ assertNotNull(artifactManager.getPath(jar).orElse(null));
+ assertEquals(
+ LOCAL_REPO,
+ request.getSession().getLocalRepository().getPath().toString().replace(File.separator, "/"));
+ }
- assertEquals(version, model.getVersion());
+ private Model readModel(Artifact pom) {
+ try {
+ Path pomPath = artifactManager.getPath(pom).orElse(null);
+ assertNotNull(pomPath);
+ return session.getService(ModelXmlFactory.class).read(pomPath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
}
-
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallFileWithPomFile() throws Exception {
- File testPom =
- new File(getBasedir(), "target/test-classes/unit/install-file-with-pomFile-test/plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(
+ name = "file",
+ value = "${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+ @MojoParameter(name = "pomFile", value = "${project.basedir}/src/test/resources/unit/pom.xml")
+ public void testInstallFileWithPomFile(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
assignValuesForParameter(mojo);
+ Path pomFile = (Path) getVariableValueFromObject(mojo, "pomFile");
- mojo.execute();
-
- File pomFile = (File) getVariableValueFromObject(mojo, "pomFile");
-
- assertTrue(pomFile.exists());
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
- + packaging);
-
- assertTrue(installedArtifact.exists());
+ ArtifactInstallerRequest request = execute(mojo);
- File installedPom = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
- + "pom");
-
- assertTrue(installedPom.exists());
-
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ assertNotNull(request);
+ Set artifacts = new HashSet<>(request.getArtifacts());
+ Artifact pom = getArtifact(null, "pom");
+ Artifact jar = getArtifact(null, "jar");
+ assertEquals(new HashSet<>(Arrays.asList(pom, jar)), artifacts);
+ assertEquals(pomFile, artifactManager.getPath(pom).orElse(null));
+ assertNotNull(artifactManager.getPath(jar).orElse(null));
+ assertEquals(
+ LOCAL_REPO,
+ request.getSession().getLocalRepository().getPath().toString().replace(File.separator, "/"));
}
- public void testInstallFileWithPomAsPackaging() throws Exception {
- File testPom = new File(
- getBasedir(), "target/test-classes/unit/install-file-with-pom-as-packaging/" + "plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "pom")
+ @MojoParameter(name = "file", value = "${project.basedir}/target/test-classes/unit/pom.xml")
+ public void testInstallFileWithPomAsPackaging(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
assignValuesForParameter(mojo);
-
- assertTrue(file.exists());
-
+ assertTrue(Files.exists(file));
assertEquals("pom", packaging);
- mojo.execute();
-
- File installedPom = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
- + "pom");
+ ArtifactInstallerRequest request = execute(mojo);
- assertTrue(installedPom.exists());
-
- assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ assertNotNull(request);
+ Set artifacts = new HashSet<>(request.getArtifacts());
+ Artifact pom = getArtifact(null, "pom");
+ assertEquals(Collections.singleton(pom), artifacts);
}
- public void testInstallFile() throws Exception {
- File testPom =
- new File(getBasedir(), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml");
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
-
+ @Test
+ @InjectMojo(goal = "install-file")
+ @MojoParameter(name = "groupId", value = "org.apache.maven.test")
+ @MojoParameter(name = "artifactId", value = "maven-install-file-test")
+ @MojoParameter(name = "version", value = "1.0-SNAPSHOT")
+ @MojoParameter(name = "packaging", value = "jar")
+ @MojoParameter(
+ name = "file",
+ value = "${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+ @MojoParameter(name = "pomFile", value = "${project.basedir}/target/test-classes/unit/pom.xml")
+ public void testInstallFile(InstallFileMojo mojo) throws Exception {
assertNotNull(mojo);
-
- setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
-
assignValuesForParameter(mojo);
- mojo.execute();
-
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
- + artifactId + "-" + version;
-
- File installedArtifact = new File(localPath + "." + "jar");
-
- assertTrue(installedArtifact.exists());
+ ArtifactInstallerRequest request = execute(mojo);
+ assertNotNull(request);
+ Set artifacts = new HashSet<>(request.getArtifacts());
+ Artifact pom = getArtifact(null, "pom");
+ Artifact jar = getArtifact(null, "jar");
+ assertEquals(new HashSet<>(Arrays.asList(pom, jar)), artifacts);
assertEquals(
- FileUtils.getFiles(new File(LOCAL_REPO), null, null).toString(),
- 5,
- FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ LOCAL_REPO,
+ request.getSession().getLocalRepository().getPath().toString().replace(File.separator, "/"));
}
private void assignValuesForParameter(Object obj) throws Exception {
- this.groupId = dotToSlashReplacer((String) getVariableValueFromObject(obj, "groupId"));
-
+ this.groupId = (String) getVariableValueFromObject(obj, "groupId");
this.artifactId = (String) getVariableValueFromObject(obj, "artifactId");
-
this.version = (String) getVariableValueFromObject(obj, "version");
-
this.packaging = (String) getVariableValueFromObject(obj, "packaging");
-
this.classifier = (String) getVariableValueFromObject(obj, "classifier");
+ this.file = (Path) getVariableValueFromObject(obj, "file");
+ }
- this.file = (File) getVariableValueFromObject(obj, "file");
+ private ArtifactStub getArtifact(String classifier, String extension) {
+ return new ArtifactStub(groupId, artifactId, classifier != null ? classifier : "", version, extension);
}
- private String dotToSlashReplacer(String parameter) {
- return parameter.replace('.', '/');
+ private ArtifactInstallerRequest execute(InstallFileMojo mojo) {
+ return execute(mojo, null);
+ }
+
+ private ArtifactInstallerRequest execute(InstallFileMojo mojo, Consumer consumer) {
+ AtomicReference request = new AtomicReference<>();
+ doAnswer(iom -> {
+ ArtifactInstallerRequest req = iom.getArgument(0, ArtifactInstallerRequest.class);
+ request.set(req);
+ if (consumer != null) {
+ consumer.accept(req);
+ }
+ return null;
+ })
+ .when(artifactInstaller)
+ .install(any(ArtifactInstallerRequest.class));
+ mojo.execute();
+ return request.get();
}
- private MavenSession createMavenSession(String localRepositoryBaseDir) throws NoLocalRepositoryManagerException {
- MavenSession session = mock(MavenSession.class);
- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory(
- new DefaultLocalPathComposer(),
- new DefaultTrackingFileManager(),
- new DefaultLocalPathPrefixComposerFactory())
- .newInstance(repositorySession, new LocalRepository(localRepositoryBaseDir)));
- ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
- buildingRequest.setRepositorySession(repositorySession);
- when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
- when(session.getRepositorySession()).thenReturn(repositorySession);
+ private void assertFileExists(Path path) {
+ assertTrue(path != null && Files.exists(path), () -> path + " should exists");
+ }
+
+ private void assertFileNotExists(Path path) {
+ assertFalse(path != null && Files.exists(path), () -> path + " should not exists");
+ }
+
+ @Provides
+ @Singleton
+ @Priority(10)
+ @SuppressWarnings("unused")
+ private static Session createMavenSession() {
+ Session session = SessionMock.getMockSession(LOCAL_REPO);
+ when(session.withLocalRepository(any())).thenAnswer(iom -> {
+ LocalRepository localRepository = iom.getArgument(0, LocalRepository.class);
+ Session mockSession = SessionMock.getMockSession(localRepository);
+ when(mockSession.getService(ArtifactInstaller.class))
+ .thenAnswer(iom2 -> session.getService(ArtifactInstaller.class));
+ return mockSession;
+ });
return session;
}
+
+ @Provides
+ private static Project createProject() {
+ ProjectStub project = new ProjectStub();
+ project.setBasedir(Paths.get(getBasedir()));
+ return project;
+ }
}
diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java
new file mode 100644
index 00000000..f1da470d
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java
@@ -0,0 +1,166 @@
+/*
+ * 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.install;
+
+import java.io.File;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.Type;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.plugin.Mojo;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.api.plugin.testing.stubs.MojoExecutionStub;
+import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
+import org.apache.maven.api.plugin.testing.stubs.SessionMock;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.internal.impl.InternalSession;
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Allan Ramirez
+ */
+@MojoTest
+public class InstallMojoPomPackagingTest {
+
+ private static final String LOCAL_REPO = "target/local-repo/";
+
+ @Inject
+ Session session;
+
+ @Inject
+ ArtifactInstaller artifactInstaller;
+
+ @Inject
+ ArtifactManager artifactManager;
+
+ @Inject
+ ProjectManager projectManager;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ FileUtils.deleteDirectory(new File(getBasedir() + "/" + LOCAL_REPO));
+ }
+
+ @Test
+ @InjectMojo(goal = "install")
+ public void testInstallIfPackagingIsPom(InstallMojo mojo) throws Exception {
+ assertNotNull(mojo);
+ Project project = (Project) getVariableValueFromObject(mojo, "project");
+ String packaging = project.getPackaging().type().id();
+ assertEquals(Type.POM, packaging);
+ artifactManager.setPath(project.getPomArtifact(), project.getPomPath());
+
+ ArtifactInstallerRequest request = execute(mojo);
+
+ assertNotNull(request);
+ Collection artifacts = request.getArtifacts();
+ assertEquals(
+ Arrays.asList("org.apache.maven.test:maven-install-test:pom:1.0-SNAPSHOT"),
+ artifacts.stream().map(Artifact::key).collect(Collectors.toList()));
+ }
+
+ @Provides
+ @Singleton
+ @Priority(10)
+ @SuppressWarnings("unused")
+ private InternalSession createInternalSession() {
+ InternalSession session = SessionMock.getMockSession(LOCAL_REPO);
+ when(session.getArtifact(any()))
+ .thenAnswer(iom -> new org.apache.maven.internal.impl.DefaultArtifact(
+ session, iom.getArgument(0, org.eclipse.aether.artifact.Artifact.class)));
+ // when(session.getMavenSession()).thenAnswer(iom -> new MavenSession(null, null, null));
+ return session;
+ }
+
+ @Provides
+ @Singleton
+ @SuppressWarnings("unused")
+ private Project createProject(InternalSession session) {
+ ProjectStub project = new ProjectStub();
+ project.setBasedir(Paths.get(getBasedir()));
+ project.setPomPath(Paths.get(getBasedir(), "src/test/resources/unit/pom.xml"));
+ project.setGroupId("org.apache.maven.test");
+ project.setArtifactId("maven-install-test");
+ project.setVersion("1.0-SNAPSHOT");
+ project.setPackaging("pom");
+ // DefaultArtifact artifact = new DefaultArtifact(
+ // "org.apache.maven.test",
+ // "maven-install-test",
+ // "1.0-SNAPSHOT",
+ // null,
+ // "pom",
+ // null,
+ // new DefaultArtifactHandlerStub("pom"));
+ // project.setArtifact(artifact);
+ // project.setAttachedArtifacts(new ArrayList<>());
+ return project;
+ }
+
+ @Provides
+ @Singleton
+ private MojoExecution createMojoExecution() {
+ return new MojoExecutionStub("default-install", "install");
+ }
+
+ private ArtifactInstallerRequest execute(Mojo mojo) {
+ return execute(mojo, null);
+ }
+
+ private ArtifactInstallerRequest execute(Mojo mojo, Consumer consumer) {
+ AtomicReference request = new AtomicReference<>();
+ doAnswer(iom -> {
+ ArtifactInstallerRequest req = iom.getArgument(0, ArtifactInstallerRequest.class);
+ request.set(req);
+ if (consumer != null) {
+ consumer.accept(req);
+ }
+ return null;
+ })
+ .when(artifactInstaller)
+ .install(any(ArtifactInstallerRequest.class));
+ mojo.execute();
+ return request.get();
+ }
+}
diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
index 8176925a..f4930d59 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
@@ -19,458 +19,205 @@
package org.apache.maven.plugins.install;
import java.io.File;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugins.install.stubs.AttachedArtifactStub0;
-import org.apache.maven.plugins.install.stubs.InstallArtifactStub;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.plugin.Mojo;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.api.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.api.plugin.testing.stubs.MojoExecutionStub;
+import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
+import org.apache.maven.api.plugin.testing.stubs.SessionMock;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.internal.impl.InternalSession;
import org.codehaus.plexus.util.FileUtils;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
-import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory;
-import org.eclipse.aether.internal.impl.DefaultTrackingFileManager;
-import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
-
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
-/**
- * @author Allan Ramirez
- */
-public class InstallMojoTest extends AbstractMojoTestCase {
+@MojoTest
+public class InstallMojoTest {
- InstallArtifactStub artifact;
+ private static final String LOCAL_REPO = "target/local-repo/";
- private final String LOCAL_REPO = "target/local-repo/";
+ @Inject
+ InternalSession session;
- public void setUp() throws Exception {
- super.setUp();
+ @Inject
+ ArtifactInstaller artifactInstaller;
- FileUtils.deleteDirectory(new File(getBasedir() + "/" + LOCAL_REPO));
- }
-
- public void testInstallTestEnvironment() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
+ @Inject
+ ArtifactManager artifactManager;
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
+ @Inject
+ ProjectManager projectManager;
- assertNotNull(mojo);
+ @BeforeEach
+ public void setUp() throws Exception {
+ FileUtils.deleteDirectory(new File(getBasedir() + "/" + LOCAL_REPO));
}
- public void testBasicInstall() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
+ @Test
+ @InjectMojo(goal = "install")
+ public void testInstallTestEnvironment(InstallMojo mojo) {
assertNotNull(mojo);
-
- File file = new File(
- getBasedir(),
- "target/test-classes/unit/basic-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile(file);
-
- mojo.execute();
-
- String groupId = dotToSlashReplacer(artifact.getGroupId());
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
- + artifact.getArtifactId() + "-" + artifact.getVersion() + "."
- + artifact.getArtifactHandler().getExtension());
-
- assertTrue(installedArtifact.exists());
-
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testBasicInstallWithAttachedArtifacts() throws Exception {
- File testPom = new File(
- getBasedir(),
- "target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
+ @Test
+ @InjectMojo(goal = "install")
+ public void testBasicInstall(InstallMojo mojo) throws Exception {
assertNotNull(mojo);
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- List attachedArtifacts = project.getAttachedArtifacts();
-
- mojo.execute();
-
- String packaging = project.getPackaging();
-
- String groupId;
-
- for (Object attachedArtifact1 : attachedArtifacts) {
- AttachedArtifactStub0 attachedArtifact = (AttachedArtifactStub0) attachedArtifact1;
-
- groupId = dotToSlashReplacer(attachedArtifact.getGroupId());
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + attachedArtifact.getArtifactId()
- + "/" + attachedArtifact.getVersion() + "/" + attachedArtifact.getArtifactId()
- + "-" + attachedArtifact.getVersion() + "." + packaging);
-
- assertTrue(installedArtifact.getPath() + " does not exist", installedArtifact.exists());
- }
-
- assertEquals(13, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ Project project = (Project) getVariableValueFromObject(mojo, "project");
+ artifactManager.setPath(
+ project.getMainArtifact().get(),
+ Paths.get(getBasedir(), "target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar"));
+
+ ArtifactInstallerRequest request = execute(mojo);
+
+ assertNotNull(request);
+ Collection artifacts = request.getArtifacts();
+ assertEquals(
+ Arrays.asList(
+ "org.apache.maven.test:maven-install-test:pom:1.0-SNAPSHOT",
+ "org.apache.maven.test:maven-install-test:jar:1.0-SNAPSHOT"),
+ artifacts.stream().map(Artifact::key).collect(Collectors.toList()));
}
- public void testNonPomInstallWithAttachedArtifactsOnly() throws Exception {
- File testPom = new File(
- getBasedir(),
- "target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
+ @Test
+ @InjectMojo(goal = "install")
+ public void testBasicInstallWithAttachedArtifacts(InstallMojo mojo) throws Exception {
assertNotNull(mojo);
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
- setVariableValueToObject(mojo, "session", createMavenSession());
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile(null);
-
- try {
- mojo.execute();
- fail("Did not throw mojo execution exception");
- } catch (MojoExecutionException e) {
- // expected, message should include artifactId
- assertEquals(
- "The packaging plugin for project maven-install-test did not assign a main file to the project "
- + "but it has attachments. Change packaging to 'pom'.",
- e.getMessage());
- }
+ Project project = (Project) getVariableValueFromObject(mojo, "project");
+ projectManager.attachArtifact(
+ project,
+ new ArtifactStub("org.apache.maven.test", "attached-artifact-test", "", "1.0-SNAPSHOT", "jar"),
+ Paths.get(getBasedir(), "target/test-classes/unit/attached-artifact-test-1.0-SNAPSHOT.jar"));
+ artifactManager.setPath(
+ project.getMainArtifact().get(),
+ Paths.get(getBasedir(), "target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar"));
+
+ ArtifactInstallerRequest request = execute(mojo);
+
+ assertNotNull(request);
+ Collection artifacts = request.getArtifacts();
+ assertEquals(
+ Arrays.asList(
+ "org.apache.maven.test:maven-install-test:pom:1.0-SNAPSHOT",
+ "org.apache.maven.test:maven-install-test:jar:1.0-SNAPSHOT",
+ "org.apache.maven.test:attached-artifact-test:jar:1.0-SNAPSHOT"),
+ artifacts.stream().map(Artifact::key).collect(Collectors.toList()));
}
- public void testUpdateReleaseParamSetToTrue() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
+ @Test
+ @InjectMojo(goal = "install")
+ public void testInstallIfArtifactFileIsNull(InstallMojo mojo) throws Exception {
assertNotNull(mojo);
+ Project project = (Project) getVariableValueFromObject(mojo, "project");
+ assertFalse(artifactManager.getPath(project.getMainArtifact().get()).isPresent());
- File file = new File(
- getBasedir(),
- "target/test-classes/unit/configured-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile(file);
-
- mojo.execute();
-
- // assertTrue( artifact.isRelease() );
-
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ assertThrows(MojoException.class, mojo::execute, "Did not throw mojo execution exception");
}
- public void testInstallIfArtifactFileIsNull() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
+ @Test
+ @InjectMojo(goal = "install")
+ public void testSkip(InstallMojo mojo) throws Exception {
assertNotNull(mojo);
+ setVariableValueToObject(mojo, "session", this.session);
+ Project project = (Project) getVariableValueFromObject(mojo, "project");
+ mojo.setSkip(true);
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile(null);
-
- assertNull(artifact.getFile());
-
- try {
- mojo.execute();
- fail("Did not throw mojo execution exception");
- } catch (MojoExecutionException e) {
- // expected, message should include artifactId
- assertEquals(
- "The packaging plugin for project maven-install-test did not assign a file to the build artifact",
- e.getMessage());
- }
-
- assertFalse(new File(LOCAL_REPO).exists());
+ assertNull(execute(mojo));
}
- public void testInstallIfProjectFileIsNull() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
- assertNotNull(mojo);
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
- setVariableValueToObject(mojo, "session", createMavenSession());
-
- project.setFile(null);
-
- assertNull(project.getFile());
-
- try {
- mojo.execute();
- fail("Did not throw mojo execution exception");
- } catch (MojoExecutionException e) {
- // expected, message should include artifactId
- assertEquals("The POM for project maven-install-test could not be attached", e.getMessage());
- }
- }
-
- public void testInstallIfPackagingIsPom() throws Exception {
- File testPom = new File(
- getBasedir(), "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
- assertNotNull(mojo);
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- String packaging = project.getPackaging();
-
- assertEquals("pom", packaging);
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- mojo.execute();
-
- String groupId = dotToSlashReplacer(artifact.getGroupId());
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
- + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom");
-
- assertTrue(installedArtifact.exists());
-
- assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
- }
-
- public void testInstallIfPackagingIsBom() throws Exception {
- File testPom = new File(
- getBasedir(), "target/test-classes/unit/basic-install-test-packaging-bom/" + "plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
- assertNotNull(mojo);
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- String packaging = project.getPackaging();
-
- assertEquals("bom", packaging);
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- mojo.execute();
-
- String groupId = dotToSlashReplacer(artifact.getGroupId());
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
- + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom");
-
- assertTrue(installedArtifact.exists());
-
- assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ @Provides
+ @Singleton
+ @Priority(10)
+ @SuppressWarnings("unused")
+ private InternalSession createSession() {
+ InternalSession session = SessionMock.getMockSession(LOCAL_REPO);
+ when(session.getArtifact(any()))
+ .thenAnswer(iom -> new org.apache.maven.internal.impl.DefaultArtifact(
+ session, iom.getArgument(0, org.eclipse.aether.artifact.Artifact.class)));
+ return session;
}
- public void testBasicInstallAndCreate() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
-
- AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
-
- assertNotNull(mojo);
-
- File file = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar");
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- MavenSession mavenSession = createMavenSession();
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile(file);
-
- mojo.execute();
-
- File pom = new File(
- new File(LOCAL_REPO),
- mavenSession
- .getRepositorySession()
- .getLocalRepositoryManager()
- .getPathForLocalArtifact(new DefaultArtifact(
- artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion())));
-
- assertTrue(pom.exists());
-
- String groupId = dotToSlashReplacer(artifact.getGroupId());
- String packaging = project.getPackaging();
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/"
- + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
-
- File installedArtifact = new File(localPath + "." + packaging);
-
- assertTrue(installedArtifact.exists());
-
- assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
+ @Provides
+ @Singleton
+ @SuppressWarnings("unused")
+ private Project createProject(InternalSession session) {
+ ProjectStub project = new ProjectStub();
+ project.setBasedir(Paths.get(getBasedir()));
+ project.setPomPath(Paths.get(getBasedir(), "src/test/resources/unit/pom.xml"));
+ project.setGroupId("org.apache.maven.test");
+ project.setArtifactId("maven-install-test");
+ project.setVersion("1.0-SNAPSHOT");
+ project.setPackaging("jar");
+ ArtifactStub artifact =
+ new ArtifactStub("org.apache.maven.test", "maven-install-test", "", "1.0-SNAPSHOT", "jar");
+ project.setMainArtifact(artifact);
+ return project;
}
- public void testSkip() throws Exception {
- File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
-
- InstallMojo mojo = (InstallMojo) lookupMojo("install", testPom);
-
- assertNotNull(mojo);
-
- File file = new File(
- getBasedir(),
- "target/test-classes/unit/basic-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
-
- MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- updateMavenProject(project);
-
- MavenSession session = createMavenSession();
- session.setProjects(Collections.singletonList(project));
- setVariableValueToObject(mojo, "session", session);
- setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
- setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
- setVariableValueToObject(mojo, "skip", Boolean.TRUE);
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile(file);
-
- mojo.execute();
-
- String groupId = dotToSlashReplacer(artifact.getGroupId());
-
- String packaging = project.getPackaging();
-
- File installedArtifact = new File(
- getBasedir(),
- LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
- + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + packaging);
-
- assertFalse(installedArtifact.exists());
-
- assertFalse(new File(LOCAL_REPO).exists());
+ @Provides
+ @Singleton
+ private MojoExecution createMojoExecution() {
+ return new MojoExecutionStub("default-install", "install");
}
- private String dotToSlashReplacer(String parameter) {
- return parameter.replace('.', '/');
+ @Provides
+ @Singleton
+ @Named("dummy.reactorProjects")
+ private List getDummyReactorProjects() {
+ return Collections.emptyList();
}
- private MavenSession createMavenSession() throws NoLocalRepositoryManagerException {
- MavenSession session = mock(MavenSession.class);
- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory(
- new DefaultLocalPathComposer(),
- new DefaultTrackingFileManager(),
- new DefaultLocalPathPrefixComposerFactory())
- .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
- ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
- buildingRequest.setRepositorySession(repositorySession);
- when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
- when(session.getRepositorySession()).thenReturn(repositorySession);
- when(session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
- .thenReturn(new ConcurrentHashMap());
- return session;
+ private ArtifactInstallerRequest execute(Mojo mojo) {
+ return execute(mojo, null);
}
- private void updateMavenProject(MavenProject project) {
- project.setGroupId(project.getArtifact().getGroupId());
- project.setArtifactId(project.getArtifact().getArtifactId());
- project.setVersion(project.getArtifact().getVersion());
-
- Plugin plugin = new Plugin();
- plugin.setArtifactId("maven-install-plugin");
- project.setBuild(new Build());
- project.getBuild().addPlugin(plugin);
+ private ArtifactInstallerRequest execute(Mojo mojo, Consumer consumer) {
+ AtomicReference request = new AtomicReference<>();
+ doAnswer(iom -> {
+ ArtifactInstallerRequest req = iom.getArgument(0, ArtifactInstallerRequest.class);
+ request.set(req);
+ if (consumer != null) {
+ consumer.accept(req);
+ }
+ return null;
+ })
+ .when(artifactInstaller)
+ .install(any(ArtifactInstallerRequest.class));
+ mojo.execute();
+ return request.get();
}
}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java b/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java
deleted file mode 100644
index 53f30b4e..00000000
--- a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java
+++ /dev/null
@@ -1,34 +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.install.stubs;
-
-import java.io.File;
-
-public class AttachedArtifactStub0 extends InstallArtifactStub {
- public String getArtifactId() {
- return "attached-artifact-test-0";
- }
-
- public File getFile() {
- return new File(
- System.getProperty("basedir"),
- "target/test-classes/unit/basic-install-test-with-attached-artifacts/"
- + "target/maven-install-test-1.0-SNAPSHOT.jar");
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java b/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java
deleted file mode 100644
index ad869b8c..00000000
--- a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java
+++ /dev/null
@@ -1,25 +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.install.stubs;
-
-public class AttachedArtifactStub1 extends AttachedArtifactStub0 {
- public String getArtifactId() {
- return "attached-artifact-test-1";
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java b/src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java
deleted file mode 100644
index 46d58c48..00000000
--- a/src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java
+++ /dev/null
@@ -1,99 +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.install.stubs;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-
-public class InstallArtifactStub extends ArtifactStub {
- private Map