Skip to content

Commit

Permalink
[MINSTALL-196] Honor packaging in install-file mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Aug 14, 2024
1 parent 75955fb commit 36ad2ec
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/it/install-file-minstall-121-bundle/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
file = test-0.1.jar
pomFile = test-0.1.pom
packaging = bundle
extension = jar
2 changes: 1 addition & 1 deletion src/it/install-file-minstall-121-bundle/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/it/install-file-minstall-121-java-source/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
file = test-0.1.jar
pomFile = test-0.1.pom
packaging = maven-archetype
extension = jar
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/it/install-file-minstall-121-targz/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
file = test-0.1.tar.gz
pomFile = test-0.1.pom
packaging = war
extension = tar.gz
2 changes: 1 addition & 1 deletion src/it/install-file-minstall-121-targz/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;
Expand All @@ -58,7 +59,6 @@
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.
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -216,16 +225,23 @@ public void execute() throws MojoExecutionException, MojoFailureException {

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);

Expand Down

0 comments on commit 36ad2ec

Please sign in to comment.