|
55 | 55 | import org.eclipse.aether.deployment.DeploymentException; |
56 | 56 | import org.eclipse.aether.repository.RemoteRepository; |
57 | 57 | import org.eclipse.aether.util.artifact.SubArtifact; |
| 58 | +import org.slf4j.Logger; |
| 59 | +import org.slf4j.LoggerFactory; |
58 | 60 |
|
59 | 61 | /** |
60 | 62 | * Installs the artifact in the remote repository. |
|
63 | 65 | */ |
64 | 66 | @Mojo(name = "deploy-file", requiresProject = false, threadSafe = true) |
65 | 67 | public class DeployFileMojo extends AbstractDeployMojo { |
| 68 | + private final Logger log = LoggerFactory.getLogger(getClass()); |
66 | 69 | /** |
67 | 70 | * GroupId of the artifact to be deployed. Retrieved from POM file if specified. |
68 | 71 | */ |
@@ -90,6 +93,15 @@ public class DeployFileMojo extends AbstractDeployMojo { |
90 | 93 | @Parameter(property = "packaging") |
91 | 94 | private String packaging; |
92 | 95 |
|
| 96 | + /** |
| 97 | + * Extension of the artifact to be deployed. If set, will override plugin own logic to detect extension. If not set, |
| 98 | + * as Maven expected, packaging determines the artifact extension. |
| 99 | + * |
| 100 | + * @since 3.1.3 |
| 101 | + */ |
| 102 | + @Parameter(property = "extension") |
| 103 | + private String extension; |
| 104 | + |
93 | 105 | /** |
94 | 106 | * Description passed to a generated POM file (in case of generatePom=true) |
95 | 107 | */ |
@@ -196,7 +208,7 @@ void initProperties() throws MojoExecutionException { |
196 | 208 | JarEntry entry = jarEntries.nextElement(); |
197 | 209 |
|
198 | 210 | if (pomEntry.matcher(entry.getName()).matches()) { |
199 | | - getLog().debug("Using " + entry.getName() + " as pomFile"); |
| 211 | + log.debug("Using {} as pomFile", entry.getName()); |
200 | 212 | foundPom = true; |
201 | 213 | String base = file.getName(); |
202 | 214 | if (base.indexOf('.') > 0) { |
@@ -215,7 +227,7 @@ void initProperties() throws MojoExecutionException { |
215 | 227 | } |
216 | 228 |
|
217 | 229 | if (!foundPom) { |
218 | | - getLog().info("pom.xml not found in " + file.getName()); |
| 230 | + log.info("pom.xml not found in {}", file.getName()); |
219 | 231 | } |
220 | 232 | } catch (IOException e) { |
221 | 233 | // ignore, artifact not packaged by Maven |
@@ -235,7 +247,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { |
235 | 247 | if (Boolean.parseBoolean(skip) |
236 | 248 | || ("releases".equals(skip) && !ArtifactUtils.isSnapshot(version)) |
237 | 249 | || ("snapshots".equals(skip) && ArtifactUtils.isSnapshot(version))) { |
238 | | - getLog().info("Skipping artifact deployment"); |
| 250 | + log.info("Skipping artifact deployment"); |
239 | 251 | return; |
240 | 252 | } |
241 | 253 |
|
@@ -266,18 +278,29 @@ public void execute() throws MojoExecutionException, MojoFailureException { |
266 | 278 | DeployRequest deployRequest = new DeployRequest(); |
267 | 279 | deployRequest.setRepository(remoteRepository); |
268 | 280 |
|
269 | | - boolean isFilePom = classifier == null && "pom".equals(packaging); |
270 | | - if (!isFilePom) { |
| 281 | + String mainArtifactExtension; |
| 282 | + if (classifier == null && "pom".equals(packaging)) { |
| 283 | + mainArtifactExtension = "pom"; |
| 284 | + } else { |
271 | 285 | ArtifactType artifactType = |
272 | 286 | session.getRepositorySession().getArtifactTypeRegistry().get(packaging); |
273 | | - if (artifactType != null |
274 | | - && (classifier == null || classifier.isEmpty()) |
275 | | - && !StringUtils.isEmpty(artifactType.getClassifier())) { |
276 | | - classifier = artifactType.getClassifier(); |
| 287 | + if (artifactType != null) { |
| 288 | + if (StringUtils.isEmpty(classifier) && !StringUtils.isEmpty(artifactType.getClassifier())) { |
| 289 | + classifier = artifactType.getClassifier(); |
| 290 | + } |
| 291 | + mainArtifactExtension = artifactType.getExtension(); |
| 292 | + } else { |
| 293 | + mainArtifactExtension = packaging; |
277 | 294 | } |
278 | 295 | } |
| 296 | + if (extension != null && !Objects.equals(extension, mainArtifactExtension)) { |
| 297 | + log.warn( |
| 298 | + "Main artifact extension should be '{}' but was overridden to '{}'", |
| 299 | + mainArtifactExtension, |
| 300 | + extension); |
| 301 | + } |
279 | 302 | Artifact mainArtifact = new DefaultArtifact( |
280 | | - groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version) |
| 303 | + groupId, artifactId, classifier, extension != null ? extension : mainArtifactExtension, version) |
281 | 304 | .setFile(file); |
282 | 305 | deployRequest.addArtifact(mainArtifact); |
283 | 306 |
|
@@ -293,10 +316,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { |
293 | 316 | deployRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", pomFile)); |
294 | 317 | } else if (generatePom) { |
295 | 318 | temporaryPom = generatePomFile(); |
296 | | - getLog().debug("Deploying generated POM"); |
| 319 | + log.debug("Deploying generated POM"); |
297 | 320 | deployRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", temporaryPom)); |
298 | 321 | } else { |
299 | | - getLog().debug("Skipping deploying POM"); |
| 322 | + log.debug("Skipping deploying POM"); |
300 | 323 | } |
301 | 324 | } |
302 | 325 |
|
|