Skip to content

Commit 4e1e56a

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 707ab61 commit 4e1e56a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
274274
classifier = artifactType.getClassifier();
275275
}
276276
}
277-
Artifact mainArtifact = new DefaultArtifact(
278-
groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
279-
.setFile(file);
277+
Artifact mainArtifact = new DefaultArtifact(groupId, artifactId, classifier, packaging, version).setFile(file);
280278
deployRequest.addArtifact(mainArtifact);
281279

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

0 commit comments

Comments
 (0)