You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2024/08/14 13:54:24 UTC
(maven-install-plugin) branch MINSTALL-196 created (now 36ad2ec)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a change to branch MINSTALL-196
in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git
at 36ad2ec [MINSTALL-196] Honor packaging in install-file mojo
This branch includes the following new commits:
new 36ad2ec [MINSTALL-196] Honor packaging in install-file mojo
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-install-plugin) 01/01: [MINSTALL-196] Honor packaging in install-file mojo
Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch MINSTALL-196
in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git
commit 36ad2ec5541f67534ca58a29341d0f3d5ae08e9c
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Wed Aug 14 15:53:53 2024 +0200
[MINSTALL-196] Honor packaging in install-file mojo
---
https://issues.apache.org/jira/browse/MINSTALL-196
---
.../test.properties | 1 +
src/it/install-file-minstall-121-bundle/verify.bsh | 2 +-
.../verify.bsh | 2 +-
.../test.properties | 1 +
.../verify.bsh | 2 +-
.../test.properties | 1 +
src/it/install-file-minstall-121-targz/verify.bsh | 2 +-
.../maven/plugins/install/InstallFileMojo.java | 30 +++++++++++++++++-----
8 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/it/install-file-minstall-121-bundle/test.properties b/src/it/install-file-minstall-121-bundle/test.properties
index 2aced53..8c87fbf 100644
--- a/src/it/install-file-minstall-121-bundle/test.properties
+++ b/src/it/install-file-minstall-121-bundle/test.properties
@@ -18,3 +18,4 @@
file = test-0.1.jar
pomFile = test-0.1.pom
packaging = bundle
+extension = jar
diff --git a/src/it/install-file-minstall-121-bundle/verify.bsh b/src/it/install-file-minstall-121-bundle/verify.bsh
index 3ef1623..75e6122 100644
--- a/src/it/install-file-minstall-121-bundle/verify.bsh
+++ b/src/it/install-file-minstall-121-bundle/verify.bsh
@@ -24,7 +24,7 @@ String[] paths =
{
"org/apache/maven/its/install/121/maven-bundle/maven-metadata-local.xml",
"org/apache/maven/its/install/121/maven-bundle/1.0/maven-bundle-1.0.pom",
- "org/apache/maven/its/install/121/maven-bundle/1.0/maven-bundle-1.0.jar",
+ "org/apache/maven/its/install/121/maven-bundle/1.0/maven-bundle-1.0.jar", // packaging bundle is NOT in core! (explicitly set with -Dextension=jar)
};
for ( String path : paths )
diff --git a/src/it/install-file-minstall-121-java-source/verify.bsh b/src/it/install-file-minstall-121-java-source/verify.bsh
index b0e36fe..666fcbc 100644
--- a/src/it/install-file-minstall-121-java-source/verify.bsh
+++ b/src/it/install-file-minstall-121-java-source/verify.bsh
@@ -24,7 +24,7 @@ String[] paths =
{
"org/apache/maven/its/install/121/test-java-source/maven-metadata-local.xml",
"org/apache/maven/its/install/121/test-java-source/1.0/test-java-source-1.0.pom",
- "org/apache/maven/its/install/121/test-java-source/1.0/test-java-source-1.0-sources.jar",
+ "org/apache/maven/its/install/121/test-java-source/1.0/test-java-source-1.0-sources.jar", // packaging java-source IS in core
};
for ( String path : paths )
diff --git a/src/it/install-file-minstall-121-maven-archetype/test.properties b/src/it/install-file-minstall-121-maven-archetype/test.properties
index 4ab80ed..393cdfd 100644
--- a/src/it/install-file-minstall-121-maven-archetype/test.properties
+++ b/src/it/install-file-minstall-121-maven-archetype/test.properties
@@ -18,3 +18,4 @@
file = test-0.1.jar
pomFile = test-0.1.pom
packaging = maven-archetype
+extension = jar
diff --git a/src/it/install-file-minstall-121-maven-archetype/verify.bsh b/src/it/install-file-minstall-121-maven-archetype/verify.bsh
index e08bfd4..a729164 100644
--- a/src/it/install-file-minstall-121-maven-archetype/verify.bsh
+++ b/src/it/install-file-minstall-121-maven-archetype/verify.bsh
@@ -24,7 +24,7 @@ String[] paths =
{
"org/apache/maven/its/install/121/maven-archetype/maven-metadata-local.xml",
"org/apache/maven/its/install/121/maven-archetype/1.0/maven-archetype-1.0.pom",
- "org/apache/maven/its/install/121/maven-archetype/1.0/maven-archetype-1.0.jar",
+ "org/apache/maven/its/install/121/maven-archetype/1.0/maven-archetype-1.0.jar", // packaging maven-archetype is NOT in core! (explicitly set with -Dextension=jar)
};
for ( String path : paths )
diff --git a/src/it/install-file-minstall-121-targz/test.properties b/src/it/install-file-minstall-121-targz/test.properties
index 8485d14..50af2b8 100644
--- a/src/it/install-file-minstall-121-targz/test.properties
+++ b/src/it/install-file-minstall-121-targz/test.properties
@@ -18,3 +18,4 @@
file = test-0.1.tar.gz
pomFile = test-0.1.pom
packaging = war
+extension = tar.gz
diff --git a/src/it/install-file-minstall-121-targz/verify.bsh b/src/it/install-file-minstall-121-targz/verify.bsh
index b3f31de..2507853 100644
--- a/src/it/install-file-minstall-121-targz/verify.bsh
+++ b/src/it/install-file-minstall-121-targz/verify.bsh
@@ -24,7 +24,7 @@ String[] paths =
{
"org/apache/maven/its/install/121/test-targz/maven-metadata-local.xml",
"org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.pom",
- "org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.tar.gz",
+ "org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.tar.gz", // this test is totally fluke: deploy POM.packaging=war and main artifact tar.gz
};
for ( String path : paths )
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 4ba6b64..b0c25a2 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
@@ -43,6 +43,7 @@ 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.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.DefaultRepositoryCache;
import org.eclipse.aether.DefaultRepositorySystemSession;
@@ -58,7 +59,6 @@ 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;
/**
* Installs a file in the local repository.
@@ -112,6 +112,15 @@ public class InstallFileMojo extends AbstractMojo {
@Parameter(property = "classifier")
private String classifier;
+ /**
+ * Extension of the artifact to be installed. If set, will override plugin own logic to detect extension. If not set,
+ * as Maven expected, packaging determines the artifact extension.
+ *
+ * @since 3.1.3
+ */
+ @Parameter(property = "extension")
+ private String extension;
+
/**
* The file to be installed in the local repository.
*/
@@ -216,16 +225,23 @@ public class InstallFileMojo extends AbstractMojo {
InstallRequest installRequest = new InstallRequest();
- boolean isFilePom = isNull(classifier) && IS_POM_PACKAGING.test(packaging);
- if (!isFilePom) {
+ String mainArtifactExtension;
+ if (classifier == null && "pom".equals(packaging)) {
+ mainArtifactExtension = "pom";
+ } else {
ArtifactType artifactType =
- repositorySystemSession.getArtifactTypeRegistry().get(packaging);
- if (nonNull(artifactType) && IS_EMPTY.test(classifier) && !IS_EMPTY.test(artifactType.getClassifier())) {
- classifier = artifactType.getClassifier();
+ session.getRepositorySession().getArtifactTypeRegistry().get(packaging);
+ if (artifactType != null) {
+ if (StringUtils.isEmpty(classifier) && !StringUtils.isEmpty(artifactType.getClassifier())) {
+ classifier = artifactType.getClassifier();
+ }
+ mainArtifactExtension = artifactType.getExtension();
+ } else {
+ mainArtifactExtension = packaging;
}
}
Artifact mainArtifact = new DefaultArtifact(
- groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
+ groupId, artifactId, classifier, extension != null ? extension : mainArtifactExtension, version)
.setFile(file);
installRequest.addArtifact(mainArtifact);