Skip to content

Commit 4e4fee1

Browse files
committed
[MDEPLOY-311] Pass on 'packaging' when creating artifact to upload
Fixes a regression introduced in 16541da [MDEPLOY-296] which caused the -Dpackaging property to be ignored when uploading the artifact. Instead, the packaging type during upload was always derived from the file name.
1 parent 29f3c81 commit 4e4fee1

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
265265
deployRequest.setRepository(remoteRepository);
266266

267267
boolean isFilePom = classifier == null && "pom".equals(packaging);
268+
String extension = packaging;
268269
if (!isFilePom) {
269270
ArtifactType artifactType =
270271
session.getRepositorySession().getArtifactTypeRegistry().get(packaging);
271272
if (artifactType != null
272273
&& (classifier == null || classifier.isEmpty())
273274
&& !StringUtils.isEmpty(artifactType.getClassifier())) {
274275
classifier = artifactType.getClassifier();
276+
extension = artifactType.getExtension();
275277
}
276278
}
277-
Artifact mainArtifact = new DefaultArtifact(
278-
groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
279-
.setFile(file);
279+
Artifact mainArtifact = new DefaultArtifact(groupId, artifactId, classifier, extension, version).setFile(file);
280280
deployRequest.addArtifact(mainArtifact);
281281

282282
File artifactLocalFile = getLocalRepositoryFile(session.getRepositorySession(), mainArtifact);

src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java

+39
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,45 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
276276
assertTrue(file.exists());
277277
}
278278

279+
public void testDeployFileIfPackagingIsSet() throws Exception {
280+
File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-packaging/plugin-config.xml");
281+
282+
mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
283+
284+
MockitoAnnotations.initMocks(this);
285+
286+
assertNotNull(mojo);
287+
288+
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
289+
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
290+
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
291+
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
292+
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
293+
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
294+
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
295+
when(session.getRepositorySession()).thenReturn(repositorySession);
296+
297+
String packaging = (String) getVariableValueFromObject(mojo, "packaging");
298+
299+
String groupId = (String) getVariableValueFromObject(mojo, "groupId");
300+
301+
String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
302+
303+
String version = (String) getVariableValueFromObject(mojo, "version");
304+
305+
assertEquals("differentpackaging", packaging);
306+
307+
mojo.execute();
308+
309+
File deployedArtifact = new File(
310+
remoteRepo,
311+
"deploy-file-packaging/" + groupId.replace('.', '/') + "/"
312+
+ artifactId + "/" + version + "/" + artifactId + "-"
313+
+ version + ".differentpackaging");
314+
315+
assertTrue(deployedArtifact.exists());
316+
}
317+
279318
private void addFileToList(File file, List<String> fileList) {
280319
if (!file.isDirectory()) {
281320
fileList.add(file.getName());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
<project>
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<artifactId>maven-deploy-plugin</artifactId>
25+
<configuration>
26+
<groupId>org.apache.maven.test</groupId>
27+
<artifactId>maven-deploy-file-test</artifactId>
28+
<version>1.0</version>
29+
<packaging>differentpackaging</packaging>
30+
<file>${basedir}/src/test/resources/unit/deploy-file-packaging/target/deploy-test-file-1.0-SNAPSHOT.jar</file>
31+
<repositoryId>deploy-test</repositoryId>
32+
<url>file://${basedir}/target/remote-repo/deploy-file-packaging</url>
33+
<generatePom>true</generatePom>
34+
</configuration>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
</project>

0 commit comments

Comments
 (0)