Skip to content

[MDEPLOY-311] Pass on 'packaging' when creating artifact to upload #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
deployRequest.setRepository(remoteRepository);

boolean isFilePom = classifier == null && "pom".equals(packaging);
String extension = packaging;
if (!isFilePom) {
ArtifactType artifactType =
session.getRepositorySession().getArtifactTypeRegistry().get(packaging);
if (artifactType != null
&& (classifier == null || classifier.isEmpty())
&& !StringUtils.isEmpty(artifactType.getClassifier())) {
classifier = artifactType.getClassifier();
extension = artifactType.getExtension();
}
}
Artifact mainArtifact = new DefaultArtifact(
groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
.setFile(file);
Artifact mainArtifact = new DefaultArtifact(groupId, artifactId, classifier, extension, version).setFile(file);
deployRequest.addArtifact(mainArtifact);

File artifactLocalFile = getLocalRepositoryFile(session.getRepositorySession(), mainArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,45 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
assertTrue(file.exists());
}

public void testDeployFileIfPackagingIsSet() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-packaging/plugin-config.xml");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is missing in PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);

MockitoAnnotations.initMocks(this);

assertNotNull(mojo);

ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

String packaging = (String) getVariableValueFromObject(mojo, "packaging");

String groupId = (String) getVariableValueFromObject(mojo, "groupId");

String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");

String version = (String) getVariableValueFromObject(mojo, "version");

assertEquals("differentpackaging", packaging);

mojo.execute();

File deployedArtifact = new File(
remoteRepo,
"deploy-file-packaging/" + groupId.replace('.', '/') + "/"
+ artifactId + "/" + version + "/" + artifactId + "-"
+ version + ".differentpackaging");

assertTrue(deployedArtifact.exists());
}

private void addFileToList(File file, List<String> fileList) {
if (!file.isDirectory()) {
fileList.add(file.getName());
Expand Down
38 changes: 38 additions & 0 deletions src/test/resources/unit/deploy-file-packaging/plugin-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
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.
-->

<project>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<groupId>org.apache.maven.test</groupId>
<artifactId>maven-deploy-file-test</artifactId>
<version>1.0</version>
<packaging>differentpackaging</packaging>
<file>${basedir}/src/test/resources/unit/deploy-file-packaging/target/deploy-test-file-1.0-SNAPSHOT.jar</file>
<repositoryId>deploy-test</repositoryId>
<url>file://${basedir}/target/remote-repo/deploy-file-packaging</url>
<generatePom>true</generatePom>
</configuration>
</plugin>
</plugins>
</build>
</project>